Cycle Counter#
Provides an interface to the cycle counter of the DWT unit.
Initialization#
The cycle counter must be enabled prior to any call to its API. If sl_system is used, only sl_system_init() must be called, otherwise sl_cycle_counter_enable() must be called manually.
Limitations#
The cycle counter is stored in an unsigned 32-bit integer. As the counter frequently rolls over, timing durations should be kept short.
Usage Notes#
When entering sleep in Energy Mode 1 (EM1), the DWT cycle counter continues to increment. The cycle counter is used by the emlib CORE component to measure the interrupt maximum disable time, when this feature is enabled. Since the power manager must enter sleep with PRIMASK set to 1, it will pause the cycle counter before entering EM1 and resume it on wakeup, in order to provide a realistic interrupt disable time. If this behaviour is not desired, the maximum interrupt disable feature must be disabled in the CORE component.
Usage example#
#include "sl_cycle_counter.h"
void main(void)
{
sl_cycle_counter_handle_t counter;
// Enable the cycle counter; not needed if sl_system_init() is used.
sl_cycle_counter_enable();
status = sl_cycle_counter_init(&counter);
if (status != SL_STATUS_OK) {
// handle error
}
sl_cycle_counter_start(&counter);
function_to_measure();
sl_cycle_counter_stop(&counter);
printf("Timing: %lu\r\n", sl_cycle_counter_get_cycles(&counter));
}
Modules#
Functions#
Enable cycle counter.
Pause cycle counter.
Resume cycle counter.
Initialize the cycle counter handle.
Start recording.
Stop recording.
Reset the cycle counter handle.
Read the last recording duration.
Read the max recording duration.
Read the current value of the cycle counter.
Function Documentation#
sl_cycle_counter_enable#
void sl_cycle_counter_enable (void )
Enable cycle counter.
N/A |
115
of file platform/driver/cycle_counter/inc/sl_cycle_counter.h
sl_cycle_counter_pause#
void sl_cycle_counter_pause (void )
Pause cycle counter.
N/A |
Note
this function pauses the DWT cycle counter
122
of file platform/driver/cycle_counter/inc/sl_cycle_counter.h
sl_cycle_counter_resume#
void sl_cycle_counter_resume (void )
Resume cycle counter.
N/A |
Note
this function resumes the DWT cycle counter
132
of file platform/driver/cycle_counter/inc/sl_cycle_counter.h
sl_cycle_counter_init#
sl_status_t sl_cycle_counter_init (sl_cycle_counter_handle_t * handle)
Initialize the cycle counter handle.
N/A | handle | Pointer to counter handle to initialize. |
Returns
SL_STATUS_OK if successful. Error code otherwise.
Initialize the cycle counter handle.
144
of file platform/driver/cycle_counter/inc/sl_cycle_counter.h
sl_cycle_counter_start#
void sl_cycle_counter_start (sl_cycle_counter_handle_t * handle)
Start recording.
N/A | handle | Pointer to initialized counter handle. |
Start recording.
152
of file platform/driver/cycle_counter/inc/sl_cycle_counter.h
sl_cycle_counter_stop#
void sl_cycle_counter_stop (sl_cycle_counter_handle_t * handle)
Stop recording.
N/A | handle | Pointer to initialized counter handle. |
Stop recording.
160
of file platform/driver/cycle_counter/inc/sl_cycle_counter.h
sl_cycle_counter_reset#
sl_status_t sl_cycle_counter_reset (sl_cycle_counter_handle_t * handle)
Reset the cycle counter handle.
N/A | handle | Pointer to initialized counter handle. |
Returns
SL_STATUS_OK if successful. Error code otherwise.
Reset the cycle counter handle.
169
of file platform/driver/cycle_counter/inc/sl_cycle_counter.h
sl_cycle_counter_get_cycles#
uint32_t sl_cycle_counter_get_cycles (sl_cycle_counter_handle_t * handle)
Read the last recording duration.
N/A | handle | Pointer to initialized counter handle. |
Returns
cycles elapsed in last recording.
Read the last recording duration.
178
of file platform/driver/cycle_counter/inc/sl_cycle_counter.h
sl_cycle_counter_get_max#
uint32_t sl_cycle_counter_get_max (sl_cycle_counter_handle_t * handle)
Read the max recording duration.
N/A | handle | Pointer to initialized counter handle. |
Returns
max cycles elapsed in recordings.
Read the max recording duration.
187
of file platform/driver/cycle_counter/inc/sl_cycle_counter.h
sl_cycle_counter_get_counter#
uint32_t sl_cycle_counter_get_counter (void )
Read the current value of the cycle counter.
N/A |
Returns
cycle counter value.
194
of file platform/driver/cycle_counter/inc/sl_cycle_counter.h