Motion_EC_Stm32_archived/App/Src/th_power.c

98 lines
3.3 KiB
C
Raw Normal View History

2021-03-10 11:03:35 +08:00
/*
* @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 <th_power.h>
#include "main.h"
#include "adc.h"
#include "navikit.h"
const osThreadAttr_t PowerMonitTask_attributes = {
.name = "PowerMonitTask",
2021-03-11 19:09:05 +08:00
.priority = (osPriority_t) osPriorityBelowNormal,
2021-03-14 23:24:59 +08:00
.stack_size = 256 * 4
2021-03-10 11:03:35 +08:00
};
2021-03-15 19:26:10 +08:00
//Event Flag
const osEventFlagsAttr_t PowerMonitorEventFlags_attributes = {
.name = "PowerMonitorEventFlags"
};
2021-03-10 11:03:35 +08:00
2021-03-15 19:26:10 +08:00
/* USER CODE BEGIN Header_PowerMonitTask */
2021-03-10 11:03:35 +08:00
/**
* @brief Function: Monit som power status and PMB status
* @param argument: Not used
* @retval None
*/
2021-03-15 19:26:10 +08:00
/* USER CODE END Header_PowerMonitTask */
void PowerMonitTask(void *argument)
2021-03-10 11:03:35 +08:00
{
2021-03-15 19:26:10 +08:00
/* USER CODE BEGIN PowerMonitTask */
2021-03-12 13:38:28 +08:00
log_d("Start Power Monitor Task");
2021-03-10 11:03:35 +08:00
HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT);
2021-03-15 19:26:10 +08:00
osDelay(10);
2021-03-10 11:03:35 +08:00
/* Infinite loop */
for(;;)
{
2021-03-15 19:26:10 +08:00
if((NaviKit.pmb.rails.main_pwr > 30) || (NaviKit.pmb.rails.main_pwr < 19)){
NaviKit.pmb.main_pwr_good = false;
log_e("Main power:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
if((NaviKit.sys.next_sta == run) && (NaviKit.sys.next_sta == run)){
TaskBeep(200,2);
}
}else{
log_d("Main power :%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
NaviKit.pmb.main_pwr_good = true;
2021-03-10 11:03:35 +08:00
}
2021-03-15 19:26:10 +08:00
if((NaviKit.pmb.rails.bkp_bat < 8) || (NaviKit.pmb.rails.bkp_bat > 15)){
TaskBeep(200,2);
}else{
//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);
2021-03-10 11:03:35 +08:00
2021-03-15 19:26:10 +08:00
if(false == NaviKit.pmb.sta.chrg_stat1 && false == NaviKit.pmb.sta.chrg_stat2)
log_d("Backup battery :%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
else if(false == NaviKit.pmb.sta.chrg_stat1 && true == NaviKit.pmb.sta.chrg_stat2)
log_d("Backup battery :%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
else if(true == NaviKit.pmb.sta.chrg_stat1 && false == NaviKit.pmb.sta.chrg_stat2)
log_d("Backup battery :%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
else if(true == NaviKit.pmb.sta.chrg_stat1 && true == NaviKit.pmb.sta.chrg_stat2)
log_d("Backup battery :%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
}
2021-03-10 11:03:35 +08:00
2021-03-15 19:26:10 +08:00
if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6)
log_e("24V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
else
log_d("24V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
2021-03-10 11:03:35 +08:00
2021-03-15 19:26:10 +08:00
if(NaviKit.pmb.rails.out_5v > 5.5 || NaviKit.pmb.rails.out_5v < 4.5)
log_e("5V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
else
log_d("5V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
2021-03-10 11:03:35 +08:00
2021-03-15 19:26:10 +08:00
if(NaviKit.pmb.rails.out_12v > 13.2 || NaviKit.pmb.rails.out_12v < 10.8)
log_e("12V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
else
log_d("12V(±10%%) :%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
2021-03-10 11:03:35 +08:00
2021-03-15 19:26:10 +08:00
osDelay(3000);
2021-03-10 11:03:35 +08:00
}
2021-03-15 19:26:10 +08:00
/* USER CODE END PowerMonitTask */
2021-03-10 11:03:35 +08:00
}