699 lines
24 KiB
C
699 lines
24 KiB
C
#include "../main/SystemInclude.h"
|
||
|
||
u16 systmeState ;
|
||
u16 UPGRADECammand ;
|
||
u16 CodeCRC ;
|
||
u16 jumpError ;
|
||
//******************************************************************************
|
||
// for internel modbus
|
||
u32 securityID; //
|
||
|
||
//*****************************************************************************
|
||
//for modbus >16bit register define
|
||
u32 flowRate,flowAccumulationInteger;
|
||
s32 GASPressure;
|
||
u64 flowAccumulationHex;
|
||
u32 minFlowRate,maxFlowRate,minAnalogOutput,maxAnalogOutput;
|
||
u32 alarmAcc,alarmUpperFlowRate,alarmLowerFlowRate;
|
||
u32 reverseFlowRateMin, reverseFlowRateMax;
|
||
u32 keyPassWord;
|
||
//*******************************************************************************
|
||
__SystemProcess_Union_TypeDef systemProcess;
|
||
__SystemState_Union_TypeDef currentMode;
|
||
__Hardware_Status_Bit_TypeDef HWState;
|
||
__Alarm_State_TypeDef systemAlarm;
|
||
//******************************************************************************
|
||
u16 curveMode;
|
||
u16 SysLcd, SysLoopChip;// currentSysState;
|
||
u16 testTypeCounter, MEMSErrorCounter;
|
||
u16 systemVoltage, batteryGrid;
|
||
u16 calibType;
|
||
// for code CRC
|
||
u16 APPCodeCRC;
|
||
u32 securityID;
|
||
u16 IDvalidTime, comCounter, comResetCounter, AutoOffsetCounter, timePeriod, autoTxdCounter, SysVolErrorCount;
|
||
u32 ModeExitTime;
|
||
u16 language;
|
||
__Display_Status_Bit_TypeDef displayMode;
|
||
u16 roughTestCounter, testCounter;
|
||
// for save data
|
||
u16 timeCompute;
|
||
//for system
|
||
u16 lastState, syatemHardState;
|
||
//------------------------------------------------------------------------------
|
||
// for display
|
||
u8 Dis1[15], timer[8];
|
||
u16 displayUpdate, displayCNT;
|
||
//u8 flowRateUnit, AccUnit;
|
||
//------------------------------------------------------------------------------
|
||
// for ADC Sampling
|
||
u16 reverseScale, zeroSuppression, calibFlowGain;
|
||
//------------------------------------------------------------------------------
|
||
// for flowRate
|
||
u32 currentFlowRate, factoryFlowRate;
|
||
//------------------------------------------------------------------------------
|
||
u16 calibTemperature;
|
||
//------------------------------------------------------------------------------
|
||
// for acc pulse output
|
||
u16 samplingInterval, samplingIntervalTarget, factoryInterval, responseTimeIndex;
|
||
u16 updatePulseTime;
|
||
//------------------------------------------------------------------------------
|
||
u16 tmpIA;
|
||
s32 tmpSLA, tmpSLB;
|
||
u32 tmpLA, tmpLB;
|
||
|
||
TypeWord tempWord;
|
||
TypeLong tempL;
|
||
TypeLongLong tempDev;
|
||
//------------------------------------------------------------------------------
|
||
const u8 ProductModel[12] = PRODUCT_MOD;
|
||
const u8 SoftVersion[12] = VERSION;
|
||
const u8 SoftBuildDate[10] = BUILD_MV;
|
||
const u8 PulseOutGain[] ={32,16,8,4,2,1}; //
|
||
const u8 FilterMax[] ={1, 2, 4, 8, 16, 32}; // filter depth
|
||
const u16 Timing[] ={BASE_125MS, BASE_250MS, BASE_500MS, BASE_1000MS, BASE_2000MS, BASE_4000MS};
|
||
const u16 TimeVaule[] ={4096, 8192, 16384, 32768, 65535}; //2048, 0.125s<EFBFBD><EFBFBD>0.25s, 0.5s, 1s, 2s, 4s
|
||
const u16 UpdateTimeVaule[] ={3000, 3850, 7372, 8192, 16384, 16384}; // 0.235s, 0.45s, 0.5s, 1s, 2s
|
||
const u16 FRUnitForHour[] ={28800, 14400, 7200, 3600, 1800, 900};
|
||
const u16 FRUnitForMinute[] ={480, 240, 120, 60, 30, 15};
|
||
//------------------------------------------------------------------------------
|
||
const u8 BuildDate[] = __DATE__; // "Oct 30 2010"
|
||
/******************************************************************************/
|
||
|
||
|
||
//******************************************************************************
|
||
void EnterUserMode(void)
|
||
{
|
||
currentMode.Bit.CalibMode = 0;
|
||
currentMode.Bit.IntCalibMode = 0;
|
||
|
||
currentMode.Bit.FactoryTestMode = 0;
|
||
currentMode.Bit.DebugMode = 0;
|
||
|
||
currentMode.Bit.DigitOutput = 1;
|
||
currentMode.Bit.ComModeOperate = 0;
|
||
ModeExitTime = 0;
|
||
}
|
||
|
||
//******************************************************************************
|
||
void EnterCalibMode(void)
|
||
{
|
||
currentMode.Bit.CalibMode = 1;
|
||
currentMode.Bit.IntCalibMode = 1;
|
||
currentMode.Bit.FactoryTestMode = 0;
|
||
currentMode.Bit.DebugMode = 0;
|
||
currentMode.Bit.DigitOutput = 1;
|
||
currentMode.Bit.ComModeOperate = 1;
|
||
ModeExitTime = 0;
|
||
}
|
||
|
||
//******************************************************************************
|
||
void EnterZeroCalibMode(void)
|
||
{
|
||
currentMode.Bit.CalibMode = 1;
|
||
currentMode.Bit.IntCalibMode = 1;
|
||
currentMode.Bit.ZeroCalib = 1;
|
||
|
||
currentMode.Bit.FactoryTestMode = 0;
|
||
currentMode.Bit.DebugMode = 0;
|
||
currentMode.Bit.DigitOutput = 1;
|
||
currentMode.Bit.ComModeOperate = 1;
|
||
ModeExitTime = 0;
|
||
}
|
||
|
||
//******************************************************************************
|
||
void EnterBatteryMode(void)
|
||
{
|
||
currentMode.Bit.CalibMode = 0;
|
||
currentMode.Bit.IntCalibMode = 0;
|
||
currentMode.Bit.FactoryTestMode = 0;
|
||
currentMode.Bit.DebugMode = 0;
|
||
|
||
currentMode.Bit.DigitOutput = 1;
|
||
currentMode.Bit.ComModeOperate = 1;
|
||
|
||
ModeExitTime = 0;
|
||
currentMode.Bit.ExtPowerInput = 0;
|
||
}
|
||
|
||
//******************************************************************************
|
||
void EnterDebugMode(void)
|
||
{
|
||
currentMode.Bit.CalibMode = 0;
|
||
currentMode.Bit.IntCalibMode = 0;
|
||
currentMode.Bit.FactoryTestMode = 0;
|
||
currentMode.Bit.DebugMode = 1;
|
||
currentMode.Bit.DigitOutput = 1;
|
||
currentMode.Bit.ComModeOperate = 1;
|
||
currentMode.Bit.ExtPowerInput = 1;
|
||
ModeExitTime = 0;
|
||
}
|
||
|
||
//******************************************************************************
|
||
void EnterGcfTestMode(void)
|
||
{
|
||
currentMode.Bit.CalibMode = 0;
|
||
currentMode.Bit.FactoryTestMode = 0;
|
||
currentMode.Bit.DebugMode = 0;
|
||
|
||
currentMode.Bit.ExtPowerInput = 1;
|
||
currentMode.Bit.DigitOutput = 1;
|
||
currentMode.Bit.ComModeOperate = 1;
|
||
ModeExitTime = 0;
|
||
}
|
||
|
||
////******************************************************************************
|
||
void ManagePrimaryTimeInterval(void)
|
||
{
|
||
u32 currentPerPulse;
|
||
samplingIntervalTarget = factoryInterval;//
|
||
|
||
if(currentMode.Bit.CalibMode)
|
||
{
|
||
//currentPerPulse = (s16)calibUnitPerPuls;
|
||
sampleState.EnableRoughTest = 0;
|
||
HWState.EnableCheck = 1;
|
||
samplingIntervalTarget = (u16)EXT_POWER_PERIOD_TIME;
|
||
}
|
||
else
|
||
{
|
||
//currentPerPulse = (s16)factoryUnitPerPuls;
|
||
if(currentMode.Bit.ExtPowerInput)
|
||
{
|
||
HWState.EnableCheck = 1;
|
||
samplingIntervalTarget = (u16)EXT_POWER_PERIOD_TIME;
|
||
currentMode.Bit.TurnOffSystem = 0;
|
||
sampleState.EnableRoughTest = 0;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
#ifndef ENABLE_ACCPULSE
|
||
#pragma message("[undefined] ENABLE_ACCPULSE")
|
||
#elif(ENABLE_ACCPULSE)
|
||
currentPerPulse = InitPulseUnit(currentPerPulse);
|
||
if(currentPerPulse != unitPerPulse) lastRemaining = 0;
|
||
unitPerPulse = currentPerPulse;
|
||
#endif
|
||
|
||
//---------------------------------------------------------------------------
|
||
if((currentMode.Bit.DebugMode)||(currentMode.Bit.ZeroCalib))
|
||
{
|
||
sampleState.EnableRoughTest = 0;
|
||
testCounter = 5;
|
||
}
|
||
else if(MEMSErrorCounter != 0) testCounter = 2;
|
||
else testCounter = 60;
|
||
//if(samplingInterval < 3) sampleState.EnableRoughTest = 0;
|
||
}
|
||
|
||
|
||
u32 ReadParameterFromMemory(u16 parameterAdr, u16 parameterLen, u32 parameterDefault)
|
||
{
|
||
tempDev.DWord[0] = 0;
|
||
|
||
if(1) ReadParameterFromFlash(tempDev.Byte , parameterAdr , parameterLen , VENDER_PARAMS_PAGE);
|
||
else ReadMultiByteFromEEPROM(parameterAdr, tempDev.Byte, parameterLen, PARA_EEPROM);
|
||
|
||
parameterLen--;
|
||
|
||
if(tempDev.Byte[parameterLen] != CRC8(tempDev.Byte, parameterLen))
|
||
{
|
||
tempDev.DWord[0] = (u32)parameterDefault;
|
||
isReadParameterOK = 0;
|
||
}
|
||
else
|
||
{
|
||
tempDev.Byte[parameterLen] = 0;
|
||
isReadParameterOK = 1;
|
||
}
|
||
|
||
return tempDev.DWord[0];
|
||
}
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
void BackupParameterToFlash(void)
|
||
{
|
||
//FY WriteShortParameterToBuffer(UPGRADECammand, UPGRADE_APP, UPGRADE_APP_WIDTH);
|
||
//FY WriteShortParameterToBuffer(localAddress, SLAVER_ADDR, SLAVER_ADDR_WIDTH);
|
||
//WriteShortParameterToBuffer(baudRate, BAUD_RATE, BAUD_RATE_WIDTH);
|
||
// clear_WDT();
|
||
//
|
||
// disable_interrupts();
|
||
////FY WriteMultiByteToInfoSegment(PARAMETER_BASE, FlashBuf, PARA_LEN);
|
||
// enable_interrupts();
|
||
|
||
//FY ReadMultiByteFromInfoSegment(PARAMETER_BASE, FlashBuf, PARA_LEN);
|
||
}
|
||
|
||
//******************************************************************************
|
||
//ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
u32 sn ;
|
||
void SystemParameterInit(void)
|
||
{
|
||
currentMode.Bit.ComModeOperate = 0;
|
||
//==============================================================================
|
||
// <20>ȶ<EFBFBD>ȡ<EFBFBD>¶ȣ<C2B6><C8A3>ж<EFBFBD>ģʽ
|
||
StaticTemperatureInit();
|
||
ManagePrimaryTimeInterval();
|
||
//==============================================================================
|
||
meterSN1 = ReadParameterFromMemory(SERIES_BASE+0*SENSOR_SN_WIDTH ,SENSOR_SN_WIDTH ,0);
|
||
meterSN2 = ReadParameterFromMemory(SERIES_BASE+1*SENSOR_SN_WIDTH ,SENSOR_SN_WIDTH ,0);
|
||
meterSN3 = ReadParameterFromMemory(SERIES_BASE+2*SENSOR_SN_WIDTH ,SENSOR_SN_WIDTH ,0);
|
||
meterSN4 = ReadParameterFromMemory(SERIES_BASE+3*SENSOR_SN_WIDTH ,SENSOR_SN_WIDTH ,0);
|
||
meterSN5 = ReadParameterFromMemory(SERIES_BASE+4*SENSOR_SN_WIDTH ,SENSOR_SN_WIDTH ,0);
|
||
meterSN6 = ReadParameterFromMemory(SERIES_BASE+5*SENSOR_SN_WIDTH ,SENSOR_SN_WIDTH ,0);
|
||
//==============================================================================
|
||
// for meter factor
|
||
MeterFactor = ReadParameterFromMemory(METER_FACTOR, METER_FACTOR_WIDTH, METER_PARAMETER_DEFAULT);
|
||
// for GDCF
|
||
GCFCoefA = (s32)ReadParameterFromMemory(GCF_A, GCF_A_WIDTH, (u32)GCF_A_DEFAULT);
|
||
GDCFactor = (u16)ReadParameterFromMemory(GCF_B, GCF_B_WIDTH, GCF_DEFAULT);
|
||
GCFCoefC = (s32)ReadParameterFromMemory(GCF_C, GCF_C_WIDTH, GCF_C_DEFAULT);
|
||
ComputeGCFFactor();
|
||
|
||
clear_WDT();
|
||
//offset Air & Gas
|
||
offsetAir = ReadParameterFromMemory(OFFSET_AIR ,OFFSET_AIR_WIDTH ,32768);
|
||
offsetGas = ReadParameterFromMemory(OFFSET_GAS ,OFFSET_GAS_WIDTH ,32768);
|
||
|
||
//------------------------------------------------------------------------------
|
||
offsetGCFX = (u16)ReadParameterFromMemory(OFFSET_GCFX, OFFSET_GCFX_WIDTH, 32768);
|
||
//------------------------------------------------------------------------------
|
||
factoryInterval = (u16)ReadParameterFromMemory(SAMPLE_PERIOD, SAMPLE_PERIOD_WIDTH, SAMPLE_PERIOD_DEFAULT);
|
||
samplingInterval = factoryInterval;
|
||
samplingTiming = SetupResponseTime(factoryInterval, SAMPLE_PERIOD_DEFAULT);
|
||
responseTimeIndex = (u16)ReadParameterFromMemory(RESPONSE_TIME, RESPONSE_TIME_WIDTH, RESPONSE_TIME_DEFAULT);
|
||
responseTime = SetupResponseTime(responseTimeIndex, RESPONSE_TIME_DEFAULT);
|
||
|
||
// for max current Loop flowrate
|
||
maxFlowRate = ReadParameterFromMemory(MAX_FLOW, MAX_FLOW_WIDTH, MAX_FR_DEFAULT);
|
||
minFlowRate = ReadParameterFromMemory(MIN_FLOW, MIN_FLOW_WIDTH, MIN_FR_DEFAULT); // V2004
|
||
|
||
// for read caluibration temperation
|
||
calibTemperature = (u16)ReadParameterFromMemory(CALIB_TEMPERATURE, CALIB_TEMPERATURE_WIDTH, TEMPRETURE_OFFSET);
|
||
|
||
// read
|
||
reverseScale = (u16)ReadParameterFromMemory(REVERSE_SCALE, REVERSE_SCALE_WIDTH, REVERSE_SCALE_DEFAULT);
|
||
|
||
// read display langauge unit
|
||
language = (u8)(u16)ReadParameterFromMemory(DIS_LANGUAGE, DIS_LANGUAGE_WIDTH, (u16)DIS_LANGUAGE_DEFAULT);
|
||
|
||
// read zero Suppression
|
||
zeroSuppression = (u16)ReadParameterFromMemory(ZERO_SUPPRESSION, ZERO_SUPPRESSION_WIDTH, ZERO_SUPPRESSION_DEFAULT);
|
||
|
||
clear_WDT();
|
||
//read uart DecimalPoint
|
||
uartDecimalPoint = (u16)ReadParameterFromMemory(COM_DECIMAL_POINT, COM_DECIMAL_POINT_WIDTH, COM_DECIMAL_POINT_DEFAULT);
|
||
|
||
//============================================================================
|
||
// for AUTO TXD DATA
|
||
timingTxdStart = (u16)ReadParameterFromMemory(TIMING_TXD_START, TIMING_TXD_START_WIDTH, TIMING_TXD_START_DEFAULT);
|
||
timingTxdLen = (u16)ReadParameterFromMemory(TIMING_TXD_LEN, TIMING_TXD_LEN_WIDTH, TIMING_TXD_LEN_DEFAULT);
|
||
timingTxdTime = (u16)ReadParameterFromMemory(TIMING_TXD_TIME, TIMING_TXD_TIME_WIDTH, TIMING_TXD_TIME_DEFAULT);
|
||
|
||
clear_WDT();
|
||
// key setup password
|
||
//============================================================================
|
||
#ifndef ENABLE_KEY_FUNCTION
|
||
#pragma message("[undefined] ENABLE_KEY_FUNCTION")
|
||
#elif(ENABLE_KEY_FUNCTION)
|
||
keyPassWord = ReadParameterFromMemory(KEY_PASSWORD, KEY_PASSWORD_WIDTH, KEY_PASSWORD_DEFAULT);
|
||
#endif
|
||
|
||
//============================================================================
|
||
UnitConverterInit();
|
||
//============================================================================
|
||
#ifndef ENABLE_ACCPULSE
|
||
#pragma message("[undefined] ENABLE_ACCPULSE")
|
||
#elif(ENABLE_ACCPULSE)
|
||
PulseParameterInit();
|
||
#endif
|
||
|
||
//============================================================================
|
||
// RHCircuitParameterInit();
|
||
|
||
//============================================================================
|
||
GasAnalysisParameterInit();
|
||
|
||
//============================================================================
|
||
SaveParameterInit();
|
||
|
||
//============================================================================
|
||
AdjustOffsetInit();
|
||
|
||
//============================================================================
|
||
#ifndef ENABLE_PLUG_IN_FLOWRATE
|
||
#pragma message("[undefined] ENABLE_PLUG_IN_FLOWRATE")
|
||
#elif(ENABLE_PLUG_IN_FLOWRATE)
|
||
PipeFlowRateComputeInit();
|
||
#endif
|
||
|
||
//============================================================================
|
||
#ifndef ENABLE_A_TYPE_FLOWRATE
|
||
#pragma message("[undefined] ENABLE_A_TYPE_FLOWRATE")
|
||
#elif(ENABLE_A_TYPE_FLOWRATE)
|
||
ATypeFlowRateInit();
|
||
#endif
|
||
|
||
//==============================================================================
|
||
// retrieve device coefficients
|
||
#ifndef ENABLE_DCOEF
|
||
#pragma message("[undefined] ENABLE_DCOEF")
|
||
#elif(ENABLE_DCOEF)
|
||
RetriveDevCoef();
|
||
#endif
|
||
|
||
//============================================================================
|
||
// for Tempreature correct
|
||
RetriveTACurve();
|
||
|
||
//==============================================================================
|
||
#ifndef REC_ACC_PER
|
||
#pragma message("[undefined] REC_ACC_PER")
|
||
#elif(REC_ACC_PER)
|
||
RetrieveLastAccumulation();
|
||
#endif
|
||
|
||
SetHistoryRecordTime();
|
||
|
||
// for modbus
|
||
InitUseBusParameter();
|
||
|
||
//==============================================================================
|
||
// for system hardware
|
||
#ifndef ENABLE_4_20MA_OUTPUT
|
||
#pragma message("[undefined] ENABLE_4_20MA_OUTPUT")
|
||
#elif(ENABLE_4_20MA_OUTPUT)
|
||
CurrentLoopInit();
|
||
#endif
|
||
|
||
//==============================================================================
|
||
#ifndef ENABLE_USE_EDM7791
|
||
#pragma message("[undefined] ENABLE_USE_EDM7791")
|
||
#elif(ENABLE_USE_EDM7791)
|
||
|
||
#ifndef ENABLE_EDM7791_ALL
|
||
#pragma message("[undefined] ENABLE_EDM7791_ALL")
|
||
#elif(ENABLE_EDM7791_ALL)
|
||
SysLcd = (u16)ReadParameterFromMemory(SYS_LCD, SYS_LCD_WIDTH, SYS_LCD_DEFAULT);
|
||
#else
|
||
#ifndef ENABLE_EMD779103D
|
||
#pragma message("[undefined] ENABLE_EMD779103D")
|
||
#elif(ENABLE_EMD779103D)
|
||
SysLcd = EDM779103D;
|
||
#endif
|
||
|
||
#ifndef ENABLE_EMD779106D
|
||
#pragma message("[undefined] ENABLE_EMD779106D")
|
||
#elif(ENABLE_EMD779106D)
|
||
SysLcd = EDM779106D;
|
||
#endif
|
||
#endif
|
||
#endif
|
||
|
||
//----------------------------------------------------------------------------
|
||
// V2004
|
||
#ifndef ENABLE_ALARM_ACC
|
||
#pragma message("[undefined] ENABLE_ALARM_ACC")
|
||
#elif(ENABLE_ALARM_ACC)
|
||
alarmAcc = ReadParameterFromMemory(ALARM_ACC, ALARM_ACC_WIDTH, ALARM_ACC_DEFAULT);
|
||
#endif
|
||
|
||
//----------------------------------------------------------------------------
|
||
#ifndef ENABLE_OFFSET_CORRECT
|
||
#pragma message("[undefined] ENABLE_OFFSET_CORRECT")
|
||
#elif(ENABLE_OFFSET_CORRECT)
|
||
ComputeOffsetDriftInit();
|
||
#endif
|
||
//----------------------------------------------------------------------------
|
||
|
||
#ifndef ENABLE_LEAK_DETECT
|
||
#pragma message("[undefined] ENABLE_LEAK_DETECT")
|
||
#elif(ENABLE_LEAK_DETECT)
|
||
minLeakFlowRate = (u16)ReadParameterFromMemory(MIN_LEAK_FLOW, MIN_LEAK_FLOW_WIDTH, MIN_LEAK_FLOW_DEFAULT);
|
||
maxLeakFlowRate = (u16)ReadParameterFromMemory(MAX_LEAK_FLOW, MAX_LEAK_FLOW_WIDTH, MAX_LEAK_FLOW_DEFAULT);
|
||
leakDetectTime = (u16)ReadParameterFromMemory(LEAK_TIME, LEAK_TIME_WIDTH, LEAK_TIME_DEFAULT);
|
||
#endif
|
||
|
||
//------------------------------------------------------------------------------
|
||
#ifndef ENABLE_FLOW_GAIN
|
||
#pragma message("[undefined] ENABLE_FLOW_GAIN")
|
||
#elif(ENABLE_FLOW_GAIN)
|
||
calibFlowGain = (u16)ReadParameterFromMemory(FLOW_GAIN, FLOW_GAIN_WIDTH, FLOW_GAIN_DEFAULT);
|
||
if(JudgeFlowRateGain(calibFlowGain)) calibFlowGain = FLOW_GAIN_DEFAULT;
|
||
#endif
|
||
}
|
||
|
||
//******************************************************************************
|
||
// Auto-check
|
||
void SystemHardWareAutoCheck(void)
|
||
{
|
||
u8 rand;
|
||
|
||
systemAlarm.Word = 0;
|
||
|
||
for(rand = 0; rand < 6; rand++) Dis1[rand] = 0;
|
||
|
||
// 1) check CRYSTAL
|
||
// if(AutoCheckCrystal())
|
||
// {
|
||
// Dis1[CHK_CRYSTAL] = 1;
|
||
// systemAlarm.Bit.CrystalAlarm = 1;
|
||
// }
|
||
|
||
// 2) Check calib memory
|
||
rand = ReadByteFromEEPROM(0, PARA_EEPROM);
|
||
rand++;
|
||
WriteByteToEEPROM(0, rand, PARA_EEPROM);
|
||
if(rand != ReadByteFromEEPROM(0, PARA_EEPROM))
|
||
{
|
||
systemAlarm.Bit.EEPROMAlarm = 1;
|
||
Dis1[CHK_PARA] = 1;
|
||
}
|
||
|
||
// 3) Check data memory
|
||
rand = ReadByteFromEEPROM(0, DATA_EEPROM);
|
||
rand++;
|
||
WriteByteToEEPROM(0, rand, DATA_EEPROM);
|
||
if(rand != ReadByteFromEEPROM(0, DATA_EEPROM))
|
||
{
|
||
systemAlarm.Bit.EEPROMAlarm = 1;
|
||
Dis1[CHK_DATA] = 1;
|
||
}
|
||
|
||
// // 4) Check acc memory
|
||
// rand = ReadByteFromFRAM(0);
|
||
// rand++;
|
||
// WriteByteToFRAM(0, rand);
|
||
// if(rand != ReadByteFromFRAM(0))
|
||
// {
|
||
// systemAlarm.Bit.EEPROMAlarm = 1;
|
||
// Dis1[CHK_ACC] = 1;
|
||
// }
|
||
|
||
// 7) Check external RTC and read current time
|
||
//===========================================================================
|
||
#ifndef ENABLE_EXT_RTC
|
||
#pragma message("[undefined] ENABLE_EXT_RTC")
|
||
#elif(ENABLE_EXT_RTC)
|
||
if(ExtRTCDataRead(USR1) == 1) Dis1[CHK_RTC] = 0;
|
||
else if(TestExtRTCReady())
|
||
{
|
||
if(ExtRTCInit())
|
||
{
|
||
Dis1[CHK_RTC] = 1;
|
||
systemAlarm.Bit.RTC_ALARM = 1;
|
||
}
|
||
}
|
||
else Dis1[CHK_RTC] = 2;
|
||
|
||
if(Dis1[CHK_RTC] == 0) ExtRTCTimeRead(); // read IS1208 time
|
||
else ReadCurrentTime();
|
||
|
||
#else
|
||
// ReadCurrentTime();
|
||
#endif
|
||
//FY SetRTCCurrentTime(); // set time to MCU RTC
|
||
|
||
// 7)Check external temprature
|
||
#ifndef ENABLE_USE_MCP9808
|
||
#pragma message("[undefined] ENABLE_USE_MCP9808")
|
||
#elif(ENABLE_USE_MCP9808)
|
||
if(ReadWordRegister(MID) != 0x0054)
|
||
{
|
||
systemAlarm.Bit.TempAlarm = 1;
|
||
Dis1[CHK_TEMP] = 1;
|
||
}
|
||
#endif
|
||
}
|
||
|
||
//******************************************************************************
|
||
void SystemHardWareInit(void)
|
||
{
|
||
/*SPI Bus Init=========================================================================*/
|
||
//TurnOffAnalogCircuit();
|
||
/*IIC Bus Init=========================================================================*/
|
||
SI2C_Init();
|
||
/*Memory Init==========================================================================*/
|
||
EEPROMInit();
|
||
//if(REC_ACC_PER) FRAMInit();// Acc flowrate save enable bit
|
||
/*external tempreture Init============================================================*/
|
||
HWState.EnableTempTest= 1;
|
||
HWState.EnableTempInit=1;
|
||
WriteWordRegister(CONFIG, SHUT_DOWN);//<2F><><EFBFBD>üĴ<C3BC><C4B4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||
/*RTC Init=============================================================================*/
|
||
//FY SetRTCCalendarMode();
|
||
/*External RTC=========================================================================*/
|
||
#ifndef ENABLE_EXT_RTC
|
||
#pragma message("[undefined] ENABLE_EXT_RTC")
|
||
#elif(ENABLE_EXT_RTC)
|
||
if(TestExtRTCReady()) ExtRTCInit();
|
||
#endif
|
||
}
|
||
|
||
//******************************************************************************
|
||
|
||
|
||
|
||
void SystemInterfaceInit(void)
|
||
{
|
||
//uart init============================================================================
|
||
#ifndef ENABLE_USER_UART
|
||
#pragma message("[undefined] ENABLE_USER_UART")
|
||
#elif(ENABLE_USER_UART)
|
||
MainUartInit(baudRateVaule[baudRate]);
|
||
StartDMAForRxdMainUartData();
|
||
#endif
|
||
//iic init============================================================================
|
||
// #ifndef ENABLE_USER_I2C
|
||
// #pragma message("[undefined] ENABLE_USER_I2C")
|
||
// #elif(ENABLE_USER_I2C)
|
||
// I2C_Slave_Init(100000 , 0x02);
|
||
// I2CAddr = localAddress;
|
||
// meterSN1=0x3031; meterSN2=0x3233; meterSN3=0x3435;
|
||
// meterSN4=0x3637; meterSN5=0x3839; meterSN6=0x4041;
|
||
// #endif
|
||
}
|
||
|
||
//******************************************************************************
|
||
void InitGlobalVar(void)
|
||
{
|
||
u8 I;
|
||
|
||
jumpError = 0;
|
||
|
||
clear_WDT();
|
||
//TXDMode = ENABLE_TXD_USE_DMA;
|
||
|
||
displayUpdate = 0;
|
||
flowRate = 0;
|
||
for(I=0; I<12; I++) Dis1[I] = 0;
|
||
for(I=0; I<ANX; I++) voltageDetected[I] = 0;
|
||
|
||
HWState.SampledOver = 0;
|
||
HWState.EnableCheck = 1;
|
||
currentMode.Bit.TurnOffSystem = 0;
|
||
|
||
//==============================================================================
|
||
// softVersion = (u16)SOFT_VERSION;
|
||
softVersion = (u16)VER_MV;
|
||
softVersion <<= 4;
|
||
softVersion |= (u16)VER_SV;
|
||
softVersion <<= 4;
|
||
softVersion |= (u16)VER_RV;
|
||
softVersion <<= 4;
|
||
softVersion |= (u16)VER_BV;
|
||
//=============================================================================
|
||
|
||
// 0x80~0xf0
|
||
protocol = 0;
|
||
localAddress = 1;
|
||
baudRate = BPS_115200;
|
||
minFlowRate = 0;
|
||
maxFlowRate = 0;
|
||
minAnalogOutput = 0;
|
||
maxAnalogOutput = 0;
|
||
GDCFactor = 0;
|
||
GDCFactorAType = 0;
|
||
filterTime = 0;
|
||
factoryInterval = 0;
|
||
offsetGas = 0;
|
||
offsetGasA = 0;
|
||
flowUnit = 0;
|
||
VHHParameterAir = 0;
|
||
VHHParameterScale = 0;
|
||
unitPerPulse = 0;
|
||
alarmFunction = 0;
|
||
alarmOutDelay = 0;
|
||
alarmAcc = 0;
|
||
alarmUpperFlowRate = 0;
|
||
alarmLowerFlowRate = 0;
|
||
|
||
PulseLevel = 0;
|
||
//==============================================================================
|
||
// 0XF0~0XFF: write only (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||
CMDComPassword = 0;
|
||
CMDCalOffset = 0;
|
||
CMDClrRecord = 0;
|
||
|
||
//==============================================================================
|
||
flowAccCumulationRemaining = 0;
|
||
flowAccumulationHex = 0;
|
||
//---------------------------------------------------------------------------
|
||
totalPulse = 0;
|
||
|
||
#ifndef ENABLE_DENSITY_DETECT
|
||
#pragma message("[undefined] ENABLE_DENSITY_DETECT")
|
||
#elif(ENABLE_DENSITY_DETECT)
|
||
density = 0;
|
||
densityFSParameter = 0;
|
||
#endif
|
||
|
||
displayMode.NeedForInit = 1;
|
||
|
||
munWriteParams = WP_NOT;//<2F><>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>Ҫд<D2AA><D0B4>
|
||
}
|
||
|
||
/*******************************************************************************/
|
||
void SystemInitProcess(void)
|
||
{
|
||
if(systmeState != 0xAA55)
|
||
{
|
||
if(CodeCRC == 0) alarmState &= ~BL_CRC_ERROR;
|
||
else alarmState |= BL_CRC_ERROR;
|
||
InitGlobalVar();
|
||
}
|
||
SystemHardWareInit(); //ϵͳӲ<CDB3><D3B2><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||
SystemHardWareAutoCheck();
|
||
SystemParameterInit(); //ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||
SystemInterfaceInit(); //ϵͳ<CFB5>ӿڳ<D3BF>ʼ<EFBFBD><CABC> //USER_UART
|
||
systmeState = 0xAA55;
|
||
}
|
||
|
||
|
||
|
||
u32 sleeptime ;
|
||
void LPTIMER1_IRQ_Callback()//
|
||
{
|
||
StartNormolFlowMeasurement();//ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>źŵIJ<C5B5><C4B2><EFBFBD>
|
||
// LHL_GPIO_TogglePin(pGPIO1, GPIO_PIN_7);
|
||
|
||
// sleeptime++;
|
||
// if (sleeptime == 40){ mcuModeSleeping = 1 ; }
|
||
}
|
||
|
||
|
||
|
||
//******************************************************************************
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
void EnterMainEntry(void)
|
||
{
|
||
samplingInterval = 0;
|
||
StartPrimaryTimerInterval(TimeVaule[samplingInterval]);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||
lptimer_register_irq_callback(PrimaryTimer,LPTIMER1_IRQ_Callback);
|
||
}
|
||
|
||
|