Fisheye: Tag 9f7c5de17f8e3d832da0888f138fb7602cc33a78 refers to a dead (removed) revision in file `firmware/App/Modes/FPModes/FlushConcentrate.c'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f7c5de17f8e3d832da0888f138fb7602cc33a78 refers to a dead (removed) revision in file `firmware/App/Modes/FPModes/FlushConcentrate.h'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f7c5de17f8e3d832da0888f138fb7602cc33a78 refers to a dead (removed) revision in file `firmware/App/Modes/FPModes/FlushFilter.c'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f7c5de17f8e3d832da0888f138fb7602cc33a78 refers to a dead (removed) revision in file `firmware/App/Modes/FPModes/FlushFilter.h'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f7c5de17f8e3d832da0888f138fb7602cc33a78 refers to a dead (removed) revision in file `firmware/App/Modes/FPModes/FlushFilterDefeatured.c'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f7c5de17f8e3d832da0888f138fb7602cc33a78 refers to a dead (removed) revision in file `firmware/App/Modes/FPModes/FlushFilterDefeatured.h'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f7c5de17f8e3d832da0888f138fb7602cc33a78 refers to a dead (removed) revision in file `firmware/App/Modes/FPModes/FlushPermeate.c'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f7c5de17f8e3d832da0888f138fb7602cc33a78 refers to a dead (removed) revision in file `firmware/App/Modes/FPModes/FlushPermeate.h'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f7c5de17f8e3d832da0888f138fb7602cc33a78 refers to a dead (removed) revision in file `firmware/App/Modes/FPModes/InletPressureCheck.c'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f7c5de17f8e3d832da0888f138fb7602cc33a78 refers to a dead (removed) revision in file `firmware/App/Modes/FPModes/InletPressureCheck.h'. Fisheye: No comparison available. Pass `N' to diff? Index: firmware/App/Modes/FPModes/ModePreGenPermeate.c =================================================================== diff -u -r47a7b0fce13cf38919932a8662c378f4f6a8b9f3 -r9f7c5de17f8e3d832da0888f138fb7602cc33a78 --- firmware/App/Modes/FPModes/ModePreGenPermeate.c (.../ModePreGenPermeate.c) (revision 47a7b0fce13cf38919932a8662c378f4f6a8b9f3) +++ firmware/App/Modes/FPModes/ModePreGenPermeate.c (.../ModePreGenPermeate.c) (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -16,18 +16,18 @@ ***************************************************************************/ #include "BoostPump.h" -#include "FlushFilter.h" -#include "FlushPermeate.h" -#include "FlushConcentrate.h" #include "FPModeStandby.h" #include "FPOperationModes.h" -#include "InletPressureCheck.h" #include "MessageSupport.h" #include "Messaging.h" #include "ModeGenPermeate.h" #include "ModePreGenPermeate.h" #include "PermeateTank.h" #include "ROPump.h" +#include "StateFlushConcentrate.h" +#include "StateFlushFilter.h" +#include "StateFlushPermeate.h" +#include "StateInletPressureCheck.h" #include "TaskGeneral.h" #include "Timers.h" #include "Valves.h" Index: firmware/App/Modes/FPModes/ModePreGenPermeateDefeatured.c =================================================================== diff -u -r47a7b0fce13cf38919932a8662c378f4f6a8b9f3 -r9f7c5de17f8e3d832da0888f138fb7602cc33a78 --- firmware/App/Modes/FPModes/ModePreGenPermeateDefeatured.c (.../ModePreGenPermeateDefeatured.c) (revision 47a7b0fce13cf38919932a8662c378f4f6a8b9f3) +++ firmware/App/Modes/FPModes/ModePreGenPermeateDefeatured.c (.../ModePreGenPermeateDefeatured.c) (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -15,14 +15,14 @@ * ***************************************************************************/ -#include "FlushFilterDefeatured.h" #include "FPModeStandby.h" #include "FPOperationModes.h" -#include "InletPressureCheck.h" #include "Messaging.h" #include "MessageSupport.h" #include "ModeGenPermeateDefeatured.h" #include "ModePreGenPermeateDefeatured.h" +#include "StateFlushFilterDefeatured.h" +#include "StateInletPressureCheck.h" #include "TaskGeneral.h" #include "Timers.h" #include "Valves.h" Index: firmware/App/Modes/FPModes/StateFlushConcentrate.c =================================================================== diff -u --- firmware/App/Modes/FPModes/StateFlushConcentrate.c (revision 0) +++ firmware/App/Modes/FPModes/StateFlushConcentrate.c (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -0,0 +1,416 @@ +/************************************************************************** +* +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file StateFlushConcentrate.c +* +* @author (last) “rkallala” +* @date (last) 15-Jan-2026 +* +* @author (original) Michael Garthwaite +* @date (original) 08-Sep-2025 +* +***************************************************************************/ + +#include "Conductivity.h" +#include "BoostPump.h" +#include "FlowSensor.h" +#include "FPOperationModes.h" +#include "Level.h" +#include "MessageSupport.h" +#include "Messaging.h" +#include "PermeateTank.h" +#include "Pressure.h" +#include "ROPump.h" +#include "StateFlushConcentrate.h" +#include "TaskGeneral.h" +#include "Timers.h" +#include "Valves.h" +#include "WaterQualityMonitor.h" + +/** + * @addtogroup FPConcentrateFlush + * @{ + */ + +// ********** private definitions ********** + +#define CONCENTRATE_FLUSH_MAX_TIMEOUT ( 600 * MS_PER_SECOND ) ///< Max override timeout for 10 minutes +#define CONCENTRATE_FLUSH_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen water mode data published. +#define CONCENTRATE_FLUSH_TIMEOUT ( 30 * MS_PER_SECOND ) ///< Concentrate flush timer (in ms) +#define CONCENTRATE_FLUSH_RO_PUMP_TGT_PWM 0.8F ///< target in PWM % for the RO pump during concentrate flush. +#define CONCENTRATE_FLUSH_BOOST_PUMP_TGT_PSI 25 ///< Pressure target in PSI for the boost pump during concentrate flush. +#define CONCENTRATE_FLUSH_VOLUME_THRESHOLD_ML 1000.0F ///< Integrated volume threshold in ml +#define CONCENTRATE_FLUSH_VOLUME_THRESHOLD_PCT 0.9F ///< Integrated volume threshold percentage +#define CONCENTRATE_FLUSH_VOLUME_THRESHOLD CONCENTRATE_FLUSH_VOLUME_THRESHOLD_ML * CONCENTRATE_FLUSH_VOLUME_THRESHOLD_PCT ///< alarm threshold for integrated volume +#define CONCENTRATE_FLUSH_WAIT_FOR_TANK_FULL_TIMEOUT ( 60 * MS_PER_SECOND ) ///< Concentrate flush wait for tank full timer (in ms) +#define CONCENTRATE_FLUSH_WAIT_FOR_TANK_FULL_TGT_FLOW 700 ///< target flow rate for waiting for tank state +#define CONCENTRATE_FLUSH_BOOST_PUMP_TGT_PSI 25 ///< Pressure target in PSI for the boost pump during concentrate flush. +#define MIN_BOOST_PUMP_DUTY_CYCLE_PCT 0.5F ///< Minimum duty cycle value for boost pump during open loop control + +// ********** private data ********** + +static FP_CONC_FLUSH_STATE_T concentrateFlushState; ///< Currently active Concentrate flush state. +static U32 concentrateFlushDataPublicationTimerCounter; ///< Used to schedule Concentrate flush data publication to CAN bus. +static OVERRIDE_U32_T concentrateFlushDataPublishInterval; ///< Concentrate Flush mode data publish interval. +static OVERRIDE_U32_T concentrateFlushTimeout; ///< Concentrate Flush timeout value +static U32 concentrateFlushTimer; ///< Concentrate Flush timeout timer +static BOOL pendingStartConcentrateFlushRequest; ///< signal to start flushing. +static BOOL isFlushComplete; ///< Concentrate Flush complete BOOL +static BOOL isTankFilled; ///< Concentrate tank filled in permeate flush state + +// ********** private function prototypes ********** + +static void publishConcentrateFlushData( void ); +static FP_CONC_FLUSH_STATE_T handleConcentrateFlushProgressState( void ); +static FP_CONC_FLUSH_STATE_T handleConcentrateFlushPausedState( void ); +static void setConcentrateFlushTransition( FP_CONC_FLUSH_STATE_T state ); +static U32 getConcentrateFlushTimeout( void ); +static U32 getConcentrateFlushPublishInterval( void ); + +/*********************************************************************//** + * @brief + * The initConcentrateFlush function initializes the Concentrate flush unit. + * @details \b Inputs: none + * @details \b Outputs: Concentrate flush unit initialized + * @return none + *************************************************************************/ +void initConcentrateFlush( void ) +{ + concentrateFlushState = CONC_FLUSH_PAUSED; + concentrateFlushDataPublishInterval.data = CONCENTRATE_FLUSH_DATA_PUBLISH_INTERVAL; + concentrateFlushDataPublishInterval.ovData = CONCENTRATE_FLUSH_DATA_PUBLISH_INTERVAL; + concentrateFlushDataPublishInterval.ovInitData = 0; + concentrateFlushDataPublishInterval.override = OVERRIDE_RESET; + concentrateFlushTimeout.data = CONCENTRATE_FLUSH_TIMEOUT; + concentrateFlushTimeout.ovData = CONCENTRATE_FLUSH_TIMEOUT; + concentrateFlushTimeout.ovInitData = 0; + concentrateFlushTimeout.override = OVERRIDE_RESET; + concentrateFlushDataPublicationTimerCounter = 0; + concentrateFlushTimer = 0; + isFlushComplete = FALSE; + pendingStartConcentrateFlushRequest = FALSE; + isTankFilled = FALSE; +} + +/*********************************************************************//** + * @brief + * The execConcentrateFlush function executes the Concentrate flush state machine + * and publishes Concentrate flush data. + * @details \b Inputs: concentrateFlushState + * @details \b Outputs: concentrateFlushState + * @details \b Alarm: ALARM_ID_FP_SOFTWARE_FAULT if in invalid flush state + * @return none + *************************************************************************/ +void execConcentrateFlush( void ) +{ + FP_CONC_FLUSH_STATE_T prevState = concentrateFlushState; + + switch ( concentrateFlushState ) + { + case CONC_FLUSH_IN_PROGRESS: + concentrateFlushState = handleConcentrateFlushProgressState(); + break; + + case CONC_FLUSH_PAUSED: + concentrateFlushState = handleConcentrateFlushPausedState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_CONCENTRATE_FLUSH_STATE, (U32)concentrateFlushState ) + concentrateFlushState = CONC_FLUSH_PAUSED; + break; + } + + if ( prevState != concentrateFlushState ) + { + setConcentrateFlushTransition( concentrateFlushState ); + } + // publish Concentrate flush data on interval + publishConcentrateFlushData(); +} + +/*********************************************************************//** + * @brief + * The handleConcentrateFlushProgressState handles the in progress state of Concentrate flush + * @details \b Inputs: concentrateFlushTimer + * @details \b Outputs: isFlushComplete + * @return the next state of Concentrate flush state + *************************************************************************/ +static FP_CONC_FLUSH_STATE_T handleConcentrateFlushProgressState( void ) +{ + FP_CONC_FLUSH_STATE_T state = CONC_FLUSH_IN_PROGRESS; + LEVEL_STATE_T level = getLevelStatus( P25_LEVL ); + +// if ( TRUE == 1 ) )// TODO Alarm and Stop State Rework +// { +// state = CONC_FLUSH_PAUSED; +// } + + if ( TRUE == didTimeout( concentrateFlushTimer, getConcentrateFlushTimeout() ) ) + { + isFlushComplete = TRUE; + state = CONC_FLUSH_PAUSED; + } + // Manual control of Permeate tank to prevent over fill. + if ( LEVEL_STATE_HIGH == level ) + { + setValveState( M4_VALV, VALVE_STATE_CLOSED ); + if ( TRUE == isBoostPumpInstalled() ) + { + F32 currentDutyCyclePct = getCurrentBoostPumpDutyCyclePCT() > MIN_BOOST_PUMP_DUTY_CYCLE_PCT ? getCurrentBoostPumpDutyCyclePCT(): MIN_BOOST_PUMP_DUTY_CYCLE_PCT; + + setBoostPumpTargetDutyCycle( currentDutyCyclePct ); + isTankFilled = TRUE; + } + } + else if ( LEVEL_STATE_LOW == level ) + { + setValveState( M4_VALV, VALVE_STATE_OPEN ); + // set boost pump to closed loop when M4 closed. Added Tank fill check to avoid reset during initial transition + if ( ( TRUE == isBoostPumpInstalled() ) && ( TRUE == isTankFilled ) ) + { + setBoostPumpTargetPressure( CONCENTRATE_FLUSH_BOOST_PUMP_TGT_PSI ); + isTankFilled = FALSE; + } + + checkROInletPressure(); + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleConcentrateFlushPausedState handles the paused state of Concentrate flush + * @details \b Inputs: pendingStartConcentrateFlushRequest + * @details \b Outputs: isFlushComplete, pendingStartConcentrateFlushRequest + * @return the next state of Concentrate flush state + *************************************************************************/ +static FP_CONC_FLUSH_STATE_T handleConcentrateFlushPausedState( void ) +{ + FP_CONC_FLUSH_STATE_T state = CONC_FLUSH_PAUSED; + + if ( TRUE == pendingStartConcentrateFlushRequest ) + { + isFlushComplete = FALSE; + pendingStartConcentrateFlushRequest = FALSE; + state = CONC_FLUSH_IN_PROGRESS; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The setConcentrateFlushTransition function sets the actuators and variables + * for the state transition in Concentrate flush mode. + * @details Inputs: Valve states, Pump speed + * @details Outputs: Actuate valves, pumps as desired. + * @param state Concentrate flush state enum + * @return none + *************************************************************************/ +static void setConcentrateFlushTransition( FP_CONC_FLUSH_STATE_T state ) +{ + // Execute on running state + switch( state ) + { + case CONC_FLUSH_IN_PROGRESS: + setValveState( M4_VALV, VALVE_STATE_OPEN ); + setValveState( M12_VALV, VALVE_STATE_OPEN ); + setValveState( P6_VALV, VALVE_STATE_CLOSED ); + setValveState( P11_VALV, VALVE_STATE_OPEN ); + setValveState( P33_VALV, VALVE_STATE_CLOSED ); + setValveState( P34_VALV, VALVE_STATE_CLOSED ); + setValveState( P37_VALV, VALVE_STATE_OPEN ); + setValveState( P39_VALV, VALVE_STATE_OPEN ); + if ( TRUE == isBoostPumpInstalled() ) + { + setBoostPumpTargetPressure( CONCENTRATE_FLUSH_BOOST_PUMP_TGT_PSI ); + } + setROPumpTargetDutyCycle( CONCENTRATE_FLUSH_RO_PUMP_TGT_PWM, TRUE ); + concentrateFlushTimer = getMSTimerCount(); + break; + + case CONC_FLUSH_PAUSED: + // Stop pumps and close only if we alarm ( pause ) during flush. + if ( FALSE == isConcentrateFlushComplete() ) + { + setValveState( M4_VALV, VALVE_STATE_CLOSED ); + setValveState( M12_VALV, VALVE_STATE_CLOSED ); + setValveState( P6_VALV, VALVE_STATE_CLOSED ); + setValveState( P11_VALV, VALVE_STATE_CLOSED ); + setValveState( P33_VALV, VALVE_STATE_CLOSED ); + setValveState( P34_VALV, VALVE_STATE_CLOSED ); + setValveState( P37_VALV, VALVE_STATE_CLOSED ); + setValveState( P39_VALV, VALVE_STATE_CLOSED ); + if ( TRUE == isBoostPumpInstalled() ) + { + signalBoostPumpHardStop(); + } + signalROPumpHardStop(); + } + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_CONCENTRATE_FLUSH_STATE, state ) + break; + } +} + +/*********************************************************************//** + * @brief + * The signalStartConcentrateFlush function signals the FP to start Concentrate flush. + * @details \b Inputs: none + * @details \b Outputs: pendingStartConcentrateFlushRequest + * @return TRUE if the start signal is set, FALSE if not + *************************************************************************/ +BOOL signalStartConcentrateFlush( void ) +{ + BOOL result = FALSE; + + if ( CONC_FLUSH_PAUSED == getCurrentConcentrateFlushState() ) + { + result = TRUE; + pendingStartConcentrateFlushRequest = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The resetFilterFlushSignals function resets the signal values for + * FP filter flush. + * @details \b Inputs: none + * @details \b Outputs: pendingStartFilterFlushRequest, isFlushComplete + * @return none + *************************************************************************/ +void resetConcentrateFlushSignals( void ) +{ + pendingStartConcentrateFlushRequest = FALSE; + isFlushComplete = FALSE; +} + +/*********************************************************************//** + * @brief + * The getCurrentConcentrateFlushState function returns the current state of + * Concentrate flush. + * @details \b Inputs: concentrateFlushState + * @details \b Outputs: none + * @return the current state of Concentrate flush + *************************************************************************/ +FP_CONC_FLUSH_STATE_T getCurrentConcentrateFlushState( void ) +{ + return concentrateFlushState; +} + +/*********************************************************************//** + * @brief + * The isConcentrateFlushComplete function returns isConcentrateFlushComplete. + * @details \b Inputs: isFlushComplete + * @details \b Outputs: none + * @return TRUE if concentrate flush is complete, FALSE if not. + *************************************************************************/ +BOOL isConcentrateFlushComplete( void ) +{ + return isFlushComplete; +} + +/*********************************************************************//** + * @brief + * The getConcentrateFlushTimeout function gets the generate water + * mode data publish interval. + * @details \b Inputs: ConcentrateFlushTimeOut + * @details \b Outputs: none + * @return the concentrate flush timeout period in ms. + *************************************************************************/ +static U32 getConcentrateFlushTimeout( void ) +{ + U32 result = getU32OverrideValue( &concentrateFlushTimeout ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getConcentrateFlushPublishInterval function gets the Concentrate flush + * mode data publish interval. + * @details \b Inputs: concentrateFlushDataPublishInterval + * @details \b Outputs: none + * @return the interval at Concentrate flush mode data being published. + *************************************************************************/ +static U32 getConcentrateFlushPublishInterval( void ) +{ + U32 result = getU32OverrideValue( &concentrateFlushDataPublishInterval ); + + return result; +} + +/*********************************************************************//** + * @brief + * The publishConcentrateFlushData function broadcasts the Concentrate flush + * mode data at defined interval. + * @details \b Inputs: concentrateFlushDataPublicationTimerCounter + * @details \b Outputs: fp Concentrate flush data broadcast message sent + * @details \b Message \b Sent: MSG_ID_FP_CONCENTRATE_FLUSH_DATA to publish the + * Concentrate flush mode data. + * @return none + *************************************************************************/ +static void publishConcentrateFlushData( void ) +{ + if ( ++concentrateFlushDataPublicationTimerCounter >= getConcentrateFlushPublishInterval() ) + { + CONC_FLUSH_DATA_T data; + + data.concentrateFlushExecState = (U32)getCurrentConcentrateFlushState(); + broadcastData( MSG_ID_FP_CONCENTRATE_FLUSH_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( CONC_FLUSH_DATA_T ) ); + + concentrateFlushDataPublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testConcentrateFlushDataPublishIntervalOverride function overrides the + * FP Concentrate flush mode data publish interval. + * @details \b Inputs: concentrateFlushDataPublishInterval + * @details \b Outputs: concentrateFlushDataPublishInterval + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP Concentrate flush data publish interval to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testConcentrateFlushDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &concentrateFlushDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testConcentrateFlushTimerOverride function overrides the + * FP Concentrate flush timeout value. + * @details \b Inputs: concentrateFlushTimeout + * @details \b Outputs: concentrateFlushTimeout + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP Concentrate flush timeout to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testConcentrateFlushTimerOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &concentrateFlushTimeout, 0, CONCENTRATE_FLUSH_MAX_TIMEOUT ); + + return result; +} + +/**@}*/ Index: firmware/App/Modes/FPModes/StateFlushConcentrate.h =================================================================== diff -u --- firmware/App/Modes/FPModes/StateFlushConcentrate.h (revision 0) +++ firmware/App/Modes/FPModes/StateFlushConcentrate.h (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -0,0 +1,57 @@ +/************************************************************************** +* +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file StateFlushConcentrate.h +* +* @author (last) Sean Nash +* @date (last) 12-Sep-2025 +* +* @author (original) Michael Garthwaite +* @date (original) 08-Sep-2025 +* +***************************************************************************/ + +#ifndef __STATE_FLUSH_CONCENTRATE_H__ +#define __STATE_FLUSH_CONCENTRATE_H__ + +#include "DDDefs.h" +#include "DDCommon.h" +#include "FPDefs.h" + +/** + * @defgroup FPConcentrateFlush FPConcentrateFlush + * @brief Concentrate Flush unit. Manages Concentrate flush functions via a state machine. + * + * @addtogroup FPConcentrateFlush + * @{ + */ + +// ********** public definitions ********** + +/// Concentrate Flush data structure +typedef struct +{ + U32 concentrateFlushExecState; ///< Concentrate Flush execution state +} CONC_FLUSH_DATA_T; + +// ********** public function prototypes ********** + +void initConcentrateFlush( void ); // Initialize this Concentrate Flush unit +U32 transitionToConcentrateFlush( void ); // Transition to Concentrate Flush +void execConcentrateFlush( void ); // Execute the Concentrate Flush state machine +BOOL isConcentrateFlushComplete( void ); // returns if flush is complete +BOOL signalStartConcentrateFlush( void ); // signal to start flush +void resetConcentrateFlushSignals( void ); // reset signals for flush + +FP_CONC_FLUSH_STATE_T getCurrentConcentrateFlushState( void ); // Get the current state of the Concentrate Flush + +BOOL testConcentrateFlushDataPublishIntervalOverride( MESSAGE_T *message ); +BOOL testConcentrateFlushTimerOverride( MESSAGE_T *message ); + +/**@}*/ + +#endif Index: firmware/App/Modes/FPModes/StateFlushFilter.c =================================================================== diff -u --- firmware/App/Modes/FPModes/StateFlushFilter.c (revision 0) +++ firmware/App/Modes/FPModes/StateFlushFilter.c (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -0,0 +1,385 @@ +/************************************************************************** +* +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file StateFlushFilter.c +* +* @author (last) “rkallala” +* @date (last) 15-Jan-2026 +* +* @author (original) Michael Garthwaite +* @date (original) 08-Sep-2025 +* +***************************************************************************/ + +#include "BoostPump.h" +#include "FPOperationModes.h" +#include "MessageSupport.h" +#include "Messaging.h" +#include "PersistentAlarm.h" +#include "Pressure.h" +#include "ROPump.h" +#include "StateFlushFilter.h" +#include "TaskGeneral.h" +#include "Temperature.h" +#include "Timers.h" +#include "Valves.h" + +/** + * @addtogroup FPFilterFlush + * @{ + */ + +// ********** private definitions ********** + +#define FILTER_FLUSH_MAX_TIMEOUT ( 600 * MS_PER_SECOND ) ///< Max override timeout for 10 minutes +#define FILTER_FLUSH_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen water mode data published. +#define FILTER_FLUSH_TIMEOUT ( 3 * SEC_PER_MIN * MS_PER_SECOND ) ///< Filter flush timeout for 3 minutes (in ms) +#define FILTER_FLUSH_BOOST_PUMP_TGT_PSI 25 ///< Pressure target in PSI for the boost pump during filter flush. +#define MAX_INLET_TEMPERATURE_HIGH_PSI_C 40.0F ///< Maximum allowed Inlet temperature in C. +#define INLET_TEMPERATURE_PERSISTENCE_CLEAR_MS ( 5 * MS_PER_SECOND ) ///< Persistence timer to clear alarm in ms. +#define INLET_TEMPERATURE_PERSISTENCE_TIMER_MS ( 5 * MS_PER_SECOND ) ///< Persistence timer to trigger alarm in ms. +#define INLET_TEMPERATURE_CRITICAL_THRESHOLD_C 40.0F ///< Maximum allowed M3 Inlet temperature in C during filters flush state. + +// ********** private data ********** + +static FP_FILTER_FLUSH_STATE_T filterFlushState; ///< Currently active filter flush state. +static U32 filterFlushDataPublicationTimerCounter; ///< Used to schedule filter flush data publication to CAN bus. +static OVERRIDE_U32_T filterFlushDataPublishInterval; ///< Filter Flush mode data publish interval. +static OVERRIDE_U32_T filterFlushTimeout; ///< Filter Flush timeout value +static U32 filterFlushTimer; ///< Filter Flush timeout timer +static BOOL pendingStartFilterFlushRequest; ///< signal to start flushing. +static BOOL isFlushComplete; ///< Filter Flush complete BOOL + +// ********** private function prototypes ********** + +static void publishFilterFlushData( void ); +static FP_FILTER_FLUSH_STATE_T handleFilterFlushProgressState( void ); +static FP_FILTER_FLUSH_STATE_T handleFilterFlushPausedState( void ); +static void setFilterFlushTransition( FP_FILTER_FLUSH_STATE_T state ); +static U32 getFilterFlushTimeout( void ); +static U32 getFilterFlushPublishInterval( void ); + +/*********************************************************************//** + * @brief + * The initFilterFlush function initializes the filter flush unit. + * @details \b Inputs: none + * @details \b Outputs: filter flush unit initialized + * @return none + *************************************************************************/ +void initFilterFlush( void ) +{ + filterFlushState = FILTER_FLUSH_PAUSED; + filterFlushDataPublishInterval.data = FILTER_FLUSH_DATA_PUBLISH_INTERVAL; + filterFlushDataPublishInterval.ovData = FILTER_FLUSH_DATA_PUBLISH_INTERVAL; + filterFlushDataPublishInterval.ovInitData = 0; + filterFlushDataPublishInterval.override = OVERRIDE_RESET; + filterFlushTimeout.data = FILTER_FLUSH_TIMEOUT; + filterFlushTimeout.ovData = FILTER_FLUSH_TIMEOUT; + filterFlushTimeout.ovInitData = 0; + filterFlushTimeout.override = OVERRIDE_RESET; + filterFlushDataPublicationTimerCounter = 0; + filterFlushTimer = 0; + isFlushComplete = FALSE; + pendingStartFilterFlushRequest = FALSE; + + initPersistentAlarm( ALARM_ID_FP_INLET_TEMPERATURE_OUT_CRITICAL_RANGE, INLET_TEMPERATURE_PERSISTENCE_CLEAR_MS, INLET_TEMPERATURE_PERSISTENCE_TIMER_MS ); +} + +/*********************************************************************//** + * @brief + * The execFilterFlush function executes the filter flush state machine + * and publishes filter flush data. + * @details \b Inputs: filterFlushState + * @details \b Outputs: filterFlushState + * @details \b Alarm: ALARM_ID_FP_SOFTWARE_FAULT if in invalid flush state + * @return none + *************************************************************************/ +void execFilterFlush( void ) +{ + FP_FILTER_FLUSH_STATE_T prevState = filterFlushState; + + switch ( filterFlushState ) + { + case FILTER_FLUSH_IN_PROGRESS: + filterFlushState = handleFilterFlushProgressState(); + break; + + case FILTER_FLUSH_PAUSED: + filterFlushState = handleFilterFlushPausedState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_FILTER_FLUSH_STATE, (U32)filterFlushState ) + filterFlushState = FILTER_FLUSH_PAUSED; + break; + } + + if ( prevState != filterFlushState ) + { + setFilterFlushTransition( filterFlushState ); + } + + // publish filter flush data on interval + publishFilterFlushData(); +} + +/*********************************************************************//** + * @brief + * The handleFilterFlushProgressState handles the in progress state of filter flush + * @details \b Inputs: filterFlushTimer + * @details \b Outputs: isFlushComplete + * @return the next state of filter flush state + *************************************************************************/ +static FP_FILTER_FLUSH_STATE_T handleFilterFlushProgressState( void ) +{ + FP_FILTER_FLUSH_STATE_T state = FILTER_FLUSH_IN_PROGRESS; + F32 temperatureM3 = getFilteredPressureSensorTemperature( M3_PRES ); + BOOL isTempOutOfHighRange = FALSE; + +// if ( TRUE == 1 )// TODO Alarm and Stop State Rework +// { +// state = FILTER_FLUSH_PAUSED; +// } + + isTempOutOfHighRange = ( ( temperatureM3 >= INLET_TEMPERATURE_CRITICAL_THRESHOLD_C ) ? TRUE : FALSE ); + checkPersistentAlarm( ALARM_ID_FP_INLET_TEMPERATURE_OUT_CRITICAL_RANGE, isTempOutOfHighRange, temperatureM3, INLET_TEMPERATURE_CRITICAL_THRESHOLD_C ); + + if( TRUE == didTimeout( filterFlushTimer, getFilterFlushTimeout() ) ) + { + isFlushComplete = TRUE; + state = FILTER_FLUSH_PAUSED; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleFilterFlushPausedState handles the pause state of filter flush + * @details \b Inputs: pendingStartFilterFlushRequest + * @details \b Outputs: pendingStartFilterFlushRequest, isFlushComplete + * @return the next state of filter flush state + *************************************************************************/ +static FP_FILTER_FLUSH_STATE_T handleFilterFlushPausedState( void ) +{ + FP_FILTER_FLUSH_STATE_T state = FILTER_FLUSH_PAUSED; + + if ( TRUE == pendingStartFilterFlushRequest ) + { + isFlushComplete = FALSE; + pendingStartFilterFlushRequest = FALSE; + state = FILTER_FLUSH_IN_PROGRESS; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The setFilterFlushTransition function sets the actuators and variables + * for the state transition in filter flush mode. + * @details Inputs: Valve states, Pump speed + * @details Outputs: Actuate valves, pumps as desired. + * @param state filter flush state enum + * @return none + *************************************************************************/ +static void setFilterFlushTransition( FP_FILTER_FLUSH_STATE_T state ) +{ + // Execute on running state + switch( state ) + { + case FILTER_FLUSH_IN_PROGRESS: + setValveState( M4_VALV, VALVE_STATE_OPEN ); + setValveState( M12_VALV, VALVE_STATE_OPEN ); + setValveState( P6_VALV, VALVE_STATE_OPEN ); + setValveState( P11_VALV, VALVE_STATE_CLOSED ); + setValveState( P33_VALV, VALVE_STATE_CLOSED ); + setValveState( P34_VALV, VALVE_STATE_CLOSED ); + setValveState( P37_VALV, VALVE_STATE_CLOSED ); + setValveState( P39_VALV, VALVE_STATE_OPEN ); + + if ( TRUE == isBoostPumpInstalled() ) + { + setBoostPumpTargetPressure( FILTER_FLUSH_BOOST_PUMP_TGT_PSI ); + } + signalROPumpHardStop(); + filterFlushTimer = getMSTimerCount(); + break; + + case FILTER_FLUSH_PAUSED: + // close only if we actually pause during flush + if ( FALSE == isFilterFlushComplete() ) + { + setValveState( M4_VALV, VALVE_STATE_CLOSED ); + setValveState( M12_VALV, VALVE_STATE_CLOSED ); + setValveState( P6_VALV, VALVE_STATE_CLOSED ); + setValveState( P11_VALV, VALVE_STATE_CLOSED ); + setValveState( P33_VALV, VALVE_STATE_CLOSED ); + setValveState( P34_VALV, VALVE_STATE_CLOSED ); + setValveState( P37_VALV, VALVE_STATE_CLOSED ); + setValveState( P39_VALV, VALVE_STATE_CLOSED ); + if ( TRUE == isBoostPumpInstalled() ) + { + signalBoostPumpHardStop(); + } + } + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_FILTER_FLUSH_STATE, state ) + break; + } +} + +/*********************************************************************//** + * @brief + * The signalStartFilterFlush function signals the FP to start filter flush. + * @details \b Inputs: filterFlushState + * @details \b Outputs: pendingStartFilterFlushRequest + * @return none + *************************************************************************/ +void signalStartFilterFlush( void ) +{ + if ( FILTER_FLUSH_PAUSED == getCurrentFilterFlushState() ) + { + pendingStartFilterFlushRequest = TRUE; + } +} + +/*********************************************************************//** + * @brief + * The resetFilterFlushSignals function resets the signal values for + * FP filter flush. + * @details \b Inputs: none + * @details \b Outputs: pendingStartFilterFlushRequest, isFlushComplete + * @return none + *************************************************************************/ +void resetFilterFlushSignals( void ) +{ + pendingStartFilterFlushRequest = FALSE; + isFlushComplete = FALSE; +} + +/*********************************************************************//** + * @brief + * The getCurrentFilterFlushState function returns the current state of + * filter flush. + * @details \b Inputs: none + * @details \b Outputs: none + * @return the current state of filter flush + *************************************************************************/ +FP_FILTER_FLUSH_STATE_T getCurrentFilterFlushState( void ) +{ + return filterFlushState; +} + +/*********************************************************************//** + * @brief + * The isFilterFlushComplete function returns isFilterFlushComplete. + * @details \b Inputs: isFlushComplete + * @details \b Outputs: none + * @return TRUE if filter flush is complete, FALSE if not. + *************************************************************************/ +BOOL isFilterFlushComplete( void ) +{ + return isFlushComplete; +} + +/*********************************************************************//** + * @brief + * The getFilterFlushTimeout function gets the generate water + * mode data publish interval. + * @details \b Inputs: filterFlushTimeOut + * @details \b Outputs: none + * @return the timeout timer for filter flush. + *************************************************************************/ +static U32 getFilterFlushTimeout( void ) +{ + U32 result = getU32OverrideValue( &filterFlushTimeout ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getFilterFlushPublishInterval function gets the filter flush + * mode data publish interval. + * @details \b Inputs: filterFlushDataPublishInterval + * @details \b Outputs: none + * @return the interval at filter flush mode data being published. + *************************************************************************/ +static U32 getFilterFlushPublishInterval( void ) +{ + U32 result = getU32OverrideValue( &filterFlushDataPublishInterval ); + + return result; +} + +/*********************************************************************//** + * @brief + * The publishFilterFlushData function broadcasts the filter flush + * mode data at defined interval. + * @details \b Inputs: filterFlushDataPublicationTimerCounter + * @details \b Outputs: fp filter flush data broadcast message sent + * @details \b Message \b Sent: MSG_ID_FP_FILTER_FLUSH_DATA to publish the + * filter flush mode data. + * @return none + *************************************************************************/ +static void publishFilterFlushData( void ) +{ + if ( ++filterFlushDataPublicationTimerCounter >= getFilterFlushPublishInterval() ) + { + FILTER_FLUSH_DATA_T data; + + data.filterFlushExecState = (U32)getCurrentFilterFlushState(); + broadcastData( MSG_ID_FP_FILTER_FLUSH_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( FILTER_FLUSH_DATA_T ) ); + + filterFlushDataPublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testFilterFlushDataPublishIntervalOverride function overrides the + * FP filter flush mode data publish interval. + * @details \b Inputs: filterFlushDataPublishInterval + * @details \b Outputs: filterFlushDataPublishInterval + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP filter flush data publish interval to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testFilterFlushDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &filterFlushDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testFilterFlushTimerOverride function overrides the + * FP filter flush timeout value. + * @details \b Inputs: filterFlushTimeout + * @details \b Outputs: filterFlushTimeout + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP filter flush timeout to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testFilterFlushTimerOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &filterFlushTimeout, 0, FILTER_FLUSH_MAX_TIMEOUT ); + + return result; +} + +/**@}*/ Index: firmware/App/Modes/FPModes/StateFlushFilter.h =================================================================== diff -u --- firmware/App/Modes/FPModes/StateFlushFilter.h (revision 0) +++ firmware/App/Modes/FPModes/StateFlushFilter.h (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -0,0 +1,57 @@ +/************************************************************************** +* +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file StateFlushFilter.h +* +* @author (last) Sean Nash +* @date (last) 12-Sep-2025 +* +* @author (original) Michael Garthwaite +* @date (original) 08-Sep-2025 +* +***************************************************************************/ + +#ifndef __STATE_FLUSH_FILTER_H__ +#define __STATE_FLUSH_FILTER_H__ + +#include "DDDefs.h" +#include "DDCommon.h" +#include "FPDefs.h" + +/** + * @defgroup FPFilterFlush FPFilterFlush + * @brief Filter Flush unit. Manages filter flush functions via a state machine. + * + * @addtogroup FPFilterFlush + * @{ + */ + +// ********** public definitions ********** + +/// Filter Flush data structure +typedef struct +{ + U32 filterFlushExecState; ///< Filter Flush execution state +} FILTER_FLUSH_DATA_T; + +// ********** public function prototypes ********** + +void initFilterFlush( void ); // Initialize this Filter Flush unit +U32 transitionToFilterFlush( void ); // Transition to Filter Flush +void execFilterFlush( void ); // Execute the Filter Flush state machine +BOOL isFilterFlushComplete( void ); // returns if flush is complete +void signalStartFilterFlush( void ); // signal to start flush +void resetFilterFlushSignals( void ); // reset signals for flush + +FP_FILTER_FLUSH_STATE_T getCurrentFilterFlushState( void ); // Get the current state of the Filter Flush + +BOOL testFilterFlushDataPublishIntervalOverride( MESSAGE_T *message ); +BOOL testFilterFlushTimerOverride( MESSAGE_T *message ); + +/**@}*/ + +#endif Index: firmware/App/Modes/FPModes/StateFlushFilterDefeatured.c =================================================================== diff -u --- firmware/App/Modes/FPModes/StateFlushFilterDefeatured.c (revision 0) +++ firmware/App/Modes/FPModes/StateFlushFilterDefeatured.c (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -0,0 +1,440 @@ +/************************************************************************** +* +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file StateFlushFilterDefeatured.c +* +* @author (last) “rkallala” +* @date (last) 15-Jan-2026 +* +* @author (original) Sameer Kalliadan Poyil +* @date (original) 17-Dec-2025 +* +***************************************************************************/ + +#include "BoostPump.h" +#include "FPOperationModes.h" +#include "MessageSupport.h" +#include "Messaging.h" +#include "PersistentAlarm.h" +#include "Pressure.h" +#include "StateFlushFilterDefeatured.h" +#include "TaskGeneral.h" +#include "Timers.h" +#include "Valves.h" +#include "WaterQualityMonitor.h" + +/** + * @addtogroup FPFilterFlushDefeatured + * @{ + */ + +// ********** private definitions ********** + +#define FILTER_FLUSH_DYNAMIC_PRESSURE_MAX_TIMEOUT ( 10 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max override timeout for 10 minutes +#define FILTER_FLUSH_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen water mode data published. +#define FILTER_FLUSH_TIMEOUT ( 5 * MS_PER_SECOND ) ///< Filter flush timeout for 5 seconds (in ms) +#define FILTER_FLUSH_STATIC_PRESSURE_CHECK_TIMEOUT ( 1 * MS_PER_SECOND ) ///< Filter flush timeout for 5 second (in ms) +#define MAX_INLET_WATER_PRESSURE_DEFEATURED_FAULT_HIGH_PSIG 40 ///< maximum dynamic M3 pressure is within range < 40 +#define MIN_FILTER_FLUSH_PRESSURE_DEFEATURED_LOW_PSIG 5.0F ///< Minimum allowed Input warning low pressure value in psig for RO Defeatured. +#define MAX_FILTER_FLUSH_PRESSURE_DEFEATURED_HIGH_PSIG 10.0F ///< Maximum allowed Input warning high pressure value in psig for RO Defeatured. + +// ********** private data ********** + +static FP_FILTER_FLUSH_DEF_STATE_T filterFlushDefState; ///< Currently active defeatured filter flush state. +static U32 filterFlushDefDataPublicationTimerCounter; ///< Used to schedule defeatured filter flush data publication to CAN bus. +static OVERRIDE_U32_T filterFlushDefDataPublishInterval; ///< Defeatured filter flush data publish interval. +static OVERRIDE_U32_T filterFlushDefDynamicPressureTimeout; ///< Defeatured filter flush timeout value for dynamic pressure check +static U32 filterFlushDefDynamicPressureTimer; ///< Defeatured filter flush timeout timer for dynamic pressure check +static U32 filterFlushDefStaticPressureTimer; ///< Defeatured filter flush timeout timer for static pressure check +static BOOL pendingStartFilterFlushDefRequest; ///< Signal to start defeatured filter flush +static BOOL isFlushDefComplete; ///< Defeatured filter flush complete + +// ********** private function prototypes ********** + +static void publishFilterFlushDefData( void ); +static FP_FILTER_FLUSH_DEF_STATE_T handleFilterFlushDefDynamicPressureCheckState( void ); +static FP_FILTER_FLUSH_DEF_STATE_T handleFilterFlushDefStaticPressureCheckState( void ); +static FP_FILTER_FLUSH_DEF_STATE_T handleFilterFlushDefPausedState( void ); +static void setFilterFlushDefTransition( FP_FILTER_FLUSH_DEF_STATE_T state ); +static U32 getFilterFlushDefTimeout( void ); +static U32 getFilterFlushDefPublishInterval( void ); + +/*********************************************************************//** + * @brief + * The initFilterFlushDefeatured function initializes the de-featured filter flush unit. + * @details \b Inputs: none + * @details \b Outputs: de-featured filter flush unit initialized + * @return none + *************************************************************************/ +void initFilterFlushDefeatured( void ) +{ + filterFlushDefState = FILTER_FLUSH_DEF_PAUSED; + + filterFlushDefDataPublishInterval.data = FILTER_FLUSH_DATA_PUBLISH_INTERVAL; + filterFlushDefDataPublishInterval.ovData = FILTER_FLUSH_DATA_PUBLISH_INTERVAL; + filterFlushDefDataPublishInterval.ovInitData = 0; + filterFlushDefDataPublishInterval.override = OVERRIDE_RESET; + + filterFlushDefDynamicPressureTimeout.data = FILTER_FLUSH_TIMEOUT; + filterFlushDefDynamicPressureTimeout.ovData = FILTER_FLUSH_TIMEOUT; + filterFlushDefDynamicPressureTimeout.ovInitData = 0; + filterFlushDefDynamicPressureTimeout.override = OVERRIDE_RESET; + + filterFlushDefDataPublicationTimerCounter = 0; + filterFlushDefDynamicPressureTimer = 0; + filterFlushDefStaticPressureTimer = 0; + + isFlushDefComplete = 0; + pendingStartFilterFlushDefRequest = FALSE; +} + +/*********************************************************************//** + * @brief + * The transitionToFilterFlushDefeatured function prepares for transition to de-featured + * FilterFlush + * permeate mode. + * @details \b Inputs: genPermeateState + * @details \b Outputs: none + * @return initial state + *************************************************************************/ +U32 transitionToFilterFlushDefeatured( void ) +{ + initFilterFlushDefeatured(); + return 0; +} + +/*********************************************************************//** + * @brief + * The execFilterFlushDefeatured function executes the de-featured filter flush state machine + * and publishes filter flush data. + * @details \b Inputs: filterFlushDefState + * @details \b Outputs: filterFlushDefState + * @details \b Alarm: ALARM_ID_FP_SOFTWARE_FAULT if in invalid flush state + * @return none + *************************************************************************/ +void execFilterFlushDefeatured( void ) +{ + FP_FILTER_FLUSH_DEF_STATE_T prevState = filterFlushDefState; + + switch ( filterFlushDefState ) + { + case FILTER_FLUSH_DEF_DYNAMIC_PRESSURE_CHECK: + filterFlushDefState = handleFilterFlushDefDynamicPressureCheckState(); + checkInletTemperatures(); + break; + + case FILTER_FLUSH_DEF_STATIC_PRESSURE_CHECK: + filterFlushDefState = handleFilterFlushDefStaticPressureCheckState(); + break; + + case FILTER_FLUSH_DEF_PAUSED: + filterFlushDefState = handleFilterFlushDefPausedState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_FILTER_FLUSH_STATE, (U32)filterFlushDefState ) + filterFlushDefState = FILTER_FLUSH_DEF_PAUSED; + break; + } + + if ( prevState != filterFlushDefState ) + { + setFilterFlushDefTransition( filterFlushDefState ); + } + // publish filter flush data on interval + publishFilterFlushDefData(); +} + +/*********************************************************************//** + * @brief + * The getCurrentFilterFlushDefState function returns the current state of + * de-featured filter flush. + * @details \b Inputs: none + * @details \b Outputs: none + * @return the current state of filter flush + *************************************************************************/ +FP_FILTER_FLUSH_DEF_STATE_T getCurrentFilterFlushDefState( void ) +{ + return filterFlushDefState; +} + +/*********************************************************************//** + * @brief + * The isFilterFlushDefComplete function returns de-featured filter flush complete status. + * @details \b Inputs: isFlushComplete + * @details \b Outputs: none + * @return TRUE if filter flush is complete, FALSE if not. + *************************************************************************/ +BOOL isFilterFlushDefComplete( void ) +{ + return isFlushDefComplete; +} + +/*********************************************************************//** + * @brief + * The signalStartDefFilterFlush function signals the FP to start de-featured filter flush. + * @details \b Inputs: filterFlushDefState + * @details \b Outputs: pendingStartFilterFlushDefRequest + * @return none + *************************************************************************/ +void signalStartDefFilterFlush( void ) +{ + if ( FILTER_FLUSH_DEF_PAUSED == getCurrentFilterFlushDefState() ) + { + pendingStartFilterFlushDefRequest = TRUE; + } +} + +/*********************************************************************//** + * @brief + * The resetFilterFlushDefSignals function resets the signal values for + * FP de-featured filter flush. + * @details \b Inputs: none + * @details \b Outputs: pendingStartFilterFlushDefRequest, isFlushDefComplete + * @return none + *************************************************************************/ +void resetFilterFlushDefSignals( void ) +{ + pendingStartFilterFlushDefRequest = FALSE; + isFlushDefComplete = FALSE; +} + +/*********************************************************************//** + * @brief + * The handleFilterFlushDefDynamicPressureCheckState handles the Dynamic pressure check state + * of de-featured filter flush + * @details \b Inputs: filterFlushDefDynamicPressureTimer, m3Pressure + * @details \b Outputs: None + * @details \b Alarm: ALARM_ID_FP_INLET_PRESSURE_CRITICAL_OUT_RANGE + * when pressure is not in range during dynamic pressure check state + * @return the next state of de-featured filter flush state + *************************************************************************/ +static FP_FILTER_FLUSH_DEF_STATE_T handleFilterFlushDefDynamicPressureCheckState( void ) +{ + FP_FILTER_FLUSH_DEF_STATE_T state = FILTER_FLUSH_DEF_DYNAMIC_PRESSURE_CHECK; + F32 m3Pressure = getFilteredPressure( M3_PRES ); + + // check the dynamic pressure after 5 second + if( TRUE == didTimeout( filterFlushDefDynamicPressureTimer, getFilterFlushDefTimeout() ) ) + { + // check for inlet pressure (M3) within range < 40 + if( m3Pressure < MAX_INLET_WATER_PRESSURE_DEFEATURED_FAULT_HIGH_PSIG ) + { + // move to dynamic pressure check state + state = FILTER_FLUSH_DEF_STATIC_PRESSURE_CHECK; + } + else + { + // change the state to paused + state = FILTER_FLUSH_DEF_PAUSED; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_INLET_PRESSURE_CRITICAL_OUT_RANGE, m3Pressure, MAX_INLET_WATER_PRESSURE_DEFEATURED_FAULT_HIGH_PSIG ) + } + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleFilterFlushDefStaticPressureCheckState handles the static pressure check of the de-featured filter flush + * @details \b Inputs: filterFlushDefStaticPressureTimer, m3Pressure + * @details \b Outputs: isFlushDefComplete + * @return the next state of de-featured filter flush state + *************************************************************************/ +static FP_FILTER_FLUSH_DEF_STATE_T handleFilterFlushDefStaticPressureCheckState( void ) +{ + FP_FILTER_FLUSH_DEF_STATE_T state = FILTER_FLUSH_DEF_STATIC_PRESSURE_CHECK; + U32 minThreshold = MIN_FILTER_FLUSH_PRESSURE_DEFEATURED_LOW_PSIG; + U32 maxThreshold = MAX_FILTER_FLUSH_PRESSURE_DEFEATURED_HIGH_PSIG; + F32 m3Pressure = getFilteredPressure( M3_PRES ); + + // check for inlet pressure (M3) within range 5 -10 + if ( TRUE == didTimeout( filterFlushDefStaticPressureTimer, FILTER_FLUSH_STATIC_PRESSURE_CHECK_TIMEOUT ) ) + { + if ( ( m3Pressure >= minThreshold ) && ( m3Pressure <= maxThreshold ) ) + { + isFlushDefComplete = TRUE; + state = FILTER_FLUSH_DEF_PAUSED; + } + // when inlet pressure is < 5 + else if ( m3Pressure <= minThreshold ) + { + // Trigger alarm if M3 pressure is not within range + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_INLET_PRESSURE_OUT_LOW_RANGE, m3Pressure, minThreshold ); + state = FILTER_FLUSH_DEF_PAUSED; + } + // when inlet pressure is > 10 + else if ( m3Pressure >= maxThreshold ) + { + // Trigger alarm if M3 pressure is not within range + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_INLET_PRESSURE_OUT_HIGH_RANGE, m3Pressure, maxThreshold ); + state = FILTER_FLUSH_DEF_PAUSED; + } + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleFilterFlushDefPausedState handles the pause state of de-featured filter flush + * @details \b Inputs: pendingStartFilterFlushDefRequest + * @details \b Outputs: pendingStartFilterFlushDefRequest, isFlushDefComplete + * @return the next state of de-featured filter flush state + *************************************************************************/ +static FP_FILTER_FLUSH_DEF_STATE_T handleFilterFlushDefPausedState( void ) +{ + FP_FILTER_FLUSH_DEF_STATE_T state = FILTER_FLUSH_DEF_PAUSED; + + if ( TRUE == pendingStartFilterFlushDefRequest ) + { + isFlushDefComplete = FALSE; + pendingStartFilterFlushDefRequest = FALSE; + state = FILTER_FLUSH_DEF_DYNAMIC_PRESSURE_CHECK; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The setFilterFlushDefTransition function sets the actuators and variables + * for the state transition in de-featured filter flush mode. + * @details Inputs: Valve states, Pump speed + * @details Outputs: Actuate valves, pumps as desired. + * @param state de-featured de-featured filter flush state enum + * @return none + *************************************************************************/ +static void setFilterFlushDefTransition( FP_FILTER_FLUSH_DEF_STATE_T state ) +{ + // Execute on running state + switch( state ) + { + case FILTER_FLUSH_DEF_DYNAMIC_PRESSURE_CHECK: + setValveState( M4_VALV, VALVE_STATE_OPEN ); + setValveState( M12_VALV, VALVE_STATE_OPEN ); + setValveState( D52_VALV, VALVE_STATE_OPEN ); + filterFlushDefDynamicPressureTimer = getMSTimerCount(); + break; + + case FILTER_FLUSH_DEF_STATIC_PRESSURE_CHECK: + setValveState( M4_VALV, VALVE_STATE_CLOSED ); + setValveState( M12_VALV, VALVE_STATE_OPEN ); + setValveState( D52_VALV, VALVE_STATE_CLOSED ); + filterFlushDefStaticPressureTimer = getMSTimerCount(); + break; + + case FILTER_FLUSH_DEF_PAUSED: + // close only if we actually pause during flush + if ( FALSE == isFilterFlushDefComplete() ) + { + setValveState( M4_VALV, VALVE_STATE_CLOSED ); + setValveState( M12_VALV, VALVE_STATE_CLOSED ); + setValveState( D52_VALV, VALVE_STATE_CLOSED ); + } + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_FILTER_FLUSH_STATE, state ) + break; + } +} + +/*********************************************************************//** + * @brief + * The getFilterFlushDefTimeout function gets the generate water + * mode data publish interval. + * @details \b Inputs: filterFlushDefDynamicPressureTimeout + * @details \b Outputs: none + * @return the timeout timer for filter flush. + *************************************************************************/ +static U32 getFilterFlushDefTimeout( void ) +{ + U32 result = getU32OverrideValue( &filterFlushDefDynamicPressureTimeout ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getFilterFlushDefPublishInterval function gets the filter flush + * mode data publish interval. + * @details \b Inputs: filterFlushDefDataPublishInterval + * @details \b Outputs: none + * @return the interval at de-featured filter flush mode data being published. + *************************************************************************/ +static U32 getFilterFlushDefPublishInterval( void ) +{ + U32 result = getU32OverrideValue( &filterFlushDefDataPublishInterval ); + + return result; +} + +/*********************************************************************//** + * @brief + * The publishFilterFlushDefData function broadcasts the de-featured filter flush + * mode data at defined interval. + * @details \b Inputs: filterFlushDefDataPublicationTimerCounter + * @details \b Outputs: fp filter flush de-featured data broadcast message sent + * @details \b Message \b Sent: MSG_ID_FP_FILTER_FLUSH_DEF_DATA to publish the + * filter flush mode data. + * @return none + *************************************************************************/ +static void publishFilterFlushDefData( void ) +{ + if ( ++filterFlushDefDataPublicationTimerCounter >= getFilterFlushDefPublishInterval() ) + { + FILTER_FLUSH_DEF_DATA_T data; + + data.filterFlushDefExecState = (U32)getCurrentFilterFlushDefState(); + broadcastData( MSG_ID_FP_FILTER_FLUSH_DEF_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( FILTER_FLUSH_DEF_DATA_T ) ); + + filterFlushDefDataPublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testFilterFlushDefDataPublishIntervalOverride function overrides the + * FP filter flush de-featured mode data publish interval. + * @details \b Inputs: filterFlushDefDataPublishInterval + * @details \b Outputs: filterFlushDefDataPublishInterval + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP filter flush de-featured data publish interval to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testFilterFlushDefDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &filterFlushDefDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testFilterFlushDefTimerOverride function overrides the + * FP filter flush timeout value. + * @details \b Inputs: filterFlushDefDynamicPressureTimeout + * @details \b Outputs: filterFlushDefDynamicPressureTimeout + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP filter flush timeout to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testFilterFlushDefTimerOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &filterFlushDefDynamicPressureTimeout, 0, FILTER_FLUSH_DYNAMIC_PRESSURE_MAX_TIMEOUT ); + + return result; +} + +/**@}*/ Index: firmware/App/Modes/FPModes/StateFlushFilterDefeatured.h =================================================================== diff -u --- firmware/App/Modes/FPModes/StateFlushFilterDefeatured.h (revision 0) +++ firmware/App/Modes/FPModes/StateFlushFilterDefeatured.h (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -0,0 +1,56 @@ +/************************************************************************** +* +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file StateFlushFilterDefeatured.h +* +* @author (last) “rkallala” +* @date (last) 15-Jan-2026 +* +* @author (original) Sameer Kalliadan Poyil +* @date (original) 17-Dec-2025 +* +***************************************************************************/ + +#ifndef __STATE_FLUSH_FILTER_DEFEATURED_H__ +#define __STATE_FLUSH_FILTER_DEFEATURED_H__ + +#include "DDDefs.h" +#include "DDCommon.h" +#include "FPDefs.h" + +/** + * @defgroup FPFilterFlushDefeatured FPFilterFlushDefeatured + * @brief Filter Flush unit. Manages de-featured filter flush functions via a state machine. + * + * @addtogroup FPFilterFlushDefeatured + * @{ + */ + +// ********** public definitions ********** + +/// Filter Flush data structure +typedef struct +{ + U32 filterFlushDefExecState; ///< Filter Flush execution state +} FILTER_FLUSH_DEF_DATA_T; + +// ********** public function prototypes ********** + +void initFilterFlushDefeatured( void ); // Initialize this de-featured Filter Flush unit +U32 transitionToFilterFlushDefeatured( void ); // Transition to Filter Flush +void execFilterFlushDefeatured( void ); // Execute the de-featured Filter Flush state machine +BOOL isFilterFlushDefComplete( void ); // returns if de-featured flush is complete +void signalStartDefFilterFlush( void ); // signal to start de-featured flush +void resetFilterFlushDefSignals( void ); // reset signals for de-featured flush +FP_FILTER_FLUSH_STATE_T getCurrentFilterFlushState( void ); // Get the current state of the de-featured Filter Flush + +BOOL testFilterFlushDefDataPublishIntervalOverride( MESSAGE_T *message ); +BOOL testFilterFlushDefTimerOverride( MESSAGE_T *message ); + +/**@}*/ + +#endif // __STATE_FLUSH_FILTER_DEFEATURED_H__ Index: firmware/App/Modes/FPModes/StateFlushPermeate.c =================================================================== diff -u --- firmware/App/Modes/FPModes/StateFlushPermeate.c (revision 0) +++ firmware/App/Modes/FPModes/StateFlushPermeate.c (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -0,0 +1,474 @@ +/************************************************************************** +* +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file StateFlushPermeate.c +* +* @author (last) “rkallala” +* @date (last) 15-Jan-2026 +* +* @author (original) Michael Garthwaite +* @date (original) 08-Sep-2025 +* +***************************************************************************/ + +#include "BoostPump.h" +#include "Conductivity.h" +#include "FPOperationModes.h" +#include "Level.h" +#include "MessageSupport.h" +#include "Messaging.h" +#include "Pressure.h" +#include "ROPump.h" +#include "StateFlushPermeate.h" +#include "TaskGeneral.h" +#include "Timers.h" +#include "Valves.h" +#include "WaterQualityMonitor.h" + +/** + * @addtogroup FPPermeateFlush + * @{ + */ + +// ********** private definitions ********** + +#define PERMEATE_FLUSH_MAX_TIMEOUT ( 10 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max override timeout for 10 minutes +#define PERMEATE_FLUSH_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen water mode data published. +#define PERMEATE_FLUSH_TIMEOUT ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Permeate flush timer (in ms) timeout for 2 minutes +#define PERMEATE_FLUSH_ALARM_TIMEOUT ( 5 * SEC_PER_MIN * MS_PER_SECOND ) ///< Permeate flush alarm timer (in ms) timeout for 5 minutes +#define PERMEATE_FLUSH_RO_PUMP_TGT_ML 700 ///< Pressure target in ml/min for the RO pump during permeate flush. +#define PERMEATE_FLUSH_BOOST_PUMP_TGT_PSI 25 ///< Pressure target in PSI for the boost pump during permeate flush. +#define PERMEATE_FLUSH_CONDUCTIVITY_THRESHOLD 200.0F ///< Conductivity alarm threshold for permeate flush. +#define MIN_BOOST_PUMP_DUTY_CYCLE_PCT 0.5F ///< Minimum duty cycle value for boost pump during open loop control + +// ********** private data ********** + +static FP_PERM_FLUSH_STATE_T permeateFlushState; ///< Currently active Permeate flush state. +static U32 permeateFlushDataPublicationTimerCounter; ///< Used to schedule Permeate flush data publication to CAN bus. +static OVERRIDE_U32_T permeateFlushDataPublishInterval; ///< Permeate Flush mode data publish interval. +static OVERRIDE_U32_T permeateFlushTimeout; ///< Permeate Flush timeout value +static OVERRIDE_U32_T permeateFlushAlarmTimeout; +static U32 permeateFlushTimer; ///< Permeate Flush timeout timer +static U32 permeateFlushAlarmTimer; +static BOOL pendingStartPermeateFlushRequest; ///< signal to start flushing. +static BOOL isFlushComplete; ///< Permeate Flush complete BOOL +static BOOL isTankFilled; ///< Permeate tank filled in permeate flush state + +// ********** private function prototypes ********** + +static void publishPermeateFlushData( void ); +static FP_PERM_FLUSH_STATE_T handlePermeateFlushProgressState( void ); +static FP_PERM_FLUSH_STATE_T handlePermeateFlushPausedState( void ); +static void setPermeateFlushTransition( FP_PERM_FLUSH_STATE_T state ); +static U32 getPermeateFlushTimeout( void ); +static U32 getPermeateFlushAlarmTimeout( void ); +static U32 getPermeateFlushPublishInterval( void ); + +/*********************************************************************//** + * @brief + * The initPermeateFlush function initializes the Permeate flush unit. + * @details \b Inputs: none + * @details \b Outputs: Permeate flush unit initialized + * @return none + *************************************************************************/ +void initPermeateFlush( void ) +{ + permeateFlushState = PERM_FLUSH_PAUSED; + permeateFlushDataPublishInterval.data = PERMEATE_FLUSH_DATA_PUBLISH_INTERVAL; + permeateFlushDataPublishInterval.ovData = PERMEATE_FLUSH_DATA_PUBLISH_INTERVAL; + permeateFlushDataPublishInterval.ovInitData = 0; + permeateFlushDataPublishInterval.override = OVERRIDE_RESET; + permeateFlushTimeout.data = PERMEATE_FLUSH_TIMEOUT; + permeateFlushTimeout.ovData = PERMEATE_FLUSH_TIMEOUT; + permeateFlushTimeout.ovInitData = 0; + permeateFlushTimeout.override = OVERRIDE_RESET; + permeateFlushAlarmTimeout.data = PERMEATE_FLUSH_ALARM_TIMEOUT; + permeateFlushAlarmTimeout.ovData = PERMEATE_FLUSH_ALARM_TIMEOUT; + permeateFlushAlarmTimeout.ovInitData = 0; + permeateFlushAlarmTimeout.override = OVERRIDE_RESET; + permeateFlushDataPublicationTimerCounter = 0; + permeateFlushTimer = 0; + permeateFlushAlarmTimer = 0; + isFlushComplete = FALSE; + pendingStartPermeateFlushRequest = FALSE; + isTankFilled = FALSE; +} + +/*********************************************************************//** + * @brief + * The execPermeateFlush function executes the Permeate flush state machine + * and publishes Permeate flush data. + * @details \b Inputs: permeateFlushState + * @details \b Outputs: permeateFlushState + * @details \b Alarm: ALARM_ID_FP_SOFTWARE_FAULT if in invalid flush state + * @return none + *************************************************************************/ +void execPermeateFlush( void ) +{ + FP_PERM_FLUSH_STATE_T prevState = permeateFlushState; + + switch ( permeateFlushState ) + { + case PERM_FLUSH_IN_PROGRESS: + permeateFlushState = handlePermeateFlushProgressState(); + break; + + case PERM_FLUSH_PAUSED: + permeateFlushState = handlePermeateFlushPausedState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_PERMEATE_FLUSH_STATE, (U32)permeateFlushState ) + permeateFlushState = PERM_FLUSH_PAUSED; + break; + } + + if ( prevState != permeateFlushState ) + { + setPermeateFlushTransition( permeateFlushState ); + } + // publish Permeate flush data on interval + publishPermeateFlushData(); +} + +/*********************************************************************//** + * @brief + * The handlePermeateFlushProgressState handles the in progress state of Permeate flush + * @details \b Inputs: permeateFlushTimer, permeateFlushAlarmTimer + * @details \b Outputs: isFlushComplete + * @return the next state of Permeate flush state + *************************************************************************/ +static FP_PERM_FLUSH_STATE_T handlePermeateFlushProgressState( void ) +{ + FP_PERM_FLUSH_STATE_T state = PERM_FLUSH_IN_PROGRESS; + LEVEL_STATE_T level = getLevelStatus( P25_LEVL ); + + // Manual control of Permeate tank while in Permeate Flush + // to prevent overfill. + if ( LEVEL_STATE_HIGH == level ) + { + setValveState( M4_VALV, VALVE_STATE_CLOSED ); + if ( TRUE == isBoostPumpInstalled() ) + { + // TODO update the default min duty cycle value after testing + F32 currentDutyCyclePct = getCurrentBoostPumpDutyCyclePCT() > MIN_BOOST_PUMP_DUTY_CYCLE_PCT ? getCurrentBoostPumpDutyCyclePCT(): MIN_BOOST_PUMP_DUTY_CYCLE_PCT; + + setBoostPumpTargetDutyCycle( currentDutyCyclePct ); + isTankFilled = TRUE; + } + } + else if ( LEVEL_STATE_LOW == level ) + { + setValveState( M4_VALV, VALVE_STATE_OPEN ); + // set boost pump to closed loop when M4 closed. Added Tank fill check to avoid reset during initial transition + if ( ( TRUE == isBoostPumpInstalled() ) && ( TRUE == isTankFilled ) ) + { + setBoostPumpTargetPressure( PERMEATE_FLUSH_BOOST_PUMP_TGT_PSI ); + isTankFilled = FALSE; + } + + checkROInletPressure(); + } + + if ( TRUE == didTimeout( permeateFlushTimer, getPermeateFlushTimeout() ) ) + { + F32 p18conductivity = getFilteredConductivity( P18_COND ); + // SRS-275 + + // inlet water pressure range M3 25- 40 PSI + checkInletPressures(); + + // inlet water conductivity p9 < 2000 + checkInletConductivity(); + + // inlet water temperature p10 range 5 - 30 + checkInletTemperatures(); + + if ( ( PERMEATE_FLUSH_CONDUCTIVITY_THRESHOLD > p18conductivity ) && ( LEVEL_STATE_HIGH == level ) ) + { + isFlushComplete = TRUE; + state = PERM_FLUSH_PAUSED; + } + + // If conductivity is not in range, continue to monitor until timeout, TODO if conductivity fluctuates for another 3 minutes + else + { + if ( TRUE == didTimeout( permeateFlushAlarmTimer, getPermeateFlushAlarmTimeout() ) ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_PERMEATE_FLUSH_CONDUCTIVITY_TIMEOUT, PERMEATE_FLUSH_CONDUCTIVITY_THRESHOLD, p18conductivity) + state = PERM_FLUSH_PAUSED; + } + } + + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handlePermeateFlushProgressState handles the in progress state of Permeate flush + * @details \b Inputs: pendingStartPermeateFlushRequest + * @details \b Outputs: isFlushComplete + * @return the next state of Permeate flush state + *************************************************************************/ +static FP_PERM_FLUSH_STATE_T handlePermeateFlushPausedState( void ) +{ + FP_PERM_FLUSH_STATE_T state = PERM_FLUSH_PAUSED; + + if ( TRUE == pendingStartPermeateFlushRequest ) + { + isFlushComplete = FALSE; + state = PERM_FLUSH_IN_PROGRESS; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The setPermeateFlushTransition function sets the actuators and variables + * for the state transition in Permeate flush mode. + * @details Inputs: Valve states, Pump speed + * @details Outputs: Actuate valves, pumps as desired. + * @details \b Alarm: ALARM_ID_FP_SOFTWARE_FAULT if in invalid flush transition + * @param state Permeate flush state enum + * @return none + *************************************************************************/ +static void setPermeateFlushTransition( FP_PERM_FLUSH_STATE_T state ) +{ + // Execute on running state + switch( state ) + { + case PERM_FLUSH_IN_PROGRESS: + setValveState( M4_VALV, VALVE_STATE_OPEN ); + setValveState( M12_VALV, VALVE_STATE_OPEN ); + setValveState( P6_VALV, VALVE_STATE_CLOSED ); + setValveState( P11_VALV, VALVE_STATE_OPEN ); + setValveState( P33_VALV, VALVE_STATE_CLOSED ); + setValveState( P34_VALV, VALVE_STATE_CLOSED ); + setValveState( P37_VALV, VALVE_STATE_CLOSED ); + setValveState( P39_VALV, VALVE_STATE_OPEN ); + if ( TRUE == isBoostPumpInstalled() ) + { + setBoostPumpTargetPressure( PERMEATE_FLUSH_BOOST_PUMP_TGT_PSI ); + } + //TODO update target macro after changing it to 750 + rinse pump rate + setROPumpTargetFlowRateMLPM( PERMEATE_FLUSH_RO_PUMP_TGT_ML, TRUE ); + permeateFlushTimer = getMSTimerCount(); + permeateFlushAlarmTimer = getMSTimerCount(); + pendingStartPermeateFlushRequest = FALSE; + break; + + case PERM_FLUSH_PAUSED: + + // Stop pumps and close only if we alarm ( pause ) during flush. + if ( FALSE == isPermeateFlushComplete() ) + { + setValveState( M4_VALV, VALVE_STATE_CLOSED ); + setValveState( M12_VALV, VALVE_STATE_CLOSED ); + setValveState( P6_VALV, VALVE_STATE_CLOSED ); + setValveState( P11_VALV, VALVE_STATE_CLOSED ); + setValveState( P33_VALV, VALVE_STATE_CLOSED ); + setValveState( P34_VALV, VALVE_STATE_CLOSED ); + setValveState( P37_VALV, VALVE_STATE_CLOSED ); + setValveState( P39_VALV, VALVE_STATE_CLOSED ); + if ( TRUE == isBoostPumpInstalled() ) + { + signalBoostPumpHardStop(); + } + signalROPumpHardStop(); + } + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_PERMEATE_FLUSH_STATE, state ) + break; + } +} + +/*********************************************************************//** + * @brief + * The signalStartPermeateFlush function signals the FP to start Permeate flush. + * @details \b Inputs: none + * @details \b Outputs: pendingStartPermeateFlushRequest + * @return none + *************************************************************************/ +void signalStartPermeateFlush( void ) +{ + if ( PERM_FLUSH_PAUSED == getCurrentPermeateFlushState() ) + { + pendingStartPermeateFlushRequest = TRUE; + } +} + +/*********************************************************************//** + * @brief + * The resetFilterFlushSignals function resets the signal values for + * FP filter flush. + * @details \b Inputs: none + * @details \b Outputs: pendingStartFilterFlushRequest, isFlushComplete + * @return none + *************************************************************************/ +void resetPermeateFlushSignals( void ) +{ + pendingStartPermeateFlushRequest = FALSE; + isFlushComplete = FALSE; +} + +/*********************************************************************//** + * @brief + * The getCurrentPermeateFlushState function returns the current state of + * Permeate flush. + * @details \b Inputs: permeateFlushState + * @details \b Outputs: none + * @return the current state of Permeate flush + *************************************************************************/ +FP_PERM_FLUSH_STATE_T getCurrentPermeateFlushState( void ) +{ + return permeateFlushState; +} + +/*********************************************************************//** + * @brief + * The isPermeateFlushComplete function returns the state of completeness + * of Permeate Flush. + * @details \b Inputs: isFlushComplete + * @details \b Outputs: none + * @return TRUE if permeate flush is complete, FALSE if not. + *************************************************************************/ +BOOL isPermeateFlushComplete( void ) +{ + return isFlushComplete; +} + +/*********************************************************************//** + * @brief + * The getPermeateFlushTimeout function gets the generate water + * mode data publish interval. + * @details \b Inputs: PermeateFlushTimeOut + * @details \b Outputs: none + * @return the timeout timer for Permeate flush. + *************************************************************************/ +static U32 getPermeateFlushTimeout( void ) +{ + U32 result = getU32OverrideValue( &permeateFlushTimeout ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getPermeateFlushTimeout function gets the generate water + * mode data publish interval. + * @details \b Inputs: PermeateFlushTimeOut + * @details \b Outputs: none + * @return the timeout timer for Permeate flush. + *************************************************************************/ +static U32 getPermeateFlushAlarmTimeout( void ) +{ + U32 result = getU32OverrideValue( &permeateFlushAlarmTimeout ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getPermeateFlushPublishInterval function gets the Permeate flush + * mode data publish interval. + * @details \b Inputs: permeateFlushDataPublishInterval + * @details \b Outputs: none + * @return the interval at Permeate flush mode data being published. + *************************************************************************/ +static U32 getPermeateFlushPublishInterval( void ) +{ + U32 result = getU32OverrideValue( &permeateFlushDataPublishInterval ); + + return result; +} + +/*********************************************************************//** + * @brief + * The publishPermeateFlushData function broadcasts the Permeate flush + * mode data at defined interval. + * @details \b Inputs: permeateFlushDataPublicationTimerCounter + * @details \b Outputs: fp Permeate flush data broadcast message sent + * @details \b Message \Sent: MSG_ID_FP_PERMEATE_FLUSH_DATA to publish the + * Permeate flush mode data. + * @return none + *************************************************************************/ +static void publishPermeateFlushData( void ) +{ + if ( ++permeateFlushDataPublicationTimerCounter >= getPermeateFlushPublishInterval() ) + { + PERM_FLUSH_DATA_T data; + + data.permeateFlushExecState = (U32)getCurrentPermeateFlushState(); + broadcastData( MSG_ID_FP_PERMEATE_FLUSH_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( PERM_FLUSH_DATA_T ) ); + + permeateFlushDataPublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testPermeateFlushDataPublishIntervalOverride function overrides the + * FP Permeate flush mode data publish interval. + * @details \b Inputs: permeateFlushDataPublishInterval + * @details \b Outputs: permeateFlushDataPublishInterval + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP Permeate flush data publish interval to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testPermeateFlushDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &permeateFlushDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testPermeateFlushTimerOverride function overrides the + * FP Permeate flush timeout value. + * @details \b Inputs: permeateFlushTimeout + * @details \b Outputs: permeateFlushTimeout + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP Permeate flush timeout to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testPermeateFlushTimerOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &permeateFlushTimeout, 0, PERMEATE_FLUSH_MAX_TIMEOUT ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testPermeateFlushAlarmTimerOverride function overrides the + * FP Permeate flush timeout value. + * @details \b Inputs: permeateFlushAlarmTimeout + * @details \b Outputs: permeateFlushAlarmTimeout + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP Permeate flush timeout to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testPermeateFlushAlarmTimerOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &permeateFlushAlarmTimeout, 0, PERMEATE_FLUSH_MAX_TIMEOUT ); + + return result; +} + +/**@}*/ Index: firmware/App/Modes/FPModes/StateFlushPermeate.h =================================================================== diff -u --- firmware/App/Modes/FPModes/StateFlushPermeate.h (revision 0) +++ firmware/App/Modes/FPModes/StateFlushPermeate.h (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -0,0 +1,58 @@ +/************************************************************************** +* +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file StateFlushPermeate.h +* +* @author (last) “rkallala” +* @date (last) 15-Jan-2026 +* +* @author (original) Michael Garthwaite +* @date (original) 08-Sep-2025 +* +***************************************************************************/ + +#ifndef __STATE_FLUSH_PERMEATE_H__ +#define __STATE_FLUSH_PERMEATE_H__ + +#include "DDDefs.h" +#include "DDCommon.h" +#include "FPDefs.h" + +/** + * @defgroup FPPermeateFlush FPPermeateFlush + * @brief Permeate Flush unit. Manages Permeate flush functions via a state machine. + * + * @addtogroup FPPermeateFlush + * @{ + */ + +// ********** public definitions ********** + +/// Permeate Flush data structure +typedef struct +{ + U32 permeateFlushExecState; ///< Permeate Flush execution state +} PERM_FLUSH_DATA_T; + +// ********** public function prototypes ********** + +void initPermeateFlush( void ); // Initialize this Permeate Flush unit +U32 transitionToPermeateFlush( void ); // Transition to Permeate Flush +void execPermeateFlush( void ); // Execute the Permeate Flush state machine +BOOL isPermeateFlushComplete( void ); // returns if flush is complete +void signalStartPermeateFlush( void ); // signal to start flush +void resetPermeateFlushSignals( void ); // reset signals for flush + +FP_PERM_FLUSH_STATE_T getCurrentPermeateFlushState( void ); // Get the current state of the Permeate Flush + +BOOL testPermeateFlushDataPublishIntervalOverride( MESSAGE_T *message ); +BOOL testPermeateFlushTimerOverride( MESSAGE_T *message ); +BOOL testPermeateFlushAlarmTimerOverride( MESSAGE_T *message ); + +/**@}*/ + +#endif Index: firmware/App/Modes/FPModes/StateInletPressureCheck.c =================================================================== diff -u --- firmware/App/Modes/FPModes/StateInletPressureCheck.c (revision 0) +++ firmware/App/Modes/FPModes/StateInletPressureCheck.c (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -0,0 +1,428 @@ +/************************************************************************** +* +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file StateInletPressureCheck.c +* +* @author (last) “rkallala” +* @date (last) 15-Jan-2026 +* +* @author (original) Michael Garthwaite +* @date (original) 08-Sep-2025 +* +***************************************************************************/ + +#include "BoostPump.h" +#include "FlowSensor.h" +#include "FPOperationModes.h" +#include "MessageSupport.h" +#include "Messaging.h" +#include "PersistentAlarm.h" +#include "Pressure.h" +#include "ROPump.h" +#include "StateInletPressureCheck.h" +#include "TaskGeneral.h" +#include "Timers.h" +#include "Valves.h" + +/** + * @addtogroup InletPressureCheck + * @{ + */ + +// ********** private definitions ********** + +#define INLET_PRES_CHECK_MAX_TIMEOUT ( 10 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max override timeout for 10 minutes +#define INLET_PRES_CHECK_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen water mode data published. +#define INLET_PRES_CHECK_BP_TIMEOUT ( 10 * MS_PER_SECOND ) ///< Inlet Pressure Check timer (in ms) for booster pump installed +#define INLET_PRES_CHECK_TIMEOUT ( 1 * MS_PER_SECOND ) ///< Inlet Pressure Check timer (in ms) for featured and de-featured +#define INLET_PRES_CHECK_BOOST_PUMP_TGT_PWM 0.2F ///< target in PWM % for the BOOST pump during inlet pressure check. +#define INLET_PRES_CHECK_WITH_BP_TGT_PSI 30 ///< Pressure target in PSI for the M3 during inlet pressure check with booster pump. +#define INLET_PRES_CHECK_TGT_PSI 75 ///< Pressure target in PSI for the M3 during inlet pressure check without booster pump. +#define INLET_PRES_CHECK_TOLERANCE_PSI 2 ///< Pressure tolerance in PSI for the M3 during inlet pressure check. +#define INLET_PRES_PERSISTENCE_TIME_WITH_BP_MS ( 1 * MS_PER_SECOND ) ///< Persistence time for M3 during inlet pressure check with booster pump. +#define INLET_PRES_OUT_OF_RANGE_CLEAR_MS ( 1 * MS_PER_SECOND ) ///< Persistence time for M3 during inlet pressure check without booster pump. +#define INLET_PRES_OUT_OF_RANGE_TIMEOUT_MS ( 1 * MS_PER_SECOND ) ///< Persistence time for M3 during inlet pressure check without booster pump. + +// ********** private data ********** + +static FP_INLET_PRES_CHECK_STATE_T inletPressureCheckState; ///< Currently active Inlet Pressure check state. +static U32 inletPressureCheckDataPublicationTimerCounter; ///< Used to schedule Inlet Pressure Check data publication to CAN bus. +static U32 inletPressureCheckTimer; ///< Inlet Pressure check timeout timer +static BOOL isPressureCheckComplete; ///< Inlet Pressure Check complete BOOL +static OVERRIDE_U32_T inletPressureCheckDataPublishInterval; ///< Inlet Pressure Check mode data publish interval. +static OVERRIDE_U32_T inletPressureCheckTimeout; ///< Inlet Pressure check timeout value + +// ********** private function prototypes ********** + +static void publishInletPressureCheckData( void ); +static FP_INLET_PRES_CHECK_STATE_T handleInletPressureCheckProgressState( void ); +static FP_INLET_PRES_CHECK_STATE_T handleInletPressureCheckPausedState( void ); +static void setInletPressureCheckTransition( FP_INLET_PRES_CHECK_STATE_T state ); +static U32 getInletPressureCheckTimeout( void ); +static U32 getInletPressureCheckPublishInterval( void ); + +/*********************************************************************//** + * @brief + * The initInletPressureCheck function initializes the Inlet Pressure Check unit. + * @details \b Inputs: none + * @details \b Outputs: Inlet Pressure Check unit initialized + * @return none + *************************************************************************/ +void initInletPressureCheck( void ) +{ + inletPressureCheckState = INLET_PRES_CHECK_PAUSED; + inletPressureCheckDataPublishInterval.data = INLET_PRES_CHECK_DATA_PUBLISH_INTERVAL; + inletPressureCheckDataPublishInterval.ovData = INLET_PRES_CHECK_DATA_PUBLISH_INTERVAL; + inletPressureCheckDataPublishInterval.ovInitData = 0; + inletPressureCheckDataPublishInterval.override = OVERRIDE_RESET; + inletPressureCheckDataPublicationTimerCounter = 0; + inletPressureCheckTimer = 0; + isPressureCheckComplete = FALSE; + + if ( TRUE == isBoostPumpInstalled() ) + { + inletPressureCheckTimeout.data = INLET_PRES_CHECK_BP_TIMEOUT; + inletPressureCheckTimeout.ovData = INLET_PRES_CHECK_BP_TIMEOUT; + inletPressureCheckTimeout.ovInitData = 0; + inletPressureCheckTimeout.override = OVERRIDE_RESET; + } + else + { + inletPressureCheckTimeout.data = INLET_PRES_CHECK_TIMEOUT; + inletPressureCheckTimeout.ovData = INLET_PRES_CHECK_TIMEOUT; + inletPressureCheckTimeout.ovInitData = 0; + inletPressureCheckTimeout.override = OVERRIDE_RESET; + } + + // Pressure alarms + initPersistentAlarm( ALARM_ID_FP_INLET_PRESSURE_REGULATOR_OUT_OF_RANGE, INLET_PRES_OUT_OF_RANGE_CLEAR_MS, INLET_PRES_OUT_OF_RANGE_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_FP_INLET_PRESSURE_REGULATOR_OUT_OF_RANGE, INLET_PRES_OUT_OF_RANGE_CLEAR_MS, INLET_PRES_OUT_OF_RANGE_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_FP_INLET_PRESSURE_CRITICAL_OUT_RANGE, INLET_PRES_OUT_OF_RANGE_CLEAR_MS, INLET_PRES_OUT_OF_RANGE_TIMEOUT_MS ); +} + +/*********************************************************************//** + * @brief + * The transitionToInletPressureCheck function prepares for transition to + * inlet pressure check + * permeate mode. + * @details \b Inputs: inletPressureCheckState + * @details \b Outputs: none + * @return initial 0 + *************************************************************************/ +U32 transitionToInletPressureCheck( void ) +{ + initInletPressureCheck(); + return 0; +} + +/*********************************************************************//** + * @brief + * The execInletPressureCheck function executes the inlet pressure check + * state machine and publishes inlet pressure check data. + * @details \b Inputs: inletPressureCheckState + * @details \b Outputs: inletPressureCheckState + * @details \b Alarm: ALARM_ID_FP_SOFTWARE_FAULT if in invalid flush state + * @return none + *************************************************************************/ +void execInletPressureCheck( void ) +{ + FP_INLET_PRES_CHECK_STATE_T prevState = inletPressureCheckState; + + switch ( inletPressureCheckState ) + { + case INLET_PRES_CHECK_IN_PROGRESS: + inletPressureCheckState = handleInletPressureCheckProgressState(); + break; + + case INLET_PRES_CHECK_PAUSED: + inletPressureCheckState = handleInletPressureCheckPausedState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_INLET_PRESSURE_CHECK_STATE, (U32)inletPressureCheckState ) + inletPressureCheckState = INLET_PRES_CHECK_PAUSED; + break; + } + + if ( prevState != inletPressureCheckState ) + { + setInletPressureCheckTransition( inletPressureCheckState ); + } + // publish Inlet Pressure check data on interval + publishInletPressureCheckData(); +} + +/*********************************************************************//** + * @brief + * The handleInletPressureCheckProgressState handles the in progress + * state of inlet pressure check + * @details \b Inputs: none + * @details \b Outputs: isPressureCheckComplete + * @return the next state of Inlet Pressure check state + *************************************************************************/ +static FP_INLET_PRES_CHECK_STATE_T handleInletPressureCheckProgressState( void ) +{ + FP_INLET_PRES_CHECK_STATE_T state = INLET_PRES_CHECK_IN_PROGRESS; + F32 pressureM3 = getFilteredPressure(M3_PRES); + F32 minThreshold = INLET_PRES_CHECK_WITH_BP_TGT_PSI - INLET_PRES_CHECK_TOLERANCE_PSI; + F32 maxThreshold = INLET_PRES_CHECK_WITH_BP_TGT_PSI + INLET_PRES_CHECK_TOLERANCE_PSI; + BOOL isPresOutOfLowRange = FALSE; + BOOL isPresOutOfHighRange = FALSE; + + if ( TRUE == isBoostPumpInstalled() ) + { + // timeout after 10 seconds + if ( TRUE == didTimeout(inletPressureCheckTimer , getInletPressureCheckTimeout() ) ) + { + isPresOutOfLowRange = ( ( pressureM3 < minThreshold ) ? TRUE : FALSE ); + isPresOutOfHighRange = ( ( ( pressureM3 > maxThreshold ) ) ? TRUE : FALSE ); + // check for inlet pressure (M3) within range + if( ( pressureM3 >= minThreshold ) && ( pressureM3 <= maxThreshold ) ) + { + isPressureCheckComplete = TRUE; + state = INLET_PRES_CHECK_PAUSED; + } + else + { + // check persistent alarm for 1 second + checkPersistentAlarm( ALARM_ID_FP_INLET_PRESSURE_REGULATOR_OUT_OF_RANGE, isPresOutOfLowRange, pressureM3, minThreshold ); + checkPersistentAlarm( ALARM_ID_FP_INLET_PRESSURE_REGULATOR_OUT_OF_RANGE, isPresOutOfHighRange, pressureM3, maxThreshold ); + } + } + } + else + { + // Change inlet pressure check for M3 criteria from 30 PSI to <75 PSI for both featured and de-featured + // ALARM_ID_FP_INLET_PRESSURE_CRITICAL_OUT_RANGE is defined for featured when > 75 and > 40 for de-featured so re using alarm ID + // INLET_PRES_CHECK_TGT_PSI = 75 + + isPresOutOfHighRange = ( ( pressureM3 >= INLET_PRES_CHECK_TGT_PSI ) ? TRUE : FALSE ); + + checkPersistentAlarm( ALARM_ID_FP_INLET_PRESSURE_REGULATOR_OUT_OF_RANGE, isPresOutOfHighRange, pressureM3, INLET_PRES_CHECK_TGT_PSI ); + + // stay in this state for 1 second for checking the persistent alarm + if ( TRUE == didTimeout(inletPressureCheckTimer , getInletPressureCheckTimeout() ) ) + { + isPressureCheckComplete = TRUE; + state = INLET_PRES_CHECK_PAUSED; + } + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleInletPressureCheckPausedState handles the paused state of Inlet Pressure check + * @details \b Inputs: none + * @details \b Outputs: none + * @return the next state of Inlet Pressure check state + *************************************************************************/ +static FP_INLET_PRES_CHECK_STATE_T handleInletPressureCheckPausedState( void ) +{ + FP_INLET_PRES_CHECK_STATE_T state = INLET_PRES_CHECK_PAUSED; + + if ( FALSE == isInletPressureCheckCompleted() ) + { + state = INLET_PRES_CHECK_IN_PROGRESS; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The setInletPressureCheckTransition function sets the actuators and variables + * for the state transition in Inlet Pressure check mode. + * @details Inputs: Valve states, Pump speed + * @details Outputs: Actuate valves, pumps as desired. + * @param state Inlet Pressure check state enum + * @return none + *************************************************************************/ +static void setInletPressureCheckTransition( FP_INLET_PRES_CHECK_STATE_T state ) +{ + // Execute on running state + switch( state ) + { + case INLET_PRES_CHECK_IN_PROGRESS: + setValveState( M4_VALV, VALVE_STATE_CLOSED ); + setValveState( M12_VALV, VALVE_STATE_CLOSED ); + if ( TRUE == isFPDefeatured() ) + { + setValveState( D52_VALV, VALVE_STATE_CLOSED ); + } + else + { + setValveState( P6_VALV, VALVE_STATE_CLOSED ); + setValveState( P11_VALV, VALVE_STATE_CLOSED ); + setValveState( P33_VALV, VALVE_STATE_CLOSED ); + setValveState( P34_VALV, VALVE_STATE_CLOSED ); + setValveState( P37_VALV, VALVE_STATE_CLOSED ); + setValveState( P39_VALV, VALVE_STATE_CLOSED ); + if ( TRUE == isBoostPumpInstalled() ) + { + setBoostPumpTargetDutyCycle( INLET_PRES_CHECK_BOOST_PUMP_TGT_PWM ); + } + signalROPumpHardStop(); + } + inletPressureCheckTimer = getMSTimerCount(); + break; + + case INLET_PRES_CHECK_PAUSED: + // Stop pumps and close only if we alarm ( pause ) during flush. + if ( FALSE == isInletPressureCheckCompleted() ) + { + setValveState( M4_VALV, VALVE_STATE_CLOSED ); + setValveState( M12_VALV, VALVE_STATE_CLOSED ); + + if ( TRUE == isFPDefeatured() ) + { + setValveState( D52_VALV, VALVE_STATE_CLOSED ); + } + else + { + setValveState( P6_VALV, VALVE_STATE_CLOSED ); + setValveState( P11_VALV, VALVE_STATE_CLOSED ); + setValveState( P33_VALV, VALVE_STATE_CLOSED ); + setValveState( P34_VALV, VALVE_STATE_CLOSED ); + setValveState( P37_VALV, VALVE_STATE_CLOSED ); + setValveState( P39_VALV, VALVE_STATE_CLOSED ); + + if ( TRUE == isBoostPumpInstalled() ) + { + signalBoostPumpHardStop(); + } + signalROPumpHardStop(); + } + } + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_INLET_PRESSURE_CHECK_STATE, state ) + break; + } +} + +/*********************************************************************//** + * @brief + * The getCurrentInletPressureCheckState function returns the current state of + * Inlet Pressure Check. + * @details \b Inputs: inletPressureCheckState + * @details \b Outputs: none + * @return the current state of inlet pressure check + *************************************************************************/ +FP_INLET_PRES_CHECK_STATE_T getCurrentInletPressureCheckState( void ) +{ + return inletPressureCheckState; +} + +/*********************************************************************//** + * @brief + * The isInletPressureCheckCompleted function returns isPressureCheckComplete. + * @details \b Inputs: isPressureCheckComplete + * @details \b Outputs: none + * @return TRUE if Inlet Pressure check is complete, FALSE if not. + *************************************************************************/ +BOOL isInletPressureCheckCompleted( void ) +{ + return isPressureCheckComplete; +} + +/*********************************************************************//** + * @brief + * The getInletPressureCheckTimeout function gets the Inlet Pressure check + * mode data publish interval. + * @details \b Inputs: inletPressureCheckTimeout + * @details \b Outputs: none + * @return the Inlet Pressure check timeout period in ms. + *************************************************************************/ +static U32 getInletPressureCheckTimeout( void ) +{ + U32 result = getU32OverrideValue( &inletPressureCheckTimeout ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getInletPressureCheckPublishInterval function gets the Inlet Pressure check + * mode data publish interval. + * @details \b Inputs: inletPressureCheckDataPublishInterval + * @details \b Outputs: none + * @return the interval at Inlet Pressure check mode data being published. + *************************************************************************/ +static U32 getInletPressureCheckPublishInterval( void ) +{ + U32 result = getU32OverrideValue( &inletPressureCheckDataPublishInterval ); + + return result; +} + +/*********************************************************************//** + * @brief + * The publishInletPressureCheckData function broadcasts the Inlet Pressure check + * mode data at defined interval. + * @details \b Inputs: inletPressureCheckDataPublicationTimerCounter + * @details \b Outputs: fp Inlet Pressure check data broadcast message sent + * @details \b Message \b Sent: MSG_ID_FP_INLET_PRESSURE_CHECK_DATA to publish the + * Inlet Pressure check mode data. + * @return none + *************************************************************************/ +static void publishInletPressureCheckData( void ) +{ + if ( ++inletPressureCheckDataPublicationTimerCounter >= getInletPressureCheckPublishInterval() ) + { + INLET_PRES_CHECK_DATA_T data; + + data.inletPressureCheckExecState = (U32)getCurrentInletPressureCheckState(); + broadcastData( MSG_ID_FP_INLET_PRESSURE_CHECK_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( INLET_PRES_CHECK_DATA_T ) ); + + inletPressureCheckDataPublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testInletPressureCheckDataPublishIntervalOverride function overrides the + * FP Inlet Pressure check mode data publish interval. + * @details \b Inputs: inletPressureCheckDataPublishInterval + * @details \b Outputs: inletPressureCheckDataPublishInterval + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP Inlet Pressure check data publish interval to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testInletPressureCheckDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &inletPressureCheckDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testInletPressureCheckTimerOverride function overrides the + * FP Inlet Pressure check timeout value. + * @details \b Inputs: inletPressureCheckTimeout + * @details \b Outputs: inletPressureCheckTimeout + * @param Override message from Dialin which includes the interval + * (in ms) to override the FP Inlet Pressure check timeout to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testInletPressureCheckTimerOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &inletPressureCheckTimeout, 0, INLET_PRES_CHECK_MAX_TIMEOUT ); + + return result; +} + +/**@}*/ Index: firmware/App/Modes/FPModes/StateInletPressureCheck.h =================================================================== diff -u --- firmware/App/Modes/FPModes/StateInletPressureCheck.h (revision 0) +++ firmware/App/Modes/FPModes/StateInletPressureCheck.h (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -0,0 +1,54 @@ +/************************************************************************** +* +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file StateInletPressureCheck.h +* +* @author (last) “rkallala” +* @date (last) 15-Jan-2026 +* +* @author (original) Michael Garthwaite +* @date (original) 08-Sep-2025 +* +***************************************************************************/ + +#ifndef __STATE_INLET_PRESSURE_CHECK_H__ +#define __STATE_INLET_PRESSURE_CHECK_H__ + +#include "DDDefs.h" +#include "DDCommon.h" +#include "FPDefs.h" + +/** + * @defgroup InletPressureCheck InletPressureCheck + * @brief Inlet Pressure Check unit. Manages Inlet Pressure Check functions via a state machine. + * + * @addtogroup InletPressureCheck + * @{ + */ + +// ********** public definitions ********** + +/// Inlet Pressure Check data structure +typedef struct +{ + U32 inletPressureCheckExecState; ///< Inlet Pressure Check progress state +} INLET_PRES_CHECK_DATA_T; + +// ********** public function prototypes ********** + +void initInletPressureCheck( void ); // Initialize Inlet Pressure Check +U32 transitionToInletPressureCheck( void ); // Transition to Inlet Pressure Check +void execInletPressureCheck( void ); // Execute the Inlet Pressure Checks state machine +BOOL isInletPressureCheckCompleted( void ); // returns if Inlet Pressure Check is complete +FP_INLET_PRES_CHECK_STATE_T getCurrentInletPressureCheckState( void ); // Get the current state of the Inlet Pressure Check + +BOOL testInletPressureCheckDataPublishIntervalOverride( MESSAGE_T *message ); +BOOL testInletPressureCheckTimerOverride( MESSAGE_T *message ); + +/**@}*/ + +#endif Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r84cde45256941a13f2c826cd35f0e0ba58a83df4 -r9f7c5de17f8e3d832da0888f138fb7602cc33a78 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 84cde45256941a13f2c826cd35f0e0ba58a83df4) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -28,17 +28,12 @@ #include "Flow.h" #include "FlowSensor.h" #include "FluidPump.h" -#include "FlushConcentrate.h" -#include "FlushFilter.h" -#include "FlushFilterDefeatured.h" -#include "FlushPermeate.h" #include "FpgaDD.h" #include "FPModeFault.h" #include "FPModeInitPOST.h" #include "FPModeStandby.h" #include "FPOperationModes.h" #include "Heaters.h" -#include "InletPressureCheck.h" #include "Level.h" #include "Messaging.h" #include "MessagePayloads.h" @@ -58,6 +53,11 @@ #include "ROPump.h" #include "SafetyShutdown.h" #include "SpentChamberFill.h" +#include "StateFlushConcentrate.h" +#include "StateFlushFilter.h" +#include "StateFlushFilterDefeatured.h" +#include "StateFlushPermeate.h" +#include "StateInletPressureCheck.h" #include "SystemCommDD.h" #include "Temperature.h" #include "TestSupport.h" Index: firmware/source/sys_main.c =================================================================== diff -u -r711ff90b0aab45c4acde333f4c9f11be9b62f383 -r9f7c5de17f8e3d832da0888f138fb7602cc33a78 --- firmware/source/sys_main.c (.../sys_main.c) (revision 711ff90b0aab45c4acde333f4c9f11be9b62f383) +++ firmware/source/sys_main.c (.../sys_main.c) (revision 9f7c5de17f8e3d832da0888f138fb7602cc33a78) @@ -72,9 +72,6 @@ #include "Flow.h" #include "FlowSensor.h" #include "FluidPump.h" -#include "FlushConcentrate.h" -#include "FlushFilter.h" -#include "FlushPermeate.h" #include "FPModeFault.h" #include "FPModeInitPOST.h" #include "FPModeStandby.h" @@ -95,6 +92,11 @@ #include "RinsePump.h" #include "ROPump.h" #include "SafetyShutdown.h" +#include "StateFlushConcentrate.h" +#include "StateFlushFilter.h" +#include "StateFlushFilterDefeatured.h" +#include "StateFlushPermeate.h" +#include "StateInletPressureCheck.h" #include "SystemCommDD.h" #include "TaskBG.h" #include "TDInterface.h" @@ -229,6 +231,8 @@ initPreGenPMode(); initGenPermeateMode(); initGenPermeateDefeaturedMode(); + initInletPressureCheck(); + initFilterFlushDefeatured(); initFilterFlush(); initConcentrateFlush(); initPermeateFlush();