Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r8d6dcaa7735630d964c57be69dc0e7616559d2c6 -ra89d6b091874136d75a9bfbdbbc1ff00f42467b3 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 8d6dcaa7735630d964c57be69dc0e7616559d2c6) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision a89d6b091874136d75a9bfbdbbc1ff00f42467b3) @@ -8,7 +8,7 @@ * @file ModeFlush.c * * @author (last) Dara Navaei -* @date (last) 10-Dec-2021 +* @date (last) 13-Jun-2022 * * @author (original) Leonardo Baloa * @date (original) 20-Dec-2019 @@ -41,9 +41,9 @@ // General defines #define FLUSH_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Mode flush data publish interval in counts. -#define RO_PUMP_TARGET_FLOW_RATE_LPM 0.8 ///< RO pump target flow rate during flush/fill in L/min. +#define RO_PUMP_TARGET_FLOW_RATE_LPM 0.8F ///< RO pump target flow rate during flush/fill in L/min. #define RO_PUMP_MAX_PRESSURE_PSI 130 ///< Maximum RO pump pressure during flush/fill states in psi. -#define DRAIN_PUMP_TARGET_RPM 2300 ///< Drain pump target RPM during drain. +#define DRAIN_PUMP_TARGET_RPM 2400 ///< Drain pump target RPM during drain. // Drain R1 & R2 states defines #define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 6 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. @@ -52,48 +52,48 @@ #define FLUSH_DRAIN_WAIT_TIME_MS ( 2 * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. TODo it was 2 minutes // Flush dialysate state defines -#define FLUSH_DIALYSATE_WAIT_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush dialysate wait time in milliseconds. +#define FLUSH_DIALYSATE_WAIT_TIME_MS ( 0.5F * 60 * MS_PER_SECOND ) ///< Flush dialysate wait time in milliseconds. // Flush concentrate straws state defines -#define FLUSH_CONCENTRATE_STRAWS_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush concentrate straws wait time in milliseconds. todo was 3 minutes -#define ACID_PUMP_SPEED_ML_PER_MIN -30.0 ///< Acid pump speed in mL/min. +#define FLUSH_CONCENTRATE_STRAWS_TIME_MS ( 0.5F * 60 * MS_PER_SECOND ) ///< Flush concentrate straws wait time in milliseconds. todo was 3 minutes +#define ACID_PUMP_SPEED_ML_PER_MIN -30.0F ///< Acid pump speed in mL/min. // The bicarb pump is 2% faster than the acid pump to create a flow from acid to bicarb line during flush -#define BICARB_PUMP_SPEED_ML_PER_MIN 30.6 ///< Bicarb pump speed in mL/min. +#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.0 ///< Reservoirs 1 & 2 full volume in mL. TODo original value was 1900 -#define RSRVRS_PARTIAL_FILL_VOL_ML 500.0 ///< Reservoirs 1 & 2 partial volume in mL. +#define RSRVRS_FULL_VOL_ML 1800.0F ///< Reservoirs 1 & 2 full volume in mL. TODo original value was 1900 +#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. #define RSRVRS_PARTIAL_FILL_TIMEOUT_MS ( 2 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 partial fill up timeout in ms. #define RSRVRS_DRAIN_TIMEOUT_MS ( 2 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 drain timeout in ms. -#define FINAL_DRAIN_RO_PUMP_FLOW_LPM 0.6 ///< Final drain RO pump flow rate in L/min. This is used to flush the drain line during drain. +#define FINAL_DRAIN_RO_PUMP_FLOW_LPM 0.6F ///< Final drain RO pump flow rate in L/min. This is used to flush the drain line during drain. // Flush drain line state defines -#define FLUSH_DRAIN_LINE_VOLUME_L 0.1 ///< Water volume to flush in liters. +#define FLUSH_DRAIN_LINE_VOLUME_L 0.1F ///< Water volume to flush in liters. #define FLUSH_DRAIN_LINE_TIMEOUT_MS ( 1 * 60 * MS_PER_SECOND ) ///< Flush drain lines timeout in milliseconds. // Flush circulation state defines -#define FLUSH_CIRCULATION_WAIT_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush circulation wait time in milliseconds. +#define FLUSH_CIRCULATION_WAIT_TIME_MS ( 0.5F * 60 * MS_PER_SECOND ) ///< Flush circulation wait time in milliseconds. // Flush with fresh water state defines -#define FLUSH_WITH_FRESH_WATER_WAIT_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush with fresh water wait time in milliseconds. +#define FLUSH_WITH_FRESH_WATER_WAIT_TIME_MS ( 0.5F * 60 * MS_PER_SECOND ) ///< Flush with fresh water wait time in milliseconds. // ********** private data ********** -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 DG_FLUSH_UI_STATE_T flushUIState = FLUSH_UI_STATE_NOT_RUNNING; ///< Current UI flush state. -static U32 rsrvrFillStableTimeCounter = 0; ///< Reservoirs fill stable time counter. -static U32 overallFlushElapsedTimeStart = 0; ///< Overall flush mode elapsed time start. -static U32 stateTimerStart = 0; ///< State timer start. +static DG_FLUSH_STATE_T flushState; ///< Current active flush state. +static DG_FLUSH_STATE_T prevFlushState; ///< Previous flush state. +static DG_FLUSH_UI_STATE_T flushUIState; ///< Current UI flush state. +static U32 rsrvrFillStableTimeCounter; ///< Reservoirs fill stable time counter. +static U32 overallFlushElapsedTimeStart; ///< Overall flush mode elapsed time start. +static U32 stateTimerStart; ///< 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. -static U32 dataPublishCounter = 0; ///< Flush data publish counter. -static BOOL hasWaterCancellationBeenSet = FALSE; ///< Water cancellation set/not set boolean flag. -static F32 flushLinesVolumeL = 0.0; ///< Volume of water pumped by RO pump during flush lines state. +static DG_RESERVOIR_STATUS_T rsrvr1Status; ///< Reservoir 1 status. +static DG_RESERVOIR_STATUS_T rsrvr2Status; ///< Reservoir 2 status. +static BOOL isThisInitialDrain; ///< Initial drain boolean flag. +static U32 dataPublishCounter; ///< Flush data publish counter. +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; ///< Boolean flag to indicate whether the drain parameters have been reset or not. // ********** private function prototypes ********** @@ -117,6 +117,7 @@ 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 ); +static void monitorModeFlush( void ); /*********************************************************************//** * @brief @@ -125,7 +126,7 @@ * @details Outputs: flushState, prevFlushState, rsrvrFillStableTimeCounter, * overallFlushElapsedTime, isThisInitialDrain, dataPublishCounter, * rsrvr1Status, rsrvr2Status, hasWaterCancellationBeenSet, - * flushLinesVolumeL, haveDrainParamsBeenInit + * flushLinesVolumeL, haveDrainParamsBeenInit, stateTimerStart * @return none *************************************************************************/ void initFlushMode( void ) @@ -143,6 +144,7 @@ hasWaterCancellationBeenSet = FALSE; flushLinesVolumeL = 0.0; haveDrainParamsBeenInit = FALSE; + stateTimerStart = 0; } /*********************************************************************//** @@ -171,6 +173,8 @@ *************************************************************************/ U32 execFlushMode( void ) { + monitorModeFlush(); + // Execute current flush state switch ( flushState ) { @@ -1028,4 +1032,31 @@ } } +/*********************************************************************//** + * @brief + * The monitorModeFlush function monitors the status of the caps and sets the + * state of the state machine to water cancellation path if the caps are not + * closed during the run. + * @details Inputs: none + * @details Outputs: prevFlushState, flushState, alarmDetectedPendingTrigger + * @return: none + *************************************************************************/ +static void monitorModeFlush( void ) +{ +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_CAPS_MONITOR ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + if ( ( STATE_OPEN == getSwitchStatus( CONCENTRATE_CAP ) ) || ( STATE_OPEN == getSwitchStatus( DIALYSATE_CAP ) ) ) + { + // Set the variables to fail and go to cancel water path. Set the pending alarm to no alarm so the cancel water path + // will not be raising the alarm at end of the cancel water path. The recoverable alarm is raised here in this function + U32 cap = (U32)( STATE_OPEN == getSwitchStatus( CONCENTRATE_CAP ) ? CONCENTRATE_CAP : DIALYSATE_CAP ); + prevFlushState = flushState; + flushState = DG_FLUSH_STATE_CANCEL_WATER_PATH; + alarmDetectedPendingTrigger = ALARM_ID_DG_DIALYSATE_OR_CONC_CAP_NOT_IN_PROPER_POSITION; + } + } +} + /**@}*/