Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -raf0faf02f1bd7bffcce083e9b52988a01c343d8e -r26f63d0260a3c35277e3e6dbca3573c253775318 --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision af0faf02f1bd7bffcce083e9b52988a01c343d8e) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 26f63d0260a3c35277e3e6dbca3573c253775318) @@ -26,6 +26,7 @@ #include "SystemComm.h" #include "TaskGeneral.h" #include "TemperatureSensors.h" +#include "Timers.h" #include "Valves.h" /** @@ -35,38 +36,42 @@ // ********** private definitions ********** -#define TARGET_DRAIN_PUMP_RPM 2100 ///< Target drain pump speed (in RPM). -#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. -/// Time period to wait after drain complete and before taring load cells. -#define DRAIN_EMPTY_TARE_WAIT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +#define TARGET_DRAIN_PUMP_RPM 2400 ///< Target drain pump speed (in RPM). +#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. -#define TARGET_RO_PRESSURE_PSI 130 ///< Target pressure for RO pump. -#define TARGET_RO_FLOW_RATE_L 0.3 ///< Target flow rate for RO pump. +#define DRAIN_EMPTY_TARE_WAIT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) /// Time period to wait after drain complete and before taring load cells. -#define DELAY_RES_DRAIN_VALVE_MS 1000 ///< Delay reservoir drain valve open by 1 second. -#define DELAY_DRAIN_PUMP_MS 2000 ///< Delay drain pump on by 2 seconds. +#define TARGET_RO_PRESSURE_PSI 130 ///< Target pressure for RO pump. +#define TARGET_RO_FLOW_RATE_L 0.3 ///< Target flow rate for RO pump. +#define DELAY_RES_DRAIN_VALVE_MS 1000 ///< Delay reservoir drain valve open by 1 second. +#define DELAY_DRAIN_PUMP_MS 2000 ///< Delay drain pump on by 2 seconds. + +#define DIALYSATE_DRAIN_TIME_OUT ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Dialysate drain time out. + // ********** private data ********** -static DG_DRAIN_STATE_T drainState; ///< Currently active drain state. -static U32 drainEmptyTareTimerCtr; ///< Timer counter for delay between drain complete and load cell tare. +static DG_DRAIN_STATE_T drainState; ///< Currently active drain state. +static U32 drainEmptyTareTimerCtr; ///< Timer counter for delay between drain complete and load cell tare. +static U32 dialysateDrainStartTime; ///< Dialysate drain start time. // ********** private function prototypes ********** +static DG_DRAIN_STATE_T handleDrainStateStart( void ); +static DG_DRAIN_STATE_T handleDrainStateDrain( void ); +static DG_DRAIN_STATE_T handleDrainStateTare( void ); -static DG_DRAIN_STATE_T handleDrainState( void ); -static DG_DRAIN_STATE_T handleTareState( void ); - /*********************************************************************//** * @brief * The initDrainMode function initializes the drain mode module. * @details Inputs: none - * @details Outputs: drainState + * @details Outputs: drainState, drainEmptyTareTimerCtr, dialysateDrainStartTime * @return none *************************************************************************/ void initDrainMode( void ) { - drainState = DG_DRAIN_STATE_START; - drainEmptyTareTimerCtr = 0; + drainState = DG_DRAIN_STATE_START; + drainEmptyTareTimerCtr = 0; + dialysateDrainStartTime = 0; } /*********************************************************************//** @@ -125,18 +130,15 @@ switch ( drainState ) { case DG_DRAIN_STATE_START: - if ( TRUE == isDrainPumpOn() ) - { - drainState = DG_DRAIN_STATE_DRAIN; - } + drainState = handleDrainStateStart(); break; case DG_DRAIN_STATE_DRAIN: - drainState = handleDrainState(); + drainState = handleDrainStateDrain(); break; case DG_DRAIN_STATE_TARE: - drainState = handleTareState(); + drainState = handleDrainStateTare(); break; default: @@ -150,13 +152,34 @@ /*********************************************************************//** * @brief - * The handleDrainState function handles the drain state of the drain mode - * state machine. + * The handleDrainStateStart function handles the drain start state of + * the drain mode state machine. * @details Inputs: none + * @details Outputs: dialysateDrainStartTime + * @return the next state + *************************************************************************/ +static DG_DRAIN_STATE_T handleDrainStateStart( void ) +{ + DG_DRAIN_STATE_T state = DG_DRAIN_STATE_START; + + if ( TRUE == isDrainPumpOn() ) + { + dialysateDrainStartTime = getMSTimerCount(); + state = DG_DRAIN_STATE_DRAIN; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleDrainStateDrain function handles the drain state of the drain + * mode state machine. + * @details Inputs: none * @details Outputs: none * @return the next state *************************************************************************/ -static DG_DRAIN_STATE_T handleDrainState( void ) +static DG_DRAIN_STATE_T handleDrainStateDrain( void ) { DG_DRAIN_STATE_T result = DG_DRAIN_STATE_DRAIN; DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); @@ -185,18 +208,24 @@ } } + // Drain timed out raise the alarm + if ( TRUE == didTimeout( dialysateDrainStartTime, DIALYSATE_DRAIN_TIME_OUT ) ) + { + activateAlarmNoData( ALARM_ID_DG_DIALYSATE_DRAIN_TIME_OUT ); + } + return result; } /*********************************************************************//** * @brief - * The handleTareState function handles the tare state of the drain mode + * The handleDrainStateTare function handles the tare state of the drain mode * state machine. * @details Inputs: drainEmptyTareTimerCtr * @details Outputs: drainEmptyTareTimerCtr * @return the next state *************************************************************************/ -static DG_DRAIN_STATE_T handleTareState( void ) +static DG_DRAIN_STATE_T handleDrainStateTare( void ) { DG_DRAIN_STATE_T result = DG_DRAIN_STATE_TARE; DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir();