aboutsummaryrefslogtreecommitdiff
path: root/timer_linux.c
diff options
context:
space:
mode:
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;
+}