You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47-47Lines changed: 47 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ A dedicated performance counter for Cortex-M Systick. It shares the SysTick with
20
20
- Easy to port to a different architecture with a porting template
21
21
22
22
-**Provide Free Services**
23
-
- Do **NOT**interfer with existing SysTickbased applications
23
+
- Do **NOT**interfere with existing SysTick-based applications
24
24
-**Support most of the arm compilers**
25
25
- Arm Compiler 5 (armcc), Arm Compiler 6 (armclang)
26
26
- arm gcc
@@ -30,7 +30,7 @@ A dedicated performance counter for Cortex-M Systick. It shares the SysTick with
30
30
-**Drag-and-Drop deployment for Arm Compiler 5 and Arm Compiler 6.**
31
31
-**CMSIS-Pack is available**
32
32
-**RT-Thread package is avaialble**
33
-
-**Timebased services**
33
+
-**Time-based services**
34
34
-`delay_us()` and `delay_ms()` with **64bit return value**.
35
35
- Provides Timestamp services via `get_system_ticks()`, `get_system_us` and `get_system_ms()`.
36
36
-**Support both RTOS and bare-metal environments**
@@ -39,12 +39,12 @@ A dedicated performance counter for Cortex-M Systick. It shares the SysTick with
39
39
- Support stack-overflow detection in RTOS environment via `perfc_check_task_stack_canary_safe()`
40
40
-**Utilities for C language enhancement**
41
41
- Macros to detect compilers, e.g. `__IS_COMPILER_ARM_COMPILER_6__`, `__IS_COMPILER_LLVM__` etc.
42
-
- Macro to create atomicity for specified code block, i.e. `__IRQ_SAFE{...}`
42
+
- Macro to create atomicity for a specified code block, i.e. `__IRQ_SAFE{...}`.
43
43
- Helper macros for C language extension:
44
44
- VB like `with()`
45
45
-`foreach()`, dimof(), `CONNECT()`
46
46
- C# like `using()`
47
-
- simple overload feature of OOPC made out of ANSI-C99, `__PLOOC_VA_NUM_ARGS()`
47
+
- simple overload feature of OOPC made out of ANSI-C99, `__PLOOC_VA_NUM_ARGS()`.
48
48
-**[new]** add macros for PT
49
49
- ...
50
50
- A dedicated macro `__perfc_sync_barrier__()` for code barrier.
@@ -53,9 +53,9 @@ A dedicated performance counter for Cortex-M Systick. It shares the SysTick with
53
53
54
54
## 1. How To Use
55
55
56
-
### 1.1 Measure CPU cycles for specified code segment
56
+
### 1.1 Measure CPU cycles for a specified code segment
57
57
58
-
You can measure specified code segment with a macro helper `__cycleof__()`, it is a wrapper of `get_system_ticks()`.
58
+
You can measure a specified code segment with a macro helper `__cycleof__()`, a wrapper of `get_system_ticks()`.
59
59
60
60
**Syntax:**
61
61
@@ -66,7 +66,7 @@ __cycleof__(<Description String for the target>, [User Code, see ref 1]) {
66
66
}
67
67
```
68
68
69
-
Here, [**ref 1**] is a small user code to read the measurement result via a local variable `__cycle_count__`. This User Code is optional. If you don't put anything here, the measured result will be shown with a `__perf_counter_printf__`.
69
+
Here, [**ref 1**] is a small user code to read the measurement result via a local variable `__cycle_count__`. This User Code is optional. If you don't put anything here, the measured result will be shown with a `__perf_counter_printf__`.
70
70
71
71
#### **Example 1:** Simple measurement with printf
72
72
@@ -78,7 +78,7 @@ Here, [**ref 1**] is a small user code to read the measurement result via a loca
The result is read out from `__cycle_count__`and used in other place:
@@ -109,12 +109,12 @@ The result is read out from `__cycle_count__`and used in other place:
109
109
110
110
#### 1.2.1 CPU Usage
111
111
112
-
For both bare-metal and OS environment, you can measure the CPU Usage with macro `__cpu_usage__()` for a given code segment as long as it is executed repeatedly.
112
+
For both bare-metal and OS environments, you can measure the CPU Usage with macro `__cpu_usage__()` for a given code segment as long as it is executed repeatedly.
113
113
114
114
**Syntax**
115
115
116
116
```c
117
-
__cycleof__(<Iteration Count before getting an average result>, [User Code, see ref 1]) {
117
+
__cpu_usage__(<Iteration Count before getting an average result>, [User Code, see ref 1]) {
118
118
//! target code segment of measurement
119
119
...
120
120
}
@@ -177,7 +177,7 @@ __cpu_perf__(<Description String for the target>, [User Code, see ref 1]) {
177
177
}
178
178
```
179
179
180
-
Here, [**ref 1**] is a small user code to read the measurement result via a local **struct** variable `__PERF_INFO__`. This User Code is optional. If you don't put anything here, the measured result will be shown with a `__perf_counter_printf__`. The prototype of the `__PERF_INFO__` is shown below:
180
+
Here, [**ref 1**] is a small user code to read the measurement result via a local **struct** variable `__PERF_INFO__`. This User Code is optional. If you don't put anything here, the measured result will be shown with a `__perf_counter_printf__`. The prototype of the `__PERF_INFO__` is shown below:
181
181
182
182
```c
183
183
struct {
@@ -192,7 +192,7 @@ struct {
192
192
} __PERF_INFO__;
193
193
```
194
194
195
-
For example, when insert user code, you can read CPI from `__PERF_INFO__.fCPI`.
195
+
For example, when inserting user code, you can read CPI from `__PERF_INFO__.fCPI`.
196
196
197
197
**Example 1: measure the Coremark**
198
198
@@ -223,13 +223,13 @@ The result might look like the following:
223
223
224
224
### 1.3 Timestamp
225
225
226
-
You can get the system timestamp (since the initialization of perf_counter service) via function `get_system_ticks()` and `get_system_ms()`.
226
+
You can get the system timestamp (since the initialization of perf_counter service) via the functions `get_system_ticks()` and `get_system_ms()`.
227
227
228
228
**NOTE**: The `get_system_ms()` is **NOT** a wrapper of the function `get_system_ticks()`.
229
229
230
230
231
231
232
-
There are various way to take advantage of those functions.
232
+
There are various ways to take advantage of those functions.
233
233
234
234
#### Example 3: Use `get_system_ms()` as random seed
235
235
@@ -244,7 +244,7 @@ int main (void)
244
244
245
245
n = 5;
246
246
247
-
/* Intializes random number generator */
247
+
/* Initialize random number generator */
248
248
srand((unsigned) get_system_ticks());
249
249
250
250
/* Print 5 random numbers from 0 to 1024 */
@@ -270,7 +270,7 @@ int main (void)
270
270
} while(0);
271
271
```
272
272
273
-
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:
273
+
This example shows how to use the delta value of `get_system_ticks()` to measure the CPU cycles used by a specified code segment. In fact, the `__cycleof__()` is implemented in the same way:
274
274
275
275
```c
276
276
#define __cycleof__(__STR, ...) \
@@ -294,7 +294,7 @@ This example shows how to use the delta value of `get_system_ticks()` to measure
294
294
295
295
### 1.4 Timer Services
296
296
297
-
perf_counter provides the basic timer services for delaying a given period of time and polling-for-timeout. For example:
297
+
perf_counter provides the basic timer services for delaying a given period and polling-for-timeout. For example:
298
298
299
299
```c
300
300
delay_ms(1000); /* block the program for 1000ms */
@@ -315,9 +315,9 @@ while(1) {
315
315
316
316
### 1.5 Work with EventRecorder in MDK
317
317
318
-
If you are using EventRecorder in MDK, once you deployed the `perf_counter`, it will provide the timer service for EventRecorder by implenting the following functions: `EventRecorderTimerSetup()`, `EventRecorderTimerGetFreq()` and `EventRecorderTimerGetCount()`.
318
+
If you are using EventRecorder in MDK, once you deploy the `perf_counter`, it will provide the timer service for EventRecorder by implementing the following functions: `EventRecorderTimerSetup()`, `EventRecorderTimerGetFreq()` and `EventRecorderTimerGetCount()`.
319
319
320
-
If you have not modify anything in `EventRecorderConf.h`, **you don't have to**, and please keep the default configuration. If you see warnings like this:
320
+
If you have not modified anything in `EventRecorderConf.h`, **you don't have to**, and please keep the default configuration. If you see warnings like this:
321
321
322
322
```
323
323
Invalid Time Stamp Source selected in EventRecorderConf.h!
@@ -329,7 +329,7 @@ Please set the macro `EVENT_TIMESTAMP_SOURCE` to `3` to suppress it.
329
329
330
330
331
331
332
-
**By using perf_counter as the reference clock, EventRecorder can have the highest clock resolution on the target system without worring about the presence of DWT or any conflicting usage of SysTick.**
332
+
**By using perf_counter as the reference clock, EventRecorder can have the highest clock resolution on the target system without worrying about the presence of DWT or any conflicting usage of SysTick.**
333
333
334
334
335
335
@@ -347,7 +347,7 @@ If you want to change the System Frequency, **after** the change, make sure:
347
347
348
348
#### 1.6.2 Reconfigure the SysTick
349
349
350
-
Some systems (e.g. FreeRTOS) might reconfigure the systick timer to fulfil the requirement of their feature. To support this:
350
+
Some systems (e.g., FreeRTOS) might reconfigure the systick timer to fulfill the requirements of their feature. To support this:
351
351
352
352
1. **Before the reconfiguration**, please call function `before_cycle_counter_reconfiguration()`.
353
353
@@ -363,7 +363,7 @@ Some systems (e.g. FreeRTOS) might reconfigure the systick timer to fulfil the r
363
363
364
364
#### 2.1.1 For Bare-metal:
365
365
366
-
1. Clone the code to your local with following command lines:
366
+
1. Clone the code to your local with the following command lines:
> **NOTE**: Please do **NOT** add any assembly source files of this `perf_counter` library to your compilation, i.e. `systick_wrapper_gcc.S`, `systick_wrapper_gnu.s` or `systick_wrapper_ual.s`.
376
376
377
-
4. Include `perf_counter.h` in corresponding c source file:
377
+
4. Include `perf_counter.h` in the corresponding c source file:
378
378
379
379
```c
380
380
#include"perf_counter.h"
381
381
```
382
382
383
383
384
-
5. Make sure your system contains the CMSIS (with a version 5.7.0 or above) as `perf_counter.h` includes `cmsis_compiler.h`.
384
+
5. Make sure your system contains the CMSIS (with version 5.7.0 or above) as `perf_counter.h` and includes `cmsis_compiler.h`.
385
385
6. Call the function `perfc_port_insert_to_system_timer_insert_ovf_handler()` in your `SysTick_Handler()`
386
386
387
387
```c
@@ -394,9 +394,9 @@ void SysTick_Handler(void)
394
394
```
395
395
396
396
397
-
7. Make sure the `SystemCoreClock` is updated with the same value as CPU frequency.
397
+
7. Ensure the `SystemCoreClock` is updated with the same value as CPU frequency.
398
398
8. **IMPORTANT**: Make sure the `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.
399
-
9. Initialize the perf_counter with boolean value that indicates whether the user applications and/or RTOS have already occupied the SysTick.
399
+
9. Initialize the perf_counter with a boolean value that indicates whether the user applications and/or RTOS have already occupied the SysTick.
400
400
401
401
```c
402
402
void main(void)
@@ -413,7 +413,7 @@ void main(void)
413
413
SystemCoreClockUpdate();
414
414
415
415
/*! \brief initialize perf_counter() and pass true if SysTick is
416
-
*! occupied by user applications or RTOS, otherwise pass
416
+
*! occupied by user applications or RTOS; otherwise, pass
417
417
*! false.
418
418
*/
419
419
init_cycle_counter(true);
@@ -425,16 +425,16 @@ void main(void)
425
425
}
426
426
```
427
427
428
-
10.**IMPORTANT**: Please enable GNU extension in your compiler. For **GCC** and **CLANG**, it is `--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.
428
+
10.**IMPORTANT**: Please enable the GNU extension in your compiler. For **GCC** and **CLANG**, it is `--std=gnu99` or `--std=gnu11`, and for other compilers, please check the user manual first. Fail 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()`doesn't report `0` when passed with no argument.
429
429
430
430
```c
431
431
#if __PLOOC_VA_NUM_ARGS() != 0
432
-
#warning Please enable GNC extensions, it is required by __cycleof__() and \
432
+
#warning Please enable GNC extensions that is required by __cycleof__() and \
433
433
__super_loop_monitor__()
434
434
#endif
435
435
```
436
436
437
-
11. It is nice to add macro definition `__PERF_COUNTER__` to your project GLOBALLY. It helps other module to detect the existence of perf_counter. For Example, LVGL [`lv_conf_cmsis.h`](https://github.com/lvgl/lvgl/blob/d367bb7cf17dc34863f4439bba9b66a820088951/env_support/cmsis-pack/lv_conf_cmsis.h#L81-L99) use this macro to detect perf_counter and uses `get_system_ms()` to implement `lv_tick_get()`.
437
+
11. It is nice to add macro definition `__PERF_COUNTER__` to your project GLOBALLY. It helps other modules to detect the existence of perf_counter. For Example, LVGL [`lv_conf_cmsis.h`](https://github.com/lvgl/lvgl/blob/d367bb7cf17dc34863f4439bba9b66a820088951/env_support/cmsis-pack/lv_conf_cmsis.h#L81-L99) use this macro to detect perf_counter and uses `get_system_ms()` to implement `lv_tick_get()`.
438
438
439
439
440
440
@@ -446,7 +446,7 @@ __super_loop_monitor__()
446
446
447
447
1. Download the cmsis-pack from the`cmsis-pack` folder. It is a file with name `GorgonMeducer.perf_counter.<version>.pack`, for example `GorgonMeducer.perf_counter.2.2.0.pack`
448
448
449
-
2. Doubleclick it to install this cmsis-pack. Once finished, you can find it in your Pack-Installer:
449
+
2. Double-click it to install this cmsis-pack. Once finished, you can find it in your Pack-Installer:
450
450
451
451

452
452
In the future, you can pull the latest version of perf_counter from the menu `Packs->Check For Updates` as shown below:
@@ -459,25 +459,25 @@ __super_loop_monitor__()
459
459
460
460

461
461
462
-
4. Include `perf_counter.h` in corresponding c source file:
462
+
4. Include `perf_counter.h` in the corresponding c source file:
463
463
464
464
```c
465
465
#include"perf_counter.h"
466
466
```
467
467
468
468
469
-
5. Make sure your system contains the CMSIS (with a version 5.7.0 or above) as `perf_counter.h` includes `cmsis_compiler.h`. Usually, you should do this with RTE as shown below:
469
+
5. Make sure your system contains the CMSIS (version 5.7.0 or above) as `perf_counter.h`and includes `cmsis_compiler.h`. Usually, you should do this with RTE, as shown below:
6.Make sure the `SystemCoreClock` is updated with the same value as CPU frequency.
473
+
6.Ensure the `SystemCoreClock` is updated with the same value as CPU frequency.
474
474
7.**IMPORTANT**: Make sure the `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.
475
-
8. Initialize the perf_counter with boolean value that indicates whether the user applications and/or RTOS have already occupied the SysTick.
475
+
8. Initialize the perf_counter with a boolean value that indicates whether the user applications and/or RTOS have already occupied the SysTick.
476
476
477
477
```c
478
478
voidmain(void)
479
479
{
480
-
//! setup system clock
480
+
//! Setup system clock
481
481
482
482
/*! \brief Update SystemCoreClock with the latest CPU frequency
483
483
*! If the function doesn't exist or doesn't work correctly,
@@ -489,7 +489,7 @@ void main(void)
489
489
SystemCoreClockUpdate();
490
490
491
491
/*! \brief initialize perf_counter() and pass true if SysTick is
492
-
*! occupied by user applications or RTOS, otherwise pass
492
+
*! occupied by user applications or RTOS; otherwise, pass
493
493
*! false.
494
494
*/
495
495
init_cycle_counter(true);
@@ -501,28 +501,28 @@ void main(void)
501
501
}
502
502
```
503
503
504
-
9. **IMPORTANT**: Please enable GNU extension in your compiler.
504
+
9. **IMPORTANT**: Please enable the GNU extension in your compiler.
505
505
506
-
For Arm Compiler 5, please select both **C99 mode** and GNU extensions in the **Option for target dialog** as shown below:
506
+
For Arm Compiler 5, please select both **C99 mode** and GNU extensions in the **Option for target dialogue** 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.
514
+
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()` doesn't report `0` when passed with no argument.
515
515
516
516
```c
517
517
#if __PLOOC_VA_NUM_ARGS() != 0
518
-
#warning Please enable GNC extensions, it is required by __cycleof__() and \
518
+
#warning Please enable GNC extensions, that is required by __cycleof__() and \
519
519
__super_loop_monitor__()
520
520
#endif
521
521
```
522
522
523
523
### 2.3 Use perf_counter in RT-Thread RTOS
524
524
525
-
perf_counter has registered as one of the [RT-Thread software packages](https://packages.rt-thread.org/en/detail.html?package=perf_counter), which locats in `system` category. In [ENV](https://www.rt-thread.io/download.html?download=Env) or [RT-Thread Studio](https://www.rt-thread.io/download.html?download=Studio), you just need to simply enable cputime framework. RT-Thread will automatically enable perf_counter if you are using Cortex-M architecture.
525
+
perf_counter has registered as one of the [RT-Thread software packages](https://packages.rt-thread.org/en/detail.html?package=perf_counter), which locats in `system` category. In [ENV](https://www.rt-thread.io/download.html?download=Env) or [RT-Thread Studio](https://www.rt-thread.io/download.html?download=Studio), you just need to enable `cputime` framework. RT-Thread will automatically enable perf_counter if you are using Cortex-M architecture.
@@ -534,7 +534,7 @@ perf_counter has registered as one of the [RT-Thread software packages](https://
534
534
535
535
### 3.1 Why I see `Undefined symbol $Super$$SysTick_Handler`
536
536
537
-
This error usually pops up in **Arm Compiler 5** and **Arm Compiler 6**. It is because you haven't implemented any non-weak `SysTick_Handler()`. Please provide an EMPTY one in any c source file to solve this problem:
537
+
This error usually appears in **Arm Compiler 5** and **Arm Compiler 6**. It is because you haven't implemented any non-weak `SysTick_Handler()`. Please provide an EMPTY one in any c source file to solve this problem:
538
538
539
539
```c
540
540
voidSysTick_Handler(void)
@@ -546,7 +546,7 @@ void SysTick_Handler(void)
546
546
547
547
### 3.2 Why do I see perf_counter in red in the MDK project manager?
548
548
549
-
Since version v2.1.0 I removed the unnecessary bundle feature from the cmsis-pack. If you have used the older version, you will encounter this issue. To solve this problem:
549
+
Since version v2.1.0, I removed the unnecessary bundle feature from the cmsis-pack. If you have used the older version, you will encounter this issue. To solve this problem:
550
550
551
551
1. please unselect ALL the performance components in RTE, press OK and close the uVision.
552
552
2. reopen the mdk project and select the perf_counter components in RTE
0 commit comments