summaryrefslogtreecommitdiff
path: root/libhw
diff options
context:
space:
mode:
Diffstat (limited to 'libhw')
-rw-r--r--libhw/host_alarmclock.c25
-rw-r--r--libhw/host_include/libhw/host_alarmclock.h29
-rw-r--r--libhw/rp2040_hwtimer.c4
3 files changed, 35 insertions, 23 deletions
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) {