master
ThinkPad-T460P 2020-12-17 20:10:40 +08:00
parent 654f9b1b3e
commit f91a03e740
3 changed files with 35 additions and 13 deletions

View File

@ -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)

View File

@ -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 */

View File

@ -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);