Index: firmware/App/Modes/TreatmentStop.c =================================================================== diff -u -r3d72b777cf1ceb673d118341c46e2d6d5b7b75f5 -r97915871fe011bc235c7a7f3c8690ee95ae637ea --- firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 3d72b777cf1ceb673d118341c46e2d6d5b7b75f5) +++ firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 97915871fe011bc235c7a7f3c8690ee95ae637ea) @@ -34,12 +34,10 @@ // ********** private definitions ********** -/// Maximum time in this mode before blood sitting alarm given (in general task intervals). -static const U32 MAX_TIME_BLOOD_SITTING = ( ( 5 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); -/// Maximum time in this mode before blood sitting warning given (in general task intervals). -static const U32 WARN_TIME_BLOOD_SITTING = ( ( 4 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); /// Treatment stop status broadcast interval. #define TREATMENT_STOP_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +/// Target flow rate for re-circulation of saline on blood-side circuit. +#define RECIRC_BP_FLOW_RATE_ML_MIN 100 // ********** private data ********** @@ -53,6 +51,11 @@ static TREATMENT_STOP_STATE_T handleTreatmentStopRecircState( void ); static TREATMENT_STOP_STATE_T handleTreatmentStopNoRecircState( void ); +static void setupForDialysateRecirculationState( void ); +static void setupForBloodRecirculationState( void ); +static TREATMENT_STOP_STATE_T handleTreatmentStopAlarmsAndSignals( TREATMENT_STOP_STATE_T state ); +static TREATMENT_STOP_STATE_T handleTreatmentStopDialysateRecircState( void ); +static TREATMENT_STOP_STATE_T handleTreatmentStopBloodRecircState( void ); static void publishTreatmentStopData( void ); @@ -95,22 +98,10 @@ } setAlarmUserActionEnabled( ALARM_USER_ACTION_END_TREATMENT, TRUE ); - // Ensure all pumps except DPi stopped - signalBloodPumpHardStop(); - signalDialOutPumpHardStop(); - stopSyringePump(); + setupForBloodRecirculationState(); - // Start out assuming we re-circulate dialysate while stopped - setDialInPumpTargetFlowRate( DIALYSATE_FLOW_RATE_FOR_RECIRC, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + setupForDialysateRecirculationState(); - // Set valves to safe state - setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); - setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); - setValvePosition( VBA, VALVE_POSITION_C_CLOSE ); - setValvePosition( VBV, VALVE_POSITION_C_CLOSE ); - // Stop air trap control - endAirTrapControl(); - // Reset saline bolus state in case alarm interrupted one resetSalineBolus(); @@ -132,6 +123,88 @@ /*********************************************************************//** * @brief + * The setupForDialysateRecirculationState function sets actuators appropriately + * for Dialysate recirculation state. + * @details Inputs: none + * @details Outputs: arterial and venous lines opened, blood pump started, + * and air trap leveling control is started. + * @return none + *************************************************************************/ +static void setupForDialysateRecirculationState( void ) +{ + // Re-circulate dialysate side of dialyzer w/ heating to maintain temperature + setDialInPumpTargetFlowRate( DIALYSATE_FLOW_RATE_FOR_RECIRC, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + cmdStartDGTrimmerHeater(); + // Set Dialysate valves to bypass filter for recirculation + setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); + setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); +} + +/*********************************************************************//** + * @brief + * The setupForBloodRecirculationState function sets actuators appropriately + * for Blood recirculation state. + * @details Inputs: none + * @details Outputs: arterial and venous lines closed, blood pump started, + * and air trap leveling control is started. + * @return none + *************************************************************************/ +static void setupForBloodRecirculationState( void ) +{ + // Close VBA and VBV valves to bypass patient for blood recirculation + setValvePosition( VBA, VALVE_POSITION_C_CLOSE ); + setValvePosition( VBV, VALVE_POSITION_C_CLOSE ); + // Ensure syringe pump is stopped + stopSyringePump(); + // Start blood pump at re-circulate flow rate + setBloodPumpTargetFlowRate( RECIRC_BP_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + // Start air trap leveling control + startAirTrapControl(); +} + +/*********************************************************************//** + * @brief + * The setupForDialysateRecirculationStopState function sets actuators appropriately + * for dialysate re-circulation stopped state. + * @details Inputs: none + * @details Outputs: Blood pump stopped, arterial and venous lines closed, + * and air trap leveling control is stopped. + * @return none + *************************************************************************/ +static void setupForDialysateRecirculationStopState( void ) +{ + // Stop dialysate side of dialyzer and heating + signalDialInPumpHardStop(); + cmdStopDGTrimmerHeater(); + // Set Dialysate valves to bypass filter for recirculation + setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); + setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); +} + +/*********************************************************************//** + * @brief + * The setupForBloodRecirculationStopState function sets actuators appropriately + * for blood re-circulation stopped state. + * @details Inputs: none + * @details Outputs: Blood pump stopped, arterial and venous lines closed, + * and air trap leveling control is stopped. + * @return none + *************************************************************************/ +static void setupForBloodRecirculationStopState( void ) +{ + // Stop blood pump + signalBloodPumpHardStop(); + // Close arterial and venous lines + setValvePosition( VBA, VALVE_POSITION_C_CLOSE ); + setValvePosition( VBV, VALVE_POSITION_C_CLOSE ); + // Stop air trap leveling control + endAirTrapControl(); + // Ensure syringe pump is stopped + stopSyringePump(); +} + +/*********************************************************************//** + * @brief * The execTreatmentStop function executes the Treatment Stop sub-mode * state machine. * @details Inputs: none @@ -161,6 +234,14 @@ currentTxStopState = handleTreatmentStopRecircState(); break; + case TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE: + currentTxStopState = handleTreatmentStopDialysateRecircState(); + break; + + case TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE: + currentTxStopState = handleTreatmentStopBloodRecircState(); + break; + case TREATMENT_STOP_NO_RECIRC_STATE: currentTxStopState = handleTreatmentStopNoRecircState(); break; @@ -176,8 +257,59 @@ /*********************************************************************//** * @brief + * The handleTreatmentStopAlarmsAndSignals function handles the Alarms and User Signals + * operations to set new states. + * @details Inputs: state, flags + * @details Outputs: flags handled + * @return next treatment re-circulation state + *************************************************************************/ +static TREATMENT_STOP_STATE_T handleTreatmentStopAlarmsAndSignals( TREATMENT_STOP_STATE_T state ) +{ + TREATMENT_STOP_STATE_T result = state; + + // Both unblocked and not in recirculate both state + if ( (TREATMENT_STOP_RECIRC_STATE != state) && ( FALSE == isDialysateRecircBlocked() ) + && ( FALSE == isBloodRecircBlocked() ) ) + { + setupForBloodRecirculationState(); + setupForDialysateRecirculationState(); + result = TREATMENT_STOP_RECIRC_STATE; + } + + // Both blocked and not in stopped state + if ( (TREATMENT_STOP_NO_RECIRC_STATE != state) && ( TRUE == isDialysateRecircBlocked() ) + && ( TRUE == isBloodRecircBlocked() ) ) + { + setupForBloodRecirculationStopState(); + setupForDialysateRecirculationStopState(); + result = TREATMENT_STOP_NO_RECIRC_STATE; + } + + // Dialysate recirculation blocked and not in blood recirc state + if ( ( TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE != state ) + && ( TRUE == isDialysateRecircBlocked() ) + && ( FALSE == isBloodRecircBlocked() ) ) + { + setupForDialysateRecirculationStopState(); + result = TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE; + } + + // Blood recirculation blocked and not in dialysate recirc state + if ( ( TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE != state ) + && ( TRUE == isBloodRecircBlocked() ) + && ( FALSE == isDialysateRecircBlocked() ) ) + { + setupForBloodRecirculationStopState(); + result = TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE; + } + + return result; +} + +/*********************************************************************//** + * @brief * The handleTreatmentStopRecircState function handles the re-circ dialysate - * state operations. + * and blood state operations. * @details Inputs: active alarms * @details Outputs: dialysate re-circulation stopped if active alarm blocks * @return next treatment stop state @@ -186,19 +318,47 @@ { TREATMENT_STOP_STATE_T result = TREATMENT_STOP_RECIRC_STATE; - // if any active alarm(s) blocks dialysate re-circulation, stop it - if ( TRUE == isDialysateRecircBlocked() ) - { - signalDialInPumpHardStop(); - cmdStopDGTrimmerHeater(); - result = TREATMENT_STOP_NO_RECIRC_STATE; - } + result = handleTreatmentStopAlarmsAndSignals( result ); return result; } /*********************************************************************//** * @brief + * The handleTreatmentStopDialysateRecircState function handles the Dialysate only + * re-circulating state operations. + * @details Inputs: flags + * @details Outputs: flags handled + * @return next treatment re-circulation state + *************************************************************************/ +static TREATMENT_STOP_STATE_T handleTreatmentStopDialysateRecircState( void ) +{ + TREATMENT_STOP_STATE_T result = TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE; + + result = handleTreatmentStopAlarmsAndSignals(result); + + return result; +} + +/*********************************************************************//** + * @brief + * The handleTreatmentStopBloodRecircState function handles the Blood only + * re-circulating state operations. + * @details Inputs: flags + * @details Outputs: flags handled + * @return next treatment re-circulation state + *************************************************************************/ +static TREATMENT_STOP_STATE_T handleTreatmentStopBloodRecircState( void ) +{ + TREATMENT_STOP_STATE_T result = TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE; + + result = handleTreatmentStopAlarmsAndSignals(result); + + return result; +} + +/*********************************************************************//** + * @brief * The handleTreatmentStopNoRecircState function handles the no re-circ dialysate * state operations. * @details Inputs: none @@ -209,7 +369,7 @@ { TREATMENT_STOP_STATE_T result = TREATMENT_STOP_NO_RECIRC_STATE; - // nothing to do in this state - alarm user response will take us to appropriate next sub-mode + result = handleTreatmentStopAlarmsAndSignals(result); return result; }