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;
183 clock_gettime(CLOCK_MONOTONIC, &now);
192 d_nsec += 1000000000L;
194 return d_sec * 10000 + d_nsec / 100000;
205 clock_gettime(CLOCK_MONOTONIC, &now);
214 d_nsec += 1000000000L;
216 return d_sec * 1000 + d_nsec / 1000000;
uint32_t get_sys_time_usec100(void)
Get the time in microseconds divided by 100 since startup.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
void sys_time_arch_init(void)
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
arch independent LED (Light Emitting Diodes) API
#define SYS_TIME_THREAD_PRIO
void * sys_time_thread_main(void *data)
static struct timespec startup_time
static void sys_tick_handler(void)
Functions to obtain rt priority or set the nice level.
static int get_rt_prio(int prio)
Architecture independent timing functions.
volatile uint32_t nb_tick
SYS_TIME_TICKS since startup.
static uint32_t sys_time_ticks_of_sec(float seconds)
volatile uint32_t nb_sec
full seconds since startup
uint32_t cpu_ticks_per_sec
cpu ticks per second
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
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
float resolution
sys_time_timer resolution in seconds
#define SYS_TIME_NB_TIMER
static uint32_t cpu_ticks_of_nsec(uint32_t nsec)
uint32_t end_time
in SYS_TIME_TICKS
struct sys_time_timer timer[SYS_TIME_NB_TIMER]
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.