Deals with busy delays, elapsed time and accumulated time.
More...
#include <longan_nano_chrono.hpp>
|
static unsigned int | get_systick_freq (void) |
| public static method get_systick_freq | void More...
|
|
static bool | delay (Unit unit, unsigned int delay_tmp) |
| public static method delay | Unit | unsigned int | More...
|
|
Deals with busy delays, elapsed time and accumulated time.
- Author
- Orso Eric
- Version
- 2020-08-08
- Bug:
- None
- Copyright
- BSD 3-Clause License Copyright (c) 2020, Orso Eric
SysTick
Use 64b 27MHz SysTick timer.
History Version
2020-07-20
Rework Utils library into Chrono library to add start/stop timer
"start" snaps the start timestamp at full resolution
"stop" snaps the stop timestamp at full resolution
"elapsed" returns the elapsed time between stop and start if valid. zero otherwise
2020-07-28
I need a method to accumulate execution time and profile how long an activity has taken
"accumulate" add stop-start to an internal accumulator at full resolution
Add combined "stop" "elapsed" implementation with better performance and fewer calls needed
I can combine the stop and accumulator counters since i use one or the other
I use a flag to handle initialization and invalid when switching between modes and automatically reset the accumulator
2020-08-04
Refactor to separate header and implementation
◆ Config
Configurations of the SysTick.
◆ Unit
Possible time units. Same names as std::Chrono.
◆ _Config
Configurations of the SysTick.
Enumerator |
---|
PEDANTIC_CHECKS | |
SYSTICK_INVALID | |
SYSTICK_PRE | |
TIME_INVALID | |
◆ _Unit
Possible time units. Same names as std::Chrono.
Enumerator |
---|
milliseconds | |
microseconds | |
◆ Chrono()
Longan_nano::Chrono::Chrono |
( |
void |
| ) |
|
Empty Constructor Chrono | void.
- Returns
- void
Initialize timestamps to invalid
◆ ~Chrono()
Longan_nano::Chrono::~Chrono |
( |
void |
| ) |
|
Empty Destructor.
~Chrono | void
- Returns
- void
◆ accumulate() [1/2]
int32_t Longan_nano::Chrono::accumulate |
( |
Unit |
unit | ) |
|
public method accumulate | Unit unit |
- Parameters
-
unit | | Unit | result is given in this time unit |
- Returns
- unsigned int | frequency of the SysTick timer
Snap the stop time
Accumulate the difference between stop and start inside the accumulator
Swap the stop and start, invalidate the stop. Prepare for next cycle
◆ accumulate() [2/2]
bool Longan_nano::Chrono::accumulate |
( |
void |
| ) |
|
public method accumulate | void |
- Returns
- unsigned int | frequency of the SysTick timer
Snap the stop time
Accumulate the difference between stop and start inside the accumulator
Swap the stop and start, invalidate the stop. Prepare for next cycle
Use stop counter as accumulator
If timer was in timer mode, reset the accumulator
◆ compute_accumulator()
int32_t Longan_nano::Chrono::compute_accumulator |
( |
uint64_t |
accumulator, |
|
|
Unit |
unit |
|
) |
| |
|
private |
private method compute_accumulator | uint64_t | Unit |
- Parameters
-
accumulator | | uint64_t | timestamp DeltaT |
unit | | Unit | result is given in this time unit |
- Returns
- int32_t | negative = invalid | zero or positive = elapsed time in the given time unit
use start and stop timestamp to compute the elapsed time in a given time unit
◆ compute_elapsed()
int32_t Longan_nano::Chrono::compute_elapsed |
( |
uint64_t |
start, |
|
|
uint64_t |
stop, |
|
|
Unit |
unit |
|
) |
| |
|
inlineprivate |
private method compute_elapsed | uint64_t | uint64_t | Unit |
- Parameters
-
start | | uint64_t | timestamp |
stop | | uint64_t | timestamp |
unit | | Unit | result is given in this time unit |
- Returns
- int32_t | negative = invalid | zero or positive = elapsed time in the given time unit
use start and stop timestamp to compute the elapsed time in a given time unit
◆ compute_tick_per_time_unit()
uint32_t Longan_nano::Chrono::compute_tick_per_time_unit |
( |
Unit |
unit | ) |
|
|
inlinestaticprivate |
private method compute_tick_per_time_unit | Unit |
- Parameters
-
unit | | Unit | result is given in this time unit |
- Returns
- uint32_t | number of systick counts needed to count one time unit
Compute the number of systick counts needed to count one time unit
◆ delay()
bool Longan_nano::Chrono::delay |
( |
Unit |
unit, |
|
|
unsigned int |
delay_tmp |
|
) |
| |
|
static |
public static method delay | Unit | unsigned int |
- Parameters
-
unit | | Unit | timeunit of the delay |
delay_tmp | | unsigned int | how long to wait for |
- Returns
- bool | false = OK | true = fail
Use the SysTick timer counter to busy wait for the correct number of microseconds
The CPU SysTick timer is clocked by the ABH clock/4 = 27MHz
SystemCoreClock defines the frequency of the CPU in Hz
◆ get_accumulator()
int32_t Longan_nano::Chrono::get_accumulator |
( |
Unit |
unit | ) |
|
|
inline |
public getter get_accumulator | Unit |
- Parameters
-
unit | | Unit | result is given in this time unit |
- Returns
- int | accumulators. negative mean the timer was uninitialized
return the DeltaT accumulated by the accumulate function in the given time unit
◆ get_elapsed()
int32_t Longan_nano::Chrono::get_elapsed |
( |
Unit |
unit | ) |
|
public getter get_elapsed | Unit |
- Parameters
-
unit | | Unit | result is given in this time unit |
- Returns
- int | elapsed time. negative mean the timer was uninitialized
Time elapsed between start and stop
◆ get_systick_freq()
unsigned int Longan_nano::Chrono::get_systick_freq |
( |
void |
| ) |
|
|
static |
public static method get_systick_freq | void
- Returns
- unsigned int | frequency of the SysTick timer
The SysTick timer is tied to the CPU clock prescaled by four
◆ restart()
void Longan_nano::Chrono::restart |
( |
void |
| ) |
|
public method start | void
- Returns
- void
Start the timer and invalidate the stop time and accumulator
◆ start()
void Longan_nano::Chrono::start |
( |
void |
| ) |
|
public method start | void
- Returns
- void
Start the timer
◆ stop() [1/2]
int32_t Longan_nano::Chrono::stop |
( |
Unit |
unit | ) |
|
public method stop | Unit |
- Parameters
-
unit | | Unit | result is given in this time unit |
- Returns
- void
Stop the timer. Snap the stop time
Return the elapsed time between stop and start in the given unit
◆ stop() [2/2]
void Longan_nano::Chrono::stop |
( |
void |
| ) |
|
public method stop | void
- Returns
- void
Stop the timer. Snap the stop time
◆ g_f_accumulator_mode
bool Longan_nano::Chrono::g_f_accumulator_mode |
|
private |
◆ g_systick_start
uint64_t Longan_nano::Chrono::g_systick_start |
|
private |
◆ g_systick_stop
uint64_t Longan_nano::Chrono::g_systick_stop |
|
private |
The documentation for this class was generated from the following file: