Index: firmware/App/Modes/Rinseback.c =================================================================== diff -u -r9ed01b26543fba3b0c2ed78534fb949b778d0355 -r5b859b160a55d1a9d8b732822a63dc570cc46072 --- firmware/App/Modes/Rinseback.c (.../Rinseback.c) (revision 9ed01b26543fba3b0c2ed78534fb949b778d0355) +++ firmware/App/Modes/Rinseback.c (.../Rinseback.c) (revision 5b859b160a55d1a9d8b732822a63dc570cc46072) @@ -45,6 +45,8 @@ #define MAX_RINSEBACK_FLOW_RATE_ML_MIN 150 ///< Maximum rinseback flow rate (in mL/min). #define MAX_RINSEBACK_VOLUME_PCT 1.2 ///< Maximum rinseback volume measured by independent means (as % of target). +/// Maximum time allowed for rinseback operation (including additional rinseback volumes). +#define MAX_RINSEBACK_TIME ( 7 * SEC_PER_MIN * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ) /// Maximum time allowed for each additional rinseback volume delivery. #define MAX_RINSEBACK_ADDITIONAL_TIME ( 15 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) @@ -53,6 +55,7 @@ // ********** private data ********** static RINSEBACK_STATE_T rinsebackState; ///< Current state of the rinseback sub-mode. +static U32 rinsebackTimerCtr; ///< Timer counter for time spent in rinseback sub-mode. static F32 cumulativeRinsebackVolume_mL; ///< Total cumulative rinseback volume (in mL). static F32 additionalRinsebackVolume_mL; ///< Total volume (in mL) delivered so far for additional volume request. @@ -107,6 +110,7 @@ void initRinseback( void ) { rinsebackState = RINSEBACK_STOP_INIT_STATE; + rinsebackTimerCtr = 0; cumulativeRinsebackVolume_mL = 0.0; additionalRinsebackVolume_mL = 0.0; rinsebackMotorCount = 0; @@ -143,7 +147,7 @@ * The transitionToRinseback function prepares for transition to Rinseback * sub-mode. * @details Inputs: none - * @details Outputs: none + * @details Outputs: Rinseback sub-mode setup to begin * @return none *************************************************************************/ void transitionToRinseback( void ) @@ -177,7 +181,9 @@ * The setupForRinsebackDelivery function sets actuators appropriately * for rinseback states where delivery is in progress. * @details Inputs: none - * @details Outputs: none + * @details Outputs: arterial and venous lines opened, blood pump started, + * and air trap levelin control is started. + * @param rate rinseback rate to use for blood pump * @return none *************************************************************************/ static void setupForRinsebackDelivery( U32 rate ) @@ -227,12 +233,14 @@ /*********************************************************************//** * @brief * The execRinseback function executes the Rinseback sub-mode state machine. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: rinsebackState, rinsebackTimerCtr, flags * @return none *************************************************************************/ void execRinseback( void ) { + rinsebackTimerCtr++; + switch ( rinsebackState ) { case RINSEBACK_STOP_INIT_STATE: @@ -268,14 +276,15 @@ * @brief * The handleRinsebackStopInitState function handles the stopped initial * rinseback state operations. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: flags + * @details Outputs: flags handled * @return next rinseback state *************************************************************************/ static RINSEBACK_STATE_T handleRinsebackStopInitState( void ) { RINSEBACK_STATE_T result = RINSEBACK_STOP_INIT_STATE; + // Has user requested rinseback start? if ( TRUE == startRinsebackRequested ) { startRinsebackRequested = FALSE; @@ -284,14 +293,22 @@ setBloodIsPrimed( FALSE ); result = RINSEBACK_RUN_STATE; } + // Has user requested to return to treatment? else if ( TRUE == backToTreatmentRequested ) { signalRinsebackToStopped(); } + // Has user requested to end the treatment? else if ( TRUE == endTreatmentRequested ) { signalRinsebackToEnd(); } + // Has rinseback operation exceeded max time? + else if ( rinsebackTimerCtr > MAX_RINSEBACK_TIME ) + { + signalRinsebackToStopped(); + activateAlarmNoData( ALARM_ID_TREATMENT_RINSEBACK_TIMEOUT_ALARM ); + } return result; } @@ -300,8 +317,8 @@ * @brief * The handleRinsebackRunState function handles the rinseback run state * operations. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: flags + * @details Outputs: cumulativeRinsebackVolume_mL, rinsebackVolumeDelivered_Safety, flags handled * @return next rinseback state *************************************************************************/ static RINSEBACK_STATE_T handleRinsebackRunState( void ) @@ -328,6 +345,12 @@ setupForRinsebackStopOrPause(); result = RINSEBACK_STOP_STATE; } + // Has rinseback operation exceeded max time? + else if ( rinsebackTimerCtr > MAX_RINSEBACK_TIME ) + { + signalRinsebackToStopped(); + activateAlarmNoData( ALARM_ID_TREATMENT_RINSEBACK_TIMEOUT_ALARM ); + } // Has user or alarm requested rinseback pause? else if ( ( TRUE == pauseRinsebackRequested ) || ( TRUE == rinsebackStopRequested ) ) { @@ -377,16 +400,22 @@ * @brief * The handleRinsebackStopInitState function handles the rinseback paused * state operations. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: flags + * @details Outputs: flags handled * @return next rinseback state *************************************************************************/ static RINSEBACK_STATE_T handleRinsebackPausedState( void ) { RINSEBACK_STATE_T result = RINSEBACK_PAUSED_STATE; - if ( TRUE == resumeRinsebackRequested ) + // Has rinseback operation exceeded max time? + if ( rinsebackTimerCtr > MAX_RINSEBACK_TIME ) { + signalRinsebackToStopped(); + activateAlarmNoData( ALARM_ID_TREATMENT_RINSEBACK_TIMEOUT_ALARM ); + } + else if ( TRUE == resumeRinsebackRequested ) + { resumeRinsebackRequested = FALSE; setupForRinsebackDelivery( getTreatmentParameterU32( TREATMENT_PARAM_RINSEBACK_FLOW_RATE ) ); result = RINSEBACK_RUN_STATE; @@ -405,8 +434,8 @@ * @brief * The handleRinsebackStoppedState function handles the stopped rinseback * state operations. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: flags + * @details Outputs: flags handled * @return next rinseback state *************************************************************************/ static RINSEBACK_STATE_T handleRinsebackStoppedState( void ) @@ -421,7 +450,9 @@ else if ( TRUE == additionalRinsebackRequested ) { additionalRinsebackRequested = FALSE; - if ( ( cumulativeRinsebackVolume_mL + TARGET_ADDITIONAL_RINSEBACK_VOLUME_ML ) <= MAX_TOTAL_RINSEBACK_VOLUME_ML ) + // deliver additional rinseback volume only if max volume not reached and max time not reached + if ( ( ( cumulativeRinsebackVolume_mL + TARGET_ADDITIONAL_RINSEBACK_VOLUME_ML ) <= MAX_TOTAL_RINSEBACK_VOLUME_ML ) && + ( rinsebackTimerCtr < MAX_RINSEBACK_TIME ) ) { rinsebackAdditionalTimerCtr = 0; additionalRinsebackVolume_mL = 0.0; @@ -445,8 +476,8 @@ * @brief * The handleRinsebackRunAdditionalState function handles the rinseback additional * state operations. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: flags + * @details Outputs: flags handled * @return next rinseback state *************************************************************************/ static RINSEBACK_STATE_T handleRinsebackRunAdditionalState( void ) @@ -468,10 +499,9 @@ // Has alarm requested stop? else if( TRUE == rinsebackStopRequested ) { - pauseRinsebackRequested = FALSE; rinsebackStopRequested = FALSE; setupForRinsebackStopOrPause(); - result = RINSEBACK_PAUSED_STATE; + result = RINSEBACK_STOP_STATE; } return result; @@ -495,7 +525,7 @@ * The signalRinsebackUserAction function signals a rinseback user action * has been requested. The request is handled and responded to. * @details Inputs: none - * @details Outputs: none + * @details Outputs: action handled, request responded to * @param action User action requested * @return none *************************************************************************/ @@ -568,8 +598,8 @@ * The handleStartRinsebackUserAction function handles a start rinseback * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: rinseback started if appropriate * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -595,8 +625,8 @@ * The handleIncrRinsebackUserAction function handles an increase rinseback * flow rate user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: rinseback rate increased if appropriate * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -630,8 +660,8 @@ * The handleDecrRinsebackUserAction function handles a decrease rinseback * flow rte user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: rinseback decreased if appropriate * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -665,8 +695,8 @@ * The handlePauseRinsebackUserAction function handles a pause rinseback * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: rinseback paused if appropriate * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -692,8 +722,8 @@ * The handleResumeRinsebackUserAction function handles a resume rinseback * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: rinseback resumed if appropriate * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -719,8 +749,8 @@ * The handleEndRinsebackUserAction function handles an end rinseback * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: rinseback ended if appropriate * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -746,8 +776,8 @@ * The handleAdditionalRinsebackUserAction function handles an additional rinseback * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: additional rinseback volume started if appropriate * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -780,8 +810,8 @@ * The handleToRecircUserAction function handles a go to re-circulate * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: transition to re-circulate if appropriate * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -807,8 +837,8 @@ * The handleBackToTreatmentUserAction function handles a back to treatment * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: return to treatment if appropriate * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -834,8 +864,8 @@ * The handleEndTreatmentUserAction function handles an end treatment * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: rinsebackState + * @details Outputs: end treatment if appropriate * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ Index: firmware/App/Modes/TreatmentRecirc.c =================================================================== diff -u -rb24e96493ad0663a0589164efa3d8d8e70074574 -r5b859b160a55d1a9d8b732822a63dc570cc46072 --- firmware/App/Modes/TreatmentRecirc.c (.../TreatmentRecirc.c) (revision b24e96493ad0663a0589164efa3d8d8e70074574) +++ firmware/App/Modes/TreatmentRecirc.c (.../TreatmentRecirc.c) (revision 5b859b160a55d1a9d8b732822a63dc570cc46072) @@ -103,7 +103,7 @@ * The transitionToTreatmentRecirc function prepares for transition to treatment * re-circulate sub-mode. * @details Inputs: none - * @details Outputs: none + * @details Outputs: Re-circ sub-mode setup to begin * @return none *************************************************************************/ void transitionToTreatmentRecirc( void ) @@ -133,7 +133,8 @@ * The setupForRecirculationState function sets actuators appropriately * for recirculation state. * @details Inputs: none - * @details Outputs: none + * @details Outputs: arterial and venous lines opened, blood pump started, + * and air trap levelin control is started. * @return none *************************************************************************/ static void setupForRecirculationState( void ) @@ -171,8 +172,8 @@ * @brief * The execTreatmentRecirc function executes the Treatment circulate sub-mode * state machine. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: treatmentRecircState + * @details Outputs: treatmentRecircState, recircTimerCtr * @return none *************************************************************************/ void execTreatmentRecirc( void ) @@ -203,27 +204,27 @@ * @brief * The handleRecircRecircState function handles the re-circulating state * operations. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: flags + * @details Outputs: flags handled * @return next treatment re-circulation state *************************************************************************/ static TREATMENT_RECIRC_STATE_T handleRecircRecircState( void ) { TREATMENT_RECIRC_STATE_T result = TREATMENT_RECIRC_RECIRC_STATE; - // is alarm stop or user reconnect requested? + // Is alarm stop or user reconnect requested? if ( ( TRUE == recircStopRequested ) || ( TRUE == recircReconnectRequested ) ) { setupForRinsebackStopOrPause(); result = TREATMENT_RECIRC_STOPPED_STATE; } - // is end treatment requested? + // Is end treatment requested? else if ( TRUE == recircEndTreatmentRequested ) { setupForRinsebackStopOrPause(); signalRinsebackToEnd(); // signal end Tx sub-mode } - // has max time in re-circ sub-mode been exceeded? + // Has max time in re-circ sub-mode been exceeded? else if ( recircTimerCtr > RECIRC_TIMEOUT_MS ) { signalRinsebackToStopped(); @@ -237,31 +238,31 @@ * @brief * The handleRecircStoppedState function handles the re-circulation stopped * state operations. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: flags + * @details Outputs: flags handled * @return next Treatment re-circulation state *************************************************************************/ static TREATMENT_RECIRC_STATE_T handleRecircStoppedState( void ) { TREATMENT_RECIRC_STATE_T result = TREATMENT_RECIRC_STOPPED_STATE; - // is back to treatment requested? + // Is back to treatment requested? if ( TRUE == recircBackToTreatmenRequested ) { signalRinsebackToStopped(); } - // is end treatment requested? + // Is end treatment requested? else if ( TRUE == recircEndTreatmentRequested ) { signalRinsebackToEnd(); } - // is re-circ resume requested? + // Is re-circ resume requested? else if ( TRUE == recircResumeRequested ) { setupForRecirculationState(); result = TREATMENT_RECIRC_RECIRC_STATE; } - // has max time in re-circ sub-mode been exceeded? + // Has max time in re-circ sub-mode been exceeded? else if ( recircTimerCtr > RECIRC_TIMEOUT_MS ) { signalRinsebackToStopped(); @@ -276,7 +277,7 @@ * The signalStopTreatmentRecirc function signals the treatment re-circulate * sub-mode to stop per an active alarm. * @details Inputs: none - * @details Outputs: none + * @details Outputs: recircStopRequested * @return none *************************************************************************/ void signalStopTreatmentRecirc( void ) @@ -289,7 +290,7 @@ * The signalTreatmentRecircUserAction function signals a re-circ user action * has been requested. The request is handled and responded to. * @details Inputs: none - * @details Outputs: none + * @details Outputs: action handled, request responded to * @param action User action requested * @return none *************************************************************************/ @@ -338,8 +339,8 @@ * The handleRecircReconnectUserAction function handles a re-circulate re-connect * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: treatmentRecircState + * @details Outputs: reconnect action handled * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -365,8 +366,8 @@ * The handleRecicConfirmReconnectUserAction function handles a re-circulate * back to treatment user action request. It is assumed that the calling * function will set the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: treatmentRecircState + * @details Outputs: confirmation of reconnection action handled * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -392,8 +393,8 @@ * The handleRecircResumeUserAction function handles a re-circulate resume * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: treatmentRecircState + * @details Outputs: resumption of re-circulation action handled * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ @@ -419,8 +420,8 @@ * The handleRecircEndTreatmentUserAction function handles an e reatment * user action request. It is assumed that the calling function will set * the reject reason parameter to None beforehand. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: treatmentRecircState + * @details Outputs: ending of treatment action handled * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/