Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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...
 
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

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
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

#define SYS_TIME_FREQUENCY   1000

(Default) sys_time timer frequency in Hz.

sys_time.resolution is set from this define.

Definition at line 55 of file sys_time.h.

Referenced by sys_time_init().

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

Definition at line 220 of file sys_time.h.

Typedef Documentation

typedef void(* sys_time_cb)(uint8_t id)

Definition at line 61 of file sys_time.h.

typedef int8_t tid_t

sys_time timer id type

Definition at line 60 of file sys_time.h.

Function Documentation

static uint32_t cpu_ticks_of_nsec ( uint32_t  nsec)
inlinestatic

Definition at line 188 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:

static uint32_t cpu_ticks_of_sec ( float  seconds)
inlinestatic

Definition at line 173 of file sys_time.h.

References sys_time::cpu_ticks_per_sec.

static uint32_t cpu_ticks_of_usec ( uint32_t  usec)
inlinestatic

Definition at line 178 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:

static uint32_t msec_of_cpu_ticks ( uint32_t  cpu_ticks)
inlinestatic

Definition at line 193 of file sys_time.h.

References sys_time::cpu_ticks_per_sec.

Referenced by get_sys_time_msec(), and TRIG_ISR().

+ Here is the caller graph for this function:

static uint32_t msec_of_sys_time_ticks ( uint32_t  ticks)
inlinestatic

Definition at line 158 of file sys_time.h.

References sys_time::ticks_per_sec.

Referenced by get_sys_time_msec(), gps_tow_from_sys_ticks(), trigger_ext_periodic(), and windturbine_periodic().

+ Here is the caller graph for this function:

static uint32_t nsec_of_cpu_ticks ( uint32_t  cpu_ticks)
inlinestatic

Definition at line 203 of file sys_time.h.

References sys_time::cpu_ticks_per_sec.

static float sec_of_sys_time_ticks ( uint32_t  ticks)
inlinestatic

Definition at line 153 of file sys_time.h.

References sys_time::resolution.

static int32_t signed_cpu_ticks_of_usec ( int32_t  usec)
inlinestatic

Definition at line 183 of file sys_time.h.

References sys_time::cpu_ticks_per_sec.

void sys_time_arch_init ( void  )

Initialize SysTick.

Generate SysTick interrupt every sys_time.resolution_cpu_ticks

Definition at line 49 of file sys_time_arch.c.

References _VIC_ADDR, _VIC_CNTL, AHB_CLK, CH_CFG_ST_FREQUENCY, sys_time::cpu_ticks_per_sec, PCLK, sys_time::resolution, sys_time::resolution_cpu_ticks, startup_time, sys_time_thread, sys_time_thread_main(), T0CCR, T0EMR, T0MCR, T0MR0, T0PR, T0TCR, TCR_ENABLE, TCR_RESET, thd_sys_tick(), TIMER0_ISR(), TIMER0_VIC_SLOT, TMCR_MR0_I, VIC_BIT, VIC_ENABLE, VIC_TIMER0, VICIntEnable, and VICIntSelect.

Referenced by sys_time_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void sys_time_cancel_timer ( tid_t  id)

Cancel a system timer by id.

Parameters
idTimer id.

Definition at line 60 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:

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 114 of file sys_time.h.

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

Referenced by handle_periodic_tasks(), handle_periodic_tasks_ap(), handle_periodic_tasks_fbw(), main(), mavlink_mission_periodic(), and px4flash_event().

+ Here is the caller graph for this function:

void sys_time_init ( void  )
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 init_ap(), init_fbw(), intermcu_init(), main(), main_init(), mavlink_mission_set_timer(), px4flash_event(), and px4flash_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static uint32_t sys_time_ticks_of_msec ( uint32_t  msec)
inlinestatic

Definition at line 143 of file sys_time.h.

References sys_time::ticks_per_sec.

static uint32_t sys_time_ticks_of_sec ( float  seconds)
inlinestatic

Definition at line 138 of file sys_time.h.

References sys_time::ticks_per_sec.

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

+ Here is the caller graph for this function:

static uint32_t sys_time_ticks_of_usec ( uint32_t  usec)
inlinestatic

Definition at line 148 of file sys_time.h.

References sys_time::ticks_per_sec.

Referenced by sys_tick_handler().

+ Here is the caller graph for this function:

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 70 of file sys_time.c.

References sys_time_timer::duration, sys_time_timer::end_time, mcu_int_disable, mcu_int_enable, 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:

static uint32_t usec_of_cpu_ticks ( uint32_t  cpu_ticks)
inlinestatic

Definition at line 198 of file sys_time.h.

References sys_time::cpu_ticks_per_sec.

Referenced by get_sys_time_usec(), and sys_time_usleep().

+ Here is the caller graph for this function:

static uint32_t usec_of_sys_time_ticks ( uint32_t  ticks)
inlinestatic

Definition at line 163 of file sys_time.h.

References sys_time::ticks_per_sec.

Referenced by get_sys_time_usec().

+ Here is the caller graph for this function:

Variable Documentation

Definition at line 41 of file sys_time.c.