Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r19934ca6e36e2dcabd6a6083a9a1f15b1ed32189 -r1e34d32fcfac88792ed72e55953dee721bacd9d5 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 19934ca6e36e2dcabd6a6083a9a1f15b1ed32189) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 1e34d32fcfac88792ed72e55953dee721bacd9d5) @@ -24,10 +24,12 @@ #include "MessageSupport.h" #include "ModeFault.h" #include "ModeFlush.h" +#include "NVDataMgmt.h" #include "OperationModes.h" #include "Pressures.h" #include "Reservoirs.h" #include "ROPump.h" +#include "RTC.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "Timers.h" @@ -64,7 +66,7 @@ #define BICARB_PUMP_SPEED_ML_PER_MIN 30.6F ///< Bicarb pump speed in mL/min. // Flush and drain R1 and R2 state defines -#define RSRVRS_FULL_VOL_ML 1800.0F ///< Reservoirs 1 & 2 full volume in mL. TODo original value was 1900 +#define RSRVRS_FULL_VOL_ML 1900.0F ///< Reservoirs 1 & 2 full volume in mL. #define RSRVRS_PARTIAL_FILL_VOL_ML 500.0F ///< Reservoirs 1 & 2 partial volume in mL. #define RSRVRS_FULL_STABLE_TIME_COUNT ( ( 4 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Reservoirs 1 & 2 full stable time in counts. #define RSRVRS_FILL_UP_TIMEOUT_MS ( 5 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 full fill up timeout in ms. @@ -98,6 +100,7 @@ static BOOL hasWaterCancellationBeenSet; ///< Water cancellation set/not set boolean flag. static F32 flushLinesVolumeL; ///< Volume of water pumped by RO pump during flush lines state. static BOOL haveDrainParamsBeenInit[ NUM_OF_DG_RESERVOIRS ]; ///< Boolean flag to indicate whether the drain parameters have been reset or not. +static BOOL hasFlushStatusBeenWrittenToNV; ///< Boolean flag to indicate whether the flush status has been written to NV or not. // ********** private function prototypes ********** @@ -121,6 +124,7 @@ static DG_RESERVOIR_STATUS_T getRsrvrDrainStatus( DG_RESERVOIR_ID_T r, U32 drainSteadyStateTimeout, U32 timeout ); static void publishFlushData( void ); static void monitorModeFlush( void ); +static void writeDisinfectDataToNV( DG_USAGE_INFO_ITEMS_T info ); /*********************************************************************//** * @brief @@ -129,7 +133,8 @@ * @details Outputs: flushState, prevFlushState, rsrvrFillStableTimeCounter, * overallFlushElapsedTime, isThisInitialDrain, dataPublishCounter, * rsrvr1Status, rsrvr2Status, hasWaterCancellationBeenSet, - * flushLinesVolumeL, haveDrainParamsBeenInit, stateTimerStart + * flushLinesVolumeL, haveDrainParamsBeenInit, stateTimerStart, + * hasFlushStatusBeenWrittenToNV * @return none *************************************************************************/ void initFlushMode( void ) @@ -149,6 +154,7 @@ haveDrainParamsBeenInit[ DG_RESERVOIR_1 ] = FALSE; haveDrainParamsBeenInit[ DG_RESERVOIR_2 ] = FALSE; stateTimerStart = 0; + hasFlushStatusBeenWrittenToNV = FALSE; } /*********************************************************************//** @@ -481,6 +487,8 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_DIALYSATE; + writeDisinfectDataToNV( USAGE_INFO_FILTER_FLUSH ); + if ( TRUE == didTimeout( stateTimerStart, FLUSH_DIALYSATE_WAIT_TIME_MS ) ) { // Turn the pumps on in reverse @@ -491,7 +499,10 @@ requestConcentratePumpOn( CONCENTRATEPUMPS_CP1_ACID ); requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); - stateTimerStart = getMSTimerCount(); + // Set the timer for the next state + // Set the NV data flag to FALSE since it should be ready for another write while the mode is running + stateTimerStart = getMSTimerCount(); + hasFlushStatusBeenWrittenToNV = FALSE; state = DG_FLUSH_STATE_FLUSH_CONCENTRATE_STRAWS; } @@ -716,6 +727,8 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_CIRCULATION_DRAIN_LINE; + writeDisinfectDataToNV( USAGE_INFO_FILTER_FLUSH ); + F32 waterFlowRate = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); F32 waterVolume = ( ( waterFlowRate / SEC_PER_MIN ) / ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); @@ -1098,4 +1111,20 @@ } } +/*********************************************************************//** + * @brief + * The writeDisinfectDataToNV function writes the disinfection data to the + * non-volatile memory. + * @details Inputs: hasFlushStatusBeenWrittenToNV + * @details Outputs: hasFlushStatusBeenWrittenToNV + * @return: none + *************************************************************************/ +static void writeDisinfectDataToNV( DG_USAGE_INFO_ITEMS_T info ) +{ + if ( FALSE == hasFlushStatusBeenWrittenToNV ) + { + hasFlushStatusBeenWrittenToNV = setLastDisinfectDate( info, getRTCTimestamp() ); + } +} + /**@}*/