From 28148e57b43a95570c345f3c9c270b1bd08523be Mon Sep 17 00:00:00 2001 From: ThinkPad-T460P Date: Wed, 10 Mar 2021 11:03:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cproject | 39 +-- App/Inc/th_button.h | 41 +++ App/Inc/th_coulomb.h | 19 ++ App/Inc/th_elog.h | 6 + App/Inc/th_led.h | 19 ++ App/Inc/th_power.h | 18 ++ App/Src/th_button.c | 149 ++++++++++ App/Src/th_coulomb.c | 55 ++++ App/Src/th_demo.c | 2 + App/Src/th_elog.c | 61 ++--- App/Src/th_led.c | 80 ++++++ App/Src/th_power.c | 103 +++++++ Core/Inc/main.h | 12 +- Core/Inc/navikit.h | 1 + Core/Src/freertos.c | 464 ++++++-------------------------- Core/Src/usart.c | 2 +- NaviKit_EC_stm32 Release.launch | 71 +++++ USB_DEVICE/App/usbd_cdc_if.c | 2 +- USB_DEVICE/Target/usbd_conf.h | 9 +- 19 files changed, 699 insertions(+), 454 deletions(-) create mode 100644 App/Inc/th_button.h create mode 100644 App/Inc/th_coulomb.h create mode 100644 App/Inc/th_led.h create mode 100644 App/Inc/th_power.h create mode 100644 App/Src/th_button.c create mode 100644 App/Src/th_coulomb.c create mode 100644 App/Src/th_led.c create mode 100644 App/Src/th_power.c create mode 100644 NaviKit_EC_stm32 Release.launch diff --git a/.cproject b/.cproject index 2837e5d..7fde85f 100644 --- a/.cproject +++ b/.cproject @@ -3,7 +3,9 @@ - + + + @@ -38,7 +40,7 @@ + + + diff --git a/App/Inc/th_button.h b/App/Inc/th_button.h new file mode 100644 index 0000000..3596128 --- /dev/null +++ b/App/Inc/th_button.h @@ -0,0 +1,41 @@ +/* + * @Description: + * @Date: 2021-03-10 10:50:02 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 10:56:12 + * @FilePath: \NaviKit_EC_stm32\App\Inc\th_button.h + */ +#ifndef __TH_BUTTON_H__ +#define __TH_BUTTON_H__ + +#include "cmsis_os2.h" + +/* Definitions for ButtonDetect */ +osThreadId_t ButtonDetectHandle; +const osThreadAttr_t ButtonDetect_attributes; + +//Timer +osTimerId_t PwrBtnLongPressTimerHandle; +const osTimerAttr_t PwrBtnLongPressTimer_attributes; + +osTimerId_t CustBtnLongPressTimerHandle; +const osTimerAttr_t CustBtnLongPressTimer_attributes; + +osTimerId_t PwrBtnShortPressTimerHandle; +const osTimerAttr_t PwrBtnShortPressTimer_attributes; + +osTimerId_t CustBtnShortPressTimerHandle; +const osTimerAttr_t CustBtnShortPressTimer_attributes; + +osTimerId_t IdleStateHoldTimerHandle; +const osTimerAttr_t IdleStateHoldTimer_attributes; + +void StartButtonDetect(void *argument); + +//callback +void PwrBtnLongPressTimerCallback(void *argument); +void CustBtnLongPressTimerCallback(void *argument); +void PwrBtnShortPressTimerCallback(void *argument); +void CustBtnShortPressTimerCallback(void *argument); + +#endif diff --git a/App/Inc/th_coulomb.h b/App/Inc/th_coulomb.h new file mode 100644 index 0000000..5bc97ab --- /dev/null +++ b/App/Inc/th_coulomb.h @@ -0,0 +1,19 @@ +/* + * @Description: + * @Date: 2021-03-10 10:36:01 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 10:39:06 + * @FilePath: \NaviKit_EC_stm32\App\Inc\th_coulomb.h + */ +#ifndef __TH_COULOMB_H__ +#define __TH_COULOMB_H__ + +#include "cmsis_os2.h" + +osThreadId_t CoulombReadHandle; + +const osThreadAttr_t CoulombRead_attributes; + +void StartCoulombRead(void *argument); + +#endif diff --git a/App/Inc/th_elog.h b/App/Inc/th_elog.h index 57e11e6..b6f5a1b 100644 --- a/App/Inc/th_elog.h +++ b/App/Inc/th_elog.h @@ -2,9 +2,15 @@ #define __TH_ELOG_H__ #include "cmsis_os2.h" + osThreadId_t ElogInitTaskHandle; +osThreadId_t ElogFlushTaskHandle; + const osThreadAttr_t ElogInitTask_attributes; +const osThreadAttr_t ElogFlushTask_attributes; void StartElogInitTask(void *argument); +void StartElogFlushTask(void *argument); + void my_elog_init(); #endif diff --git a/App/Inc/th_led.h b/App/Inc/th_led.h new file mode 100644 index 0000000..19a93cc --- /dev/null +++ b/App/Inc/th_led.h @@ -0,0 +1,19 @@ +/* + * @Description: + * @Date: 2021-03-10 10:11:23 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 10:12:24 + * @FilePath: \NaviKit_EC_stm32\App\Inc\th_led.h + */ +#ifndef __TH_LED_H__ +#define __TH_LED_H__ + +#include "cmsis_os2.h" + +/* Definitions for LedBlinkTask */ +osThreadId_t LedBlinkTaskHandle; +const osThreadAttr_t LedBlinkTask_attributes; +void StartLedBlinkTask(void *argument); + + +#endif diff --git a/App/Inc/th_power.h b/App/Inc/th_power.h new file mode 100644 index 0000000..307dd03 --- /dev/null +++ b/App/Inc/th_power.h @@ -0,0 +1,18 @@ +/* + * @Description: + * @Date: 2021-03-10 10:44:21 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 10:45:51 + * @FilePath: \NaviKit_EC_stm32\App\Inc\th_power.h + */ +#ifndef __TH_POWER_H__ +#define __TH_POWER_H__ + +#include "cmsis_os2.h" + +/* Definitions for PowerMonitTask */ +osThreadId_t PowerMonitTaskHandle; +const osThreadAttr_t PowerMonitTask_attributes; + +void StartPowerMonitTask(void *argument); +#endif diff --git a/App/Src/th_button.c b/App/Src/th_button.c new file mode 100644 index 0000000..e6274f8 --- /dev/null +++ b/App/Src/th_button.c @@ -0,0 +1,149 @@ +/* + * @Description: + * @Date: 2021-03-10 10:49:52 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 10:56:58 + * @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 ButtonDetect_attributes = { + .name = "ButtonDetect", + .priority = (osPriority_t) osPriorityLow, + .stack_size = 128 * 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" +}; +const osTimerAttr_t IdleStateHoldTimer_attributes = { + .name = "IdleStateHoldTimer" +}; + + +/* USER CODE BEGIN Header_StartButtonDetect */ +/** +* @brief Function implementing the ButtonDetect thread. +* @param argument: Not used +* @retval None +*/ +/* USER CODE END Header_StartButtonDetect */ +void StartButtonDetect(void *argument) +{ + /* USER CODE BEGIN StartButtonDetect */ + /* Infinite loop */ + log_v("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; + } +} +void IdleStateHoldTimerCallback(void *argument){ + if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){ + log_v("Idle state duration more than 5000ms."); + NaviKit.sys.next_sta = standby; + } +} diff --git a/App/Src/th_coulomb.c b/App/Src/th_coulomb.c new file mode 100644 index 0000000..9f331df --- /dev/null +++ b/App/Src/th_coulomb.c @@ -0,0 +1,55 @@ +/* + * @Description: + * @Date: 2021-03-10 10:35:58 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 10:38:44 + * @FilePath: \NaviKit_EC_stm32\App\Src\th_coulomb.c + */ +#define LOG_TAG "TH-Coulomb" + +#include +#include "coulomb.h" +#include "main.h" +#include "navikit.h" + + +/* Definitions for CoulombRead */ +const osThreadAttr_t CoulombRead_attributes = { + .name = "CoulombRead", + .priority = (osPriority_t) osPriorityLow, + .stack_size = 128 * 4 +}; + +/* USER CODE BEGIN Header_StartCoulombRead */ +/** +* @brief Function implementing the CoulombRead thread. +* @param argument: Not used +* @retval None +*/ +/* USER CODE END Header_StartCoulombRead */ +void StartCoulombRead(void *argument) +{ + /* USER CODE BEGIN StartCoulombRead */ + log_v("Start Coulomb Read Task"); + //写寄存器方法 + coulomb_write_config_load(); + coulomb_write_config_actual_to_raw(); + coulomb_write_config(); + //读寄存器方法 + coulomb_read_status_and_config(); + coulomb_read_status_raw_to_actual(); + coulomb_read_config_raw_to_actual(); + + /* Infinite loop */ + for(;;) + { + coulomb_read_status_and_config(); + coulomb_read_status_raw_to_actual(); + if(NaviKit.sys.sta == run) + osDelay(500); + else + osDelay(5000); + + } + /* USER CODE END StartCoulombRead */ +} diff --git a/App/Src/th_demo.c b/App/Src/th_demo.c index 1e51e56..c61edb3 100644 --- a/App/Src/th_demo.c +++ b/App/Src/th_demo.c @@ -16,6 +16,7 @@ const osThreadAttr_t DemoTask2_attributes = { }; void StartDemoTask1(void *argument){ uint8_t i=0; + log_v("Start Demo Task1"); for(;;){ log_v("demo task 1 [%d].",i++); osDelay(1000); @@ -23,6 +24,7 @@ void StartDemoTask1(void *argument){ } void StartDemoTask2(void *argument){ uint8_t i=0; + log_v("Start Demo Task2"); for(;;){ log_v("demo task 2 [%d].",i++); osDelay(1000); diff --git a/App/Src/th_elog.c b/App/Src/th_elog.c index 63041ba..d6334fd 100644 --- a/App/Src/th_elog.c +++ b/App/Src/th_elog.c @@ -2,7 +2,7 @@ * @Description: * @Date: 2021-03-09 11:30:52 * @LastEditors: CK.Zh - * @LastEditTime: 2021-03-09 17:50:24 + * @LastEditTime: 2021-03-10 10:59:15 * @FilePath: \NaviKit_EC_stm32\App\Src\th_elog.c */ @@ -14,58 +14,41 @@ const osThreadAttr_t ElogInitTask_attributes = { .name = "ElogInitTask", + .priority = (osPriority_t) osPriorityBelowNormal, + .stack_size = 128 * 4 +}; + +const osThreadAttr_t ElogFlushTask_attributes = { + .name = "ElogFlushTask", .priority = (osPriority_t) osPriorityLow, .stack_size = 128 * 4 }; void StartElogInitTask(void *argument){ - elog_init(); - /* close printf buffer */ - setbuf(stdout, NULL); -#ifndef DEBUG //release mode :only output level、tag、time information - ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME; -#else //debug mode:output all information - ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_ALL ; -#endif - /* set EasyLogger log format */ - /* 断言:输出所有内容 */ - elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_SETTING); - /* 错误:输出级别、标签和时间 */ - elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_SETTING); - /* 警告:输出级别、标签和时间 */ - elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_SETTING); - /* 信息:输出级别、标签和时间 */ - elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_SETTING); - /* 调试:输出除了方法名之外的所有内容 */ - elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_SETTING); - /* 详细:输出除了方法名之外的所有内容 */ - elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_SETTING); +// my_elog_init(); - /* start EasyLogger */ - elog_start(); - - - -// log_a("Hello EasyLogger!"); -// log_e("Hello EasyLogger!"); -// log_w("Hello EasyLogger!"); -// log_i("Hello EasyLogger!"); -// log_d("Hello EasyLogger!"); -// log_v("Hello EasyLogger!"); -// -// osDelay(10000); -// log_d("Hello EasyLogger!"); // osThreadExit();//exit this thread,execute this code only once } + +void StartElogFlushTask(void *argument){ + + log_v("Start Elog Flush Task"); + for(;;){ + elog_flush(); + osDelay(5); + } +} + + void my_elog_init(){ elog_init(); /* close printf buffer */ setbuf(stdout, NULL); -#ifndef DEBUG //release mode :only output level、tag、time information - ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME; -#else //debug mode:output all information +#ifdef DEBUG //debug mode:output all information ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_ALL ; +#else //release mode :only output level、tag、time information + ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME; #endif /* set EasyLogger log format */ /* 断言:输出所有内容 */ diff --git a/App/Src/th_led.c b/App/Src/th_led.c new file mode 100644 index 0000000..f734450 --- /dev/null +++ b/App/Src/th_led.c @@ -0,0 +1,80 @@ +/* + * @Description: + * @Date: 2021-03-10 10:11:18 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 10:13:16 + * @FilePath: \NaviKit_EC_stm32\App\Src\th_led.c + */ +#define LOG_TAG "TH-Led" + +#include +#include "main.h" +#include "navikit.h" + +const osThreadAttr_t LedBlinkTask_attributes = { + .name = "LedBlinkTask", + .priority = (osPriority_t) osPriorityLow, + .stack_size = 128 * 4 +}; + +/* USER CODE BEGIN Header_StartLedBlinkTask */ +/** +* @brief Function implementing the LedBlinkTask thread. +* @param argument: Not used +* @retval None +*/ +/* USER CODE END Header_StartLedBlinkTask */ +void StartLedBlinkTask(void *argument) +{ + /* USER CODE BEGIN StartLedBlinkTask */ + /* Infinite loop */ + log_v("Start LED Blink Task"); + for(;;) + { + + osDelay(1000); + switch(NaviKit.sys.sta){ + case run: { + PWR_Enable(SYS_PWR_LED,true,0);//turn on power led + + PWR_Enable(SYS_RUN_LED,true,50);//turn on sys run led + PWR_Enable(SYS_RUN_LED,false,0);//turn off sys run led + }break; + case idle:{ + PWR_Enable(SYS_PWR_LED,false,0);//turn on power led//turn off power led + + PWR_Enable(SYS_RUN_LED,true,20);//turn on sys run led + PWR_Enable(SYS_RUN_LED,false,3000);//turn off sys run led + }break; + case sleep:{//sleep mode + for(uint16_t i=0;i<25;i++){//20 light level + for(uint16_t j=0;j<3;j++){//the time length of every light level + PWR_Enable(SYS_PWR_LED,false,0); + PWR_Enable(SYS_RUN_LED,false,0); + osDelay(i); + PWR_Enable(SYS_PWR_LED,true,0); + PWR_Enable(SYS_RUN_LED,true,0); + osDelay(25-i); + } + } + for(uint16_t i=0;i<25;i++){ + for(uint16_t j=0;j<3;j++){ + PWR_Enable(SYS_PWR_LED,false,0); + PWR_Enable(SYS_RUN_LED,false,0); + osDelay(25-i); + PWR_Enable(SYS_PWR_LED,true,0); + PWR_Enable(SYS_RUN_LED,true,0); + osDelay(i); + } + } + }break; + case dfu:{ + PWR_Enable(SYS_PWR_LED,!PWR_Status(SYS_PWR_LED),0); + PWR_Enable(SYS_RUN_LED,!PWR_Status(SYS_PWR_LED),0); + }break; + default : break; + } + } + /* USER CODE END StartLedBlinkTask */ +} + diff --git a/App/Src/th_power.c b/App/Src/th_power.c new file mode 100644 index 0000000..034f266 --- /dev/null +++ b/App/Src/th_power.c @@ -0,0 +1,103 @@ +/* + * @Description: + * @Date: 2021-03-10 10:44:19 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-10 10:45:36 + * @FilePath: \NaviKit_EC_stm32\App\Src\th_power.c + */ +#define LOG_TAG "TH-Power" + +#include +#include "main.h" +#include "adc.h" +#include "navikit.h" + +const osThreadAttr_t PowerMonitTask_attributes = { + .name = "PowerMonitTask", + .priority = (osPriority_t) osPriorityLow, + .stack_size = 128 * 4 +}; + + +/* USER CODE BEGIN Header_StartPowerMonitTask */ +/** +* @brief Function: Monit som power status and PMB status +* @param argument: Not used +* @retval None +*/ +/* USER CODE END Header_StartPowerMonitTask */ +void StartPowerMonitTask(void *argument) +{ + /* USER CODE BEGIN StartPowerMonitTask */ + log_v("Start Power Monitor Task"); + HAL_ADCEx_Calibration_Start(&hadc1); + HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT); + osDelay(100); + /* Infinite loop */ + for(;;) + { + + if(NaviKit.pmb.rails.main_pwr > 30){ + TaskBeep(200,1); + log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); + } + if(NaviKit.pmb.rails.bkp_bat > 15){ + log_e("Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); + TaskBeep(200,1); + } + //stat1 stat2 lead-acid + //1 1 Not Charging + //1 0 Float Charge + //0 1 Absorption Charge + //0 0 Bulk Charge + NaviKit.pmb.sta.chrg_stat1 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT1_GPIO_Port, PMB_CHRG_STAT1_Pin); + NaviKit.pmb.sta.chrg_stat2 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT2_GPIO_Port, PMB_CHRG_STAT2_Pin); + + if(!NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2) + log_v("Backup battery status:%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); + if(!NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2) + log_v("Backup battery status:%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); + if(NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2) + log_v("Backup battery status:%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); + if(NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2) + log_v("Backup battery status:%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); + + if(NaviKit.sys.sta == run || NaviKit.sys.sta == dfu ){ + if(NaviKit.pmb.rails.main_pwr < 19){ + TaskBeep(200,1); + log_w("Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); + }else + log_v("Main power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); + + if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6) + log_e("24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000)); + else + log_v("24V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000)); + + if(NaviKit.pmb.rails.out_5v > 5.5 || NaviKit.pmb.rails.out_5v < 4.5) + log_e("5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000)); + else + log_v("5V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000)); + + if(NaviKit.pmb.rails.out_12v > 13.2 || NaviKit.pmb.rails.out_12v < 10.8) + log_e("12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000)); + else + log_v("12V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000)); + + if(NaviKit.pmb.rails.bkp_bat < 9.5) + log_w("Backup battery exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); + else + log_v("Backup battery is regular:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); + + osDelay(2000); + + }else {//not run state + osDelay(5000); + + } +// log_d("state :%d",NaviKit.sys.sta); +// log_d("next_state :%d",NaviKit.sys.next_sta); + + } + /* USER CODE END StartPowerMonitTask */ +} diff --git a/Core/Inc/main.h b/Core/Inc/main.h index ea2b4ca..91c0b3a 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -33,9 +33,9 @@ extern "C" { /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "stdbool.h" -#include "log.h" +#include "stdio.h" + #include "elog.h" -#include /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ @@ -57,7 +57,7 @@ extern "C" { void Error_Handler(void); /* USER CODE BEGIN EFP */ -void ISP_Judge(); + /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ @@ -190,12 +190,6 @@ void ISP_Judge(); #define APP_VERSION "v0.9.6" -#ifdef DEBUG -#define DEPLOY_MODE "DEBUG" //debug mode -#else -#define DEPLOY_MODE "RELEASE" //release mode -#endif - /* USER CODE END Private defines */ #ifdef __cplusplus diff --git a/Core/Inc/navikit.h b/Core/Inc/navikit.h index 31827df..3a66ca8 100644 --- a/Core/Inc/navikit.h +++ b/Core/Inc/navikit.h @@ -17,6 +17,7 @@ #include "main.h" #include "adc.h" +#include //#include "stm32f1xx_hal.h" //#include "gpio.h" diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index 518bb11..15a6c42 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -2,7 +2,7 @@ * @Description: * @Date: 2020-04-02 21:44:31 * @LastEditors: CK.Zh - * @LastEditTime: 2021-03-09 18:11:08 + * @LastEditTime: 2021-03-10 10:56:36 * @FilePath: \NaviKit_EC_stm32\Core\Src\freertos.c */ /* USER CODE BEGIN Header */ @@ -25,7 +25,7 @@ */ //TODO:拆分该文件中的功能到不同的文件中,按照任务进行模块化拆分 - +#define LOG_TAG "RTOS" /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ @@ -39,10 +39,14 @@ /* USER CODE BEGIN Includes */ #include "timers.h" #include "navikit.h" -#include "coulomb.h" #include #include #include +#include +#include +#include +#include + /* USER CODE END Includes */ @@ -64,36 +68,11 @@ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN Variables */ -//Timer -osTimerId_t PwrBtnLongPressTimerHandle; -const osTimerAttr_t PwrBtnLongPressTimer_attributes = { - .name = "PwrBtnLongPressTimer" -}; -osTimerId_t CustBtnLongPressTimerHandle; -const osTimerAttr_t CustBtnLongPressTimer_attributes = { - .name = "CustBtnLongPressTimer" -}; -osTimerId_t PwrBtnShortPressTimerHandle; -const osTimerAttr_t PwrBtnShortPressTimer_attributes = { - .name = "PwrBtnShortPressTimer" -}; -osTimerId_t CustBtnShortPressTimerHandle; -const osTimerAttr_t CustBtnShortPressTimer_attributes = { - .name = "CustBtnShortPressTimer" -}; -osTimerId_t IdleStateHoldTimerHandle; -const osTimerAttr_t IdleStateHoldTimer_attributes = { - .name = "IdleStateHoldTimer" -}; + //Thread -osThreadId_t LogtoUartTaskHandle; -const osThreadAttr_t LogtoUartTask_attributes = { - .name = "LogtoUartTask", - .priority = (osPriority_t) osPriorityBelowNormal, - .stack_size = 128 * 4 -}; + @@ -111,58 +90,23 @@ const osThreadAttr_t defaultTask_attributes = { .priority = (osPriority_t) osPriorityNormal, .stack_size = 128 * 4 }; -/* Definitions for LedBlinkTask */ -osThreadId_t LedBlinkTaskHandle; -const osThreadAttr_t LedBlinkTask_attributes = { - .name = "LedBlinkTask", - .priority = (osPriority_t) osPriorityLow, - .stack_size = 128 * 4 -}; -/* Definitions for CoulombRead */ -osThreadId_t CoulombReadHandle; -const osThreadAttr_t CoulombRead_attributes = { - .name = "CoulombRead", - .priority = (osPriority_t) osPriorityLow, - .stack_size = 128 * 4 -}; -/* Definitions for PowerMonitTask */ -osThreadId_t PowerMonitTaskHandle; -const osThreadAttr_t PowerMonitTask_attributes = { - .name = "PowerMonitTask", - .priority = (osPriority_t) osPriorityLow, - .stack_size = 128 * 4 -}; -/* Definitions for EventDetect */ -osThreadId_t EventDetectHandle; -const osThreadAttr_t EventDetect_attributes = { - .name = "EventDetect", - .priority = (osPriority_t) osPriorityLow, - .stack_size = 128 * 4 -}; + + + + /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ bool isWakeUpReset() { return __HAL_PWR_GET_FLAG(PWR_FLAG_WU);} -//callback -void PwrBtnLongPressTimerCallback(void *argument); -void CustBtnLongPressTimerCallback(void *argument); -void PwrBtnShortPressTimerCallback(void *argument); -void CustBtnShortPressTimerCallback(void *argument); void IdleStateHoldTimerCallback(void *argument); -//task -void StartLogtoUartTask(void *argument); /* USER CODE END FunctionPrototypes */ void StartDefaultTask(void *argument); -void StartLedBlinkTask(void *argument); -void StartCoulombRead(void *argument); -void StartPowerMonitTask(void *argument); -void StartEventDetect(void *argument); extern void MX_USB_DEVICE_Init(void); void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ @@ -243,7 +187,7 @@ __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime) */ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN Init */ -// elog_init(); + my_elog_init(); NaviKit_var_init(); /* USER CODE END Init */ @@ -258,11 +202,11 @@ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN RTOS_TIMERS */ /* start timers, add new ones, ... */ - PwrBtnLongPressTimerHandle = osTimerNew(PwrBtnLongPressTimerCallback, osTimerOnce, NULL, &PwrBtnLongPressTimer_attributes); - CustBtnLongPressTimerHandle = osTimerNew(CustBtnLongPressTimerCallback, osTimerOnce, NULL, &CustBtnLongPressTimer_attributes); - PwrBtnShortPressTimerHandle = osTimerNew(PwrBtnShortPressTimerCallback, osTimerOnce, NULL, &PwrBtnShortPressTimer_attributes); - CustBtnShortPressTimerHandle = osTimerNew(CustBtnShortPressTimerCallback, osTimerOnce, NULL, &CustBtnShortPressTimer_attributes); - IdleStateHoldTimerHandle = osTimerNew(IdleStateHoldTimerCallback, osTimerOnce, NULL, &IdleStateHoldTimer_attributes); +// PwrBtnLongPressTimerHandle = osTimerNew(PwrBtnLongPressTimerCallback, osTimerOnce, NULL, &PwrBtnLongPressTimer_attributes); +// CustBtnLongPressTimerHandle = osTimerNew(CustBtnLongPressTimerCallback, osTimerOnce, NULL, &CustBtnLongPressTimer_attributes); +// PwrBtnShortPressTimerHandle = osTimerNew(PwrBtnShortPressTimerCallback, osTimerOnce, NULL, &PwrBtnShortPressTimer_attributes); +// CustBtnShortPressTimerHandle = osTimerNew(CustBtnShortPressTimerCallback, osTimerOnce, NULL, &CustBtnShortPressTimer_attributes); +// IdleStateHoldTimerHandle = osTimerNew(IdleStateHoldTimerCallback, osTimerOnce, NULL, &IdleStateHoldTimer_attributes); /* USER CODE END RTOS_TIMERS */ @@ -277,7 +221,7 @@ void MX_FREERTOS_Init(void) { defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); /* creation of LedBlinkTask */ - LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes); +// LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes); /* creation of CoulombRead */ // CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes); @@ -286,22 +230,54 @@ void MX_FREERTOS_Init(void) { // PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes); /* creation of EventDetect */ - EventDetectHandle = osThreadNew(StartEventDetect, NULL, &EventDetect_attributes); +// EventDetectHandle = osThreadNew(StartEventDetect, NULL, &EventDetect_attributes); /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ -// LogtoUartTaskHandle = osThreadNew(StartLogtoUartTask, NULL, &LogtoUartTask_attributes); + + //Power-------------------------------------------- +// PowerMonitTaskHandle = osThreadNew(StartPowerMonitTask, NULL, &PowerMonitTask_attributes); + + + //Button-------------------------------------------- + ButtonDetectHandle = osThreadNew(StartButtonDetect, NULL, &ButtonDetect_attributes); + + + //LED-------------------------------------------- + LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes); + + + //CDC-------------------------------------------- + cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes); + + + //Coulomb-------------------------------------------- +// CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes); + + + //Elog-------------------------------------------- +// ElogInitTaskHandle = osThreadNew(StartElogInitTask, NULL, &ElogInitTask_attributes); + ElogFlushTaskHandle = osThreadNew(StartElogFlushTask, NULL, &ElogFlushTask_attributes); +// ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes); + + + //Demo-------------------------------------------- // DemoTask1Handle = osThreadNew(StartDemoTask1, NULL, &DemoTask1_attributes); // DemoTask2Handle = osThreadNew(StartDemoTask2, NULL, &DemoTask2_attributes); - cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes); -// ElogInitTaskHandle = osThreadNew(StartElogInitTask, NULL, &ElogInitTask_attributes); -// ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes); /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ /* add events, ... */ + + PwrBtnLongPressTimerHandle = osTimerNew(PwrBtnLongPressTimerCallback, osTimerOnce, NULL, &PwrBtnLongPressTimer_attributes); + CustBtnLongPressTimerHandle = osTimerNew(CustBtnLongPressTimerCallback, osTimerOnce, NULL, &CustBtnLongPressTimer_attributes); + PwrBtnShortPressTimerHandle = osTimerNew(PwrBtnShortPressTimerCallback, osTimerOnce, NULL, &PwrBtnShortPressTimer_attributes); + CustBtnShortPressTimerHandle = osTimerNew(CustBtnShortPressTimerCallback, osTimerOnce, NULL, &CustBtnShortPressTimer_attributes); + IdleStateHoldTimerHandle = osTimerNew(IdleStateHoldTimerCallback, osTimerOnce, NULL, &IdleStateHoldTimer_attributes); + + /* USER CODE END RTOS_EVENTS */ } @@ -351,26 +327,28 @@ void StartDefaultTask(void *argument) // TaskBeep(50,1); } - log_i("----------------------------------------------"); - log_i("Copyright (c) Powered by www.autolabor.com.cn"); + log_i("----------------------------------------------"); + log_i("Copyright (c) Powered by www.autolabor.com.cn"); + #ifdef DEBUG + log_i("EC Firmware: %s[DEBUG], build: %s, %s",APP_VERSION,__DATE__ ,__TIME__); + #else + log_i("EC Firmware: %s[RELEASE], build: %s, %s",APP_VERSION,__DATE__ ,__TIME__); + #endif + log_i("HAL Version: 0x%X ", HAL_GetHalVersion()); + log_i("Revision ID: 0x%X ", HAL_GetREVID()); + log_i("Device ID: 0x%X ", HAL_GetDEVID()); + log_i("Chip UID: 0x%X%X%X ", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2()); - log_i("EC Firmware: %s[%s], build: %s, %s, by STD:%u",APP_VERSION,DEPLOY_MODE,__DATE__ ,__TIME__,__STDC_VERSION__ ); - log_i("HAL Version: 0x%X ", HAL_GetHalVersion()); - log_i("Revision ID: 0x%X ", HAL_GetREVID()); - log_i("Device ID: 0x%X ", HAL_GetDEVID()); - log_i("Chip UID: 0x%X%X%X ", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2()); + if(osOK == osKernelGetInfo(&osVersion,id_buf,id_size)){ + log_i("OS Kernel Version: %u ", osVersion.kernel); + log_i("OS Kernel ID: %s ",id_buf); + } + log_i("OS Kernel Tick Frequence: %d ",osKernelGetTickFreq()); + log_i("OS Kernel System Timer Frequence: %d ",osKernelGetSysTimerFreq()); + log_i("Log Library Version: V%s",ELOG_SW_VERSION); - if(osOK == osKernelGetInfo(&osVersion,id_buf,id_size)){ - log_i("OS Kernel Version: %u ", osVersion.kernel); - log_i("OS Kernel ID: %s ",id_buf); - } - log_i("OS Kernel Tick Frequence: %d ",osKernelGetTickFreq()); - log_i("OS Kernel System Timer Frequence: %d ",osKernelGetSysTimerFreq()); - log_i("Log Library Version: V%s",ELOG_SW_VERSION); - - log_i("Core initial successfully"); - // log_i("EasyLogger V%s is initialize success.", ELOG_SW_VERSION); - log_i("----------------------------------------------"); + log_i("Core initial successfully"); + log_i("----------------------------------------------"); /* Infinite loop */ for(;;) @@ -434,301 +412,15 @@ void StartDefaultTask(void *argument) /* USER CODE END StartDefaultTask */ } -/* USER CODE BEGIN Header_StartLedBlinkTask */ -/** -* @brief Function implementing the LedBlinkTask thread. -* @param argument: Not used -* @retval None -*/ -/* USER CODE END Header_StartLedBlinkTask */ -void StartLedBlinkTask(void *argument) -{ - /* USER CODE BEGIN StartLedBlinkTask */ - /* Infinite loop */ -// log_v("Start LED Blink"); - for(;;) - { - - osDelay(1000); - switch(NaviKit.sys.sta){ - case run: { - PWR_Enable(SYS_PWR_LED,true,0);//turn on power led - - PWR_Enable(SYS_RUN_LED,true,50);//turn on sys run led - PWR_Enable(SYS_RUN_LED,false,0);//turn off sys run led - }break; - case idle:{ - PWR_Enable(SYS_PWR_LED,false,0);//turn on power led//turn off power led - - PWR_Enable(SYS_RUN_LED,true,20);//turn on sys run led - PWR_Enable(SYS_RUN_LED,false,3000);//turn off sys run led - }break; - case sleep:{//sleep mode - for(uint16_t i=0;i<25;i++){//20 light level - for(uint16_t j=0;j<3;j++){//the time length of every light level - PWR_Enable(SYS_PWR_LED,false,0); - PWR_Enable(SYS_RUN_LED,false,0); - osDelay(i); - PWR_Enable(SYS_PWR_LED,true,0); - PWR_Enable(SYS_RUN_LED,true,0); - osDelay(25-i); - } - } - for(uint16_t i=0;i<25;i++){ - for(uint16_t j=0;j<3;j++){ - PWR_Enable(SYS_PWR_LED,false,0); - PWR_Enable(SYS_RUN_LED,false,0); - osDelay(25-i); - PWR_Enable(SYS_PWR_LED,true,0); - PWR_Enable(SYS_RUN_LED,true,0); - osDelay(i); - } - } - }break; - case dfu:{ - PWR_Enable(SYS_PWR_LED,!PWR_Status(SYS_PWR_LED),0); - PWR_Enable(SYS_RUN_LED,!PWR_Status(SYS_PWR_LED),0); - }break; - default : break; - } - } - /* USER CODE END StartLedBlinkTask */ -} - -/* USER CODE BEGIN Header_StartCoulombRead */ -/** -* @brief Function implementing the CoulombRead thread. -* @param argument: Not used -* @retval None -*/ -/* USER CODE END Header_StartCoulombRead */ -void StartCoulombRead(void *argument) -{ - /* USER CODE BEGIN StartCoulombRead */ -// log_v("Start Coulomb Read Task"); - //写寄存器方法 - coulomb_write_config_load(); - coulomb_write_config_actual_to_raw(); - coulomb_write_config(); - //读寄存器方法 - coulomb_read_status_and_config(); - coulomb_read_status_raw_to_actual(); - coulomb_read_config_raw_to_actual(); - - /* Infinite loop */ - for(;;) - { - coulomb_read_status_and_config(); - coulomb_read_status_raw_to_actual(); - if(NaviKit.sys.sta == run) - osDelay(500); - else - osDelay(5000); - - } - /* USER CODE END StartCoulombRead */ -} - -/* USER CODE BEGIN Header_StartPowerMonitTask */ -/** -* @brief Function: Monit som power status and PMB status -* @param argument: Not used -* @retval None -*/ -/* USER CODE END Header_StartPowerMonitTask */ -void StartPowerMonitTask(void *argument) -{ - /* USER CODE BEGIN StartPowerMonitTask */ -// log_v("Start Power Monitor Task"); - HAL_ADCEx_Calibration_Start(&hadc1); - HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT); - osDelay(100); - /* Infinite loop */ - for(;;) - { - - if(NaviKit.pmb.rails.main_pwr > 30){ - TaskBeep(200,1); - log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); - } - if(NaviKit.pmb.rails.bkp_bat > 15){ - log_e("Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); - TaskBeep(200,1); - } - //stat1 stat2 lead-acid - //1 1 Not Charging - //1 0 Float Charge - //0 1 Absorption Charge - //0 0 Bulk Charge - NaviKit.pmb.sta.chrg_stat1 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT1_GPIO_Port, PMB_CHRG_STAT1_Pin); - NaviKit.pmb.sta.chrg_stat2 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT2_GPIO_Port, PMB_CHRG_STAT2_Pin); - - if(!NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2) - log_v("Backup battery status:%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); - if(!NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2) - log_v("Backup battery status:%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); - if(NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2) - log_v("Backup battery status:%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); - if(NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2) - log_v("Backup battery status:%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); - - if(NaviKit.sys.sta == run || NaviKit.sys.sta == dfu ){ - if(NaviKit.pmb.rails.main_pwr < 19){ - TaskBeep(200,1); - log_w("Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); - }else - log_v("Main power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); - - if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6) - log_e("24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000)); - else - log_v("24V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000)); - - if(NaviKit.pmb.rails.out_5v > 5.5 || NaviKit.pmb.rails.out_5v < 4.5) - log_e("5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000)); - else - log_v("5V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000)); - - if(NaviKit.pmb.rails.out_12v > 13.2 || NaviKit.pmb.rails.out_12v < 10.8) - log_e("12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000)); - else - log_v("12V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000)); - - if(NaviKit.pmb.rails.bkp_bat < 9.5) - log_w("Backup battery exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); - else - log_v("Backup battery is regular:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); - - osDelay(2000); - - }else {//not run state - osDelay(5000); - - } -// log_d("state :%d",NaviKit.sys.sta); -// log_d("next_state :%d",NaviKit.sys.next_sta); - - } - /* USER CODE END StartPowerMonitTask */ -} - -/* USER CODE BEGIN Header_StartEventDetect */ -/** -* @brief Function implementing the EventDetect thread. -* @param argument: Not used -* @retval None -*/ -/* USER CODE END Header_StartEventDetect */ -void StartEventDetect(void *argument) -{ - /* USER CODE BEGIN StartEventDetect */ - /* Infinite loop */ -// log_v("Start Event 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 StartEventDetect */ -} + /* Private application code --------------------------------------------------*/ /* USER CODE BEGIN Application */ -void StartLogtoUartTask(void *argument){ - - // HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,2); -} -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; - } -} -void IdleStateHoldTimerCallback(void *argument){ - if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){ - log_v("Idle state duration more than 5000ms."); - NaviKit.sys.next_sta = standby; - } -} /* USER CODE END Application */ diff --git a/Core/Src/usart.c b/Core/Src/usart.c index c4aaa8a..e91d7da 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -21,7 +21,7 @@ #include "usart.h" /* USER CODE BEGIN 0 */ -#include "log.h" + /* USER CODE END 0 */ UART_HandleTypeDef huart4; diff --git a/NaviKit_EC_stm32 Release.launch b/NaviKit_EC_stm32 Release.launch new file mode 100644 index 0000000..519b745 --- /dev/null +++ b/NaviKit_EC_stm32 Release.launch @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/USB_DEVICE/App/usbd_cdc_if.c b/USB_DEVICE/App/usbd_cdc_if.c index 85639b2..fbbb27b 100644 --- a/USB_DEVICE/App/usbd_cdc_if.c +++ b/USB_DEVICE/App/usbd_cdc_if.c @@ -23,7 +23,7 @@ #include "usbd_cdc_if.h" /* USER CODE BEGIN INCLUDE */ -#include "log.h" + /* USER CODE END INCLUDE */ /* Private typedef -----------------------------------------------------------*/ diff --git a/USB_DEVICE/Target/usbd_conf.h b/USB_DEVICE/Target/usbd_conf.h index e6fc6f8..c84489b 100644 --- a/USB_DEVICE/Target/usbd_conf.h +++ b/USB_DEVICE/Target/usbd_conf.h @@ -1,3 +1,10 @@ +/* + * @Description: + * @Date: 2020-02-20 11:58:24 + * @LastEditors: CK.Zh + * @LastEditTime: 2021-03-09 18:32:44 + * @FilePath: \NaviKit_EC_stm32\USB_DEVICE\Target\usbd_conf.h + */ /* USER CODE BEGIN Header */ /** ****************************************************************************** @@ -69,7 +76,7 @@ /*---------- -----------*/ #define USBD_MAX_STR_DESC_SIZ 512 /*---------- -----------*/ -#define USBD_DEBUG_LEVEL 3 +#define USBD_DEBUG_LEVEL 0 /*---------- -----------*/ #define USBD_SELF_POWERED 1 /*---------- -----------*/