Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u --- firmware/App/Controllers/ROPump.c (revision 0) +++ firmware/App/Controllers/ROPump.c (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -0,0 +1,272 @@ +/************************************************************************** +* +* Copyright (c) 2020-2024 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 ROPump.c +* +* @author (last) Sean Nash +* @date (last) 12-Nov-2024 +* +* @author (original) Sean Nash +* @date (original) 12-Nov-2024 +* +***************************************************************************/ + +//#include + +//#include "FlowSensors.h" +//#include "NVDataMgmt.h" +#include "Messaging.h" +#include "MessageSupport.h" +#include "OperationModes.h" +#include "PersistentAlarm.h" +//#include "PIControllers.h" +//#include "Pressures.h" +#include "ROPump.h" +#include "SafetyShutdown.h" +#include "TaskGeneral.h" +#include "Timers.h" +#include "Utilities.h" + +/** + * @addtogroup ROPump + * @{ + */ + +// ********** private definitions ********** + +#define RO_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the RO Pump data is published on the CAN bus. +#define ROP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the RO pump is controlled. + +//#define ROP_FLOW_CONTROL_P_COEFFICIENT 0.15F ///< P term for RO pump flow control. +//#define ROP_FLOW_CONTROL_I_COEFFICIENT 0.65F ///< I term for RO pump flow control. +//#define ROP_MAX_PRESSURE_P_COEFFICIENT 0.01F ///< P term for RO pump max pressure control. +//#define ROP_MAX_PRESSURE_I_COEFFICIENT 0.01F ///< I term for RO pump max pressure control. +//#define ROP_PWM_STEP_LIMIT 0.50F ///< Current maximum PWM step limit used in RO Profiles. + +#define DATA_PUBLISH_COUNTER_START_COUNT 10 ///< Data publish counter start count. + +/// Enumeration of RO pump states. +typedef enum ROPump_States +{ + RO_PUMP_OFF_STATE = 0, ///< RO pump off state. + RO_PUMP_OPEN_LOOP_STATE, ///< RO pump open loop state. + NUM_OF_RO_PUMP_STATES ///< Number of RO pump states. +} RO_PUMP_STATE_T; + +/// Enumeration of RO pump self-test states. +//typedef enum ROPump_Self_Test_States +//{ +// RO_PUMP_SELF_TEST_STATE_START = 0, ///< RO pump self-test start state. +// RO_PUMP_TEST_STATE_IN_PROGRESS, ///< RO pump self-tests in progress state. +// RO_PUMP_TEST_STATE_COMPLETE, ///< RO pump self-tests completed state. +// NUM_OF_RO_PUMP_SELF_TEST_STATES ///< Number of RO pump self-test states. +//} RO_PUMP_SELF_TEST_STATE_T; + +// ********** private data ********** + +static RO_PUMP_STATE_T roPumpState[ NUM_OF_BOOST_PUMPS ]; ///< Current state of pump controller state machine. +static PUMP_CONTROL_MODE_T roPumpControlMode[ NUM_OF_BOOST_PUMPS ]; ///< Requested pump control mode. +static BOOL isROPumpOn[ NUM_OF_BOOST_PUMPS ]; ///< Flag indicating whether pump is currently running. +static BOOL stopPumpRequest[ NUM_OF_BOOST_PUMPS ]; ///< Flag indicating pump stop is requested. +static U32 roPumpDataPublicationTimerCounter; ///< Used to schedule RO pump data publication to CAN bus. +static OVERRIDE_U32_T roPumpDataPublishInterval; ///< Interval (in ms) at which to publish boost pump data to CAN bus. +static U32 roControlTimerCounter; ///< Determines when to perform control on RO pump. +static U32 roPumpControlInterval; ///< RO pump Control interval. + +// ********** private function prototypes ********** + +static RO_PUMP_STATE_T handleROPumpOffState( RO_BOOST_PUMP_T pumpID ); +static RO_PUMP_STATE_T handleROPumpOpenLoopState( RO_BOOST_PUMP_T pumpID ); + +static void publishROPumpData( void ); + +/*********************************************************************//** + * @brief + * The initROPump function initializes the RO Pump module. + * @details \b Inputs: none + * @details \b Outputs: RO Pump controller unit initialized + * @return none + *************************************************************************/ +void initROPump( void ) +{ + U32 pump; + + initBoostPump(); + + // Initialize the variables + for ( pump = 0; pump < NUM_OF_BOOST_PUMPS; pump++ ) + { + roPumpState[ pump ] = RO_PUMP_OFF_STATE; + roPumpControlMode[ pump ] = NUM_OF_PUMP_CONTROL_MODES; + isROPumpOn[ pump ] = FALSE; + stopPumpRequest[ pump ] = FALSE; + } + roPumpControlInterval = ROP_CONTROL_INTERVAL; + roControlTimerCounter = 0; + roPumpDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + roPumpDataPublishInterval.data = RO_PUMP_DATA_PUB_INTERVAL; + roPumpDataPublishInterval.ovData = RO_PUMP_DATA_PUB_INTERVAL; + roPumpDataPublishInterval.ovInitData = 0; + roPumpDataPublishInterval.override = OVERRIDE_RESET; +} + +/*********************************************************************//** + * @brief + * The execROPumpController function executes the RO pump controller. + * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if pump is in an invalid state + * @details \b Inputs: roPumpState[] + * @details \b Outputs: roPumpState[] + * @return none + *************************************************************************/ +void execROPumpController( void ) +{ + RO_BOOST_PUMP_T pump; + + // Update RO pump feedback from FPGA + readBoostPumps(); + + // Execute pump control state machine for each boost pump + for ( pump = (RO_BOOST_PUMP_T)0; pump < NUM_OF_BOOST_PUMPS; pump++ ) + { + switch ( roPumpState[ pump ] ) + { + case RO_PUMP_OFF_STATE: + roPumpState[ pump ] = handleROPumpOffState( pump ); + break; + + case RO_PUMP_OPEN_LOOP_STATE: + roPumpState[ pump ] = handleROPumpOpenLoopState( pump ); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RO_SOFTWARE_FAULT, SW_FAULT_ID_RO_PUMP_INVALID_EXEC_STATE, roPumpState[ pump ] ) + roPumpState[ pump ] = RO_PUMP_OFF_STATE; + break; + } + } + + // Publish RO pump data on interval + publishROPumpData(); +} + +/*********************************************************************//** + * @brief + * The handleROPumpOffState function handles the off state of the RO pump + * state machine. + * @details \b Inputs: + * @details \b Outputs: + * @param pumpID ID of boost pump to handle off state for + * @return next state + *************************************************************************/ +static RO_PUMP_STATE_T handleROPumpOffState( RO_BOOST_PUMP_T pumpID ) +{ + RO_PUMP_STATE_T state = RO_PUMP_OFF_STATE; + + return state; +} + +/*********************************************************************//** + * @brief + * The handleROPumpOpenLoopState function handles the open loop control + * state of the RO pump state machine. + * @details \b Inputs: stopPumpRequest[] + * @details \b Outputs: roPumpState[], stopPumpRequest[] + * @param pumpID ID of boost pump to handle open loop control state for + * @return next state + *************************************************************************/ +static RO_PUMP_STATE_T handleROPumpOpenLoopState( RO_BOOST_PUMP_T pumpID ) +{ + RO_PUMP_STATE_T state = RO_PUMP_OPEN_LOOP_STATE; + + if ( TRUE == stopPumpRequest[ pumpID ] ) + { + stopPumpRequest[ pumpID ] = FALSE; + roPumpState[ pumpID ] = RO_PUMP_OFF_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The signalROPumpStop function stops the RO pump immediately and + * resets all the variables associated with the RO pump run. + * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if invalid pump ID given + * @details \b Inputs: roPumpState[] + * @details \b Outputs: stopPumpRequest[] + * @param pumpID ID of boost pump to stop + * @return none + *************************************************************************/ +void signalROPumpStop( RO_BOOST_PUMP_T pumpID ) +{ + if ( pumpID < NUM_OF_BOOST_PUMPS ) + { + setBoostPumpPWMDutyCycle( pumpID, 0 ); // stop pump immediately + if ( roPumpState[ pumpID ] != RO_PUMP_OFF_STATE ) + { + stopPumpRequest[ pumpID ] = TRUE; // set stop request so state machine goes to off state + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RO_SOFTWARE_FAULT, SW_FAULT_ID_RO_PUMP_INVALID_PUMP_ID1, (U32)pumpID ) + } +} + +/*********************************************************************//** + * @brief + * The publishROPumpData function publishes RO pump data at the set interval. + * @details \b Message \b Sent: + * @details \b Inputs: roPumpDataPublicationTimerCounter + * @details \b Outputs: roPumpDataPublicationTimerCounter + * @return none + *************************************************************************/ +static void publishROPumpData( void ) +{ + // publish RO pump data on interval + if ( ++roPumpDataPublicationTimerCounter >= getU32OverrideValue( &roPumpDataPublishInterval ) ) + { + RO_PUMP_DATA_T pumpData; + + pumpData.roPumpState = (U32)roPumpState[ RO_PUMP ]; + pumpData.roPumpDutyCycle = (U32)getBoostPumpPWMDutyCycle( RO_PUMP ); + pumpData.roPumpFBDutyCycle = (U32)getBoostPumpReadPWMDutyCycle( RO_PUMP ); + pumpData.roPumpSpeed = getBoostPumpRPM( RO_PUMP ); + pumpData.bstPumpState = (U32)roPumpState[ RO_BOOST_PUMP ]; + pumpData.bstPumpDutyCycle = (U32)getBoostPumpPWMDutyCycle( RO_BOOST_PUMP ); + pumpData.bstPumpFBDutyCycle = (U32)getBoostPumpReadPWMDutyCycle( RO_BOOST_PUMP ); + pumpData.bstPumpSpeed = getBoostPumpRPM( RO_BOOST_PUMP ); + + broadcastData( MSG_ID_RO_PUMP_DATA, COMM_BUFFER_OUT_CAN_RO_BROADCAST, (U08*)&pumpData, sizeof( RO_PUMP_DATA_T ) ); + roPumpDataPublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testROPumpDataPublishIntervalOverride function overrides the RO pump + * data publish interval. + * @details Inputs: roPumpDataPublishInterval + * @details Outputs: roPumpDataPublishInterval + * @param message Override message from Dialin which includes the value + * that override ro pump data publish interval with (in ms) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testROPumpDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &roPumpDataPublishInterval, TASK_GENERAL_INTERVAL ); + + return result; +} + +/**@}*/ Index: firmware/App/Controllers/ROPump.h =================================================================== diff -u --- firmware/App/Controllers/ROPump.h (revision 0) +++ firmware/App/Controllers/ROPump.h (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -0,0 +1,59 @@ +/************************************************************************** +* +* Copyright (c) 2020-2024 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 ROPump.h +* +* @author (last) Sean Nash +* @date (last) 12-Nov-2024 +* +* @author (original) Sean Nash +* @date (original) 12-Nov-2024 +* +***************************************************************************/ + +#ifndef __RO_PUMP_H__ +#define __RO_PUMP_H__ + +#include "ROCommon.h" +#include "BoostPump.h" + +/** + * @defgroup ROPump ROPump + * @brief RO Pump controller unit. Controls and monitors the RO pump. + * The diaphragm (RO) pump is manufactured by Aquatec, PN: 5889-2MM1-V724DY. + * + * @addtogroup ROPump + * @{ + */ + +// ********** public definitions ********** + +/// RO pump data record. +typedef struct +{ + U32 roPumpState; ///< RO pump current state. + U32 roPumpDutyCycle; ///< RO pump duty cycle. + U32 roPumpFBDutyCycle; ///< RO pump feedback duty cycle. + F32 roPumpSpeed; ///< RO pump speed (RPM). + U32 bstPumpState; ///< Boost pump current state. + U32 bstPumpDutyCycle; ///< Boost pump duty cycle. + U32 bstPumpFBDutyCycle; ///< Boost pump feedback duty cycle. + F32 bstPumpSpeed; ///< Boost pump speed (RPM). +} RO_PUMP_DATA_T; + +// ********** public function prototypes ********** + +void initROPump( void ); +void execROPumpController( void ); + +void signalROPumpStop( RO_BOOST_PUMP_T pumpID ); + +BOOL testROPumpDataPublishIntervalOverride( MESSAGE_T *message ); + +/**@}*/ + +#endif Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r2205857f59dd884c4af450239381387cfb560c2e -r0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 2205857f59dd884c4af450239381387cfb560c2e) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -40,13 +40,18 @@ #define VALVES_STATE_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval ( ms / task time ) at which valves states are published on CAN bus. #define DATA_PUBLISH_COUNTER_START_COUNT 50 ///< Data publish counter start count. -/// Payload record structure for valve open/close request -typedef struct -{ - U32 valveID; ///< ValveID ( valid range 0 to 28 ) - U32 valveState; ///< Valve state ( Open : 0, closed :1) -} VALVE_CMD_PAYLOAD_T; - +/// Bits associated with RO valves when interfacing with FPGA to command a valve position. 1=energized, 0=de-energized. +static const U08 ValveBits[ NUM_OF_VALVES ] = { + 0x01, + 0x02, + 0x04, + 0x08, + 0x10, + 0x20, + 0x40, + 0x80 +}; + // ********** private data ********** static U32 valvesStatesPublicationTimerCounter; ///< Timer counter used to schedule valve state publication to CAN bus. @@ -161,7 +166,7 @@ * @brief * The readCommandedValveStates function gets the hydraulics, Balancing chamber * and Ultrafiltration valvesStates that can be passed to FPGA for setting valves. - * @details \b Inputs: valveStates[] + * @details \b Inputs: valveStates[], ValveBits[] * @details \b Outputs: commandedValvesStates * @return none *************************************************************************/ @@ -170,12 +175,12 @@ U32 valve; // Initiliaze before updating commanded states - commandedValvesStates = ALL_VALVES_DEENERGIZED; + commandedValvesStates = ALL_VALVES_DEENERGIZED; - // flag hydraulics valves that are currently commanded to be energized + // flag RO valves that are currently commanded to be energized for ( valve = FIRST_VALVE; valve < NUM_OF_VALVES; valve++ ) { - commandedValvesStates |= ( getValveState( valve ) == ENERGIZED ? 0x0001 << valve : 0 ); + commandedValvesStates |= ( getValveState( valve ) == ENERGIZED ? ValveBits[ valve ] : 0 ); } } Index: firmware/App/Controllers/Valves.h =================================================================== diff -u -r2205857f59dd884c4af450239381387cfb560c2e -r0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef --- firmware/App/Controllers/Valves.h (.../Valves.h) (revision 2205857f59dd884c4af450239381387cfb560c2e) +++ firmware/App/Controllers/Valves.h (.../Valves.h) (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -30,11 +30,12 @@ /// Enumeration of valves. typedef enum Valves -{ - VFF = 0, ///< Valve (P6) - FIRST_VALVE = 0, ///< First valve +{ + VWI = 0, ///< Valve (M4) + FIRST_VALVE = VWI, ///< First valve + VFB, ///< Valve (M7) + VFF, ///< Valve (P6) VPI, ///< Valve (P11) - VLP, ///< Valve (P21) VCR, ///< Valve (P33) VCB, ///< Valve (P34) VCD, ///< Valve (P37) Index: firmware/App/Drivers/BoostPump.c =================================================================== diff -u --- firmware/App/Drivers/BoostPump.c (revision 0) +++ firmware/App/Drivers/BoostPump.c (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -0,0 +1,295 @@ +/************************************************************************** +* +* Copyright (c) 2020-2024 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 BoostPump.c +* +* @author (last) Sean Nash +* @date (last) 12-Nov-2024 +* +* @author (original) Sean Nash +* @date (original) 12-Nov-2024 +* +***************************************************************************/ + +#include "BoostPump.h" +#include "FpgaRO.h" +#include "Messaging.h" +#include "MessageSupport.h" +#include "PersistentAlarm.h" +#include "Timers.h" +#include "Utilities.h" + +/** + * @addtogroup BoostPump + * @{ + */ + +// ********** private definitions ********** + +#define BOOST_PUMP_COUNTS_2_RPM_NUMERATOR 1500000.0F ///< Numerator in counts to RPM conversion. +#define BOOST_PUMP_COUNTS_FOR_STOPPED_PUMP 0xFFFF ///< FPGA will report FFFF counts when pump is stopped. + +/// Payload record structure for boost pump set PWM request +typedef struct +{ + U32 pumpID; ///< Pump ID + U32 pwm; ///< Pump PWM magnitude (0..500). +} BOOST_PUMP_CMD_PAYLOAD_T; + +// ********** private data ********** + +static U16 boostPumpCmdDutyCycle[ NUM_OF_BOOST_PUMPS ]; ///< Commanded duty cycles for boost pumps. +static OVERRIDE_U32_T boostPumpReadDutyCycle[ NUM_OF_BOOST_PUMPS ]; ///< Boost pump duty cycles read back from FPGA. +static OVERRIDE_F32_T boostPumpMeasRPM[ NUM_OF_BOOST_PUMPS ]; ///< Boost pump measured speeds (RPM). + +// ********** private function prototypes ********** + +/*********************************************************************//** + * @brief + * The initBoostPump function initializes the Boost Pump driver unit. + * @details \b Inputs: none + * @details \b Outputs: Boost pump unit initialized. + * @return none + *************************************************************************/ +void initBoostPump( void ) +{ + U32 pump; + + // initialize duty cycles and measured speeds + for ( pump = 0; pump < NUM_OF_BOOST_PUMPS; pump++ ) + { + boostPumpCmdDutyCycle[ pump ] = 0; + boostPumpReadDutyCycle[ pump ].data = 0; + boostPumpReadDutyCycle[ pump ].ovData = 0; + boostPumpReadDutyCycle[ pump ].ovInitData = 0; + boostPumpReadDutyCycle[ pump ].override = OVERRIDE_RESET; + boostPumpMeasRPM[ pump ].data = 0.0F; + boostPumpMeasRPM[ pump ].ovData = 0.0F; + boostPumpMeasRPM[ pump ].ovInitData = 0.0F; + boostPumpMeasRPM[ pump ].override = OVERRIDE_RESET; + } + + // set RO pump to stop + setROPumpPWMPct( 0 ); + + // TODO set boost pump to stop +} + +/*********************************************************************//** + * @brief + * The readBoostPumps function reads the PWM and tach counts for each boost pump. + * @details \b Inputs: none + * @details \b Outputs: boostPumpReadDutyCycle[], boostPumpMeasRPM[] + * @return none + *************************************************************************/ +void readBoostPumps( void ) +{ + U32 tach; + + // get latest RO pump duty cycle read back from FPGA + boostPumpReadDutyCycle[ RO_PUMP ].data = getROPumpPWMPct(); + + // get latest RO pump tachometer count from FPGA and convert to RPM + tach = (U32)getROPumpTachCount(); + if ( ( tach != 0 ) && ( tach < BOOST_PUMP_COUNTS_FOR_STOPPED_PUMP ) ) + { + boostPumpMeasRPM[ RO_PUMP ].data = BOOST_PUMP_COUNTS_2_RPM_NUMERATOR / (F32)tach; + } + else + { + boostPumpMeasRPM[ RO_PUMP ].data = 0.0F; + } + + // TODO - get latest for booster pump PWM and tach +} + +/*********************************************************************//** + * @brief + * The setBoostPumpPWMDutyCycle function sets the commanded PWM magnitude (0..500) + * for the given boost pump. + * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if invalid boost pump ID given. + * @details \b Inputs: none + * @details \b Outputs: boostPumpCmdDutyCycle[] + * @param pumpID ID of boost pump to set commanded PWM magnitude for. + * @param pwm Value (0..500) indicating magnitude of PWM duty cycle to set + * @return TRUE if duty cycle set successfully, FALSE if not + *************************************************************************/ +BOOL setBoostPumpPWMDutyCycle( RO_BOOST_PUMP_T pumpID, U16 pwm ) +{ + BOOL result = FALSE; + + if ( pumpID < NUM_OF_BOOST_PUMPS ) + { + // constrain given pwm magnitude to valid range + pwm = MIN( pwm, MAX_BOOST_PUMP_PWM_DUTY_CYCLE ); + // set commanded duty cycle for given boost pump to given pwm magnitude + boostPumpCmdDutyCycle[ pumpID ] = pwm; + if ( RO_PUMP == pumpID ) + { + setROPumpPWMPct( pwm ); + } + else + { + // TODO set boost pump PWM + } + result = TRUE; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RO_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_BOOST_PUMP_ID1, (U32)pumpID ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getBoostPumpPWMDutyCycle function gets the commanded PWM magnitude (0..500) + * for the given boost pump. + * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if invalid boost pump ID given. + * @details \b Inputs: boostPumpCmdDutyCycle[] + * @details \b Outputs: none + * @param pumpID ID of boost pump to get commanded PWM magnitude for. + * @return Value (0..500) indicating magnitude of PWM duty cycle + *************************************************************************/ +U16 getBoostPumpPWMDutyCycle( RO_BOOST_PUMP_T pumpID ) +{ + U16 result = 0; + + if ( pumpID < NUM_OF_BOOST_PUMPS ) + { + result = boostPumpCmdDutyCycle[ pumpID ]; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RO_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_BOOST_PUMP_ID2, (U32)pumpID ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getBoostPumpReadPWMDutyCycle function gets the PWM magnitude (0..500) + * read back from FPGA for the given boost pump. + * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if invalid boost pump ID given. + * @details \b Inputs: boostPumpReadDutyCycle[] + * @details \b Outputs: none + * @param pumpID ID of boost pump to get read back PWM magnitude for. + * @return Value (0..500) indicating magnitude of PWM duty cycle + *************************************************************************/ +U16 getBoostPumpReadPWMDutyCycle( RO_BOOST_PUMP_T pumpID ) +{ + U16 result = 0; + + if ( pumpID < NUM_OF_BOOST_PUMPS ) + { + result = (U16)getU32OverrideValue( &boostPumpReadDutyCycle[ pumpID ] ); + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RO_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_BOOST_PUMP_ID3, (U32)pumpID ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getBoostPumpRPM function gets the measured speed (RPM) for the given + * boost pump. + * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if invalid boost pump ID given. + * @details \b Inputs: boostPumpMeasRPM[] + * @details \b Outputs: none + * @param pumpID ID of boost pump to get measured speed for. + * @return measured pump speed (RPM) for the given pump + *************************************************************************/ +F32 getBoostPumpRPM( RO_BOOST_PUMP_T pumpID ) +{ + F32 result = 0.0F; + + if ( pumpID < NUM_OF_BOOST_PUMPS ) + { + result = (U16)getF32OverrideValue( &boostPumpMeasRPM[ pumpID ] ); + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RO_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_BOOST_PUMP_ID4, (U32)pumpID ) + } + + return result; +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSetBoostPumpPWM function sets a given boost pump to a given PWM + * value. + * @details \b Inputs: none + * @details \b Outputs: valveStates[] + * @param message Override message from Dialin which includes an ID of + * the valve to override and the state to override the valve to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetBoostPumpPWM( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + if ( sizeof( BOOST_PUMP_CMD_PAYLOAD_T ) == message->hdr.payloadLen ) + { + BOOST_PUMP_CMD_PAYLOAD_T payload; + + memcpy( &payload, &message->payload[0], sizeof( BOOST_PUMP_CMD_PAYLOAD_T ) ); + result = setBoostPumpPWMDutyCycle( (RO_BOOST_PUMP_T)payload.pumpID, (U16)payload.pwm ); + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testBoostPumpPWMOverride function overrides the measured PWM of the + * given boost pump. + * @details \b Inputs: none + * @details \b Outputs: boostPumpReadDutyCycle[] + * @param message Override message from Dialin which includes an ID of + * the boost pump to override PWM for and the PWM to override the pump to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testBoostPumpPWMOverride( MESSAGE_T *message ) +{ + BOOL result = u32ArrayOverride( message, &boostPumpReadDutyCycle[0], NUM_OF_BOOST_PUMPS - 1, 0, MAX_BOOST_PUMP_PWM_DUTY_CYCLE ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testBoostPumpRPMOverride function overrides the measured speed (RPM) + * of the given boost pump. + * @details \b Inputs: none + * @details \b Outputs: boostPumpMeasRPM[] + * @param message Override message from Dialin which includes an ID of + * the boost pump to override speed for and the speed to override the pump to. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testBoostPumpRPMOverride( MESSAGE_T *message ) +{ + BOOL result = f32ArrayOverride( message, &boostPumpMeasRPM[0], NUM_OF_BOOST_PUMPS - 1 ); + + return result; +} + +/**@}*/ Index: firmware/App/Drivers/BoostPump.h =================================================================== diff -u --- firmware/App/Drivers/BoostPump.h (revision 0) +++ firmware/App/Drivers/BoostPump.h (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -0,0 +1,61 @@ +/************************************************************************** +* +* Copyright (c) 2020-2024 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 BoostPump.h +* +* @author (last) Sean Nash +* @date (last) 12-Nov-2024 +* +* @author (original) Sean Nash +* @date (original) 12-Nov-2024 +* +***************************************************************************/ + +#ifndef __BOOST_PUMP_H__ +#define __BOOST_PUMP_H__ + +#include "ROCommon.h" + +/** + * @defgroup BoostPump BoostPump + * @brief Boost Pump driver unit. Controls the RO and booster pumps. + * The diaphragm (RO) pump is manufactured by TBD. + * The optional booster pump is manufactured by TBD. + * + * @addtogroup BoostPump + * @{ + */ + +// ********** public definitions ********** + +#define MAX_BOOST_PUMP_PWM_DUTY_CYCLE 500 ///< Maximum settable boost pump duty cycle magnitude. + +/// Enumerations of RO boost pumps. +typedef enum BoostPumps +{ + RO_PUMP = 0, ///< RO pump + RO_BOOST_PUMP, ///< Optional boost pump + NUM_OF_BOOST_PUMPS, ///< Number of boost pumps +} RO_BOOST_PUMP_T; + +// ********** public function prototypes ********** + +void initBoostPump( void ); +void readBoostPumps( void ); + +BOOL setBoostPumpPWMDutyCycle( RO_BOOST_PUMP_T pumpID, U16 pwm ); +U16 getBoostPumpPWMDutyCycle( RO_BOOST_PUMP_T pumpID ); +U16 getBoostPumpReadPWMDutyCycle( RO_BOOST_PUMP_T pumpID ); +F32 getBoostPumpRPM( RO_BOOST_PUMP_T pumpID ); + +BOOL testSetBoostPumpPWM( MESSAGE_T *message ); +BOOL testBoostPumpPWMOverride( MESSAGE_T *message ); +BOOL testBoostPumpRPMOverride( MESSAGE_T *message ); + +/**@}*/ + +#endif Index: firmware/App/Services/AlarmMgmtSWFaults.h =================================================================== diff -u -r2205857f59dd884c4af450239381387cfb560c2e -r0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef --- firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 2205857f59dd884c4af450239381387cfb560c2e) +++ firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -93,6 +93,12 @@ SW_FAULT_ID_VALVES_INVALID_VALVE_ID2 = 76, SW_FAULT_ID_VALVES_INVALID_VALVE_ID3 = 77, SW_FAULT_ID_VALVES_INVALID_VALVE_ID4 = 78, + SW_FAULT_ID_INVALID_BOOST_PUMP_ID1 = 79, + SW_FAULT_ID_INVALID_BOOST_PUMP_ID2 = 80, + SW_FAULT_ID_INVALID_BOOST_PUMP_ID3 = 81, + SW_FAULT_ID_INVALID_BOOST_PUMP_ID4 = 82, + SW_FAULT_ID_RO_PUMP_INVALID_EXEC_STATE = 83, + SW_FAULT_ID_RO_PUMP_INVALID_PUMP_ID1 = 84, NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T; Index: firmware/App/Services/FpgaRO.c =================================================================== diff -u -rc7dcb245c2378b1c96eeaa02f120f61dff598b11 -r0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef --- firmware/App/Services/FpgaRO.c (.../FpgaRO.c) (revision c7dcb245c2378b1c96eeaa02f120f61dff598b11) +++ firmware/App/Services/FpgaRO.c (.../FpgaRO.c) (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -17,16 +17,9 @@ #include "string.h" // for memset(), memcpy() -#include "gio.h" // hal headers -#include "sci.h" -#include "sys_dma.h" - -#include "Comm.h" #include "Compatible.h" -#include "FPGA.h" -#include "Messaging.h" +#include "FpgaRO.h" #include "OperationModes.h" -#include "PersistentAlarm.h" #include "Timers.h" #include "Utilities.h" @@ -124,7 +117,14 @@ U08 conductSensor2ReadCount; ///< Reg 354. Conductivity sensor 2 read counter. U08 conductSensor2ErrorCount; ///< Reg 355. Conductivity sensor 2 error counter. U16 flowRateCountFmp; ///< Reg 356. FMP flow sensor pulse counter. - U16 levelSwitch; ///< Reg 358. LRO1..3 level sensors. + U16 flowTemp; ///< Reg 358. FMP flow sensor temperature. + U16 roPumpTachCount; ///< Reg 360. ROP tachometer counter. + U16 dsPumpTachCount; ///< Reg 362. DSP tachometer counter. + U16 flowIntTemp; ///< Reg 364. FMP flow sensor internal temperature. + U08 valveControlReadback; ///< Reg 366. Valve control bits read back. + U08 valvePWMEnableReadback; ///< Reg 367. Valve PWM enable read back. + U16 roPumpPWMReadback; ///< Reg 368. ROP PWM read back. + U16 heaterPWMReadback; ///< Reg 370. Heater PWM read back. } FPGA_SENSORS_T; /// Record structure for FPGA continuous priority writes. @@ -144,16 +144,9 @@ U08 reserved1; ///< Reg 25. Reserved. U16 valveVwiPWMLow; ///< Reg 26. Valve VWi PWM low pulse period in 0.1 uSec. U16 valveVwiPWMPeriod; ///< Reg 28. Valve VWi PWM full period in 0.1 uSec. - U16 valveVffPWMLow; ///< Reg 30. - U16 valveVffPWMPeriod; ///< Reg 32. - U16 valveVPiPWMLow; ///< Reg 34. - U16 valveVPiPWMPeriod; ///< Reg 36. - U16 valveVcrPWMLow; ///< Reg 38. - U16 valveVcrPWMPeriod; ///< Reg 40. - U16 valveVcmPWMLow; ///< Reg 42. - U16 valveVcmPWMPeriod; ///< Reg 44. - U16 valveVprPWMLow; ///< Reg 46. - U16 valveVprPWMPeriod; ///< Reg 48. + U16 valvePWMPullIn; ///< Reg 30. Valve PWM high pulse period when valve is on in 0.1 uSec. + U16 roPumpPWMDutyCyclePct; ///< Reg 32. ROP PWM duty cycle in percentage. + U16 heaterPWMDutyCyclePct; ///< Reg 34. HRO PWM duty cycle in percentage. } FPGA_ACTUATORS_T; #pragma pack(pop) @@ -350,14 +343,14 @@ * The setFPGAValveStates function sets the RO valve states with an 8-bit * mask of states - one bit per valve, with a 1 meaning "energized" and a 0 * meaning "de-energized". The bit positions for these bit states are as follows: - * 0 - VFf.\n - * 1 - VPi.\n - * 2 - VLp.\n - * 3 - VCr.\n - * 4 - VCb.\n - * 5 - VCd1.\n - * 6 - VROd.\n - * 7 - reserved or unused. + * 0 - VWi.\n + * 1 - VFb.\n + * 2 - VFf.\n + * 3 - VPi.\n + * 4 - VCr.\n + * 5 - VCb.\n + * 6 - VCd.\n + * 7 - VROd.\n * @details \b Inputs: none * @details \b Outputs: fpgaActuatorSetPoints.valveControl * @param valveStates bit mask for requested valve states @@ -374,13 +367,55 @@ * an 8-bit mask representing the set of states with a 1 meaning "energized" * and a 0 meaning "de-energized". * @details \b Inputs: none - * @details \b Outputs: fpgaSensorReadings.TBD + * @details \b Outputs: fpgaSensorReadings.valveControlReadback * @return none *************************************************************************/ U08 getFPGAValveStates( void ) { -// return fpgaSensorReadings.TBD; - return 0; // TODO + return fpgaSensorReadings.valveControlReadback; } +/*********************************************************************//** + * @brief + * The setROPumpPWMPct function sets the RO pump PWM duty cycle. + * The higher the PWM duty cycle (0..500), the faster the pump will go. + * @details \b Inputs: none + * @details \b Outputs: fpgaActuatorSetPoints.roPumpPWMDutyCyclePct + * @param pwm PWM duty cycle magnitude + * @return none + *************************************************************************/ +void setROPumpPWMPct( U16 pwm ) +{ + if ( pwm <= MAX_RO_PUMP_PWM ) + { + fpgaActuatorSetPoints.roPumpPWMDutyCyclePct = pwm; + } +} + +/*********************************************************************//** + * @brief + * The getROPumpPWMPct function gets a read back from FPGA of RO pump PWM + * duty cycle. + * @details \b Inputs: fpgaSensorReadings.roPumpPWMReadback + * @details \b Outputs: none + * @return measured speed (RPM) of the RO pump + *************************************************************************/ +U16 getROPumpPWMPct( void ) +{ + return fpgaSensorReadings.roPumpPWMReadback; +} + +/*********************************************************************//** + * @brief + * The getROPumpTachCount function gets the running 16-bit tachometer count + * from the RO pump hall sensor. + * @details \b Inputs: fpgaSensorReadings.roPumpTachCount + * @details \b Outputs: none + * @return RO pump tachometer count + *************************************************************************/ +U16 getROPumpTachCount( void ) +{ + return fpgaSensorReadings.roPumpTachCount; +} + /**@}*/ Index: firmware/App/Services/FpgaRO.h =================================================================== diff -u -rc7dcb245c2378b1c96eeaa02f120f61dff598b11 -r0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef --- firmware/App/Services/FpgaRO.h (.../FpgaRO.h) (revision c7dcb245c2378b1c96eeaa02f120f61dff598b11) +++ firmware/App/Services/FpgaRO.h (.../FpgaRO.h) (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -5,7 +5,7 @@ * 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 FPGA.h +* @file FpgaRO.h * * @author (last) Sean Nash * @date (last) 09-Nov-2024 @@ -19,18 +19,21 @@ #define __FPGA_RO_H__ #include "ROCommon.h" +#include "FPGA.h" /** * @defgroup FpgaRO FpgaRO * @brief FPGA service unit for RO firmware. * The FPGA unit contains get/set functions for the RO FPGA registers. * - * @addtogroup FpgaTD + * @addtogroup FpgaRO * @{ */ // ********** public definitions ********** +#define MAX_RO_PUMP_PWM 100U ///< Maximum RO pump PWM duty cycle percentage. + // ********** public function prototypes ********** void initFPGARO( void ); @@ -41,6 +44,10 @@ void setFPGAValveStates( U16 valveStates ); U08 getFPGAValveStates( void ); +void setROPumpPWMPct( U16 pwm ); +U16 getROPumpPWMPct( void ); +U16 getROPumpTachCount( void ); + /**@}*/ #endif Index: firmware/App/Services/Messaging.c =================================================================== diff -u -rf3646622112ca7402527b541766b92a6560f2b17 -r0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision f3646622112ca7402527b541766b92a6560f2b17) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -1,15 +1,17 @@ #include // for memcpy() +#include "BoostPump.h" #include "Compatible.h" #include "Messaging.h" #include "OperationModes.h" #include "PAL.h" +#include "PressureSensor.h" +#include "ROPump.h" #include "SystemCommRO.h" #include "Utilities.h" #include "Valves.h" - /** * @addtogroup Messaging * @{ @@ -55,7 +57,10 @@ MSG_ID_RO_SEND_TEST_CONFIGURATION, MSG_ID_RO_VALVE_PUBLISH_INTERVAL_OVERRIDE_REQUEST, MSG_ID_RO_VALVE_CMD_STATE_OVERRIDE_REQUEST, - MSG_ID_RO_VALVE_SENSED_STATE_OVERRIDE_REQUEST + MSG_ID_RO_VALVE_SENSED_STATE_OVERRIDE_REQUEST, + MSG_ID_RO_BOOST_PUMP_SET_PWM_REQUEST, + MSG_ID_RO_BOOST_PUMP_READ_PWM_OVERRIDE_REQUEST, + MSG_ID_RO_BOOST_PUMP_SPEED_OVERRIDE_REQUEST }; /// Message handling function table @@ -66,6 +71,9 @@ &testValvesStatesPublishIntervalOverride, &testValveStateOverride, &testValveSensedStateOverride, + &testSetBoostPumpPWM, + &testBoostPumpPWMOverride, + &testBoostPumpRPMOverride }; #define NUM_OF_FUNCTION_HANDLERS (sizeof(MSG_FUNCTION_HANDLERS) / sizeof(MsgFuncPtr)) Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r129a1c2f4343bc85efdb4767c2dec35e4ba8ce98 -r0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 129a1c2f4343bc85efdb4767c2dec35e4ba8ce98) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -2,6 +2,7 @@ #include "AlarmMgmtRO.h" #include "Messaging.h" #include "OperationModes.h" +#include "ROPump.h" #include "SystemCommRO.h" #include "TaskGeneral.h" //#include "Voltages.h" // TODO uncomment @@ -44,6 +45,9 @@ // // Manage NVDataMgmt process record state machine // execNVDataMgmtProcessRecord(); + // Control RO pumps + execROPumpController(); + // Manage alarm state execAlarmMgmt(); Index: firmware/source/sys_main.c =================================================================== diff -u -r2205857f59dd884c4af450239381387cfb560c2e -r0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef --- firmware/source/sys_main.c (.../sys_main.c) (revision 2205857f59dd884c4af450239381387cfb560c2e) +++ firmware/source/sys_main.c (.../sys_main.c) (revision 0d2351b8e47e40fdcd706ed7b7ac1379b69a20ef) @@ -70,6 +70,7 @@ #include "MsgQueues.h" #include "OperationModes.h" #include "Pressure.h" +#include "ROPump.h" #include "SafetyShutdown.h" #include "SystemCommRO.h" #include "TaskBG.h" @@ -165,6 +166,7 @@ initLevels(); initPressure(); initTemperature(); + initROPump(); initValves(); initOperationModes(); initTestConfigs();