aboutsummaryrefslogtreecommitdiff
path: root/timer_linux.c
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2021-02-27 22:26:22 +1300
committerDavid Phillips <david@yeah.nah.nz>2021-02-27 22:26:22 +1300
commiteaba2a7b0658f648bf32219aec0ce827c94333a0 (patch)
tree42f50d2f3c87abfb7af0149430a67afb778fd4f1 /timer_linux.c
parent450829bab633da3bce84a9a0f6857e68e46c7eb4 (diff)
downloadaltimeter-eaba2a7b0658f648bf32219aec0ce827c94333a0.tar.xz
Make timer mandatory for data manager
The NULL check was a bit of a hack to get the test building. Probably a bad idea to leave it around, since there's no time it's sane to leave the timestamps on data manager contexts unset.
Diffstat (limited to 'timer_linux.c')
-rw-r--r--timer_linux.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/timer_linux.c b/timer_linux.c
new file mode 100644
index 0000000..56886e3
--- /dev/null
+++ b/timer_linux.c
@@ -0,0 +1,29 @@
+#include <time.h>
+#include <stdint.h>
+
+#include "timer.h"
+
+/* On POSIX, we emulate a monotonic 16-bit timer for timestamping events in
+ * lieu of timer3 on the AVR.
+ */
+
+static void timer_init(void)
+{
+ /* do nothing */
+}
+
+static uint16_t timer_get_value(void)
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ /* FIXME abort on error */
+ /* return milliseconds as uint16_t, truncating the rest */
+ return ts.tv_nsec / 1e6;
+}
+
+
+void get_system_timer(struct timer *timer)
+{
+ timer->init = timer_init;
+ timer->get_time = timer_get_value;
+}