Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r4e11c80367b5ae522aa34fb137079e516c98831b -rcb4d35cc50df2d3cc9e828cd92e53cf456ca9b9d --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 4e11c80367b5ae522aa34fb137079e516c98831b) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision cb4d35cc50df2d3cc9e828cd92e53cf456ca9b9d) @@ -80,6 +80,13 @@ F32 previousDrainFlowML; ///< Previous reservoir drain flow in milliliters. } RESERVOIRS_PREVIOUS_STATUS; +/// Non-volatile write structure +typedef struct +{ + BOOL hasDisStatusBeenWrittenToNV; ///< Boolean flag to indicate whether the disinfect status been written to NV or not. + BOOL hasROGenVolBeenWrittenToNV; ///< Boolean flag to indicate whether the generated RO volume has been written to NV or not. +} NV_OPS_T; + static HEATERS_TEMPERATURE_CALC_DATA_T heatersTempCalc; ///< Heaters temperature calculations data structure. static U32 dataPublishCounter; ///< used to schedule reservoir data publication to CAN bus. @@ -104,28 +111,27 @@ static BOOL isThisTheFirstCycle; ///< Boolean flag to indicate whether this is the first cycle. static RESERVOIRS_PREVIOUS_STATUS reservoirPreviousStatus[ NUM_OF_DG_RESERVOIRS ]; ///< Reservoirs previous status. static HD_MODE_SUB_MODE_T hdModes; ///< HD operations mode. -static BOOL hasROVolBeenWrittenToNV; ///< Boolean flag to indicate whether the RO volume has been written to NV RAM or not. -static BOOL hasDisinfectStatusBeenSet; ///< Boolean flag to indicate whether disinfect has been voided after starting treatment. +static NV_OPS_T nvOps; ///< Non-volatile memory operations. /*********************************************************************//** * @brief * The initReservoirs function initializes the Reservoirs module. * @details Inputs: none * @details Outputs: activeReservoir.data, fillVolumeTargetMl.data, * drainVolumeTargetMl.data, targetFillFlowRateLPM, isThisTheFirstCycle, - * previousReservoiWeight, dataPublishCounter + * previousReservoiWeight, dataPublishCounter, nvOps * @return none *************************************************************************/ void initReservoirs( void ) { - activeReservoir.data = (U32)DG_RESERVOIR_1; - fillVolumeTargetMl.data = DEFAULT_FILL_VOLUME_ML; - drainVolumeTargetMl.data = DEFAULT_DRAIN_VOLUME_ML; - targetFillFlowRateLPM = 0.0; - isThisTheFirstCycle = TRUE; - dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; - hasROVolBeenWrittenToNV = FALSE; - hasDisinfectStatusBeenSet = FALSE; + activeReservoir.data = (U32)DG_RESERVOIR_1; + fillVolumeTargetMl.data = DEFAULT_FILL_VOLUME_ML; + drainVolumeTargetMl.data = DEFAULT_DRAIN_VOLUME_ML; + targetFillFlowRateLPM = 0.0; + isThisTheFirstCycle = TRUE; + dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; + nvOps.hasDisStatusBeenWrittenToNV = FALSE; + nvOps.hasROGenVolBeenWrittenToNV = FALSE; memset( &reservoirPreviousStatus, 0.0, sizeof( RESERVOIRS_PREVIOUS_STATUS ) * NUM_OF_DG_RESERVOIRS ); } @@ -151,10 +157,9 @@ NUM_OF_CAL_DATA_RSRVRS, ALARM_ID_DG_HEATING_INVALID_CAL_RECORD ); } - if ( ( ( DG_MODE_FAUL == getCurrentOperationMode() ) || ( DG_MODE_STAN == getCurrentOperationMode() ) ) && ( FALSE == hasROVolBeenWrittenToNV ) ) + if ( ( ( DG_MODE_FAUL == getCurrentOperationMode() ) || ( DG_MODE_STAN == getCurrentOperationMode() ) ) && ( FALSE == nvOps.hasROGenVolBeenWrittenToNV ) ) { // If the mode is fault or it is standby and the RO volume has not been written already, write it - BOOL status; DG_OP_MODE_T prevMode = getPreviousOperationMode(); switch( prevMode ) @@ -168,26 +173,15 @@ // Mode is changing, write the RO generated volume to the RTC RAM and set the service flag to FALSE // since this is not a from a service change. If the previous modes were any of the above modes, it means // it has been generating water. - status = setROWaterGeneratedL( getROGeneratedVolumeL() ); + nvOps.hasROGenVolBeenWrittenToNV = setROWaterGeneratedL( getROGeneratedVolumeL() ); break; } - - if ( TRUE == status ) - { - // The generated water has been successfully written - hasROVolBeenWrittenToNV = TRUE; - } } - if ( ( FALSE == hasDisinfectStatusBeenSet ) && ( MODE_TREA == hdModes.hdMode ) ) + if ( ( FALSE == nvOps.hasDisStatusBeenWrittenToNV ) && ( MODE_TREA == hdModes.hdMode ) ) { // If the disinfect status has not been set and we are in treatment mode, void the disinfect (chemical or heat disinfects) - BOOL status = setDisinfectStatus( FALSE ); - - if ( TRUE == status ) - { - hasDisinfectStatusBeenSet = TRUE; - } + nvOps.hasDisStatusBeenWrittenToNV = setDisinfectStatus( FALSE ); } // publish active reservoir, fill/drain volume targets at 1 Hz.