From 4ecbf6bca6232be5d3fddd003b92a0017fe3800a Mon Sep 17 00:00:00 2001 From: ThinkPad-T460P Date: Tue, 5 Jan 2021 16:06:45 +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 --- Core/Inc/navikit.h | 14 +++++++------- Core/Src/freertos.c | 36 ++++++++++++++---------------------- Core/Src/navikit.c | 2 ++ 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Core/Inc/navikit.h b/Core/Inc/navikit.h index 1801107..dd3aa3d 100644 --- a/Core/Inc/navikit.h +++ b/Core/Inc/navikit.h @@ -122,13 +122,13 @@ typedef struct extern NaviKit_t NaviKit; //device on board -enum Device_t{USB2_Port1,USB2_Port2,USB2_Port3,USB2_Port4,USB2_Port5,USB2_Port6, - USB3_Port1,USB3_Port2,USB3_Port3,USB3_Port4,USB3_Port5,USB3_Port6, - SOC_USB2_HUB,SOC_USB3_HUB,SOC_USB3_HOST,SOC_USB3_GEC,SOC_GE_SW, - SYS_FAN1,SYS_FAN2,SYS_FAN3, - SYS_RUN_LED,SYS_PWR_LED, - SOM_PWR_EN,SOM_DFU, - PMB_PS_ON}; +enum Device_t{USB2_Port1,USB2_Port2,USB2_Port3,USB2_Port4,USB2_Port5,USB2_Port6, //USB2.0 Port + USB3_Port1,USB3_Port2,USB3_Port3,USB3_Port4,USB3_Port5,USB3_Port6, //USB3.0 Port + SOC_USB2_HUB,SOC_USB3_HUB,SOC_USB3_HOST,SOC_USB3_GEC,SOC_GE_SW, //SOC on Board + SYS_FAN1,SYS_FAN2,SYS_FAN3, //Fan on Board + SYS_RUN_LED,SYS_PWR_LED, //LED on Board + SOM_PWR_EN,SOM_DFU,SOM_RESET, //SOM Control + PMB_PS_ON}; //Power Management Board void PWR_Enable(enum Device_t device,bool en,uint16_t delay); bool PWR_Status(enum Device_t device); diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index 71f8210..98d8c25 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -68,12 +68,12 @@ osEventFlagsId_t buttonEventHandle; const osEventFlagsAttr_t buttonEvent_attributes = { .name = "buttonEvent" }; -osThreadId_t StateSwitchTaskHandle; -const osThreadAttr_t StateSwitchTask_attributes = { - .name = "StateSwitchTask", - .priority = (osPriority_t) osPriorityNormal, - .stack_size = 128 * 4 -}; +//osThreadId_t StateSwitchTaskHandle; +//const osThreadAttr_t StateSwitchTask_attributes = { +// .name = "StateSwitchTask", +// .priority = (osPriority_t) osPriorityNormal, +// .stack_size = 128 * 4 +//}; /* USER CODE END Variables */ /* Definitions for defaultTask */ osThreadId_t defaultTaskHandle; @@ -125,8 +125,8 @@ const osTimerAttr_t CustBtnTimer_attributes = { /* USER CODE BEGIN FunctionPrototypes */ //void osEnterSleepState(); //void osEnterRuningState(); -void StartStateSwitchTask(void *argument); -void StartChangeStateTask(state_t target_sta); +//void StartStateSwitchTask(void *argument); +//void StartChangeStateTask(state_t target_sta); bool isWakeUpReset() { return __HAL_PWR_GET_FLAG(PWR_FLAG_WU);} /* USER CODE END FunctionPrototypes */ @@ -262,7 +262,7 @@ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ - StateSwitchTaskHandle = osThreadNew(StartStateSwitchTask, NULL, &defaultTask_attributes); +// StateSwitchTaskHandle = osThreadNew(StartStateSwitchTask, NULL, &defaultTask_attributes); /* USER CODE END RTOS_THREADS */ @@ -477,7 +477,7 @@ void StartPowerMonitTask(void *argument) { /* USER CODE BEGIN StartPowerMonitTask */ HAL_ADCEx_Calibration_Start(&hadc1); - osDelay(2000); + HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT); /* Infinite loop */ for(;;) { @@ -499,7 +499,6 @@ void StartPowerMonitTask(void *argument) Log(trace,"Backup battery status:%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); - HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT); if(NaviKit.sys.sta == run || NaviKit.sys.next_sta == run ){ osDelay(2000); if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6) @@ -574,7 +573,7 @@ void StartEventDetect(void *argument) osTimerStart(PwrBtnTimerHandle,2000); } if(NaviKit.sys.custom_btn && !osTimerIsRunning(CustBtnTimerHandle)){ - osTimerStart(PwrBtnTimerHandle,2000); + osTimerStart(CustBtnTimerHandle,2000); } if(!NaviKit.sys.power_btn && osTimerIsRunning(PwrBtnTimerHandle)){ osTimerStop(PwrBtnTimerHandle); @@ -612,9 +611,9 @@ void CustBtnTimerCallback(void *argument) Log(trace,"custom btn long pressed"); switch(NaviKit.sys.sta){ case run:{//system is run now, user request to restart system - HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port,SOM_SYS_RESET_Pin,GPIO_PIN_RESET); - osDelay(10); - HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port,SOM_SYS_RESET_Pin,GPIO_PIN_SET); + PWR_Enable(SOM_RESET,true,10); + PWR_Enable(SOM_RESET,false,0); + Log(info,"SOM Reset."); }break; case idle:{ }break; @@ -631,14 +630,7 @@ void CustBtnTimerCallback(void *argument) /* Private application code --------------------------------------------------*/ /* USER CODE BEGIN Application */ -void StartStateSwitchTask(void *argument) -{ - for(;;) - { - - } -} //printf redirect diff --git a/Core/Src/navikit.c b/Core/Src/navikit.c index 595b5dd..ff873c0 100644 --- a/Core/Src/navikit.c +++ b/Core/Src/navikit.c @@ -273,6 +273,7 @@ void PWR_Enable(enum Device_t device,bool en,uint16_t delay){ case SYS_PWR_LED: {HAL_GPIO_WritePin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin, !en); }break; case SOM_PWR_EN: {HAL_GPIO_WritePin(SOM_POWER_EN_GPIO_Port,SOM_POWER_EN_Pin, en); }break; case SOM_DFU: {HAL_GPIO_WritePin(SOM_FORCE_RECOVERY_GPIO_Port,SOM_FORCE_RECOVERY_Pin, !en); }break; + case SOM_RESET: {HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port,SOM_SYS_RESET_Pin, !en); }break; case PMB_PS_ON: {HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port,PMB_PS_ON_Pin, en); }break; default: {Log(error,"PWR_Enable device parameter is invalid."); }break; } @@ -307,6 +308,7 @@ bool PWR_Status(enum Device_t device){ case SYS_PWR_LED: {sta = !HAL_GPIO_ReadPin(SYS_POWER_LED_CTL_GPIO_Port,SYS_POWER_LED_CTL_Pin); }break; case SOM_PWR_EN: {sta = HAL_GPIO_ReadPin(SOM_POWER_EN_GPIO_Port,SOM_POWER_EN_Pin); }break; case SOM_DFU: {sta = !HAL_GPIO_ReadPin(SOM_FORCE_RECOVERY_GPIO_Port,SOM_FORCE_RECOVERY_Pin); }break; + case SOM_RESET: {sta = !HAL_GPIO_ReadPin(SOM_SYS_RESET_GPIO_Port,SOM_SYS_RESET_Pin); }break; case PMB_PS_ON: {sta = HAL_GPIO_ReadPin(PMB_PS_ON_GPIO_Port,PMB_PS_ON_Pin); }break; default: {Log(error,"PWR_Status device parameter is invalid."); }break; }