Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -ra8a6babaca9203b780b4b44f9c15f73e3c0bf2a3 -r65292e443646d135d8fcad0a2eda19d844b06dff --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision a8a6babaca9203b780b4b44f9c15f73e3c0bf2a3) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 65292e443646d135d8fcad0a2eda19d844b06dff) @@ -15,7 +15,6 @@ * ***************************************************************************/ -//#include "AlarmMgmt.h" #include "Common.h" #include "DDDefs.h" #include "DryBiCart.h" @@ -56,12 +55,14 @@ // ********** private data ********** 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 U32 dryBiCartFillStartTime; ///< Dry bicart fill start time. static U32 biCartFillCycleCounter; ///< Number of drybicart fill cycle static OVERRIDE_U32_T biCartMaxFillCycleCount; ///< Maximum number of drybicart fill cycle ( overrideable) static U32 lastFillDurationInMS; ///< Previous time duration to fill the bicart fill. 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 bicarbChamberFillRequested; ///< Start/stop Bicarb chamber fill. static OVERRIDE_U32_T dryBiCartDataPublishInterval; ///< Dry bicart data publish interval. static U32 dryBiCartDataPublicationTimerCounter; ///< Used to schedule drybicart data publication to CAN bus. @@ -74,6 +75,9 @@ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillDurationCheckState(void); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillCompleteState(void); +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCheckLevelState( void ); +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberFillState( void ); +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberPressureCheckState( void ); static void publishDryBicartData( void ); static U32 getDryBicartFillDataPublishInterval( void ); @@ -87,6 +91,7 @@ void initDryBiCart( void ) { dryBiCartFillExecState = DRY_BICART_START_STATE; + bicarbChamberFillExecState = BICARB_CHAMBER_START_STATE; dryBiCartDataPublishInterval.data = DRY_BICART_DATA_PUBLISH_INTERVAL; dryBiCartDataPublishInterval.ovData = DRY_BICART_DATA_PUBLISH_INTERVAL; dryBiCartDataPublishInterval.ovInitData = 0; @@ -99,6 +104,10 @@ dryBiCartFillRequested.ovData = FALSE; dryBiCartFillRequested.ovInitData = FALSE; dryBiCartFillRequested.override = 0; + bicarbChamberFillRequested.data = FALSE; + bicarbChamberFillRequested.ovData = FALSE; + bicarbChamberFillRequested.ovInitData = FALSE; + bicarbChamberFillRequested.override = 0; dryBiCartFillStartTime = 0; lastFillDurationInMS = 0; currentFillDurationInMS = 0; @@ -122,6 +131,25 @@ /*********************************************************************//** * @brief + * The execDryBicart function executes the set of dry bicart related state machines. + * @details \b Inputs: none + * @details \b Outputs: none + * @return none. + *************************************************************************/ +void execDryBicart( void ) +{ + // Dry bicart fill exec + execDryBicartFillMode(); + + //Fill Bicarb chamber F + execBicarbChamberFillMode(); + + //Publish dry bicart data + publishDryBicartData(); +} + +/*********************************************************************//** + * @brief * The execDryBicartFillMode function executes the dry bicart fill (mixing water * with dry sodium bicarbonate ) state machine. * @details \b Inputs: dryBiCartFillExecState @@ -171,9 +199,6 @@ break; } - //Publish dry bicart data - publishDryBicartData(); - return dryBiCartFillExecState; } @@ -375,6 +400,137 @@ /*********************************************************************//** * @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 execBicarbChamberFillMode( void ) +{ + // execute bicarb chamber fill state machine + switch ( bicarbChamberFillExecState ) + { + case BICARB_CHAMBER_START_STATE: + if ( TRUE == getU32OverrideValue( &bicarbChamberFillRequested ) ) + { + bicarbChamberFillExecState = BICARB_CHAMBER_CHECK_LEVEL_STATE; + } + break; + + case BICARB_CHAMBER_CHECK_LEVEL_STATE: + bicarbChamberFillExecState = handleBicarbChamberCheckLevelState(); + break; + + case BICARB_CHAMBER_FILL_STATE: + bicarbChamberFillExecState = handleBicarbChamberFillState(); + break; + + case BICARB_CHAMBER_PRESSURE_CHECK_STATE: + bicarbChamberFillExecState = handleBicarbChamberPressureCheckState(); + 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 bicarbChamberFillExecState; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberCheckLevelState function checks the bicarb level(D63) + * in the chamber F and decides to open the bicarb inlet valve (D80). + * @details \b Inputs: D63 level + * @details \b Outputs: valve states + * @return the next bicarb chamber fill state. + *************************************************************************/ +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCheckLevelState( void ) +{ + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_CHECK_LEVEL_STATE; + LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); + + // Close vent valves and descaling valve + setValveState( D81_VALV, VALVE_STATE_CLOSED ); + setValveState( D64_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + + // TODO : Confirm D80 open on chamber low or end of balancing chamber switching? + if ( LEVEL_STATE_LOW == bicarbChamberLevel ) + { + // Open the Bicarb chamber inlet valve + setValveState( D80_VALV, VALVE_STATE_OPEN ); + state = BICARB_CHAMBER_FILL_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberFillState function checks the D66 pressure & + * decides to open D65 and Close the inlet valve (D80) once level reached + * @details \b Inputs: D66 pressure sensor reading + * @details \b Outputs: valve states + * @return the next bicarb chamber fill state. + *************************************************************************/ +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberFillState( void ) +{ + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_FILL_STATE; + F32 d66Pressure = getFilteredPressure( D66_PRES ); + LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); + + // Once level reached, close the valve + if ( LEVEL_STATE_HIGH == bicarbChamberLevel ) + { + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + state = BICARB_CHAMBER_START_STATE; + } + // Open water inlet valve to fill the bicart + else if ( d66Pressure <= DRY_BICART_FILL_INITIATE_PRESSURE ) + { + setValveState( D65_VALV, VALVE_STATE_OPEN ); + state = BICARB_CHAMBER_PRESSURE_CHECK_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberPressureCheckStartState function actuates the vent valve + * present in the Bicart assembly. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return the next bicarb chamber fill state. + *************************************************************************/ +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberPressureCheckState( void ) +{ + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_PRESSURE_CHECK_STATE; + F32 d66Pressure = getFilteredPressure( D66_PRES ); + LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); + + // Once level reached, close the valve + if ( LEVEL_STATE_HIGH == bicarbChamberLevel ) + { + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + } + + // Close water inlet valve as fill is complete. + if ( d66Pressure >= DRY_BICART_FILL_COMPLETE_PRESSURE ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + state = BICARB_CHAMBER_START_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief * The publishDryBicartData function broadcasts the dry bicart * data at defined interval. * @details \b Inputs: dryBiCartDataPublicationTimerCounter @@ -390,6 +546,7 @@ DRY_BICART_DATA_T data; data.dryBiCartFillExecState = (U32)dryBiCartFillExecState; + data.bicarbChamberFillExecState = (U32)bicarbChamberFillExecState; data.dryBiCartFillCycleCounter = biCartFillCycleCounter; data.dryBiCartMaxFillCycleCount = getU32OverrideValue( &biCartMaxFillCycleCount ); data.dryBiCartFillRequest = getU32OverrideValue( &dryBiCartFillRequested ); @@ -459,4 +616,21 @@ return result; } +/*********************************************************************//** + * @brief + * The testDryBiCartFillRequestOverride function starts/stops the bicarb + * chamber F fill. + * @details \b Inputs: tester logged in + * @details \b Outputs: bicarbChamberFillRequested + * @param message set message from Dialin which includes the bicarb chamber + * fill start/stop. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testBiCarbChamberFillRequestOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &bicarbChamberFillRequested, FALSE, TRUE ); + + return result; +} + /**@}*/