Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r89c8709e3b27648926fbb20f25c9a67cbeb99adc -rf7f6305f054732569330f6001568777857e20442 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 89c8709e3b27648926fbb20f25c9a67cbeb99adc) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision f7f6305f054732569330f6001568777857e20442) @@ -74,10 +74,10 @@ static F32 freshDialPressure; ///< Fresh side dialysate pressure static F32 spentDialPressure; ///< Spent side dialysate pressure -#ifdef __DRY_BICARB__ +//TODO: remove later static U32 bicarbChamberPeriodicFillCounter; ///< Counter for checking the timeout for drybicart chamber fill request. -#endif + // ********** private function prototypes ********** static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillStart( void ); @@ -131,9 +131,11 @@ isPressureDroppedDuringFill = FALSE; freshDialPressure = 0.0F; spentDialPressure = 0.0F; -#ifdef __DRY_BICARB__ - bicarbChamberPeriodicFillCounter = 0; -#endif + + if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DRY_BICARB ) == TRUE ) + { + bicarbChamberPeriodicFillCounter = 0; + } } /*********************************************************************//** @@ -201,21 +203,22 @@ // Increment counter indicating fill is in progress. currentBalChamberSwitchingCounter += 1; -#ifdef __DRY_BICARB__ - //Increment counter for dry bicarb chamber fill - bicarbChamberPeriodicFillCounter += 1; - // Fill bicarb chamber once every 60secs. - if ( bicarbChamberPeriodicFillCounter >= BICARB_CHAMBER_PERIODIC_FILL_TIME ) + if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DRY_BICARB ) == TRUE ) { - if ( FALSE == setBicarbChamberFillRequested() ) + //Increment counter for dry bicarb chamber fill + bicarbChamberPeriodicFillCounter += 1; + // Fill bicarb chamber once every 60secs. + if ( bicarbChamberPeriodicFillCounter >= BICARB_CHAMBER_PERIODIC_FILL_TIME ) { - // TODO - //drybicart state machines are combined and so this is not an issue in future - //set alarm ? + if ( FALSE == setBicarbChamberFillRequested() ) + { + // TODO + //drybicart state machines are combined and so this is not an issue in future + //set alarm ? + } + bicarbChamberPeriodicFillCounter = 0; } - bicarbChamberPeriodicFillCounter = 0; } -#endif switch ( balChamberExecState ) { @@ -526,10 +529,13 @@ freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); + BOOL isFreshDialysatePressureInRange = ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ); + BOOL isSpentDialysatePressureInRange = ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ); + BOOL isBalChamberSwitchOnly = ( TRUE == getBalChamberSwitchingOnlyStatus() ); + BOOL isDisableBCPressureAlarms = ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_DISABLE_BC_PRESSURE_ALARMS ) ); + // Check fresh and spent dialysate pressure in range or BC switch only flag set - 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_DD_DISABLE_BC_PRESSURE_ALARMS ) ) ) + if ( ( isFreshDialysatePressureInRange && isSpentDialysatePressureInRange ) || isBalChamberSwitchOnly || isDisableBCPressureAlarms ) { //Valve control for state 1 fill valveControlForBCState1FillStart(); @@ -622,15 +628,16 @@ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1ValvesClose( void ) { BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_VALVES_CLOSE; + BOOL isFreshDialysatePressureInRange = ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ); + BOOL isSpentDialysatePressureInRange = ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ); freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); // Check fresh and spent dialysate pressure back in range to indicate fill complete. if ( getTestConfigStatus( TEST_CONFIG_DD_DISABLE_BC_PRESSURE_ALARMS ) != TRUE ) { - 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 ( isFreshDialysatePressureInRange && isSpentDialysatePressureInRange ) { if ( ++balChamberFillCompleteStablePressureCounter >= BAL_CHAMBER_FILL_COMPLETE_MS ) { @@ -740,10 +747,13 @@ freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); + BOOL isFreshDialysatePressureInRange = ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ); + BOOL isSpentDialysatePressureInRange = ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ); + BOOL isBalChamberSwitchOnly = ( TRUE == getBalChamberSwitchingOnlyStatus() ); + BOOL isDisableBCPressureAlarms = ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_DISABLE_BC_PRESSURE_ALARMS ) ); + // Check fresh and spent dialysate pressure in range - 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_DD_DISABLE_BC_PRESSURE_ALARMS ) ) ) + if ( ( isFreshDialysatePressureInRange && isSpentDialysatePressureInRange ) || isBalChamberSwitchOnly || isDisableBCPressureAlarms ) { // Valve control for state 2 fill valveControlForBCState2FillStart(); @@ -785,15 +795,16 @@ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2ValvesClose( void ) { BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE2_VALVES_CLOSE; + BOOL isFreshDialysatePressureInRange = ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ); + BOOL isSpentDialysatePressureInRange = ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ); freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); // Check fresh and spent dialysate pressure back in range to indicate fill complete. if ( getTestConfigStatus( TEST_CONFIG_DD_DISABLE_BC_PRESSURE_ALARMS ) != TRUE ) { - 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 ( isFreshDialysatePressureInRange && isSpentDialysatePressureInRange ) { if ( ++balChamberFillCompleteStablePressureCounter >= BAL_CHAMBER_FILL_COMPLETE_MS ) { Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -r22cf24fa6c521fd7c437aaf17c1b674d22537f4b -rf7f6305f054732569330f6001568777857e20442 --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 22cf24fa6c521fd7c437aaf17c1b674d22537f4b) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision f7f6305f054732569330f6001568777857e20442) @@ -69,16 +69,17 @@ #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 +/// Enumeration of dry bicart top level state machine operation typedef enum DryBicart_StateMachines { - DRY_BICART_INITIAL_FILL = 0, ///< Dry bicart initial fill + DRY_BICART_IDLE = 0, ///< Dry bicart Idle + DRY_BICART_INITIAL_FILL, ///< 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 @@ -114,19 +115,21 @@ 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 +static DRY_BICART_OPERATION_T dryBicartStartRequest; ///< Dry bicart operation, fill or supply or drain request // ********** private function prototypes ********** static void updateDrybicartOperation(void); // Fill +static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartStartState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterStartState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterEndState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasStartState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasEndState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillDurationCheckState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillCompleteState( void ); // Supply & Vent +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberStartState( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterStartState( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterEndState( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCheckLevelState( void ); @@ -156,6 +159,7 @@ dryBiCartFillExecState = DRY_BICART_START_STATE; bicarbChamberFillExecState = BICARB_CHAMBER_START_STATE; dryBiCartDrainExecState = DRY_BICART_DRAIN_START_STATE; + dryBicartStartRequest = DRY_BICART_IDLE; dryBiCartDataPublishInterval.data = DRY_BICART_DATA_PUBLISH_INTERVAL; dryBiCartDataPublishInterval.ovData = DRY_BICART_DATA_PUBLISH_INTERVAL; @@ -215,42 +219,47 @@ /*********************************************************************//** * @brief - * The execDryBicart function executes the set of dry bicarbonate cartridge - * , Bicarbonate chamber fill and bicarbonate cartridge drain related state machines one at time - * @details \b Inputs: pendingStartRequest + * The execDryBicart function executes the set of dry bicarbonate cartridge fill, + * bicarbonate chamber fill and bicarbonate cartridge drain related state machines one at time + * @details \b Inputs: dryBicartStartRequest * @details \b Outputs: none * @return none. *************************************************************************/ void execDryBicart( void ) { updateDrybicartOperation(); - //state = based on request ; - U08 state = pendingStartRequest; - U32 substate; + // top level state machine selection + DRY_BICART_OPERATION_T dryBicartState = dryBicartStartRequest; + U32 dryBicartSubstate; - switch ( state ) + switch ( dryBicartState ) { + case DRY_BICART_IDLE: + // run as idle state + dryBicartSubstate = 0x0; + break; + case DRY_BICART_INITIAL_FILL: // Dry bicart fill exec - substate = execDryBicartFillMode(); + dryBicartSubstate = 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(); + dryBicartSubstate = execBicarbChamberFillMode(); break; case DRY_BICART_DRAIN: // Dry bicart drain exec - substate = execDryBicartDrainMode(); + dryBicartSubstate = 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 ); + // software fault, + dryBicartSubstate = 0x0; + dryBicartStartRequest = DRY_BICART_IDLE; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DRY_BICART_FILL_INVALID_EXEC_STATE, dryBicartStartRequest ); break; } @@ -274,18 +283,7 @@ switch ( dryBiCartFillExecState ) { case DRY_BICART_START_STATE: - if ( TRUE == getU32OverrideValue( &dryBiCartFillRequested ) ) - { - // fill drybicart only if iofp state is in FP_MODE_GENP - //if(FP_MODE_GENP == getCurrentFPOperationMode()) - { - // TODO: pre gen should start the D12 pump and D14 valve - setValveState( D14_VALV, VALVE_STATE_OPEN ); - setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, TRUE ); - - dryBiCartFillExecState = DRY_BICART_FILL_WATER_START_STATE; - } - } + dryBiCartFillExecState = handleDryBicartStartState(); break; case DRY_BICART_FILL_WATER_START_STATE: @@ -336,10 +334,7 @@ switch ( bicarbChamberFillExecState ) { case BICARB_CHAMBER_START_STATE: - if ( TRUE == getU32OverrideValue( &bicarbChamberFillRequested ) ) - { - bicarbChamberFillExecState = BICARB_CARTRIDGE_FILL_WATER_START_STATE; - } + bicarbChamberFillExecState = handleBicarbChamberStartState(); break; case BICARB_CARTRIDGE_FILL_WATER_START_STATE: @@ -393,18 +388,7 @@ switch ( dryBiCartDrainExecState ) { case DRY_BICART_DRAIN_START_STATE: - if ( TRUE == getU32OverrideValue( &dryBiCartDrainRequested ) ) - { - if ( TRUE == getU32OverrideValue( &dryBiCartType ) ) - { - dryBiCartDrainTimePeriod = LARGE_DRY_BICART_MAX_DRAIN_TIME_MS; - } - else - { - dryBiCartDrainTimePeriod = SMALL_DRY_BICART_MAX_DRAIN_TIME_MS; - } - dryBiCartDrainExecState = handleDryBicartDrainStartState(); - } + dryBiCartDrainExecState = handleDryBicartDrainStartState(); break; case DRY_BICART_FLUID_DRAIN_STATE: @@ -438,10 +422,10 @@ BOOL setBicarbChamberFillRequested( void ) { BOOL result = FALSE; - BOOL internalFlag = dryBiCartFillRequested.data || dryBiCartDrainRequested.data; - BOOL overrideFlag = dryBiCartFillRequested.ovData || dryBiCartDrainRequested.ovData; + BOOL requestStatus = getU32OverrideValue( &dryBiCartFillRequested ) || getU32OverrideValue( &dryBiCartDrainRequested ); - if ( FALSE == internalFlag && FALSE == overrideFlag ) + // ensure that there is no other operation in progress before new request set to true + if ( FALSE == requestStatus ) { bicarbChamberFillRequested.data = TRUE; result = TRUE; @@ -462,7 +446,7 @@ { BOOL result = FALSE; - if ( TRUE == bicarbChamberFillRequested.data || TRUE == bicarbChamberFillRequested.ovData ) + if ( (TRUE == getU32OverrideValue( &bicarbChamberFillRequested ) ) ) { result = TRUE; } @@ -481,10 +465,10 @@ BOOL setBicartFillRequested( void ) { BOOL result = FALSE; - BOOL internalFlag = bicarbChamberFillRequested.data || dryBiCartDrainRequested.data; - BOOL overrideFlag = bicarbChamberFillRequested.ovData || dryBiCartDrainRequested.ovData; + BOOL requestStatus = getU32OverrideValue( &bicarbChamberFillRequested ) || getU32OverrideValue( &dryBiCartDrainRequested ); - if( FALSE == internalFlag && FALSE == overrideFlag ) + //ensure that there is no other operation in progress before new request set to true + if ( FALSE == requestStatus ) { dryBiCartFillRequested.data = TRUE; result = TRUE; @@ -505,7 +489,7 @@ { BOOL result = FALSE; - if( TRUE == dryBiCartFillRequested.data || TRUE == dryBiCartFillRequested.ovData ) + if ( ( TRUE == getU32OverrideValue( &dryBiCartFillRequested ) ) ) { result = TRUE; } @@ -524,10 +508,10 @@ BOOL setBicartDrainRequested( void ) { BOOL result = FALSE; - BOOL internalFlag = bicarbChamberFillRequested.data || dryBiCartFillRequested.data; - BOOL overrideFlag = bicarbChamberFillRequested.ovData || dryBiCartFillRequested.ovData; + BOOL requestStatus = getU32OverrideValue( &bicarbChamberFillRequested ) || getU32OverrideValue( &dryBiCartFillRequested ); - if( FALSE == internalFlag && FALSE == overrideFlag ) + //ensure that there is no other operation in progress before new request set to true + if ( FALSE == requestStatus ) { dryBiCartDrainRequested.data = TRUE; result = TRUE; @@ -548,7 +532,7 @@ { BOOL result = FALSE; - if( TRUE == dryBiCartDrainRequested.data || TRUE == dryBiCartDrainRequested.ovData ) + if ( ( TRUE == getU32OverrideValue( &dryBiCartDrainRequested ) ) ) { result = TRUE; } @@ -558,39 +542,78 @@ /*********************************************************************//** * @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. + *************************************************************************/ +DRY_BICART_FILL_EXEC_STATE_T getCurrentDryBiCartFillExecState( void ) +{ + return dryBiCartFillExecState; +} + +/*********************************************************************//** + * @brief * The updateDrybicartOperation function initiates the water fill, bicarbonate supply or bicarbonate drain * operation - * @details \b Inputs: pendingStartRequest - * @details \b Outputs: none + * @details \b Inputs: none + * @details \b Outputs: dryBicartStartRequest * @return none *************************************************************************/ static void updateDrybicartOperation(void) { - if( TRUE == getBicarbChamberFillRequested() ) + if ( TRUE == getBicarbChamberFillRequested() ) { // supply - pendingStartRequest = DRY_BICART_INITIAL_FILL; + dryBicartStartRequest = DRY_BICART_SUPPLY ; } else if ( TRUE == getBicartFillRequested() ) { // fill - pendingStartRequest = DRY_BICART_SUPPLY; + dryBicartStartRequest = DRY_BICART_INITIAL_FILL; } else if ( TRUE == getBicartDrainRequested() ) { //drain - pendingStartRequest = DRY_BICART_DRAIN; + dryBicartStartRequest = 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; + // idle + dryBicartStartRequest = DRY_BICART_IDLE; } } /*********************************************************************//** * @brief + * The handleDryBicartStartState function wait for a fill request + * @details \b Inputs: dryBiCartFillRequested + * @details \b Outputs: valve states + * @return the next drybicart fill water start state. + *************************************************************************/ +static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartStartState( void ) +{ + DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_START_STATE; + + if ( TRUE == getU32OverrideValue( &dryBiCartFillRequested ) ) + { + // fill drybicart only if iofp state is in FP_MODE_GENP + //if(FP_MODE_GENP == getCurrentFPOperationMode()) + { + // TODO: pre gen should start the D12 pump and D14 valve + setValveState( D14_VALV, VALVE_STATE_OPEN ); + setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, TRUE ); + + state = DRY_BICART_FILL_WATER_START_STATE; + } + } + + return state; +} + +/*********************************************************************//** + * @brief * The handleDryBicartFillWaterStartState function initiates the water fill * into dry bicarbonate cartridge. * @details \b Inputs: none @@ -787,19 +810,6 @@ /*********************************************************************//** * @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. - *************************************************************************/ -DRY_BICART_FILL_EXEC_STATE_T getCurrentDryBiCartFillExecState( void ) -{ - return dryBiCartFillExecState; -} - -/*********************************************************************//** - * @brief * The getDryBicartFillDataPublishInterval function gets the dry bicart * fill data publish interval. * @details \b Inputs: dryBiCartDataPublishInterval @@ -815,6 +825,24 @@ /*********************************************************************//** * @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_FILL_EXEC_STATE_T handleBicarbChamberStartState( void ) +{ + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_START_STATE; + + if ( TRUE == getU32OverrideValue( &bicarbChamberFillRequested ) ) + { + state = 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 @@ -1014,42 +1042,55 @@ * @brief * The handleDryBicartDrainStartState function set the one time actuation * for bicarb drain request. - * @details \b Inputs: none - * @details \b Outputs: valve states, dryBiCartDrainStartTime, - * dryBiCartDrainLastCondSampleTime, - * dryBiCartDrainCondStableCount + * @details \b Inputs: dryBiCartDrainRequested, dryBiCartType + * @details \b Outputs: valve states, dryBiCartDrainStartTime, dryBiCartDrainTimePeriod + * dryBiCartDrainLastCondSampleTime, dryBiCartDrainCondStableCount * @return the next drybicart fluid drain state. *************************************************************************/ static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainStartState( void ) { - DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_FLUID_DRAIN_STATE; + DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_DRAIN_START_STATE; - // open bypass valve - setValveState( D34_VALV, VALVE_STATE_OPEN ); + if ( TRUE == getU32OverrideValue( &dryBiCartDrainRequested ) ) + { + if ( TRUE == getU32OverrideValue( &dryBiCartType ) ) + { + dryBiCartDrainTimePeriod = LARGE_DRY_BICART_MAX_DRAIN_TIME_MS; + } + else + { + dryBiCartDrainTimePeriod = SMALL_DRY_BICART_MAX_DRAIN_TIME_MS; + } - // TODO: open DD drain - setValveState( D53_VALV, VALVE_STATE_OPEN ); + // open bypass valve + setValveState( D34_VALV, VALVE_STATE_OPEN ); - // TODO: open iofp drain valve - setValveState( M12_VALV, VALVE_STATE_OPEN ); + // TODO: open DD drain + setValveState( D53_VALV, VALVE_STATE_OPEN ); - // Open balancing chamber valves - valveControlForBCOpenState(); + // TODO: open iofp drain valve + setValveState( M12_VALV, VALVE_STATE_OPEN ); - //Close D14 valve - setValveState( D14_VALV, VALVE_STATE_CLOSED ); + // Open balancing chamber valves + valveControlForBCOpenState(); - // Run D10 In Open loop mode(max speed 200ml/min) - setConcentratePumpTargetSpeed( D10_PUMP, DRAIN_BICART_PUMP_SPEED, DOSING_CONT_VOLUME ); - requestConcentratePumpOn( D10_PUMP ); + //Close D14 valve + setValveState( D14_VALV, VALVE_STATE_CLOSED ); - // Run D48 at 1000 rpm,There is no improvement over above 1000 rpm for drain duration. - setDialysatePumpTargetRPM( D48_PUMP, DIAL_PUMP_DRAIN_RPM, TRUE ); + // Run D10 In Open loop mode(max speed 200ml/min) + setConcentratePumpTargetSpeed( D10_PUMP, DRAIN_BICART_PUMP_SPEED, DOSING_CONT_VOLUME ); + requestConcentratePumpOn( D10_PUMP ); - dryBiCartDrainStartTime = getMSTimerCount(); - dryBiCartDrainLastCondSampleTime = dryBiCartDrainStartTime; - dryBiCartDrainCondStableCount = 0; + // Run D48 at 1000 rpm,There is no improvement over above 1000 rpm for drain duration. + setDialysatePumpTargetRPM( D48_PUMP, DIAL_PUMP_DRAIN_RPM, TRUE ); + dryBiCartDrainStartTime = getMSTimerCount(); + dryBiCartDrainLastCondSampleTime = dryBiCartDrainStartTime; + dryBiCartDrainCondStableCount = 0; + + state = DRY_BICART_FLUID_DRAIN_STATE; + } + return state; } Index: firmware/App/DDCommon.h =================================================================== diff -u -r89c8709e3b27648926fbb20f25c9a67cbeb99adc -rf7f6305f054732569330f6001568777857e20442 --- firmware/App/DDCommon.h (.../DDCommon.h) (revision 89c8709e3b27648926fbb20f25c9a67cbeb99adc) +++ firmware/App/DDCommon.h (.../DDCommon.h) (revision f7f6305f054732569330f6001568777857e20442) @@ -51,9 +51,6 @@ //Uncomment below for Maxon controller speed change #define __MAXON_SPEED_UPDATE__ 1 -//UnComment below for DryBicarb testing -#define __DRY_BICARB__ 1 - //Uncomment below to disable heaters debug message #define __HEATERS_DEBUG__ 1 Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r89c8709e3b27648926fbb20f25c9a67cbeb99adc -rf7f6305f054732569330f6001568777857e20442 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 89c8709e3b27648926fbb20f25c9a67cbeb99adc) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision f7f6305f054732569330f6001568777857e20442) @@ -62,7 +62,7 @@ #define LOW_DIAL_FLOW_RATE 150.0F ///< Dialysate flow rate lesser than 150 considered to be low Qds. #define ZERO_DIAL_FLOW_RATE 0.0F ///< Zero dialysate flow rate #define SPENT_CHAMBER_FILL_MAX_COUNT 10 ///< Total number of spent chamber fill allowed. -#define BICARB_CHAMBER_FILL_TIMEOUT ( 1 * MS_PER_SECOND ) ///< Bicarb chamber fill timeout. +#define BICARB_CHAMBER_FILL_TIMEOUT ( 1 * MS_PER_SECOND ) ///< Bicarb chamber fill timeout. //Testing #define DELAY_BC_SWITCHING_AT_START_UP ( 10 * MS_PER_SECOND ) ///< Provide a balancing chamber switching start up delay to stabilize pump speed etc., /// Payload record structure for Gen dialysate execution state set request @@ -222,11 +222,13 @@ setValveState( D81_VALV, VALVE_STATE_CLOSED ); setValveState( D85_VALV, VALVE_STATE_CLOSED ); setValveState( D31_VALV, VALVE_STATE_CLOSED ); -#ifndef __DRY_BICARB__ - setValveState( D80_VALV, VALVE_STATE_OPEN ); // Bicarb valve - setValveState( D64_VALV, VALVE_STATE_CLOSED ); -#endif + if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DRY_BICARB ) == FALSE ) + { + setValveState( D80_VALV, VALVE_STATE_OPEN ); // Bicarb valve + setValveState( D64_VALV, VALVE_STATE_CLOSED ); + } + // Turn on the primary heater calculateTargetDialysateTemp(); setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); @@ -278,10 +280,12 @@ setValveState( D34_VALV, VALVE_STATE_CLOSED ); // Bypass valve setValveState( D35_VALV, VALVE_STATE_OPEN ); // VDI setValveState( D40_VALV, VALVE_STATE_OPEN ); // VDO -#ifndef __DRY_BICARB__ - setValveState( D80_VALV, VALVE_STATE_OPEN ); // Bicarb valve - setValveState( D64_VALV, VALVE_STATE_CLOSED ); -#endif + + if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DRY_BICARB ) == FALSE ) + { + setValveState( D80_VALV, VALVE_STATE_OPEN ); // Bicarb valve + setValveState( D64_VALV, VALVE_STATE_CLOSED ); + } break; case DD_GEND_SPENT_CHAMBER_FILL_STATE: @@ -296,10 +300,13 @@ setValveState( D14_VALV, VALVE_STATE_OPEN ); setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve -#ifndef __DRY_BICARB__ - setValveState( D80_VALV, VALVE_STATE_OPEN ); // Bicarb valve - setValveState( D64_VALV, VALVE_STATE_CLOSED ); -#endif + + if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DRY_BICARB ) == FALSE ) + { + setValveState( D80_VALV, VALVE_STATE_OPEN ); // Bicarb valve + setValveState( D64_VALV, VALVE_STATE_CLOSED ); + } + setValveState( D47_VALV, VALVE_STATE_OPEN ); // Spent chamber purge valve requestConcentratePumpOff( D76_PUMP, FALSE ); @@ -335,10 +342,13 @@ setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve -#ifndef __DRY_BICARB__ - setValveState( D80_VALV, VALVE_STATE_OPEN ); // Bicarb valve - setValveState( D64_VALV, VALVE_STATE_OPEN ); // Bicarb chamber purge valve -#endif + + if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DRY_BICARB ) == FALSE ) + { + setValveState( D80_VALV, VALVE_STATE_OPEN ); // Bicarb valve + setValveState( D64_VALV, VALVE_STATE_OPEN ); // Bicarb chamber purge valve + } + bicarbFillStartTimeMS = getMSTimerCount(); // Turn on the primary heater @@ -388,10 +398,12 @@ setValveState( D34_VALV, VALVE_STATE_OPEN ); setValveState( D53_VALV, VALVE_STATE_OPEN ); -#ifndef __DRY_BICARB__ - setValveState( D80_VALV, VALVE_STATE_OPEN ); - setValveState( D64_VALV, VALVE_STATE_CLOSED ); -#endif + + if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DRY_BICARB ) == FALSE ) + { + setValveState( D80_VALV, VALVE_STATE_OPEN ); + setValveState( D64_VALV, VALVE_STATE_CLOSED ); + } break; case DD_GEND_ISOLATED_UF_STATE: Index: firmware/App/Modes/ModePreGenDialysate.c =================================================================== diff -u -rf031f37d3f9985c1224472f2827cd180287c5621 -rf7f6305f054732569330f6001568777857e20442 --- firmware/App/Modes/ModePreGenDialysate.c (.../ModePreGenDialysate.c) (revision f031f37d3f9985c1224472f2827cd180287c5621) +++ firmware/App/Modes/ModePreGenDialysate.c (.../ModePreGenDialysate.c) (revision f7f6305f054732569330f6001568777857e20442) @@ -58,7 +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 ); +static DD_PRE_GEN_DIALYSATE_STATE_T handleDryBicartInitialFillState( void ); //Wet Self test static void setModePreGenWetSelfStateTransition( DD_WET_SELF_TEST_STATE_T state ); @@ -146,8 +146,8 @@ preGenDialysateState = handlePreGenWetSelfTestState(); break; - case DD_PRE_GEN_DRY_BICART_FILL_CHECK: - preGenDialysateState = handleDryBicartFillCheckState(); + case DD_PRE_GEN_DRY_BICART_INITIAL_FILL: + preGenDialysateState = handleDryBicartInitialFillState(); break; case DD_PRE_GEN_DIALYSATE_WAIT_FOR_GEND: @@ -247,34 +247,34 @@ 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_DRY_BICART_FILL_CHECK; + DD_PRE_GEN_DIALYSATE_STATE_T state = DD_PRE_GEN_DRY_BICART_INITIAL_FILL; + setBicartFillRequested(); //execWetSelfTest(); return state; } /*********************************************************************//** * @brief - * The handleDryBicartFillCheckState function executes intial dry bicart fill request + * The handleDryBicartInitialFillState function executes intial dry bicart fill request * @details \b Inputs: none * @details \b Outputs: none * @return current state of PreGenDialysate mode *************************************************************************/ -static DD_PRE_GEN_DIALYSATE_STATE_T handleDryBicartFillCheckState( void ) +static DD_PRE_GEN_DIALYSATE_STATE_T handleDryBicartInitialFillState( void ) { //TODO: Change to wet self test state later - DD_PRE_GEN_DIALYSATE_STATE_T state = DD_PRE_GEN_DRY_BICART_FILL_CHECK; + DD_PRE_GEN_DIALYSATE_STATE_T state = DD_PRE_GEN_DRY_BICART_INITIAL_FILL; - if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DRY_BICARB ) == TRUE ) + if ( getTestConfigStatus( TEST_CONFIG_DD_DRY_BICART_TEST ) == TRUE ) { - setBicartFillRequested(); - // stay in this state till bicart fill complete. if ( getCurrentDryBiCartFillExecState() == DRY_BICART_FILL_COMPLETE_STATE ) { state = DD_PRE_GEN_DIALYSATE_WAIT_FOR_GEND; } + // alarm if not completed within 1 minutes } else { Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r89c8709e3b27648926fbb20f25c9a67cbeb99adc -rf7f6305f054732569330f6001568777857e20442 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 89c8709e3b27648926fbb20f25c9a67cbeb99adc) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision f7f6305f054732569330f6001568777857e20442) @@ -94,8 +94,11 @@ // manage concentrate pumps execConcentratePumpController(); - // manage drybicart state machines - execDryBicart(); + if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DRY_BICARB ) == TRUE ) + { + // manage drybicart state machines + execDryBicart(); + } // Control RO pump execROPumpController();