Index: firmware/App/Modes/ModeRecirculate.c =================================================================== diff -u -r138efd92a8645e0d2fe422409ef5a33dd2929a25 -rc48a99d2d1c852adcc986253b6c420a90dab7bfe --- firmware/App/Modes/ModeRecirculate.c (.../ModeRecirculate.c) (revision 138efd92a8645e0d2fe422409ef5a33dd2929a25) +++ firmware/App/Modes/ModeRecirculate.c (.../ModeRecirculate.c) (revision c48a99d2d1c852adcc986253b6c420a90dab7bfe) @@ -14,7 +14,10 @@ * **************************************************************************/ +#include "FPGA.h" #include "OperationModes.h" +#include "ROPump.h" +#include "TaskGeneral.h" #include "Timers.h" #include "ModeRecirculate.h" @@ -29,27 +32,23 @@ // ********** private definitions ********** -/// Enumberation of re-circulation mode states. -typedef enum Recirculate_Mode_States -{ - RECIRCULATE_MODE_STATE_START = 0, ///< Start re-circulation mode state. - RECIRCULATE_MODE_STATE_CHECK_INLET_WATER, ///< Check inlet water state. - RECIRCULATE_MODE_STATE_RECIRC_PRODUCT_WATER, ///< Re-circulate product water state. - NUM_OF_RECIRCULATE_MODE_STATES ///< Number of fill mode states. -} RECIRCULATE_MODE_STATE_T; +#define TARGET_RO_PRESSURE_PSI 120 ///< Target pressure for RO pump. +#define FLUSH_LINES_VOLUME_ML 100.0 ///< Water volume to flush when starting re-circulate mode. // ********** private data ********** static RECIRCULATE_MODE_STATE_T recircState; ///< Currently active re-circulation state. +static F32 flushLinesVolume = 0.0; ///< Volume of water pumped by RO pump during flush lines state. // ********** private function prototypes ********** -static RECIRCULATE_MODE_STATE_T handleCheckInletWaterState( void ); -static RECIRCULATE_MODE_STATE_T handleRecircProductWaterState( void ); +static RECIRCULATE_MODE_STATE_T handleFlushLinesState( void ); +static RECIRCULATE_MODE_STATE_T handleRecircWaterState( void ); +static RECIRCULATE_MODE_STATE_T handleRecircPauseState( void ); /*********************************************************************//** - * @brief initFillMode - * The initFillMode function initializes the Fill Mode module. + * @brief + * The initRecirculateMode function initializes the Fill Mode module. * @details * Inputs : none * Outputs : Fill Mode module initialized. @@ -58,47 +57,60 @@ void initRecirculateMode( void ) { recircState = RECIRCULATE_MODE_STATE_START; + flushLinesVolume = 0.0; } /*********************************************************************//** - * @brief transitionToFillMode - * The transitionToFillMode function prepares for transition to \n + * @brief + * The transitionToRecirculateMode function prepares for transition to \n * fill mode. * @details * Inputs : none - * Outputs : fillState + * Outputs : recircState * @return none *************************************************************************/ void transitionToRecirculateMode( void ) { - recircState = RECIRCULATE_MODE_STATE_START; + // re-initialize each time we transition to re-circulate mode + initRecirculateMode(); + + // TODO - set initial actuator states + setFPGAValveStates(0x014F); + // VPi open, VRc re-circ, VDr and VPo to drain + // UV on + // Primary heater on } /*********************************************************************//** - * @brief execFillMode - * The execFillMode function executes the Fill Mode state machine. + * @brief + * The execRecirculateMode function executes the Re-circulate Mode state machine. * @details - * Inputs : fillState - * Outputs : fillState + * Inputs : recircState + * Outputs : recircState * @return none *************************************************************************/ void execRecirculateMode( void ) { - // execute current Fill state + // execute current re-circulate state switch ( recircState ) { case RECIRCULATE_MODE_STATE_START: - recircState = RECIRCULATE_MODE_STATE_CHECK_INLET_WATER; + setROPumpTargetPressure( TARGET_RO_PRESSURE_PSI, PUMP_CONTROL_MODE_CLOSED_LOOP ); + recircState = RECIRCULATE_MODE_STATE_FLUSH_LINES; break; - case RECIRCULATE_MODE_STATE_CHECK_INLET_WATER: - recircState = handleCheckInletWaterState(); + case RECIRCULATE_MODE_STATE_FLUSH_LINES: + recircState = handleFlushLinesState(); break; - case RECIRCULATE_MODE_STATE_RECIRC_PRODUCT_WATER: - recircState = handleRecircProductWaterState(); + case RECIRCULATE_MODE_STATE_RECIRC_WATER: + recircState = handleRecircWaterState(); break; + case RECIRCULATE_MODE_STATE_PAUSE: + recircState = handleRecircPauseState(); + break; + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, 0, recircState ) // TODO - add s/w fault enum to 1st data param recircState = RECIRCULATE_MODE_STATE_START; @@ -108,36 +120,92 @@ /*********************************************************************//** * @brief - * The handleCheckInletWaterState function executes the Check Inlet Water \n - * state of the Fill Mode state machine. + * The handleCheckInletWaterState function executes the flush lines \n + * state of the Re-circulate Mode state machine. * @details * Inputs : none * Outputs : - * @param none * @return the next state *************************************************************************/ -static RECIRCULATE_MODE_STATE_T handleCheckInletWaterState( void ) +static RECIRCULATE_MODE_STATE_T handleFlushLinesState( void ) { - RECIRCULATE_MODE_STATE_T result = RECIRCULATE_MODE_STATE_CHECK_INLET_WATER; + RECIRCULATE_MODE_STATE_T result = RECIRCULATE_MODE_STATE_FLUSH_LINES; + F32 waterFlowRate = getMeasuredROFlowRate(); + F32 waterVolume = ( ( waterFlowRate / SEC_PER_MIN ) / ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); + flushLinesVolume += waterVolume; + + // when enough water volume has flowed to flush the lines, transition to re-circ state + if ( flushLinesVolume >= FLUSH_LINES_VOLUME_ML ) + { + // TODO - change VDr from drain to re-circulate + result = RECIRCULATE_MODE_STATE_RECIRC_WATER; + } + return result; } /*********************************************************************//** * @brief - * The handleRecircProductWaterState function executes the Create Product \n - * Water state of the Fill Mode state machine. + * The handleRecircProductWaterState function executes the re-circulate \n + * water state of the Re-circulate Mode state machine. * @details * Inputs : none * Outputs : - * @param none * @return the next state *************************************************************************/ -static RECIRCULATE_MODE_STATE_T handleRecircProductWaterState( void ) +static RECIRCULATE_MODE_STATE_T handleRecircWaterState( void ) { - RECIRCULATE_MODE_STATE_T result = RECIRCULATE_MODE_STATE_RECIRC_PRODUCT_WATER; + RECIRCULATE_MODE_STATE_T result = RECIRCULATE_MODE_STATE_RECIRC_WATER; return result; } +/*********************************************************************//** + * @brief + * The handleRecircPauseState function executes the pause state of the \n + * Re-circulate Mode state machine. + * @details + * Inputs : none + * Outputs : + * @return the next state + *************************************************************************/ +static RECIRCULATE_MODE_STATE_T handleRecircPauseState( void ) +{ + RECIRCULATE_MODE_STATE_T result = RECIRCULATE_MODE_STATE_PAUSE; + + return result; +} + +/*********************************************************************//** + * @brief + * The requestDGStop function handles an HD request to stop (return to Standby mode). + * @details + * Inputs : none + * Outputs : DG standby mode requested + * @return TRUE if request accepted, FALSE if not. + *************************************************************************/ +BOOL requestDGStop( void ) +{ + BOOL result = TRUE; + + requestNewOperationMode( MODE_STAN ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getRecirculateModeState function returns the current state of the \n + * re-circulate mode. + * @details + * Inputs : recircState + * Outputs : none + * @return the current state of re-circulate mode. + *************************************************************************/ +RECIRCULATE_MODE_STATE_T getRecirculateModeState( void ) +{ + return recircState; +} + /**@}*/