|
Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
|
Architecture independent timing functions. More...
#include "mcu_periph/sys_time.h"#include "mcu.h"#include "pprzlink/dl_protocol.h"#include "limits.h"Go to the source code of this file.
Macros | |
| #define | SYS_TIME_GPS_SYNC_TIMEOUT 10000 |
| Time without GPS sync in ms before the ground time is used. | |
| #define | SYS_TIME_RTC_SYNC_PERIOD 5000 |
| Period of the RTC updates in ms. | |
| #define | SYS_TIME_GROUND_SYNC_THRESHOLD 200 |
| Minimum difference in ms before the ground time is applied again, avoids steps (also backwards) from the round trip jitter of the link. | |
| #define | SYS_TIME_GPS_LEAP_MS ((uint64_t)SYS_TIME_GPS_LEAP_SECONDS * 1000) |
Functions | |
| static uint64_t | uptime_msec (void) |
| Milliseconds since startup without the ~49.7 days wrap of get_sys_time_msec() nb_sec gives the number of wraps, get_sys_time_msec() the exact time. | |
| uint32_t | get_sys_time_tow (void) |
| Get the GPS time of week in milliseconds. | |
| uint64_t | get_sys_time_unix_msec (void) |
| Get the UTC unix time in milliseconds. | |
| uint32_t | get_sys_time_unix (void) |
| Get the UTC unix time in seconds. | |
| static uint64_t | msec_of_stamp (uint32_t stamp, uint64_t *now) |
| uptime_msec() at the moment of the timestamp in usec the usec stamp wraps after ~71 min, so only use its age with respect to now | |
| static void | set_tow (uint32_t tow, uint64_t msec) |
| static void | set_unix (uint64_t unix_ms, uint64_t msec, uint64_t now) |
| 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_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. | |
| tid_t | sys_time_register_timer (float duration, sys_time_cb cb) |
| Register a new system timer. | |
| 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. | |
| void | sys_time_cancel_timer (tid_t id) |
| Cancel a system timer by id. | |
| void | sys_time_update_timer (tid_t id, float duration) |
| Update the duration until a timer elapses. | |
| void | sys_time_parse_TIME_SYNC (uint8_t *buf) |
| Parse the TIME_SYNC datalink message (ground time). | |
| void | sys_time_init (void) |
Variables | |
| struct sys_time | sys_time |
Architecture independent timing functions.
Definition in file sys_time.c.
| #define SYS_TIME_GPS_LEAP_MS ((uint64_t)SYS_TIME_GPS_LEAP_SECONDS * 1000) |
Definition at line 60 of file sys_time.c.
Referenced by sys_time_sync_gps(), and sys_time_sync_unix().
| #define SYS_TIME_GPS_SYNC_TIMEOUT 10000 |
Time without GPS sync in ms before the ground time is used.
Definition at line 46 of file sys_time.c.
Referenced by sys_time_sync_unix().
| #define SYS_TIME_GROUND_SYNC_THRESHOLD 200 |
Minimum difference in ms before the ground time is applied again, avoids steps (also backwards) from the round trip jitter of the link.
Definition at line 57 of file sys_time.c.
Referenced by sys_time_sync_unix().
| #define SYS_TIME_RTC_SYNC_PERIOD 5000 |
Period of the RTC updates in ms.
Definition at line 51 of file sys_time.c.
Referenced by set_unix().
| uint32_t get_sys_time_tow | ( | void | ) |
Get the GPS time of week in milliseconds.
Synced from the GPS, or from the ground (TIME_SYNC) without GPS. Until synced this is the time since startup.
Definition at line 72 of file sys_time.c.
References SYS_TIME_MSEC_PER_WEEK, sys_time::tow_offset, and uptime_msec().
Referenced by gps_tow_from_sys_ticks().
| uint32_t get_sys_time_unix | ( | void | ) |
Get the UTC unix time in seconds.
Synced from the GPS, or from the ground (TIME_SYNC) without GPS.
Definition at line 87 of file sys_time.c.
References get_sys_time_unix_msec().
| uint64_t get_sys_time_unix_msec | ( | void | ) |
Get the UTC unix time in milliseconds.
Definition at line 77 of file sys_time.c.
References sys_time::unix_offset, sys_time::unix_synced, and uptime_msec().
Referenced by get_sys_time_unix().
uptime_msec() at the moment of the timestamp in usec the usec stamp wraps after ~71 min, so only use its age with respect to now
Definition at line 94 of file sys_time.c.
References get_sys_time_usec(), and uptime_msec().
Referenced by sys_time_sync_gps(), and sys_time_sync_unix().
Definition at line 101 of file sys_time.c.
References SYS_TIME_MSEC_PER_WEEK, and sys_time::tow_offset.
Referenced by sys_time_sync_gps(), and sys_time_sync_unix().
Definition at line 107 of file sys_time.c.
References sys_time::rtc_sync, sys_time_rtc_set(), SYS_TIME_RTC_SYNC_PERIOD, sys_time::unix_offset, and sys_time::unix_synced.
Referenced by sys_time_sync_gps(), and sys_time_sync_unix().
| void sys_time_cancel_timer | ( | tid_t | id | ) |
Cancel a system timer by id.
| id | Timer id. |
Definition at line 205 of file sys_time.c.
References sys_time_timer::cb, sys_time_timer::duration, sys_time_timer::elapsed, sys_time_timer::end_time, sys_time_timer::in_use, and sys_time::timer.
Referenced by mavlink_mission_cancel_timer(), and px4flash_event().
| void sys_time_init | ( | void | ) |
Definition at line 263 of file sys_time.c.
References sys_time_timer::cb, sys_time_timer::duration, sys_time_timer::elapsed, sys_time_timer::end_time, sys_time::gps_tow_sync, sys_time::gps_tow_synced, sys_time::gps_unix_sync, sys_time::gps_unix_synced, sys_time::ground_offset, sys_time::ground_synced, sys_time_timer::in_use, sys_time::nb_sec, sys_time::nb_sec_rem, sys_time::nb_tick, sys_time::resolution, sys_time::rtc_sync, shell_add_entry(), sys_time_arch_init(), SYS_TIME_FREQUENCY, SYS_TIME_NB_TIMER, sys_time::ticks_per_sec, sys_time::timer, sys_time::tow_offset, sys_time::unix_offset, and sys_time::unix_synced.
Referenced by mcu_init().
| void sys_time_parse_TIME_SYNC | ( | uint8_t * | buf | ) |
Parse the TIME_SYNC datalink message (ground time).
Definition at line 221 of file sys_time.c.
References get_sys_time_usec(), and sys_time_sync_unix().
| tid_t sys_time_register_timer | ( | float | duration, |
| sys_time_cb | cb ) |
Register a new system timer.
| duration | Duration in seconds until the timer elapses. |
| cb | Callback function that is called from the ISR when timer elapses, or NULL |
Definition at line 172 of file sys_time.c.
References sys_time_timer::cb, sys_time_timer::duration, sys_time_timer::elapsed, sys_time_timer::end_time, sys_time_timer::in_use, sys_time::nb_tick, start_time, SYS_TIME_NB_TIMER, sys_time_ticks_of_sec(), and sys_time::timer.
Referenced by main_ap_init(), main_fbw_init(), main_init(), main_init(), main_init(), main_init(), main_init(), main_recovery_init(), mavlink_mission_set_timer(), and px4flash_init().
| 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.
| timer | timer providing start time and duration |
| offset | offset in seconds beetween the timers (will overlap if longer than duration) |
| cb | Callback function that is called from the ISR when timer elapses, or NULL |
Definition at line 188 of file sys_time.c.
References sys_time_timer::cb, sys_time_timer::duration, sys_time_timer::elapsed, sys_time_timer::end_time, sys_time_timer::in_use, offset, SYS_TIME_NB_TIMER, sys_time_ticks_of_sec(), and sys_time::timer.
Referenced by main_ap_init().
Synchronize the time with a GPS measurement (has priority over the ground).
| week | GPS week, 0 if unknown (only syncs the time of week) |
| tow | GPS time of week in milliseconds |
| stamp | get_sys_time_usec() timestamp at which tow was valid |
Definition at line 120 of file sys_time.c.
References sys_time::gps_tow_sync, sys_time::gps_tow_synced, sys_time::gps_unix_sync, sys_time::gps_unix_synced, msec_of_stamp(), set_tow(), set_unix(), SYS_TIME_GPS_LEAP_MS, SYS_TIME_MSEC_PER_WEEK, and SYS_TIME_UNIX_GPS_EPOCH_MS.
Referenced by gps_cb().
Synchronize the time with the ground, only used without recent GPS sync.
| unix_time | UTC unix time in seconds |
| unix_ms | milliseconds part of the unix time |
| stamp | get_sys_time_usec() timestamp at which the time was valid |
Definition at line 137 of file sys_time.c.
References sys_time::gps_tow_sync, sys_time::gps_tow_synced, sys_time::gps_unix_sync, sys_time::gps_unix_synced, sys_time::ground_offset, sys_time::ground_synced, msec_of_stamp(), offset, set_tow(), set_unix(), SYS_TIME_GPS_LEAP_MS, SYS_TIME_GPS_SYNC_TIMEOUT, SYS_TIME_GROUND_SYNC_THRESHOLD, SYS_TIME_MSEC_PER_WEEK, and SYS_TIME_UNIX_GPS_EPOCH_MS.
Referenced by sys_time_parse_TIME_SYNC().
| void sys_time_update_timer | ( | tid_t | id, |
| float | duration ) |
Update the duration until a timer elapses.
| id | Timer id |
| duration | Duration in seconds until the timer elapses. |
Definition at line 215 of file sys_time.c.
References sys_time_timer::duration, sys_time_timer::end_time, sys_time_ticks_of_sec(), and sys_time::timer.
Referenced by mavlink_mission_set_timer().
|
static |
Milliseconds since startup without the ~49.7 days wrap of get_sys_time_msec() nb_sec gives the number of wraps, get_sys_time_msec() the exact time.
Definition at line 64 of file sys_time.c.
References get_sys_time_msec(), and sys_time::nb_sec.
Referenced by get_sys_time_tow(), get_sys_time_unix_msec(), and msec_of_stamp().
| struct sys_time sys_time |
Definition at line 42 of file sys_time.c.