This commit is contained in:
2026-03-20 21:19:04 +08:00
parent 90c3d919df
commit 9d3b4b836f
247 changed files with 22127 additions and 30305 deletions

View File

@@ -1,804 +0,0 @@
#include "../main/SystemInclude.h"
/**************************************************************************************/
/**
* @brief 低功耗定时器初始化函数
* @note 需要定义与硬件相关的函数和IO
* // 数据采样定时器以ms位单位1ms采样一次数据
* StartSamplingTimer(): 1ms 定时为基值
* StopSamplingTimer()
* EnableSamplingInterrupt()、 DisableSamplingInterrupt()
* SamplingInterruptCallBack()
*
* // 加热流程控制定时器以ms位单位
* StartProcessTimer()、 StopProcessTimer()、
* ProcessTimerInterruptCallBack();
* EnableProcessTimerInterrupt();
*/
//##############################################################################
#if(DP2201_CORE_V5000)
//##############################################################################
//__SAMPLE_STATUS_BIT_TypeDef sampleState;
TypeSample sampleProcess;
TypeCalibOffset calibOffset;
u16 FRType;
u16 dynamicOffset,rapidOffsetGas;
u32 roughTestCounter, MEMSErrorCounter;
//ADC放大倍数值与索引转换--------------------------------------------------
u16 GetAdcGain(u16 gianX)
{
switch(gianX)
{
case 1: return GAIN1;
case 2: return GAIN2;
case 4: return GAIN4;
case 8: return GAIN8;
case 16: return GAIN16;
case 32: return GAIN32;
case 64: return GAIN64;
case 128: return GAIN128;
default:
return GetAdcGain(ADC_GAIN_DEFAULT);
}
}
/******************************************************************************/
void SetNextProcess(void)
{
if(sampleProcess.NextRun == 0) {
StopProcessTimer(); //关闭采集时钟
return;
}
// u32 currentTAR = ProcessTimer->CNT; //定时器当前计数值
// if(currentTAR >= sampleProcess.NextTime) {
// sampleProcess.NextTime = currentTAR;
// FlowProcessManagement();
// }
//else ResetProcessTimer(sampleProcess.NextTime);
StartProcessTimer(sampleProcess.NextTime);
}
/******************************************************************************/
void AnalogCircuitInit(void)
{
RH_CON_OUTPUT();
TURN_ON_RH_POWER();
sampleProcess.CTypeGain = GetAdcGain(adcGain); //默认采样系数
SampingADCInit();
DisableSamplingInterrupt();
}
/******************************************************************************/
void EnableRHControlByTD(void)
{
RH_CON_OUTPUT();
TURN_ON_RH_POWER();
SELECT_TD_CON();
HEATING_OUTPUT();
TURN_OFF_HEATING();
}
/******************************************************************************/
void EnableRHControlByTU(void)
{
RH_CON_OUTPUT();
TURN_ON_RH_POWER();
// SELECT_TU_CON();
HEATING_OUTPUT();
TURN_OFF_HEATING();
}
/******************************************************************************/
void TurnOffAnalogCircuit(void)
{
TURN_OFF_HEATING();
TURN_OFF_RH_POWER();
CLR_HEATING();
StopSamplingADC();
DisableSamplingInterrupt();
}
/******************************************************************************/
void RapidHeating(void)
{
DisableSamplingInterrupt();
RH_CON_OUTPUT();
TURN_ON_RH_POWER();
SELECT_TD_CON();
//----------------------------------------------------------------------------
SELECT_VREF_CON();
// TURN_ON_LOW_HEAT();
}
/******************************************************************************/
void FirstStageHeating(void)
{
// RH controled by TD
HWState.EnableTempTest = 1;
HWState.EnableTempInit = 1;
systemProcessing.Bit.TempHandle = 1;
EnableRHControlByTD();
}
/******************************************************************************/
void StartNormolFlowMeasurement(void)
{
//--------------------------------------------------------------------------
// 校准引脚控制(通过宏开关控制)
// 如果定义了 ENABLE_CALPIN_FOR_UPDATE_FR则拉低校准引脚
//--------------------------------------------------------------------------
#ifndef ENABLE_CALPIN_FOR_UPDATE_FR
#pragma message("[undefined] ENABLE_CALPIN_FOR_UPDATE_FR")
#elif(ENABLE_CALPIN_FOR_UPDATE_FR)
EXT_CALIB_OUTPUT(); // 配置引脚为输出模式
CLR_CALIB_PIN(); // 拉低引脚
#endif
//--------------------------------------------------------------------------
HWState.SampledOver = 0; // 清除“采样完成”标志,表示测量开始,数据尚未就绪
AnalogCircuitInit();// 初始化模拟电路如运放偏置、ADC配置等
// 根据全局状态决定起始状态
// EnableRoughTest 为真:进入“粗检模式”(低功耗检测是否有流量)
// EnableRoughTest 为假:直接进入“正常测量模式”(第一级加热)
if(sampleProcess.State.EnableRoughTest) sampleProcess.NextRun = START_DETECT_STAGE_HEATING;
else sampleProcess.NextRun = START_1ST_STAGE_HEATING;
sampleProcess.NextTime = 0; // 定时器计数基准清零
//--------------------------------------------------------------------------
StartProcessTimer(64000); // 启动比较定时器,开始从0递增计数
Timer_register_irq_callback(ProcessTimer,ProcessTimerIT, ProcessTimerInterruptCallBack );//注册中断回调函数
// 立即执行一次流程管理,处理初始状态(如进入加热阶段)
FlowProcessManagement();
}
/******************************************************************************/
s16 ComputeOffsetCorrectValue(unsigned int offsetHigh, unsigned int offsetLow)
{
tmpSLA = (u32)voltageDetected[TGAS];
tmpSLA -= (u32)calibTemperature;
tmpSLB = (u32)offsetHigh;
tmpSLB -= (u32)offsetLow;
tmpSLA *= tmpSLB;
tmpSLB = (u32)staticHighTemperature;
tmpSLB -= (u32)staticLowTemperature;
tmpSLA /= tmpSLB;
return (s16)tmpSLA;
}
/******************************************************************************/
bool JudgmentFlowRate(void)
{
u16 tempIndex;
sampleProcess.NextRun = 0;
sampleProcess.State.EnableRoughTest = 0;
if(currentMode.Bit.CalibMode) return 0;
tempIndex = abs(voltageDetected[RIDX] - rapidOffsetGas);
rapidOffsetGas = voltageDetected[RIDX];
if(tempIndex > STATIC_HIGH_CODE) return 0;
systemProcessing.Bit.FRHandle = 1;
samplingInterval = factoryInterval;
flowRate = 0;
roughTestCounter++;
if(roughTestCounter >= 150)
{
roughTestCounter = 0;
sampleProcess.State.EnableRoughTest = 0;
}
else sampleProcess.State.EnableRoughTest = 1;
Clear_WDT();
return 1;
}
/******************************************************************************/
void CheckATypeSensor(void)
{
if((voltageDetected[RHVOL] < 500) || (voltageDetected[RHVOL] > 2600)) MEMSErrorCounter += 0x10;
else MEMSErrorCounter &= 0x0f;
}
/******************************************************************************/
// Check sensor error
bool CheckSensor(u16 voltageIndex)
{
u16 I=0;
if((voltageIndex < 2000) || (voltageIndex > 65000)) MEMSErrorCounter += 0x01;
else MEMSErrorCounter &= 0xf0;
I = MEMSErrorCounter & 0x0f;
I += MEMSErrorCounter >> 4;
if(I > 4) {
MEMSErrorCounter = 0x55;
systemAlarm.Bit.SensorErr = 1;
return 1;
}
else {
systemAlarm.Bit.SensorErr = 0;
return 0;
}
}
/******************************************************************************/
u16 ComputeCTypeIndex(u16 detectIndex, u16 indexOffset)
{
if(detectIndex > indexOffset) {
detectIndex -= indexOffset;
}
else {
detectIndex = indexOffset - detectIndex;
if(detectIndex > reverseScale) {
systemAlarm.Bit.Pollution = 1;
}
detectIndex = 0;
}
return detectIndex;
}
/******************************************************************************/
void ComputeFlowRateIndexAndFlowRate(void)
{
disable_interrupts();
//===========================================================================
currentFlowRate = 0;
displayUpdate = 0;
FRType = CTYPE_FR;
GetFilterDepth(responseTimeIndex);
//============================================================================
rapidOffsetGas = voltageDetected[RIDX];
systemAlarm.Bit.Pollution = 0;
systemAlarm.Bit.FRAlarm = 0;
// Compute offset
//============================================================================
if(currentMode.Bit.CalibMode) {
calibOffset.Value[CAL_VDUX] = offsetAir;
calibOffset.Value[CAL_VDUGX] = offsetAirGainx;
}
//----------------------------------------------------------------------------
#ifndef ENABLE_GAS_RECOGNITION
#pragma message("[undefined] ENABLE_GAS_RECOGNITION")
#elif(ENABLE_GAS_RECOGNITION)
else if(systemAlarm.Bit.GasChange = 1) {
calibOffset.Value[CAL_VDUX] = offsetGas;
calibOffset.Value[CAL_VDUGX] = offsetGasGainx;
}
#endif
//----------------------------------------------------------------------------
else {
calibOffset.Value[CAL_VDUX] = offsetGas;
calibOffset.Value[CAL_VDUGX] = offsetGasGainx;
}
calibOffset.CalTA = calibTemperature;
//----------------------------------------------------------------------------
//Compute RR Parameter
voltageDetected[VRRX] = sampleProcess.RTypeResult;
ComputeRRParameter();
voltageDetected[RRRES] = MovingAverage(voltageDetected[RRRES], 10, RRRES);
StaticTGasCompute();
if(sampleProcess.State.AType == SAMPLE_VRH) {
voltageDetected[VRHX] = sampleProcess.ATypeResult;
ComputeRHParameter();
CheckATypeSensor();
}
else {
voltageDetected[IVHDX] = sampleProcess.ATypeResult;
voltageDetected[IVHDX] = MovingAverage(voltageDetected[IVHDX], 10, IVHDX);
}
//----------------------------------------------------------------------------
// Compute TD-TU parameter
if(sampleProcess.State.CType == SAMPLE_GVDU) {
voltageDetected[VDUGX] = sampleProcess.CTypeResult;
voltageDetected[VDUGX] = MovingAverage(voltageDetected[VDUGX], 10, VDUGX);
//-------------------------------------------------------------------------
CheckSensor(voltageDetected[VDUGX]);
//-------------------------------------------------------------------------
#ifndef ENABLE_OFFSET_CORRECT
#pragma message("[undefined] ENABLE_OFFSET_CORRECT")
#elif(ENABLE_OFFSET_CORRECT)
tmpSLA = (s32)ComputeOffsetCorrectValue(VDUGXHigh, VDUGXLow);
voltageDetected[TVDUGX] = tmpSLA;
tmpSLA += (u32)voltageDetected[VDUGX];
voltageDetected[MICRO_FR] = (u16)tmpSLA;
#else
voltageDetected[MICRO_FR] = voltageDetected[VDUGX];
#endif
//-------------------------------------------------------------------------
// 转换成气体识别所用的内码
voltageDetected[MICRO_FR] = ComputeCTypeIndex(voltageDetected[MICRO_FR], calibOffset.Value[CAL_VDUGX]);
voltageDetected[REG_INDEX] = 128/adcGain;
voltageDetected[REG_INDEX] = voltageDetected[MICRO_FR] / voltageDetected[REG_INDEX];
if(voltageDetected[MICRO_FR] > CALIB_MAX_INDEX) voltageDetected[MICRO_FR] = CALIB_MAX_INDEX;
FRType = MICRO_FR;
}
else {
voltageDetected[VDUX] = sampleProcess.CTypeResult;
voltageDetected[VDUX] = MovingAverage(voltageDetected[VDUX], 10, VDUX);
//-------------------------------------------------------------------------
CheckSensor(voltageDetected[VDUX]);
//-------------------------------------------------------------------------
#ifndef ENABLE_OFFSET_CORRECT
#pragma message("[undefined] ENABLE_OFFSET_CORRECT")
#elif(ENABLE_OFFSET_CORRECT)
tmpSLA = (signed long int)ComputeOffsetCorrectValue(OffsetHigh, OffsetLow);
voltageDetected[TVDUX] = tmpSLA;
tmpSLA += (u32)voltageDetected[VDUX];
voltageDetected[CTYPE_FR] = (u16)tmpSLA;
#else
voltageDetected[CTYPE_FR] = voltageDetected[VDUX];
#endif
//-------------------------------------------------------------------------
voltageDetected[CTYPE_FR] = ComputeCTypeIndex(voltageDetected[CTYPE_FR], calibOffset.Value[CAL_VDUX]);
voltageDetected[REG_INDEX] = voltageDetected[CTYPE_FR];
FRType = CTYPE_FR;
}
//============================================================================
voltageDetected[NIDX] = voltageDetected[VDUX];
//----------------------------------------------------------------------------
//气体识别
GasAnasisCompute();
SaveVHHAndNRHInTempretureMode();
//----------------------------------------------------------------------------
//当前流量计算
currentFlowRate = GetFlowRate(voltageDetected[FRType], FRType);
//----------------------------------------------------------------------------
PCBTemperature = TestTemperature(); // 测试环境温度
TemperatureLowPower(); // 温度传感器低功耗
voltageDetected[TPCB] = MovingAverage((u16)(TEMPRETURE_OFFSET + PCBTemperature), 100, TPCB);
PCBTemperature = (u16)voltageDetected[TPCB];
PCBTemperature -= (u16)TEMPRETURE_OFFSET;
TemperatureCorrection();
//----------------------------------------------------------------------------
GCFCorrection();
//----------------------------------------------------------------------------
if( systemAlarm.Bit.SensorErr | systemAlarm.Bit.Pollution ) currentFlowRate = 0;
//----------------------------------------------------------------------------
// JudgeflowUnit, for com and compute ACC
currentFlowRate = ConvertFlowrate(currentFlowRate, flowComUnit, FR_STD_UNIT);
FlowRateSecondaryCorrection();
FlowRateAlarmJudgment();
//----------------------------------------------------------------------------
disable_interrupts();
//----------------------------------------------------------------------------
flowRate = currentFlowRate;
FlowRateMoving();
tempL.DWord = flowRate;
voltageDetected[FR_H] = tempL.Word[1];
voltageDetected[FR_L] = tempL.Word[0];
//----------------------------------------------------------------------------
//¼ÆËã×ÜÁ÷Á¿
#ifndef REC_ACC_PER
#pragma message("[undefined] REC_ACC_PER")
#elif(REC_ACC_PER)
ComputeFlowRateToTotal();
ReleaseTotalToDisArray();
#endif
//----------------------------------------------------------------------------
//Êä³öÓû§Á÷Á¿
#ifndef ENABLE_FLOW_GAIN
#pragma message("[undefined] ENABLE_FLOW_GAIN")
#elif(ENABLE_FLOW_GAIN)
flowRate /= calibFlowGain;
#endif
//---------------------------------------------------------------------------
enable_interrupts();
//---------------------------------------------------------------------------
if(flowRate > 0) {
roughTestCounter = 0;
return;
}
else if(samplingInterval <= RESP_2000MS) return; // Èç¹ûÁ÷Á¿Îª0£¬½øÈë×Ô¶¯Áãµã¸ú×Ù
else if(MEMSErrorCounter > 0) return;
roughTestCounter++;
if(roughTestCounter >= 4) {
roughTestCounter = 0;
sampleProcess.State.EnableRoughTest = 1;
}
}
/******************************************************************************/
void FlowRateDealAndOuputSub(void)
{
// disable_interrupts();
//===========================================================================
ComputeFlowRateIndexAndFlowRate();
ReleaseToIntAndDecimalBufForUart();
//---------------------------------------------------------------------------
flowRateL = (u16)flowRate;
flowRateH = flowRate >> 16;
HWState.SampledOver = 0;
systemProcessing.Bit.FRHandle = 0;
sampleProcess.NextRun = 0;
Clear_WDT();
enable_interrupts();
//----------------------------------------------------------------------------
// Update 2024/01/29
#ifndef ENABLE_CALPIN_FOR_UPDATE_FR
#pragma message("[undefined] ENABLE_CALPIN_FOR_UPDATE_FR")
#elif(ENABLE_CALPIN_FOR_UPDATE_FR)
// EXT_CALIB_OUTPUT();
// SET_CALIB_PIN();
// sampleProcess.NextRun = FR_UPDATE;
// sampleProcess.NextTime = MAINTAR;
// sampleProcess.NextTime += FR_UPDATE_PULSE_TIME;
// SetNextProcess();
#endif
}
///******************************************************************************/
void ComputeSampleData(u16 sampleNum, u16 sampleShift)
{
u32 I;
sampleProcess.ADC0Result = 0;
sampleProcess.ADC1Result = 0;
// if(sampleProcess.CounterMax < sampleNum) return;
// disable_interrupts();
// for(I = sampleProcess.CounterMax - sampleNum; I<sampleProcess.CounterMax; I++)
for(I = 0; I<sampleNum; I++)
{
sampleProcess.ADC0Result += ((sampleProcess.ADC0Buffer[I] >> 8) + 32768) & 0xFFFF;
sampleProcess.ADC1Result += ((sampleProcess.ADC1Buffer[I] >> 8) + 32768) & 0xFFFF;
//sampleProcess.ADC0Result += ((((sampleProcess.ADC0Buffer[I] & 0xFFFFFF) | ((sampleProcess.ADC0Buffer[I] & 0x800000) ? 0xFF000000 : 0)) >> 8) + 32768) & 0xFFFF;//处理成16位数据 //sampleProcess.ADC0Buffer[I];
//sampleProcess.ADC1Result += ((((sampleProcess.ADC1Buffer[I] & 0xFFFFFF) | ((sampleProcess.ADC1Buffer[I] & 0x800000) ? 0xFF000000 : 0)) >> 8) + 32768) & 0xFFFF;//处理成16位数据 //sampleProcess.ADC1Buffer[I];
}
sampleProcess.ADC0Result >>= sampleShift;
sampleProcess.ADC1Result >>= sampleShift;
// enable_interrupts();
}
///******************************************************************************/
void ComputeSampleDataForSingle(u16 sampleNum, u16 sampleShift)
{
u32 I;
sampleProcess.ADC0Result = 0;
for(I = 0; I<sampleNum; I++)
{
sampleProcess.ADC0Result += ((sampleProcess.ADC0Buffer[I] >> 8) + 32768) & 0xFFFF;
//sampleProcess.ADC0Result += ((((sampleProcess.ADC0Buffer[I] & 0xFFFFFF) | ((sampleProcess.ADC0Buffer[I] & 0x800000) ? 0xFF000000 : 0)) >> 8) + 32768) & 0xFFFF;//处理成16位数据 //sampleProcess.ADC0Buffer[I];
}
sampleProcess.ADC0Result >>= sampleShift;
}
/******************************************************************************/
void SetSystemForADCSample(u16 sampleNum)
{
sampleProcess.Counter = 0;
sampleProcess.CounterMax = sampleNum;
StartSamplingADC();
}
/******************************************************************************/
void FlowProcessManagement(void)
{
// 进入流程
switch(sampleProcess.NextRun)
{
//-------
//-------------------------------------------------------------------------
// 状态 1: 粗检阶段 - 加热
// 场景:低功耗模式,快速判断管道内是否有流体流动
//-------------------------------------------------------------------------------------------------------------------------------------------
// In low power consumption mode, judge whether there is flow?
case START_DETECT_STAGE_HEATING:
RapidHeating(); // 快速加热传感器
SetupCTypeChannle(sampleProcess.CTypeGain); // 配置测量通道
SetSystemForADCSample(SAMPLING_TIMES_IN_DETECT_STAGE);// 配置ADC采样次数
// 状态流转:设定下一步要做什么,以及多久后做
sampleProcess.NextRun = START_DETECT_STAGE_PROCESSING; // 下一状态:处理粗检数据
sampleProcess.NextTime += SET_UP_TIME_OF_DETECT_STAGE;// 累加时间:加热稳定时间
break;
//-------------------------------------------------------------------------
// 状态 2: 粗检阶段 - 数据处理与判断
// 场景读取ADC值判断是否有流量
//-------------------------------------------------------------------------
case START_DETECT_STAGE_PROCESSING:
TurnOffAnalogCircuit(); // 省电:关闭模拟电路电源
// 计算粗检阶段的采样数据
ComputeSampleData(SAMPLING_TIMES_IN_DETECT_STAGE, SHIFT_IN_DETECT_STAGE);
voltageDetected[RIDX] = sampleCTypeValue;// 保存检测值
// 核心逻辑:判断是否有流量
// JudgmentFlowRate() 返回 1 表示检测到有流量,直接 break等待后续正常测量
if(JudgmentFlowRate()) break;
// 若无流量,则需要进入正常测量流程(或是误触发)
AnalogCircuitInit();
HWState.SampledOver = 0;
sampleProcess.NextTime = 1638; // TimeVaule[0];
sampleProcess.NextRun = START_1ST_STAGE_HEATING;
FlowProcessManagement();
return;
//-------------------------------------------------------------------------
// normal check flowrate
// start First stage heating
case START_1ST_STAGE_HEATING:
FirstStageHeating();
// 如果不是检定模式,则启动预采样
if(currentMode.Bit.IntCalibMode) sampleProcess.State.PreSampling = 0;
else sampleProcess.State.PreSampling = 1;
SetupCTypeChannle(sampleProcess.CTypeGain); //设置VDU
SetupRTypeChannle(); //设置VRR
SetSystemForADCSample(PRESAMPLING_TIMES_IN_1ST_STAGE); //(PRESAMPLING_TIMES_MAX_IN_1ST_STAGE);
TestTemperatureInit(TEMP_SENSOR_RESULT); // 温度传感器初始化
// sampleProcess.NextTime += SET_UP_TIME_OF_1ST_STAGE;
sampleProcess.NextTime = SET_UP_TIME_OF_1ST_STAGE;
sampleProcess.NextRun = START_1ST_STAGE_SAMPLING;
break;
//------------------------------------------------------------------------
// 1ST: normal SAMPLING
// start sampling data
case START_1ST_STAGE_SAMPLING:
ComputeSampleData(PRESAMPLING_TIMES_IN_1ST_STAGE, SHIFT_IN_PRESAMPLING_1ST_STAGE);
sampleProcess.RTypeResult = sampleRTypeValue; //VRR 8304 sampleProcess.ADC1Result
// 通过预采样确定CTYPE放大倍数
// Setup CType Channel -----------------------------------------------------
if(sampleProcess.State.PreSampling) {
tmpIA = ComputeCTypeIndex((u16)sampleCTypeValue, calibOffset.Value[CAL_VDUX]); // |采样内码-零点内码| 预采样内码值结果
if(sampleSwitchThreshold < 500) sampleProcess.State.CType = SAMPLE_VDU; // 小于500禁止使用变增益功能
else if(tmpIA > sampleSwitchThreshold + 500) sampleProcess.State.CType = SAMPLE_VDU; //
else if(tmpIA < sampleSwitchThreshold) sampleProcess.State.CType = SAMPLE_GVDU;
}
else sampleProcess.State.CType++; // 该值为一个 1 位宽的无符号位域,++操作会在0 1之间切换
if(sampleProcess.State.CType == SAMPLE_VDU) SetupCTypeChannle(sampleProcess.CTypeGain); // Gain=32 128
else SetupCTypeChannle( GIDX_GAIN ); // GAIN = 128
// Setup AType Channel --------------------------------------------------------
if(sampleProcess.State.AType == SAMPLE_VRH) {
sampleProcess.State.AType = SAMPLE_IRH;
SetupIRHChannle();
}
else {
sampleProcess.State.AType = SAMPLE_VRH;
SetupVRHChannle();
}
// Start ADC --------------------------------------------------------
SetSystemForADCSample(SAMPLING_TIMES_IN_1ST_STAGE);
// sampleProcess.NextTime += SAMPLING_TIME_OF_1ST_STAGE;
sampleProcess.NextTime = SAMPLING_TIME_OF_1ST_STAGE;
sampleProcess.NextRun = START_1ST_STAGE_PROCESSING;
//CLR_TEST_PIN();
break;
//------------------------------------------------------------------------
case START_1ST_STAGE_PROCESSING:
CLR_TEST_PIN();
if(samplingInterval > RESP_125MS) TurnOffAnalogCircuit();
ComputeSampleData(SAMPLING_TIMES_IN_1ST_STAGE, SHIFT_IN_1ST_STAGE);
sampleProcess.CTypeResult = sampleCTypeValue;
sampleProcess.ATypeResult = sampleATypeValue;
//End Sampling
sampleProcess.NextRun = 0;
HWState.SampledOver = 1;
systemProcessing.Bit.FRHandle = 1;
break;
//------------------------------------------------------------------------
// Update 2024/01/29
case FR_UPDATE:
EXT_CALIB_OUTPUT();
CLR_CALIB_PIN();
sampleProcess.NextRun = 0;
break;
//------------------------------------------------------------------------
default:
TurnOffAnalogCircuit(); // into lowpower mode
sampleProcess.NextRun = 0;
systemProcessing.Bit.FRHandle = 0;
break;
}
// 设置下一个流程定时
SetNextProcess();
// if(sampleProcess.NextRun == 0) {
// StopProcessTimer();//关闭采集时钟
// return;
// }
// else {
// u32 currentTAR = SamplingTimer->CNT; //定时器当前计数值
// if(currentTAR >= sampleProcess.NextTime) {
// sampleProcess.NextTime = currentTAR;
// FlowProcessManagement();
// }
// else ResetSamplingTimer(sampleProcess.NextTime);
//}
}
//******************************************************************************/
void CoreInit(void)
{
SystemGPIOInit();
// ExternCalibratinInput();
TurnOffAnalogCircuit();
}
//******************************************************************************/
void CoreColdStartProcessing(void)
{
//----------------------------------------------------------------------------
// check cold start
if(systmeState != 0xAA55)
{
// if(CodeCRC == 0) alarmState &= ~BL_CRC_ERROR;
// else alarmState |= BL_CRC_ERROR;
//// CodeCheckCRC();
// if(CodeCRC == 0) alarmState &= ~AP_CRC_ERROR;
// else alarmState |= AP_CRC_ERROR;
SystemHardWareAutoCheck();
#ifndef ENABLE_ZERO_CALIB_CMD
#pragma message("[undefined] ENABLE_ZERO_CALIB_CMD")
#elif(ENABLE_ZERO_CALIB_CMD)
tempL.Word[0] = ReadShortParameterFromMemory(SYS_COMMAND, 0);
currentMode.Word = tempL.Word[0];
if(currentMode.Bit.ZeroCalib) EnterZeroCalibMode();
else EnterUserMode();
#else
EnterUserMode();
#endif
}
//----------------------------------------------------------------------------
Clear_WDT();
//----------------------------------------------------------------------------
// Interface Init
SystemInterfaceInit();
//----------------------------------------------------------------------------
enable_interrupts();
}
//----------------------------------------------------------------------------
void ProcessTimerInterruptCallBack(void)
{
DisableProcessTimerInterrupt();
HWState.ProcessTimerOut = 1;
//FlowProcessManagement();
//enable_interrupts();
}
//采样中断--------------------------------------------------------------------
//void SamplingTimer_IRQ_Callback(void)
//{
// FlowProcessManagement();
//// LHL_GPIO_TogglePin(pGPIO1, GPIO_PIN_7); MEMSErrorCounter
//}
//主程序中断------------------------------------------------------------
void PrimaryTimer_IRQ_Callback()
{
SET_TEST_PIN();
//TEST_PIN_TOGGLE();
HWState.MainTimerOut = 1;
}
//系统轮询----------------------------------------------------------------------
void SystemPolling(void)
{
while(1) {
//--------------------------------------------------------------------------
//test flowrate
if(HWState.MainTimerOut == 1 ) {
ManagePrimaryTimeInterval(); // 判断下阶段的工作模式
ModeExitCount(); // 判断各种模式退出
Clear_WDT();
StartNormolFlowMeasurement();
HWState.MainTimerOut = 0;
}
else if(HWState.ProcessTimerOut == 1 ) {
FlowProcessManagement();
HWState.ProcessTimerOut = 0;
}
if(HWState.SampledOver) {
FlowRateDealAndOuputSub();
//------------------------------------------------------------------------
#if ENABLE_USE_AVANT_PROTOCOL
if(urrentMode.Bit.DigitOutput) AvantGardeAutoUploadData();
#endif
}
//----------------------------------------------------------------------------
#ifndef ENABLE_USER_UART
#pragma message("[undefined] ENABLE_USER_UART")
#elif(ENABLE_USER_UART)
if(comState.state.ReceivedData ) {
ReceivedDataProcessing();
continue;
}
#endif
//--------------------------------------------------------------------------
#ifndef ENABLE_USER_I2C
#pragma message("[undefined] ENABLE_USER_I2C")
#elif(ENABLE_USER_I2C)
if(comState.I2CReceivedData) {
DoneI2CComm();
continue;
}
#endif
//--------------------------------------------------------------------------
if(HWState.EnableSaveData) DataStorageManagement();
alarmState = systemAlarm.Word;
//--------------------------------------------------------------------------
}
}
/* File end *****************************************************************/
#endif
/****************************************************************************/