From f91a03e7401f7cabdd6a75fd4896d7007c4f65b2 Mon Sep 17 00:00:00 2001 From: ThinkPad-T460P Date: Thu, 17 Dec 2020 20:10:40 +0800 Subject: [PATCH] update --- Core/Src/freertos.c | 31 ++++++++++++++++++++++++++----- Core/Src/main.c | 10 +++++++++- Core/Src/navikit.c | 7 ------- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index f18a191..09582b0 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: 2020-12-17 18:39:26 + * @LastEditTime: 2020-12-17 20:08:43 * @FilePath: \NaviKit_stm32\Core\Src\freertos.c */ /* USER CODE BEGIN Header */ @@ -36,11 +36,11 @@ #include "iwdg.h" #include "gpio.h" #include "usart.h" -//#include "stdio.h" #include "navikit.h" #include "coulomb.h" #include "stdbool.h" #include "adc.h" +#include "i2c.h" #include "log.h" /* USER CODE END Includes */ @@ -115,6 +115,8 @@ const osThreadAttr_t PowerMonitTask_attributes = { /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ +void osEnterSleepState(); +void osEnterRuningState(); /* USER CODE END FunctionPrototypes */ void StartDefaultTask(void *argument); @@ -217,7 +219,7 @@ void MX_FREERTOS_Init(void) { LedBlinkTaskHandle = osThreadNew(StartLedBlinkTask, NULL, &LedBlinkTask_attributes); /* creation of IWDGRefreshTask */ - IWDGRefreshTaskHandle = osThreadNew(StartIWDGRefreshTask, NULL, &IWDGRefreshTask_attributes); + // IWDGRefreshTaskHandle = osThreadNew(StartIWDGRefreshTask, NULL, &IWDGRefreshTask_attributes); /* creation of EventDetect */ EventDetectHandle = osThreadNew(StartEventDetect, NULL, &EventDetect_attributes); @@ -277,7 +279,7 @@ void StartDefaultTask(void *argument) Log(info,"Core initial successfully"); Log(info,"----------------------------------------------"); - + osEnterSleepState(); /* Infinite loop */ for(;;) { @@ -535,6 +537,7 @@ void StartStateSwitchTask(void *argument) {//only from running state if((NaviKit.sys.sta == running))// && (NaviKit.som.shutdown_req == true) enter_shutdown_state(); + osEnterSleepState(); }break; case running: {//from sleep and shutdown state @@ -601,7 +604,25 @@ void StartPowerMonitTask(void *argument) /* Private application code --------------------------------------------------*/ /* USER CODE BEGIN Application */ - +//os enter sleep state for save power +void osEnterSleepState(){ + Log(info,"EC Enter Sleep State"); + vTaskSuspendAll(); + HAL_SuspendTick(); + HAL_I2C_MspDeInit(&hi2c1); + HAL_ADC_MspDeInit(&hadc1); + HAL_ADC_Stop_DMA(&hadc1); + HAL_PWR_EnableSleepOnExit();//for rtos application,enter sleep after interrupt end + HAL_PWR_EnterSLEEPMode(0,PWR_SLEEPENTRY_WFE); +} +void osEnterRuningState(){ + HAL_ResumeTick(); + HAL_I2C_MspInit(&hi2c1); + HAL_ADC_MspInit(&hadc1); + HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT); + xTaskResumeAll(); + Log(info,"EC Enter Runing State"); +} //printf redefine #ifdef __GNUC__ //#define PUTCHAR_PROTOTYPE int __io_putchar(int ch) diff --git a/Core/Src/main.c b/Core/Src/main.c index 5213fd2..26a9551 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -1,3 +1,10 @@ +/* + * @Description: + * @Date: 2020-02-20 11:40:37 + * @LastEditors: CK.Zh + * @LastEditTime: 2020-12-17 19:24:44 + * @FilePath: \NaviKit_stm32\Core\Src\main.c + */ /* USER CODE BEGIN Header */ /** ****************************************************************************** @@ -98,7 +105,7 @@ int main(void) MX_GPIO_Init(); MX_DMA_Init(); MX_I2C1_Init(); - MX_IWDG_Init(); +// MX_IWDG_Init(); MX_UART4_Init(); MX_ADC1_Init(); MX_USART1_UART_Init(); @@ -108,6 +115,7 @@ int main(void) MX_NVIC_Init(); /* USER CODE BEGIN 2 */ + HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); /* USER CODE END 2 */ /* Init scheduler */ diff --git a/Core/Src/navikit.c b/Core/Src/navikit.c index 5ddeb8e..6ce73d9 100644 --- a/Core/Src/navikit.c +++ b/Core/Src/navikit.c @@ -34,13 +34,6 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) { if(hadc->Instance == ADC1) { -// NaviKit.pmb.rails.out_24v = (float)((NaviKit.pmb.rails.adc[1]*16.0) / 1241.21); -// NaviKit.pmb.rails.out_5v = (float)((NaviKit.pmb.rails.adc[2]*8.0 ) / 1241.21); -// NaviKit.pmb.rails.out_12v = (float)((NaviKit.pmb.rails.adc[3]*8.0 ) / 1241.21); -// NaviKit.pmb.rails.bkp_bat = (float)((NaviKit.pmb.rails.adc[4]*8.0 ) / 1241.21); -// NaviKit.pmb.rails.main_pwr = (float)((NaviKit.pmb.rails.adc[5]*16.0) / 1241.21); - - float adc_17_voltage = 1.2 / NaviKit.pmb.rails.adc[1];//reference voltage NaviKit.pmb.rails.out_24v = (float)(adc_17_voltage * NaviKit.pmb.rails.adc[2] * 16);