Index: firmware/App/Modes/ModeRecirculate.c =================================================================== diff -u -ra2c32d4d221603054ca9ad7a097112caebf08c4e -r6f1f269cd7d91f41c51797d17a85a7ea249e21f3 --- firmware/App/Modes/ModeRecirculate.c (.../ModeRecirculate.c) (revision a2c32d4d221603054ca9ad7a097112caebf08c4e) +++ firmware/App/Modes/ModeRecirculate.c (.../ModeRecirculate.c) (revision 6f1f269cd7d91f41c51797d17a85a7ea249e21f3) @@ -24,6 +24,7 @@ #include "FPGA.h" #include "Heaters.h" #include "ModeRecirculate.h" +#include "NVDataMgmt.h" #include "OperationModes.h" #include "Pressures.h" #include "ROPump.h" @@ -44,19 +45,22 @@ #define TARGET_RO_FLOW_RATE_L 0.3 ///< Target flow rate for RO pump. #define TARGET_FLUSH_LINES_RO_FLOW_RATE_L 0.6 ///< Target flow rate for RO pump. -#define FLUSH_LINES_VOLUME_L 0.01 ///< Water volume (in Liters) to flush when starting re-circulate mode. +#define FLUSH_LINES_VOLUME_L 0.01 ///< Water volume (in Liters) to flush when starting re-circulate mode. // ********** private data ********** -static DG_RECIRCULATE_MODE_STATE_T recircState; ///< Currently active re-circulation state. -static F32 flushLinesVolumeL = 0.0; ///< Volume of water pumped by RO pump during flush lines state. +static DG_RECIRCULATE_MODE_STATE_T recircState; ///< Currently active re-circulation state. +static F32 flushLinesVolumeL = 0.0; ///< Volume of water pumped by RO pump during flush lines state. +static F32 flushLinesTargetVolumeL = FLUSH_LINES_VOLUME_L; ///< Flush lines target volume in liters. // ********** private function prototypes ********** static DG_RECIRCULATE_MODE_STATE_T handleFlushLinesState( void ); static DG_RECIRCULATE_MODE_STATE_T handleRecircWaterState( void ); static DG_RECIRCULATE_MODE_STATE_T handleRecircPauseState( void ); +static BOOL processCalibrationData( void ); + /*********************************************************************//** * @brief * The initRecirculateMode function initializes the re-circulate mode module. @@ -66,8 +70,12 @@ *************************************************************************/ void initRecirculateMode( void ) { - recircState = DG_RECIRCULATE_MODE_STATE_START; - flushLinesVolumeL = 0.0; + recircState = DG_RECIRCULATE_MODE_STATE_START; + flushLinesVolumeL = 0.0; + + // TODO temporary code remove + flushLinesTargetVolumeL = FLUSH_LINES_VOLUME_L; + // TODO temporary code remove } /*********************************************************************//** @@ -124,6 +132,13 @@ *************************************************************************/ U32 execRecirculateMode( void ) { + // Check if a new calibration is available + if ( TRUE == isNewCalibrationRecordAvailable() ) + { + // Get the new calibration data and check its validity + processCalibrationData(); + } + // check inlet water conductivity, temperature, pressure, and RO rejection ratio checkInletWaterConductivity(); checkInletWaterTemperature(); @@ -160,6 +175,35 @@ /*********************************************************************//** * @brief + * The requestDGStop function handles an HD request to stop (return to standby mode). + * @details Inputs: none + * @details Outputs: DG standby mode requested + * @return TRUE if request accepted, FALSE if not. + *************************************************************************/ +BOOL requestDGStop( void ) +{ + BOOL result = TRUE; + + requestNewOperationMode( DG_MODE_STAN ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getCurrentRecirculateState function returns the current state of the + * re-circulate mode. + * @details Inputs: recircState + * @details Outputs: none + * @return the current state of re-circulate mode + *************************************************************************/ +DG_RECIRCULATE_MODE_STATE_T getCurrentRecirculateState( void ) +{ + return recircState; +} + +/*********************************************************************//** + * @brief * The handleFlushLinesState function executes the flush lines state of the * re-circulate mode state machine. * @details Inputs: none @@ -176,11 +220,9 @@ flushLinesVolumeL += waterVolume; // when enough water volume has flowed to flush the lines, transition to re-circ state - if ( flushLinesVolumeL >= FLUSH_LINES_VOLUME_L ) + if ( flushLinesVolumeL >= flushLinesTargetVolumeL ) { -#ifndef SKIP_RECIRC setValveState( VDR, VALVE_STATE_RECIRC_C_TO_NC ); -#endif setROPumpTargetFlowRate( TARGET_RO_FLOW_RATE_L, TARGET_RO_PRESSURE_PSI ); result = DG_RECIRCULATE_MODE_STATE_RECIRC_WATER; } @@ -220,31 +262,39 @@ /*********************************************************************//** * @brief - * The requestDGStop function handles an HD request to stop (return to standby mode). + * The processCalibrationData function gets the calibration data and makes + * sure it is valid by checking the calibration date. The calibration date + * should not be 0. * @details Inputs: none - * @details Outputs: DG standby mode requested - * @return TRUE if request accepted, FALSE if not. + * @details Outputs: flushLinesVolumeL + * @return TRUE if the calibration record is valid, otherwise FALSE *************************************************************************/ -BOOL requestDGStop( void ) +static BOOL processCalibrationData( void ) { - BOOL result = TRUE; + BOOL status = TRUE; - requestNewOperationMode( DG_MODE_STAN ); + // Get the calibration record from NVDataMgmt + DG_DRAIN_LINE_VOLUME_T calData = getDGDrainLineVolumeRecord(); - return result; -} + // Check if the calibration data that was received from NVDataMgmt is legitimate + // The calibration date item should not be zero. If the calibration date is 0, + // then the data is not stored in the NV memory or it was corrupted. + if ( 0 == calData.calibrationTime ) + { +#ifndef DISABLE_CAL_CHECK + activateAlarmNoData( ALARM_ID_DG_DRAIN_LINE_VOLUME_INVALID_CALIBRATION ); +#endif + // In case calibration time was 0 set the flush target volume to default + flushLinesTargetVolumeL = FLUSH_LINES_VOLUME_L; + status = FALSE; + } + else + { + // The calibration data was valid, update the local copy + flushLinesVolumeL = calData.volume; + } -/*********************************************************************//** - * @brief - * The getCurrentRecirculateState function returns the current state of the - * re-circulate mode. - * @details Inputs: recircState - * @details Outputs: none - * @return the current state of re-circulate mode - *************************************************************************/ -DG_RECIRCULATE_MODE_STATE_T getCurrentRecirculateState( void ) -{ - return recircState; + return status; } /**@}*/