Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sys_time.h File Reference

Architecture independent timing functions. More...

#include <inttypes.h>
#include <stdlib.h>
#include "std.h"
#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   8
 
#define cpu_time_sec   sys_time.nb_sec
 
#define cpu_time_ticks   sys_time.nb_sec_rem
 
#define GET_CUR_TIME_FLOAT()   ((float)sys_time.nb_sec + SEC_OF_CPU_TICKS((float)sys_time.nb_sec_rem))
 
#define CPU_TICKS_OF_USEC(us)   CPU_TICKS_OF_SEC((us) * 1e-6)
 
#define CPU_TICKS_OF_NSEC(ns)   CPU_TICKS_OF_SEC((ns) * 1e-9)
 
#define SIGNED_CPU_TICKS_OF_USEC(us)   SIGNED_CPU_TICKS_OF_SEC((us) * 1e-6)
 
#define SIGNED_CPU_TICKS_OF_NSEC(us)   SIGNED_CPU_TICKS_OF_SEC((us) * 1e-9)
 
#define CPU_TICKS_PER_SEC   CPU_TICKS_OF_SEC( 1.)
 
#define SYS_TIME_RESOLUTION   ( 1./1024. )
 
#define SYS_TIME_RESOLUTION_CPU_TICKS   CPU_TICKS_OF_SEC(SYS_TIME_RESOLUTION)
 
#define SYS_TIME_TICKS_OF_SEC(s)   (uint32_t)((s) / SYS_TIME_RESOLUTION + 0.5)
 
#define SYS_TIME_TICKS_OF_USEC(us)   SYS_TIME_TICKS_OF_SEC((us) * 1e-6)
 
#define SYS_TIME_TICKS_OF_NSEC(ns)   SYS_TIME_TICKS_OF_SEC((ns) * 1e-9)
 
#define SEC_OF_SYS_TIME_TICKS(t)   ((t) * SYS_TIME_RESOLUTION)
 
#define USEC_OF_SYS_TIME_TICKS(t)   ((t) * SYS_TIME_RESOLUTION / 1e-6)
 
#define NSEC_OF_SYS_TIME_TICKS(t)   ((t) * SYS_TIME_RESOLUTION / 1e-9)
 
#define USEC_OF_SEC(sec)   ((sec) * 1e6)
 

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)
 
void sys_time_arch_init (void)
 

Variables

struct sys_time sys_time
 

Detailed Description

Architecture independent timing functions.

Definition in file sys_time.h.

Macro Definition Documentation

#define CPU_TICKS_OF_NSEC (   ns)    CPU_TICKS_OF_SEC((ns) * 1e-9)

Definition at line 103 of file sys_time.h.

#define CPU_TICKS_OF_USEC (   us)    CPU_TICKS_OF_SEC((us) * 1e-6)

Definition at line 102 of file sys_time.h.

Referenced by sys_time_usleep(), and xtend_rssi_periodic().

#define CPU_TICKS_PER_SEC   CPU_TICKS_OF_SEC( 1.)

Definition at line 107 of file sys_time.h.

Referenced by sys_tick_handler(), and sys_tick_irq_handler().

#define cpu_time_ticks   sys_time.nb_sec_rem

Definition at line 65 of file sys_time.h.

#define GET_CUR_TIME_FLOAT ( )    ((float)sys_time.nb_sec + SEC_OF_CPU_TICKS((float)sys_time.nb_sec_rem))

Definition at line 98 of file sys_time.h.

#define NSEC_OF_SYS_TIME_TICKS (   t)    ((t) * SYS_TIME_RESOLUTION / 1e-9)

Definition at line 122 of file sys_time.h.

#define SEC_OF_SYS_TIME_TICKS (   t)    ((t) * SYS_TIME_RESOLUTION)

Definition at line 120 of file sys_time.h.

#define SIGNED_CPU_TICKS_OF_NSEC (   us)    SIGNED_CPU_TICKS_OF_SEC((us) * 1e-9)

Definition at line 105 of file sys_time.h.

#define SIGNED_CPU_TICKS_OF_USEC (   us)    SIGNED_CPU_TICKS_OF_SEC((us) * 1e-6)

Definition at line 104 of file sys_time.h.

#define SYS_TIME_NB_TIMER   8
#define SYS_TIME_RESOLUTION   ( 1./1024. )

Definition at line 112 of file sys_time.h.

#define SYS_TIME_RESOLUTION_CPU_TICKS   CPU_TICKS_OF_SEC(SYS_TIME_RESOLUTION)

Definition at line 114 of file sys_time.h.

Referenced by sys_tick_handler(), sys_tick_irq_handler(), and sys_time_arch_init().

#define SYS_TIME_TICKS_OF_NSEC (   ns)    SYS_TIME_TICKS_OF_SEC((ns) * 1e-9)

Definition at line 118 of file sys_time.h.

#define SYS_TIME_TICKS_OF_SEC (   s)    (uint32_t)((s) / SYS_TIME_RESOLUTION + 0.5)

Definition at line 116 of file sys_time.h.

Referenced by sys_time_register_timer(), and sys_time_update_timer().

#define SYS_TIME_TICKS_OF_USEC (   us)    SYS_TIME_TICKS_OF_SEC((us) * 1e-6)

Definition at line 117 of file sys_time.h.

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

Definition at line 124 of file sys_time.h.

Referenced by actuators_set().

#define USEC_OF_SYS_TIME_TICKS (   t)    ((t) * SYS_TIME_RESOLUTION / 1e-6)

Definition at line 121 of file sys_time.h.

Typedef Documentation

typedef void(* sys_time_cb)(uint8_t id)

Definition at line 44 of file sys_time.h.

typedef uint8_t tid_t

sys_time timer id type

Definition at line 43 of file sys_time.h.

Function Documentation

void sys_time_arch_init ( void  )

Definition at line 96 of file sys_time_arch.c.

References _VIC_ADDR, _VIC_CNTL, SYS_TIME_RESOLUTION_CPU_TICKS, T0CCR, T0EMR, T0MCR, T0MR0, T0PR, T0TCR, TCR_ENABLE, TCR_RESET, 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 51 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

Definition at line 90 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  )

Definition at line 69 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_sec, sys_time::nb_sec_rem, sys_time::nb_tick, sys_time_arch_init(), SYS_TIME_NB_TIMER, and sys_time::timer.

Referenced by main(), and mcu_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 35 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, 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 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 62 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.

Variable Documentation

Definition at line 33 of file sys_time.c.