Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -r483ebbb75171ec93ab24d1f69f83a6248376266f -r7a9cfc7590be84e1c4af6a04ca92c598d49cf9de --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 483ebbb75171ec93ab24d1f69f83a6248376266f) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 7a9cfc7590be84e1c4af6a04ca92c598d49cf9de) @@ -7,8 +7,8 @@ * * @file DryBiCart.c * -* @author (last) Sameer Kalliadan Poyil -* @date (last) 13-Jul-2026 +* @author (last) Jashwant Gantyada +* @date (last) 29-Jul-2026 * * @author (original) Vinayakam Mani * @date (original) 19-Nov-2025 @@ -46,17 +46,17 @@ #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 500 ///< 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 ( 3.0F + WCDI2_PRESSURE_OFFSET_PSI ) ///< Maximum pressure reached to indicate the dry bicart fill being completed for WCID2 +#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_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_COMPLETE_SUPPLY_PRESSURE_PSI 10.0F ///< Maximum pressure allowed at bicart fill during supply process/state #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 @@ -104,6 +104,7 @@ DRY_BICART_SUPPLY, ///< Dry bicart chamber fill DRY_BICART_DRAIN, ///< Dry bicart drain DRY_BICART_DEPRESSURIZE, ///< Dry bicart depressurize + DRY_BICART_PRE_GEN_CHAMBER_FILL, NUM_OF_DRY_BICART_OPERATION ///< Number of dry bicart operation } DRY_BICART_OPERATION_T; @@ -113,6 +114,7 @@ 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 +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T bicarbChamberPreGenFillExecState; // fill static U32 dryBiCartFillStartTime; ///< Dry bicart fill start time. static U32 biCartFillCycleCounter; ///< Number of drybicart fill cycle @@ -128,6 +130,7 @@ 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 +static OVERRIDE_U32_T bicarbChamberPreGenFillRequested; ///< Start/stop bicarb chamber pre gen fill. // publish static OVERRIDE_U32_T dryBiCartDataPublishInterval; ///< Dry bicart data publish interval. static U32 dryBiCartDataPublicationTimerCounter; ///< Used to schedule drybicart data publication to CAN bus. @@ -136,14 +139,17 @@ // 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 U32 dryBiCarbSupplyVentStartTime; ///< Bicarb supply vent start time for both bicart & Chamber F. // drain static U32 dryBiCartDrainStartTime; ///< Drain overall start time (for max timeout) //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 dryBiCarbPreGenSupplyStartTime; +static U32 dryBiCartPreGenPersistenceStartTime; +static U32 drybicartPreGenPersistenceOnLowercartPressureStartTime; ///< Dry bicart Persistence on lower cart pressure start time. 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. @@ -172,13 +178,22 @@ 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 ); +// Pre Gen Supply & Vent +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenStartState( void ); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenCartridgeFillWaterStartState( void ); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenCartridgeFillWaterEndState( void ); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyStart( void ); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenPressureCheckState( void ); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyVentStartState(void); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyVentEndState(void); static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeStartState( void ); static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeVentStartState( void ); @@ -256,12 +271,14 @@ dryBiCartDataPublicationTimerCounter = 0; biCartFillCycleCounter = 0; dryBiCarbSupplyStartTime = 0; - dryBiCarbSypplyVentStartTime = 0; + dryBiCarbSupplyVentStartTime = 0; dryBiCartDrainStartTime = 0; //dryBiCartDrainLastCondSampleTime = 0; //dryBiCartDrainCondStableCount = 0; dryBiCartDrainTimePeriod = 0; dryBiCartPersistenceStartTime = 0; + dryBiCarbPreGenSupplyStartTime = 0; + dryBiCartPreGenPersistenceStartTime = 0; drybicartPersistenceOnLowercartPressureStartTime = 0; prevDryBicartState = DRY_BICART_IDLE; } @@ -321,6 +338,11 @@ execDryBicartDepressurize(); break; + case DRY_BICART_PRE_GEN_CHAMBER_FILL: + // Fill Bicarb chamber F exec + execBicarbChamberPreGenFillMode(); + break; + default: // software fault, dryBicartStartRequest = DRY_BICART_IDLE; @@ -517,6 +539,117 @@ /*********************************************************************//** * @brief + * The execBicarbChamberFillMode 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 execBicarbChamberPreGenFillMode( void ) +{ + // TODO in pregen mode call hydChamberWaterInletControl(); + // execute bicarb chamber fill state machine + switch ( bicarbChamberPreGenFillExecState ) + { + case PRE_GEN_BICARB_CHAMBER_START_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenStartState(); + break; + + case PRE_GEN_BICARB_CARTRIDGE_FILL_WATER_START_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenCartridgeFillWaterStartState(); + break; + + case PRE_GEN_BICARB_CARTRIDGE_FILL_WATER_END_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenCartridgeFillWaterEndState(); + break; + + case PRE_GEN_BICARB_CHAMBER_SUPPLY_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenSupplyStart(); + break; + + case PRE_GEN_BICARB_CHAMBER_PRESSURE_CHECK_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenPressureCheckState(); + break; + + case PRE_GEN_BICARB_SUPPLY_VENT_START_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenSupplyVentStartState(); + break; + + case PRE_GEN_BICARB_SUPPLY_VENT_END_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenSupplyVentEndState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_BICARB_CHAMBER_FILL_INVALID_EXEC_STATE, bicarbChamberFillExecState ); + break; + } + + return bicarbChamberPreGenFillExecState; +} + +/*********************************************************************//** + * @brief + * The setBicartFillRequested function sets the bicart fill request + * flag value to be True. + * @details \b Inputs: bicarbChamberFillRequested, dryBiCartDrainRequested, + * dryBiCartDepressurizeRequested + * @details \b Outputs: dryBiCartFillRequested + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +BOOL setBicartPreGenFillRequested( void ) +{ + BOOL result = FALSE; + BOOL requestStatus = getU32OverrideValue( &bicarbChamberPreGenFillRequested ) \ + || getU32OverrideValue( &dryBiCartDrainRequested ) || \ + getU32OverrideValue( &dryBiCartDepressurizeRequested ) ; + + //ensure that there is no other operation in progress before new request set to true + if ( FALSE == requestStatus ) + { + bicarbChamberPreGenFillRequested.data = TRUE; + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getBicartFillRequested function gets the bicart fill request + * flag value + * @details \b Inputs: dryBiCartFillRequested + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +BOOL getBicartPreGenFillRequested( void ) +{ + BOOL result = FALSE; + + if ( ( TRUE == getU32OverrideValue( &bicarbChamberPreGenFillRequested ) ) ) + { + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getCurrentDryBiCartFillExecState function returns the current state + * of the dry bicart fill state. + * @details \b Inputs: dryBiCartFillExecState + * @details \b Outputs: none + * @return the current state of dry bicart fill exec state. + *************************************************************************/ +BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T getCurrentDryBiCartPreGenFillExecState( void ) +{ + return bicarbChamberPreGenFillExecState; +} + +/*********************************************************************//** + * @brief * The setBicarbChamberFillRequested function sets the chmaberFillRequest * flag value to be True. * @details \b Inputs: dryBiCartFillRequested, dryBiCartDrainRequested, @@ -809,6 +942,11 @@ { dryBicartStartRequest = DRY_BICART_DEPRESSURIZE; } + else if ( TRUE == getBicartPreGenFillRequested() ) + { + // pre gen fill + dryBicartStartRequest = DRY_BICART_PRE_GEN_CHAMBER_FILL ; + } else { // idle @@ -1163,7 +1301,7 @@ { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_END_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - F32 fillCompletePressure = GET_FILL_COMPLETE_PRESSURE_PSI; + F32 fillCompletePressure = DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE_PSI; LVL_STATE_T bicarbChamberLevel = getBicarbChamberLevelStatus(); if ( FALSE == isDryBicartChamberFillWindowOpen() ) @@ -1191,8 +1329,8 @@ setValveState( D65_VALV, VALVE_STATE_CLOSED ); dryBiCartPersistenceStartTime = 0; - //state = BICARB_CHAMBER_SUPPLY_STATE; - state = BICARB_SUPPLY_VENT_END_STATE; + // Return to idle + state = completeBicarbChamberFillToIdle(); } } @@ -1204,8 +1342,8 @@ //Additional code if ( LVL_STATE_LOW == bicarbChamberLevel ) { - //Force transition to end state to allow next supply - state = BICARB_SUPPLY_VENT_END_STATE; + // Force return to idle to allow next supply + state = completeBicarbChamberFillToIdle(); } return state; @@ -1276,7 +1414,7 @@ setValveState( D85_VALV, VALVE_STATE_OPEN ); dryBiCarbSupplyStartTime = getMSTimerCount(); - dryBiCarbSypplyVentStartTime = getMSTimerCount(); + dryBiCarbSupplyVentStartTime = getMSTimerCount(); state = BICARB_SUPPLY_VENT_START_STATE; } @@ -1289,7 +1427,6 @@ dryBiCarbSupplyStartTime = getMSTimerCount(); state = BICARB_CARTRIDGE_FILL_WATER_START_STATE; - } } else if ( d66Pressure <= getDryBicartLowerCartPressure() ) @@ -1348,7 +1485,7 @@ BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_START_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) + if ( TRUE == didTimeout( dryBiCarbSupplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) { //Vent chamber F to atmosphere setValveState( D64_VALV, VALVE_STATE_OPEN ); @@ -1370,7 +1507,7 @@ state = BICARB_SUPPLY_VENT_END_STATE; } } - else if ( ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) + else if ( ( TRUE == didTimeout( dryBiCarbSupplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); dryBiCartPersistenceStartTime = 0; @@ -1390,25 +1527,39 @@ /*********************************************************************//** * @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; } @@ -1617,7 +1768,7 @@ F32 d66Pressure = getFilteredPressure( D66_PRES ); - if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) + if ( TRUE == didTimeout( dryBiCarbSupplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) { //Vent chamber F to atmosphere setValveState( D64_VALV, VALVE_STATE_OPEN ); @@ -1674,6 +1825,275 @@ /*********************************************************************//** * @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. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenStartState( void ) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_CHAMBER_START_STATE; + + dryBiCartPressureDecayStartTimeFlag = FALSE; + + if ( TRUE == getU32OverrideValue( &bicarbChamberPreGenFillRequested ) ) + { + state = PRE_GEN_BICARB_CARTRIDGE_FILL_WATER_START_STATE; + } + + return state; +} +/*********************************************************************//** + * @brief + * The handleBicarbChamberCartridgeFillWaterStartState function 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. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenCartridgeFillWaterStartState( void ) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_CARTRIDGE_FILL_WATER_END_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 ); + + // open inlet water to bicart + setValveState( D65_VALV, VALVE_STATE_OPEN ); + setValveState( D64_VALV, VALVE_STATE_OPEN ); + setValveState( D14_VALV, VALVE_STATE_OPEN ); + + dryBiCarbPreGenSupplyStartTime = getMSTimerCount(); + dryBiCartPreGenPersistenceStartTime = 0; + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberCartridgeFillWaterStartState function stop water in the dry bicart + * @details \b Inputs: D66 pressure, dryBiCartPersistenceStartTime + * @details \b Outputs: valve states + * @return the next bicarb chamber check level state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenCartridgeFillWaterEndState( void ) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_CARTRIDGE_FILL_WATER_END_STATE; + F32 d66Pressure = getFilteredPressure( D66_PRES ); + F32 fillCompletePressure = GET_FILL_COMPLETE_PRESSURE_PSI; + + // check D66 pressure greater than or equal to 17 PSI + if ( d66Pressure >= fillCompletePressure ) + { + // start the persistence timer once d66 reaches 17 PSI + if ( 0 == dryBiCartPreGenPersistenceStartTime ) + { + dryBiCartPreGenPersistenceStartTime = getMSTimerCount(); + } + + // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + if ( TRUE == didTimeout( dryBiCartPreGenPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + { + // Close water inlet valve as D66 pressure reaches 1 PSI after persistence + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + dryBiCartPreGenPersistenceStartTime = 0; + + state = PRE_GEN_BICARB_CHAMBER_SUPPLY_STATE; + } + } + else + { + dryBiCartPreGenPersistenceStartTime = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberSupplyStart function open the bicarb inlet valve (D80). + * @details \b Inputs: none + * @details \b Outputs: valve states, dryBiCarbSupplyStartTime + * @return the next bicarb chamber fill state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyStart( void ) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_CHAMBER_PRESSURE_CHECK_STATE; + + // TODO: set supply in progress to inform BC control to disable alarm + setValveState( D64_VALV, VALVE_STATE_OPEN ); + // Open the Bicarb chamber inlet valve + setValveState( D80_VALV, VALVE_STATE_OPEN ); + + // Start a timer when bicarb supply started to chamber F + dryBiCarbPreGenSupplyStartTime = getMSTimerCount(); + + // TODO: alarm + + return state; +} + +/*********************************************************************//** + * @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 + * @return the next bicarb chamber Supply Vent Start state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenPressureCheckState( void ) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_CHAMBER_PRESSURE_CHECK_STATE; + F32 d66Pressure = getFilteredPressure( D66_PRES ); + LVL_STATE_T bicarbChamberLevel = getBicarbChamberLevelStatus(); + + // 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( dryBiCarbPreGenSupplyStartTime, DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ) ) ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + + // start the timer for d66 pressure decay + if( FALSE == dryBiCartPressureDecayStartTimeFlag ) + { + dryBiCarbPreGenSupplyStartTime = getMSTimerCount(); + dryBiCartPressureDecayStartTimeFlag = TRUE; + } + // do not close the D80 valve, wait till d66 decays to 3 PSI + if ( TRUE == didTimeout( dryBiCarbPreGenSupplyStartTime, DRY_BICART_SUPPLY_COMPLETE_TIME_MS ) ) + { + if ( d66Pressure <= getDryBicartLowerCartPressure() ) + { + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_OPEN ); + + dryBiCarbPreGenSupplyStartTime = getMSTimerCount(); + dryBiCarbSupplyVentStartTime = getMSTimerCount(); + + state = PRE_GEN_BICARB_SUPPLY_VENT_START_STATE; + } + } + } + else if ( d66Pressure <= getDryBicartLowerCartPressure() ) + { + // start persistence timer + if ( 0 == drybicartPreGenPersistenceOnLowercartPressureStartTime ) + { + drybicartPreGenPersistenceOnLowercartPressureStartTime = getMSTimerCount(); + } + // 200 ms persistence on D66 pressure + if ( TRUE == didTimeout( drybicartPreGenPersistenceOnLowercartPressureStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + { + setValveState( D65_VALV, VALVE_STATE_OPEN ); + drybicartPreGenPersistenceOnLowercartPressureStartTime = 0; + } + } + // Close water inlet valve as fill is complete. + else if ( d66Pressure >= getDryBicartUpperCartPressure() ) + { + // start persistence timer + if ( 0 == dryBiCartPreGenPersistenceStartTime ) + { + dryBiCartPreGenPersistenceStartTime = getMSTimerCount(); + } + + // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + if ( TRUE == didTimeout( dryBiCartPreGenPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + dryBiCartPreGenPersistenceStartTime = 0; + } + } + else + { + dryBiCartPreGenPersistenceStartTime = 0; + drybicartPreGenPersistenceOnLowercartPressureStartTime = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberSupplyVentStartState function actuates the vent valve + * present in the Bicart assembly. + * @details \b Inputs: dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime + * @details \b Outputs: dryBiCarbSypplyVentStartTime + * @return the next bicarb chamber Supply Vent End state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyVentStartState(void) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_SUPPLY_VENT_START_STATE; + F32 d66Pressure = getFilteredPressure( D66_PRES ); + + if ( TRUE == didTimeout( dryBiCarbSupplyVentStartTime, 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 == dryBiCartPreGenPersistenceStartTime ) + { + dryBiCartPreGenPersistenceStartTime = getMSTimerCount(); + } + // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + if ( TRUE == didTimeout( dryBiCartPreGenPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + { + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + dryBiCartPreGenPersistenceStartTime = 0; + + state = PRE_GEN_BICARB_SUPPLY_VENT_END_STATE; + } + } + else if ( ( TRUE == didTimeout( dryBiCarbSupplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) + { + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + dryBiCartPreGenPersistenceStartTime = 0; + dryBiCartFillVentTimeOut = TRUE; + + state = PRE_GEN_BICARB_SUPPLY_VENT_END_STATE; + } + else + { + dryBiCartPreGenPersistenceStartTime = 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. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyVentEndState(void) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_SUPPLY_VENT_END_STATE; + + bicarbChamberPreGenFillRequested.data = FALSE; + // for this request override also cleared + bicarbChamberPreGenFillRequested.ovData = FALSE; + + dryBiCartPressureDecayStartTimeFlag = FALSE; + + state = PRE_GEN_BICARB_CHAMBER_START_STATE; + + dryBicartStartRequest = DRY_BICART_IDLE; + + return state; +} +/*********************************************************************//** + * @brief * The publishDryBicartData function broadcasts the dry bicart * data at defined interval. * @details \b Inputs: dryBiCartDataPublicationTimerCounter @@ -1700,6 +2120,7 @@ data.dryBiCartCurrentFillTime = currentFillDurationInMS; data.dryBiCartType = getU32OverrideValue( &dryBiCartType ); data.dryBiCartDrainTimePeriod = dryBiCartDrainTimePeriod; + data.dryBiCartPreGenFillState = (U32)bicarbChamberPreGenFillExecState; broadcastData( MSG_ID_DD_DRY_BICART_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( DRY_BICART_DATA_T ) );