NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
High Resolution Timers

Macros

#define CPUTIME_LT(__t1, __t2)   ((int32_t) ((__t1) - (__t2)) < 0)
 
#define CPUTIME_GT(__t1, __t2)   ((int32_t) ((__t1) - (__t2)) > 0)
 
#define CPUTIME_GEQ(__t1, __t2)   ((int32_t) ((__t1) - (__t2)) >= 0)
 
#define CPUTIME_LEQ(__t1, __t2)   ((int32_t) ((__t1) - (__t2)) <= 0)
 

Functions

int os_cputime_init (uint32_t clock_freq)
 
uint32_t os_cputime_get32 (void)
 
uint32_t os_cputime_nsecs_to_ticks (uint32_t nsecs)
 
uint32_t os_cputime_ticks_to_nsecs (uint32_t ticks)
 
void os_cputime_delay_nsecs (uint32_t nsecs)
 
uint32_t os_cputime_usecs_to_ticks (uint32_t usecs)
 
uint32_t os_cputime_ticks_to_usecs (uint32_t ticks)
 
void os_cputime_delay_ticks (uint32_t ticks)
 
void os_cputime_delay_usecs (uint32_t usecs)
 
void os_cputime_timer_init (struct hal_timer *timer, hal_timer_cb fp, void *arg)
 
int os_cputime_timer_start (struct hal_timer *timer, uint32_t cputime)
 
int os_cputime_timer_relative (struct hal_timer *timer, uint32_t usecs)
 
void os_cputime_timer_stop (struct hal_timer *timer)
 

Detailed Description

Macro Definition Documentation

◆ CPUTIME_GEQ

#define CPUTIME_GEQ (   __t1,
  __t2 
)    ((int32_t) ((__t1) - (__t2)) >= 0)

evaluates to true if t1 is on or after t2 in time

◆ CPUTIME_GT

#define CPUTIME_GT (   __t1,
  __t2 
)    ((int32_t) ((__t1) - (__t2)) > 0)

evaluates to true if t1 is after t2 in time

◆ CPUTIME_LEQ

#define CPUTIME_LEQ (   __t1,
  __t2 
)    ((int32_t) ((__t1) - (__t2)) <= 0)

evaluates to true if t1 is on or before t2 in time

◆ CPUTIME_LT

#define CPUTIME_LT (   __t1,
  __t2 
)    ((int32_t) ((__t1) - (__t2)) < 0)

evaluates to true if t1 is before t2 in time

Function Documentation

◆ os_cputime_delay_nsecs()

void os_cputime_delay_nsecs ( uint32_t  nsecs)

Wait until 'nsecs' nanoseconds has elapsed. This is a blocking delay. Not defined if OS_CPUTIME_FREQ_PWR2 is defined.

Parameters
nsecsThe number of nanoseconds to wait.

◆ os_cputime_delay_ticks()

void os_cputime_delay_ticks ( uint32_t  ticks)

Wait until the number of ticks has elapsed. This is a blocking delay.

Parameters
ticksThe number of ticks to wait.

◆ os_cputime_delay_usecs()

void os_cputime_delay_usecs ( uint32_t  usecs)

Wait until 'usecs' microseconds has elapsed. This is a blocking delay.

Parameters
usecsThe number of usecs to wait.

◆ os_cputime_get32()

uint32_t os_cputime_get32 ( void  )

Returns the low 32 bits of cputime.

Returns
uint32_t The lower 32 bits of cputime

◆ os_cputime_init()

int os_cputime_init ( uint32_t  clock_freq)

Initialize the cputime module. This must be called after os_init is called and before any other timer API are used. This should be called only once and should be called before the hardware timer is used.

Parameters
clock_freqThe desired cputime frequency, in hertz (Hz).
Returns
int 0 on success; -1 on error.

◆ os_cputime_nsecs_to_ticks()

uint32_t os_cputime_nsecs_to_ticks ( uint32_t  nsecs)

Converts the given number of nanoseconds into cputime ticks. Not defined if OS_CPUTIME_FREQ_PWR2 is defined.

Parameters
usecsThe number of nanoseconds to convert to ticks
Returns
uint32_t The number of ticks corresponding to 'nsecs'

◆ os_cputime_ticks_to_nsecs()

uint32_t os_cputime_ticks_to_nsecs ( uint32_t  ticks)

Convert the given number of ticks into nanoseconds. Not defined if OS_CPUTIME_FREQ_PWR2 is defined.

Parameters
ticksThe number of ticks to convert to nanoseconds.
Returns
uint32_t The number of nanoseconds corresponding to 'ticks'

◆ os_cputime_ticks_to_usecs()

uint32_t os_cputime_ticks_to_usecs ( uint32_t  ticks)

Convert the given number of ticks into microseconds.

Parameters
ticksThe number of ticks to convert to microseconds.
Returns
uint32_t The number of microseconds corresponding to 'ticks'

◆ os_cputime_timer_init()

void os_cputime_timer_init ( struct hal_timer timer,
hal_timer_cb  fp,
void *  arg 
)

Initialize a CPU timer, using the given HAL timer.

Parameters
timerThe timer to initialize. Cannot be NULL.
fpThe timer callback function. Cannot be NULL.
argPointer to data object to pass to timer.

◆ os_cputime_timer_relative()

int os_cputime_timer_relative ( struct hal_timer timer,
uint32_t  usecs 
)

Sets a cpu timer that will expire 'usecs' microseconds from the current cputime.

NOTE: This must be called when the timer is stopped.

Parameters
timerPointer to timer. Cannot be NULL.
usecsThe number of usecs from now at which the timer will expire.
Returns
int 0 on success; EINVAL if timer already started or timer struct invalid

◆ os_cputime_timer_start()

int os_cputime_timer_start ( struct hal_timer timer,
uint32_t  cputime 
)

Start a cputimer that will expire at 'cputime'. If cputime has already passed, the timer callback will still be called (at interrupt context).

NOTE: This must be called when the timer is stopped.

Parameters
timerPointer to timer to start. Cannot be NULL.
cputimeThe cputime at which the timer should expire.
Returns
int 0 on success; EINVAL if timer already started or timer struct invalid

◆ os_cputime_timer_stop()

void os_cputime_timer_stop ( struct hal_timer timer)

Stops a cputimer from running. The timer is removed from the timer queue and interrupts are disabled if no timers are left on the queue. Can be called even if timer is not running.

Parameters
timerPointer to cputimer to stop. Cannot be NULL.

◆ os_cputime_usecs_to_ticks()

uint32_t os_cputime_usecs_to_ticks ( uint32_t  usecs)

Converts the given number of microseconds into cputime ticks.

Parameters
usecsThe number of microseconds to convert to ticks
Returns
uint32_t The number of ticks corresponding to 'usecs'