#include "sys.h" #include "common.h" #include "stm32f10x_exti.h" #include "stm32f10x_pwr.h" #include "stm32f10x_rtc.h" #include "app_pwr_manage.h" #include "uds_api.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 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);// }