Longan Nano
Longan Nano Demo
Longan_nano::Chrono Class Reference

Deals with busy delays, elapsed time and accumulated time. More...

#include <longan_nano_chrono.hpp>

Public Types

enum  _Config { PEDANTIC_CHECKS = false, SYSTICK_INVALID = 0xFFFFFFFF, SYSTICK_PRE = 4, TIME_INVALID = -1 }
 Configurations of the SysTick. More...
 
enum  _Unit { milliseconds, microseconds }
 Possible time units. Same names as std::Chrono. More...
 
typedef enum Longan_nano::Chrono::_Config Config
 Configurations of the SysTick. More...
 
typedef enum Longan_nano::Chrono::_Unit Unit
 Possible time units. Same names as std::Chrono. More...
 

Public Member Functions

 Chrono (void)
 Empty Constructor Chrono | void. More...
 
 ~Chrono (void)
 Empty Destructor. More...
 
void start (void)
 public method start | void More...
 
void restart (void)
 public method start | void More...
 
void stop (void)
 public method stop | void More...
 
int32_t stop (Unit unit)
 public method stop | Unit | More...
 
bool accumulate (void)
 public method accumulate | void | More...
 
int32_t accumulate (Unit unit)
 public method accumulate | Unit unit | More...
 
int32_t get_elapsed (Unit unit)
 public getter get_elapsed | Unit | More...
 
int32_t get_accumulator (Unit unit)
 public getter get_accumulator | Unit | More...
 

Static Public Member Functions

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...
 

Private Member Functions

int32_t compute_elapsed (uint64_t start, uint64_t stop, Unit unit)
 private method compute_elapsed | uint64_t | uint64_t | Unit | More...
 
int32_t compute_accumulator (uint64_t accumulator, Unit unit)
 private method compute_accumulator | uint64_t | Unit | More...
 

Static Private Member Functions

static uint32_t compute_tick_per_time_unit (Unit unit)
 private method compute_tick_per_time_unit | Unit | More...
 

Private Attributes

bool g_f_accumulator_mode
 
uint64_t g_systick_start
 
uint64_t g_systick_stop
 

Detailed Description

Deals with busy delays, elapsed time and accumulated time.

Author
Orso Eric
Version
2020-08-08
Bug:
None


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

Member Typedef Documentation

◆ Config

Configurations of the SysTick.

◆ Unit

Possible time units. Same names as std::Chrono.

Member Enumeration Documentation

◆ _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 

Constructor & Destructor Documentation

◆ 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

Member Function Documentation

◆ 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

Here is the call graph for this function:

◆ 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

Here is the caller graph for this function:

◆ 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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Here is the caller graph for this function:

◆ 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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Here is the call graph for this function:

◆ 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

Here is the caller graph for this function:

◆ 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

Here is the call graph for this function:

◆ stop() [2/2]

void Longan_nano::Chrono::stop ( void  )

public method stop | void

Returns
void



Stop the timer. Snap the stop time

Here is the caller graph for this function:

Member Data Documentation

◆ 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: