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
|
|||
|
|
//<2F>жϸ<D0B6><CFB8><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
|
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
|
|||
|
|
//==============================================================================
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ 3V
|
|||
|
|
CheckSystemVoltageInit();
|
|||
|
|
systemVoltage = ReadAndComputeVoltage();
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD><D8B9><EFBFBD><EFBFBD><EFBFBD>ѹ
|
|||
|
|
CheckBatteryVoltageInit();
|
|||
|
|
batteryVoltage = ReadAndComputeVoltage();
|
|||
|
|
//batteryVoltage = MovingAverage(batteryVoltage, 100, BATT);
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD><EFBFBD><EFBFBD><CDB9><EFBFBD>ģʽ
|
|||
|
|
CheckEndIntoLowPower();
|
|||
|
|
|
|||
|
|
//<2F>жϵ<D0B6><CFB5>ع<EFBFBD><D8B9><EFBFBD>״̬
|
|||
|
|
JudgeSystemVolState();
|
|||
|
|
}
|