From 26ff1cf7bc3d484fcf5f8fb617f2cc5abe39dfdf Mon Sep 17 00:00:00 2001 From: ThinkPad-T460P Date: Sun, 14 Mar 2021 23:24:59 +0800 Subject: [PATCH] update --- .cproject | 8 +- App/Inc/th_elog.h | 4 + App/Inc/{th_button.h => th_exti.h} | 33 ++++- App/Inc/th_info.h | 11 ++ App/Src/th_button.c | 141 ------------------ App/Src/th_cdc.c | 2 +- App/Src/th_demo.c | 6 +- App/Src/th_elog.c | 12 +- App/Src/th_exti.c | 221 +++++++++++++++++++++++++++++ App/Src/th_info.c | 24 ++++ App/Src/th_iwdg.c | 2 +- App/Src/th_led.c | 2 +- App/Src/th_power.c | 2 +- Core/Inc/FreeRTOSConfig.h | 6 +- Core/Inc/navikit.h | 1 + Core/Src/freertos.c | 23 +-- Core/Src/main.c | 7 +- Core/Src/navikit.c | 49 +------ Core/Src/stm32f1xx_it.c | 1 + Core/Src/usart.c | 4 +- Middlewares/EasyLogger | 2 +- NaviKit_EC_stm32.ioc | 37 ++--- Utils/CPU/Release_Notes.html | 197 +++++++++++++++++++++++++ Utils/CPU/cpu_utils.c | 144 +++++++++++++++++++ Utils/CPU/cpu_utils.h | 64 +++++++++ 25 files changed, 764 insertions(+), 239 deletions(-) rename App/Inc/{th_button.h => th_exti.h} (52%) create mode 100644 App/Inc/th_info.h delete mode 100644 App/Src/th_button.c create mode 100644 App/Src/th_exti.c create mode 100644 App/Src/th_info.c create mode 100644 Utils/CPU/Release_Notes.html create mode 100644 Utils/CPU/cpu_utils.c create mode 100644 Utils/CPU/cpu_utils.h diff --git a/.cproject b/.cproject index 218e6d7..803ee27 100644 --- a/.cproject +++ b/.cproject @@ -70,6 +70,7 @@ + @@ -100,11 +101,12 @@ - + + @@ -171,6 +173,7 @@ + @@ -200,11 +203,12 @@ - + + diff --git a/App/Inc/th_elog.h b/App/Inc/th_elog.h index 23eb358..d84b830 100644 --- a/App/Inc/th_elog.h +++ b/App/Inc/th_elog.h @@ -3,6 +3,10 @@ #include "cmsis_os2.h" +osSemaphoreId_t ElogOutputBinarySemHandle; +const osSemaphoreAttr_t ElogOutputBinarySem_attributes; + + osMutexId_t ElogUartMutexHandle; const osMutexAttr_t ElogUartMutex_attributes; diff --git a/App/Inc/th_button.h b/App/Inc/th_exti.h similarity index 52% rename from App/Inc/th_button.h rename to App/Inc/th_exti.h index 4c4f541..ad3849a 100644 --- a/App/Inc/th_button.h +++ b/App/Inc/th_exti.h @@ -10,9 +10,30 @@ #include "cmsis_os2.h" -/* Definitions for ButtonDetect */ -osThreadId_t ButtonDetectTaskHandle; -const osThreadAttr_t ButtonDetectTask_attributes; +//pressed time < short press time(ms) +#define SHORT_PRESS_TIME 500 + +//pressed time > long press time(ms) +#define LONG_PRESS_TIME 1000 + +//define exti flag for task-notification / thread-flags +typedef enum{ + SHUTDOWN_REQ_ACTIVE = 0x01<< 0, + SHUTDOWN_REQ_INACTIVE = 0x01<< 1, + MOD_SLEEP_ACTIVE = 0x01<< 2, + MOD_SLEEP_INACTIVE = 0x01<< 3, + PWR_BTN_ACTIVE = 0x01<< 4, + PWR_BTN_INACTIVE = 0x01<< 5, + CUS_BTN_ACTIVE = 0x01<< 6, + CUS_BTN_INACTIVE = 0x01<< 7, +}Exti_Flags_t; +Exti_Flags_t Exti_Flags; + + + +/* Definitions for ButtonDetectTask */ +osThreadId_t ExtiServiceTaskHandle; +const osThreadAttr_t ExtiServiceTask_attributes; //Timer osTimerId_t PwrBtnLongPressTimerHandle; @@ -27,8 +48,12 @@ const osTimerAttr_t PwrBtnShortPressTimer_attributes; osTimerId_t CustBtnShortPressTimerHandle; const osTimerAttr_t CustBtnShortPressTimer_attributes; +//Event Flag +osEventFlagsId_t ExtiEventFlags; +const osEventFlagsAttr_t ExtiEventFlags_attributes; -void StartButtonDetectTask(void *argument); +//Task +void StartExtiServiceTask(void *argument); //callback void PwrBtnLongPressTimerCallback(void *argument); diff --git a/App/Inc/th_info.h b/App/Inc/th_info.h new file mode 100644 index 0000000..5e0f40f --- /dev/null +++ b/App/Inc/th_info.h @@ -0,0 +1,11 @@ +#ifndef __TH_INFO_H__ +#define __TH_INFO_H__ + +#include "cmsis_os2.h" + +osThreadId_t InfoOutputTaskHandle; + +const osThreadAttr_t InfoOutputTask_attributes; + +void StartInfoOutputTask(void *argument); +#endif diff --git a/App/Src/th_button.c b/App/Src/th_button.c deleted file mode 100644 index 6c579bd..0000000 --- a/App/Src/th_button.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * @Description: - * @Date: 2021-03-10 10:49:52 - * @LastEditors: CK.Zh - * @LastEditTime: 2021-03-10 11:57:47 - * @FilePath: \NaviKit_EC_stm32\App\Src\th_button.c - */ -#define LOG_TAG "TH-Button" - -#include -#include "main.h" -#include "navikit.h" - -//Thread -const osThreadAttr_t ButtonDetectTask_attributes = { - .name = "ButtonDetectTask", - .priority = (osPriority_t) osPriorityBelowNormal, - .stack_size = 128 * 8 -}; - -//Timer -const osTimerAttr_t PwrBtnLongPressTimer_attributes = { - .name = "PwrBtnLongPressTimer" -}; -const osTimerAttr_t CustBtnLongPressTimer_attributes = { - .name = "CustBtnLongPressTimer" -}; -const osTimerAttr_t PwrBtnShortPressTimer_attributes = { - .name = "PwrBtnShortPressTimer" -}; -const osTimerAttr_t CustBtnShortPressTimer_attributes = { - .name = "CustBtnShortPressTimer" -}; - - - -/* USER CODE BEGIN Header_StartButtonDetect */ -/** -* @brief Function implementing the ButtonDetect thread. -* @param argument: Not used -* @retval None -*/ -/* USER CODE END Header_StartButtonDetect */ -void StartButtonDetectTask(void *argument) -{ - /* USER CODE BEGIN StartButtonDetect */ - /* Infinite loop */ - log_d("Start Button Detect Task"); - for(;;) - { - //power button - if(NaviKit.sys.power_btn && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){ - osTimerStart(PwrBtnLongPressTimerHandle,1500); - osTimerStart(PwrBtnShortPressTimerHandle,100); - } - osDelay(2); - if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnLongPressTimerHandle)){ - osTimerStop(PwrBtnLongPressTimerHandle); - osTimerStop(PwrBtnShortPressTimerHandle); - } - osDelay(2); - //custom button - if(!NaviKit.sys.custom_btn && osTimerIsRunning(CustBtnLongPressTimerHandle)){ - osTimerStop(CustBtnLongPressTimerHandle); - osTimerStop(CustBtnShortPressTimerHandle); - } - osDelay(2); - if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnLongPressTimerHandle)){ - osTimerStart(CustBtnLongPressTimerHandle,1500); - osTimerStart(CustBtnShortPressTimerHandle,100); - } - osDelay(2); - - - } - /* USER CODE END StartButtonDetect */ -} - - - - -void PwrBtnLongPressTimerCallback(void *argument) -{ - log_v("power btn long pressed."); - switch(NaviKit.sys.sta){ - case run: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;//system is run now, user request to idle - case idle: {NaviKit.sys.next_sta = run;log_v("change to run"); }break;//system is idle now , user request to power on - case dfu: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break; - case sleep:{NaviKit.sys.next_sta = run;log_v("change to run"); }break; - case isp: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break; - default : break; - } -} -void CustBtnLongPressTimerCallback(void *argument) -{ - log_v("custom btn long pressed."); - switch(NaviKit.sys.sta){ - case run:{//system is run now, user request to reboot SOM - som_reboot(100); - }break; - case idle:{ - }break; - case dfu:{ - som_reboot(100); - }break; - case sleep:{ - }break; - default : break; - } -} -void PwrBtnShortPressTimerCallback(void *argument) -{ - log_v("power btn short pressed."); - switch(NaviKit.sys.sta){ - case run: {//som is running, send sleep requeset to operate system - log_v("Request operate system pop up the shutdown dialog."); - PWR_Enable(SOM_SLEEP,true,100); - PWR_Enable(SOM_SLEEP,false,0); - }break; - case idle: { }break;//system is idle now , user request to power on - case dfu: { }break; - case sleep:{ }break; - case isp: { }break; - default : break; - } -} -void CustBtnShortPressTimerCallback(void *argument) -{ - log_v("custom btn short pressed."); - switch(NaviKit.sys.sta){ - case run:{ - }break; - case idle:{ - }break; - case dfu:{ - }break; - case sleep:{ - }break; - default : break; - } -} diff --git a/App/Src/th_cdc.c b/App/Src/th_cdc.c index 4508ca2..9debe6c 100644 --- a/App/Src/th_cdc.c +++ b/App/Src/th_cdc.c @@ -16,7 +16,7 @@ extern uint32_t number_restart; const osThreadAttr_t cdcMonitorTask_attributes = { .name = "cdcMonitorTask", .priority = (osPriority_t) osPriorityBelowNormal7, - .stack_size = 128 * 8 + .stack_size = 256 * 4 }; //task instance diff --git a/App/Src/th_demo.c b/App/Src/th_demo.c index 00e856b..e0dbf74 100644 --- a/App/Src/th_demo.c +++ b/App/Src/th_demo.c @@ -13,13 +13,13 @@ const osThreadAttr_t DemoTask1_attributes = { .name = "DemoTask1", - .priority = (osPriority_t) osPriorityLow2, - .stack_size = 128 * 8 + .priority = (osPriority_t) osPriorityLow1, + .stack_size = 256 * 4 }; const osThreadAttr_t DemoTask2_attributes = { .name = "DemoTask2", .priority = (osPriority_t) osPriorityLow1, - .stack_size = 128 * 8 + .stack_size = 256 * 4 }; void StartDemoTask1(void *argument){ uint8_t i=0; diff --git a/App/Src/th_elog.c b/App/Src/th_elog.c index 18c7431..e0f23a8 100644 --- a/App/Src/th_elog.c +++ b/App/Src/th_elog.c @@ -11,13 +11,18 @@ #include #include "main.h" +//semaphore +const osSemaphoreAttr_t ElogOutputBinarySem_attributes = { + .name = "ElogOutputBinarySem" +}; +//mutex const osMutexAttr_t ElogUartMutex_attributes = { .name = "ElogUartMutex" }; const osMutexAttr_t ElogOutputMutex_attributes = { .name = "ElogOutputMutex" }; - +//task const osThreadAttr_t ElogInitTask_attributes = { .name = "ElogInitTask", .priority = (osPriority_t) osPriorityNormal, @@ -27,7 +32,7 @@ const osThreadAttr_t ElogInitTask_attributes = { const osThreadAttr_t ElogFlushTask_attributes = { .name = "ElogFlushTask", .priority = (osPriority_t) osPriorityLow, - .stack_size = 128 * 8 + .stack_size = 256 * 4 }; void StartElogInitTask(void *argument){ @@ -39,8 +44,7 @@ void StartElogInitTask(void *argument){ void StartElogFlushTask(void *argument){ - uint8_t i=0; - log_d("Start Elog Flush Task"); + log_d("Start log Flush Task"); for(;;){ elog_flush(); osDelay(1); diff --git a/App/Src/th_exti.c b/App/Src/th_exti.c new file mode 100644 index 0000000..2f5b5a0 --- /dev/null +++ b/App/Src/th_exti.c @@ -0,0 +1,221 @@ +/* + * @Description: + * @Date: 2021-03-10 10:49:52 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 11:57:47 + * @FilePath: \NaviKit_EC_stm32\App\Src\th_button.c + */ +#define LOG_TAG "TH-Exti" + +#include +#include "main.h" +#include "navikit.h" + +//Thread +const osThreadAttr_t ExtiServiceTask_attributes = { + .name = "ExtiServiceTask", + .priority = (osPriority_t) osPriorityBelowNormal, + .stack_size = 256 * 4 +}; + +//Timer +const osTimerAttr_t PwrBtnLongPressTimer_attributes = { + .name = "PwrBtnLongPressTimer" +}; +const osTimerAttr_t CustBtnLongPressTimer_attributes = { + .name = "CustBtnLongPressTimer" +}; +const osTimerAttr_t PwrBtnShortPressTimer_attributes = { + .name = "PwrBtnShortPressTimer" +}; +const osTimerAttr_t CustBtnShortPressTimer_attributes = { + .name = "CustBtnShortPressTimer" +}; + +//Event Flag +const osEventFlagsAttr_t ExtiEventFlags_attributes = { + .name = "ExtiEventFlags" +}; + + +/* USER CODE BEGIN Header_StartExtiServiceTask */ +/** +* @brief Function implementing the ExtiServiceTask thread. +* @param argument: Not used +* @retval None +*/ +/* USER CODE END Header_StartExtiServiceTask */ +void StartExtiServiceTask(void *argument) +{ + /* USER CODE BEGIN StartExtiServiceTask */ + /* Infinite loop */ + uint32_t thread_flag = 0; + log_d("Start EXTI Service Task"); + for(;;) + { + thread_flag = osThreadFlagsGet(); + + if(thread_flag & SHUTDOWN_REQ){ + + } + if(thread_flag & MOD_SLEEP){ + + } + //powwer button + if((thread_flag & PWR_BTN) && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){ + osTimerStart(PwrBtnLongPressTimerHandle,LONG_PRESS_TIME); + osTimerStart(PwrBtnShortPressTimerHandle,SHORT_PRESS_TIME); + }else if(!(thread_flag & PWR_BTN) && osTimerIsRunning(PwrBtnLongPressTimerHandle)){ + osTimerStop(PwrBtnLongPressTimerHandle); + osTimerStop(PwrBtnShortPressTimerHandle); + } + //custom button + if((thread_flag & CUS_BTN) && !osTimerIsRunning(CustBtnLongPressTimerHandle)) { + osTimerStart(CustBtnLongPressTimerHandle,LONG_PRESS_TIME); + osTimerStart(CustBtnShortPressTimerHandle,SHORT_PRESS_TIME); + }else if(!(thread_flag & CUS_BTN) && osTimerIsRunning(CustBtnLongPressTimerHandle)){ + osTimerStop(CustBtnLongPressTimerHandle); + osTimerStop(CustBtnShortPressTimerHandle); + } + +// //power button +// if(NaviKit.sys.power_btn && !osTimerIsRunning(PwrBtnLongPressTimerHandle)){ +// osTimerStart(PwrBtnLongPressTimerHandle,LONG_PRESS_TIME); +// osTimerStart(PwrBtnShortPressTimerHandle,SHORT_PRESS_TIME); +// } +// osDelay(2); +// if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnLongPressTimerHandle)){ +// osTimerStop(PwrBtnLongPressTimerHandle); +// osTimerStop(PwrBtnShortPressTimerHandle); +// } +// osDelay(2); + //custom button +// if(!NaviKit.sys.custom_btn && osTimerIsRunning(CustBtnLongPressTimerHandle)){ +// } +// osDelay(2); +// if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnLongPressTimerHandle)){ +// } +// osDelay(2); + osDelay(10); + + } + /* USER CODE END StartExtiServiceTask */ +} + + + + +void PwrBtnLongPressTimerCallback(void *argument) +{ + log_v("power button long pressed."); + switch(NaviKit.sys.sta){ + case run: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;//system is run now, user request to idle + case idle: {NaviKit.sys.next_sta = run;log_v("change to run"); }break;//system is idle now , user request to power on + case dfu: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break; + case sleep:{NaviKit.sys.next_sta = run;log_v("change to run"); }break; + case isp: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break; + default : break; + } +} +void CustBtnLongPressTimerCallback(void *argument) +{ + log_v("custom button long pressed."); + switch(NaviKit.sys.sta){ + case run:{//system is run now, user request to reboot SOM + som_reboot(100); + }break; + case idle:{ + }break; + case dfu:{ + som_reboot(100); + }break; + case sleep:{ + }break; + default : break; + } +} +void PwrBtnShortPressTimerCallback(void *argument) +{ + log_v("power button short pressed."); + switch(NaviKit.sys.sta){ + case run: {//som is running, send sleep requeset to operate system + log_v("Request operate system pop up the shutdown dialog."); + PWR_Enable(SOM_SLEEP,true,100); + PWR_Enable(SOM_SLEEP,false,0); + }break; + case idle: { }break;//system is idle now , user request to power on + case dfu: { }break; + case sleep:{ }break; + case isp: { }break; + default : break; + } +} +void CustBtnShortPressTimerCallback(void *argument) +{ + log_v("custom button short pressed."); + switch(NaviKit.sys.sta){ + case run:{ + }break; + case idle:{ + }break; + case dfu:{ + }break; + case sleep:{ + }break; + default : break; + } +} + + + +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) +{ + switch (GPIO_Pin){ + case SOM_SHUTDOWN_REQ_Pin:{ + if(HAL_GPIO_ReadPin(SOM_SHUTDOWN_REQ_GPIO_Port, SOM_SHUTDOWN_REQ_Pin)==GPIO_PIN_RESET){//falling edge trigger + if(NaviKit.sys.sta == run){//if jetson nano shutdown output low,the power_en should be set low less than 10us + PWR_Enable(SOM_PWR_EN,false,0); + NaviKit.sys.next_sta = idle; + osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)SHUTDOWN_REQ_ACTIVE); +// log_i("SOM's shutdown_req pin falling edge, SOM request to shutdown."); + } + }else{//Rising edge trigger + osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)SHUTDOWN_REQ_INACTIVE); + } + }break; + + case SOM_MOD_SLEEP_Pin:{ + if(HAL_GPIO_ReadPin(SOM_MOD_SLEEP_GPIO_Port, SOM_MOD_SLEEP_Pin)==GPIO_PIN_SET){//Rising edge trigger +// log_i("SOM's sleep pin rising edge."); + osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)MOD_SLEEP_ACTIVE); + }else{//falling edge trigger +// log_v("SOM's sleep pin falling edge."); + osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)MOD_SLEEP_INACTIVE); + } + }break; + case SYS_POWER_BTN_Pin:{ + if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){//Rising edge trigger + NaviKit.sys.power_btn = true; +// log_v("power_btn status: pressed."); + osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)PWR_BTN_ACTIVE); + }else{//falling edge trigger + NaviKit.sys.power_btn = false; +// log_v("power_btn status: released."); + osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)PWR_BTN_INACTIVE); + } + }break; + case SYS_CUSTOM_BTN_Pin:{ + if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){//falling edge trigger +// log_v("custom_btn status: pressed."); + NaviKit.sys.custom_btn = true; + osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)CUS_BTN_ACTIVE); + }else{//Rising edge trigger +// log_v("custom_btn status: released."); + NaviKit.sys.custom_btn = false; + osThreadFlagsSet(ExtiServiceTaskHandle,(Exti_Flags_t)CUS_BTN_INACTIVE); + } + }break; + } + +} + diff --git a/App/Src/th_info.c b/App/Src/th_info.c new file mode 100644 index 0000000..09f2259 --- /dev/null +++ b/App/Src/th_info.c @@ -0,0 +1,24 @@ +/* + * @Description: + * @Date: 2021-03-09 18:19:26 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 15:07:01 + * @FilePath: \NaviKit_EC_stm32\App\Src\th_demo.c + */ +#define LOG_TAG "TH-Info" + +#include +#include "main.h" + + +const osThreadAttr_t InfoOutputTask_attributes = { + .name = "InfoOutputTask", + .priority = (osPriority_t) osPriorityLow2, + .stack_size = 256 * 4 +}; +void StartInfoOutputTask(void *argument){ + log_d("Start Info Output Task"); + for(;;){ + osThreadExit(); + } +} diff --git a/App/Src/th_iwdg.c b/App/Src/th_iwdg.c index 54b779b..9fdfd3c 100644 --- a/App/Src/th_iwdg.c +++ b/App/Src/th_iwdg.c @@ -15,7 +15,7 @@ const osThreadAttr_t IWDGTask_attributes = { .name = "IWDGTask", .priority = (osPriority_t) osPriorityHigh, - .stack_size = 128 * 8 + .stack_size = 256 * 4 }; void StartIWDGTask(void *argument){ diff --git a/App/Src/th_led.c b/App/Src/th_led.c index a00549c..ed05358 100644 --- a/App/Src/th_led.c +++ b/App/Src/th_led.c @@ -14,7 +14,7 @@ const osThreadAttr_t LedBlinkTask_attributes = { .name = "LedBlinkTask", .priority = (osPriority_t) osPriorityLow7, - .stack_size = 128 * 8 + .stack_size = 256 * 4 }; /* USER CODE BEGIN Header_StartLedBlinkTask */ diff --git a/App/Src/th_power.c b/App/Src/th_power.c index 811b6a4..c943016 100644 --- a/App/Src/th_power.c +++ b/App/Src/th_power.c @@ -15,7 +15,7 @@ const osThreadAttr_t PowerMonitTask_attributes = { .name = "PowerMonitTask", .priority = (osPriority_t) osPriorityBelowNormal, - .stack_size = 128 * 8 + .stack_size = 256 * 4 }; diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h index 7f4b630..ef267b8 100644 --- a/Core/Inc/FreeRTOSConfig.h +++ b/Core/Inc/FreeRTOSConfig.h @@ -64,13 +64,15 @@ #define configTICK_RATE_HZ ((TickType_t)1000) #define configMAX_PRIORITIES ( 56 ) #define configMINIMAL_STACK_SIZE ((uint16_t)128) -#define configTOTAL_HEAP_SIZE ((size_t)8192) +#define configTOTAL_HEAP_SIZE ((size_t)16384) #define configMAX_TASK_NAME_LEN ( 32 ) #define configGENERATE_RUN_TIME_STATS 1 +#define configUSE_TRACE_FACILITY 1 +#define configUSE_STATS_FORMATTING_FUNCTIONS 1 #define configUSE_16_BIT_TICKS 0 #define configUSE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 8 -#define configCHECK_FOR_STACK_OVERFLOW 1 +#define configCHECK_FOR_STACK_OVERFLOW 2 #define configUSE_RECURSIVE_MUTEXES 1 #define configUSE_COUNTING_SEMAPHORES 1 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 diff --git a/Core/Inc/navikit.h b/Core/Inc/navikit.h index 911c984..591a442 100644 --- a/Core/Inc/navikit.h +++ b/Core/Inc/navikit.h @@ -26,6 +26,7 @@ #define ADC_CH_COUNT 5+2 //number of adc channels (include temp sensor and vrefint adc_in17) + typedef enum { standby, //minimum current state diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index 1730c5d..36df4b6 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include @@ -71,7 +71,7 @@ const osTimerAttr_t IdleStateHoldTimer_attributes = { osThreadId_t defaultTaskHandle; const osThreadAttr_t defaultTask_attributes = { .name = "defaultTask", - .stack_size = 128 * 8, + .stack_size = 256 * 4, .priority = (osPriority_t) osPriorityNormal, }; @@ -82,7 +82,7 @@ void IdleStateHoldTimerCallback(void *argument); bool isWakeUpFromReset() { return __HAL_PWR_GET_FLAG(PWR_FLAG_WU);} -//__HAL_RCC_GET_FLAG(); //判断复位源 +//__HAL_RCC_GET_FLAG(); //judge reset source flag /* USER CODE END FunctionPrototypes */ @@ -143,6 +143,8 @@ void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName) /* Run time stack overflow checking is performed if configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is called if a stack overflow is detected. */ + + while(1); } /* USER CODE END 4 */ @@ -168,7 +170,8 @@ __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime) void MX_FREERTOS_Init(void) { /* USER CODE BEGIN Init */ - ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes); + // ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes); + ElogOutputBinarySemHandle = osSemaphoreNew(1, 1, &ElogOutputBinarySem_attributes); // ElogUartMutexHandle = osMutexNew(&ElogUartMutex_attributes); my_elog_init(); NaviKit_var_init(); @@ -181,6 +184,7 @@ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN RTOS_SEMAPHORES */ /* add semaphores, ... */ + /* USER CODE END RTOS_SEMAPHORES */ /* USER CODE BEGIN RTOS_TIMERS */ @@ -195,7 +199,6 @@ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN RTOS_QUEUES */ /* add queues, ... */ -// LogMessageQueueHandle = osMessageQueueNew (1024, sizeof(uint8_t), &LogMessageQueue_attributes); /* USER CODE END RTOS_QUEUES */ @@ -215,7 +218,7 @@ void MX_FREERTOS_Init(void) { //Button-------------------------------------------- - ButtonDetectTaskHandle = osThreadNew(StartButtonDetectTask, NULL, &ButtonDetectTask_attributes); + ExtiServiceTaskHandle = osThreadNew(StartExtiServiceTask, NULL, &ExtiServiceTask_attributes); //LED-------------------------------------------- @@ -223,7 +226,7 @@ void MX_FREERTOS_Init(void) { //CDC-------------------------------------------- - cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes); + cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes); //Coulomb-------------------------------------------- @@ -237,15 +240,15 @@ void MX_FREERTOS_Init(void) { #endif //Demo-------------------------------------------- -DemoTask1Handle = osThreadNew(StartDemoTask1, NULL, &DemoTask1_attributes); -DemoTask2Handle = osThreadNew(StartDemoTask2, NULL, &DemoTask2_attributes); + DemoTask1Handle = osThreadNew(StartDemoTask1, NULL, &DemoTask1_attributes); + DemoTask2Handle = osThreadNew(StartDemoTask2, NULL, &DemoTask2_attributes); /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ /* add events, ... */ - + ExtiEventFlags = osEventFlagsNew(&ExtiEventFlags_attributes); /* USER CODE END RTOS_EVENTS */ } diff --git a/Core/Src/main.c b/Core/Src/main.c index 35fc979..6dd2553 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -173,8 +173,8 @@ void SystemClock_Config(void) |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV4; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV16; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { @@ -189,6 +189,9 @@ void SystemClock_Config(void) { Error_Handler(); } + /** Enables the Clock Security System + */ + HAL_RCC_EnableCSS(); /** Configure the Systick interrupt time */ __HAL_RCC_PLLI2S_ENABLE(); diff --git a/Core/Src/navikit.c b/Core/Src/navikit.c index 2cfdfe5..f185265 100644 --- a/Core/Src/navikit.c +++ b/Core/Src/navikit.c @@ -57,60 +57,17 @@ void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc) HAL_ADCEx_Calibration_Start(&hadc1); } -void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) -{ - switch (GPIO_Pin){ - case SOM_SHUTDOWN_REQ_Pin:{ - if(HAL_GPIO_ReadPin(SOM_SHUTDOWN_REQ_GPIO_Port, SOM_SHUTDOWN_REQ_Pin)==GPIO_PIN_RESET){//falling edge trigger - if(NaviKit.sys.sta == run){//if jetson nano shutdown output low,the power_en should be set low less than 10us - PWR_Enable(SOM_PWR_EN,false,0); - NaviKit.sys.next_sta = idle; - log_i("SOM's shutdown_req pin falling edge, SOM request to shutdown."); - } - }else{//Rising edge trigger - } - }break; - - case SOM_MOD_SLEEP_Pin:{ - if(HAL_GPIO_ReadPin(SOM_MOD_SLEEP_GPIO_Port, SOM_MOD_SLEEP_Pin)==GPIO_PIN_SET){//Rising edge trigger - log_i("SOM's sleep pin rising edge."); - }else{//falling edge trigger - log_v("SOM's sleep pin falling edge."); - } - }break; - case SYS_POWER_BTN_Pin:{ - if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){//Rising edge trigger - NaviKit.sys.power_btn = true; - log_v("power_btn status: pressed."); - }else{//falling edge trigger - NaviKit.sys.power_btn = false; - log_v("power_btn status: released."); - } - }break; - case SYS_CUSTOM_BTN_Pin:{ - if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){//falling edge trigger - log_v("custom_btn status: pressed."); - NaviKit.sys.custom_btn = true; - }else{//Rising edge trigger - log_v("custom_btn status: released."); - NaviKit.sys.custom_btn = false; - } - }break; - } - -} - void enter_standby_state(){ log_i("EC enter to STANDBY Mode to save power, see you!"); osDelay(10); - HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);//Enable PA0 wakeup function - __HAL_RCC_RTC_DISABLE(); + HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);//Enable PA0 wakeup function + __HAL_RCC_RTC_DISABLE(); HAL_PWR_EnterSTANDBYMode(); } -//write "bios update flag" to bkp register, and reset system void enter_isp_state() { + //write "bios update flag" to bkp register, and reset system ISP_Prepare(); } diff --git a/Core/Src/stm32f1xx_it.c b/Core/Src/stm32f1xx_it.c index 805c18d..d787a4d 100644 --- a/Core/Src/stm32f1xx_it.c +++ b/Core/Src/stm32f1xx_it.c @@ -84,6 +84,7 @@ void NMI_Handler(void) /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ /* USER CODE END NonMaskableInt_IRQn 0 */ + HAL_RCC_NMI_IRQHandler(); /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ /* USER CODE END NonMaskableInt_IRQn 1 */ diff --git a/Core/Src/usart.c b/Core/Src/usart.c index cbb36ca..5666729 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -43,7 +43,7 @@ void MX_UART4_Init(void) /* USER CODE END UART4_Init 1 */ huart4.Instance = UART4; - huart4.Init.BaudRate = 56000; + huart4.Init.BaudRate = 115200; huart4.Init.WordLength = UART_WORDLENGTH_8B; huart4.Init.StopBits = UART_STOPBITS_1; huart4.Init.Parity = UART_PARITY_NONE; @@ -72,7 +72,7 @@ void MX_USART1_UART_Init(void) /* USER CODE END USART1_Init 1 */ huart1.Instance = USART1; - huart1.Init.BaudRate = 56000; + huart1.Init.BaudRate = 115200; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; diff --git a/Middlewares/EasyLogger b/Middlewares/EasyLogger index 32679ed..a813ff5 160000 --- a/Middlewares/EasyLogger +++ b/Middlewares/EasyLogger @@ -1 +1 @@ -Subproject commit 32679ed89f7364d5f7d5281ba1b8319434ced00c +Subproject commit a813ff549eeec5fa41af5604770092e62ab504fc diff --git a/NaviKit_EC_stm32.ioc b/NaviKit_EC_stm32.ioc index 8e24c9e..43c80ef 100644 --- a/NaviKit_EC_stm32.ioc +++ b/NaviKit_EC_stm32.ioc @@ -115,19 +115,19 @@ FREERTOS.INCLUDE_xTaskAbortDelay=1 FREERTOS.INCLUDE_xTaskGetCurrentTaskHandle=1 FREERTOS.INCLUDE_xTaskGetHandle=1 FREERTOS.IPParameters=Tasks01,configMAX_TASK_NAME_LEN,configUSE_TICKLESS_IDLE,INCLUDE_xTaskGetCurrentTaskHandle,INCLUDE_xTaskGetHandle,configUSE_APPLICATION_TASK_TAG,FootprintOK,configUSE_IDLE_HOOK,configUSE_TICK_HOOK,configUSE_MALLOC_FAILED_HOOK,configGENERATE_RUN_TIME_STATS,configUSE_STATS_FORMATTING_FUNCTIONS,configUSE_TRACE_FACILITY,HEAP_NUMBER,configTOTAL_HEAP_SIZE,configCHECK_FOR_STACK_OVERFLOW,configUSE_TASK_NOTIFICATIONS,INCLUDE_xTaskAbortDelay,INCLUDE_xEventGroupSetBitFromISR,INCLUDE_xSemaphoreGetMutexHolder,INCLUDE_pcTaskGetTaskName,INCLUDE_vTaskCleanUpResources -FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL -FREERTOS.configCHECK_FOR_STACK_OVERFLOW=1 +FREERTOS.Tasks01=defaultTask,24,256,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL +FREERTOS.configCHECK_FOR_STACK_OVERFLOW=2 FREERTOS.configGENERATE_RUN_TIME_STATS=1 FREERTOS.configMAX_TASK_NAME_LEN=32 -FREERTOS.configTOTAL_HEAP_SIZE=8192 +FREERTOS.configTOTAL_HEAP_SIZE=16384 FREERTOS.configUSE_APPLICATION_TASK_TAG=0 FREERTOS.configUSE_IDLE_HOOK=1 FREERTOS.configUSE_MALLOC_FAILED_HOOK=0 -FREERTOS.configUSE_STATS_FORMATTING_FUNCTIONS=0 +FREERTOS.configUSE_STATS_FORMATTING_FUNCTIONS=1 FREERTOS.configUSE_TASK_NOTIFICATIONS=1 FREERTOS.configUSE_TICKLESS_IDLE=1 FREERTOS.configUSE_TICK_HOOK=1 -FREERTOS.configUSE_TRACE_FACILITY=0 +FREERTOS.configUSE_TRACE_FACILITY=1 File.Version=6 GPIO.groupedBy=Group By Peripherals IWDG.IPParameters=Prescaler,Reload @@ -248,7 +248,7 @@ NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.I2C1_ER_IRQn=true\:5\:0\:true\:true\:true\:7\:false\:true\:true NVIC.I2C1_EV_IRQn=true\:5\:0\:false\:true\:true\:6\:true\:true\:true NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true NVIC.OTG_FS_IRQn=true\:5\:0\:false\:true\:true\:4\:true\:false\:true NVIC.PVD_IRQn=true\:5\:0\:true\:true\:true\:1\:false\:true\:true NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:false @@ -594,7 +594,7 @@ ProjectManager.DeviceId=STM32F107VCTx ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.3 ProjectManager.FreePins=false ProjectManager.HalAssertFull=false -ProjectManager.HeapSize=0x400 +ProjectManager.HeapSize=0x1f00 ProjectManager.KeepUserCode=true ProjectManager.LastFirmware=true ProjectManager.LibraryCopy=1 @@ -605,28 +605,29 @@ ProjectManager.ProjectBuild=false ProjectManager.ProjectFileName=NaviKit_EC_stm32.ioc ProjectManager.ProjectName=NaviKit_EC_stm32 ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x800 +ProjectManager.StackSize=0x1f00 ProjectManager.TargetToolchain=STM32CubeIDE ProjectManager.ToolChainLocation= ProjectManager.UnderRoot=true ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-true,4-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,5-MX_I2C1_Init-I2C1-false-HAL-true,6-MX_IWDG_Init-IWDG-false-HAL-true,7-MX_UART4_Init-UART4-false-HAL-true,8-MX_ADC1_Init-ADC1-false-HAL-true,9-MX_USART1_UART_Init-USART1-false-HAL-true,10-MX_RTC_Init-RTC-false-HAL-true -RCC.ADCFreqValue=140625 +RCC.ADCFreqValue=562500 RCC.ADCPresc=RCC_ADCPCLK2_DIV8 RCC.AHBCLKDivider=RCC_SYSCLK_DIV4 RCC.AHBFreq_Value=18000000 -RCC.APB1CLKDivider=RCC_HCLK_DIV16 -RCC.APB1Freq_Value=1125000 -RCC.APB1TimFreq_Value=2250000 -RCC.APB2CLKDivider=RCC_HCLK_DIV16 -RCC.APB2Freq_Value=1125000 -RCC.APB2TimFreq_Value=2250000 +RCC.APB1CLKDivider=RCC_HCLK_DIV4 +RCC.APB1Freq_Value=4500000 +RCC.APB1TimFreq_Value=9000000 +RCC.APB2CLKDivider=RCC_HCLK_DIV4 +RCC.APB2Freq_Value=4500000 +RCC.APB2TimFreq_Value=9000000 +RCC.EnbaleCSS=true RCC.FCLKCortexFreq_Value=18000000 RCC.FamilyName=M RCC.HCLKFreq_Value=18000000 RCC.HSE_VALUE=12000000 RCC.I2S2Freq_Value=72000000 RCC.I2S3Freq_Value=72000000 -RCC.IPParameters=ADCFreqValue,ADCPresc,AHBCLKDivider,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,I2S2Freq_Value,I2S3Freq_Value,MCOFreq_Value,PLL2CLKoutputFreqValue,PLL2VCOoutputFreqValue,PLL3CLKoutputFreqValue,PLL3VCOoutputFreqValue,PLLCLKFreq_Value,PLLMUL,Prediv2,Prediv2FreqValue,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,TimSys_Div,USBFreq_Value,VCOOutput2Freq_Value +RCC.IPParameters=ADCFreqValue,ADCPresc,AHBCLKDivider,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,EnbaleCSS,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,I2S2Freq_Value,I2S3Freq_Value,MCOFreq_Value,PLL2CLKoutputFreqValue,PLL2VCOoutputFreqValue,PLL3CLKoutputFreqValue,PLL3VCOoutputFreqValue,PLLCLKFreq_Value,PLLMUL,Prediv2,Prediv2FreqValue,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,TimSys_Div,USBFreq_Value,VCOOutput2Freq_Value RCC.MCOFreq_Value=72000000 RCC.PLL2CLKoutputFreqValue=6000000 RCC.PLL2VCOoutputFreqValue=12000000 @@ -666,11 +667,11 @@ SH.GPXTI7.0=GPIO_EXTI7 SH.GPXTI7.ConfNb=1 SH.GPXTI8.0=GPIO_EXTI8 SH.GPXTI8.ConfNb=1 -UART4.BaudRate=56000 +UART4.BaudRate=115200 UART4.IPParameters=VirtualMode,BaudRate UART4.IPParametersWithoutCheck=BaudRate UART4.VirtualMode=Asynchronous -USART1.BaudRate=56000 +USART1.BaudRate=115200 USART1.IPParameters=VirtualMode,WordLength,BaudRate USART1.VirtualMode=VM_ASYNC USART1.WordLength=WORDLENGTH_8B diff --git a/Utils/CPU/Release_Notes.html b/Utils/CPU/Release_Notes.html new file mode 100644 index 0000000..0ed2957 --- /dev/null +++ b/Utils/CPU/Release_Notes.html @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + Release Notes for STM32Cube CPU Utilities Driver + + + + + + + + + +
+


