Index: firmware/App/Modes/ModeGenPermeate.c =================================================================== diff -u -r410afd26b3ae5e372310c696c82f58c59235e10d -r8d272582cbd2cb5fc0c6af0fead2867ce02658b0 --- firmware/App/Modes/ModeGenPermeate.c (.../ModeGenPermeate.c) (revision 410afd26b3ae5e372310c696c82f58c59235e10d) +++ firmware/App/Modes/ModeGenPermeate.c (.../ModeGenPermeate.c) (revision 8d272582cbd2cb5fc0c6af0fead2867ce02658b0) @@ -15,14 +15,16 @@ * ***************************************************************************/ -#include +#include "BoostPump.h" #include "DDInterface.h" #include "Level.h" #include "MessageSupport.h" #include "Messaging.h" #include "ModeGenPermeate.h" +#include "ModePreGenPermeate.h" #include "ModeStandby.h" #include "OperationModes.h" +#include "ROPump.h" #include "TaskGeneral.h" #include "Timers.h" #include "Valves.h" @@ -34,16 +36,21 @@ // ********** private definitions ********** -#define GEN_PERMEATE_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen permeate mode data published. -#define GEN_PERMEATE_TIMEOUT_MS ( 6 * MS_PER_SECOND ) ///< state switch timeout (in ms) +#define PRE_GEN_PERMEATE_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen permeate mode data published. +#define GEN_PERMEATE_TANK_FULL_SWITCH_MS ( 6 * MS_PER_SECOND ) ///< state switch timeout (in ms) +#define GEN_PERMEATE_TANK_FULL_TIMEOUT_MS ( 60 * MS_PER_SECOND ) +#define GEN_PERMEATE_BOOST_PUMP_TGT_PSI 25 // ********** private data ********** static FP_GENP_MODE_STATE_T genPermeateState; ///< Currently active generate Permeate state. static U32 genPermeateDataPublicationTimerCounter; ///< Used to schedule generate Permeate data publication to CAN bus. static OVERRIDE_U32_T genPermeateDataPublishInterval; ///< Generate permeate mode data publish interval. -static U32 stateDelayTime; ///< Time stamp to track delay before valve switch. -static U32 pendingStartGenRequest; ///< Flag indicating DD has requested FP start the generate permeate. +static U32 tankFullDelayTime; ///< Time stamp to track delay before valve switch. +static BOOL pendingStartGenRequest; ///< Flag indicating DD has requested FP start the generate permeate. +static F32 genPermeateRODutyCycle; +static F32 genPermeateBoostDutyCycle; +static U32 tankFullAlarmTimeout; // ********** private function prototypes ********** @@ -63,13 +70,16 @@ void initGenPermeateMode( void ) { genPermeateState = FP_GENP_TANK_FILL_STATE; - genPermeateDataPublishInterval.data = GEN_PERMEATE_DATA_PUBLISH_INTERVAL; - genPermeateDataPublishInterval.ovData = GEN_PERMEATE_DATA_PUBLISH_INTERVAL; + genPermeateDataPublishInterval.data = PRE_GEN_PERMEATE_DATA_PUBLISH_INTERVAL; + genPermeateDataPublishInterval.ovData = PRE_GEN_PERMEATE_DATA_PUBLISH_INTERVAL; genPermeateDataPublishInterval.ovInitData = 0; genPermeateDataPublishInterval.override = OVERRIDE_RESET; genPermeateDataPublicationTimerCounter = 0; - stateDelayTime = 0; + tankFullDelayTime = 0; + tankFullAlarmTimeout = 0; pendingStartGenRequest = 0; + genPermeateRODutyCycle = 0.0F; + genPermeateBoostDutyCycle = 0.0F; } /*********************************************************************//** @@ -84,7 +94,6 @@ { initGenPermeateMode(); setCurrentSubState( genPermeateState ); - return genPermeateState; } @@ -98,13 +107,8 @@ *************************************************************************/ U32 execGenPermeateMode( void ) { - LEVEL_STATE_T level = getLevelStatus(); + FP_GENP_MODE_STATE_T prevState = genPermeateState; - if ( LEVEL_STATE_ILLEGAL == level ) - { - // TODO: Raise illegal level alarm - } - // execute current gen Permeate state switch ( genPermeateState ) { @@ -121,6 +125,12 @@ break; } + + if ( prevState != genPermeateState ) + { + setModeGenPTransition( genPermeateState ); + SEND_EVENT_WITH_2_U32_DATA( FP_EVENT_GENP_CHANGE, genPermeateState, prevState ) + } //Publish Gen Permeate mode data publishGenPModeData(); @@ -147,6 +157,12 @@ setValveState( P6_VALV,VALVE_STATE_CLOSED ); setValveState( P39_VALV,VALVE_STATE_OPEN ); setValveState( P11_VALV, VALVE_STATE_OPEN ); + + if ( TRUE == isBoostPumpInstalled() ) + { + setBoostPumpTargetPressure( GEN_PERMEATE_BOOST_PUMP_TGT_PSI ); + } + setROPumpTargetDutyCycle( getGenPermeateRODutyCycle() ); break; case FP_GENP_TANK_FULL_STATE: @@ -155,7 +171,14 @@ setValveState( P6_VALV,VALVE_STATE_CLOSED ); setValveState( P39_VALV,VALVE_STATE_OPEN ); setValveState( P11_VALV, VALVE_STATE_CLOSED ); - stateDelayTime = getMSTimerCount(); + + if ( TRUE == isBoostPumpInstalled() ) + { + signalBoostPumpHardStop(); + } + tankFullDelayTime = getMSTimerCount(); + tankFullAlarmTimeout = getMSTimerCount(); + setROPumpTargetDutyCycle( getGenPermeateRODutyCycle() ); break; default: @@ -178,8 +201,13 @@ if ( LEVEL_STATE_HIGH == level ) { - setModeGenPTransition( FP_GENP_TANK_FULL_STATE ); state = FP_GENP_TANK_FULL_STATE; + // save boost pump + if ( TRUE == isBoostPumpInstalled() ) + { + setGenPermeateBoostDutyCycle( getCurrentBoostPumpDutyCyclePCT() ); + SEND_EVENT_WITH_2_U32_DATA( FP_EVENT_GENP_BOOST_SET_PWM, getCurrentBoostPumpDutyCyclePCT(), getFluidPumpReadPWMDutyCycle( P40_PUMP ) ) + } } else if ( level <= LEVEL_STATE_MEDIUM ) @@ -203,14 +231,14 @@ FP_GENP_MODE_STATE_T state = FP_GENP_TANK_FULL_STATE; LEVEL_STATE_T level = getLevelStatus(); - if ( LEVEL_STATE_LOW == level ) + if ( TRUE == didTimeout( tankFullAlarmTimeout, GEN_PERMEATE_TANK_FULL_TIMEOUT_MS ) ) { - // TODO: Turn off heater. + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_FP_GEN_PERMEATE_TANK_FULL_TIMEOUT, level ) } - else if ( ( level >= LEVEL_STATE_MEDIUM ) && ( TRUE == didTimeout( stateDelayTime, GEN_PERMEATE_TIMEOUT_MS ) ) ) + if ( ( ( level == LEVEL_STATE_MEDIUM ) && ( TRUE == didTimeout( tankFullDelayTime, GEN_PERMEATE_TANK_FULL_SWITCH_MS ) ) ) || + ( level == LEVEL_STATE_LOW ) ) { - setModeGenPTransition( FP_GENP_TANK_FILL_STATE ); state = FP_GENP_TANK_FILL_STATE; } @@ -219,6 +247,58 @@ /*********************************************************************//** * @brief + * The getGenPermeateBoostDutyCycle function returns the current Boost pump pwm setting + * in gen permeate mode. + * @details \b Inputs: genPermeateBoostDutyCycle + * @details \b Outputs: genPermeateBoostDutyCycle + * @return the current pwm setting for the RO Pump + *************************************************************************/ +F32 getGenPermeateBoostDutyCycle( void ) +{ + return genPermeateBoostDutyCycle; +} + +/*********************************************************************//** + * @brief + * The setGenPermeateBoostDutyCycle function sets the Boost pump pwm in gen permeate + * mode + * @details \b Inputs: none + * @details \b Outputs: genPermeateBoostDutyCycle + * @return none + *************************************************************************/ +void setGenPermeateBoostDutyCycle( F32 duty) +{ + genPermeateBoostDutyCycle = duty; +} + +/*********************************************************************//** + * @brief + * The getGenPermeateRODutyCycle function returns the current pwm setting + * for the RO pump in gen permeate mode. + * @details \b Inputs: genPermeateRODutyCycle + * @details \b Outputs: genPermeateRODutyCycle + * @return the current pwm setting for the RO Pump + *************************************************************************/ +F32 getGenPermeateRODutyCycle( void ) +{ + return genPermeateRODutyCycle; +} + +/*********************************************************************//** + * @brief + * The setGenPermeateRODutyCycle function sets the RO PWM pump in gen permeate + * mode + * @details \b Inputs: none + * @details \b Outputs: genPermeateRODutyCycle + * @return none + *************************************************************************/ +void setGenPermeateRODutyCycle( F32 duty) +{ + genPermeateRODutyCycle = duty; +} + +/*********************************************************************//** + * @brief * The getCurrentGenPermeateState function returns the current state of the * gen permeate mode. * @details \b Inputs: genPermeateState @@ -232,6 +312,19 @@ /*********************************************************************//** * @brief + * The getGenPermeateRequest function returns the current state of the + * gen permeate mode. + * @details \b Inputs: pendingStartGenRequest + * @details \b Outputs: none + * @return the current state of gen permeate request + *************************************************************************/ +BOOL getGenPermeateRequest( void ) +{ + return pendingStartGenRequest; +} + +/*********************************************************************//** + * @brief * The getGenPermeateDataPublishInterval function gets the generate water * mode data publish interval. * @details \b Inputs: genPermeateDataPublishInterval @@ -285,6 +378,7 @@ { result = TRUE; pendingStartGenRequest = TRUE; + requestNewOperationMode( FP_MODE_GENP ); } return result; @@ -301,6 +395,12 @@ { BOOL result = TRUE; pendingStartGenRequest = FALSE; + signalROPumpHardStop(); + + if ( TRUE == isBoostPumpInstalled() ) + { + signalBoostPumpHardStop(); + } requestNewOperationMode( FP_MODE_STAN ); return result;