Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "cpu_utils.h"
Private variables
xIdleHandle
osCPU_Usage
osCPU_IdleStartTime
osCPU_IdleSpentTime
osCPU_TotalIdleTime
vApplicationIdleHook()
vApplicationTickHook()
StartIdleMonitor()
EndIdleMonitor()
osGetCPUUsage()
Files
loading...
SourceVuSTM32 Libraries and SamplesUtilitiesCPU/cpu_utils.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file cpu_utils.c * @author MCD Application Team * @brief Utilities for CPU Load calculation ****************************************************************************** * @attention * * Copyright (c) 2014 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /********************** NOTES ********************************************** To use this module, the following steps should be followed : 1- in the _OS_Config.h file (ex. FreeRTOSConfig.h) enable the following macros : - #define configUSE_IDLE_HOOK 1 - #define configUSE_TICK_HOOK 1 2- in the _OS_Config.h define the following macros : - #define traceTASK_SWITCHED_IN() extern void StartIdleMonitor(void); \ StartIdleMonitor() - #define traceTASK_SWITCHED_OUT() extern void EndIdleMonitor(void); \ EndIdleMonitor() *******************************************************************************//* ... */ /* Includes ------------------------------------------------------------------*/ #include "cpu_utils.h" Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ xTaskHandle xIdleHandle = NULL; __IO uint32_t osCPU_Usage = 0; uint32_t osCPU_IdleStartTime = 0; uint32_t osCPU_IdleSpentTime = 0; uint32_t osCPU_TotalIdleTime = 0; Private variables /* Private functions ---------------------------------------------------------*/ /** * @brief Application Idle Hook * @param None * @retval None *//* ... */ void vApplicationIdleHook(void) { if( xIdleHandle == NULL ) { /* Store the handle to the idle task. */ xIdleHandle = xTaskGetCurrentTaskHandle(); }if (xIdleHandle == NULL) { ... } }{ ... } /** * @brief Application Idle Hook * @param None * @retval None *//* ... */ void vApplicationTickHook (void) { static int tick = 0; if(tick ++ > CALCULATION_PERIOD) { tick = 0; if(osCPU_TotalIdleTime > 1000) { osCPU_TotalIdleTime = 1000; }if (osCPU_TotalIdleTime > 1000) { ... } osCPU_Usage = (100 - (osCPU_TotalIdleTime * 100) / CALCULATION_PERIOD); osCPU_TotalIdleTime = 0; }if (tick ++ > CALCULATION_PERIOD) { ... } }{ ... } /** * @brief Start Idle monitor * @param None * @retval None *//* ... */ void StartIdleMonitor (void) { if( xTaskGetCurrentTaskHandle() == xIdleHandle ) { osCPU_IdleStartTime = xTaskGetTickCountFromISR(); }if (xTaskGetCurrentTaskHandle() == xIdleHandle) { ... } }{ ... } /** * @brief Stop Idle monitor * @param None * @retval None *//* ... */ void EndIdleMonitor (void) { if( xTaskGetCurrentTaskHandle() == xIdleHandle ) { /* Store the handle to the idle task. */ osCPU_IdleSpentTime = xTaskGetTickCountFromISR() - osCPU_IdleStartTime; osCPU_TotalIdleTime += osCPU_IdleSpentTime; }if (xTaskGetCurrentTaskHandle() == xIdleHandle) { ... } }{ ... } /** * @brief Stop Idle monitor * @param None * @retval None *//* ... */ uint16_t osGetCPUUsage (void) { return (uint16_t)osCPU_Usage; }{ ... }
Details