Index: firmware/App/Controllers/SpentChamberFill.c =================================================================== diff -u --- firmware/App/Controllers/SpentChamberFill.c (revision 0) +++ firmware/App/Controllers/SpentChamberFill.c (revision c51c9d66062c27c588006850550b412ea7dd5144) @@ -0,0 +1,390 @@ +/************************************************************************** +* +* Copyright (c) 2024-2025 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 SpentChamberFill.c +* +* @author (last) Vinayakam Mani +* @date (last) 20-Aug-2025 +* +* @author (original) Vinayakam Mani +* @date (original) 20-Aug-2025 +* +***************************************************************************/ + +#include "BalancingChamber.h" +#include "Conductivity.h" +#include "ConcentratePumps.h" +#include "DialysatePumps.h" +#include "FpgaDD.h" +#include "Heaters.h" +#include "ModeGenDialysate.h" +#include "Messaging.h" +#include "OperationModes.h" +#include "Pressure.h" +#include "SpentChamberFill.h" +#include "TaskGeneral.h" +#include "Temperature.h" +#include "TestSupport.h" +#include "Valves.h" + +/** + * @addtogroup SpentChamberFill + * @{ + */ + +// ********** private definitions ********** + +#define SPENT_CHAMBER_FILL_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. + +// ********** private data ********** + +static SPENT_CHAMBER_FILL_EXEC_STATE_T spentChamberFillExecState; ///< Current spent chamber fill executive state. +static U32 spentChamberFillSwitchingPeriod; ///< Periodic spent chamber fill switching time in task interval count. +static U32 currentSpentChamberFillSwitchingCounter; ///< Counter (in task interval) to monitor the timing spent during spent chamber fill operation. +static U32 totalSpentChamberfillCounter; ///< Counter (in task interval) to monitor the total number of spent chamber fill operation. +static U32 spentChamberFillDataPublicationTimerCounter; ///< Used to schedule spent chamber fill data publication to CAN bus. +static OVERRIDE_U32_T spentChamberFillDataPublishInterval; ///< Spent chamber fill data publish interval. + +// ********** private function prototypes ********** + +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState1FillStart( void ); +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState1FillEnd(void); +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState2FillStart( void ); +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState2FillEnd(void); +static void publishSpentChamberFillData( void ); + +/*********************************************************************//** + * @brief + * The initSpentChamberFill function initializes the Spent chamber fill unit. + * @details \b Inputs: none + * @details \b Outputs: unit variables initialized + * @return none + *************************************************************************/ +void initSpentChamberFill( void ) +{ + spentChamberFillExecState = SPENT_CHAMBER_FILL_STATE_START; + spentChamberFillDataPublishInterval.data = SPENT_CHAMBER_FILL_DATA_PUBLISH_INTERVAL; + spentChamberFillDataPublishInterval.ovData = SPENT_CHAMBER_FILL_DATA_PUBLISH_INTERVAL; + spentChamberFillDataPublishInterval.ovInitData = 0; + spentChamberFillDataPublishInterval.override = OVERRIDE_RESET; + spentChamberFillSwitchingPeriod = 0; + currentSpentChamberFillSwitchingCounter = 0; + spentChamberFillDataPublicationTimerCounter = 0; + totalSpentChamberfillCounter = 0; +} + +/*********************************************************************//** + * @brief + * The transitionToSpentChamberFill function prepares for transition to + * spent chamber fill operations. + * @details \b Inputs: balChamberSwitchingPeriod + * @details \b Outputs: spentChamberFillSwitchingPeriod + * @return none + *************************************************************************/ +void transitionToSpentChamberFill( void ) +{ + initSpentChamberFill(); + updateBalChamberSwitchingPeriod(); + // Follow the same cycle for spent chamber fill + spentChamberFillSwitchingPeriod = getBalChamberSwitchingPeriod(); +} + +/*********************************************************************//** + * @brief + * The execSpentChamberFillControl function executes the spent chamber(H) fill + * state machine. + * @details \b Inputs: spentChamberFillExecState + * @details \b Outputs: spentChamberFillExecState + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong spent chamber fill + * state invoked. + * @return current spent chamber fill state. + *************************************************************************/ +U32 execSpentChamberFillControl( void ) +{ + // Increment counter indicating fill is in progress. + currentSpentChamberFillSwitchingCounter += 1; + + // execute current spent chamber fill exec state + switch ( spentChamberFillExecState ) + { + case SPENT_CHAMBER_FILL_STATE_START: + spentChamberFillExecState = SPENT_CHAMBER_FILL_STATE1_FILL_START; + break; + + case SPENT_CHAMBER_FILL_STATE1_FILL_START: + spentChamberFillExecState = handleSpentChamberFillState1FillStart(); + break; + + case SPENT_CHAMBER_FILL_STATE1_FILL_END: + spentChamberFillExecState = handleSpentChamberFillState1FillEnd(); + break; + + case SPENT_CHAMBER_FILL_STATE2_FILL_START: + spentChamberFillExecState = handleSpentChamberFillState2FillStart(); + break; + + case SPENT_CHAMBER_FILL_STATE2_FILL_END: + spentChamberFillExecState = handleSpentChamberFillState2FillEnd(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_SPENT_CHAMBER_FILL_INVALID_EXEC_STATE, spentChamberFillExecState ) + spentChamberFillExecState = SPENT_CHAMBER_FILL_STATE_START; + break; + } + + //Publish spent chamber fill data + publishSpentChamberFillData(); + + return spentChamberFillExecState; +} + +/*********************************************************************//** + * @brief + * The valveControlForSCFillState1FillStart function actuates the valve combination + * for state 1 fill process. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +static void valveControlForSCFillState1FillStart( void ) +{ + // Close balancing chamber valves D24,D20,D26 and D21 + setValveState( D20_VALV, VALVE_STATE_CLOSED ); + setValveState( D24_VALV, VALVE_STATE_CLOSED ); + setValveState( D26_VALV, VALVE_STATE_CLOSED ); + setValveState( D21_VALV, VALVE_STATE_CLOSED ); + + //Open balancing chamber valves D19,D23, D22 and D25 + setValveState( D19_VALV, VALVE_STATE_OPEN ); + setValveState( D23_VALV, VALVE_STATE_OPEN ); + setValveState( D25_VALV, VALVE_STATE_OPEN ); + setValveState( D22_VALV, VALVE_STATE_OPEN ); +} + +/*********************************************************************//** + * @brief + * The valveControlForSCFillState2FillStart function actuates the valve combination + * for state 2 fill process. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +static void valveControlForSCFillState2FillStart( void ) +{ + // Close balancing chamber valves D24,D22,D26,D19 + setValveState( D19_VALV, VALVE_STATE_CLOSED ); + setValveState( D22_VALV, VALVE_STATE_CLOSED ); + setValveState( D24_VALV, VALVE_STATE_CLOSED ); + setValveState( D26_VALV, VALVE_STATE_CLOSED ); + + //Open balancing chamber valves D21,D20,D23 and D25 + setValveState( D21_VALV, VALVE_STATE_OPEN ); + setValveState( D23_VALV, VALVE_STATE_OPEN ); + setValveState( D25_VALV, VALVE_STATE_OPEN ); + setValveState( D20_VALV, VALVE_STATE_OPEN ); +} + +/*********************************************************************//** + * @brief + * The handleSpentChamberFillState1FillStart function handles the spent chamber + * state 1 fill operations. + * @details \b Inputs: fresh and spent dialysate pressure + * @details \b Outputs: valve states,current spent chamber fill state + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber fill start. + * @return next spent chamber fill state. + *************************************************************************/ +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState1FillStart( void ) +{ + SPENT_CHAMBER_FILL_EXEC_STATE_T state = SPENT_CHAMBER_FILL_STATE1_FILL_START; + currentSpentChamberFillSwitchingCounter = 0; + + F32 freshDialPressure = getFilteredPressure( D18_PRES ); + F32 spentDialPressure = getFilteredPressure( D51_PRES ); + + // Check fresh and spent dialysate pressure in range + if ( ( ( freshDialPressure >= FRESH_DIAL_FILL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_FILL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_FILL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_FILL_PRESSURE_MAX_PSIG ) ) ) + { + //Valve control for state 1 spent chamber fill + valveControlForSCFillState1FillStart(); + + state = SPENT_CHAMBER_FILL_STATE1_FILL_END; + } + else + { + //Alarm when pressure is not in range + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_SC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleSpentChamberFillState1FillEnd function check for the spent chamber + * fill switching period and tranistion to next state. + * @details \b Inputs: currentSpentChamberFillSwitchingCounter,spentChamberFillSwitchingPeriod + * @details \b Outputs: currentSpentChamberFillSwitchingCounter, Valves state + * @return next spent chamber fill state. + *************************************************************************/ +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState1FillEnd( void ) +{ + SPENT_CHAMBER_FILL_EXEC_STATE_T state = SPENT_CHAMBER_FILL_STATE1_FILL_END; + + // On completion of cycle time, transition to next state + if ( currentSpentChamberFillSwitchingCounter >= spentChamberFillSwitchingPeriod ) + { + //Close all balancing chamber valves + valveControlForBCClosedState(); + totalSpentChamberfillCounter++; + + // Move to next state. + state = SPENT_CHAMBER_FILL_STATE2_FILL_START; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleSpentChamberFillState2FillStart function handles the spent chamber + * state 2 fill operations. + * @details \b Inputs: fresh and spent dialysate pressure + * @details \b Outputs: balancing chamber valves state + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill start. + * @return next spent chamber fill state. + *************************************************************************/ +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState2FillStart( void ) +{ + SPENT_CHAMBER_FILL_EXEC_STATE_T state = SPENT_CHAMBER_FILL_STATE2_FILL_START; + currentSpentChamberFillSwitchingCounter = 0; + + F32 freshDialPressure = getFilteredPressure( D18_PRES ); + F32 spentDialPressure = getFilteredPressure( D51_PRES ); + + // Check fresh and spent dialysate pressure in range + if ( ( ( freshDialPressure >= FRESH_DIAL_FILL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_FILL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_FILL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_FILL_PRESSURE_MAX_PSIG ) ) ) + { + // Valve control for state 2 fill + valveControlForSCFillState2FillStart(); + + state = SPENT_CHAMBER_FILL_STATE2_FILL_END; + } + else + { + //Alarm when pressure is not in range + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_SC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } + return state; +} + +/*********************************************************************//** + * @brief + * The handleSpentChamberFillState2FillEnd function check for the spent chamber + * switching period complete and transition to next state. + * @details \b Inputs: currentSpentChamberFillSwitchingCounter,spentChamberFillSwitchingPeriod + * @details \b Outputs: balancing chamber valves state + * @return next balancing chamber state. + *************************************************************************/ +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState2FillEnd( void ) +{ + SPENT_CHAMBER_FILL_EXEC_STATE_T state = SPENT_CHAMBER_FILL_STATE2_FILL_END; + + // On completion of cycle time, transition to next state + if ( currentSpentChamberFillSwitchingCounter >= spentChamberFillSwitchingPeriod ) + { + //Close all balancing chamber valves + valveControlForBCClosedState(); + totalSpentChamberfillCounter++; + + // Move to next state + state = SPENT_CHAMBER_FILL_STATE1_FILL_START; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The totalSpentChamberfillCounter function returns the total number + * of the Spent chamber fills. + * @details \b Inputs: totalSpentChamberfillCounter + * @details \b Outputs: none + * @return the total number of spent chamber fills. + *************************************************************************/ +U32 getTotalSpentChamberFillCounts( void ) +{ + return totalSpentChamberfillCounter; +} + +/*********************************************************************//** + * @brief + * The getCurrentSpentChamberFillExecState function returns the current state + * of the Spent chamber fill execution state. + * @details \b Inputs: spentChamberFillExecState + * @details \b Outputs: none + * @return the current state of spent chamber fill states. + *************************************************************************/ +SPENT_CHAMBER_FILL_EXEC_STATE_T getCurrentSpentChamberFillExecState( void ) +{ + return spentChamberFillExecState; +} + +/*********************************************************************//** + * @brief + * The publishSpentChamberFillData function broadcasts the spent chamber + * fill execution data at defined interval. + * @details \b Inputs: spentChamberFillDataPublicationTimerCounter + * @details \b Outputs: DD spent chamber fill data broadcast message sent + * @details \b Message \Sent: MSG_ID_DD_SPENT_CHAMBER_FILL_DATA to publish the + * Spent chamber fill data. + * @return none + *************************************************************************/ +static void publishSpentChamberFillData( void ) +{ + if ( ++spentChamberFillDataPublicationTimerCounter >= getU32OverrideValue( &spentChamberFillDataPublishInterval ) ) + { + SPENT_CHAMBER_FILL_DATA_T data; + + data.spentChamberFillExecState = (U32)spentChamberFillExecState; + data.spentChamberFillSwPeriod = spentChamberFillSwitchingPeriod; + data.totalSpentChamberfillCounter = totalSpentChamberfillCounter; + + broadcastData( MSG_ID_DD_SPENT_CHAMBER_FILL_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( SPENT_CHAMBER_FILL_DATA_T ) ); + + spentChamberFillDataPublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testDDSpentChamberFillDataPublishIntervalOverride function overrides the + * DD spent chamber fill data publish interval. + * @details \b Inputs: spentChamberFillDataPublishInterval + * @details \b Outputs: spentChamberFillDataPublishInterval + * @param Override message from Dialin which includes the interval + * (in ms) to override the DD spent chamber fill data publish interval to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDDSpentChamberFillDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &spentChamberFillDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/**@}*/ Index: firmware/App/Controllers/SpentChamberFill.h =================================================================== diff -u --- firmware/App/Controllers/SpentChamberFill.h (revision 0) +++ firmware/App/Controllers/SpentChamberFill.h (revision c51c9d66062c27c588006850550b412ea7dd5144) @@ -0,0 +1,59 @@ +/************************************************************************** +* +* Copyright (c) 2024-2025 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 SpentChamberFill.h +* +* @author (last) Vinayakam Mani +* @date (last) 20-Aug-2025 +* +* @author (original) Vinayakam Mani +* @date (original) 20-Aug-2025 +* +***************************************************************************/ + +#ifndef __SPENT_CHAMBER_FILL_H__ +#define __SPENT_CHAMBER_FILL_H__ + +#include "DDCommon.h" +#include "DDDefs.h" + +/** + * @defgroup SpentChamberFill SpentChamberFill + * @brief Spent Chamber Fill unit. Performs filling/degassing the spent chamber via a state machine. + * + * @addtogroup SpentChamberFill + * @{ + */ + +// ********** public definitions ********** + +#define FRESH_DIAL_FILL_PRESSURE_MIN_PSIG 22.0F ///< Minimum fresh dialysate pressure (D18) limit for balancing chamber fill operations. +#define FRESH_DIAL_FILL_PRESSURE_MAX_PSIG 28.0F ///< Maximum fresh dialysate pressure (D18) limit for balancing chamber fill operations. +#define SPENT_DIAL_FILL_PRESSURE_MIN_PSIG 24.0F ///< Minimum spent dialysate pressure (D51) limit for spent chamber fill operations. +#define SPENT_DIAL_FILL_PRESSURE_MAX_PSIG 28.0F ///< Maximum spent dialysate pressure (D51) limit for spent chamber fill operations. + +/// spent chamber fill data structure +typedef struct +{ + U32 spentChamberFillExecState; ///< Spent chamber fill execution state + U32 spentChamberFillSwPeriod; ///< Spent chamber fill switching period + U32 totalSpentChamberfillCounter; ///< Total number of spent chamber fills +} SPENT_CHAMBER_FILL_DATA_T; + +// ********** public function prototypes ********** + +void initSpentChamberFill( void ); // Initialize spent chamber fill unit +void transitionToSpentChamberFill( void ); // Prepares for transition to spent chamber fill execution +U32 execSpentChamberFillControl( void ); // Execute the spent chamber fill state machine +U32 getTotalSpentChamberFillCounts( void ); // Get the total number of spent chamber fill counts +SPENT_CHAMBER_FILL_EXEC_STATE_T getCurrentSpentChamberFillExecState( void ); // Get the current state of the spent chamber fill execution + +BOOL testDDSpentChamberFillDataPublishIntervalOverride( MESSAGE_T *message ); // To override the spent chamber fill data publish interval + +/**@}*/ + +#endif Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r977f03e20990ed5579160b9b927df1c0f2428101 -rc51c9d66062c27c588006850550b412ea7dd5144 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 977f03e20990ed5579160b9b927df1c0f2428101) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision c51c9d66062c27c588006850550b412ea7dd5144) @@ -59,6 +59,7 @@ #define LINEAR_SLOPE_FACTOR -0.0029F ///< Slope factor used in adjusted dialysate temperature linear calculation for high Qds #define LINEAR_INTERCEPT_FACTOR 3.47F ///< Intercept factor used in adjusted dialysate temperature linear calculation for high Qds #define LOW_DIAL_FLOW_RATE 150.0F ///< Dialysate flow rate lesser than 150 considered to be low Qds. +#define SPENT_CHAMBER_FILL_MAX_COUNT 7 ///< Total number of spent chamber fill allowed. //Testing #define DELAY_BC_SWITCHING_AT_START_UP ( 10 * MS_PER_SECOND ) ///< Provide a balancing chamber switching start up delay to stabilize pump speed etc., @@ -70,7 +71,7 @@ // ********** private data ********** -static DD_GEND_MODE_STATE_T genDialysateState = DD_GEND_STATE_START; ///< Currently active gen dialysate state. +static DD_GEND_MODE_STATE_T genDialysateState; ///< Currently active gen dialysate state. static OVERRIDE_F32_T targetHydChamberFluidTemp; ///< Target hydraulics chamber fluid temperature. static OVERRIDE_U32_T isDialDeliveryInProgress; ///< To indicate dialysate started delivering to dialyzer for treatment (overrideable) static OVERRIDE_U32_T isDialysateGoodtoDeliver; ///< Flag indicating whether ready to deliver dialysate or not. @@ -90,6 +91,8 @@ static DD_GEND_MODE_STATE_T handleGenDDialysateDeliveryPauseState( void ); static DD_GEND_MODE_STATE_T handleGenDSpentChamberFillState(void); static DD_GEND_MODE_STATE_T handleGenDIsolatedUFState( void ); +static F32 getGenDialysateTargetTemperature( void ); +static void calculateTargetDialysateTemp( void ); static void checkDialysateTemperature( void ); static void publishGenDialysateModeData( void ); @@ -195,12 +198,13 @@ break; case DD_GEND_DIALYSATE_BYPASS_STATE: + //Close all balancing chamber valves + valveControlForBCClosedState(); //Previous state setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); - // Get the target temperature from TD - //targetHydChamberFluidTemp.data = getTDTargetDialysateTemperature(); - calculateTargetDialysateTemp(); + // Turn on the primary heater + calculateTargetDialysateTemp(); setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); startHeater( D5_HEAT ); @@ -224,8 +228,8 @@ case DD_GEND_DIALYSATE_DELIVERY_STATE: //Previous state setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); - // Get the target temperature from TD - //targetHydChamberFluidTemp.data = getTDTargetDialysateTemperature(); + + // Turn on the primary heater calculateTargetDialysateTemp(); setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); startHeater( D5_HEAT ); @@ -242,6 +246,28 @@ setValveState( D40_VALV, VALVE_STATE_OPEN ); // VDO break; + case DD_GEND_SPENT_CHAMBER_FILL_STATE: + //Close all balancing chamber valves + valveControlForBCClosedState(); + transitionToSpentChamberFill(); + + //Set valves and actuators + setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); + + calculateTargetDialysateTemp(); + // Turn on the primary heater + setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); + startHeater( D5_HEAT ); + + setValveState( D14_VALV, VALVE_STATE_OPEN ); + setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, TRUE ); + setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve + setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI + setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO + setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve + setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_FILL_RPM, TRUE ); + break; + case DD_GEND_DIALYSATE_DELIVERY_PAUSE: // stop the motor during pause conditions signalDialysatePumpHardStop( D12_PUMP ); @@ -387,7 +413,7 @@ * @details \b Outputs: Adjusted Target temperature * @return none. *************************************************************************/ -void calculateTargetDialysateTemp( void ) +static void calculateTargetDialysateTemp( void ) { // Get the dialysate flow rate from TD F32 dialFlowrate = getTDDialysateFlowrate(); @@ -438,7 +464,8 @@ *************************************************************************/ static DD_GEND_MODE_STATE_T handleGenDDialysateBypassState( void ) { - DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_BYPASS_STATE; + DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_BYPASS_STATE; + LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); //Testing if ( TRUE == delayBypassStateFlag ) @@ -454,6 +481,14 @@ execBalancingChamberControl(); } +#ifdef __SPENT_CHAMBER_FILL__ + if ( LEVEL_STATE_LOW == spentChamberLevel ) + { + setModeGenDStateTransition( DD_GEND_SPENT_CHAMBER_FILL_STATE ); + isDialDeliveryInProgress.data = FALSE; + state = DD_GEND_SPENT_CHAMBER_FILL_STATE; + } +#endif //if the produced dialysate is good and TD asks for dialysate delivery //move to next state if ( ( TRUE == getDialGoodToDeliverStatus() ) && ( FALSE == getTDDialyzerBypass() ) ) @@ -476,14 +511,9 @@ *************************************************************************/ static DD_GEND_MODE_STATE_T handleGenDDialysateDeliveryState( void ) { - DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_DELIVERY_STATE; + DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_DELIVERY_STATE; + LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); - //Execute balancing chamber - execBalancingChamberControl(); - - //Execute ultrafiltration - execUFControl(); - // if TD asks for bypass or dialysate is not good to deliver //transition to bypass dialystate state if ( ( FALSE == getDialGoodToDeliverStatus() ) || ( TRUE == getTDDialyzerBypass() ) ) @@ -492,7 +522,23 @@ isDialDeliveryInProgress.data = FALSE; state = DD_GEND_DIALYSATE_BYPASS_STATE; } +#ifdef __SPENT_CHAMBER_FILL__ + else if ( LEVEL_STATE_LOW == spentChamberLevel ) + { + setModeGenDStateTransition( DD_GEND_SPENT_CHAMBER_FILL_STATE ); + isDialDeliveryInProgress.data = FALSE; + state = DD_GEND_SPENT_CHAMBER_FILL_STATE; + } +#endif + else + { + //Execute balancing chamber + execBalancingChamberControl(); + //Execute ultrafiltration + execUFControl(); + } + return state; } /*********************************************************************//** @@ -508,9 +554,11 @@ DD_GEND_MODE_STATE_T state = DD_GEND_SPENT_CHAMBER_FILL_STATE; LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); + U32 totalSpentChamberFill = getTotalSpentChamberFillCounts(); - // High level is met - if ( LEVEL_STATE_HIGH == spentChamberLevel ) + // High level is met or total fill count exceeded + if ( ( LEVEL_STATE_HIGH == spentChamberLevel ) || + ( totalSpentChamberFill >= SPENT_CHAMBER_FILL_MAX_COUNT ) ) { setModeGenDStateTransition( DD_GEND_DIALYSATE_BYPASS_STATE ); isDialDeliveryInProgress.data = FALSE; @@ -678,7 +726,7 @@ * @details \b Outputs: none * @return the target dialysate temperature for the treatment. *************************************************************************/ -F32 getGenDialysateTargetTemperature( void ) +static F32 getGenDialysateTargetTemperature( void ) { F32 temp = getF32OverrideValue( &targetHydChamberFluidTemp ); Index: firmware/App/Modes/ModeGenDialysate.h =================================================================== diff -u -r977f03e20990ed5579160b9b927df1c0f2428101 -rc51c9d66062c27c588006850550b412ea7dd5144 --- firmware/App/Modes/ModeGenDialysate.h (.../ModeGenDialysate.h) (revision 977f03e20990ed5579160b9b927df1c0f2428101) +++ firmware/App/Modes/ModeGenDialysate.h (.../ModeGenDialysate.h) (revision c51c9d66062c27c588006850550b412ea7dd5144) @@ -62,8 +62,6 @@ void setTreatmentParamUpdate( void ); // To indicate one or more treatment parameters updated void updateTreatmentSettings( void ); // Process the recent treatment parameters changes BOOL requestDDGenDialyasteStop( void ); // Stop generate dialysate -void calculateTargetDialysateTemp( void ); // Update target dialysate temmperature with Delta Temp -F32 getGenDialysateTargetTemperature( void ); // Get the target dialysate temperature BOOL testDDGenDialysateDataPublishIntervalOverride( MESSAGE_T *message ); // GenD Mode data publish interval override BOOL testDialDeliveryInProgressOverride( MESSAGE_T *message ); // To override the dialysate delivery in progress flag Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r573a26b2a0273a4983b1de1cbff5bed63e01dce0 -rc51c9d66062c27c588006850550b412ea7dd5144 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 573a26b2a0273a4983b1de1cbff5bed63e01dce0) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision c51c9d66062c27c588006850550b412ea7dd5144) @@ -39,6 +39,7 @@ #endif #include "Pressure.h" #include "SafetyShutdown.h" +#include "SpentChamberFill.h" #include "SystemCommDD.h" #include "Temperature.h" #include "TDInterface.h" @@ -163,6 +164,7 @@ { MSG_ID_FW_VERSIONS_REQUEST, &handleVersionRequestMessage }, { MSG_ID_DD_SAFETY_SHUTDOWN_OVERRIDE_REQUEST, &testSetResetSafetyShutdownOverride }, { MSG_ID_DD_UF_DATA_PUBLISH_OVERRIDE_REQUEST, &testDDUFDataPublishIntervalOverride }, + { MSG_ID_DD_SPENT_CHAMB_FILL_DATA_PUBLISH_OVERRIDE_REQUEST, &testDDSpentChamberFillDataPublishIntervalOverride }, #ifdef __PUMPTEST__ { MSG_ID_DD_PISTON_PUMP_DATA_PUBLISH_OVERRIDE_REQUEST, &testDDPistonPumpControlDataPublishIntervalOverride }, { MSG_ID_DD_PISTON_PUMP_START_STOP_OVERRIDE_REQUEST, &testDDPistonPumpStartStopOverride },