30 #include <sys/timerfd.h>
38 #ifndef SYS_TIME_THREAD_PRIO
39 #define SYS_TIME_THREAD_PRIO 29
47 #define NSEC_OF_SEC(sec) ((sec) * 1e9)
54 fd = timerfd_create(CLOCK_MONOTONIC, 0);
56 perror(
"Could not set up timer.");
63 struct itimerspec timer;
65 timer.it_value.tv_sec = 0;
68 timer.it_interval.tv_sec = 0;
71 if (timerfd_settime(fd, 0, &timer, NULL) == -1) {
72 perror(
"Could not set up timer.");
77 unsigned long long missed;
80 int r = read(fd, &missed,
sizeof(missed));
82 perror(
"Couldn't read timer!");
85 fprintf(stderr,
"Missed %lld timer events!\n", missed);
103 perror(
"Could not setup sys_time_thread");
107 pthread_setname_np(tid,
"sys_time");
115 clock_gettime(CLOCK_MONOTONIC, &now);
124 d_nsec += 1000000000L;
160 clock_gettime(CLOCK_MONOTONIC, &now);
169 d_nsec += 1000000000L;
171 return d_sec * 1000000 + d_nsec / 1000;
182 clock_gettime(CLOCK_MONOTONIC, &now);
191 d_nsec += 1000000000L;
193 return d_sec * 1000 + d_nsec / 1000000;
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 get_sys_time_msec(void)
Get the time in milliseconds since startup.
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.
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
static int get_rt_prio(int prio)
uint32_t duration
in SYS_TIME_TICKS
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
static uint32_t sys_time_ticks_of_usec(uint32_t usec)
void sys_time_arch_init(void)
uint32_t resolution_cpu_ticks
sys_time_timer resolution in cpu ticks