| | |
| | | #include "tim.h" |
| | | #include "sizhu_ctrl_word.h" |
| | | #include "system_run_fun.h" |
| | | #include "system_mem_para.h" |
| | | #include "sizhu_ctrl_word.h" |
| | | #include "linked_list.h" |
| | | |
| | | PWR_VOL_T pwr_vol_g = {LMS_PERIOD, AMS_PERIOD, SET,.lith_vcc_per = 100}; // ĬÈÏÉϵç²É¼¯Ò»´ÎµçÁ¿ºÍMCUÎÂ¶È |
| | | PWR_VOL_T pwr_vol_g = {.lith_flag = LMS_PERIOD, .alka_flag = AMS_PERIOD, .mcu_temp_flag = SET,.lith_vcc_per = 100}; // ĬÈÏÉϵç²É¼¯Ò»´ÎµçÁ¿ºÍMCUÎÂ¶È |
| | | |
| | | |
| | | uint8_t first_power_get_cnt_g = 0; |
| | |
| | | Alka_Battery_GPIO_Clk_Init(); |
| | | ADC_IN8_Init(); |
| | | ALK_DEC_ON; |
| | | // delay_ms(10); |
| | | delay_ms(5); |
| | | // ÉêÇëÈáÐÔÊý×éÄÚ´æ¿Õ¼ä |
| | | if ((data_ins = (ad_data_s *)malloc(sizeof(ad_data_s) + sizeof(uint16_t) * AD_ALKA_BAT_CNT)) != NULL) |
| | | { |
| | |
| | | Lith_Battery_GPIO_Clk_Init(); |
| | | ADC_IN4_Init(); |
| | | LIT_DEC_ON; |
| | | // delay_ms(10); |
| | | delay_ms(5); |
| | | if ((data_ins = (ad_data_s *)malloc(sizeof(data_ins) + sizeof(uint16_t) * AD_LITH_BAT_CNT)) != NULL) |
| | | { |
| | | data_ins->ad_buffer_cnt = AD_LITH_BAT_CNT; |
| | |
| | | } |
| | | |
| | | |
| | | /*µç³Øµçѹ״̬ÅжÏ*/ |
| | | #define LITH_LOW_EFFECTIVE_VOLTAGE_VALUE (3.2f - 2.9f) |
| | | void Lith_Bat_Voltage_Status(float lith_vcc,int8_t * pLith_vcc_per) |
| | | /*µç³Øµçѹ״̬ÅжÏ,״̬ÍùÉϱä¸üÐèÒª´óÓÚãÐÖµ+0.2V£¬·Àֹ״̬ÔÚãÐÖµÉÏÏÂÌø¶¯*/ |
| | | void Lith_Bat_Voltage_Status(float lith_vcc,PWR_VOL_T *pwr_vol_p) |
| | | { |
| | | |
| | | if(lith_vcc < bat_para_g.lith_bat_under_v*0.1){ |
| | | pwr_vol_p->lith_vcc_status = BAT_V_DOWN; |
| | | }else if(lith_vcc < bat_para_g.lith_bat_under_v*0.1 + 0.2){ |
| | | if(pwr_vol_p->lith_vcc_status == BAT_V_DOWN){ |
| | | pwr_vol_p->lith_vcc_status = BAT_V_DOWN; |
| | | }else{ |
| | | pwr_vol_p->lith_vcc_status = BAT_V_LOW; |
| | | } |
| | | }else if(lith_vcc < bat_para_g.lith_bat_low_v*0.1){ |
| | | pwr_vol_p->lith_vcc_status = BAT_V_LOW; |
| | | }else if(lith_vcc < bat_para_g.lith_bat_low_v*0.1 + 0.2){ |
| | | if(pwr_vol_p->lith_vcc_status == BAT_V_LOW){ |
| | | pwr_vol_p->lith_vcc_status = BAT_V_LOW; |
| | | }else{ |
| | | pwr_vol_p->lith_vcc_status = BAT_V_NONE; |
| | | } |
| | | }else{ |
| | | pwr_vol_p->lith_vcc_status = BAT_V_NONE; |
| | | } |
| | | |
| | | } |
| | | |
| | | void Alka_Bat_Voltage_Status(float alka_vcc) |
| | | void Alka_Bat_Voltage_Status(float alka_vcc,PWR_VOL_T *pwr_vol_p) |
| | | { |
| | | float fTemp; |
| | | if(alka_vcc < bat_para_g.alka_bat_under_v*0.1){ |
| | | pwr_vol_p->alka_vcc_status = BAT_V_DOWN; |
| | | }else if(alka_vcc < bat_para_g.alka_bat_under_v*0.1 + 0.2){ |
| | | if(pwr_vol_p->alka_vcc_status == BAT_V_DOWN){ |
| | | pwr_vol_p->alka_vcc_status = BAT_V_DOWN; |
| | | }else{ |
| | | pwr_vol_p->alka_vcc_status = BAT_V_LOW; |
| | | } |
| | | }else if(alka_vcc < bat_para_g.alka_bat_low_v*0.1){ |
| | | pwr_vol_p->alka_vcc_status = BAT_V_LOW; |
| | | }else if(alka_vcc < bat_para_g.alka_bat_low_v*0.1 + 0.2){ |
| | | if(pwr_vol_p->alka_vcc_status==BAT_V_LOW){ |
| | | pwr_vol_p->alka_vcc_status = BAT_V_LOW; |
| | | }else{ |
| | | pwr_vol_p->alka_vcc_status = BAT_V_NONE; |
| | | } |
| | | }else{ |
| | | pwr_vol_p->alka_vcc_status = BAT_V_NONE; |
| | | } |
| | | |
| | | if(pwr_vol_p->alka_vcc_status == BAT_V_DOWN){ |
| | | pwr_vol_p->lith_vcc_per = 0; |
| | | }else if(pwr_vol_p->alka_vcc_status == BAT_V_LOW){ |
| | | if(bat_para_g.alka_bat_low_v > bat_para_g.alka_bat_under_v){ |
| | | fTemp = BAT_PERSENT_LEVEL_1*(alka_vcc - bat_para_g.alka_bat_low_v*0.1) /(0.1*(bat_para_g.alka_bat_low_v - bat_para_g.alka_bat_under_v)); |
| | | if |
| | | }else |
| | | { |
| | | pwr_vol_p->lith_vcc_per = 0; |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /**MCUζÈ״̬ÅжÏ*/ |
| | | void MCU_temperature_Status(float mcu_tem,PWR_VOL_T *pwr_vol_p) |
| | | { |
| | | |
| | | } |
| | | |
| | | |
| | | //ï®µç³ØÊ¹ÓÃʱ¼ä¼ÆÊý |
| | | void LithBatUseTimeCalculate(BAT_PARA_T *bat_para_p) |
| | | { |
| | | bat_para_p->lith_bat_used_sec ++; |
| | | if(bat_para_p->lith_bat_used_sec >=3600){ |
| | | bat_para_p->lith_bat_used_sec = 0; |
| | | |
| | | bat_para_p->lith_bat_used_hour ++; |
| | | |
| | | //? ´æ´¢£¬Ôݶ¨Ã¿Ð¡Ê±´æ´¢Ò»´Î |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | /*»ñµÃµç³Øµçѹ*/ |
| | | void GetBatVoltagePro(PWR_VOL_T *pwr_vol_p) |
| | | /*»ñµÃµçԴ״̬¡£ï®µç¡¢¼îµç¡¢Íâµç¡¢MCUζÈ*/ |
| | | void GetPwrStatusPro(PWR_VOL_T *pwr_vol_p) |
| | | { |
| | | const uint16_t DELAY_TIME = 5; |
| | | static uint16_t delay_time_cnt = 0; |
| | |
| | | if(pwr_vol_p->lith_flag != LMS_NONE ){ |
| | | pwr_vol_p->lith_flag = LMS_NONE; |
| | | pwr_vol_p->lith_vcc = Get_Lith_Bat_Voltage();//﮵ç¼ì²â |
| | | Lith_Bat_Voltage_Status(pwr_vol_p->lith_vcc,pwr_vol_p); |
| | | } |
| | | |
| | | if((pwr_vol_p->alka_flag != LMS_NONE)&&(delay_time_cnt >= DELAY_TIME) ){ |
| | | pwr_vol_p->alka_flag = AMS_PERIOD; |
| | | pwr_vol_p->alka_vcc = Get_Alka_Bat_Voltage();//¼îµç¼ì²â |
| | | } |
| | | Alka_Bat_Voltage_Status(pwr_vol_p->alka_vcc,pwr_vol_p); |
| | | } |
| | | |
| | | if(pwr_vol_p->mcu_temp_flag == SET){ |
| | | pwr_vol_p->mcu_temp_flag = RESET; |
| | | pwr_vol_p->mcu_temperature = Get_Mcu_Temp();//mcuζȻñÈ¡ |
| | | |
| | | } |
| | | |
| | | |
| | | /*µç³ØÊ¹ÓÃʱ¼ä¼ÆË㣬ÔÙ¸ù¾Ýµçѹ״̬ºÍʹÓÃʱ¼ä״̬×ۺϵóö×îÖÕµÄµç³Ø×´Ì¬*/ |
| | | if(__SYS_STATUS_BYTES_GET(power_state) ==RESET) |
| | | LithBatUseTimeCalculate(&bat_para_g); |
| | | |
| | | |
| | | |
| | | /****Íâµçʵʱ¼à²â******/ |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | //³ÌÐòÆô¶¯ºóµçÔ´¹ÜÀí³õʼ»¯£¬ Ê×´ÎÍâµçÅжϣ¬Ê×´Îµç³Øµçѹ²É¼¯ |
| | | void PowerManagrInit(void) |
| | | { |
| | | pwr_vol_g.lith_vcc = Get_Lith_Bat_Voltage();//﮵ç¼ì²â |
| | | if(pwr_vol_g.lith_vcc < bat_para_g.lith_bat_under_v*0.1){ |
| | | __SYS_STATUS_BYTES_STATUS(lith_down, SET, ALARM_ID_LITH_BAT_DOWN); |
| | | __SYS_STATUS_BYTES_STATUS(lith_low, SET, ALARM_ID_LITH_BAT_LOW); |
| | | }else if(pwr_vol_g.lith_vcc < bat_para_g.lith_bat_low_v*0.1){ |
| | | __SYS_STATUS_BYTES_STATUS(lith_down, RESET, ALARM_ID_LITH_BAT_DOWN); |
| | | __SYS_STATUS_BYTES_STATUS(lith_low, SET, ALARM_ID_LITH_BAT_LOW); |
| | | }else{ |
| | | __SYS_STATUS_BYTES_STATUS(lith_down, RESET, ALARM_ID_LITH_BAT_DOWN); |
| | | __SYS_STATUS_BYTES_STATUS(lith_low, RESET, ALARM_ID_LITH_BAT_LOW); |
| | | } |
| | | |
| | | pwr_vol_g.alka_vcc = Get_Alka_Bat_Voltage();//¼îµç¼ì²â |
| | | if(pwr_vol_g.alka_vcc < bat_para_g.alka_bat_under_v*0.1){ |
| | | __SYS_STATUS_BYTES_STATUS(alka_down, SET, ALARM_ID_ALKA_BAT_DOWN); |
| | | __SYS_STATUS_BYTES_STATUS(alka_low, SET, ALARM_ID_ALKA_BAT_LOW); |
| | | }else if(pwr_vol_g.alka_vcc < bat_para_g.alka_bat_low_v*0.1){ |
| | | __SYS_STATUS_BYTES_STATUS(alka_down, RESET, ALARM_ID_ALKA_BAT_DOWN); |
| | | __SYS_STATUS_BYTES_STATUS(alka_low, SET, ALARM_ID_ALKA_BAT_LOW); |
| | | }else{ |
| | | __SYS_STATUS_BYTES_STATUS(alka_down, RESET, ALARM_ID_ALKA_BAT_DOWN); |
| | | __SYS_STATUS_BYTES_STATUS(alka_low, RESET, ALARM_ID_ALKA_BAT_LOW); |
| | | } |
| | | |
| | | //Íâµç¼ì²â,HWID0µÍλÓÐÍâµç |
| | | if(HWIDO_EX_PWR_IO_READ == Bit_RESET){ |
| | | delay_ms(10); |
| | | if(HWIDO_EX_PWR_IO_READ == Bit_RESET){ |
| | | __SYS_STATUS_BYTES_STATUS(power_state, SET, ALARM_ID_NORMAL); |
| | | }else{ |
| | | __SYS_STATUS_BYTES_STATUS(power_state, RESET, ALARM_ID_NORMAL); |
| | | } |
| | | }else{ |
| | | __SYS_STATUS_BYTES_STATUS(power_state, RESET, ALARM_ID_NORMAL); |
| | | } |
| | | |
| | | |
| | | } |