差异
This commit is contained in:
@@ -7,6 +7,9 @@ u16 totalPulse;
|
||||
u8 MemoryPointer;
|
||||
u16 flowAccCumulationRemaining, samplingIntervalForTotal;
|
||||
|
||||
//#define REC_PULSE_REMAINING
|
||||
//#define PULSE_COUNTER
|
||||
|
||||
/******************************************************************************/
|
||||
void ReleaseTotalToDisArray(void)
|
||||
{
|
||||
@@ -155,36 +158,36 @@ u16 FRAMWriteTotal(void)
|
||||
// write to first bank and second bank and update EPROMPointer
|
||||
// input: voltAcc, voltAcc0, EPROMPointer
|
||||
// output: EPROMPointer
|
||||
unsigned int blockAddr, I;
|
||||
u16 blockAddr, I;
|
||||
u8 temp[7], WriteCounter=0;
|
||||
|
||||
FRAMWriteRepeat:
|
||||
MemoryPointer++;
|
||||
WriteCounter++;
|
||||
if (MemoryPointer > REC_DEPTH) MemoryPointer = 0;
|
||||
if (WriteCounter > REC_DEPTH) return 1;
|
||||
if (MemoryPointer > REC_ACC_DEPTH) MemoryPointer = 0;
|
||||
if (WriteCounter > REC_ACC_DEPTH) return 1;
|
||||
|
||||
blockAddr = REC_BASE + MemoryPointer * REC_WIDTH;
|
||||
blockAddr = REC_ACC_BASE + MemoryPointer * REC_ACC_WIDTH;
|
||||
WriteMultiByteToFRAM(blockAddr,Total,7);
|
||||
ReadMultiByteFromFRAM(blockAddr,temp,7);
|
||||
|
||||
for(I=0; I < (u16)BLOCK_WIDTH; I++)
|
||||
for(I=0; I < (u16)ACC_BLOCK_WIDTH; I++)
|
||||
{
|
||||
if(temp[I] != Total[I]) goto FRAMWriteRepeat;
|
||||
}
|
||||
|
||||
blockAddr += BLOCK2_START;
|
||||
blockAddr += ACC_BLOCK2_START;
|
||||
WriteMultiByteToFRAM(blockAddr,Total,7);
|
||||
ReadMultiByteFromFRAM(blockAddr,temp,7);
|
||||
for(I=0; I<BLOCK_WIDTH; I++)
|
||||
for(I=0; I<ACC_BLOCK_WIDTH; I++)
|
||||
{
|
||||
if(temp[I] != Total[I]) goto FRAMWriteRepeat;
|
||||
}
|
||||
|
||||
blockAddr = REC_PULSE_REMAINING + MemoryPointer * PULSE_REMAINING_WIDTH;
|
||||
tempDev.DWord[0] = lastRemaining;
|
||||
tempDev.Byte[PULSE_REMAINING_CRC] = CRC8(tempDev.Byte, PULSE_REMAINING_CRC);
|
||||
WriteMultiByteToFRAM(blockAddr,tempDev.Byte,PULSE_REMAINING_WIDTH);
|
||||
// blockAddr = REC_PULSE_REMAINING + MemoryPointer * PULSE_REMAINING_WIDTH;
|
||||
// tempDev.DWord[0] = lastRemaining;
|
||||
// tempDev.Byte[PULSE_REMAINING_CRC] = CRC8(tempDev.Byte, PULSE_REMAINING_CRC);
|
||||
// WriteMultiByteToFRAM(blockAddr,tempDev.Byte,PULSE_REMAINING_WIDTH);
|
||||
|
||||
//tempDev.DWord[0] = pulseCounter;
|
||||
//tempDev.Byte[PULSE_COUNTER_CRC] = CRC8(tempDev.Byte, PULSE_COUNTER_CRC);
|
||||
@@ -200,9 +203,9 @@ u16 FRAMCheckSaveTotalFlow(u8 Pointer)
|
||||
u8 block1[7], block2[7];
|
||||
u16 blockAddr, I;
|
||||
|
||||
blockAddr = REC_BASE + Pointer * REC_WIDTH;
|
||||
blockAddr = REC_ACC_BASE + Pointer * REC_ACC_WIDTH;
|
||||
ReadMultiByteFromFRAM(blockAddr, block1, 7);
|
||||
blockAddr += BLOCK2_START;
|
||||
blockAddr += ACC_BLOCK2_START;
|
||||
ReadMultiByteFromFRAM(blockAddr, block2, 7);
|
||||
|
||||
if(block1[CRC_CHK] != CRC8(block1, 6)) return false;
|
||||
@@ -226,15 +229,14 @@ u16 RetrieveLastAccumulationFromFRAM(void)
|
||||
{
|
||||
u32 voltPartA, tempPartA;
|
||||
u16 voltPartB, tempPartB;
|
||||
unsigned char I, max_g;
|
||||
unsigned char good_ind[REC_DEPTH+1];
|
||||
u8 I, max_g;
|
||||
u8 good_ind[REC_ACC_DEPTH+1];
|
||||
|
||||
if(ReadFRAMDeviceID()) return 0;
|
||||
// if(ReadFRAMDeviceID()) return 0;
|
||||
|
||||
//find EPROMPointer with good data
|
||||
max_g = 0;
|
||||
for(I = 0; I <= REC_DEPTH; I++)
|
||||
{
|
||||
for(I = 0; I <= REC_ACC_DEPTH; I++) {
|
||||
if(FRAMCheckSaveTotalFlow(I)) { good_ind[max_g] = I; max_g++; }
|
||||
}
|
||||
if(max_g == 0) return 0;
|
||||
@@ -243,11 +245,8 @@ u16 RetrieveLastAccumulationFromFRAM(void)
|
||||
voltPartA = 0;
|
||||
voltPartB = 0;
|
||||
MemoryPointer = 0;
|
||||
for(I = 0; I < max_g; I++)
|
||||
{
|
||||
ReadMultiByteFromFRAM(REC_BASE + (u16)good_ind[I]* REC_WIDTH, Total, 7);
|
||||
//tempPartA = make32(Total[0],Total[1],Total[2],Total[3]);
|
||||
//tempPartB = make16(Total[4],Total[5]);
|
||||
for(I = 0; I < max_g; I++) {
|
||||
ReadMultiByteFromFRAM(REC_ACC_BASE + (u16)good_ind[I]* REC_ACC_WIDTH, Total, 7);
|
||||
tempL.Byte[3] = Total[0];
|
||||
tempL.Byte[2] = Total[1];
|
||||
tempL.Byte[1] = Total[2];
|
||||
@@ -269,12 +268,12 @@ u16 RetrieveLastAccumulationFromFRAM(void)
|
||||
MemoryPointer = good_ind[I];
|
||||
}
|
||||
|
||||
ReadMultiByteFromFRAM(REC_BASE + (u16)MemoryPointer* REC_WIDTH, Total, 7);
|
||||
ReadMultiByteFromFRAM(REC_ACC_BASE + (u16)MemoryPointer* REC_ACC_WIDTH, Total, 7);
|
||||
ReleaseTotalToDisArray();
|
||||
|
||||
ReadMultiByteFromFRAM(REC_PULSE_REMAINING+ MemoryPointer * PULSE_REMAINING_WIDTH, tempDev.Byte, PULSE_REMAINING_WIDTH);
|
||||
if(tempDev.Byte[PULSE_REMAINING_CRC] != CRC8(tempDev.Byte, PULSE_REMAINING_CRC)) lastRemaining = 0;
|
||||
else lastRemaining = tempDev.DWord[0];
|
||||
// ReadMultiByteFromFRAM(REC_PULSE_REMAINING+ MemoryPointer * PULSE_REMAINING_WIDTH, tempDev.Byte, PULSE_REMAINING_WIDTH);
|
||||
// if(tempDev.Byte[PULSE_REMAINING_CRC] != CRC8(tempDev.Byte, PULSE_REMAINING_CRC)) lastRemaining = 0;
|
||||
// else lastRemaining = tempDev.DWord[0];
|
||||
|
||||
//ReadMultiByteFromFRAM(PULSE_COUNTER, tempDev.Byte, PULSE_COUNTER_WIDTH);
|
||||
//if(tempDev.Byte[PULSE_COUNTER_CRC] != CRC8(tempDev.Byte, PULSE_COUNTER_CRC)) pulseCounter = 0;
|
||||
@@ -463,11 +462,12 @@ void ComputeFlowRateToTotal(void)
|
||||
#ifndef ENABLE_ACCPULSE
|
||||
#pragma message("[undefined] ENABLE_ACCPULSE")
|
||||
#elif(ENABLE_ACCPULSE)
|
||||
lastRemaining += (u32)tempInt;
|
||||
totalPulse = (u16)(lastRemaining / unitPerPulse);
|
||||
lastRemaining -= (u32)totalPulse * (u32)unitPerPulse;
|
||||
if(totalPulse > MaxPulseOutput[samplingIntervalForTotal]) totalPulse = MaxPulseOutput[samplingIntervalForTotal];
|
||||
// lastRemaining += (u32)tempInt;
|
||||
// totalPulse = (u16)(lastRemaining / unitPerPulse);
|
||||
// lastRemaining -= (u32)totalPulse * (u32)unitPerPulse;
|
||||
// if(totalPulse > MaxPulseOutput[samplingIntervalForTotal]) totalPulse = MaxPulseOutput[samplingIntervalForTotal];
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef REC_ACC_PER
|
||||
#pragma message("[undefined] REC_ACC_PER")
|
||||
@@ -501,7 +501,7 @@ void SetupACCArray(void)
|
||||
#ifndef REC_ACC_PER
|
||||
#pragma message("[undefined] REC_ACC_PER")
|
||||
#elif(REC_ACC_PER)
|
||||
for(I=0; I <= REC_DEPTH; I++) FRAMWriteTotal();
|
||||
for(I=0; I <= REC_ACC_DEPTH; I++) FRAMWriteTotal();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user