Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
sys_time.h File Reference

Architecture independent timing functions. More...

#include <inttypes.h>
#include <stdlib.h>
#include "std.h"
#include <BOARD_CONFIG>
#include "mcu_periph/sys_time_arch.h"
+ Include dependency graph for sys_time.h:

Go to the source code of this file.

Data Structures

struct  sys_time_timer
 
struct  sys_time
 

Macros

#define SYS_TIME_NB_TIMER   16
 
#define SYS_TIME_FREQUENCY   1000
 (Default) sys_time timer frequency in Hz. More...
 
#define USEC_OF_SEC(sec)   ((sec) * 1e6)
 
#define SysTimeTimerStart(_t)   { _t = get_sys_time_usec(); }
 
#define SysTimeTimer(_t)   ( get_sys_time_usec() - (_t))
 
#define SysTimeTimerStop(_t)   { _t = ( get_sys_time_usec() - (_t)); }
 

Typedefs

typedef int8_t tid_t
 sys_time timer id type More...
 
typedef void(* sys_time_cb) (uint8_t id)
 

Functions

void sys_time_init (void)
 
tid_t sys_time_register_timer (float duration, sys_time_cb cb)
 Register a new system timer. More...
 
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. More...
 
void sys_time_cancel_timer (tid_t id)
 Cancel a system timer by id. More...
 
void sys_time_update_timer (tid_t id, float duration)
 Update the duration until a timer elapses. More...
 
static bool sys_time_check_and_ack_timer (tid_t id)
 Check if timer has elapsed. More...
 
static float get_sys_time_float (void)
 Get the time in seconds since startup. More...
 
static uint32_t sys_time_ticks_of_sec (float seconds)
 
static uint32_t sys_time_ticks_of_msec (uint32_t msec)
 
static uint32_t sys_time_ticks_of_usec (uint32_t usec)
 
static float sec_of_sys_time_ticks (uint32_t ticks)
 
static uint32_t msec_of_sys_time_ticks (uint32_t ticks)
 
static uint32_t usec_of_sys_time_ticks (uint32_t ticks)
 
static uint32_t cpu_ticks_of_sec (float seconds)
 
static uint32_t cpu_ticks_of_usec (uint32_t usec)
 
static int32_t signed_cpu_ticks_of_usec (int32_t usec)
 
static uint32_t cpu_ticks_of_nsec (uint32_t nsec)
 
static uint32_t msec_of_cpu_ticks (uint32_t cpu_ticks)
 
static uint32_t usec_of_cpu_ticks (uint32_t cpu_ticks)
 
static uint32_t nsec_of_cpu_ticks (uint32_t cpu_ticks)
 
void sys_time_arch_init (void)
 Initialize SysTick. More...
 

Variables

struct sys_time sys_time
 

Detailed Description

Architecture independent timing functions.

Definition in file sys_time.h.


Data Structure Documentation

◆ sys_time_timer

struct sys_time_timer

Definition at line 63 of file sys_time.h.

Data Fields
sys_time_cb cb
uint32_t duration in SYS_TIME_TICKS
volatile bool elapsed
uint32_t end_time in SYS_TIME_TICKS
bool in_use

◆ sys_time

struct sys_time

Definition at line 71 of file sys_time.h.

+ Collaboration diagram for sys_time:
Data Fields
uint32_t cpu_ticks_per_sec cpu ticks per second
volatile uint32_t nb_sec full seconds since startup
volatile uint32_t nb_sec_rem remainder of seconds since startup in CPU_TICKS
volatile uint32_t nb_tick SYS_TIME_TICKS since startup.
float resolution sys_time_timer resolution in seconds
uint32_t resolution_cpu_ticks sys_time_timer resolution in cpu ticks
uint32_t ticks_per_sec sys_time ticks per second (SYS_TIME_FREQUENCY)
struct sys_time_timer timer[SYS_TIME_NB_TIMER]

Macro Definition Documentation

◆ SYS_TIME_FREQUENCY

#define SYS_TIME_FREQUENCY   1000

(Default) sys_time timer frequency in Hz.

sys_time.resolution is set from this define.

Definition at line 56 of file sys_time.h.

◆ SYS_TIME_NB_TIMER

#define SYS_TIME_NB_TIMER   16

Definition at line 44 of file sys_time.h.

◆ SysTimeTimer

#define SysTimeTimer (   _t)    ( get_sys_time_usec() - (_t))

Definition at line 228 of file sys_time.h.

◆ SysTimeTimerStart

#define SysTimeTimerStart (   _t)    { _t = get_sys_time_usec(); }

Definition at line 227 of file sys_time.h.

◆ SysTimeTimerStop

#define SysTimeTimerStop (   _t)    { _t = ( get_sys_time_usec() - (_t)); }

