blob: 56886e3bfa57f5eeab069d4588667f2f230b366e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
}
|