perf_counter v2.1.0
A dedicated performance counter for Cortex-M Systick. It shares the SysTick with users' original SysTick function(s) without interfering with it.
1 Basic

Functions

int64_t get_system_ticks (void)
 get the elapsed cycles since perf_counter is initialised More...
 
int32_t get_system_ms (void)
 get the elapsed milliseconds since perf_counter is initialised More...
 
int32_t get_system_us (void)
 get the elapsed microsecond since perf_counter is initialised More...
 
void start_cycle_counter (void)
 try to set a start pointer for the performance counter More...
 
int64_t stop_cycle_counter (void)
 calculate the elapsed cycle count since the last start point More...
 
void delay_us (int32_t nUs)
 delay specified time in microsecond More...
 
void delay_ms (int32_t nMs)
 delay specified time in millisecond More...
 
void init_cycle_counter (bool bIsSysTickOccupied)
 initialise cycle counter service More...
 
void user_code_insert_to_systick_handler (void)
 a system timer handler inserted to the SysTick_Handler More...
 
void update_perf_counter (void)
 update perf_counter as SystemCoreClock has been updated. More...
 

Detailed Description

Function Documentation

◆ delay_ms()

void delay_ms ( int32_t  nMs)

delay specified time in millisecond

Parameters
[in]nMstime in millisecond

Definition at line 328 of file perf_counter.c.

References get_system_ticks().

◆ delay_us()

void delay_us ( int32_t  nUs)

delay specified time in microsecond

Parameters
[in]nUstime in microsecond

Definition at line 310 of file perf_counter.c.

References get_system_ticks().

◆ get_system_ms()

int32_t get_system_ms ( void  )

get the elapsed milliseconds since perf_counter is initialised

Returns
int32_t the elapsed milliseconds

Definition at line 387 of file perf_counter.c.

◆ get_system_ticks()

int64_t get_system_ticks ( void  )

get the elapsed cycles since perf_counter is initialised

Returns
int64_t the elpased cycles

Definition at line 346 of file perf_counter.c.

Referenced by delay_ms(), delay_us(), init_task_cycle_counter(), start_cycle_counter(), stop_cycle_counter(), and update_perf_counter().

◆ get_system_us()

int32_t get_system_us ( void  )

get the elapsed microsecond since perf_counter is initialised

Returns
int32_t the elapsed microsecond

Definition at line 398 of file perf_counter.c.

◆ init_cycle_counter()

void init_cycle_counter ( bool  bIsSysTickOccupied)

initialise cycle counter service

Note
- don't forget to tell the function whether the systick is already used by user applications. Don't worry, this cycle counter service won't affect your existing systick service.
- Usually the perf_counter can initialise itself with the help of attribute((constructor(255))), this works fine in Arm Compiler 5 (armcc), Arm Compiler 6 (armclang), arm gcc and llvm. It doesn't work for IAR. So, when you are using IAR, please call this function manually to initialise the perf_counter service.
- Perf_counter library assumes that:
  1. Your project has already using SysTick
  2. It assumes that you have already implemented the SysTick_Handler
  3. It assumes that you have enabled the exception handling for SysTick. If these are not the case, please:
    1. Add an empty SysTick_Handler to your project if you don't have one
    2. Make sure you have the SysTick Exception handling enabled
    3. And call function init_cycle_counter(false) if you doesn't use SysTick in your project at all.
Parameters
[in]bIsSysTickOccupiedA boolean value which indicates whether SysTick is already used by user application.

Definition at line 249 of file perf_counter.c.

References update_perf_counter().

◆ start_cycle_counter()

void start_cycle_counter ( void  )

try to set a start pointer for the performance counter

Definition at line 416 of file perf_counter.h.

References get_system_ticks().

◆ stop_cycle_counter()

int64_t stop_cycle_counter ( void  )

calculate the elapsed cycle count since the last start point

Note
you can have multiple stop_cycle_counter following one start point
Returns
int32_t the elapsed cycle count

Definition at line 427 of file perf_counter.h.

References get_system_ticks().

◆ update_perf_counter()

void update_perf_counter ( void  )

update perf_counter as SystemCoreClock has been updated.

Definition at line 237 of file perf_counter.c.

References get_system_ticks().

Referenced by init_cycle_counter().

◆ user_code_insert_to_systick_handler()

void user_code_insert_to_systick_handler ( void  )

a system timer handler inserted to the SysTick_Handler

Note
- if you are using a compiler other than armcc or armclang, e.g. iar, arm gcc etc, the systick_wrapper_ual.o doesn't work with the linker of your target toolchain as it use the $Super$$ which is only supported by armlink. For this condition, you have to manually put this function into your existing SysTick_Handler to make the perf_counter library work.
- if you are using Arm Compiler 5 (armcc) or Arm Compiler 6 (armclang) you do NOT have to insert this function into your SysTick_Handler, the systick_wrapper_ual.s will do the work for you.

Definition at line 208 of file perf_counter.c.