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

64
user/Compute/AccCompute.c Executable file → Normal file
View File

@@ -7,9 +7,6 @@ u16 totalPulse;
u8 MemoryPointer;
u16 flowAccCumulationRemaining, samplingIntervalForTotal;
//#define REC_PULSE_REMAINING
//#define PULSE_COUNTER
/******************************************************************************/
void ReleaseTotalToDisArray(void)
{
@@ -158,36 +155,36 @@ u16 FRAMWriteTotal(void)
// write to first bank and second bank and update EPROMPointer
// input: voltAcc, voltAcc0, EPROMPointer
// output: EPROMPointer
u16 blockAddr, I;
unsigned int blockAddr, I;
u8 temp[7], WriteCounter=0;
FRAMWriteRepeat:
MemoryPointer++;
WriteCounter++;
if (MemoryPointer > REC_ACC_DEPTH) MemoryPointer = 0;
if (WriteCounter > REC_ACC_DEPTH) return 1;
if (MemoryPointer > REC_DEPTH) MemoryPointer = 0;
if (WriteCounter > REC_DEPTH) return 1;
blockAddr = REC_ACC_BASE + MemoryPointer * REC_ACC_WIDTH;
blockAddr = REC_BASE + MemoryPointer * REC_WIDTH;
WriteMultiByteToFRAM(blockAddr,Total,7);
ReadMultiByteFromFRAM(blockAddr,temp,7);
for(I=0; I < (u16)ACC_BLOCK_WIDTH; I++)
for(I=0; I < (u16)BLOCK_WIDTH; I++)
{
if(temp[I] != Total[I]) goto FRAMWriteRepeat;
}
blockAddr += ACC_BLOCK2_START;
blockAddr += BLOCK2_START;
WriteMultiByteToFRAM(blockAddr,Total,7);
ReadMultiByteFromFRAM(blockAddr,temp,7);
for(I=0; I<ACC_BLOCK_WIDTH; I++)
for(I=0; I<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);
@@ -203,9 +200,9 @@ u16 FRAMCheckSaveTotalFlow(u8 Pointer)
u8 block1[7], block2[7];
u16 blockAddr, I;
blockAddr = REC_ACC_BASE + Pointer * REC_ACC_WIDTH;
blockAddr = REC_BASE + Pointer * REC_WIDTH;
ReadMultiByteFromFRAM(blockAddr, block1, 7);
blockAddr += ACC_BLOCK2_START;
blockAddr += BLOCK2_START;
ReadMultiByteFromFRAM(blockAddr, block2, 7);
if(block1[CRC_CHK] != CRC8(block1, 6)) return false;
@@ -229,14 +226,15 @@ u16 RetrieveLastAccumulationFromFRAM(void)
{
u32 voltPartA, tempPartA;
u16 voltPartB, tempPartB;
u8 I, max_g;
u8 good_ind[REC_ACC_DEPTH+1];
unsigned char I, max_g;
unsigned char good_ind[REC_DEPTH+1];
// if(ReadFRAMDeviceID()) return 0;
if(ReadFRAMDeviceID()) return 0;
//find EPROMPointer with good data
max_g = 0;
for(I = 0; I <= REC_ACC_DEPTH; I++) {
for(I = 0; I <= REC_DEPTH; I++)
{
if(FRAMCheckSaveTotalFlow(I)) { good_ind[max_g] = I; max_g++; }
}
if(max_g == 0) return 0;
@@ -245,8 +243,11 @@ u16 RetrieveLastAccumulationFromFRAM(void)
voltPartA = 0;
voltPartB = 0;
MemoryPointer = 0;
for(I = 0; I < max_g; I++) {
ReadMultiByteFromFRAM(REC_ACC_BASE + (u16)good_ind[I]* REC_ACC_WIDTH, Total, 7);
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]);
tempL.Byte[3] = Total[0];
tempL.Byte[2] = Total[1];
tempL.Byte[1] = Total[2];
@@ -268,12 +269,12 @@ u16 RetrieveLastAccumulationFromFRAM(void)
MemoryPointer = good_ind[I];
}
ReadMultiByteFromFRAM(REC_ACC_BASE + (u16)MemoryPointer* REC_ACC_WIDTH, Total, 7);
ReadMultiByteFromFRAM(REC_BASE + (u16)MemoryPointer* REC_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;
@@ -462,12 +463,11 @@ 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_ACC_DEPTH; I++) FRAMWriteTotal();
for(I=0; I <= REC_DEPTH; I++) FRAMWriteTotal();
#endif
}