Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -r7339a52a44b3095162224ac775ba2a627469481a -rd513f36b5f073cab9dcb91db28f2b5bb6599eaf4 --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 7339a52a44b3095162224ac775ba2a627469481a) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision d513f36b5f073cab9dcb91db28f2b5bb6599eaf4) @@ -44,23 +44,24 @@ // ********** private definitions ********** #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 WCDI2_PRESSURE_OFFSET_PSI 7.0F ///< The difference between the actual pressure measured at bicart assembly using Alicat and the measured D66 pressure sensor for WCID2 +#define WCID1_PRESSURE_OFFSET_PSI 1.0F ///< The difference between the actual pressure measured at bicart assembly using Alicat and the measured D66 pressure sensor for WCID1 #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_SUPPLY_PERSISTENCE_DURATION_MS 500 ///< Supply 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 DRY_BICART_WCID2_SUPPLY_COMPLETE_PRESSURE_PSI ( 10.0F ) ///< Maximum pressure reached to indicate the dry bicart supply fill being completed for WCID2 -#define DRY_BICART_WCID1_SUPPLY_COMPLETE_PRESSURE_PSI ( 6.0F ) ///< Maximum pressure reached to indicate the dry bicart supply fill being completed for WCID1. +#define DRY_BICART_WCID2_FILL_COMPLETE_PRESSURE_PSI ( 10.0F + WCDI2_PRESSURE_OFFSET_PSI ) ///< The maximum pressure has been reached, indicating that the dry bicart fill for WCID2 is complete +#define DRY_BICART_WCID1_FILL_COMPLETE_PRESSURE_PSI ( 10.0F + WCID1_PRESSURE_OFFSET_PSI ) ///< The maximum pressure has been reached, indicating that the dry bicart fill for WCID1 is complete +#define DRY_BICART_WCID2_SUPPLY_COMPLETE_PRESSURE_PSI ( 10.0F ) ///< The maximum pressure has been reached, indicating that the dry bicart supply fill for WCID2 is complete +#define DRY_BICART_WCID1_SUPPLY_COMPLETE_PRESSURE_PSI ( 6.0F ) ///< The maximum pressure has been reached, indicating that the dry bicart Supply fill for WCID1 is complete + #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 GET_SUPPLY_COMPLETE_PRESSURE_PSI (getTestConfigStatus( TEST_CONFIG_DD_ENABLE_WCID_1 ) != TRUE ? \ - DRY_BICART_WCID2_SUPPLY_COMPLETE_PRESSURE_PSI : DRY_BICART_WCID1_SUPPLY_COMPLETE_PRESSURE_PSI ) ///< Get fill complete pressure based on the WCID configuration +#define GET_SUPPLY_FILL_COMPLETE_PRESSURE_PSI (getTestConfigStatus( TEST_CONFIG_DD_ENABLE_WCID_1 ) != TRUE ? \ + DRY_BICART_WCID2_SUPPLY_COMPLETE_PRESSURE_PSI : DRY_BICART_WCID1_SUPPLY_COMPLETE_PRESSURE_PSI ) ///< Get supply 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 @@ -71,9 +72,10 @@ // 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. #define DRY_BICART_FILL_VENT_MAX_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. -#define DRY_BICART_FILL_VENT_COMPLETE_PRESSURE_PSI 1.5F ///< Pressure reached to indicate the dry bicart venting being completed. +#define DRY_BICART_DEPRESSURIZE_VENT_MAX_TIME_MS ( 30 * MS_PER_SECOND ) ///< Max vent time out for dry bicart to depressurize +#define DRY_BICART_FILL_VENT_COMPLETE_PRESSURE_PSI 1.5F ///< Minimum Pressure to indicate the dry bicart venting being completed. -// Bicarb chamber fill/Supply +// Bicarb chamber Supply/Vent #ifdef CONDUCTIVE_LEVEL_SENSOR_ENABLED #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 @@ -91,16 +93,19 @@ #define DRY_BICART_DRAIN_FLUID_PHASE_TIME_MS ( 3 * MS_PER_SECOND ) ///< Time to stay in fluid drain per cycle #define DRY_BICART_DRAIN_VENT_PHASE_TIME_MS ( 8 * MS_PER_SECOND ) ///< Time to keep D64 open per vent cycle -#define DRY_BICART_DRAIN_D85_CLOSE_TIME_MS ( 10 * MS_PER_SECOND ) -#define DRY_BICART_DRAIN_D85_OPEN_TIME_MS ( 10 * MS_PER_SECOND ) -#define DRY_BICART_DRAIN_TIMEOUT_INCREMENT_MS ( 2 * MS_PER_SECOND ) ///< Amount to increase each time -#define DRY_BICART_DRAIN_MAX_ALLOWED_CLOSE_TIME_MS ( 20 * MS_PER_SECOND ) #define DRY_BICART_DRAIN_D18_PRESSURE_PSI 5 +#define DIAL_PUMP_DRAIN_D48_RPM 2500 ///< Nominal RPM target for dialysate pump D48 to drain the dry bicart. +#define DIAL_PUMP_DRAIN_D12_RPM 1600 ///< Nominal RPM target for dialysate pump D12 to drain the dry bicart. + + +#define INLET_PRES_OUT_OF_RANGE_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< Persistence period for d66 pressure out of range error in milliseconds. +#define INLET_PRES_OUT_OF_RANGE_CLEAR_MS ( 3 * MS_PER_SECOND ) ///< Persistence period for d66 pressure out of range clear in milliseconds. + /// Payload record structure for dry bicart fill request typedef struct { - U32 startStop; ///< Dry bicart fill request start:1 and stop: 0 + U32 startStop; ///< Dry bicart fill request start:1 and stop: 0 } DRY_BICART_FILL_START_CMD_PAYLOAD_T; /// Enumeration of dry bicart top level state machine operation @@ -116,87 +121,98 @@ // ********** private data ********** +// publish +static OVERRIDE_U32_T dryBiCartDataPublishInterval; ///< Dry bicart data publish interval. +static U32 dryBiCartDataPublicationTimerCounter; ///< Used to schedule drybicart data publication to CAN bus. + 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 dryBiCarbFillVentStartTime; ///< Bicarb fill vent start time. static U32 biCartFillCycleCounter; ///< Number of drybicart fill cycle static U32 lastFillDurationInMS; ///< Previous time duration to fill the bicart fill. static U32 currentFillDurationInMS; ///< Current time duration to fill the bicart fill. static OVERRIDE_U32_T biCartMaxFillCycleCount; ///< Maximum number of drybicart fill cycle ( overrideable) -static OVERRIDE_F32_T dryBiCartUpperCartPressure; ///< Upper cart pressure -static OVERRIDE_F32_T dryBiCartLowerCartPressure; ///< Lower cart pressure static BOOL dryBiCartFillVentTimeOut; ///< Vent time out flag // initiate the fill/supply/drain 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. -// cart selection for draining -static OVERRIDE_U32_T dryBiCartType; ///< Dry bicart size(small/large) + // supply static U32 dryBiCarbSupplyStartTime; ///< Bicarb supply start time from bicart to Chamber F. -// vent static U32 dryBiCarbSypplyVentStartTime; ///< Bicarb supply vent start time for both bicart & Chamber F. +static OVERRIDE_F32_T dryBiCartUpperCartPressure; ///< Upper cart pressure +static OVERRIDE_F32_T dryBiCartLowerCartPressure; ///< Lower cart pressure + // drain +// cart selection for draining +static OVERRIDE_U32_T dryBiCartType; ///< Dry bicart size(small/large) static U32 dryBiCartDrainStartTime; ///< Drain overall start time (for max timeout) -static U32 dryBiCartValveOnOffStartTime ; -static U32 dryBiCartPumpStartStopStartTime ; -static U32 dryBiCartDrainTimePeriod; ///< Dry bicart drain time period -static U32 dryBiCartCurrentCloseTimeoutMs; +static U32 dryBiCartPumpStartStopStartTime ; ///< Pump start time (for delaying after valves are open) +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 dryBiCartPressureDecayStartTimeFlag; ///< Dry bicart d66 pressure decay to 4 PSI start timer flag static BOOL dryBiCartVentCycleWaitTimeStartedFlag; ///< Flag indicating venting cycle timer started for opening D85. + +static U32 dryBiCartFillPersistenceStartTime; ///< Dry bicart fill Persistence time. +static U32 dryBiCartFillVentPersistenceStartTime; ///< Dry bicart Vent Persistence time. +static U32 dryBiCartSupplyFillPersistenceStartTime; ///< Dry bicart supply fill Persistence time. +static U32 dryBiCartSupplyVentPersistenceStartTime; ///< Dry bicart supply fill Persistence time. +static U32 dryBiCartDepressurizePersistenceStartTime; ///< Dry bicart depressurize Persistence time. +static U32 drybicartLowercartPressurePersistenceStartTime; ///< Dry bicart Persistence on lower cart pressure start time. +static U32 drybicartUppercartPressurePersistenceStartTime; ///< Dry bicart Persistence on upper cart pressure start time. static U32 dryBiCartVentCycleStartTime; ///< Dry bicart Vent cycle start time. -static DRY_BICART_OPERATION_T dryBicartStartRequest; ///< Dry bicart operation, fill or supply or drain request +// depressurize +static U32 dryBiCartDepressurizeStartTime; ///< Drain overall start time (for max timeout) + +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); -// Fill -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartStartState( void ); -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterStartState( void ); -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterEndState( void ); -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasStartState( void ); -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasEndState( void ); +// Fill & Vent +static void startDryBicartVent( void ); +static void resetDryBicartFillRequest( void ); +static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillIdleState( void ); +static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterState( void ); +static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartVentState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillDurationCheckState( void ); -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillCompleteState( void ); + // Supply & Vent -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberStartState( void ); -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterStartState( void ); -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterEndState( void ); -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyStart( void ); -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 void startBicarbChamberCartridgeFillWaterSequence( void ); +static void startBicarbChamberSupply( void ); +static F32 getDryBicartLowerCartPressure( void ); +static F32 getDryBicartUpperCartPressure( void ); static BOOL isDryBicartChamberFillWindowOpen( void ); -static void closeD65IfBalChamberSwitchImminent( void ); +static void updateValvesOnBalChamberSwitch( void ); +static void resetBicarbChamberFillRequest( void ); +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyIdleState( void ); +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterState( void ); +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyState( void ); +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentState(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 prepareSystemForDrain( void ); +static configureValvesForDrain( void ); static terminateDrainSequence( void ); +static void resetDryBicartDrainRequest( void ); +static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainIdleState( void ); +static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainState( void ); +static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainDurationCheckState( 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 ); +// Depressurize +static void resetDryBicartDepressurizeRequest( void ); +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeIdleState( void ); +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeState( void ); -static F32 getDryBicartLowerCartPressure( void ); -static F32 getDryBicartUpperCartPressure( void ); - // publish the status static void publishDryBicartData( void ); static U32 getDryBicartFillDataPublishInterval( void ); @@ -211,10 +227,12 @@ *************************************************************************/ void initDryBiCart( void ) { - dryBiCartFillExecState = DRY_BICART_START_STATE; - bicarbChamberFillExecState = BICARB_CHAMBER_START_STATE; - dryBiCartDrainExecState = DRY_BICART_DRAIN_START_STATE; + dryBiCartFillExecState = DRY_BICART_FILL_IDLE_STATE; + bicarbChamberFillExecState = BICARB_CHAMBER_SUPPLY_IDLE_STATE; + dryBiCartDrainExecState = BICART_DRAIN_IDLE_STATE; + dryBiCartDepressurizeExecState = DRY_BICART_DEPRESSURIZE_IDLE_STATE; dryBicartStartRequest = DRY_BICART_IDLE; + prevDryBicartState = DRY_BICART_IDLE; dryBiCartDataPublishInterval.data = DRY_BICART_DATA_PUBLISH_INTERVAL; dryBiCartDataPublishInterval.ovData = DRY_BICART_DATA_PUBLISH_INTERVAL; @@ -246,8 +264,8 @@ dryBiCartType.ovInitData = 0; dryBiCartType.override = OVERRIDE_RESET; - dryBiCartUpperCartPressure.data = GET_SUPPLY_COMPLETE_PRESSURE_PSI; - dryBiCartUpperCartPressure.ovData = GET_SUPPLY_COMPLETE_PRESSURE_PSI; + dryBiCartUpperCartPressure.data = GET_SUPPLY_FILL_COMPLETE_PRESSURE_PSI; + dryBiCartUpperCartPressure.ovData = GET_SUPPLY_FILL_COMPLETE_PRESSURE_PSI; dryBiCartUpperCartPressure.ovInitData = 0.0F; dryBiCartUpperCartPressure.override = OVERRIDE_RESET; @@ -268,15 +286,15 @@ dryBiCarbSupplyStartTime = 0; dryBiCarbSypplyVentStartTime = 0; dryBiCartDrainStartTime = 0; - dryBiCartValveOnOffStartTime = 0; dryBiCartPumpStartStopStartTime = 0; - //dryBiCartDrainLastCondSampleTime = 0; - //dryBiCartDrainCondStableCount = 0; dryBiCartDrainTimePeriod = 0; - dryBiCartPersistenceStartTime = 0; - drybicartPersistenceOnLowercartPressureStartTime = 0; - dryBiCartCurrentCloseTimeoutMs = DRY_BICART_DRAIN_TIMEOUT_INCREMENT_MS; - prevDryBicartState = DRY_BICART_IDLE; + + dryBiCartFillPersistenceStartTime = 0; + //dryBiCartVentPersistenceStartTime = 0; + drybicartLowercartPressurePersistenceStartTime = 0; + drybicartUppercartPressurePersistenceStartTime = 0; + + initPersistentAlarm( ALARM_ID_DD_DRY_BICART_FILL_INLET_PRESSURE_LOW, INLET_PRES_OUT_OF_RANGE_TIMEOUT_MS, INLET_PRES_OUT_OF_RANGE_CLEAR_MS ); } /*********************************************************************//** @@ -307,6 +325,8 @@ // top level state machine selection DRY_BICART_OPERATION_T dryBicartState = dryBicartStartRequest; + hydChamberWaterInletControl(); + switch ( dryBicartState ) { case DRY_BICART_IDLE: @@ -316,17 +336,17 @@ case DRY_BICART_INITIAL_FILL: // Dry bicart fill exec - execDryBicartFillMode(); + execDryBicartFill(); break; case DRY_BICART_SUPPLY: // Fill Bicarb chamber F exec - execBicarbChamberFillMode(); + execBicarbChamberSupply(); break; case DRY_BICART_DRAIN: // Dry bicart drain exec - execDryBicartDrainMode(); + execDryBicartDrain(); break; case DRY_BICART_DEPRESSURIZE: @@ -353,49 +373,35 @@ /*********************************************************************//** * @brief - * The execDryBicartFillMode function executes the dry bicart fill (mixing water + * The execDryBicartFill function executes the dry bicart fill (mixing water * with dry sodium bicarbonate ) state machine. * @details \b Inputs: dryBiCartFillExecState * @details \b Outputs: dryBiCartFillExecState * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong dry bicart fill state * invoked. * @return current state. *************************************************************************/ -U32 execDryBicartFillMode( void ) +U32 execDryBicartFill( void ) { - hydChamberWaterInletControl(); - // execute drybicart fill state machine switch ( dryBiCartFillExecState ) { - case DRY_BICART_START_STATE: - dryBiCartFillExecState = handleDryBicartStartState(); + case DRY_BICART_FILL_IDLE_STATE: + dryBiCartFillExecState = handleDryBicartFillIdleState(); break; - case DRY_BICART_FILL_WATER_START_STATE: - dryBiCartFillExecState = handleDryBicartFillWaterStartState(); + case DRY_BICART_FILL_WATER_STATE: + dryBiCartFillExecState = handleDryBicartFillWaterState(); break; - case DRY_BICART_FILL_WATER_END_STATE: - dryBiCartFillExecState = handleDryBicartFillWaterEndState(); - break; - - case DRY_BICART_DEGAS_START_STATE: - dryBiCartFillExecState = handleDryBicartDegasStartState(); + case DRY_BICART_VENT_STATE: + dryBiCartFillExecState = handleDryBicartVentState(); break; - case DRY_BICART_DEGAS_END_STATE: - dryBiCartFillExecState = handleDryBicartDegasEndState(); - break; - case DRY_BICART_FILL_DURATION_CHECK_STATE: dryBiCartFillExecState = handleDryBicartFillDurationCheckState(); break; - case DRY_BICART_FILL_COMPLETE_STATE: - dryBiCartFillExecState = handleDryBicartFillCompleteState(); - break; - default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DRY_BICART_FILL_INVALID_EXEC_STATE, dryBiCartFillExecState ); break; @@ -406,48 +412,35 @@ /*********************************************************************//** * @brief - * The execBicarbChamberFillMode function executes the bicarb chamber fill + * The execBicarbChamberSupply function executes the bicarb chamber fill * (delivering bicarbonate from Bicart assembly to chamber F)state machine. * @details \b Inputs: bicarbChamberFillExecState * @details \b Outputs: bicarbChamberFillExecState * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong bicarb chamber * fill state invoked. * @return current state. *************************************************************************/ -U32 execBicarbChamberFillMode( void ) +U32 execBicarbChamberSupply( void ) { - // TODO in pregen mode call hydChamberWaterInletControl(); // execute bicarb chamber fill state machine switch ( bicarbChamberFillExecState ) { - case BICARB_CHAMBER_START_STATE: - bicarbChamberFillExecState = handleBicarbChamberStartState(); + case BICARB_CHAMBER_SUPPLY_IDLE_STATE: + bicarbChamberFillExecState = handleBicarbChamberSupplyIdleState(); break; - case BICARB_CARTRIDGE_FILL_WATER_START_STATE: - bicarbChamberFillExecState = handleBicarbChamberCartridgeFillWaterStartState(); + case BICARB_CARTRIDGE_FILL_WATER_STATE: + bicarbChamberFillExecState = handleBicarbChamberCartridgeFillWaterState(); break; - case BICARB_CARTRIDGE_FILL_WATER_END_STATE: - bicarbChamberFillExecState = handleBicarbChamberCartridgeFillWaterEndState(); - break; - case BICARB_CHAMBER_SUPPLY_STATE: - bicarbChamberFillExecState = handleBicarbChamberSupplyStart(); + bicarbChamberFillExecState = handleBicarbChamberSupplyState(); break; - case BICARB_CHAMBER_PRESSURE_CHECK_STATE: - bicarbChamberFillExecState = handleBicarbChamberPressureCheckState(); + case BICARB_SUPPLY_VENT_STATE: + bicarbChamberFillExecState = handleBicarbChamberSupplyVentState(); break; - case BICARB_SUPPLY_VENT_START_STATE: - bicarbChamberFillExecState = handleBicarbChamberSupplyVentStartState(); - break; - - case BICARB_SUPPLY_VENT_END_STATE: - bicarbChamberFillExecState = handleBicarbChamberSupplyVentEndState(); - break; - default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_BICARB_CHAMBER_FILL_INVALID_EXEC_STATE, bicarbChamberFillExecState ); break; @@ -458,34 +451,30 @@ /*********************************************************************//** * @brief - * The execDryBicartDrainMode function executes the dry bicart drain state machine. + * The execDryBicartDrain function executes the dry bicart drain state machine. * @details \b Inputs: dryBiCartDrainExecState * @details \b Outputs: dryBiCartDrainExecState * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong dry bicart drain state * invoked. * @return current state. *************************************************************************/ -U32 execDryBicartDrainMode( void ) +U32 execDryBicartDrain( void ) { // execute drybicart drain state machine switch ( dryBiCartDrainExecState ) { - case DRY_BICART_DRAIN_START_STATE: - dryBiCartDrainExecState = handleDryBicartDrainStartState(); + case BICART_DRAIN_IDLE_STATE: + dryBiCartDrainExecState = handleDryBicartDrainIdleState(); break; - case DRY_BICART_FLUID_DRAIN_STATE: - dryBiCartDrainExecState = handleDryBicartFluidDrainState(); + case BICART_DRAIN_STATE: + dryBiCartDrainExecState = handleDryBicartDrainState(); break; - case DRY_BICART_FLUID_DRAIN_DURATION_CHECK_STATE: - dryBiCartDrainExecState = handleDryBicartFluidDrainDurationCheckState(); + case BICART_DRAIN_DURATION_CHECK_STATE: + dryBiCartDrainExecState = handleDryBicartDrainDurationCheckState(); break; - case DRY_BICART_FLUID_DRAIN_END_STATE: - dryBiCartDrainExecState = handleDryBicartFluidDrainEndState(); - break; - default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DRY_BICART_DRAIN_INVALID_EXEC_STATE, dryBiCartDrainExecState ); break; @@ -508,18 +497,14 @@ // execute drybicart depressurize state machines switch ( dryBiCartDepressurizeExecState ) { - case DRY_BICART_DEPRESSURIZE_START_STATE: - dryBiCartDepressurizeExecState = handleDryBicartDepressurizeStartState(); + case DRY_BICART_DEPRESSURIZE_IDLE_STATE: + dryBiCartDepressurizeExecState = handleDryBicartDepressurizeIdleState(); break; - case DRY_BICART_DEPRESSURIZE_VENT_START_STATE: - dryBiCartDepressurizeExecState = handleDryBicartDepressurizeVentStartState(); + case DRY_BICART_DEPRESSURIZE_STATE: + dryBiCartDepressurizeExecState = handleDryBicartDepressurizeState(); 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; @@ -598,13 +583,13 @@ /*********************************************************************//** * @brief - * The closeD65IfBalChamberSwitchImminent function closes D65 when the balancing - * chamber is within 100 ms of switching. + * The updateValvesOnBalChamberSwitch function closes D65 when the balancing + * chamber is within 100 ms of switching and open D80 * @details \b Inputs: isBalChamberSwitchImminent * @details \b Outputs: valve states * @return none *************************************************************************/ -static void closeD65IfBalChamberSwitchImminent( void ) +static void updateValvesOnBalChamberSwitch( void ) { if ( TRUE == isBalChamberSwitchImminent() ) { @@ -766,6 +751,22 @@ /*********************************************************************//** * @brief + * The checkDryBicartInletPressure function check the persistence alarm + * @details \b Inputs: none + * @details \b Outputs: none + * @return none. + *************************************************************************/ +void checkDryBicartInletPressure( ALARM_ID_T alarm, F32 lowerThreshold ) +{ + F32 pressureD66 = getFilteredPressure( D66_PRES ); + + BOOL isPressureLowRange = ( ( pressureD66 < lowerThreshold ) ? TRUE : FALSE ); + + checkPersistentAlarm( alarm, isPressureLowRange, pressureD66, lowerThreshold ); +} + +/*********************************************************************//** + * @brief * The getDryBicartUpperCartPressure function gets the bicart upper threshold pressure * @details \b Inputs: dryBiCartUpperCartPressure * @details \b Outputs: none @@ -831,27 +832,34 @@ /*********************************************************************//** * @brief - * The handleDryBicartStartState function wait for a fill request + * The handleDryBicartFillIdleState function wait for a fill request * @details \b Inputs: dryBiCartFillRequested - * @details \b Outputs: valve states - * @return the next drybicart fill water start state. + * @details \b Outputs: valve states, dryBiCartFillStartTime + * @return the next drybicart fill water state. *************************************************************************/ -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartStartState( void ) +static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillIdleState( void ) { - DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_START_STATE; + DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_FILL_IDLE_STATE; if ( TRUE == getU32OverrideValue( &dryBiCartFillRequested ) ) { - // fill drybicart only if iofp state is in FP_MODE_GENP - //if(FP_MODE_GENP == getCurrentFPOperationMode()) - { - // TODO: pre gen should start the D12 pump and D14 valve - setValveState( D14_VALV, VALVE_STATE_OPEN ); - setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM_B1_9_B2_0, TRUE ); + // TODO: pre gen should start the D12 pump and D14 valve + setValveState( D14_VALV, VALVE_STATE_OPEN ); + setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM_B1_9_B2_0, TRUE ); - state = DRY_BICART_FILL_WATER_START_STATE; - } - // TODO: alarm if fill requested without IOFP in Gen mode + // Close vent valves and de-scaling valve + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + setValveState( D81_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + + // Open D65 and D64 + setValveState( D65_VALV, VALVE_STATE_OPEN ); + setValveState( D64_VALV, VALVE_STATE_OPEN ); + + // Initiate timer to measure length of fill (ONLY ONCE) + dryBiCartFillStartTime = getMSTimerCount(); + + state = DRY_BICART_FILL_WATER_STATE; } return state; @@ -861,120 +869,87 @@ * @brief * The handleDryBicartFillWaterStartState function initiates the water fill * into dry bicarbonate cartridge. - * @details \b Inputs: none - * @details \b Outputs: valve states, dryBiCartFillStartTime + * @details \b Inputs: dryBiCartFillPersistenceStartTime + * @details \b Outputs: valve states, dryBiCartFillStartTime, lastFillDurationInMS, + * currentFillDurationInMS * @return the next drybicart fill water end state. *************************************************************************/ -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterStartState( void ) +static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterState( void ) { - DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_FILL_WATER_START_STATE; + DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_FILL_WATER_STATE; - // Close vent valves and de-scaling valve - setValveState( D80_VALV, VALVE_STATE_CLOSED ); - setValveState( D81_VALV, VALVE_STATE_CLOSED ); - setValveState( D85_VALV, VALVE_STATE_CLOSED ); + F32 d66Pressure = getFilteredPressure( D66_PRES ); + F32 fillCompletePressure = GET_FILL_COMPLETE_PRESSURE_PSI; - //Open D65 - setValveState( D65_VALV, VALVE_STATE_OPEN ); + checkDryBicartInletPressure(ALARM_ID_DD_DRY_BICART_FILL_INLET_PRESSURE_LOW, DRY_BICART_FILL_INITIATE_PRESSURE_PSI ); - //Open D64 - setValveState( D64_VALV, VALVE_STATE_OPEN ); - - //Initiate timer to measure length of fill - dryBiCartFillStartTime = getMSTimerCount(); - - state = DRY_BICART_FILL_WATER_END_STATE; - - return state; -} - -/*********************************************************************//** - * @brief - * The handleDryBicartFillWaterEndState function closes the valve opened - * for Dry bicart fill. - * @details \b Inputs: D66 pressure sensor reading, dryBiCartPersistenceStartTime - * @details \b Outputs: valve states, lastFillDurationInMS, currentFillDurationInMS, - * biCartFillCycleCounter - * @return the next drybicart degas start state. - *************************************************************************/ -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterEndState( void ) -{ - DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_FILL_WATER_END_STATE; - F32 d66Pressure = getFilteredPressure( D66_PRES ); - F32 fillCompletePressure = GET_FILL_COMPLETE_PRESSURE_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 fill complete pressure - if ( 0 == dryBiCartPersistenceStartTime ) + if ( 0 == dryBiCartFillPersistenceStartTime ) { - dryBiCartPersistenceStartTime = getMSTimerCount(); + dryBiCartFillPersistenceStartTime = getMSTimerCount(); } // defined persistence on D66 pressure since pressure overshoot just after D65 opening - if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + if ( TRUE == didTimeout( dryBiCartFillPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); lastFillDurationInMS = currentFillDurationInMS; currentFillDurationInMS = calcTimeSince( dryBiCartFillStartTime ); //Increment number of fill cycle biCartFillCycleCounter++; - dryBiCartPersistenceStartTime = 0; + dryBiCartFillPersistenceStartTime = 0; - state = DRY_BICART_DEGAS_START_STATE; + startDryBicartVent(); + + state = DRY_BICART_VENT_STATE; } } else { - dryBiCartPersistenceStartTime = 0; + dryBiCartFillPersistenceStartTime = 0; } - //TODO:Handle timeout alarm for opening D65 valve too long return state; } /*********************************************************************//** * @brief - * The handleDryBicartDegasStartState function actuates the vent valve + * The startDryBicartVent function actuates the vent valve * present in the Bicart assembly. * @details \b Inputs: none * @details \b Outputs: valve states, dryBiCartFillStartTime, dryBiCartPersistenceStartTime * @return the next drybicart degas end state. *************************************************************************/ -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasStartState( void ) +static void startDryBicartVent( void ) { - DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_DEGAS_START_STATE; - //Close D64 setValveState( D64_VALV, VALVE_STATE_CLOSED); //Vent bicart to chamber F setValveState( D85_VALV, VALVE_STATE_OPEN ); //Initiate timer to measure length of bicart vent - dryBiCartFillStartTime = getMSTimerCount(); - dryBiCartPersistenceStartTime = 0; - - state = DRY_BICART_DEGAS_END_STATE; - - return state; + dryBiCarbFillVentStartTime = getMSTimerCount(); + dryBiCartFillVentPersistenceStartTime = 0; } /*********************************************************************//** * @brief * The handleDryBicartDegasEndState function open vent valve present in * the F Chamber (Bicarb) and closes the vent valve once pressure is met. - * @details \b Inputs: D66 pressure sensor reading, dryBiCartFillStartTime, - * dryBiCartPersistenceStartTime + * @details \b Inputs: D66 pressure sensor reading, dryBiCarbFillVentStartTime, + * dryBiCartFillVentPersistenceStartTime * @details \b Outputs: valve states, dryBiCartFillVentTimeOut * @return the next drybicart fill duration check state. *************************************************************************/ -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasEndState( void ) +static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartVentState( void ) { - DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_DEGAS_END_STATE; + DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_VENT_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - if ( TRUE == didTimeout( dryBiCartFillStartTime, DRY_BICART_FILL_VENT_TIME_MS ) ) + if ( TRUE == didTimeout( dryBiCarbFillVentStartTime, DRY_BICART_FILL_VENT_TIME_MS ) ) { //Vent chamber F to atmosphere setValveState( D64_VALV, VALVE_STATE_OPEN ); @@ -983,30 +958,30 @@ if ( ( d66Pressure <= DRY_BICART_FILL_VENT_COMPLETE_PRESSURE_PSI ) ) { // start the persistence timer once d66 reaches fill vent complete pressure - if ( 0 == dryBiCartPersistenceStartTime ) + if ( 0 == dryBiCartFillVentPersistenceStartTime ) { - dryBiCartPersistenceStartTime = getMSTimerCount(); + dryBiCartFillVentPersistenceStartTime = getMSTimerCount(); } // 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 ) ) + if ( TRUE == didTimeout( dryBiCartFillVentPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistenceStartTime = 0; + dryBiCartFillVentPersistenceStartTime = 0; state = DRY_BICART_FILL_DURATION_CHECK_STATE; } } - else if ( ( TRUE == didTimeout( dryBiCartFillStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) + else if ( ( TRUE == didTimeout( dryBiCarbFillVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistenceStartTime = 0; + dryBiCartFillVentPersistenceStartTime = 0; dryBiCartFillVentTimeOut = TRUE; state = DRY_BICART_FILL_DURATION_CHECK_STATE; } else { - dryBiCartPersistenceStartTime = 0; + dryBiCartFillVentPersistenceStartTime = 0; } } //TODO: Alarm when vent timeout exceeded, but pressure not dropped below expected PSI (0 psi) @@ -1034,62 +1009,49 @@ if ( ( ( biCartFillCycleCounter >= DRY_BICART_MINIMUM_FILL_CYCLE_CNT ) && ( TRUE == dryBiCartFillVentTimeOut ) ) || ( biCartFillCycleCounter >= dryBiCartMaxFillCount ) ) { - state = DRY_BICART_FILL_COMPLETE_STATE; - // TODO: stop the D12 pump signalDialysatePumpHardStop( D12_PUMP ); // TODO: close the D14 valve setValveState( D14_VALV, VALVE_STATE_CLOSED ); - // TODO: remove ? start timer for timeout to reset fill complete state to DRY_BICART_START_STATE - dryBiCartFillStartTime = getMSTimerCount(); + resetDryBicartFillRequest(); + + state = DRY_BICART_FILL_IDLE_STATE; } else { dryBiCartFillVentTimeOut = FALSE; // transition to next fill cycle and degas - state = DRY_BICART_FILL_WATER_START_STATE; + state = DRY_BICART_FILL_WATER_STATE; } return state; } /*********************************************************************//** * @brief - * The handleDryBicartFillCompleteState function terminal for the dry bicart - * fill states. - * @details \b Inputs: dryBiCartFillRequested, dryBiCartFillStartTime - * @details \b Outputs: valve states, lastFillDurationInMS, biCartFillCycleCounter, - * dryBiCartFillVentTimeOut, dryBiCartFillRequested + * The resetDryBicartFillRequest function reset dry bicart + * fill states related variables + * @details \b Inputs: none + * @details \b Outputs: valve states, currentFillDurationInMS, lastFillDurationInMS, biCartFillCycleCounter, + * dryBiCartFillVentTimeOut, dryBiCartFillRequested, dryBicartStartRequest * @return the next drybicart start state. *************************************************************************/ -static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillCompleteState( void ) +static void resetDryBicartFillRequest( void ) { - // stay in this state till bicart request is cleared so that fill complete status can be checked - DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_FILL_COMPLETE_STATE; - // TODO: in pre-gen, need to check the fill complete status - if ( TRUE == didTimeout( dryBiCartFillStartTime, DRY_BICART_FILL_COMPLETE_TIME_MS ) ) - { - currentFillDurationInMS = 0; - lastFillDurationInMS = 0; - biCartFillCycleCounter = 0; - dryBiCartFillVentTimeOut = FALSE; - // Go idle - dryBiCartFillRequested.data = FALSE; - // for this request override also cleared - dryBiCartFillRequested.ovData = FALSE; + currentFillDurationInMS = 0; + lastFillDurationInMS = 0; + biCartFillCycleCounter = 0; + dryBiCartFillVentTimeOut = FALSE; + // Go idle + dryBiCartFillRequested.data = FALSE; + // for this request override also cleared + dryBiCartFillRequested.ovData = FALSE; - // when fill complete , need to close the d3 valve - hydChamberWaterInletControl(); - - state = DRY_BICART_START_STATE; - dryBicartStartRequest = DRY_BICART_IDLE; - } - - return state; + dryBicartStartRequest = DRY_BICART_IDLE; } /*********************************************************************//** @@ -1109,20 +1071,23 @@ /*********************************************************************//** * @brief - * The handleBicarbChamberStartState function wait for bicarb chamber fill request + * The handleBicarbChamberSupplyIdleState function wait for bicarb chamber fill request * @details \b Inputs: bicarbChamberFillRequested * @details \b Outputs: dryBiCartVentCycleWaitTimeStartedFlag, dryBiCartPressureDecayStartTimeFlag, * dryBiCartVentCycleStartTime. * @return the next drybicart fluid supply state. *************************************************************************/ -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberStartState( void ) +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyIdleState( void ) { - BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_START_STATE; + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_SUPPLY_IDLE_STATE; dryBiCartPressureDecayStartTimeFlag = FALSE; if ( TRUE == getU32OverrideValue( &bicarbChamberFillRequested ) ) { + //startBicarbChamberCartridgeFillWaterSequence(); + startBicarbChamberSupply(); + state = BICARB_CHAMBER_SUPPLY_STATE; if ( FALSE == dryBiCartVentCycleWaitTimeStartedFlag ) @@ -1136,15 +1101,13 @@ } /*********************************************************************//** * @brief - * The handleBicarbChamberCartridgeFillWaterStartState function fill water in the dry bicart + * The startBicarbChamberCartridgeFillWaterSequence function start fill water in the dry bicart * @details \b Inputs: none - * @details \b Outputs: valve states, dryBiCarbSupplyStartTime, dryBiCartPersistenceStartTime - * @return the next bicarb cartridge fill water end state. + * @details \b Outputs: valve states, dryBiCarbSupplyStartTime, dryBiCartSupplyFillPersistenceStartTime + * @return none. *************************************************************************/ -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterStartState( void ) +static void startBicarbChamberCartridgeFillWaterSequence( void ) { - BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_START_STATE; - if ( TRUE == isDryBicartChamberFillWindowOpen() ) { // Close vent valves and descaling valve @@ -1156,27 +1119,26 @@ setValveState( D65_VALV, VALVE_STATE_OPEN ); setValveState( D64_VALV, VALVE_STATE_OPEN ); - dryBiCarbSupplyStartTime = getMSTimerCount(); - dryBiCartPersistenceStartTime = 0; + //startBicarbChamberSupply(); - state = BICARB_CARTRIDGE_FILL_WATER_END_STATE; + dryBiCarbSupplyStartTime = getMSTimerCount(); + dryBiCartSupplyFillPersistenceStartTime = 0; } - - return state; } /*********************************************************************//** * @brief - * The handleBicarbChamberCartridgeFillWaterStartState function stops the inlet water to cartridge. - * @details \b Inputs: dryBiCartPersistenceStartTime + * The handleBicarbChamberCartridgeFillWaterState function stops the inlet water to cartridge. + * @details \b Inputs: dryBiCartSupplyFillPersistenceStartTime * @details \b Outputs: valve states * @return the next bicarb chamber check level state. *************************************************************************/ -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterEndState( void ) +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterState( 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_STATE; + F32 d66Pressure = getFilteredPressure( D66_PRES ); - F32 fillCompletePressure = GET_SUPPLY_COMPLETE_PRESSURE_PSI; + F32 fillCompletePressure = GET_SUPPLY_FILL_COMPLETE_PRESSURE_PSI; LVL_STATE_T bicarbChamberLevel = getBicarbChamberLevelStatus(); if ( FALSE == isDryBicartChamberFillWindowOpen() ) @@ -1192,49 +1154,51 @@ if ( d66Pressure >= fillCompletePressure ) { // start the persistence timer once d66 reaches 17 PSI - if ( 0 == dryBiCartPersistenceStartTime ) + if ( 0 == dryBiCartSupplyFillPersistenceStartTime ) { - dryBiCartPersistenceStartTime = getMSTimerCount(); + dryBiCartSupplyFillPersistenceStartTime = getMSTimerCount(); } // Defined persistence on D66 pressure since pressure overshoot just after D65 opening only for chamber fill - if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_SUPPLY_PERSISTENCE_DURATION_MS ) ) + if ( TRUE == didTimeout( dryBiCartSupplyFillPersistenceStartTime, DRY_BICART_SUPPLY_PERSISTENCE_DURATION_MS ) ) { // Close water inlet valve as D66 pressure reaches 11 PSI after persistence setValveState( D65_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistenceStartTime = 0; + dryBiCartSupplyFillPersistenceStartTime = 0; // Return to idle - state = completeBicarbChamberFillToIdle(); + resetBicarbChamberFillRequest(); + state = BICARB_CHAMBER_SUPPLY_IDLE_STATE; + } } else { - dryBiCartPersistenceStartTime = 0; + dryBiCartSupplyFillPersistenceStartTime = 0; } //Additional code if ( LVL_STATE_LOW == bicarbChamberLevel ) { // Force return to idle to allow next supply - state = completeBicarbChamberFillToIdle(); + resetBicarbChamberFillRequest(); + + state = BICARB_CHAMBER_SUPPLY_IDLE_STATE; } return state; } /*********************************************************************//** * @brief - * The handleBicarbChamberSupplyStart function open the bicarb inlet valve (D80). + * The startBicarbChamberSupply function open the bicarb inlet valve (D80). * @details \b Inputs: none * @details \b Outputs: valve states, dryBiCarbSupplyStartTime - * @return the next bicarb chamber fill state. + * @return none. *************************************************************************/ -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyStart( void ) +static void startBicarbChamberSupply( void ) { - 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_OPEN ); @@ -1245,27 +1209,27 @@ dryBiCarbSupplyStartTime = getMSTimerCount(); // TODO: alarm - - return state; } /*********************************************************************//** * @brief * The handleBicarbChamberPressureCheckStartState function actuates the vent valve * present in the Bicart assembly. - * @details \b Inputs: dryBiCarbSupplyStartTime, dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime, - * bicarbChamberLevel, dryBiCartPressureDecayStartTimeFlag, drybicartPersistenceOnLowercartPressureStartTime + * @details \b Inputs: dryBiCarbSupplyStartTime, dryBiCarbSypplyVentStartTime, + * drybicartUppercartPressurePersistenceStartTime, + * bicarbChamberLevel, dryBiCartPressureDecayStartTimeFlag, + * drybicartLowercartPressurePersistenceStartTime * @details \b Outputs: dryBiCarbSypplyVentStartTime, valve states * @return the next bicarb chamber Supply Vent Start state. *************************************************************************/ -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberPressureCheckState( void ) +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyState( void ) { - BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_PRESSURE_CHECK_STATE; + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_SUPPLY_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); LVL_STATE_T bicarbChamberLevel = getBicarbChamberLevelStatus(); - // Close D65 irrespective of pressure for balancing chamber fresh side fill to complete. - closeD65IfBalChamberSwitchImminent(); + // Close D65 , open D85 irrespective of pressure for balancing chamber fresh side fill to complete. + updateValvesOnBalChamberSwitch(); // 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 ) || @@ -1280,84 +1244,87 @@ 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 ( ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_SUPPLY_COMPLETE_TIME_MS ) ) || ( d66Pressure <= DRY_BICART_SUPPLY_DECAY_COMPLETE_PRESSURE_PSI ) ) { - 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 ); + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + setValveState( D64_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_OPEN ); - dryBiCarbSupplyStartTime = getMSTimerCount(); - dryBiCarbSypplyVentStartTime = getMSTimerCount(); + dryBiCarbSupplyStartTime = getMSTimerCount(); + dryBiCarbSypplyVentStartTime = getMSTimerCount(); - state = BICARB_SUPPLY_VENT_START_STATE; - } - } + state = BICARB_SUPPLY_VENT_STATE; + } } else { setValveState( D65_VALV, VALVE_STATE_CLOSED ); setValveState( D80_VALV, VALVE_STATE_CLOSED ); + dryBiCarbSupplyStartTime = getMSTimerCount(); - state = BICARB_CARTRIDGE_FILL_WATER_START_STATE; + startBicarbChamberCartridgeFillWaterSequence(); + + state = BICARB_CARTRIDGE_FILL_WATER_STATE; } } else if ( d66Pressure <= getDryBicartLowerCartPressure() ) { // start persistence timer - if ( 0 == drybicartPersistenceOnLowercartPressureStartTime ) + if ( 0 == drybicartLowercartPressurePersistenceStartTime ) { - drybicartPersistenceOnLowercartPressureStartTime = getMSTimerCount(); + drybicartLowercartPressurePersistenceStartTime = getMSTimerCount(); } // defined persistence on D66 pressure - if ( ( TRUE == didTimeout( drybicartPersistenceOnLowercartPressureStartTime, DRY_BICART_SUPPLY_PERSISTENCE_DURATION_MS ) ) && + if ( ( TRUE == didTimeout( drybicartLowercartPressurePersistenceStartTime, DRY_BICART_SUPPLY_PERSISTENCE_DURATION_MS ) ) && ( TRUE == isDryBicartChamberFillWindowOpen() ) ) { setValveState( D65_VALV, VALVE_STATE_OPEN ); setValveState( D80_VALV, VALVE_STATE_CLOSED ); - drybicartPersistenceOnLowercartPressureStartTime = 0; + + drybicartLowercartPressurePersistenceStartTime = 0; } } // Close water inlet valve as fill is complete. else if ( d66Pressure >= getDryBicartUpperCartPressure() ) { // start persistence timer - if ( 0 == dryBiCartPersistenceStartTime ) + if ( 0 == drybicartUppercartPressurePersistenceStartTime ) { - dryBiCartPersistenceStartTime = getMSTimerCount(); + drybicartUppercartPressurePersistenceStartTime = getMSTimerCount(); } // defined persistence on D66 pressure since pressure overshoot just after D65 opening - if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_SUPPLY_PERSISTENCE_DURATION_MS ) ) + if ( TRUE == didTimeout( drybicartUppercartPressurePersistenceStartTime, DRY_BICART_SUPPLY_PERSISTENCE_DURATION_MS ) ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); setValveState( D80_VALV, VALVE_STATE_OPEN ); - dryBiCartPersistenceStartTime = 0; + + drybicartUppercartPressurePersistenceStartTime = 0; } } else { - dryBiCartPersistenceStartTime = 0; - drybicartPersistenceOnLowercartPressureStartTime = 0; + drybicartUppercartPressurePersistenceStartTime = 0; + drybicartLowercartPressurePersistenceStartTime = 0; } return state; } /*********************************************************************//** * @brief - * The handleBicarbChamberSupplyVentStartState function actuates the vent valve + * The handleBicarbChamberSupplyVentState function actuates the vent valve * present in the Bicart assembly. - * @details \b Inputs: dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime - * @details \b Outputs: dryBiCarbSypplyVentStartTime, valve states + * @details \b Inputs: dryBiCarbSypplyVentStartTime, dryBiCartSupplyVentPersistenceStartTime + * @details \b Outputs: dryBiCarbSypplyVentStartTime,dryBiCartVentCycleWaitTimeStartedFlag, + * dryBiCartFillVentTimeOut, valve states * @return the next bicarb chamber Supply Vent End state. *************************************************************************/ -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentStartState(void) +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentState(void) { - BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_START_STATE; + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) @@ -1369,31 +1336,38 @@ if ( ( d66Pressure <= DRY_BICART_FILL_VENT_COMPLETE_PRESSURE_PSI ) ) { // start the persistence timer once d66 reaches if it drops below fill vent complete pressure - if ( 0 == dryBiCartPersistenceStartTime ) + if ( 0 == dryBiCartSupplyVentPersistenceStartTime ) { - dryBiCartPersistenceStartTime = getMSTimerCount(); + dryBiCartSupplyVentPersistenceStartTime = getMSTimerCount(); } // defined persistence on D66 pressure since pressure overshoot just after D65 opening - if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + if ( TRUE == didTimeout( dryBiCartSupplyVentPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistenceStartTime = 0; + + dryBiCartSupplyVentPersistenceStartTime = 0; dryBiCartVentCycleWaitTimeStartedFlag = FALSE; - state = BICARB_SUPPLY_VENT_END_STATE; + + resetBicarbChamberFillRequest(); + + state = BICARB_CHAMBER_SUPPLY_IDLE_STATE; } } else if ( ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistenceStartTime = 0; + + dryBiCartSupplyVentPersistenceStartTime = 0; dryBiCartFillVentTimeOut = TRUE; dryBiCartVentCycleWaitTimeStartedFlag = FALSE; - state = BICARB_SUPPLY_VENT_END_STATE; + resetBicarbChamberFillRequest(); + + state = BICARB_CHAMBER_SUPPLY_IDLE_STATE; } else { - dryBiCartPersistenceStartTime = 0; + dryBiCartSupplyVentPersistenceStartTime = 0; } } @@ -1402,93 +1376,53 @@ /*********************************************************************//** * @brief - * The completeBicarbChamberFillToIdle function clears bicarb chamber fill - * request and returns the bicarb chamber fill state machine to start. + * The resetBicarbChamberFillRequest function clears bicarb chamber fill + * request. * @details \b Inputs: none * @details \b Outputs: bicarbChamberFillRequested, dryBiCartPressureDecayStartTimeFlag, * dryBicartStartRequest * @return BICARB_CHAMBER_START_STATE *************************************************************************/ -static BICARB_CHAMBER_FILL_EXEC_STATE_T completeBicarbChamberFillToIdle( void ) +static void resetBicarbChamberFillRequest( void ) { - BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_START_STATE; - bicarbChamberFillRequested.data = FALSE; // for this request override also cleared bicarbChamberFillRequested.ovData = FALSE; dryBiCartPressureDecayStartTimeFlag = FALSE; dryBicartStartRequest = DRY_BICART_IDLE; - - return state; } /*********************************************************************//** * @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; -} - -/*********************************************************************//** - * @brief - * The handleDryBicartDrainStartState function set the one time actuation - * for bicarb drain request. - * @details \b Inputs: dryBiCartDrainRequested, dryBiCartType - * @details \b Outputs: valve states, dryBiCartDrainStartTime, dryBiCartDrainTimePeriod - * dryBiCartDrainLastCondSampleTime, dryBiCartDrainCondStableCount - * @return the next drybicart fluid drain state. - *************************************************************************/ -static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainStartState( void ) -{ - DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_DRAIN_START_STATE; - - if ( TRUE == getU32OverrideValue( &dryBiCartDrainRequested ) ) - { - dryBiCartDrainStartTime = getMSTimerCount(); - - // Prepares the system fluid matrix by establishing the correct valve states. - // This function acts as an initialization guard, ensuring that all - // non-essential lines are isolated and all active lines are open - // before downstream equipment (pumps) can be energized. - prepareSystemForDrain(); - - state = DRY_BICART_FLUID_DRAIN_STATE; - } - - return state; -} - -/*********************************************************************//** - * @brief - * The prepareSystemForDrain function open all necessary valves for drain + * The configureValvesForDrain function open all necessary valves for drain * @details \b Inputs: None * @details \b Outputs: valve states * @return None. *************************************************************************/ -static prepareSystemForDrain() +static configureValvesForDrain() { //Close valves + setValveState( D8_VALV, VALVE_STATE_CLOSED ); setValveState( D14_VALV, VALVE_STATE_CLOSED ); + setValveState( D34_VALV, VALVE_STATE_CLOSED ); + setValveState( D40_VALV, VALVE_STATE_CLOSED ); + setValveState( D52_VALV, VALVE_STATE_CLOSED ); + setValveState( D54_VALV, VALVE_STATE_CLOSED ); setValveState( D65_VALV, VALVE_STATE_CLOSED ); + setValveState( D34_VALV, VALVE_STATE_CLOSED ); setValveState( D35_VALV, VALVE_STATE_CLOSED ); setValveState( D40_VALV, VALVE_STATE_CLOSED ); - setValveState( D64_VALV, VALVE_STATE_CLOSED ); + setValveState( D80_VALV, VALVE_STATE_CLOSED ); setValveState( D81_VALV, VALVE_STATE_CLOSED ); setValveState( D83_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_CLOSED ); setValveState( D91_VALV, VALVE_STATE_CLOSED ); + setValveState( D100_VALV, VALVE_STATE_CLOSED ); // Open vent valves and supply valve - setValveState( D80_VALV, VALVE_STATE_OPEN ); + + setValveState( D83_VALV, VALVE_STATE_OPEN ); setValveState( D85_VALV, VALVE_STATE_OPEN ); // Open D64 valve (vent for chamber F) @@ -1501,38 +1435,73 @@ setValveState( M12_VALV, VALVE_STATE_OPEN ); // Open balancing chamber valves - valveControlForBCOpenState(); + //valveControlForBCOpenState(); + valveControlForBCSpentSideOnlyOpenState(); + + dryBiCartPumpStartStopStartTime = getMSTimerCount(); } /*********************************************************************//** * @brief - * The handleDryBicartFluidDrainState function initiates the water drain - * from dry bicarbonate cartridge by turning on the pumps - * @details \b Inputs: none - * @details \b Outputs: valve states + * The handleDryBicartDrainIdleState function set the one time actuation + * for bicarb drain request. + * @details \b Inputs: dryBiCartDrainRequested, dryBiCartType + * @details \b Outputs: valve states, dryBiCartDrainStartTime, dryBiCartDrainTimePeriod + * @return the next drybicart fluid drain state. + *************************************************************************/ +static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainIdleState( void ) +{ + DRY_BICART_DRAIN_EXEC_STATE_T state = BICART_DRAIN_IDLE_STATE; + + if ( TRUE == getU32OverrideValue( &dryBiCartDrainRequested ) ) + { + if ( TRUE == getU32OverrideValue( &dryBiCartType ) ) + { + dryBiCartDrainTimePeriod = LARGE_DRY_BICART_MAX_DRAIN_TIME_MS; + } + else + { + dryBiCartDrainTimePeriod = SMALL_DRY_BICART_MAX_DRAIN_TIME_MS; + } + + dryBiCartDrainStartTime = getMSTimerCount(); + + configureValvesForDrain(); + + state = BICART_DRAIN_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleDryBicartDrainState function initiates the water drain + * from dry bicarbonate cartridge. + * @details \b Inputs: dryBiCartPumpStartStopStartTime + * @details \b Outputs: valve states, dryBiCartDrainStartTime * @return the next drybicart drain duration check state. *************************************************************************/ -static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainState( void ) +static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainState( void ) { - DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_FLUID_DRAIN_STATE; + DRY_BICART_DRAIN_EXEC_STATE_T state = BICART_DRAIN_STATE; if ( TRUE == didTimeout( dryBiCartPumpStartStopStartTime, DRY_BICART_DRAIN_FLUID_PHASE_TIME_MS ) ) { - // 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 ); + // Run D48 at 2500 rpm ie 800ml/min + setDialysatePumpTargetRPM( D48_PUMP, DIAL_PUMP_DRAIN_D48_RPM, TRUE ); - dryBiCartValveOnOffStartTime = getMSTimerCount(); + setDialysatePumpTargetRPM( D12_PUMP, DIAL_PUMP_DRAIN_D12_RPM, TRUE ); + //dryBiCartValveOnOffStartTime = getMSTimerCount(); + if( 0 == dryBiCartDrainStartTime ) { - dryBiCartDrainStartTime = getMSTimerCount(); + dryBiCartDrainStartTime = getMSTimerCount(); } - state = DRY_BICART_FLUID_DRAIN_DURATION_CHECK_STATE; + state = BICART_DRAIN_DURATION_CHECK_STATE; } return state; @@ -1550,6 +1519,7 @@ // Stop pumps requestConcentratePumpOff( D10_PUMP, FALSE ); signalDialysatePumpHardStop( D48_PUMP ); + signalDialysatePumpHardStop( D12_PUMP ); // Close valves used for drain setValveState( D64_VALV, VALVE_STATE_CLOSED ); @@ -1569,150 +1539,87 @@ /*********************************************************************//** * @brief - * The handleDryBicartFluidDrainDurationCheckState function monitors and - * determines drain complete by max timeout or cancel request - * @details \b Inputs: dryBiCartDrainStartTime, dryBiCartValveOnOffStartTime, - * dryBiCartType, dryBiCartDrainRequested and dryBiCartDrainTimePeriod, dryBiCartCurrentCloseTimeoutMs - * @details \b Outputs: None - * @return the next drybicart drain end state. + * The handleDryBicartFluidDrainDurationCheckState function determines drain complete by max timeout + * @details \b Inputs: dryBiCartDrainStartTime + * @details \b Outputs: none + * @return the next drybicart drain idle state. *************************************************************************/ -static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainDurationCheckState( void ) +static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainDurationCheckState( void ) { - DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_FLUID_DRAIN_DURATION_CHECK_STATE; + // switch back to DRY_BICART_FLUID_DRAIN_STATE if not fully drained or not timeout + DRY_BICART_DRAIN_EXEC_STATE_T state = BICART_DRAIN_DURATION_CHECK_STATE; - F32 d18Pressure = getFilteredPressure( D18_PRES ); - - if ( TRUE == getU32OverrideValue( &dryBiCartType ) ) - { - dryBiCartDrainTimePeriod = LARGE_DRY_BICART_MAX_DRAIN_TIME_MS; - } - else - { - dryBiCartDrainTimePeriod = SMALL_DRY_BICART_MAX_DRAIN_TIME_MS; - } - - if ( d18Pressure >= DRY_BICART_DRAIN_D18_PRESSURE_PSI ) - { - requestConcentratePumpOff( D10_PUMP, FALSE ); - - dryBiCartPumpStartStopStartTime = getMSTimerCount(); - - // move back to the previous state and wait for 3 second and then turn on the D10 pump - state = DRY_BICART_FLUID_DRAIN_STATE; - } - - if ( ( VALVE_STATE_OPEN == getValveStateName(D85_VALV)) && - ( TRUE == didTimeout( dryBiCartValveOnOffStartTime, DRY_BICART_DRAIN_D85_OPEN_TIME_MS ) ) ) - { - // Vent using D85 , we need to create exact opposite step of the initial fill, first fill large , - // a little second fill and a little third fill - setValveState( D85_VALV, VALVE_STATE_CLOSED ); - setValveState( D64_VALV, VALVE_STATE_CLOSED ); - - dryBiCartValveOnOffStartTime = getMSTimerCount(); - } - else if ( ( VALVE_STATE_CLOSED == getValveStateName(D85_VALV)) && - ( TRUE == didTimeout( dryBiCartValveOnOffStartTime, dryBiCartCurrentCloseTimeoutMs ) ) ) - { - // order of opening the valve is important here, if we open the D85 first , - // more negative pressure created at the upper part of the bicart - setValveState( D64_VALV, VALVE_STATE_OPEN ); - setValveState( D85_VALV, VALVE_STATE_OPEN ); - - dryBiCartValveOnOffStartTime = getMSTimerCount(); - - // --- Increment Timeout For The Next Off Cycle to create more negative pressure in the Chamber F --- - dryBiCartCurrentCloseTimeoutMs += DRY_BICART_DRAIN_TIMEOUT_INCREMENT_MS; - - if ( dryBiCartCurrentCloseTimeoutMs > DRY_BICART_DRAIN_MAX_ALLOWED_CLOSE_TIME_MS ) - { - dryBiCartCurrentCloseTimeoutMs = DRY_BICART_DRAIN_MAX_ALLOWED_CLOSE_TIME_MS; - } - } - - if ( FALSE == getU32OverrideValue( &dryBiCartDrainRequested ) ) - { - dryBiCartDrainTimePeriod = 0; - } - // Max drain time fall back, it is different for small and large bicart, // 4 minutes for small bicart with full of water and 8 minutes for large bicart // TODO: user settings should be derived for large and small dry bicart for drain time out // right now dialin override is provided. if ( TRUE == didTimeout( dryBiCartDrainStartTime, dryBiCartDrainTimePeriod ) ) { + state = BICART_DRAIN_IDLE_STATE; - state = DRY_BICART_FLUID_DRAIN_END_STATE; + terminateDrainSequence(); + + resetDryBicartDrainRequest(); } return state; } /*********************************************************************//** * @brief - * The handleDryBicartFluidDrainEndState function handles the end state for - * draining of the fluid. - * @details \b Inputs: dryBiCartDrainRequested + * The resetDryBicartDrainRequest function reset the drain request + * * @details \b Inputs: dryBiCartDrainRequested * @details \b Outputs: dryBiCartDrainRequested * @return the next drybicart drain start state. *************************************************************************/ -static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainEndState( void ) +static void resetDryBicartDrainRequest( void ) { - // stay in this state till drain request is cleared so that Drain completion status can be checked - DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_FLUID_DRAIN_END_STATE; - - terminateDrainSequence( ); - // Go idle dryBiCartDrainRequested.data = FALSE; // for this request override also cleared dryBiCartDrainRequested.ovData = FALSE; - state = DRY_BICART_DRAIN_START_STATE; - dryBicartStartRequest = DRY_BICART_IDLE; - - return state; } /*********************************************************************//** * @brief - * The handleDryBicartDepressurizeStartState function set the one time actuation + * The handleDryBicartDepressurizeIdleState 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 ) +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeIdleState( void ) { - DRY_BICART_DEPRESSURIZE_EXEC_STATE_T state = DRY_BICART_DEPRESSURIZE_START_STATE; + DRY_BICART_DEPRESSURIZE_EXEC_STATE_T state = DRY_BICART_DEPRESSURIZE_IDLE_STATE; if ( TRUE == getU32OverrideValue( &dryBiCartDepressurizeRequested ) ) { setValveState( D85_VALV, VALVE_STATE_OPEN ); - state = DRY_BICART_DEPRESSURIZE_VENT_START_STATE; + state = DRY_BICART_DEPRESSURIZE_STATE; } return state; } /*********************************************************************//** * @brief - * The handleDryBicartDepressurizeVentStartState function handles the vent start state for + * The handleDryBicartDepressurizeState function handles the vent start state for * drybicart de-pressurise - * @details \b Inputs: dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime + * @details \b Inputs: dryBiCartDepressurizeStartTime, dryBiCartDepressurizePersistenceStartTime * @details \b Outputs: none * @return the next drybicart depressurize state. *************************************************************************/ -static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeVentStartState( void ) +static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeState( void ) { - DRY_BICART_DEPRESSURIZE_EXEC_STATE_T state = DRY_BICART_DEPRESSURIZE_VENT_START_STATE; + DRY_BICART_DEPRESSURIZE_EXEC_STATE_T state = DRY_BICART_DEPRESSURIZE_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) + if ( TRUE == didTimeout( dryBiCartDepressurizeStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) { //Vent chamber F to atmosphere setValveState( D64_VALV, VALVE_STATE_OPEN ); @@ -1721,22 +1628,34 @@ 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 ) + if ( 0 == dryBiCartDepressurizePersistenceStartTime ) { - dryBiCartPersistenceStartTime = getMSTimerCount(); + dryBiCartDepressurizePersistenceStartTime = getMSTimerCount(); } - // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening - if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + // 200 ms persistence on D66 pressure since pressure drop just after D64 opening + if ( TRUE == didTimeout( dryBiCartDepressurizePersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistenceStartTime = 0; + dryBiCartDepressurizePersistenceStartTime = 0; - state = DRY_BICART_DEPRESSURIZE_VENT_END_STATE; + resetDryBicartDepressurizeRequest(); + + state = DRY_BICART_DEPRESSURIZE_IDLE_STATE; } } + else if ( ( TRUE == didTimeout( dryBiCartDepressurizeStartTime, DRY_BICART_DEPRESSURIZE_VENT_MAX_TIME_MS ) ) ) + { + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + + dryBiCartDepressurizePersistenceStartTime = 0; + + resetDryBicartDepressurizeRequest(); + + state = DRY_BICART_DEPRESSURIZE_IDLE_STATE; + } else { - dryBiCartPersistenceStartTime = 0; + dryBiCartDepressurizePersistenceStartTime = 0; } } @@ -1745,26 +1664,19 @@ /*********************************************************************//** * @brief - * The handleDryBicartDepressurizeVentEndState function handles the vent end state for - * drybicart de-pressurise + * The resetDryBicartDepressurizeRequest function handles reset request depressurize request * @details \b Inputs: none * @details \b Outputs: dryBiCartDepressurizeRequested * @return the next drybicart depressurize state. *************************************************************************/ -static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeVentEndState( void ) +static void resetDryBicartDepressurizeRequest( 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; } /*********************************************************************//** @@ -1786,11 +1698,13 @@ data.dryBiCartFillExecState = (U32)dryBiCartFillExecState; data.bicarbChamberFillExecState = (U32)bicarbChamberFillExecState; data.dryBiCartDrainExecState = (U32)dryBiCartDrainExecState; + data.dryBiCartDepressurizeExecState = (U32)dryBiCartDepressurizeExecState; data.dryBiCartFillCycleCounter = biCartFillCycleCounter; data.dryBiCartMaxFillCycleCount = getU32OverrideValue( &biCartMaxFillCycleCount ); data.dryBiCartFillRequest = getU32OverrideValue( &dryBiCartFillRequested ); data.bicarbChamberFillRequest = getU32OverrideValue( &bicarbChamberFillRequested ); data.dryBiCartDrainRequest = getU32OverrideValue( &dryBiCartDrainRequested ); + data.dryBiCartDepressurizeRequest = getU32OverrideValue( &dryBiCartDepressurizeRequested ); data.dryBiCartLastFillTime = lastFillDurationInMS; data.dryBiCartCurrentFillTime = currentFillDurationInMS; data.dryBiCartType = getU32OverrideValue( &dryBiCartType ); Index: firmware/App/Controllers/DryBiCart.h =================================================================== diff -u -ra631e128cd6be44aa232e23b58a229bfb8fe9043 -rd513f36b5f073cab9dcb91db28f2b5bb6599eaf4 --- firmware/App/Controllers/DryBiCart.h (.../DryBiCart.h) (revision a631e128cd6be44aa232e23b58a229bfb8fe9043) +++ firmware/App/Controllers/DryBiCart.h (.../DryBiCart.h) (revision d513f36b5f073cab9dcb91db28f2b5bb6599eaf4) @@ -39,11 +39,13 @@ U32 dryBiCartFillExecState; ///< Dry bicart execution state U32 bicarbChamberFillExecState; ///< Bicarb chamber Fill execution state U32 dryBiCartDrainExecState; ///< Dry bicart drain execution state + U32 dryBiCartDepressurizeExecState; ///< Dry bicart depressurize execution state U32 dryBiCartFillCycleCounter; ///< Dry bicart fill cycle counter U32 dryBiCartMaxFillCycleCount; ///< Dry bicart fill cycle max count U32 dryBiCartFillRequest; ///< Dry bicart fill request U32 bicarbChamberFillRequest; ///< Bicarb chamber fill request U32 dryBiCartDrainRequest; ///< Dry bicart drain request + U32 dryBiCartDepressurizeRequest; ///< Dry bicart depressurize request U32 dryBiCartLastFillTime; ///< Dry bicart last fill duration in milli second U32 dryBiCartCurrentFillTime; ///< Dry bicart current fill duration in milli second U32 dryBiCartType; ///< Dry bicart type (small-0/large-1) @@ -55,16 +57,18 @@ void initDryBiCart( void ); void transitionToDryBicart( void ); -U32 execDryBicartFillMode( void ); -U32 execBicarbChamberFillMode( void ); -U32 execDryBicartDrainMode( void ); +U32 execDryBicartFill( void ); +U32 execBicarbChamberSupply( void ); +U32 execDryBicartDrain( void ); U32 execDryBicartDepressurize( void ); void execDryBicart( void ); BOOL setBicarbChamberFillRequested( void ); BOOL getBicarbChamberFillRequested( void ); BOOL setBicartFillRequested( void ); BOOL setBicartDrainRequested( void ); +BOOL setBicartDepressurizeRequested( void ); + DRY_BICART_FILL_EXEC_STATE_T getCurrentDryBiCartFillExecState( void ); BOOL testDryBiCartDataPublishIntervalOverride( MESSAGE_T *message ); Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -rff0edadf0c6f161a0a092ddaf94d1940d64f7d5e -rd513f36b5f073cab9dcb91db28f2b5bb6599eaf4 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision ff0edadf0c6f161a0a092ddaf94d1940d64f7d5e) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision d513f36b5f073cab9dcb91db28f2b5bb6599eaf4) @@ -889,7 +889,7 @@ isLevelLow = ( ( getLevelStatus( D46_LEVL ) != LEVEL_STATE_LOW ) ? FALSE : TRUE ); } - checkPersistentAlarm( alarm, isLevelLow, 0.0F, 0.0F ); + //checkPersistentAlarm( alarm, isLevelLow, 0.0F, 0.0F ); } else { Index: firmware/App/Services/Messaging.c =================================================================== diff -u -rff0edadf0c6f161a0a092ddaf94d1940d64f7d5e -rd513f36b5f073cab9dcb91db28f2b5bb6599eaf4 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision ff0edadf0c6f161a0a092ddaf94d1940d64f7d5e) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision d513f36b5f073cab9dcb91db28f2b5bb6599eaf4) @@ -315,6 +315,10 @@ { MSG_ID_FP_CONDUCTIVITY_SENSOR_CAL_REQUEST, &testHandleConductivitySensorCalRequest }, { MSG_ID_DD_MIXING_CONTROL_DATA_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testMixingControlDataPublishIntervalOverride }, { MSG_ID_DD_BICART_DEPRESSURISE_REQUEST_OVERRIDE_REQUEST, &testDryBiCartDepressurizeRequestOverride }, + { MSG_ID_DD_DIALYSATE_TARGET_CONDUCTIVITY_OVERRIDE_REQUEST, &testMixingControlDialysateTargetConductivityOverride }, + { MSG_ID_DD_DIALYSATE_DELTA_CONDUCTIVITY_OVERRIDE_REQUEST, &testMixingControlDialysateDeltaConductivityOverride }, + { MSG_ID_DD_MIXING_BICARB_CONTROL_INTERVAL_OVERRIDE_REQUEST, &testMixingControlBicarbControlIntervalOverride }, + { MSG_ID_DD_MIXING_ACID_CONTROL_INTERVAL_OVERRIDE_REQUEST, &testMixingControlAcidControlIntervalOverride }, }; /// Calculation for number of entries in the incoming message function handler look-up table.