Definition at line 229 of file sys_time.h.

◆ USEC_OF_SEC

#define USEC_OF_SEC (   sec)    ((sec) * 1e6)

Definition at line 219 of file sys_time.h.

Typedef Documentation

◆ sys_time_cb

typedef void(* sys_time_cb) (uint8_t id)

Definition at line 61 of file sys_time.h.

◆ tid_t

typedef int8_t tid_t

sys_time timer id type

Definition at line 60 of file sys_time.h.

Function Documentation

◆ cpu_ticks_of_nsec()

static uint32_t cpu_ticks_of_nsec ( uint32_t  nsec)
inlinestatic

Definition at line 197 of file sys_time.h.

References sys_time::cpu_ticks_per_sec.

Referenced by ms2100_reset_cb(), and sys_tick_handler().

+ Here is the caller graph for this function:

◆ cpu_ticks_of_sec()

static uint32_t cpu_ticks_of_sec ( float  seconds)
inlinestatic

Definition at line 182 of file sys_time.h.

References sys_time::cpu_ticks_per_sec.

Referenced by sys_tick_handler().

+ Here is the caller graph for this function:

◆ cpu_ticks_of_usec()

static uint32_t cpu_ticks_of_usec ( uint32_t  usec)
inlinestatic

Definition at line 187 of file sys_time.h.

References sys_time::cpu_ticks_per_sec.

Referenced by sys_time_usleep(), and xtend_rssi_periodic().

+ Here is the caller graph for this function:

◆ get_sys_time_float()

static float get_sys_time_float ( void  )
inlinestatic

Get the time in seconds since startup.

Returns
current system time as float with sys_time.resolution

Definition at line 138 of file sys_time.h.

References sys_time::cpu_ticks_per_sec, sys_time::nb_sec, and sys_time::nb_sec_rem.

Referenced by accel_sp_cb(), actuators_faulhaber_periodic(), actuators_uavcan_esc_status_cb(), agl_cb(), agl_dist_init(), airspeed_cb(), autopilot_arming_check_motors_on(), autopilot_arming_set(), baro_cb(), cc2500_delayMicroseconds(), check_anchor_timeout(), chirp_call(), ctrl_module_run(), dc_periodic(), ekf_run(), fill_anchor(), gps_cb(), gps_fix_valid(), gyro_cb(), hmc58xx_start_configure(), i2c_blocking_receive(), i2c_blocking_transceive(), i2c_blocking_transmit(), imu_aspirin2_configure_mag_slave(), imu_mpu9250_configure_mag_slave(), incidence_cb(), ins_flow_init(), ins_flow_update(), logger_control_effectiveness_periodic(), logger_file_write_row(), mag_cb(), nav_rosette_setup(), optical_flow_landing_init(), periodic_report_sysmon(), periodic_sys_id_auto_doublets(), pfc_actuators_run(), PID_divergence_control(), preflight_check(), pressure_diff_cb(), px4flow_i2c_downlink(), px4flow_i2c_frame_cb(), read_rc_setpoint_heading(), reset_all_vars(), reset_horizontal_vars(), reset_vertical_vars(), rotwing_state_feedback_cb(), rotwing_state_hover_motors_idling(), rotwing_state_hover_motors_running(), rotwing_state_periodic(), rotwing_state_pusher_motor_running(), rotwing_state_skew_angle_valid(), rpm_cb(), spi_blocking_transceive(), start_chirp(), start_doublet(), start_wave(), stop_chirp(), stop_doublet(), stop_wave(), sys_id_auto_doublets_on_activation(), sys_id_chirp_activate_handler(), sys_id_chirp_init(), sys_id_chirp_run(), sys_id_doublet_activate_handler(), sys_id_doublet_init(), sys_id_doublet_run(), sys_id_wave_activate_handler(), sys_id_wave_frequency_hz_set(), sys_id_wave_init(), sys_id_wave_lag_rad_set(), sys_id_wave_run(), vel_sp_cb(), vertical_ctrl_module_run(), and vertical_ctrl_optical_flow_cb().

◆ msec_of_cpu_ticks()

static uint32_t msec_of_cpu_ticks ( uint32_t  cpu_ticks)
inlinestatic

Definition at line 202 of file sys_time.h.

References cpu_ticks, and sys_time::cpu_ticks_per_sec.

Referenced by get_sys_time_msec().

+ Here is the caller graph for this function:

◆ msec_of_sys_time_ticks()

static uint32_t msec_of_sys_time_ticks ( uint32_t  ticks)
inlinestatic

Definition at line 167 of file sys_time.h.

References ticks, and sys_time::ticks_per_sec.

Referenced by gps_tow_from_sys_ticks(), and windturbine_periodic().

+ Here is the caller graph for this function:

