Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -r145fd716a856f864f39fb0f9884865f6e45b9256 -r67d2fdfc9ec326b98b5a0ac2dbfcee283c8791af --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 145fd716a856f864f39fb0f9884865f6e45b9256) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 67d2fdfc9ec326b98b5a0ac2dbfcee283c8791af) @@ -8,7 +8,7 @@ * @file DryBiCart.c * * @author (last) Sameer Kalliadan Poyil -* @date (last) 16-Jun-2026 +* @date (last) 13-Jul-2026 * * @author (original) Vinayakam Mani * @date (original) 19-Nov-2025 @@ -24,6 +24,7 @@ #include "DryBiCart.h" #include "Level.h" #include "Messaging.h" +#include "MessageSupport.h" #include "MixingControl.h" #include "ModeGenDialysate.h" #include "OperationModes.h" @@ -45,21 +46,20 @@ #define DRY_BICART_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the drybicart data published. #define WCDI2_PRESSURE_OFFSET_PSI 7.0F ///< The difference between the actual pressure measured at bicart assembly and the measured D66 pressure based on the placement of the sensor for WCID1 #define WCID1_PRESSURE_OFFSET_PSI 1.0F ///< The difference between the actual pressure measured at bicart assembly and the measured D66 pressure based on the placement of the sensor for WCID2 -#define DRY_BICART_PERSISTENCE_DURATION_MS 200 ///< Fill persistence duration to overcome the pressure overshoot/ drop for beta 1.9 and above. +#define DRY_BICART_PERSISTENCE_DURATION_MS 500 ///< Fill persistence duration to overcome the pressure overshoot/ drop for beta 1.9 and above. +//#define DRY_BICART_FILL_PERSISTENCE_DURATION_MS ( 1 * MS_PER_SECOND ) ///< Fill persistence duration to overcome the pressure overshoot/ drop for beta 1.9 and above. // Dry Bicart Fill #define DRY_BICART_FILL_COMPLETE_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to reset the request flag after fill complete -#define DRY_BICART_WCID2_FILL_COMPLETE_PRESSURE_PSI ( 10.0F + WCDI2_PRESSURE_OFFSET_PSI ) ///< Maximum pressure reached to indicate the dry bicart fill being completed for WCID2 -#define DRY_BICART_WCID1_FILL_COMPLETE_PRESSURE_PSI ( 10.0F + WCID1_PRESSURE_OFFSET_PSI ) ///< Maximum pressure reached to indicate the dry bicart fill being completed for WCID1 -#define GET_DRY_BICART_FILL_COMPLETE_PRESSURE_PSI (getTestConfigStatus( TEST_CONFIG_DD_ENABLE_WCID_1 ) \ - != TRUE ? DRY_BICART_WCID2_FILL_COMPLETE_PRESSURE_PSI : DRY_BICART_WCID1_FILL_COMPLETE_PRESSURE_PSI ) +#define DRY_BICART_WCID2_FILL_COMPLETE_PRESSURE_PSI ( 3.0F + WCDI2_PRESSURE_OFFSET_PSI ) ///< Maximum pressure reached to indicate the dry bicart fill being completed for WCID2 +#define DRY_BICART_WCID1_FILL_COMPLETE_PRESSURE_PSI ( 10.0F + WCID1_PRESSURE_OFFSET_PSI ) ///< Maximum pressure reached to indicate the dry bicart fill being completed for WCID1. +#define GET_FILL_COMPLETE_PRESSURE_PSI (getTestConfigStatus( TEST_CONFIG_DD_ENABLE_WCID_1 ) != TRUE ? \ + DRY_BICART_WCID2_FILL_COMPLETE_PRESSURE_PSI : DRY_BICART_WCID1_FILL_COMPLETE_PRESSURE_PSI ) ///< Get fill complete pressure based on the WCID configuration #define DRY_BICART_FILL_INITIATE_PRESSURE_PSI 1.5F ///< Minimum pressure required to initiate the dry bicart fill process. #define DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE_PSI 10.0F ///< Maximum pressure allowed at bicart fill during supply process/state -#define DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE_PSI 3.0F ///< Minimum pressure required to initiate the dry bicart fill during supply process/state -#define MAX_DRY_BICART_FILL_COMPLETE_PRESSURE 20.0F ///< Very max dry bicart fill complete pressure for persistence on d66 -#define DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT 10 ///< Default max fill cycle allowed for dry bicart fill/mix with water. -#define DRY_BICART_MAX_FILL_CYCLE_CNT 15 ///< Max fill cycle allowed (by override) for dry bicart fill/mix with water. +#define DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE_PSI 4.0F ///< Minimum pressure required to initiate the dry bicart fill during supply process/state +#define DRY_BICART_MAX_FILL_CYCLE_CNT 10 ///< Max fill cycle allowed (by override) for dry bicart fill/mix with water. #define DRY_BICART_MINIMUM_FILL_CYCLE_CNT 3 ///< Minimum fill cycle count for filling dry bicart // Dry Bicart Fill Vent #define DRY_BICART_FILL_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bicart gas before actuating Bicarb chamber(F) venting. @@ -68,13 +68,15 @@ // Bicarb chamber fill/Supply #ifdef CONDUCTIVE_LEVEL_SENSOR_ENABLED -#define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 10 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill using level sensor +#define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 60 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill using level sensor #else #define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill time based fill #endif #define DRY_BICART_SUPPLY_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bicart gas before actuating Bicarb chamber(F) venting. #define DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ( 1 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. #define DRY_BICART_SUPPLY_COMPLETE_TIME_MS ( 2 * MS_PER_SECOND ) ///< Wait time to close the D80 valve after D65 is closed +#define DRY_BICART_SUPPLY_DECAY_COMPLETE_PRESSURE_PSI 4.0F ///< Minimum decay pressure needed to end the supply process. +#define DRY_BICART_SUPPLY_VENT_CYCLE_TIME_MS ( 15 * SEC_PER_MIN * MS_PER_SECOND ) ///< Vent cycle time to initiate D85 opening. // Dry Bicart Drain #define LARGE_DRY_BICART_MAX_DRAIN_TIME_MS ( 8 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for large dry bicart in ms. @@ -98,6 +100,7 @@ DRY_BICART_INITIAL_FILL, ///< Dry bicart initial fill DRY_BICART_SUPPLY, ///< Dry bicart chamber fill DRY_BICART_DRAIN, ///< Dry bicart drain + DRY_BICART_DEPRESSURIZE, ///< Dry bicart depressurize NUM_OF_DRY_BICART_OPERATION ///< Number of dry bicart operation } DRY_BICART_OPERATION_T; @@ -106,6 +109,7 @@ static DRY_BICART_FILL_EXEC_STATE_T dryBiCartFillExecState; ///< Current state of dry bicart fill executive state machine. static BICARB_CHAMBER_FILL_EXEC_STATE_T bicarbChamberFillExecState; ///< Current state of bicarb chamber fill executive state machine. static DRY_BICART_DRAIN_EXEC_STATE_T dryBiCartDrainExecState; ///< Current state of dry bicart drain executive state machine +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T dryBiCartDepressurizeExecState; ///< Current state of dry bicart depressurize executive state machine // fill static U32 dryBiCartFillStartTime; ///< Dry bicart fill start time. static U32 biCartFillCycleCounter; ///< Number of drybicart fill cycle @@ -120,6 +124,7 @@ static OVERRIDE_U32_T dryBiCartFillRequested; ///< Start/stop dry bicart fill. static OVERRIDE_U32_T bicarbChamberFillRequested; ///< Start/stop bicarb chamber fill. static OVERRIDE_U32_T dryBiCartDrainRequested; ///< Start/stop dry bicart drain. +static OVERRIDE_U32_T dryBiCartDepressurizeRequested; ///< Start/stop dry bicart depressurize // publish static OVERRIDE_U32_T dryBiCartDataPublishInterval; ///< Dry bicart data publish interval. static U32 dryBiCartDataPublicationTimerCounter; ///< Used to schedule drybicart data publication to CAN bus. @@ -131,15 +136,20 @@ static U32 dryBiCarbSypplyVentStartTime; ///< Bicarb supply vent start time for both bicart & Chamber F. // drain static U32 dryBiCartDrainStartTime; ///< Drain overall start time (for max timeout) -static U32 dryBiCartDrainLastCondSampleTime; ///< Last time conductivity was sampled -static U32 dryBiCartDrainCondStableCount; ///< Debounce counter for "zero" conductivity +//TODO: implement draining +//static U32 dryBiCartDrainLastCondSampleTime; ///< Last time conductivity was sampled +//static U32 dryBiCartDrainCondStableCount; ///< Debounce counter for "zero" conductivity static U32 dryBiCartDrainTimePeriod; ///< Dry bicart drain time period static U32 dryBiCartPersistenceStartTime; ///< Dry bicart Persistence time. static U32 drybicartPersistenceOnLowercartPressureStartTime; ///< Dry bicart Persistence on lower cart pressure start time. static BOOL dryBiCartPressureDecayStartTimeFlag; ///< Dry bicart d66 pressure decay start timer. +static BOOL dryBiCartVentCycleWaitTimeStartedFlag; ///< Flag indicating venting cycle timer started for opening D85. +static U32 dryBiCartVentCycleStartTime; ///< Dry bicart Vent cycle start time. static DRY_BICART_OPERATION_T dryBicartStartRequest; ///< Dry bicart operation, fill or supply or drain request +static DRY_BICART_OPERATION_T prevDryBicartState; ///< Dry BiCart State Change Tracker + // ********** private function prototypes ********** static void updateDrybicartOperation(void); @@ -159,12 +169,19 @@ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberPressureCheckState( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentStartState(void); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentEndState(void); +static BICARB_CHAMBER_FILL_EXEC_STATE_T completeBicarbChamberFillToIdle( void ); +static BOOL isDryBicartChamberFillWindowOpen( void ); +static void closeD65IfBalChamberSwitchImminent( void ); // Drain static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainStartState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainDurationCheckState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainEndState( void ); +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeStartState( void ); +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeVentStartState( void ); +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeVentEndState( void ); + static F32 getDryBicartLowerCartPressure( void ); static F32 getDryBicartUpperCartPressure( void ); @@ -192,8 +209,8 @@ dryBiCartDataPublishInterval.ovInitData = 0; dryBiCartDataPublishInterval.override = OVERRIDE_RESET; - biCartMaxFillCycleCount.data = DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT; - biCartMaxFillCycleCount.ovData = DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT; + biCartMaxFillCycleCount.data = DRY_BICART_MAX_FILL_CYCLE_CNT; + biCartMaxFillCycleCount.ovData = DRY_BICART_MAX_FILL_CYCLE_CNT; biCartMaxFillCycleCount.ovInitData = 0; biCartMaxFillCycleCount.override = OVERRIDE_RESET; @@ -228,7 +245,9 @@ dryBiCartLowerCartPressure.override = OVERRIDE_RESET; dryBiCartPressureDecayStartTimeFlag = FALSE; + dryBiCartVentCycleWaitTimeStartedFlag = FALSE; dryBiCartFillVentTimeOut = FALSE; + dryBiCartVentCycleStartTime = 0; dryBiCartFillStartTime = 0; lastFillDurationInMS = 0; currentFillDurationInMS = 0; @@ -237,11 +256,12 @@ dryBiCarbSupplyStartTime = 0; dryBiCarbSypplyVentStartTime = 0; dryBiCartDrainStartTime = 0; - dryBiCartDrainLastCondSampleTime = 0; - dryBiCartDrainCondStableCount = 0; + //dryBiCartDrainLastCondSampleTime = 0; + //dryBiCartDrainCondStableCount = 0; dryBiCartDrainTimePeriod = 0; dryBiCartPersistenceStartTime = 0; drybicartPersistenceOnLowercartPressureStartTime = 0; + prevDryBicartState = DRY_BICART_IDLE; } /*********************************************************************//** @@ -261,17 +281,14 @@ * @brief * The execDryBicart function executes the set of dry bicarbonate cartridge fill, * bicarbonate chamber fill and bicarbonate cartridge drain related state machines one at time - * @details \b Inputs: dryBicartStartRequest - * @details \b Outputs: none + * @details \b Inputs: dryBicartStartRequest, prevDryBicartState + * @details \b Outputs: prevDryBicartState * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong dry bicart state machine is * invoked. * @return none. *************************************************************************/ void execDryBicart( void ) { - - execMixingControl(); - // top level state machine selection DRY_BICART_OPERATION_T dryBicartState = dryBicartStartRequest; @@ -297,13 +314,24 @@ execDryBicartDrainMode(); break; + case DRY_BICART_DEPRESSURIZE: + // Dry bicart depressurize + execDryBicartDepressurize(); + break; + default: // software fault, dryBicartStartRequest = DRY_BICART_IDLE; SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DRY_BICART_FILL_INVALID_EXEC_STATE, dryBicartStartRequest ); break; } + if ( prevDryBicartState != dryBicartStartRequest ) + { + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_DRY_BICART_STATE_CHANGE, prevDryBicartState, dryBicartStartRequest ); + prevDryBicartState = dryBicartStartRequest; + } + // Publish dry bicart data publishDryBicartData(); } @@ -453,16 +481,53 @@ /*********************************************************************//** * @brief + * The execDryBicartDepressurize function executes the dry bicart depressurize state machine. + * @details \b Inputs: dryBiCartDepressurizeExecState + * @details \b Outputs: dryBiCartDepressurizeExecState + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong dry bicart depressurize state + * invoked. + * @return current state. + *************************************************************************/ +U32 execDryBicartDepressurize( void ) +{ + // execute drybicart depressurize state machines + switch ( dryBiCartDepressurizeExecState ) + { + case DRY_BICART_DEPRESSURIZE_START_STATE: + dryBiCartDepressurizeExecState = handleDryBicartDepressurizeStartState(); + break; + + case DRY_BICART_DEPRESSURIZE_VENT_START_STATE: + dryBiCartDepressurizeExecState = handleDryBicartDepressurizeVentStartState(); + break; + + case DRY_BICART_DEPRESSURIZE_VENT_END_STATE: + dryBiCartDepressurizeExecState = handleDryBicartDepressurizeVentEndState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DRY_BICART_DEPRESURIZE_INVALID_EXEC_STATE, dryBiCartDepressurizeExecState ); + break; + } + + return dryBiCartDepressurizeExecState; +} + +/*********************************************************************//** + * @brief * The setBicarbChamberFillRequested function sets the chmaberFillRequest * flag value to be True. - * @details \b Inputs: dryBiCartFillRequested, dryBiCartDrainRequested + * @details \b Inputs: dryBiCartFillRequested, dryBiCartDrainRequested, + * dryBiCartDepressurizeRequested * @details \b Outputs: bicarbChamberFillRequested * @return TRUE if successful, FALSE if not. *************************************************************************/ BOOL setBicarbChamberFillRequested( void ) { BOOL result = FALSE; - BOOL requestStatus = getU32OverrideValue( &dryBiCartFillRequested ) || getU32OverrideValue( &dryBiCartDrainRequested ); + BOOL requestStatus = getU32OverrideValue( &dryBiCartFillRequested ) ||\ + getU32OverrideValue( &dryBiCartDrainRequested ) || \ + getU32OverrideValue( &dryBiCartDepressurizeRequested ); // ensure that there is no other operation in progress before new request set to true if ( FALSE == requestStatus ) @@ -496,16 +561,59 @@ /*********************************************************************//** * @brief + * The isDryBicartChamberFillWindowOpen function checks whether D65 may be + * opened for dry bicarb refill: fresh-side BC valves closed and BC switch not + * within the 50 ms valve-close window. + * @details \b Inputs: getBalChamberFreshSideValvesClosedStatus, isBalChamberSwitchImminent + * @details \b Outputs: none + * @return TRUE when the BC fill is completed and allow D65 to fill Chamber F + *************************************************************************/ +static BOOL isDryBicartChamberFillWindowOpen( void ) +{ + BOOL result = FALSE; + + if ( ( TRUE == getBalChamberFreshSideValvesClosedStatus() ) && + ( FALSE == isBalChamberSwitchImminent() ) ) + { + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The closeD65IfBalChamberSwitchImminent function closes D65 when the balancing + * chamber is within 100 ms of switching. + * @details \b Inputs: isBalChamberSwitchImminent + * @details \b Outputs: valve states + * @return none + *************************************************************************/ +static void closeD65IfBalChamberSwitchImminent( void ) +{ + if ( TRUE == isBalChamberSwitchImminent() ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + // Open D80 only in supply state + setValveState( D80_VALV, VALVE_STATE_OPEN ); + } +} + +/*********************************************************************//** + * @brief * The setBicartFillRequested function sets the bicart fill request * flag value to be True. - * @details \b Inputs: bicarbChamberFillRequested, dryBiCartDrainRequested + * @details \b Inputs: bicarbChamberFillRequested, dryBiCartDrainRequested, + * dryBiCartDepressurizeRequested * @details \b Outputs: dryBiCartFillRequested * @return TRUE if successful, FALSE if not. *************************************************************************/ BOOL setBicartFillRequested( void ) { BOOL result = FALSE; - BOOL requestStatus = getU32OverrideValue( &bicarbChamberFillRequested ) || getU32OverrideValue( &dryBiCartDrainRequested ); + BOOL requestStatus = getU32OverrideValue( &bicarbChamberFillRequested ) \ + || getU32OverrideValue( &dryBiCartDrainRequested ) || \ + getU32OverrideValue( &dryBiCartDepressurizeRequested ) ; //ensure that there is no other operation in progress before new request set to true if ( FALSE == requestStatus ) @@ -541,14 +649,17 @@ * @brief * The setBicartDrainRequested function sets the bicart drain request * flag value to be True. - * @details \b Inputs: bicarbChamberFillRequested,dryBiCartFillRequested + * @details \b Inputs: bicarbChamberFillRequested,dryBiCartFillRequested, + * dryBiCartDepressurizeRequested * @details \b Outputs: dryBiCartDrainRequested * @return TRUE if successful, FALSE if not. *************************************************************************/ BOOL setBicartDrainRequested( void ) { BOOL result = FALSE; - BOOL requestStatus = getU32OverrideValue( &bicarbChamberFillRequested ) || getU32OverrideValue( &dryBiCartFillRequested ); + BOOL requestStatus = getU32OverrideValue( &bicarbChamberFillRequested ) || \ + getU32OverrideValue( &dryBiCartFillRequested ) || \ + getU32OverrideValue( &dryBiCartDepressurizeRequested ); //ensure that there is no other operation in progress before new request set to true if ( FALSE == requestStatus ) @@ -582,6 +693,51 @@ /*********************************************************************//** * @brief + * The setBicartDepressurizeRequested function sets the bicart depressurize request + * flag value to be True. + * @details \b Inputs: bicarbChamberFillRequested,dryBiCartFillRequested,dryBiCartDrainRequested + * @details \b Outputs: dryBiCartDepressurizeRequested + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +BOOL setBicartDepressurizeRequested( void ) +{ + BOOL result = FALSE; + BOOL requestStatus = getU32OverrideValue( &bicarbChamberFillRequested ) || \ + getU32OverrideValue( &dryBiCartFillRequested ) || \ + getU32OverrideValue( &dryBiCartDrainRequested ); + + //ensure that there is no other operation in progress before new request set to true + if ( FALSE == requestStatus ) + { + dryBiCartDepressurizeRequested.data = TRUE; + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getBicartDepressurizeRequested function gets the bicart depressurize request + * flag value + * @details \b Inputs: dryBiCartDepressurizeRequested + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +BOOL getBicartDepressurizeRequested( void ) +{ + BOOL result = FALSE; + + if ( ( TRUE == getU32OverrideValue( &dryBiCartDepressurizeRequested ) ) ) + { + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief * The getCurrentDryBiCartFillExecState function returns the current state * of the dry bicart fill state. * @details \b Inputs: dryBiCartFillExecState @@ -623,7 +779,8 @@ /*********************************************************************//** * @brief - * The updateDrybicartOperation function initiates the water fill, bicarbonate supply or bicarbonate drain + * The updateDrybicartOperation function initiates bicart fill water, bicarbonate supply, + * bicart drain or bicart depressurize * operation * @details \b Inputs: none * @details \b Outputs: dryBicartStartRequest @@ -646,6 +803,10 @@ //drain dryBicartStartRequest = DRY_BICART_DRAIN; } + else if ( TRUE == getBicartDepressurizeRequested() ) + { + dryBicartStartRequest = DRY_BICART_DEPRESSURIZE; + } else { // idle @@ -725,30 +886,18 @@ { DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_FILL_WATER_END_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - F32 fillCompletePressure = GET_DRY_BICART_FILL_COMPLETE_PRESSURE_PSI; + F32 fillCompletePressure = GET_FILL_COMPLETE_PRESSURE_PSI; - // Close dry bicart inlet water if D66 pressure is 17 PSI + // Close dry bicart inlet water if D66 pressure is equal to fill complete pressure if ( d66Pressure >= fillCompletePressure ) { - // start the persistence timer once d66 reaches 17 PSI + // start the persistence timer once d66 reaches fill complete pressure if ( 0 == dryBiCartPersistenceStartTime ) { dryBiCartPersistenceStartTime = getMSTimerCount(); } - //check the the maximum cart pressure during persistence on D66 - if ( d66Pressure >= MAX_DRY_BICART_FILL_COMPLETE_PRESSURE ) - { - setValveState( D65_VALV, VALVE_STATE_CLOSED ); - lastFillDurationInMS = currentFillDurationInMS; - currentFillDurationInMS = calcTimeSince( dryBiCartFillStartTime ); - //Increment number of fill cycle - biCartFillCycleCounter++; - dryBiCartPersistenceStartTime = 0; - - state = DRY_BICART_DEGAS_START_STATE; - } - // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + // defined persistence on D66 pressure since pressure overshoot just after D65 opening if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); @@ -762,6 +911,10 @@ state = DRY_BICART_DEGAS_START_STATE; } } + else + { + dryBiCartPersistenceStartTime = 0; + } //TODO:Handle timeout alarm for opening D65 valve too long return state; @@ -811,15 +964,15 @@ //Vent chamber F to atmosphere setValveState( D64_VALV, VALVE_STATE_OPEN ); - // D66 pressure drops to below 1.5 PSI + // D66 pressure drops to below fill vent complete pressure if ( ( d66Pressure <= DRY_BICART_FILL_VENT_COMPLETE_PRESSURE_PSI ) ) { - // start the persistence timer once d66 reaches 1.5 PSI + // start the persistence timer once d66 reaches fill vent complete pressure if ( 0 == dryBiCartPersistenceStartTime ) { dryBiCartPersistenceStartTime = getMSTimerCount(); } - // 200 ms persistence on D66 pressure since pressure drop below 1.5 PSI after opening D64 + // defined persistence on D66 pressure since pressure drop below fill vent complete pressure after opening D64 if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); @@ -836,6 +989,10 @@ state = DRY_BICART_FILL_DURATION_CHECK_STATE; } + else + { + dryBiCartPersistenceStartTime = 0; + } } //TODO: Alarm when vent timeout exceeded, but pressure not dropped below expected PSI (0 psi) @@ -939,8 +1096,9 @@ * @brief * The handleBicarbChamberStartState function wait for bicarb chamber fill request * @details \b Inputs: bicarbChamberFillRequested - * @details \b Outputs: none - * @return the next drybicart fluid drain state. + * @details \b Outputs: dryBiCartVentCycleWaitTimeStartedFlag, dryBiCartPressureDecayStartTimeFlag, + * dryBiCartVentCycleStartTime. + * @return the next drybicart fluid supply state. *************************************************************************/ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberStartState( void ) { @@ -950,7 +1108,13 @@ if ( TRUE == getU32OverrideValue( &bicarbChamberFillRequested ) ) { - state = BICARB_CARTRIDGE_FILL_WATER_START_STATE; + state = BICARB_CHAMBER_SUPPLY_STATE; + + if ( FALSE == dryBiCartVentCycleWaitTimeStartedFlag ) + { + dryBiCartVentCycleWaitTimeStartedFlag = TRUE; + dryBiCartVentCycleStartTime = getMSTimerCount(); + } } return state; @@ -964,64 +1128,84 @@ *************************************************************************/ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterStartState( void ) { - BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_END_STATE; + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_START_STATE; - // Close vent valves and descaling valve - setValveState( D80_VALV, VALVE_STATE_CLOSED ); - setValveState( D81_VALV, VALVE_STATE_CLOSED ); - setValveState( D85_VALV, VALVE_STATE_CLOSED ); + if ( TRUE == isDryBicartChamberFillWindowOpen() ) + { + // Close vent valves and descaling valve + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + setValveState( D81_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_CLOSED ); - // open inlet water to bicart - setValveState( D65_VALV, VALVE_STATE_OPEN ); - setValveState( D64_VALV, VALVE_STATE_OPEN ); + // open inlet water to bicart only when fresh-side BC valves are closed + setValveState( D65_VALV, VALVE_STATE_OPEN ); + setValveState( D64_VALV, VALVE_STATE_OPEN ); - dryBiCarbSupplyStartTime = getMSTimerCount(); - dryBiCartPersistenceStartTime = 0; + dryBiCarbSupplyStartTime = getMSTimerCount(); + dryBiCartPersistenceStartTime = 0; + state = BICARB_CARTRIDGE_FILL_WATER_END_STATE; + } + return state; } /*********************************************************************//** * @brief - * The handleBicarbChamberCartridgeFillWaterStartState function stop water in the dry bicart - * @details \b Inputs: D66 pressure, dryBiCartPersistenceStartTime + * The handleBicarbChamberCartridgeFillWaterStartState function stops the inlet water to cartridge. + * @details \b Inputs: dryBiCartPersistenceStartTime * @details \b Outputs: valve states * @return the next bicarb chamber check level state. *************************************************************************/ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterEndState( void ) { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_END_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - F32 fillCompletePressure = GET_DRY_BICART_FILL_COMPLETE_PRESSURE_PSI; + F32 fillCompletePressure = GET_FILL_COMPLETE_PRESSURE_PSI; + LVL_STATE_T bicarbChamberLevel = getBicarbChamberLevelStatus(); - // check D66 pressure greater than or equal to 17 PSI + if ( FALSE == isDryBicartChamberFillWindowOpen() ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + } + else if ( TRUE == isDryBicartChamberFillWindowOpen() ) + { + setValveState( D65_VALV, VALVE_STATE_OPEN ); + } + + // check D66 pressure greater than or equal to Fill complete pressure if ( d66Pressure >= fillCompletePressure ) { // start the persistence timer once d66 reaches 17 PSI if ( 0 == dryBiCartPersistenceStartTime ) { dryBiCartPersistenceStartTime = getMSTimerCount(); } - // check the the maximum cart pressure during persistence on D66 - if ( d66Pressure >= MAX_DRY_BICART_FILL_COMPLETE_PRESSURE ) - { - // Close water inlet valve as D66 pressure reaches max PSI(20) after persistence - setValveState( D65_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistenceStartTime = 0; - state = BICARB_CHAMBER_SUPPLY_STATE; - } - // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + // Defined persistence on D66 pressure since pressure overshoot just after D65 opening only for chamber fill if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { // Close water inlet valve as D66 pressure reaches 11 PSI after persistence setValveState( D65_VALV, VALVE_STATE_CLOSED ); dryBiCartPersistenceStartTime = 0; - state = BICARB_CHAMBER_SUPPLY_STATE; + // Return to idle + state = completeBicarbChamberFillToIdle(); + } } + else + { + dryBiCartPersistenceStartTime = 0; + } + //Additional code + if ( LVL_STATE_LOW == bicarbChamberLevel ) + { + // Force return to idle to allow next supply + state = completeBicarbChamberFillToIdle(); + } + return state; } @@ -1037,7 +1221,8 @@ BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_PRESSURE_CHECK_STATE; // TODO: set supply in progress to inform BC control to disable alarm - setValveState( D64_VALV, VALVE_STATE_CLOSED ); + setValveState( D64_VALV, VALVE_STATE_OPEN ); + // Open the Bicarb chamber inlet valve setValveState( D80_VALV, VALVE_STATE_OPEN ); @@ -1053,10 +1238,9 @@ * @brief * The handleBicarbChamberPressureCheckStartState function actuates the vent valve * present in the Bicart assembly. - * @details \b Inputs: D66 Pressure, D63 level, dryBiCarbSupplyStartTime, - * dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime, bicarbChamberLevel, - * dryBiCartPressureDecayStartTimeFlag, drybicartPersistenceOnLowercartPressureStartTime - * @details \b Outputs: dryBiCarbSypplyVentStartTime + * @details \b Inputs: dryBiCarbSupplyStartTime, dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime, + * bicarbChamberLevel, dryBiCartPressureDecayStartTimeFlag, drybicartPersistenceOnLowercartPressureStartTime + * @details \b Outputs: dryBiCarbSypplyVentStartTime, valve states * @return the next bicarb chamber Supply Vent Start state. *************************************************************************/ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberPressureCheckState( void ) @@ -1065,32 +1249,45 @@ F32 d66Pressure = getFilteredPressure( D66_PRES ); LVL_STATE_T bicarbChamberLevel = getBicarbChamberLevelStatus(); + // Close D65 irrespective of pressure for balancing chamber fresh side fill to complete. + closeD65IfBalChamberSwitchImminent(); + // Once upper level reached high , close the valve, timeout is for safety in case level sensor didn't work(10 sec), or else its a time based filling (3 sec) if ( ( LVL_STATE_HIGH == bicarbChamberLevel ) || ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ) ) ) { - setValveState( D65_VALV, VALVE_STATE_CLOSED ); - - // start the timer for d66 pressure decay - if( FALSE == dryBiCartPressureDecayStartTimeFlag ) + if ( TRUE == didTimeout( dryBiCartVentCycleStartTime, DRY_BICART_SUPPLY_VENT_CYCLE_TIME_MS ) ) { - dryBiCarbSupplyStartTime = getMSTimerCount(); - dryBiCartPressureDecayStartTimeFlag = TRUE; - } - // do not close the D80 valve, wait till d66 decays to 3 PSI - if ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_SUPPLY_COMPLETE_TIME_MS ) ) - { - if ( d66Pressure <= getDryBicartLowerCartPressure() ) + // start the timer for d66 pressure decay + if ( FALSE == dryBiCartPressureDecayStartTimeFlag ) { - setValveState( D80_VALV, VALVE_STATE_CLOSED ); - setValveState( D85_VALV, VALVE_STATE_OPEN ); - dryBiCarbSupplyStartTime = getMSTimerCount(); - dryBiCarbSypplyVentStartTime = getMSTimerCount(); + dryBiCartPressureDecayStartTimeFlag = TRUE; + } + // do not close the D80 valve, wait till d66 decays to supply decay complete pressure + if ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_SUPPLY_COMPLETE_TIME_MS ) ) + { + if ( d66Pressure <= DRY_BICART_SUPPLY_DECAY_COMPLETE_PRESSURE_PSI ) + { + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + setValveState( D64_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_OPEN ); - state = BICARB_SUPPLY_VENT_START_STATE; + dryBiCarbSupplyStartTime = getMSTimerCount(); + dryBiCarbSypplyVentStartTime = getMSTimerCount(); + + state = BICARB_SUPPLY_VENT_START_STATE; + } } } + else + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + dryBiCarbSupplyStartTime = getMSTimerCount(); + + state = BICARB_CARTRIDGE_FILL_WATER_START_STATE; + } } else if ( d66Pressure <= getDryBicartLowerCartPressure() ) { @@ -1099,10 +1296,13 @@ { drybicartPersistenceOnLowercartPressureStartTime = getMSTimerCount(); } - // 200 ms persistence on D66 pressure - if ( TRUE == didTimeout( drybicartPersistenceOnLowercartPressureStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + + // defined persistence on D66 pressure + if ( ( TRUE == didTimeout( drybicartPersistenceOnLowercartPressureStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) && + ( TRUE == isDryBicartChamberFillWindowOpen() ) ) { setValveState( D65_VALV, VALVE_STATE_OPEN ); + setValveState( D80_VALV, VALVE_STATE_CLOSED ); drybicartPersistenceOnLowercartPressureStartTime = 0; } } @@ -1114,19 +1314,20 @@ { dryBiCartPersistenceStartTime = getMSTimerCount(); } - //check the the maximum cart pressure during persistence on D66 - if ( d66Pressure >= MAX_DRY_BICART_FILL_COMPLETE_PRESSURE ) - { - setValveState( D65_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistenceStartTime = 0; - } - // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + + // defined persistence on D66 pressure since pressure overshoot just after D65 opening if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); + setValveState( D80_VALV, VALVE_STATE_OPEN ); dryBiCartPersistenceStartTime = 0; } } + else + { + dryBiCartPersistenceStartTime = 0; + drybicartPersistenceOnLowercartPressureStartTime = 0; + } return state; } @@ -1136,7 +1337,7 @@ * The handleBicarbChamberSupplyVentStartState function actuates the vent valve * present in the Bicart assembly. * @details \b Inputs: dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime - * @details \b Outputs: dryBiCarbSypplyVentStartTime + * @details \b Outputs: dryBiCarbSypplyVentStartTime, valve states * @return the next bicarb chamber Supply Vent End state. *************************************************************************/ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentStartState(void) @@ -1149,20 +1350,20 @@ //Vent chamber F to atmosphere setValveState( D64_VALV, VALVE_STATE_OPEN ); - // D66 pressure drops to below 1.5 PSI or time out + // D66 pressure drops to below fill vent complete pressure or time out if ( ( d66Pressure <= DRY_BICART_FILL_VENT_COMPLETE_PRESSURE_PSI ) ) { - // start the persistence timer once d66 reaches if it drops below 1.5 + // start the persistence timer once d66 reaches if it drops below fill vent complete pressure if ( 0 == dryBiCartPersistenceStartTime ) { dryBiCartPersistenceStartTime = getMSTimerCount(); } - // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + // defined persistence on D66 pressure since pressure overshoot just after D65 opening if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); dryBiCartPersistenceStartTime = 0; - + dryBiCartVentCycleWaitTimeStartedFlag = FALSE; state = BICARB_SUPPLY_VENT_END_STATE; } } @@ -1171,35 +1372,54 @@ setValveState( D85_VALV, VALVE_STATE_CLOSED ); dryBiCartPersistenceStartTime = 0; dryBiCartFillVentTimeOut = TRUE; + dryBiCartVentCycleWaitTimeStartedFlag = FALSE; state = BICARB_SUPPLY_VENT_END_STATE; } + else + { + dryBiCartPersistenceStartTime = 0; + } } return state; } /*********************************************************************//** * @brief - * The handleBicarbChamberSupplyVentEndState function actuates the vent valve - * present in the Bicart assembly. - * @details \b Inputs: dryBiCarbSypplyVentStartTime - * @details \b Outputs: bicarbChamberFillRequested - * @return the next bicarb chamber start state. + * The completeBicarbChamberFillToIdle function clears bicarb chamber fill + * request and returns the bicarb chamber fill state machine to start. + * @details \b Inputs: none + * @details \b Outputs: bicarbChamberFillRequested, dryBiCartPressureDecayStartTimeFlag, + * dryBicartStartRequest + * @return BICARB_CHAMBER_START_STATE *************************************************************************/ -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentEndState(void) +static BICARB_CHAMBER_FILL_EXEC_STATE_T completeBicarbChamberFillToIdle( void ) { - BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_END_STATE; + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_START_STATE; - bicarbChamberFillRequested.data = FALSE; + bicarbChamberFillRequested.data = FALSE; // for this request override also cleared bicarbChamberFillRequested.ovData = FALSE; dryBiCartPressureDecayStartTimeFlag = FALSE; + dryBicartStartRequest = DRY_BICART_IDLE; - state = BICARB_CHAMBER_START_STATE; + return state; +} - dryBicartStartRequest = DRY_BICART_IDLE; +/*********************************************************************//** + * @brief + * The handleBicarbChamberSupplyVentEndState function completes bicarb chamber + * fill to idle. Kept for any residual VentEnd transitions; prefer calling + * completeBicarbChamberFillToIdle() directly from FillWater/Vent completion. + * @details \b Inputs: none + * @details \b Outputs: bicarbChamberFillRequested, dryBicartStartRequest + * @return the next bicarb chamber start (idle) state. + *************************************************************************/ +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentEndState(void) +{ + BICARB_CHAMBER_FILL_EXEC_STATE_T state = completeBicarbChamberFillToIdle(); return state; } @@ -1228,35 +1448,9 @@ dryBiCartDrainTimePeriod = SMALL_DRY_BICART_MAX_DRAIN_TIME_MS; } - //Close D14 valve - setValveState( D14_VALV, VALVE_STATE_CLOSED ); - setValveState( D34_VALV, VALVE_STATE_CLOSED ); - setValveState( D35_VALV, VALVE_STATE_CLOSED ); - setValveState( D40_VALV, VALVE_STATE_CLOSED ); - setValveState( D91_VALV, VALVE_STATE_CLOSED ); - - // open bypass valve - setValveState( D34_VALV, VALVE_STATE_OPEN ); - - // open DD drain - setValveState( D53_VALV, VALVE_STATE_OPEN ); - - // open iofp drain valve - setValveState( M12_VALV, VALVE_STATE_OPEN ); - - // Open balancing chamber valves - valveControlForBCOpenState(); - - // Run D10 In Open loop mode(max speed 200ml/min) - setConcentratePumpTargetSpeed( D10_PUMP, DRAIN_BICART_PUMP_SPEED, DOSING_CONT_VOLUME ); - requestConcentratePumpOn( D10_PUMP ); - - // Run D48 at 1000 rpm,There is no improvement over above 1000 rpm for drain duration. - setDialysatePumpTargetRPM( D48_PUMP, DIAL_PUMP_DRAIN_RPM, TRUE ); - dryBiCartDrainStartTime = getMSTimerCount(); - dryBiCartDrainLastCondSampleTime = dryBiCartDrainStartTime; - dryBiCartDrainCondStableCount = 0; + //dryBiCartDrainLastCondSampleTime = dryBiCartDrainStartTime; + //dryBiCartDrainCondStableCount = 0; state = DRY_BICART_FLUID_DRAIN_STATE; } @@ -1276,14 +1470,33 @@ { DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_FLUID_DRAIN_STATE; - // Open vent valves and close de-scaling valve - setValveState( D80_VALV, VALVE_STATE_OPEN ); + //Close D14 valve + setValveState( D14_VALV, VALVE_STATE_CLOSED ); + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + setValveState( D35_VALV, VALVE_STATE_CLOSED ); + setValveState( D40_VALV, VALVE_STATE_CLOSED ); + setValveState( D91_VALV, VALVE_STATE_CLOSED ); setValveState( D81_VALV, VALVE_STATE_CLOSED ); - setValveState( D85_VALV, VALVE_STATE_OPEN ); + // Open vent valves and close descaling valve + setValveState( D80_VALV, VALVE_STATE_OPEN ); + setValveState( D85_VALV, VALVE_STATE_OPEN ); // Open D64 valve (vent for equilibrium) setValveState( D64_VALV, VALVE_STATE_OPEN ); + // open bypass valve + setValveState( D34_VALV, VALVE_STATE_OPEN ); + // TODO: open iofp drain valve, remove, this should be handled in IO/FP module. + setValveState( M12_VALV, VALVE_STATE_OPEN ); + // Open balancing chamber valves + valveControlForBCOpenState(); + // Run D10 In Open loop mode(max speed 200ml/min) + setConcentratePumpTargetSpeed( D10_PUMP, DRAIN_BICART_PUMP_SPEED, DOSING_CONT_VOLUME ); + requestConcentratePumpOn( D10_PUMP ); + + // Run D48 at 1000 rpm,There is no improvement over above 1000 rpm for drain duration. + setDialysatePumpTargetRPM( D48_PUMP, DIAL_PUMP_DRAIN_RPM, TRUE ); + state = DRY_BICART_FLUID_DRAIN_DURATION_CHECK_STATE; return state; @@ -1318,14 +1531,10 @@ setValveState( D64_VALV, VALVE_STATE_CLOSED ); setValveState( D80_VALV, VALVE_STATE_CLOSED ); setValveState( D85_VALV, VALVE_STATE_CLOSED ); - // close bypass valve setValveState( D34_VALV, VALVE_STATE_CLOSED ); - // TODO: close DD drain - setValveState( D53_VALV, VALVE_STATE_CLOSED ); - - // TODO : close iofp drain valve + // TODO : close iofp drain valve, remove this should be handled in IO/FP module. setValveState( M12_VALV, VALVE_STATE_CLOSED ); //close all balancing chamber valves @@ -1385,6 +1594,97 @@ /*********************************************************************//** * @brief + * The handleDryBicartDepressurizeStartState function set the one time actuation + * for drybicart de-pressurise request. + * @details \b Inputs: dryBiCartDepressurizeRequested + * @details \b Outputs: none + * @return the next drybicart depressurize state. + *************************************************************************/ +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeStartState( void ) +{ + DRY_BICART_DEPRESSURIZE_EXEC_STATE_T state = DRY_BICART_DEPRESSURIZE_START_STATE; + + if ( TRUE == getU32OverrideValue( &dryBiCartDepressurizeRequested ) ) + { + setValveState( D85_VALV, VALVE_STATE_OPEN ); + + state = DRY_BICART_DEPRESSURIZE_VENT_START_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleDryBicartDepressurizeVentStartState function handles the vent start state for + * drybicart de-pressurise + * @details \b Inputs: dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime + * @details \b Outputs: none + * @return the next drybicart depressurize state. + *************************************************************************/ +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeVentStartState( void ) +{ + DRY_BICART_DEPRESSURIZE_EXEC_STATE_T state = DRY_BICART_DEPRESSURIZE_VENT_START_STATE; + + F32 d66Pressure = getFilteredPressure( D66_PRES ); + + if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) + { + //Vent chamber F to atmosphere + setValveState( D64_VALV, VALVE_STATE_OPEN ); + + // D66 pressure drops to below 1.5 PSI or time out + if ( ( d66Pressure <= DRY_BICART_FILL_VENT_COMPLETE_PRESSURE_PSI ) ) + { + // start the persistence timer once d66 reaches if it drops below 1.5 + if ( 0 == dryBiCartPersistenceStartTime ) + { + dryBiCartPersistenceStartTime = getMSTimerCount(); + } + // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + { + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + dryBiCartPersistenceStartTime = 0; + + state = DRY_BICART_DEPRESSURIZE_VENT_END_STATE; + } + } + else + { + dryBiCartPersistenceStartTime = 0; + } + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleDryBicartDepressurizeVentEndState function handles the vent end state for + * drybicart de-pressurise + * @details \b Inputs: none + * @details \b Outputs: dryBiCartDepressurizeRequested + * @return the next drybicart depressurize state. + *************************************************************************/ +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeVentEndState( void ) +{ + DRY_BICART_DEPRESSURIZE_EXEC_STATE_T state = DRY_BICART_DEPRESSURIZE_VENT_END_STATE; + + // Go idle + dryBiCartDepressurizeRequested.data = FALSE; + // for this request override also cleared + dryBiCartDepressurizeRequested.ovData = FALSE; + + state = DRY_BICART_DEPRESSURIZE_START_STATE; + + dryBicartStartRequest = DRY_BICART_IDLE; + + return state; +} + +/*********************************************************************//** + * @brief * The publishDryBicartData function broadcasts the dry bicart * data at defined interval. * @details \b Inputs: dryBiCartDataPublicationTimerCounter @@ -1432,7 +1732,7 @@ * @details \b Outputs: dryBiCartDataPublishInterval * @param Override message from Dialin which includes the interval * (in ms) to override the DD dry bicart data publish interval to. - * @return TRUE if override successful, FALSE if not + * @return TRUE if override successful, FALSE if not. *************************************************************************/ BOOL testDryBiCartDataPublishIntervalOverride( MESSAGE_T *message ) { @@ -1511,6 +1811,23 @@ /*********************************************************************//** * @brief + * The testDryBiCartDepressurizeRequestOverride function starts/stops the bicart + * depressurize request + * @details \b Inputs: dryBiCartDepressurizeRequested + * @details \b Outputs: dryBiCartDepressurizeRequested + * @param message set message from Dialin which includes the bicart + * depressurize request start/stop. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartDepressurizeRequestOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &dryBiCartDepressurizeRequested, FALSE, TRUE ); + + return result; +} + +/*********************************************************************//** + * @brief * The testDryBiCartTypeOverride function selects small/large cartridge type * @details \b Inputs: dryBiCartType * @details \b Outputs: dryBiCartType