Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG_patch mbed-rtos mbed
cpu_utils.c
00001 /** 00002 ****************************************************************************** 00003 * @file cpu_utils.c 00004 * @author MCD Application Team 00005 * @version V1.1.0 00006 * @date 20-November-2014 00007 * @brief Utilities for CPU Load calculation 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 /********************** NOTES ********************************************** 00039 To use this module, the following steps should be followed : 00040 00041 1- in the _OS_Config.h file (ex. FreeRTOSConfig.h) enable the following macros : 00042 - #define configUSE_IDLE_HOOK 1 00043 - #define configUSE_TICK_HOOK 1 00044 00045 2- in the _OS_Config.h define the following macros : 00046 - #define traceTASK_SWITCHED_IN() extern void StartIdleMonitor(void); \ 00047 StartIdleMonitor() 00048 - #define traceTASK_SWITCHED_OUT() extern void EndIdleMonitor(void); \ 00049 EndIdleMonitor() 00050 *******************************************************************************/ 00051 00052 00053 /* Includes ------------------------------------------------------------------*/ 00054 #include "cpu_utils.h" 00055 00056 /* Private typedef -----------------------------------------------------------*/ 00057 /* Private define ------------------------------------------------------------*/ 00058 /* Private macro -------------------------------------------------------------*/ 00059 /* Private function prototypes -----------------------------------------------*/ 00060 /* Private variables ---------------------------------------------------------*/ 00061 00062 xTaskHandle xIdleHandle = NULL; 00063 __IO uint32_t osCPU_Usage = 0; 00064 uint32_t osCPU_IdleStartTime = 0; 00065 uint32_t osCPU_IdleSpentTime = 0; 00066 uint32_t osCPU_TotalIdleTime = 0; 00067 00068 /* Private functions ---------------------------------------------------------*/ 00069 /** 00070 * @brief Application Idle Hook 00071 * @param None 00072 * @retval None 00073 */ 00074 void vApplicationIdleHook(void) 00075 { 00076 if( xIdleHandle == NULL ) 00077 { 00078 /* Store the handle to the idle task. */ 00079 xIdleHandle = xTaskGetCurrentTaskHandle(); 00080 } 00081 } 00082 00083 /** 00084 * @brief Application Idle Hook 00085 * @param None 00086 * @retval None 00087 */ 00088 void vApplicationTickHook (void) 00089 { 00090 static int tick = 0; 00091 00092 if(tick ++ > CALCULATION_PERIOD) 00093 { 00094 tick = 0; 00095 00096 if(osCPU_TotalIdleTime > 1000) 00097 { 00098 osCPU_TotalIdleTime = 1000; 00099 } 00100 osCPU_Usage = (100 - (osCPU_TotalIdleTime * 100) / CALCULATION_PERIOD); 00101 osCPU_TotalIdleTime = 0; 00102 } 00103 } 00104 00105 /** 00106 * @brief Start Idle monitor 00107 * @param None 00108 * @retval None 00109 */ 00110 void StartIdleMonitor (void) 00111 { 00112 if( xTaskGetCurrentTaskHandle() == xIdleHandle ) 00113 { 00114 osCPU_IdleStartTime = xTaskGetTickCountFromISR(); 00115 } 00116 } 00117 00118 /** 00119 * @brief Stop Idle monitor 00120 * @param None 00121 * @retval None 00122 */ 00123 void EndIdleMonitor (void) 00124 { 00125 if( xTaskGetCurrentTaskHandle() == xIdleHandle ) 00126 { 00127 /* Store the handle to the idle task. */ 00128 osCPU_IdleSpentTime = xTaskGetTickCountFromISR() - osCPU_IdleStartTime; 00129 osCPU_TotalIdleTime += osCPU_IdleSpentTime; 00130 } 00131 } 00132 00133 /** 00134 * @brief Stop Idle monitor 00135 * @param None 00136 * @retval None 00137 */ 00138 uint16_t osGetCPUUsage (void) 00139 { 00140 return (uint16_t)osCPU_Usage; 00141 } 00142 00143 00144 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 00145
Generated on Tue Jul 12 2022 14:57:26 by
1.7.2