43#ifndef SYS_TIME_NB_TIMER
44#define SYS_TIME_NB_TIMER 16
52#ifndef SYS_TIME_FREQUENCY
53#if defined PERIODIC_FREQUENCY
54#define SYS_TIME_FREQUENCY (2 * PERIODIC_FREQUENCY)
56#define SYS_TIME_FREQUENCY 1000
60#define SYS_TIME_MSEC_PER_WEEK (1000UL * 60 * 60 * 24 * 7)
61#define SYS_TIME_UNIX_GPS_EPOCH_MS 315964800000ULL
64#ifndef SYS_TIME_GPS_LEAP_SECONDS
65#define SYS_TIME_GPS_LEAP_SECONDS 18
322#define USEC_OF_SEC(sec) ((sec) * 1e6)
329#define SysTimeTimerStart(_t) { _t = get_sys_time_usec(); }
330#define SysTimeTimer(_t) ( get_sys_time_usec() - (_t))
331#define SysTimeTimerStop(_t) { _t = ( get_sys_time_usec() - (_t)); }
static uint32_t cpu_ticks
volatile uint32_t nb_tick
SYS_TIME_TICKS since startup.
static uint32_t msec_of_cpu_ticks(uint32_t cpu_ticks)
uint32_t ticks_per_sec
sys_time ticks per second (SYS_TIME_FREQUENCY)
void sys_time_msleep(uint32_t ms)
Sleep.
void sys_time_parse_TIME_SYNC(uint8_t *buf)
Parse the TIME_SYNC datalink message (ground time).
uint64_t ground_offset
last applied ground UTC unix time at startup in ms
static uint32_t nsec_of_cpu_ticks(uint32_t cpu_ticks)
static uint32_t sys_time_ticks_of_sec(float seconds)
void sys_time_update_timer(tid_t id, float duration)
Update the duration until a timer elapses.
volatile uint32_t nb_sec
full seconds since startup
bool ground_synced
a ground time was applied
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
void(* sys_time_cb)(uint8_t id)
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)
tid_t sys_time_register_timer_offset(tid_t timer, float offset, sys_time_cb cb)
Register a new system timer with an fixed offset from another one.
uint32_t tow_offset
GPS time of week at startup in ms (0 until synced).
uint32_t gps_tow_sync
uptime in ms of the last GPS time of week sync
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
uint64_t unix_offset
UTC unix time at startup in ms.
uint32_t resolution_cpu_ticks
sys_time_timer resolution in cpu ticks
void sys_time_sync_gps(uint16_t week, uint32_t tow, uint32_t stamp)
Synchronize the time with a GPS measurement (has priority over the ground).
void sys_time_usleep(uint32_t us)
Sleep.
uint32_t get_sys_time_usec100(void)
Get the time in 100microseconds since startup.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
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).
float resolution
sys_time_timer resolution in seconds
static uint32_t cpu_ticks_of_usec(uint32_t usec)
void sys_time_arch_init(void)
uint64_t get_sys_time_unix_msec(void)
Get the UTC unix time in milliseconds.
bool gps_unix_synced
unix time synced with a GPS
#define SYS_TIME_NB_TIMER
uint32_t rtc_sync
uptime in ms of the last RTC update
static uint32_t msec_of_sys_time_ticks(uint32_t ticks)
static uint32_t cpu_ticks_of_nsec(uint32_t nsec)
static uint32_t sys_time_ticks_of_msec(uint32_t msec)
uint32_t end_time
in SYS_TIME_TICKS
void sys_time_cancel_timer(tid_t id)
Cancel a system timer by id.
static uint32_t cpu_ticks_of_sec(float seconds)
uint32_t get_sys_time_tow(void)
Get the GPS time of week in milliseconds.
struct sys_time_timer timer[SYS_TIME_NB_TIMER]
static uint32_t usec_of_cpu_ticks(uint32_t cpu_ticks)
bool gps_tow_synced
time of week synced with a GPS
static float sec_of_sys_time_ticks(uint32_t ticks)
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
static uint32_t usec_of_sys_time_ticks(uint32_t ticks)
void sys_time_sync_unix(uint32_t unix_time, uint16_t unix_ms, uint32_t stamp)
Synchronize the time with the ground, only used without recent GPS sync.
uint32_t gps_unix_sync
uptime in ms of the last GPS unix time sync
uint32_t get_sys_time_unix(void)
Get the UTC unix time in seconds.
static float get_sys_time_float(void)
Get the time in seconds since startup.
bool unix_synced
unix time synced (GPS or ground)
uint32_t sys_time_rtc_millisecond(void)
Get the RTC time in milliseconds since midnight.
int8_t tid_t
sys_time timer id type
static int32_t signed_cpu_ticks_of_usec(int32_t usec)
static const float offset[]
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned long long uint64_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.