Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -r289696b3b5e15120cfecbe447ff45ef093959056 -r4bbd5980e71fec58ab5ee2f1c9a50bdc76a5a38c --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 289696b3b5e15120cfecbe447ff45ef093959056) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 4bbd5980e71fec58ab5ee2f1c9a50bdc76a5a38c) @@ -1,20 +1,21 @@ /************************************************************************** * -* Copyright (c) 2025-2025 Diality Inc. - All Rights Reserved. +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file ModeTreatment.c * -* @author (last) Sean -* @date (last) 25-Mar-2025 +* @author (last) Varshini Nagabooshanam +* @date (last) 19-Jan-2026 * -* @author (original) Sean -* @date (original) 25-Mar-2025 +* @author (original) Sean Nash +* @date (original) 21-Apr-2025 * ***************************************************************************/ +#include #include "AirTrap.h" //#include "BloodFlow.h" #include "Bubbles.h" @@ -24,6 +25,7 @@ #include "ModeTreatment.h" //#include "NVDataMgmt.h" #include "OperationModes.h" +#include "Pressures.h" #include "StateTxDialysis.h" #include "StateTxPaused.h" //#include "Switches.h" @@ -183,7 +185,7 @@ // Initialize treatment mode each time we transition to it initTreatmentMode(); // Initialize treatment sub-modes each time we transition to treatment mode -// initBloodPrime(); + initBloodPrime(); initDialysis(); initTreatmentPaused(); // initRinseback(); @@ -316,6 +318,35 @@ /*********************************************************************//** * @brief + * The setBloodIsPrimed function sets that flag indicating whether the + * blood-side circuit has been primed with blood. Call this function with + * TRUE when blood prime operation is completed. Call this function with + * FALSE at start of treatment or start of rinseback operation. + * @details Inputs: none + * @details Outputs: bloodIsPrimed + * @param flag TRUE if blood side circuit is primed with blood, FALSE if not + * @return none + *************************************************************************/ +void setBloodIsPrimed( BOOL flag ) +{ + bloodIsPrimed = flag; +} + +/*********************************************************************//** + * @brief + * The getBloodIsPrimed function determines whether the blood-side circuit + * has been primed with blood (indicating blood-side circuit should be primarily blood). + * @details Inputs: bloodIsPrimed + * @details Outputs: none + * @return bloodIsPrimed + *************************************************************************/ +BOOL getBloodIsPrimed( void ) +{ + return bloodIsPrimed; +} + +/*********************************************************************//** + * @brief * The signalAlarmActionToTreatmentMode function executes the given alarm action * as appropriate while in Treatment Mode. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if invalid alarm action given. @@ -329,7 +360,7 @@ switch( action ) { case ALARM_ACTION_STOP: - // Stop signal actively polled by mode/sub-mode/state + // signal actively polled by mode/sub-mode/state break; case ALARM_ACTION_RESUME: @@ -369,9 +400,22 @@ /*********************************************************************//** * @brief + * The signalBloodPrimeToDialysis function signals that blood prime has + * completed and it is time to move on to dialysis. + * @details Inputs: none + * @details Outputs: bloodPrimeToDialysisRequest + * @return none + *************************************************************************/ +void signalBloodPrimeToDialysis( void ) +{ + bloodPrimeToDialysisRequest = TRUE; +} + +/*********************************************************************//** + * @brief * The execTreatmentMode function executes the Treatment Mode state machine. - * @details \b Alarm: ALARM_ID_TD_TREATMENT_STOPPED_BY_USER if user presses - * the stop button + * @details \b Alarm: ALARM_ID_TD_TREATMENT_PED_BY_USER if user presses + * the button * @details \b Inputs: currentTreatmentState * @details \b Outputs: currentTreatmentState, resumeBlockedByAlarm * @return current state (sub-mode) @@ -380,7 +424,7 @@ { BOOL stop = isStopButtonPressed(); - // Trigger user stop alarm at any time in treatment mode when user presses stop button + // Trigger user alarm at any time in treatment mode when user presses button if ( TRUE == stop ) { activateAlarmNoData( ALARM_ID_TD_TREATMENT_STOPPED_BY_USER ); @@ -480,7 +524,7 @@ TREATMENT_STATE_T result = TREATMENT_BLOOD_PRIME_STATE; lastTreatmentTimeStamp = getMSTimerCount(); - //transitionToBloodPrime(); // TODO + transitionToBloodPrime(); setDialysisBloodPumpFlowRate( getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ) ); // TODO - remove later return result; @@ -500,19 +544,19 @@ // setRinsebackIsCompleted( FALSE ); -// // Handle alarm stoppage -// if ( TRUE == doesAlarmStatusIndicateStop() ) -// { -// transitionToTreatmentStop(); -// result = TREATMENT_STOP_STATE; -// } -// else -// { -// execBloodPrime(); -// -// // Handle signals from blood prime sub-mode -// if ( TRUE == bloodPrimeToDialysisRequest ) -// { + // Handle alarm page + if ( TRUE == doesAlarmStatusIndicateStop() ) + { + transitionToTreatmentPaused(); + result = TREATMENT_PAUSED_STATE; + } + else + { + execBloodPrime(); + + // Handle signals from blood prime sub-mode + if ( TRUE == bloodPrimeToDialysisRequest ) + { lastTreatmentTimeStamp = getMSTimerCount(); // Kick dialysis sub-mode off setDialysisBloodPumpFlowRate( getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ) ); @@ -526,8 +570,8 @@ // // To update partial blood pump occlusion baseline - start of treatment // signalBloodPumpPressureOcclBaseline(); result = TREATMENT_DIALYSIS_STATE; -// } -// } + } + } return result; } @@ -567,7 +611,7 @@ else { execDialysis(); - // Handle alarm stoppage + // Handle alarm page if ( TRUE == doesAlarmStatusIndicateStop() ) { transitionToTreatmentPaused(); @@ -596,18 +640,18 @@ { resumeTreatmentAlarmResponseRequest = FALSE; -// if ( TRUE == getBloodIsPrimed() ) + if ( TRUE == getBloodIsPrimed() ) { lastTreatmentTimeStamp = getMSTimerCount(); transitionToDialysis(); result = TREATMENT_DIALYSIS_STATE; } -// else -// { -// transitionToBloodPrime(); -// result = TREATMENT_BLOOD_PRIME_STATE; -// } -// signalInitiatePressureStabilization( USE_NORMAL_STABILIZATION_PERIOD ); + else + { + transitionToBloodPrime(); + result = TREATMENT_BLOOD_PRIME_STATE; + } + signalInitiatePressureStabilization( USE_NORMAL_STABILIZATION_PERIOD ); } // If user requests rinseback, go to rinseback // else if ( TRUE == initiateRinsebackAlarmResponseRequest ) @@ -631,7 +675,7 @@ // If leaving treatment paused state, zero alarm countdown timer for UI // if ( TRUE == leavingTreatmentPausedState ) // { -// TREATMENT_STOP_PAYLOAD_T data; +// TREATMENT_PAUSED_PAYLOAD_T data; // // data.timeout = 0; // data.countdown = 0; @@ -646,7 +690,7 @@ * The handleTreatmentRinsebackState function executes the rinseback state of the * Treatment Mode state machine. * @details \b Inputs: endTreatmentAlarmResponseRequest, resumeTreatmentAlarmResponseRequest, - * rinsebackToRecircRequest, rinsebackToStoppedRequest, endTreatmentRequest + * rinsebackToRecircRequest, rinsebackTopedRequest, endTreatmentRequest * @details \b Outputs: treatment rinseback sub-mode executed, sendLastTreatmentPeriodicData * @return next treatment mode state *************************************************************************/ @@ -679,10 +723,10 @@ // transitionToTreatmentRecirc(); // result = TREATMENT_RECIRC_STATE; // } -// else if ( TRUE == rinsebackToStoppedRequest ) +// else if ( TRUE == rinsebackTopedRequest ) // { -// transitionToTreatmentStop(); -// result = TREATMENT_STOP_STATE; +// transitionToTreatment(); +// result = TREATMENT_PAUSED_STATE; // } // else if ( TRUE == endTreatmentRequest ) // { @@ -696,7 +740,7 @@ * @brief * The handleTreatmentRecircState function executes the re-circulate state of the * Treatment Mode state machine. - * @details \b Inputs: endTreatmentAlarmResponseRequest, rinsebackToStoppedRequest, + * @details \b Inputs: endTreatmentAlarmResponseRequest, rinsebackTopedRequest, * endTreatmentRequest * @details \b Outputs: sendLastTreatmentPeriodicData * @return next treatment mode state @@ -718,11 +762,11 @@ // } // // // Handle signals from treatment re-circ sub-mode -// if ( TRUE == rinsebackToStoppedRequest ) +// if ( TRUE == rinsebackTopedRequest ) // { -// stopDialysis(); -// transitionToTreatmentStop(); -// result = TREATMENT_STOP_STATE; +// Dialysis(); +// transitionToTreatment(); +// result = TREATMENT__STATE; // } // else if ( TRUE == endTreatmentRequest ) // { @@ -829,10 +873,10 @@ treatmentStateBroadcastTimerCtr = 0; payload.treatmentSubMode = (U32)currentTreatmentState; - payload.bldPrimeState = 0; // getCurrentBloodPrimeState(); + payload.bldPrimeState = getCurrentBloodPrimeState(); payload.dialysisState = getDialysisState(); payload.isoUFState = 0; - payload.txStopState = getCurrentTreatmentPausedState(); + payload.txPausedState = getCurrentTreatmentPausedState(); payload.rinsebackState = 0; // getCurrentRinsebackState(); payload.txRecircState = 0; // getCurrentTreatmentRecircState(); payload.txEndState = 0; // getCurrentTreatmentEndState(); @@ -1000,7 +1044,7 @@ *************************************************************************/ static void resetSignalFlags( void ) { -// rinsebackToStoppedRequest = FALSE; +// rinsebackTopedRequest = FALSE; endTreatmentRequest = FALSE; // rinsebackToRecircRequest = FALSE; bloodPrimeToDialysisRequest = FALSE;