7a7daad23a
Signed-off-by: lidun <1084178170@qq.com>
171 lines
3.8 KiB
C
171 lines
3.8 KiB
C
#include "sys.h"
|
|
#include "common.h"
|
|
#include "stm32f10x_exti.h"
|
|
|
|
#include "stm32f10x_pwr.h"
|
|
#include "stm32f10x_rtc.h"
|
|
#include "app_pwr_manage.h"
|
|
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t VMin_Cfg;/*mv*/
|
|
uint16_t VMax_Cfg;
|
|
|
|
uint16_t MinTimeCfg;
|
|
uint16_t MaxTimeCfg;
|
|
}PWR_Volt_State_Config_Type;
|
|
|
|
PWR_BATT_VOLT_STATE_ENUM battery_volt_state = NORM_VOLT; //µç³Ø״̬±êÖ¾
|
|
static const PWR_Volt_State_Config_Type pwr_volt_state_range_cfg[]= //10mv
|
|
{
|
|
{0, 650, 0x02, 0x02},
|
|
{630, 950, 0x02, 0x05},
|
|
{900, 1600, 0x02, 0x05},
|
|
{1550, 1850, 0x02, 0x05},
|
|
{1820, 2400, 0x02, 0x05},
|
|
};
|
|
|
|
/**
|
|
* @breif: ¼à¿ØB+µçѹ
|
|
*
|
|
* @param void
|
|
*
|
|
* @return None
|
|
*/
|
|
void Pwr_BatVoltRangeMonitor(void)
|
|
{
|
|
uint8_t i/*,sned_msg[10]*/;
|
|
uint16_t batt_mon_value,tempVolt;
|
|
PWR_BATT_VOLT_STATE_ENUM temp_volt_state;
|
|
|
|
static uint8_t up_chage_flag = FALSE,dn_chage_flag=FALSE;
|
|
static uint16_t wait_change_time = 0x00;
|
|
#ifdef CS_TEMP_MODIFY
|
|
tempVolt = (uint16_t)(Sample_DataS.VIN_Input_Voltage*100); //0.01v
|
|
#else
|
|
tempVolt = 1200;
|
|
#endif
|
|
|
|
if( tempVolt<350)return;
|
|
|
|
batt_mon_value=tempVolt;
|
|
|
|
temp_volt_state = battery_volt_state;
|
|
|
|
if(batt_mon_value > pwr_volt_state_range_cfg[temp_volt_state].VMax_Cfg)
|
|
{
|
|
for(i = temp_volt_state ;i<VOLT_STATE_NUM;i++)
|
|
{
|
|
if((batt_mon_value > pwr_volt_state_range_cfg[i].VMin_Cfg) &&
|
|
batt_mon_value < pwr_volt_state_range_cfg[i].VMax_Cfg)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(i>=VOLT_STATE_NUM)
|
|
{
|
|
i = VOLT_STATE_NUM-1;
|
|
}
|
|
dn_chage_flag = FALSE;
|
|
if(up_chage_flag == FALSE)
|
|
{
|
|
up_chage_flag = TRUE;
|
|
wait_change_time = pwr_volt_state_range_cfg[temp_volt_state].MaxTimeCfg;
|
|
}
|
|
temp_volt_state = (PWR_BATT_VOLT_STATE_ENUM)i;
|
|
}
|
|
else if(batt_mon_value < pwr_volt_state_range_cfg[temp_volt_state].VMin_Cfg)
|
|
{
|
|
for(i = temp_volt_state ;i>0;i--)
|
|
{
|
|
if((batt_mon_value > pwr_volt_state_range_cfg[i].VMin_Cfg) &&
|
|
batt_mon_value < pwr_volt_state_range_cfg[i].VMax_Cfg)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
up_chage_flag = FALSE;
|
|
if(dn_chage_flag == FALSE)
|
|
{
|
|
dn_chage_flag = TRUE;
|
|
wait_change_time = pwr_volt_state_range_cfg[temp_volt_state].MaxTimeCfg;
|
|
}
|
|
temp_volt_state = (PWR_BATT_VOLT_STATE_ENUM)i;
|
|
}
|
|
else
|
|
{
|
|
dn_chage_flag=FALSE;
|
|
up_chage_flag=FALSE;
|
|
}
|
|
|
|
if(0u != wait_change_time)
|
|
{
|
|
wait_change_time--;
|
|
}
|
|
else if((battery_volt_state != temp_volt_state)&&(batt_mon_value>50))
|
|
{
|
|
|
|
battery_volt_state = temp_volt_state;
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
#ifdef CS_TEMP_MODIFY
|
|
/**
|
|
* @breif: ¼ì²âIGN1ÊÇ·ñÓÐЧ
|
|
*
|
|
* @param void
|
|
*
|
|
* @return result
|
|
*/
|
|
uint8_t ChkInputIGN1(void)
|
|
{
|
|
static uint8_t pressCnt,unpressCnt;
|
|
static uint8_t result = 0;
|
|
|
|
if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_9))
|
|
{
|
|
unpressCnt = 0;
|
|
if (pressCnt < 5)
|
|
{
|
|
pressCnt++;
|
|
}
|
|
else if (pressCnt == 5)
|
|
{
|
|
pressCnt++;
|
|
result = 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
pressCnt = 0;
|
|
if (unpressCnt < 5)
|
|
{
|
|
unpressCnt++;
|
|
}
|
|
else if (unpressCnt == 5)
|
|
{
|
|
unpressCnt++;
|
|
pressCnt = 0;
|
|
result = 0;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
#endif
|
|
|
|
/**
|
|
* @brief RTC Backup Initialize.
|
|
*/
|
|
void BSP_BKP_Init(void)
|
|
{
|
|
RCC_APB1PeriphClockCmd (RCC_APB1Periph_PWR | RCC_APB1Periph_BKP,ENABLE );//
|
|
PWR_BackupAccessCmd(ENABLE);//
|
|
}
|
|
|