◆ nsec_of_cpu_ticks()

static uint32_t nsec_of_cpu_ticks ( uint32_t  cpu_ticks)
inlinestatic

Definition at line 212 of file sys_time.h.

References cpu_ticks, and sys_time::cpu_ticks_per_sec.

◆ sec_of_sys_time_ticks()

static float sec_of_sys_time_ticks ( uint32_t  ticks)
inlinestatic

Definition at line 162 of file sys_time.h.

References sys_time::resolution, and ticks.

◆ signed_cpu_ticks_of_usec()

static int32_t signed_cpu_ticks_of_usec ( int32_t  usec)
inlinestatic

Definition at line 192 of file sys_time.h.

References sys_time::cpu_ticks_per_sec.

◆ sys_time_arch_init()

void sys_time_arch_init ( void  )

Initialize SysTick.

Generate SysTick interrupt every sys_time.resolution_cpu_ticks

Definition at line 52 of file sys_time_arch.c.

References AHB_CLK, CH_CFG_ST_FREQUENCY, sys_time::cpu_ticks_per_sec, sys_time::resolution, sys_time::resolution_cpu_ticks, startup_time, sys_time_thread_main(), and thd_sys_tick().

Referenced by sys_time_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sys_time_cancel_timer()

void sys_time_cancel_timer ( tid_t  id)

Cancel a system timer by id.

Parameters
idTimer id.

Definition at line 76 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().

+ Here is the caller graph for this function:

◆ sys_time_check_and_ack_timer()

static bool sys_time_check_and_ack_timer ( tid_t  id)
inlinestatic

Check if timer has elapsed.

Parameters
idTimer id
Returns
TRUE if timer has elapsed

Definition at line 123 of file sys_time.h.

References sys_time_timer::elapsed, SYS_TIME_NB_TIMER, and sys_time::timer.

Referenced by main(), main_ap_periodic(), main_fbw_periodic(), main_recovery_periodic(), mavlink_mission_periodic(), and px4flash_event().

+ Here is the caller graph for this function:

◆ sys_time_init()

◆ sys_time_register_timer()

tid_t sys_time_register_timer ( float  duration,
sys_time_cb  cb 
)

Register a new system timer.

Parameters
durationDuration in seconds until the timer elapses.
cbCallback function that is called from the ISR when timer elapses, or NULL
Returns
-1 if it failed, the timer id otherwise

Definition at line 43 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 intermcu_init(), main(), main_ap_init(), main_fbw_init(), main_init(), main_recovery_init(), mavlink_mission_set_timer(), and px4flash_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sys_time_register_timer_offset()

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.

Parameters
timertimer providing start time and duration
offsetoffset in seconds beetween the timers (will overlap if longer than duration)
cbCallback function that is called from the ISR when timer elapses, or NULL
Returns
-1 if it failed, the timer id otherwise

Definition at line 59 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sys_time_ticks_of_msec()

static uint32_t sys_time_ticks_of_msec ( uint32_t  msec)
inlinestatic

Definition at line 152 of file sys_time.h.

References sys_time::ticks_per_sec.

◆ sys_time_ticks_of_sec()

static uint32_t sys_time_ticks_of_sec ( float  seconds)
inlinestatic

Definition at line 147 of file sys_time.h.

References sys_time::ticks_per_sec.

Referenced by sys_tick_handler(), sys_time_register_timer(), sys_time_register_timer_offset(), and sys_time_update_timer().

+ Here is the caller graph for this function:

◆ sys_time_ticks_of_usec()

static uint32_t sys_time_ticks_of_usec ( uint32_t  usec)
inlinestatic

Definition at line 157 of file sys_time.h.

References sys_time::ticks_per_sec.

Referenced by sys_tick_handler().

+ Here is the caller graph for this function:

◆ sys_time_update_timer()

void sys_time_update_timer ( tid_t  id,
float  duration 
)

Update the duration until a timer elapses.

Parameters
idTimer id
durationDuration in seconds until the timer elapses.

Definition at line 86 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ usec_of_cpu_ticks()

static uint32_t usec_of_cpu_ticks ( uint32_t  cpu_ticks)
inlinestatic

Definition at line 207 of file sys_time.h.

References cpu_ticks, and sys_time::cpu_ticks_per_sec.

Referenced by get_sys_time_usec(), get_sys_time_usec100(), and sys_time_usleep().

+ Here is the caller graph for this function:

◆ usec_of_sys_time_ticks()

static uint32_t usec_of_sys_time_ticks ( uint32_t  ticks)
inlinestatic

Definition at line 172 of file sys_time.h.

References ticks, and sys_time::ticks_per_sec.

Variable Documentation

◆ sys_time

struct sys_time sys_time
extern

Definition at line 1 of file sys_time.c.