From eaba2a7b0658f648bf32219aec0ce827c94333a0 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 27 Feb 2021 22:26:22 +1300 Subject: 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. --- timer_linux.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 timer_linux.c (limited to 'timer_linux.c') 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 +#include + +#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; +} -- cgit v1.1