The MyNewt cputime
module provides high resolution time and timer support.
The cputime
API provides high resolution time and timer support. The module must be initialized, using the os_cputime_init()
function, with the clock frequency to use. The module uses the hal_timer
API, defined in hal/hal_timer.h, to access the hardware timers. It uses the hardware timer number specified by the OS_CPUTIME_TIMER_NUM
system configuration setting.
The module uses the following data structures:
uint32_t
to represent cputime
. Only the lower 32 bits of a 64 timer are used.struct hal_timer
to represent a cputime timer.The functions available in cputime are:
Function | Description |
---|---|
os_cputime_delay_nsecs | Delays for a specified number of nanoseconds. |
os_cputime_delay_ticks | Delays for a specified number of ticks. |
os_cputime_delay_usecs | Delays for a specified number of microseconds. |
os_cputime_get32 | Gets the current value of the cpu time. |
os_cputime_init | Initializes the cputime module. |
os_cputime_nsecs_to_ticks | Converts the specified number of nanoseconds to number of ticks. |
os_cputime_ticks_to_nsecs | Converts the specified number of ticks to number of nanoseconds. |
os_cputime_ticks_to_usecs | Converts the specified number of ticks to number of microseconds. |
os_cputime_timer_init | Initializes a timer. |
os_cputime_timer_relative | Sets a timer to expire in the specified number of microseconds from the current time. |
os_cputime_timer_start | Sets a timer to expire at the specified cputime. |
os_cputime_timer_stop | Stops a timer from running. |
os_cputime_usecs_to_ticks | Converts the specified number of microseconds to number of ticks. |
These macros should be used to evaluate the time with respect to each other.
CPUIME_LT(t1,t2)
-- evaluates to true if t1 is before t2 in time.CPUTIME_GT(t1,t2)
-- evaluates to true if t1 is after t2 in timeCPUTIME_LEQ(t1,t2)
-- evaluates to true if t1 is on or before t2 in time.CPUTIME_GEQ(t1,t2)
-- evaluates to true if t1 is on or after t2 in time.