Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r3f8d037ec63961e553b5ec67553332db829c9dac -rcaa15db89a49c98671f0a87dc2242d0fc7f683b7 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 3f8d037ec63961e553b5ec67553332db829c9dac) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision caa15db89a49c98671f0a87dc2242d0fc7f683b7) @@ -37,7 +37,10 @@ */ // ********** private definitions ********** + #define BAL_CHAMBER_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. +#define BAL_CHAMBER_FILL_PRES_DROP_MS ( 200 / TASK_GENERAL_INTERVAL ) ///< Time (ms/tasktime) to confirm the balancing chamber filling started and corrosponding valves opened. +#define BAL_CHAMBER_FILL_COMPLETE_MS ( 300 / TASK_GENERAL_INTERVAL ) ///< Time (ms/tasktime) to confirm the balancing chamber fill completed and pressure is within range /// Payload record structure for balancing chamber switch only request typedef struct @@ -55,21 +58,28 @@ static U32 currentBalChamberSwitchingCounter; ///< Counter (in task interval) to monitor the timing spent during balancing chamber fill/drain operation. static BOOL isBalChamberFillInProgress; ///< Flag indicating balancing chamber fill/drain is in progress. static BOOL isPressureStalbilizedDuringFill; ///< Flag indicating that the pressure is stablized due to fill complete. -static BOOL isPressureDroppedDuringFill; ///< Flag indicating that the pressure is dropped due to BC fill (state 1 or state 2) in progress condition. static BAL_CHAMBER_SW_STATE_T balChamberSWState; ///< Current balancing chamber switching state ( state 1 or state 2). static U32 balChamberDataPublicationTimerCounter; ///< Used to schedule balancing chamber data publication to CAN bus. +static U32 balChamberFillPressureDropCounter; ///< Counter to check balancing chamber valves opened and there by pressure drop is seen. static OVERRIDE_U32_T balChamberDataPublishInterval; ///< Balancing chamber data publish interval. static BOOL balanceChamberSwitchingOnly; ///< Balancing chamber switching without any pressure check and dosing delivery. +static BOOL isPressureDroppedDuringFill; ///< Flag indicating that the pressure is dropped due to BC fill (state 1 or state 2) in progress condition. +static BOOL isFirstCycleBCSwitchingCompleted; ///< Flag indicating that first time balancing chamber swithcing is done to trigger alarms from next cycle onwards. +static U32 balChamberFillCompleteStablePressureCounter; ///< Counter to check balancing chamber fill complete and stable pressure is met. static OVERRIDE_F32_T acidDoseVolume; ///< Acid concentrate volume in ml ( overrideable). static OVERRIDE_F32_T bicarbDoseVolume; ///< Bicarb concentrate volume in ml ( overrideable). static F32 lastTdDialysateFlowrate; ///< Previous TD dialysate flow rate +static F32 freshDialPressure; ///< Fresh side dialysate pressure +static F32 spentDialPressure; ///< Spent side dialysate pressure // ********** private function prototypes ********** static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillStart( void ); static BAL_CHAMBER_EXEC_STATE_T handleBalChamberConcentrateControl(void); +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1ValvesClose( void ); static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd(void); static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillStart( void ); +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2ValvesClose( void ); static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd(void); static void publishBalChamberData( void ); static U32 getBalChamberDataPublishInterval( void ); @@ -109,6 +119,12 @@ isPressureStalbilizedDuringFill = FALSE; lastTdDialysateFlowrate = 0.0F; balChamberDataPublicationTimerCounter = 0; + balChamberFillPressureDropCounter = 0; + balChamberFillCompleteStablePressureCounter = 0; + isFirstCycleBCSwitchingCompleted = FALSE; + isPressureDroppedDuringFill = FALSE; + freshDialPressure = 0.0F; + spentDialPressure = 0.0F; } /*********************************************************************//** @@ -151,6 +167,9 @@ //Update last td dialysate flow rate lastTdDialysateFlowrate = tdDialysateFlowrate; + //Reset the BC switching flag for new Qd. + isFirstCycleBCSwitchingCompleted = FALSE; + //Update heater control on dialysate flow change signalHeaterControlOnQDUpdate( D5_HEAT ); @@ -188,6 +207,10 @@ balChamberExecState = handleBalChamberConcentrateControl(); break; + case BAL_CHAMBER_STATE1_VALVES_CLOSE: + balChamberExecState = handleBalChamberState1ValvesClose(); + break; + case BAL_CHAMBER_STATE1_FILL_END: balChamberExecState = handleBalChamberState1FillEnd(); break; @@ -200,6 +223,10 @@ balChamberExecState = handleBalChamberConcentrateControl(); break; + case BAL_CHAMBER_STATE2_VALVES_CLOSE: + balChamberExecState = handleBalChamberState2ValvesClose(); + break; + case BAL_CHAMBER_STATE2_FILL_END: balChamberExecState = handleBalChamberState2FillEnd(); break; @@ -385,16 +412,15 @@ isPressureDroppedDuringFill = FALSE; balChamberSWState = BAL_CHAMBER_SW_STATE1; - F32 freshDialPressure = getFilteredPressure( D18_PRES ); - F32 spentDialPressure = getFilteredPressure( D51_PRES ); F32 acidVolume = getF32OverrideValue( &acidDoseVolume ); F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); + // Check fresh and spent dialysate pressure in range or BC switch only flag set - //TODO : comment the pressure check - if ( 1 ) - //if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && - // ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) || - // ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) || + ( TRUE == getBalChamberSwitchingOnlyStatus() ) || ( TRUE == getTestConfigStatus( TEST_CONFIG_DISABLE_BC_PRESSURE_ALARMS ) ) ) { //Valve control for state 1 fill valveControlForBCState1FillStart(); @@ -416,10 +442,11 @@ } else { -#ifdef ENABLE_ALARM_2 - //Alarm when pressure is not in range - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif + if ( getTestConfigStatus( TEST_CONFIG_DISABLE_BC_PRESSURE_ALARMS ) != TRUE ) + { + //Alarm when pressure is not in range + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } } return state; @@ -436,102 +463,140 @@ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberConcentrateControl( void ) { BAL_CHAMBER_EXEC_STATE_T state; + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); - F32 freshDialPressure = getFilteredPressure( D18_PRES ); - F32 spentDialPressure = getFilteredPressure( D51_PRES ); + if ( BAL_CHAMBER_SW_STATE1 == balChamberSWState ) + { + state = BAL_CHAMBER_STATE1_BICARB_ACID_DOSING_CNTRL; + } + else + { + state = BAL_CHAMBER_STATE2_BICARB_ACID_DOSING_CNTRL; + } // Pressure drop check during fill process helps to find if there is any issue with valves opening - if ( ( freshDialPressure <= BC_FILL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= BC_FILL_PRESSURE_MIN_PSIG ) ) + if ( ( freshDialPressure <= BC_FRESH_FILL_PRESSURE_PSIG ) && ( spentDialPressure <= BC_SPENT_FILL_PRESSURE_PSIG ) ) { - isPressureDroppedDuringFill = TRUE; + if ( ++balChamberFillPressureDropCounter >= BAL_CHAMBER_FILL_PRES_DROP_MS ) + { + isPressureDroppedDuringFill = TRUE; + } } // On dosing completion, transition to next state based on the current switching state - // TODO : Need an updated FPGA to perform this check. For now commenting this check. -// if ( ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && -// ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) || -// ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) -// { + if ( ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && + ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) || + ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) + { if ( BAL_CHAMBER_SW_STATE1 == balChamberSWState ) { - state = BAL_CHAMBER_STATE1_FILL_END; + state = BAL_CHAMBER_STATE1_VALVES_CLOSE; } else { - state = BAL_CHAMBER_STATE2_FILL_END; + state = BAL_CHAMBER_STATE2_VALVES_CLOSE; } -// } + } return state; } /*********************************************************************//** * @brief - * The handleBalChamberState1FillEnd function check for the balancing chamber + * The handleBalChamberState1ValvesClose function check for the balancing chamber * fill complete and close the currently opened valves. - * @details \b Inputs: balChamberSWState, spent and fresh dialysate pressure + * @details \b Inputs: currentBalChamberSwitchingCounter, spent and fresh dialysate pressure * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress - * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE - * when pressure drop is not in range during balacing chamber fill in progress. - * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE - * when pressure is not in range during balacing chamber fill complete. * @return next balancing chamber state. *************************************************************************/ -static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd( void ) +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1ValvesClose( void ) { - BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_FILL_END; + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_VALVES_CLOSE; - F32 freshDialPressure = getFilteredPressure( D18_PRES ); - F32 spentDialPressure = getFilteredPressure( D51_PRES ); + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); // Check fresh and spent dialysate pressure back in range to indicate fill complete. - //TODO : comment the pressure check - //if ( 1 ) - if ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) - //if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && - // ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) + if ( getTestConfigStatus( TEST_CONFIG_DISABLE_BC_PRESSURE_ALARMS ) != TRUE ) { - // stabilized pressure indicating fill is complete - isPressureStalbilizedDuringFill = TRUE; - isBalChamberFillInProgress = FALSE; - // isPressureStalbilizedDuringFill = FALSE; + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) + { + if ( ++balChamberFillCompleteStablePressureCounter >= BAL_CHAMBER_FILL_COMPLETE_MS ) + { + // stabilized pressure indicating fill is complete + isPressureStalbilizedDuringFill = TRUE; + isBalChamberFillInProgress = FALSE; + } + } } + else + { + isPressureStalbilizedDuringFill = FALSE; + } // Switching time met or pressure in range, close valves - if ( ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) || + if ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) || ( TRUE == isPressureStalbilizedDuringFill ) ) { // close the state 1 opened valves valveControlForBCState1FillEnd(); + + //Transition to next state + state = BAL_CHAMBER_STATE1_FILL_END; } + return state; +} + +/*********************************************************************//** + * @brief + * The handleBalChamberState1FillEnd function check for the balancing chamber + * switching period and tranistion to next state switching. + * @details \b Inputs: currentBalChamberSwitchingCounter, balChamberSwitchingPeriod + * @details \b Outputs: balChamberFillPressureDropCounter,balChamberFillCompleteStablePressureCounter + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE + * when pressure drop is not in range during balacing chamber fill in progress. + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber fill complete. + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_FILL_END; + // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { + balChamberFillPressureDropCounter = 0; + balChamberFillCompleteStablePressureCounter = 0; + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { - if ( TRUE != isPressureDroppedDuringFill ) + if ( getTestConfigStatus( TEST_CONFIG_DISABLE_BC_PRESSURE_ALARMS ) != TRUE ) { -#ifdef ENABLE_ALARM_2 - // When fill initiated, pressure is not dropped to the expected range, possible valve failures. - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif + if ( ( TRUE != isPressureDroppedDuringFill ) && ( TRUE == isFirstCycleBCSwitchingCompleted ) ) + { + // When fill initiated, pressure is not dropped to the expected range, possible valve failures. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } + else if ( TRUE != isPressureStalbilizedDuringFill ) + { + // Alarm when switching time expired, but still pressure not in range which indicates fill is not yet completed. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } + else + { + // Move to next state when pressure is in range. + state = BAL_CHAMBER_STATE2_FILL_START; + } } - else if ( TRUE != isPressureStalbilizedDuringFill ) - { -#ifdef ENABLE_ALARM_2 - // Alarm when switching time expired, but still pressure not in range which indicates fill is not yet completed. - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif - } else { - // Move to next state when pressure is in range. + // Allow to proceed next state even though pressure is not stabilized. state = BAL_CHAMBER_STATE2_FILL_START; } - - //TODO : Temporarily allow to proceed next state even though pressure is not stabilized. - state = BAL_CHAMBER_STATE2_FILL_START; } else { @@ -561,17 +626,15 @@ isPressureDroppedDuringFill = FALSE; balChamberSWState = BAL_CHAMBER_SW_STATE2; - F32 freshDialPressure = getFilteredPressure( D18_PRES ); - F32 spentDialPressure = getFilteredPressure( D51_PRES ); F32 acidVolume = getF32OverrideValue( &acidDoseVolume ); F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); // Check fresh and spent dialysate pressure in range - //TODO : comment the pressure check - if ( 1 ) - //if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && - // ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) || - // ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) || + ( TRUE == getBalChamberSwitchingOnlyStatus() ) || ( TRUE == getTestConfigStatus( TEST_CONFIG_DISABLE_BC_PRESSURE_ALARMS ) ) ) { // Valve control for state 2 fill valveControlForBCState2FillStart(); @@ -593,82 +656,117 @@ } else { -#ifdef ENABLE_ALARM_2 - //Alarm when pressure is not in range - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif + if ( getTestConfigStatus( TEST_CONFIG_DISABLE_BC_PRESSURE_ALARMS ) != TRUE ) + { + //Alarm when pressure is not in range + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } } return state; } /*********************************************************************//** * @brief - * The handleBalChamberState2FillEnd function check for the balancing chamber + * The handleBalChamberState2ValvesClose function check for the balancing chamber * fill complete and close the currently opened valves. - * @details \b Inputs: balChamberSWState, spent and fresh dialysate pressure + * @details \b Inputs: currentBalChamberSwitchingCounter, spent and fresh dialysate pressure * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress - * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE - * when pressure is not in range during balacing chamber state 2 fill in progress. - * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE - * when pressure is not in range during balacing chamber state 2 fill complete. * @return next balancing chamber state. *************************************************************************/ -static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd( void ) +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2ValvesClose( void ) { - BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE2_FILL_END; + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE2_VALVES_CLOSE; - F32 freshDialPressure = getFilteredPressure( D18_PRES ); - F32 spentDialPressure = getFilteredPressure( D51_PRES ); + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); // Check fresh and spent dialysate pressure back in range to indicate fill complete. - //TODO : comment the pressure check - //if ( 1 ) - if ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) - //if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && - // ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) + if ( getTestConfigStatus( TEST_CONFIG_DISABLE_BC_PRESSURE_ALARMS ) != TRUE ) { - // stabilized pressure indicating fill is complete - isPressureStalbilizedDuringFill = TRUE; - isBalChamberFillInProgress = FALSE; - //isPressureStalbilizedDuringFill = FALSE; + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) + { + if ( ++balChamberFillCompleteStablePressureCounter >= BAL_CHAMBER_FILL_COMPLETE_MS ) + { + // stabilized pressure indicating fill is complete + isPressureStalbilizedDuringFill = TRUE; + isBalChamberFillInProgress = FALSE; + } + } } + else + { + isPressureStalbilizedDuringFill = FALSE; + } // Check switching cycle time or pressure check for valve closure - if ( ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) || + if ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) || ( TRUE == isPressureStalbilizedDuringFill ) ) { // close the valves valveControlForBCState2FillEnd(); + + //Transition to next state + state = BAL_CHAMBER_STATE2_FILL_END; } + return state; +} + +/*********************************************************************//** + * @brief + * The handleBalChamberState2FillEnd function check for the balancing chamber + * switching period complete and transition to next state. + * @details \b Inputs: currentBalChamberSwitchingCounter, balChamberSwitchingPeriod + * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill in progress. + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill complete. + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE2_FILL_END; + // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { + balChamberFillPressureDropCounter = 0; + balChamberFillCompleteStablePressureCounter = 0; + // Pressure alarm check if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { - if ( TRUE != isPressureDroppedDuringFill ) + if ( getTestConfigStatus( TEST_CONFIG_DISABLE_BC_PRESSURE_ALARMS ) != TRUE ) { -#ifdef ENABLE_ALARM_2 - // When fill initiated, pressure is not dropped to the expected range, possible valve failures. - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif + if ( ( TRUE != isPressureDroppedDuringFill ) && ( TRUE == isFirstCycleBCSwitchingCompleted ) ) + { + // When fill initiated, pressure is not dropped to the expected range, possible valve failures. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } + else if ( TRUE != isPressureStalbilizedDuringFill ) + { + // Alarm when switching time expired, but still pressure not in range which indicates fill is not completed. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } + else + { + // Move to next state when pressure is in range. + state = BAL_CHAMBER_STATE1_FILL_START; + + // Trigger pressure drop alarm after first cycle of balancing chamber switching complete + if ( FALSE == isFirstCycleBCSwitchingCompleted ) + { + isFirstCycleBCSwitchingCompleted = TRUE; + } + } } - else if ( TRUE != isPressureStalbilizedDuringFill ) - { -#ifdef ENABLE_ALARM_2 - // Alarm when switching time expired, but still pressure not in range which indicates fill is not completed. - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif - } else { - // Move to next state when pressure is in range. + // Allow to proceed next state even though pressure is not stabilized. state = BAL_CHAMBER_STATE1_FILL_START; } - - //TODO : Temporarily allow to proceed next state even though pressure is not stabilized. - state = BAL_CHAMBER_STATE1_FILL_START; } else { @@ -754,6 +852,19 @@ /*********************************************************************//** * @brief + * The getBalChamberSwitchingPeriod function gets the balancing chamber + * switching period. + * @details \b Inputs: balChamberSwitchingPeriod + * @details \b Outputs: none + * @return balancing chamber switching period + *************************************************************************/ +U32 getBalChamberSwitchingPeriod( void ) +{ + return balChamberSwitchingPeriod; +} + +/*********************************************************************//** + * @brief * The getBalChamberDataPublishInterval function gets the balancing chamber * data publish interval. * @details \b Inputs: balChamberDataPublishInterval