30#include <sys/timerfd.h>
41#ifndef SYS_TIME_THREAD_PRIO
42#define SYS_TIME_THREAD_PRIO 29
51#define NSEC_OF_SEC(sec) ((sec) * 1e9)
58 fd = timerfd_create(CLOCK_MONOTONIC, 0);
60 perror(
"Could not set up timer.");
67 struct itimerspec timer;
69 timer.it_value.tv_sec = 0;
72 timer.it_interval.tv_sec = 0;
75 if (timerfd_settime(
fd, 0, &timer, NULL) == -1) {
76 perror(
"Could not set up timer.");
81 unsigned long long missed;
84 int r = read(
fd, &missed,
sizeof(missed));
86 perror(
"Couldn't read timer!");
89 fprintf(stderr,
"Missed %lld timer events!\n", missed);
107 perror(
"Could not setup sys_time_thread");
111 pthread_setname_np(tid,
"sys_time");
119 clock_gettime(CLOCK_MONOTONIC, &now);
128 d_nsec += 1000000000L;
164 clock_gettime(CLOCK_MONOTONIC, &now);
173 d_nsec += 1000000000L;
175 return d_sec * 1000000 + d_nsec / 1000;
187 clock_gettime(CLOCK_MONOTONIC, &now);
196 d_nsec += 1000000000L;
198 return d_sec * 10000 + d_nsec / 100000;
209 clock_gettime(CLOCK_MONOTONIC, &now);
218 d_nsec += 1000000000L;
220 return d_sec * 1000 + d_nsec / 1000000;
235 struct tm local_time;
237 clock_gettime(CLOCK_REALTIME, &now);
238 gmtime_r(&now.tv_sec, &local_time);
239 uint32_t ms = (local_time.tm_hour * 3600 + local_time.tm_min * 60 + local_time.tm_sec) * 1000
240 + now.tv_nsec / 1000000;
void sys_time_msleep(uint32_t ms)
Sleep.
uint32_t sys_time_rtc_millisecond()
Get the RTC time in milliseconds since midnight.
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
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_rtc_set(uint32_t unix_time, uint16_t unix_ms)
Set the RTC to the UTC unix time (architecture specific, may do nothing).
void sys_time_arch_init(void)
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
void sys_tick_handler(void)
arch independent LED (Light Emitting Diodes) API
#define SYS_TIME_THREAD_PRIO
void * sys_time_thread_main(void *data)
static struct timespec startup_time
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 short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.