Index: firmware/App/Modes/TreatmentRecirc.c =================================================================== diff -u -r9ed01b26543fba3b0c2ed78534fb949b778d0355 -rb24e96493ad0663a0589164efa3d8d8e70074574 --- firmware/App/Modes/TreatmentRecirc.c (.../TreatmentRecirc.c) (revision 9ed01b26543fba3b0c2ed78534fb949b778d0355) +++ firmware/App/Modes/TreatmentRecirc.c (.../TreatmentRecirc.c) (revision b24e96493ad0663a0589164efa3d8d8e70074574) @@ -37,15 +37,14 @@ /// Alarm if re-circulation is running for this much time. TODO - finalize these times w/ Systems #define RECIRC_TIMEOUT_MS ( ( 15 * 60 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) -/// Alarm if re-circulation is stopped for this much time. -#define RECIRC_STOP_TIMEOUT_MS ( ( 15 * 60 * 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 ********** static TREATMENT_RECIRC_STATE_T treatmentRecircState; ///< Current state of the treatment re-circulate sub-mode. -static U32 recircTimerCtr; ///< Timer counter (in GP task intervals) that re-circulation is running. -static U32 recircStoppedTimerCtr; ///< Timer counter (in GP task intervals) that re-circulation is stopped. +static U32 recircTimerCtr; ///< Timer counter (in GP task intervals) counts time spent in re-circulation sub-mode. static BOOL recircStopRequested; ///< Flag indicates alarm requesting to stop rinseback. static BOOL recircReconnectRequested; ///< Flag indicates user requesting re-circulate stop so they can re-connect. @@ -57,6 +56,9 @@ static void resetTreatmentRecircFlags( void ); +static void setupForRecirculationState( void ); +static void setupForRecirculationStopState( void ); + static TREATMENT_RECIRC_STATE_T handleRecircRecircState( void ); static TREATMENT_RECIRC_STATE_T handleRecircStoppedState( void ); @@ -77,7 +79,6 @@ { treatmentRecircState = TREATMENT_RECIRC_RECIRC_STATE; recircTimerCtr = 0; - recircStoppedTimerCtr = 0; resetTreatmentRecircFlags(); } @@ -112,12 +113,14 @@ // 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 ); + setValvePosition( VBA, VALVE_POSITION_B_OPEN ); + setValvePosition( VBV, VALVE_POSITION_B_OPEN ); + + // 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 control startAirTrapControl(); - // Should always have stopped alarm active in treatment stop sub-mode so that user can take action - activateAlarmNoData( ALARM_ID_TREATMENT_STOPPED_BY_USER ); + // *Note - Dialysate pump should already be re-circulating from rinseback sub-mode // Set user alarm recovery actions allowed in this sub-mode setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, FALSE ); @@ -127,6 +130,45 @@ /*********************************************************************//** * @brief + * The setupForRecirculationState function sets actuators appropriately + * for recirculation state. + * @details Inputs: none + * @details Outputs: none + * @return none + *************************************************************************/ +static void setupForRecirculationState( void ) +{ + // Open VBA and VBV valves to allow flow from saline bag and to patient venous line + setValvePosition( VBA, VALVE_POSITION_B_OPEN ); + setValvePosition( VBV, VALVE_POSITION_B_OPEN ); + // 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 setupForRecirculationStopState function sets actuators appropriately + * for 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 setupForRinsebackStopOrPause( 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(); +} + +/*********************************************************************//** + * @brief * The execTreatmentRecirc function executes the Treatment circulate sub-mode * state machine. * @details Inputs: none @@ -135,6 +177,9 @@ *************************************************************************/ void execTreatmentRecirc( void ) { + // count time in this sub-mode + recircTimerCtr++; + switch ( treatmentRecircState ) { case TREATMENT_RECIRC_RECIRC_STATE: @@ -166,22 +211,24 @@ { TREATMENT_RECIRC_STATE_T result = TREATMENT_RECIRC_RECIRC_STATE; - // TODO - update timer on this state - recircTimerCtr++; - - // is stop or reconnect requested or max re-circ time exceeded? - if ( ( TRUE == recircStopRequested ) || ( TRUE == recircReconnectRequested ) || ( recircTimerCtr > RECIRC_TIMEOUT_MS ) ) + // is alarm stop or user reconnect requested? + if ( ( TRUE == recircStopRequested ) || ( TRUE == recircReconnectRequested ) ) { - // TODO stop BP, close VBA and VBV + setupForRinsebackStopOrPause(); result = TREATMENT_RECIRC_STOPPED_STATE; } // is end treatment requested? else if ( TRUE == recircEndTreatmentRequested ) { - // TODO stop BP, close VBA and VBV - endAirTrapControl(); - // TODO - signal end Tx sub-mode + setupForRinsebackStopOrPause(); + signalRinsebackToEnd(); // signal end Tx sub-mode } + // has max time in re-circ sub-mode been exceeded? + else if ( recircTimerCtr > RECIRC_TIMEOUT_MS ) + { + signalRinsebackToStopped(); + activateAlarmNoData( ALARM_ID_TREATMENT_RECIRC_TIMEOUT_ALARM ); + } return result; } @@ -198,33 +245,27 @@ { TREATMENT_RECIRC_STATE_T result = TREATMENT_RECIRC_STOPPED_STATE; - // TODO - update timer on this state - recircStoppedTimerCtr++; - // is back to treatment requested? if ( TRUE == recircBackToTreatmenRequested ) { - // TODO - signal return to treatment stop sub-mode + signalRinsebackToStopped(); } // is end treatment requested? else if ( TRUE == recircEndTreatmentRequested ) { - // TODO - signal end Tx sub-mode + signalRinsebackToEnd(); } // is re-circ resume requested? else if ( TRUE == recircResumeRequested ) { - // TODO start BP, open VBA and VBV - startAirTrapControl(); + setupForRecirculationState(); result = TREATMENT_RECIRC_RECIRC_STATE; } - else + // has max time in re-circ sub-mode been exceeded? + else if ( recircTimerCtr > RECIRC_TIMEOUT_MS ) { - // is max re-circ stopped time exceeded? - if ( recircStoppedTimerCtr > RECIRC_STOP_TIMEOUT_MS ) - { - // TODO - alarm - } + signalRinsebackToStopped(); + activateAlarmNoData( ALARM_ID_TREATMENT_RECIRC_TIMEOUT_ALARM ); } return result;