Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -rf031f37d3f9985c1224472f2827cd180287c5621 -r22cf24fa6c521fd7c437aaf17c1b674d22537f4b --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision f031f37d3f9985c1224472f2827cd180287c5621) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 22cf24fa6c521fd7c437aaf17c1b674d22537f4b) @@ -69,12 +69,21 @@ #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) -/// Payload record structure for dry bicart fill request +// Payload record structure for dry bicart fill request typedef struct { U32 startStop; ///< Dry bicart fill request start:1 and stop: 0 } DRY_BICART_FILL_START_CMD_PAYLOAD_T; +// Enumeration of dry bicart state machine operation +typedef enum DryBicart_StateMachines +{ + DRY_BICART_INITIAL_FILL = 0, ///< Dry bicart initial fill + DRY_BICART_SUPPLY, ///< Dry bicart chamber fill + DRY_BICART_DRAIN, ///< Dry bicart drain + NUM_OF_DRY_BICART_OPERATION ///< Number of dry bicart operation +} DRY_BICART_OPERATION_T; + // ********** private data ********** static DRY_BICART_FILL_EXEC_STATE_T dryBiCartFillExecState; ///< Current state of dry bicart fill executive state machine. @@ -105,8 +114,11 @@ static U32 dryBiCartDrainCondStableCount; ///< Debounce counter for "zero" conductivity static U32 dryBiCartDrainTimePeriod; ///< Dry bicart drain time period +static U08 pendingStartRequest; ///< Dry bicart operation, fill or supply or drain request + // ********** private function prototypes ********** +static void updateDrybicartOperation(void); // Fill static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterStartState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterEndState( void ); @@ -204,22 +216,44 @@ /*********************************************************************//** * @brief * The execDryBicart function executes the set of dry bicarbonate cartridge - * and Bicarb chamber fill related state machines. - * @details \b Inputs: none + * , Bicarbonate chamber fill and bicarbonate cartridge drain related state machines one at time + * @details \b Inputs: pendingStartRequest * @details \b Outputs: none * @return none. *************************************************************************/ void execDryBicart( void ) { - // Dry bicart fill exec - execDryBicartFillMode(); + updateDrybicartOperation(); - // Fill Bicarb chamber F - execBicarbChamberFillMode(); + //state = based on request ; + U08 state = pendingStartRequest; + U32 substate; - // Dry bicart drain exec - execDryBicartDrainMode(); + switch ( state ) + { + case DRY_BICART_INITIAL_FILL: + // Dry bicart fill exec + substate = execDryBicartFillMode(); + break; + case DRY_BICART_SUPPLY: + // Fill Bicarb chamber F exec + // by default, supply state machine is selected ,ie. even if no request, supply state machine wait in BICARB_CHAMBER_START_STATE + substate = execBicarbChamberFillMode(); + break; + + case DRY_BICART_DRAIN: + // Dry bicart drain exec + substate = execDryBicartDrainMode(); + break; + + default: + // software fault + substate = 0xFFFFFFFF; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DRY_BICART_FILL_INVALID_EXEC_STATE, pendingStartRequest ); + break; + } + // Publish dry bicart data publishDryBicartData(); } @@ -397,15 +431,17 @@ * @brief * The setBicarbChamberFillRequested function sets the chmaberFillRequest * flag value to be True. - * @details \b Inputs: none + * @details \b Inputs: dryBiCartFillRequested, dryBiCartDrainRequested * @details \b Outputs: bicarbChamberFillRequested * @return TRUE if successful, FALSE if not. *************************************************************************/ BOOL setBicarbChamberFillRequested( void ) { BOOL result = FALSE; + BOOL internalFlag = dryBiCartFillRequested.data || dryBiCartDrainRequested.data; + BOOL overrideFlag = dryBiCartFillRequested.ovData || dryBiCartDrainRequested.ovData; - if ( FALSE == dryBiCartFillRequested.data && FALSE == dryBiCartDrainRequested.data ) + if ( FALSE == internalFlag && FALSE == overrideFlag ) { bicarbChamberFillRequested.data = TRUE; result = TRUE; @@ -416,17 +452,39 @@ /*********************************************************************//** * @brief + * The getBicarbChamberFillRequested function gets the chmaberFillRequest + * flag values + * @details \b Inputs: bicarbChamberFillRequested + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +BOOL getBicarbChamberFillRequested( void ) +{ + BOOL result = FALSE; + + if ( TRUE == bicarbChamberFillRequested.data || TRUE == bicarbChamberFillRequested.ovData ) + { + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief * The setBicartFillRequested function sets the bicart fill request * flag value to be True. - * @details \b Inputs: none + * @details \b Inputs: bicarbChamberFillRequested, dryBiCartDrainRequested * @details \b Outputs: dryBiCartFillRequested * @return TRUE if successful, FALSE if not. *************************************************************************/ BOOL setBicartFillRequested( void ) { BOOL result = FALSE; + BOOL internalFlag = bicarbChamberFillRequested.data || dryBiCartDrainRequested.data; + BOOL overrideFlag = bicarbChamberFillRequested.ovData || dryBiCartDrainRequested.ovData; - if( FALSE == bicarbChamberFillRequested.data && FALSE == dryBiCartDrainRequested.data ) + if( FALSE == internalFlag && FALSE == overrideFlag ) { dryBiCartFillRequested.data = TRUE; result = TRUE; @@ -437,17 +495,39 @@ /*********************************************************************//** * @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 getBicartFillRequested( void ) +{ + BOOL result = FALSE; + + if( TRUE == dryBiCartFillRequested.data || TRUE == dryBiCartFillRequested.ovData ) + { + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief * The setBicartDrainRequested function sets the bicart drain request * flag value to be True. - * @details \b Inputs: none + * @details \b Inputs: bicarbChamberFillRequested,dryBiCartFillRequested * @details \b Outputs: dryBiCartDrainRequested * @return TRUE if successful, FALSE if not. *************************************************************************/ BOOL setBicartDrainRequested( void ) { BOOL result = FALSE; + BOOL internalFlag = bicarbChamberFillRequested.data || dryBiCartFillRequested.data; + BOOL overrideFlag = bicarbChamberFillRequested.ovData || dryBiCartFillRequested.ovData; - if( FALSE == bicarbChamberFillRequested.data && FALSE == dryBiCartFillRequested.data ) + if( FALSE == internalFlag && FALSE == overrideFlag ) { dryBiCartDrainRequested.data = TRUE; result = TRUE; @@ -458,6 +538,59 @@ /*********************************************************************//** * @brief + * The getBicartDrainRequested function gets the bicart drain request + * flag value + * @details \b Inputs: dryBiCartDrainRequested + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +BOOL getBicartDrainRequested( void ) +{ + BOOL result = FALSE; + + if( TRUE == dryBiCartDrainRequested.data || TRUE == dryBiCartDrainRequested.ovData ) + { + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The updateDrybicartOperation function initiates the water fill, bicarbonate supply or bicarbonate drain + * operation + * @details \b Inputs: pendingStartRequest + * @details \b Outputs: none + * @return none + *************************************************************************/ +static void updateDrybicartOperation(void) +{ + if( TRUE == getBicarbChamberFillRequested() ) + { + // supply + pendingStartRequest = DRY_BICART_INITIAL_FILL; + } + else if ( TRUE == getBicartFillRequested() ) + { + // fill + pendingStartRequest = DRY_BICART_SUPPLY; + } + else if ( TRUE == getBicartDrainRequested() ) + { + //drain + pendingStartRequest = DRY_BICART_DRAIN; + } + else + { + // by default run supply state machine even if there is no request + // in this case state machine waits in BICARB_CHAMBER_START_STATE + pendingStartRequest = DRY_BICART_SUPPLY; + } +} + +/*********************************************************************//** + * @brief * The handleDryBicartFillWaterStartState function initiates the water fill * into dry bicarbonate cartridge. * @details \b Inputs: none