perf_counter v1.9.8
A dedicated performance counter for Cortex-M Systick. It shares the SysTick with users' original SysTick function(s) without interfering with it.
|
A dedicated performance counter for Cortex-M Systick. It shares the SysTick with users' original SysTick function(s) without interfering with it. This library will bring new functionalities, such as performance counter,delay_us
and clock()
service defined in time.h
.
__cycleof__()
, __super_loop_monitor__()
etc.start_cycle_counter()
, stop_cycle_counter()
etc.delay_us()
and delay_ms()
get_system_ms()
__IS_COMPILER_ARM_COMPILER_6__
, __IS_COMPILER_LLVM__
etc.__IRQ_SAFE{...}
with()
foreach()
, dimof(), CONNECT()
using()
__PLOOC_VA_NUM_ARGS()
You can measure specified code segment with a macro helper __cycleof__()
, it is a wrapper of get_system_ticks()
.
Syntax:
Here, [ref 1] is a small user code to read the measurement result via a local variable __cycle_count__
for perl lovers, you can also use "`_`" to read the result. This User Code is optional. If you don't put anything here, the measured result will be shown with a printf()
.
You will see the measured result in console:
The result is read out from __cycle_count__
and used in other place:
You can get the system timestamp (since the initialization of perf_counter service) via function get_system_ticks()
and get_system_ms()
.
NOTE: The get_system_ms()
is NOT a wrapper of the function get_system_ticks()
.
There are various way to take advantage of those functions.
This example shows how to use the delta value of get_system_ticks()
to measure the CPU cycles used by specified code segment. In fact, the __cycleof__()
is implemented in the same way:
perf_counter
folderperf_counter.c
to your compilationperf_counter.h
in corresponding c source file:perf_counter.h
includes cmsis_compiler.h
.user_code_insert_to_systick_handler()
in your SysTick_Handler()
SystemCoreClock
is updated with the same value as CPU frequency.SysTick_CTRL_CLKSOURCE_Msk
bit ( bit 2) of SysTick->CTRL
register is 1
that means SysTick runs with the same clock source as the target Cortex-M processor.--std=gnu99
or --std=gnu11
, and for other compilers, please check the user manual first. Failed to do so, you will not only trigger the warning in perf_counter.h
, but also lose the function correctness of __cycleof__()
and __super_loop_monitor__()
, because __PLOOC_VA_NUM_ARGS()
isn't report 0
when passed with no argument.__PERF_COUNTER__
to your project GLOBALLY. It helps other module to detect the existence of perf_counter. For Example, LVGL lv_conf_cmsis.h
use this macro to detect perf_counter and uses get_system_ms()
to implement lv_tick_get()
.Enjoy !
cmsis-pack
folder. It is a file with name GorgonMeducer.perf_counter.<version>.pack
, for example GorgonMeducer.perf_counter.1.9.4.pack
Double click it to install this cmsis-pack. Once finished, you can find it in your Pack-Installer:
In the future, you can pull the latest version of perf_counter from the menu
Packs->Check For Updates
as shown below:
perf_counter.h
in corresponding c source file:perf_counter.h
includes cmsis_compiler.h
. Usually, you should do this with RTE as shown below:SystemCoreClock
is updated with the same value as CPU frequency.SysTick_CTRL_CLKSOURCE_Msk
bit ( bit 2) of SysTick->CTRL
register is 1
that means SysTick runs with the same clock source as the target Cortex-M processor.IMPORTANT: Please enable GNU extension in your compiler.
For Arm Compiler 5, please select both C99 mode and GNU extensions in the Option for target dialog as shown below:
For Arm Compiler 6, please select gnu99 or gnu11 in Language C drop-list as shown below:
Failed to do so, you will not only trigger the warning in perf_counter.h
, but also lose the function correctness of __cycleof__()
and __super_loop_monitor__()
, because __PLOOC_VA_NUM_ARGS()
isn't report 0
when passed with no argument.
perf_counter has registered as one of the RT-Thread software packages, which locats in system
category. In ENV or RT-Thread Studio, you just need to simply enable cputime framework. RT-Thread will automatically enable perf_counter if you are using Cortex-M architecture.
Enjoy !
This error usually pops-up in Arm Compiler 5 and Arm Compiler 6, it is because you haven't implement any non-weak Systick_Handler()
. Please provide an EMPTY one in any c source file to solve this problem:
NOTE: If you deploy perf_counter using cmsis-pack and encounter this issue, please DO NOT call function user_code_insert_to_systick_handler()
in this should-be-empty SysTick_Handler()
.
Performance Counter for Cortex-M, a.k.a. perf_counter is under Apache 2.0 license.