Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -r9af3827512621c9c710adea691c5e42f07023485 -r8d2a2aec6986e58a1f6f75d4ba8864ee689fde48 --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 9af3827512621c9c710adea691c5e42f07023485) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 8d2a2aec6986e58a1f6f75d4ba8864ee689fde48) @@ -8,10 +8,10 @@ * @file DryBiCart.c * * @author (original) Sameer poyil -* @date (original) 23-Oct-2025 +* @date (original) 10-Nov-2025 * * @author (original) Sameer poyil -* @date (original) 23-Oct-2025 +* @date (original) 10-Nov-2025 * ***************************************************************************/ @@ -41,25 +41,31 @@ // ********** private definitions ********** #define DRY_BICART_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. + +// Bicart Fill +#define DRY_BICART_FILL_DURATION_MIN_MS (2 * MS_PER_SECOND) ///< Minimum fill duration to be met to end the fill cycle. +#define DRY_BICART_FILL_DURATION_DIFF_MS 750 ///< Fill duration difference between last and current fill cycle. #define DRY_BICART_FILL_MAX_PRESSURE 12.0F ///< Maximum pressure that drybicart can withstand. #define DRY_BICART_FILL_COMPLETE_PRESSURE 15.0F ///< Maximum pressure reached to inidcate the drybicart fill being completed. #define DRY_BICART_FILL_INITIATE_PRESSURE 5.0F ///< Minimum pressure required to initiate the drybicart fill process. -#define DRY_BICART_VENT_COMPLETE_PRESSURE 1.5F ///< Pressure reached to inidcate the drybicart venting being completed. -#define DRY_BICART_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bibag gas before actuating Bicarb chamber(F) venting. -#define DRY_BICART_VENT_MAX_TIME_MS ( 10 * MS_PER_SECOND ) ///< Max time to vent both bicart and Chamber F. -#define DRY_BICART_FILL_DURATION_DIFF_MS 500 ///< Fill duration difference between last and current fill cycle. -#define DRY_BICART_FILL_DURATION_MIN_MS 1500 ///< Minimum fill duration to be met to end the fill cycle. #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 30 ///< Max fill cycle allowed (by override) for dry bicart fill/mix with water. -//TODO: uncomment later based on the testing results -//#define VALV_D80_MAX_OPEN_TIME_MS ( 10 * MS_PER_SECOND ) ///< Max time allowed for opening D80 valve during bicarb chamber (F) fill. -#define VALV_D80_MAX_OPEN_TIME_MS ( 500 ) ///< Max time allowed for opening D80 valve during bicarb chamber (F) fill. -#define DRY_BICART_MAX_DRAIN_TIME_MS ( 240 * MS_PER_SECOND ) ///< Max drain time for bicart chamber in ms. -#define DRY_BICART_DRAIN_COND_SAMPLE_PERIOD_MS 500 ///< Conductivity sample period -#define DRY_BICART_DRAIN_COND_ZERO_THRESH 0.05F ///< "Zero" conductivity threshold -#define DRY_BICART_DRAIN_COND_STABLE_SAMPLES 10U ///< Debounce samples (10*50ms=500ms) + +// Bicart Vent +#define DRY_BICART_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bibag gas before actuating Bicarb chamber(F) venting. +#define DRY_BICART_VENT_MAX_TIME_MS ( 10 * MS_PER_SECOND ) ///< Max time to vent both bicart and Chamber F. +#define DRY_BICART_VENT_COMPLETE_PRESSURE 1.5F ///< Pressure reached to inidcate the drybicart venting being completed. + +// Bicarb chamber fill/Supply +#define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time allowed for opening D80 valve during bicarb chamber (F) fill. + +// Bicart Drain +#define DRY_BICART_MAX_DRAIN_TIME_MS ( 4 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for bicart chamber in ms. #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_COND_SAMPLE_PERIOD_MS 500 ///< Conductivity sample period +#define DRY_BICART_DRAIN_COND_ZERO_THRESH 0.05F ///< "Zero" conductivity threshold +#define DRY_BICART_DRAIN_COND_STABLE_SAMPLES 10U ///< Debounce samples (10*50ms=500ms) #define DRY_BICART_DRAIN_COND_STABLE_COUNT_MAX 0xFFFFU /// Payload record structure for dry bicart fill request @@ -80,6 +86,7 @@ static U32 currentFillDurationInMS; ///< Current time duartion to fill the bicart fill. static OVERRIDE_U32_T dryBiCartFillRequested; ///< Start/stop Dry bicart fill. static OVERRIDE_U32_T dryBiCartDrainRequested; ///< Start/stop Dry bicart drain. +static OVERRIDE_U32_T dryBiCartFillRequested; ///< Start/stop Dry bicart fill. static OVERRIDE_U32_T dryBiCartDataPublishInterval; ///< Dry bicart data publish interval. static U32 dryBiCartDataPublicationTimerCounter; ///< Used to schedule drybicart data publication to CAN bus. static U32 dryBiCarbSupplyStartTime; ///< Bicarb supply start time from bicart to Chamber F. @@ -132,6 +139,10 @@ dryBiCartFillRequested.ovData = FALSE; dryBiCartFillRequested.ovInitData = FALSE; dryBiCartFillRequested.override = 0; + dryBiCartDrainRequested.data = FALSE; + dryBiCartDrainRequested.ovData = FALSE; + dryBiCartDrainRequested.ovInitData = FALSE; + dryBiCartDrainRequested.override = 0; bicarbChamberFillRequested.data = FALSE; bicarbChamberFillRequested.ovData = FALSE; bicarbChamberFillRequested.ovInitData = FALSE; @@ -252,7 +263,7 @@ { DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_FILL_WATER_START_STATE; - // Close vent valves and descaling valve + // 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 ); @@ -455,8 +466,10 @@ switch ( bicarbChamberFillExecState ) { case BICARB_CHAMBER_START_STATE: + if ( TRUE == getU32OverrideValue( &bicarbChamberFillRequested ) ) { + bicarbChamberFillExecState = BICARB_CHAMBER_CHECK_LEVEL_STATE; bicarbChamberFillRequested.data = FALSE; } @@ -560,10 +573,11 @@ // Once level reached, close the valve if ( ( LEVEL_STATE_HIGH == bicarbChamberLevel ) || - ( TRUE == didTimeout( dryBiCarbSupplyStartTime, VALV_D80_MAX_OPEN_TIME_MS ) ) ) + ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ) ) ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); setValveState( D80_VALV, VALVE_STATE_CLOSED ); + state = BICARB_CHAMBER_START_STATE; } @@ -598,6 +612,13 @@ dryBiCartDrainLastCondSampleTime = dryBiCartDrainStartTime; dryBiCartDrainCondStableCount = 0; dryBiCartDrainExecState = DRY_BICART_FLUID_DRAIN_STATE; + + // 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 ); } break; @@ -763,6 +784,13 @@ setValveState( D80_VALV, VALVE_STATE_CLOSED ); setValveState( D85_VALV, VALVE_STATE_CLOSED ); + // close bypass valve + setValveState( D34_VALV, VALVE_STATE_CLOSED ); + // close DD drain + setValveState( D53_VALV, VALVE_STATE_CLOSED ); + // close iofp drain valve + setValveState( M12_VALV, VALVE_STATE_CLOSED ); + // Go idle when request cleared if ( FALSE == getU32OverrideValue( &dryBiCartDrainRequested ) ) { @@ -785,8 +813,35 @@ bicarbChamberFillRequested.data = TRUE; } + /*********************************************************************//** * @brief + * The setBicartFillRequested function sets the bicart fill request + * flag value to be True. + * @details \b Inputs: none + * @details \b Outputs: dryBiCartFillRequested + * @return none. + *************************************************************************/ +void setBicartFillRequested( void ) +{ + dryBiCartFillRequested.data = TRUE; +} + +/*********************************************************************//** + * @brief + * The setBicartDrainRequested function sets the bicart drain request + * flag value to be True. + * @details \b Inputs: none + * @details \b Outputs: dryBiCartDrainRequested + * @return none. + *************************************************************************/ +void setBicartDrainRequested( void ) +{ + dryBiCartDrainRequested.data = TRUE; +} + +/*********************************************************************//** + * @brief * The publishDryBicartData function broadcasts the dry bicart * data at defined interval. * @details \b Inputs: dryBiCartDataPublicationTimerCounter @@ -803,10 +858,12 @@ data.dryBiCartFillExecState = (U32)dryBiCartFillExecState; data.bicarbChamberFillExecState = (U32)bicarbChamberFillExecState; + data.dryBiCartDrainExecState = (U32)dryBiCartDrainExecState; data.dryBiCartFillCycleCounter = biCartFillCycleCounter; data.dryBiCartMaxFillCycleCount = getU32OverrideValue( &biCartMaxFillCycleCount ); data.dryBiCartFillRequest = getU32OverrideValue( &dryBiCartFillRequested ); data.bicarbChamberFillRequest = getU32OverrideValue( &bicarbChamberFillRequested ); + data.dryBiCartDrainRequested = getU32OverrideValue( &dryBiCartDrainRequested ); data.dryBiCartLastFillTime = lastFillDurationInMS; data.dryBiCartCurrentFillTime = currentFillDurationInMS; @@ -890,4 +947,20 @@ return result; } +/*********************************************************************//** + * @brief + * The testDryBiCartDrainRequestOverride function starts/stops the bicart + * drain request + * @details \b Inputs: tester logged in + * @details \b Outputs: bicarbChamberFillRequested + * @param message set message from Dialin which includes the bicart + * drain request start/stop. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartDrainRequestOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &dryBiCartDrainRequested, FALSE, TRUE ); + + return result; +} /**@}*/ Index: firmware/App/Modes/ModePreGenDialysate.c =================================================================== diff -u -r3417933e6edf61a914c428e2fa944b3b349272a4 -r8d2a2aec6986e58a1f6f75d4ba8864ee689fde48 --- firmware/App/Modes/ModePreGenDialysate.c (.../ModePreGenDialysate.c) (revision 3417933e6edf61a914c428e2fa944b3b349272a4) +++ firmware/App/Modes/ModePreGenDialysate.c (.../ModePreGenDialysate.c) (revision 8d2a2aec6986e58a1f6f75d4ba8864ee689fde48) @@ -17,6 +17,7 @@ #include "ConcentratePumps.h" #include "DialysatePumps.h" +#include "DryBiCart.h" #include "Heaters.h" #include "ModePreGenDialysate.h" #include "ModeGenDialysate.h" @@ -57,6 +58,7 @@ static void publishPreGenDialysateState( void ); static DD_PRE_GEN_DIALYSATE_STATE_T handlePreGenDialysateFillCompleteCheckState( void ); static DD_PRE_GEN_DIALYSATE_STATE_T handlePreGenWetSelfTestState( void ); +static DD_PRE_GEN_DIALYSATE_STATE_T handleDryBicartFillCheckState( void ); //Wet Self test static void setModePreGenWetSelfStateTransition( DD_WET_SELF_TEST_STATE_T state ); @@ -144,6 +146,10 @@ preGenDialysateState = handlePreGenWetSelfTestState(); break; + case DD_PRE_GEN_DRY_BICART_FILL_CHECK: + preGenDialysateState = handleDryBicartFillCheckState(); + break; + case DD_PRE_GEN_DIALYSATE_WAIT_FOR_GEND: // TODO : handle wait for Gen dialysate break; @@ -241,15 +247,52 @@ static DD_PRE_GEN_DIALYSATE_STATE_T handlePreGenWetSelfTestState( void ) { //TODO: Change to wet self test state later - DD_PRE_GEN_DIALYSATE_STATE_T state = DD_PRE_GEN_DIALYSATE_WAIT_FOR_GEND; + DD_PRE_GEN_DIALYSATE_STATE_T state = DD_PRE_GEN_DRY_BICART_FILL_CHECK; + if ( getTestConfigStatus( TEST_CONFIG_ENABLE_DRY_BICART_FILL ) == TRUE ) + { + setValveState( D14_VALV, VALVE_STATE_OPEN ); + setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, TRUE ); + + } + //execWetSelfTest(); return state; } + /*********************************************************************//** * @brief + * The handleDryBicartFillCheckState function executes intial dryy bicart fill request + * @details \b Inputs: state + * @details \b Outputs: none + * @return current state of PreGenDialysate mode + *************************************************************************/ +static DD_PRE_GEN_DIALYSATE_STATE_T handleDryBicartFillCheckState( void ) +{ + //TODO: Change to wet self test state later + DD_PRE_GEN_DIALYSATE_STATE_T state = DD_PRE_GEN_DRY_BICART_FILL_CHECK; + + if ( getTestConfigStatus( TEST_CONFIG_ENABLE_DRY_BICART_FILL ) == TRUE ) + { + setBicartFillRequested(); + + if ( getCurrentDryBiCartFillExecState() == DRY_BICART_FILL_COMPLETE_STATE ) + { + state = DD_PRE_GEN_DIALYSATE_WAIT_FOR_GEND; + } + } + else + { + state = DD_PRE_GEN_DIALYSATE_WAIT_FOR_GEND; + } + + return state; +} + +/*********************************************************************//** + * @brief * The setModePreGenWetSelfStateTransition function sets the actuators and variables * for the state transition in pre-gen WetSlef test mode. * @details Inputs: Valve states, Pump speed