30 #include <sys/timerfd.h>
38 #ifndef SYS_TIME_THREAD_PRIO
39 #define SYS_TIME_THREAD_PRIO 29
48 #define NSEC_OF_SEC(sec) ((sec) * 1e9)
55 fd = timerfd_create(CLOCK_MONOTONIC, 0);
57 perror(
"Could not set up timer.");
64 struct itimerspec timer;
66 timer.it_value.tv_sec = 0;
69 timer.it_interval.tv_sec = 0;
72 if (timerfd_settime(fd, 0, &timer, NULL) == -1) {
73 perror(
"Could not set up timer.");
78 unsigned long long missed;
81 int r = read(fd, &missed,
sizeof(missed));
83 perror(
"Couldn't read timer!");
86 fprintf(stderr,
"Missed %lld timer events!\n", missed);
103 perror(
"Could not setup sys_time_thread");
112 clock_gettime(CLOCK_MONOTONIC, &now);
121 d_nsec += 1000000000L;
static void sys_tick_handler(void)
static uint32_t cpu_ticks_of_nsec(uint32_t nsec)
float resolution
sys_time_timer resolution in seconds
uint32_t cpu_ticks_per_sec
cpu ticks per second
void * sys_time_thread_main(void *data)
volatile uint32_t nb_tick
SYS_TIME_TICKS since startup.
Functions to obtain rt priority or set the nice level.
pthread_t sys_time_thread
Architecture independent timing functions.
uint32_t end_time
in SYS_TIME_TICKS
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
struct sys_time_timer timer[SYS_TIME_NB_TIMER]
static uint32_t sys_time_ticks_of_sec(float seconds)
volatile uint32_t nb_sec
full seconds since startup
static struct timespec startup_time
#define SYS_TIME_THREAD_PRIO
arch independent LED (Light Emitting Diodes) API
#define SYS_TIME_NB_TIMER
void sys_time_arch_init(void)
static int get_rt_prio(int prio)
uint32_t duration
in SYS_TIME_TICKS
static uint32_t sys_time_ticks_of_usec(uint32_t usec)
uint32_t resolution_cpu_ticks
sys_time_timer resolution in cpu ticks