145 lines
4.1 KiB
C
145 lines
4.1 KiB
C
#include "../main/SystemInclude.h"
|
|
//==============================================================================
|
|
|
|
u16 batteryTestPeriod, batteryTestPeriodSet;
|
|
|
|
//******************************************************************************
|
|
void CheckSystemVoltageInit(void)
|
|
{
|
|
}
|
|
|
|
//******************************************************************************
|
|
void CheckBatteryVoltageInit(void)
|
|
{
|
|
//BATOP_POWER_OUTPUT();
|
|
//TURN_ON_BATOP_POWER();
|
|
|
|
//==============================================================================
|
|
#ifndef ENABLE_BAT_SEL_PIN
|
|
#pragma message("[undefined] ENABLE_BAT_SEL_PIN")
|
|
#elif(ENABLE_BAT_SEL_PIN)
|
|
BATOP_SEL_OUTPUT();
|
|
SELECT_MAIN_BAT();
|
|
#endif
|
|
//==============================================================================
|
|
}
|
|
|
|
//******************************************************************************
|
|
u16 ComputeVoltage(u16 codeVol)
|
|
{
|
|
tmpLA = (u32)codeVol;
|
|
tmpLA *= 400; //for vref=2.0V
|
|
tmpLA >>= 10;
|
|
|
|
return (u16)tmpLA;
|
|
}
|
|
|
|
//******************************************************************************
|
|
u16 ReadAndComputeVoltage(void)
|
|
{
|
|
return ComputeVoltage(1);
|
|
}
|
|
|
|
//******************************************************************************
|
|
void CheckEndIntoLowPower(void)
|
|
{
|
|
//TURN_OFF_BATOP_POWER();
|
|
|
|
//============================================================================
|
|
#ifndef ENABLE_BAT_SEL_PIN
|
|
#pragma message("[undefined] ENABLE_BAT_SEL_PIN")
|
|
#elif(ENABLE_BAT_SEL_PIN)
|
|
BATOP_SEL_OUTPUT();
|
|
SELECT_RF_BAT();
|
|
#endif
|
|
|
|
}
|
|
|
|
//******************************************************************************
|
|
void JudgeSystemVolState(void)
|
|
{
|
|
// systemVoltage = 271; //FY
|
|
// batteryVoltage = 278;
|
|
|
|
|
|
#ifndef DISABLE_BAT_ALARM
|
|
#pragma message("[undefined] DISABLE_BAT_ALARM")
|
|
#elif(DISABLE_BAT_ALARM)
|
|
systemAlarm.Bit.BatteryAlarm = 0;
|
|
systemAlarm.Bit.BatteryOff = 0;
|
|
#else
|
|
//Åжϸ÷¹¤×÷״̬
|
|
systemAlarm.Bit.BatteryAlarm = 0;
|
|
systemAlarm.Bit.BatteryOff = 0;
|
|
|
|
batteryGrid = 0;
|
|
if(batteryVoltage >= VOLTAGE_315) batteryGrid = 4;
|
|
else if(batteryVoltage >= VOLTAGE_310) batteryGrid = 3;
|
|
else if(batteryVoltage >= VOLTAGE_305) batteryGrid = 2;
|
|
else if(batteryVoltage >= VOLTAGE_300) batteryGrid = 1;
|
|
|
|
if(batteryGrid > 0) return;
|
|
batteryGrid = 0;
|
|
systemAlarm.Bit.BatteryAlarm = 1;
|
|
HWState.EnableCheck = 1;
|
|
sampleState.EnableRoughTest = 0;
|
|
roughTestCounter = 0;
|
|
|
|
// if(batteryVoltage < systemVoltage )
|
|
// {
|
|
// HWState.EnableCheck = 1;
|
|
// sampleState.EnableRoughTest = 0;
|
|
// roughTestCounter = 0;
|
|
// }
|
|
|
|
currentMode.Bit.TurnOffSystem = 0;
|
|
if(systemVoltage < TURN_OFF_SYSTEM)
|
|
{
|
|
SysVolErrorCount++;
|
|
if(SysVolErrorCount < 16) return;
|
|
|
|
SysVolErrorCount = 16;
|
|
currentMode.Bit.TurnOffSystem = 1;
|
|
systemAlarm.Bit.BatteryAlarm = 1;
|
|
systemAlarm.Bit.BatteryOff = 1;
|
|
HWState.EnableCheck = 0;
|
|
}
|
|
else SysVolErrorCount = 0;
|
|
|
|
#endif
|
|
}
|
|
|
|
//******************************************************************************
|
|
void CheckSystemAndBatteryVoltage(void)
|
|
{
|
|
batteryTestPeriodSet = 0;
|
|
batteryTestPeriod = (u16)ReadParameterFromMemory(BATTEST_PERIOD, BATTEST_PERIOD_WIDTH, BATTEST_PERIOD_DEFAULT);
|
|
|
|
//BATOP_POWER_OUTPUT();
|
|
//TURN_ON_BATOP_POWER();
|
|
|
|
//==============================================================================
|
|
#ifndef ENABLE_BAT_SEL_PIN
|
|
#pragma message("[undefined] ENABLE_BAT_SEL_PIN")
|
|
#elif(ENABLE_BAT_SEL_PIN)
|
|
BATOP_SEL_OUTPUT();
|
|
SELECT_MAIN_BAT();
|
|
#endif
|
|
//==============================================================================
|
|
|
|
//²âÁ¿ÏµÍ³¹¤×÷µçѹ 3V
|
|
CheckSystemVoltageInit();
|
|
systemVoltage = ReadAndComputeVoltage();
|
|
|
|
//²âÁ¿µç³Ø¹¤×÷µçѹ
|
|
CheckBatteryVoltageInit();
|
|
batteryVoltage = ReadAndComputeVoltage();
|
|
//batteryVoltage = MovingAverage(batteryVoltage, 100, BATT);
|
|
|
|
//²âÁ¿Íê±Ï½øÈëµÍ¹¦ºÄģʽ
|
|
CheckEndIntoLowPower();
|
|
|
|
//ÅÐ¶Ïµç³Ø¹¤×÷״̬
|
|
JudgeSystemVolState();
|
|
}
|