Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r370877da1639ae01135cf4c5f1e009e1517bbf03 -r63e6ce4cca0236d9886c73979bd183a6ec7e6da3 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 370877da1639ae01135cf4c5f1e009e1517bbf03) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 63e6ce4cca0236d9886c73979bd183a6ec7e6da3) @@ -75,9 +75,9 @@ static DG_FLUSH_STATE_T flushState = DG_FLUSH_STATE_START; ///< Current active flush state. static DG_FLUSH_STATE_T prevFlushState = DG_FLUSH_STATE_START; ///< Previous flush state. static U32 rsrvrFillStableTimeCounter = 0; ///< Reservoirs fill stable time counter. -static U32 overallFlushElapsedTime = 0; ///< Overall flush mode elapsed time. -static U32 stateTimer = 0; ///< State timer. -static ALARM_ID_T alarm; ///< Alarm ID. +static U32 overallFlushElapsedTimeStart = 0; ///< Overall flush mode elapsed time start. +static U32 stateTimerStart = 0; ///< State timer start. +static ALARM_ID_T alarmDetectedPendingTrigger; ///< Alarm ID that is detected and is pending to be triggered. static DG_RESERVOIR_STATUS_T rsrvr1Status = NUM_OF_DG_RESERVOIR_STATUS; ///< Reservoir 1 status. static DG_RESERVOIR_STATUS_T rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; ///< Reservoir 2 status. static BOOL isThisInitialDrain = TRUE; ///< Initial drain boolean flag. @@ -100,17 +100,15 @@ static DG_FLUSH_STATE_T handleFlushModeComplete( void ); static void resetActuators( void ); -static void setModeToFailed( void ); +static void failFlushMode( void ); static DG_RESERVOIR_STATUS_T getRsrvrFillStatus( DG_RESERVOIR_ID_T r, F32 targetVol, U32 timeout ); static DG_RESERVOIR_STATUS_T getRsrvrDrainStatus( DG_RESERVOIR_ID_T r, U32 drainSteadyStateTimeout, U32 timeout ); static void publishFlushData( void ); /*********************************************************************//** * @brief * The initFlushMode function initializes flush mode module. - * @details Inputs: flushState, prevFlushState, rsrvrFillStableTimeCounter, - * overallFlushElapsedTime, isThisInitialDrain, dataPublishCounter, - * rsrvr1Status, rsrvr2Status, hasWaterCancellationBeenSet + * @details Inputs: none * @details Outputs: flushState, prevFlushState, rsrvrFillStableTimeCounter, * overallFlushElapsedTime, isThisInitialDrain, dataPublishCounter, * rsrvr1Status, rsrvr2Status, hasWaterCancellationBeenSet @@ -122,7 +120,7 @@ flushState = DG_FLUSH_STATE_START; prevFlushState = DG_FLUSH_STATE_START; rsrvrFillStableTimeCounter = 0; - overallFlushElapsedTime = 0; + overallFlushElapsedTimeStart = 0; isThisInitialDrain = TRUE; dataPublishCounter = 0; rsrvr1Status = NUM_OF_DG_RESERVOIR_STATUS; @@ -239,9 +237,6 @@ *************************************************************************/ void stopDGFlush( void ) { - // Reset all the actuators - resetActuators(); - // Transition to mode standby requestNewOperationMode( DG_MODE_STAN ); } @@ -262,7 +257,7 @@ DG_FLUSH_STATE_T state = DG_FLUSH_STATE_START; // Start overall flush timer - overallFlushElapsedTime = getMSTimerCount(); + overallFlushElapsedTimeStart = getMSTimerCount(); // Reset the load cells lowest weight prior to starting the run resetReservoirsLowestWeight(); @@ -277,7 +272,7 @@ setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; state = DG_FLUSH_STATE_DRAIN_R1; @@ -313,7 +308,7 @@ // NOTE: Drain pump is already on and VDr is already on drain state setValveState( VRD, VALVE_STATE_R2_C_TO_NO ); - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; state = DG_FLUSH_STATE_DRAIN_R2; } @@ -368,7 +363,7 @@ state = DG_FLUSH_STATE_FLUSH_CIRCULATION; } - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); } else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) { @@ -390,7 +385,7 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_DRAIN; - if ( didTimeout( stateTimer, FLUSH_DRAIN_WAIT_TIME_MS ) ) + if ( didTimeout( stateTimerStart, FLUSH_DRAIN_WAIT_TIME_MS ) ) { setValveState( VPD, VALVE_STATE_OPEN_C_TO_NO ); setROPumpTargetFlowRate( RO_PUMP_TARGET_FLOW_RATE_LPM, RO_PUMP_MAX_PRESSURE_PSI ); @@ -399,7 +394,7 @@ turnOnUVReactor( INLET_UV_REACTOR ); turnOnUVReactor( OUTLET_UV_REACTOR ); - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); state = DG_FLUSH_STATE_FLUSH_DIALYSATE; } @@ -421,10 +416,10 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_DIALYSATE; - if ( didTimeout( stateTimer, FLUSH_DIALYSATE_WAIT_TIME_MS ) ) + if ( didTimeout( stateTimerStart, FLUSH_DIALYSATE_WAIT_TIME_MS ) ) { // TODO turn on the concentrate pumps - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); state = DG_FLUSH_STATE_FLUSH_CONCENTRATE_STRAWS; } @@ -445,13 +440,13 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_CONCENTRATE_STRAWS; - if ( didTimeout( stateTimer, FLUSH_CONCENTRATE_STRAWS_TIME_MS ) ) + if ( didTimeout( stateTimerStart, FLUSH_CONCENTRATE_STRAWS_TIME_MS ) ) { // TODO turn off the concentrate pumps setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); setValveState( VRF, VALVE_STATE_R1_C_TO_NC ); setValveState( VRI, VALVE_STATE_R2_C_TO_NC ); - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); rsrvr1Status = DG_RESERVOIR_BELOW_TARGET; rsrvr2Status = DG_RESERVOIR_BELOW_TARGET; @@ -493,7 +488,7 @@ setValveState( VRO, VALVE_STATE_R2_C_TO_NC ); setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); // Set both reservoirs' status rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; @@ -562,7 +557,7 @@ setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); isThisInitialDrain = FALSE; rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; state = DG_FLUSH_STATE_DRAIN_R1; @@ -595,7 +590,7 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_CIRCULATION; - if ( didTimeout( stateTimer, FLUSH_CIRCULATION_WAIT_TIME_MS ) ) + if ( didTimeout( stateTimerStart, FLUSH_CIRCULATION_WAIT_TIME_MS ) ) { resetActuators(); state = DG_FLUSH_STATE_COMPLETE; @@ -618,7 +613,7 @@ DG_FLUSH_STATE_T state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; // Once the fault alarm is raised, the DG Software will de-energize all the actuators - setModeToFailed(); + failFlushMode(); return state; } @@ -641,8 +636,8 @@ // Stop all the actuators first then decide who should run next resetActuators(); - // The fluid is hot so this is a mix drain. Set the VPd to direct the cold inlet fluid to drain - setValveState( VPI, VALVE_STATE_OPEN ); + // Set the actuators + setValveState( VPI, VALVE_STATE_CLOSED ); setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); // Set both reservoirs to be considered as full @@ -657,7 +652,7 @@ setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); // Start the timer for drain timeout - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); } // If reservoir 2 is empty, set to drain reservoir 1 @@ -685,7 +680,7 @@ if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) { - setModeToFailed(); + failFlushMode(); } } else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) @@ -727,7 +722,7 @@ turnOffUVReactor( OUTLET_UV_REACTOR ); // De-energize all the valves - setValveState( VPI, VALVE_STATE_OPEN ); + setValveState( VPI, VALVE_STATE_CLOSED ); setValveState( VBF, VALVE_STATE_CLOSED ); setValveState( VSP, VALVE_STATE_CLOSED ); setValveState( VPD, VALVE_STATE_OPEN_C_TO_NO ); @@ -748,21 +743,21 @@ /*********************************************************************//** * @brief - * The setModeToFailed function sets the alarm that failed the flush mode. + * The failFlushMode function sets the alarm that failed the flush mode. * @details Inputs: alarm, prevHeatDisinfectState * @details Outputs: none * @return none *************************************************************************/ -static void setModeToFailed( void ) +static void failFlushMode( void ) { - SET_ALARM_WITH_1_U32_DATA( alarm, prevFlushState ) + SET_ALARM_WITH_1_U32_DATA( alarmDetectedPendingTrigger, prevFlushState ) } /*********************************************************************//** * @brief - * The isRsrvrFull function checks whether the target reservoir is full or - * not. If the fill times out, the function sets the status to did not reach - * to target. + * The getRsrvrFillStatus function checks whether the target reservoir is + * full or not. If the fill times out, the function sets the status to did + * not reach to target. * @details Inputs: rsrvrFillStableTimeCounter, alarm, stateTimer, flushState, * prevFlushState * @details Outputs: rsrvrFillStableTimeCounter, alarm, stateTimer, @@ -794,14 +789,14 @@ status = DG_RESERVOIR_REACHED_TARGET; rsrvrFillStableTimeCounter = 0; // Set the state timer in case it needs to be used for another timeout check - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); } } - else if ( didTimeout( stateTimer, timeout ) ) + else if ( didTimeout( stateTimerStart, timeout ) ) { // Failed to fill on time prevFlushState = flushState; - alarm = ALARM_ID_DG_RESERVOIR_FILL_TIMEOUT; + alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_FILL_TIMEOUT; status = DG_RESERVOIR_NOT_REACHED_TARGET; } @@ -833,14 +828,14 @@ if ( TRUE == isDrainComplete ) { // Set the state timer in case it needs to be used for another timeout check - stateTimer = getMSTimerCount(); + stateTimerStart = getMSTimerCount(); status = DG_RESERVOIR_REACHED_TARGET; } - else if ( didTimeout( stateTimer, timeout ) ) + else if ( didTimeout( stateTimerStart, timeout ) ) { // Failed to drain on time prevFlushState = flushState; - alarm = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; + alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; status = DG_RESERVOIR_NOT_REACHED_TARGET; } @@ -862,8 +857,8 @@ MODE_FLUSH_DATA_T data; data.flushState = (U32)flushState; - data.overallElapsedTime = calcTimeSince( overallFlushElapsedTime ); - data.stateElapsedTime = calcTimeSince( stateTimer ); + data.overallElapsedTime = calcTimeSince( overallFlushElapsedTimeStart ); + data.stateElapsedTime = calcTimeSince( stateTimerStart ); broadcastFlushData( &data );