summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-02 02:01:30 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-09 22:22:28 -0700
commit4a6fbecab34616a7b16a859f9458a21b339bb6b0 (patch)
tree4ffc6a8f2732ac29e6e75d0677c93c2213db6948
parentfa10ceb13e66309ba24605dd5df91c4d626f0614 (diff)
Have main() set `bootclock`
-rw-r--r--cmd/sbc_harness/main.c3
-rw-r--r--lib9p/tests/test_server/main.c6
-rw-r--r--libhw/host_alarmclock.c25
-rw-r--r--libhw/host_include/libhw/host_alarmclock.h29
-rw-r--r--libhw/rp2040_hwtimer.c4
-rw-r--r--libhw_generic/alarmclock.c4
6 files changed, 47 insertions, 24 deletions
diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c
index b17725d..4580acc 100644
--- a/cmd/sbc_harness/main.c
+++ b/cmd/sbc_harness/main.c
@@ -10,7 +10,9 @@
#include <hardware/flash.h> /* pico-sdk:hardware_flash: for flash_get_unique_id() */
#include <libcr/coroutine.h>
+#include <libhw/generic/alarmclock.h> /* so we can set `bootclock` */
#include <libhw/rp2040_hwspi.h>
+#include <libhw/rp2040_hwtimer.h>
#include <libhw/w5500.h>
#include <libmisc/hash.h>
#include <libmisc/vcall.h>
@@ -131,6 +133,7 @@ COROUTINE init_cr(void *) {
}
int main() {
+ bootclock = rp2040_hwtimer(0);
stdio_uart_init();
/* char *hdr = "=" * (80-strlen("info : MAIN: ")); */
infof("===================================================================");
diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c
index f4b21db..b979a4b 100644
--- a/lib9p/tests/test_server/main.c
+++ b/lib9p/tests/test_server/main.c
@@ -10,6 +10,7 @@
#include <libcr/coroutine.h>
#include <libhw/generic/net.h>
#include <libhw/generic/alarmclock.h>
+#include <libhw/host_alarmclock.h>
#include <libhw/host_net.h>
#include <libmisc/macro.h>
#include <util9p/static.h>
@@ -193,6 +194,11 @@ static COROUTINE init_cr(void *) {
}
int main() {
+ struct hostclock clock_monotonic = {
+ .vtable = &hostclock_vtable,
+ .clock_id = CLOCK_MONOTONIC,
+ };
+ bootclock = &clock_monotonic;
coroutine_add("init", init_cr, NULL);
coroutine_main();
return 0;
diff --git a/libhw/host_alarmclock.c b/libhw/host_alarmclock.c
index 5f7e494..bb1821a 100644
--- a/libhw/host_alarmclock.c
+++ b/libhw/host_alarmclock.c
@@ -1,13 +1,12 @@
/* libhw/host_alarmclock.c - <libhw/generic/alarmclock.h> implementation for POSIX hosts
*
- * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+ * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <errno.h>
#include <error.h>
#include <signal.h>
-#include <time.h>
#include <libcr/coroutine.h>
#include <libmisc/assert.h>
@@ -16,17 +15,10 @@
#define IMPLEMENTATION_FOR_LIBHW_GENERIC_ALARMCLOCK_H YES
#include <libhw/generic/alarmclock.h>
-#include "host_util.h" /* for host_sigrt_alloc(), ns_to_host_ns_time() */
-
-/* Types **********************************************************************/
+#define IMPLEMENTATION_FOR_LIBHW_HOST_ALARMCLOCK_H YES
+#include <libhw/host_alarmclock.h>
-struct hostclock {
- implements_alarmclock;
- bool initialized;
- clockid_t clock_id;
- timer_t timer_id;
- struct alarmclock_trigger *queue;
-};
+#include "host_util.h" /* for host_sigrt_alloc(), ns_to_host_ns_time() */
/* Globals ********************************************************************/
@@ -39,19 +31,12 @@ static bool hostclock_add_trigger(implements_alarmclock *self,
static void hostclock_del_trigger(implements_alarmclock *self,
struct alarmclock_trigger *trigger);
-static struct alarmclock_vtable hostclock_vtable = {
+struct alarmclock_vtable hostclock_vtable = {
.get_time_ns = hostclock_get_time_ns,
.add_trigger = hostclock_add_trigger,
.del_trigger = hostclock_del_trigger,
};
-static struct hostclock clock_monotonic = {
- .vtable = &hostclock_vtable,
- .clock_id = CLOCK_MONOTONIC,
-};
-
-implements_alarmclock *bootclock = &clock_monotonic;
-
/* Main implementation ********************************************************/
static uint64_t hostclock_get_time_ns(implements_alarmclock *_alarmclock) {
diff --git a/libhw/host_include/libhw/host_alarmclock.h b/libhw/host_include/libhw/host_alarmclock.h
new file mode 100644
index 0000000..163fb9f
--- /dev/null
+++ b/libhw/host_include/libhw/host_alarmclock.h
@@ -0,0 +1,29 @@
+/* libhw/host_alarmclock.h - <libhw/generic/alarmclock.h> implementation for hosted glibc
+ *
+ * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#ifndef _LIBHW_HOST_ALARMCLOCK_H_
+#define _LIBHW_HOST_ALARMCLOCK_H_
+
+#include <stdbool.h> /* for bool */
+#include <time.h> /* for clockid_t, timer_t */
+
+#include <libmisc/private.h>
+#include <libhw/generic/alarmclock.h>
+
+struct hostclock {
+ implements_alarmclock;
+ clockid_t clock_id;
+
+ BEGIN_PRIVATE(LIBHW_HOST_ALARMCLOCK_H)
+ bool initialized;
+ timer_t timer_id;
+ struct alarmclock_trigger *queue;
+ END_PRIVATE(LIBHW_HOST_ALARMCLOCK_H)
+};
+
+extern struct alarmclock_vtable hostclock_vtable;
+
+#endif /* _LIBHW_HOST_ALARMCLOCK_H_ */
diff --git a/libhw/rp2040_hwtimer.c b/libhw/rp2040_hwtimer.c
index c8c281e..6c871a3 100644
--- a/libhw/rp2040_hwtimer.c
+++ b/libhw/rp2040_hwtimer.c
@@ -1,6 +1,6 @@
/* libhw/rp2040_hwtimer.c - <libhw/generic/alarmclock.h> implementation for the RP2040's hardware timer
*
- * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+ * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
@@ -54,8 +54,6 @@ static struct rp2040_hwtimer hwtimers[] = {
};
static_assert(sizeof(hwtimers)/sizeof(hwtimers[0]) == _RP2040_HWALARM_NUM);
-implements_alarmclock *bootclock = &hwtimers[0];
-
/* Main implementation ********************************************************/
implements_alarmclock *rp2040_hwtimer(enum rp2040_hwalarm_instance alarm_num) {
diff --git a/libhw_generic/alarmclock.c b/libhw_generic/alarmclock.c
index a16f2f6..d501f51 100644
--- a/libhw_generic/alarmclock.c
+++ b/libhw_generic/alarmclock.c
@@ -1,6 +1,6 @@
/* libhw_generic/alarmclock.c - Device-independent <libhw/generic/alarmclock.h> utilities
*
- * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+ * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
@@ -9,6 +9,8 @@
#include <libhw/generic/alarmclock.h>
+implements_alarmclock *bootclock = NULL;
+
static void alarmclock_sleep_intrhandler(void *_arg) {
cid_t cid = *(cid_t *)_arg;
cr_unpause_from_intrhandler(cid);