Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 uint8_t tid_t
 sys_time timer id type More...
 
typedef void(* sys_time_cb )(uint8_t id)
 

Functions

void sys_time_init (void)
 
int 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_t 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.

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

Referenced by sys_time_init().

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

Definition at line 200 of file sys_time.h.

Typedef Documentation

typedef void(* sys_time_cb)(uint8_t id)

Definition at line 58 of file sys_time.h.

typedef uint8_t tid_t

sys_time timer id type

Definition at line 57 of file sys_time.h.

Function Documentation

static uint32_t cpu_ticks_of_nsec ( uint32_t  nsec)
inlinestatic

Definition at line 172 of file sys_time.h.

References sys_time::cpu_ticks_per_sec.

Referenced by ms2100_reset_cb().

+ Here is the caller graph for this function:

static uint32_t cpu_ticks_of_sec ( float  seconds)
inlinestatic

Definition at line 160 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 164 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 float get_sys_time_float ( void  )
inlinestatic

Get the time in seconds since startup.

Returns
current system time as float

Definition at line 123 of file sys_time.h.

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

Referenced by hmc58xx_start_configure(), and imu_aspirin2_configure_mag_slave().

+ Here is the caller graph for this function:

static uint32_t msec_of_cpu_ticks ( uint32_t  cpu_ticks)
inlinestatic

Definition at line 176 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 147 of file sys_time.h.

References sys_time::ticks_per_sec.

Referenced by 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 184 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 143 of file sys_time.h.

References sys_time::resolution.

static int32_t signed_cpu_ticks_of_usec ( int32_t  usec)
inlinestatic

Definition at line 168 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 105 of file sys_time_arch.c.

References _VIC_ADDR, _VIC_CNTL, AHB_CLK, sys_time::cpu_ticks_per_sec, PCLK, sys_time::resolution, sys_time::resolution_cpu_ticks, sys_tick_handler(), T0CCR, T0EMR, T0MCR, T0MR0, T0PR, T0TCR, TCR_ENABLE, TCR_RESET, TIMER0_ISR(), TIMER0_VIC_SLOT, TMCR_MR0_I, USEC_OF_SEC, 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 54 of file sys_time.c.

References sys_time_timer::cb, sys_time_timer::duration, sys_time_timer::elapsed, sys_time_timer::end_time, FALSE, sys_time_timer::in_use, and sys_time::timer.

static bool_t 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 111 of file sys_time.h.

References sys_time_timer::elapsed, FALSE, sys_time::timer, and TRUE.

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

+ Here is the caller graph for this function:

void sys_time_init ( void  )
int 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 37 of file sys_time.c.

References sys_time_timer::cb, sys_time_timer::duration, sys_time_timer::elapsed, sys_time_timer::end_time, FALSE, sys_time_timer::in_use, sys_time::nb_tick, start_time, SYS_TIME_NB_TIMER, sys_time_ticks_of_sec(), sys_time::timer, and TRUE.

Referenced by init_ap(), init_fbw(), main(), and main_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 135 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 131 of file sys_time.h.

References sys_time::ticks_per_sec.

Referenced by 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 139 of file sys_time.h.

References sys_time::ticks_per_sec.

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

+ Here is the call graph for this function:

static uint32_t usec_of_cpu_ticks ( uint32_t  cpu_ticks)
inlinestatic

Definition at line 180 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 151 of file sys_time.h.

References sys_time::ticks_per_sec.

Variable Documentation

Definition at line 35 of file sys_time.c.