+

+
+ + + + + + +
+ + + + + + + + + +
+

Back to Release page

+
+

Release +Notes for STM32Cube CPU Utilities Driver

+

Copyright +2014 STMicroelectronics

+

+
+

 

+ + + + + + +
+

Update History

+

V1.1.0 / 20-November-2014

+ + + + + + + +

Main +Changes

+ + + + + + + +

+ + + + + +
    +
  • Update some APIs to be in line with FreeRTOS V8.1.2
  • +
+ +

V1.0.0 / 18-February-2014

+ + + + + +

Main +Changes

+ + + + + +

+ + + +
    +
  • First official release
    +
  • +

License

+
+Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met:
+
+
  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions +in binary form must reproduce the above copyright notice, this list of +conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of STMicroelectronics nor the names of its contributors may be used to endorse or promote products derived
    +
    +
+        from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ +
+

+ + +
+
+

For +complete documentation on STM32 Microcontrollers +visit www.st.com/STM32

+
+

+
+
+

 

+
+ + \ No newline at end of file diff --git a/Utils/CPU/cpu_utils.c b/Utils/CPU/cpu_utils.c new file mode 100644 index 0000000..748e4ae --- /dev/null +++ b/Utils/CPU/cpu_utils.c @@ -0,0 +1,144 @@ +/** + ****************************************************************************** + * @file cpu_utils.c + * @author MCD Application Team + * @version V1.1.0 + * @date 20-November-2014 + * @brief Utilities for CPU Load calculation + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2014 STMicroelectronics

+ * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/********************** 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" + +/* 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 functions ---------------------------------------------------------*/ +/** + * @brief Application Idle Hook + * @param None + * @retval None + */ +void vApplicationIdleHook(void) +{ + if( xIdleHandle == NULL ) + { + /* Store the handle to the idle task. */ + xIdleHandle = xTaskGetCurrentTaskHandle(); + } +} + +/** + * @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; + } + osCPU_Usage = (100 - (osCPU_TotalIdleTime * 100) / CALCULATION_PERIOD); + osCPU_TotalIdleTime = 0; + } +} + +/** + * @brief Start Idle monitor + * @param None + * @retval None + */ +void StartIdleMonitor (void) +{ + if( xTaskGetCurrentTaskHandle() == xIdleHandle ) + { + osCPU_IdleStartTime = xTaskGetTickCountFromISR(); + } +} + +/** + * @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; + } +} + +/** + * @brief Stop Idle monitor + * @param None + * @retval None + */ +uint16_t osGetCPUUsage (void) +{ + return (uint16_t)osCPU_Usage; +} + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Utils/CPU/cpu_utils.h b/Utils/CPU/cpu_utils.h new file mode 100644 index 0000000..839981c --- /dev/null +++ b/Utils/CPU/cpu_utils.h @@ -0,0 +1,64 @@ +/** + ****************************************************************************** + * @file cpu_utils.h + * @author MCD Application Team + * @version V1.1.0 + * @date 20-November-2014 + * @brief Header for cpu_utils module + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2014 STMicroelectronics

+ * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef _CPU_UTILS_H__ +#define _CPU_UTILS_H__ + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported variables --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +#define CALCULATION_PERIOD 1000 + +/* Exported functions ------------------------------------------------------- */ +uint16_t osGetCPUUsage (void); + +#ifdef __cplusplus +} +#endif + +#endif /* _CPU_UTILS_H__ */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/