#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; }