CPU Time

The MyNewt cputime module provides high resolution time and timer support.

Description

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.

Data Structures

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.

List of Functions

The functions available in cputime are:

FunctionDescription
os_cputime_delay_nsecsDelays for a specified number of nanoseconds.
os_cputime_delay_ticksDelays for a specified number of ticks.
os_cputime_delay_usecsDelays for a specified number of microseconds.
os_cputime_get32Gets the current value of the cpu time.
os_cputime_initInitializes the cputime module.
os_cputime_nsecs_to_ticksConverts the specified number of nanoseconds to number of ticks.
os_cputime_ticks_to_nsecsConverts the specified number of ticks to number of nanoseconds.
os_cputime_ticks_to_usecsConverts the specified number of ticks to number of microseconds.
os_cputime_timer_initInitializes a timer.
os_cputime_timer_relativeSets a timer to expire in the specified number of microseconds from the current time.
os_cputime_timer_startSets a timer to expire at the specified cputime.
os_cputime_timer_stopStops a timer from running.
os_cputime_usecs_to_ticksConverts the specified number of microseconds to number of ticks.

List of Macros

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 time
  • CPUTIME_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.