Index: firmware/App/Controllers/AirPump.c =================================================================== diff -u -rf3a26c402a2ec88f5ee7dbb8eb7127ab5b4692aa -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Controllers/AirPump.c (.../AirPump.c) (revision f3a26c402a2ec88f5ee7dbb8eb7127ab5b4692aa) +++ firmware/App/Controllers/AirPump.c (.../AirPump.c) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -36,6 +36,7 @@ // ********** private data ********** static AIR_PUMP_STATE_T currentAirPumpState; ///< Current air pump control state. +static U08 currentAirPumpPowerLevel; ///< Current air pump power level setting. static U32 airPumpDataPublicationTimerCounter; ///< Air pump data broadcast timer counter. static OVERRIDE_U32_T airPumpDataPublishInterval; ///< Air pump data broadcast interval (in ms). @@ -61,6 +62,7 @@ // Initialize controller variables airPumpDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; currentAirPumpState = AIR_PUMP_STATE_INIT; + currentAirPumpPowerLevel = AIR_PUMP_MOTOR_OFF; airPumpDataPublishInterval.data = AIR_PUMP_DATA_PUB_INTERVAL; airPumpDataPublishInterval.ovData = AIR_PUMP_DATA_PUB_INTERVAL; airPumpDataPublishInterval.ovInitData = AIR_PUMP_DATA_PUB_INTERVAL; @@ -74,13 +76,20 @@ * @details \b Inputs: currentAirPumpState * @details \b Outputs: currentAirPumpState * @param state Air pump state to set + * @param power Power level to set air pump to * @return none *************************************************************************/ -void setAirPumpState( AIR_PUMP_STATE_T state ) +void setAirPumpState( AIR_PUMP_STATE_T state, U08 power ) { if ( state < NUM_OF_AIR_PUMP_STATES ) { currentAirPumpState = state; + // power level should be 0 (OFF) when pump state is not ON + if ( state != AIR_PUMP_STATE_ON ) + { + power = AIR_PUMP_MOTOR_OFF; + } + currentAirPumpPowerLevel = power; } else { @@ -157,7 +166,11 @@ { AIR_PUMP_STATE_T state = AIR_PUMP_STATE_OFF; - setAirPumpMotorState( AIR_PUMP_MOTOR_OFF ); + if ( getAirPumpMotorPower() != 0 ) + { + currentAirPumpPowerLevel = 0; + setAirPumpMotorPower( currentAirPumpPowerLevel ); + } return state; } @@ -173,7 +186,10 @@ { AIR_PUMP_STATE_T state = AIR_PUMP_STATE_ON; - setAirPumpMotorState( AIR_PUMP_MOTOR_ON ); + if ( getAirPumpMotorPower() != currentAirPumpPowerLevel ) + { + setAirPumpMotorPower( currentAirPumpPowerLevel ); + } return state; } @@ -189,11 +205,14 @@ *************************************************************************/ static void publishAirPumpData( void ) { + currentAirPumpPowerLevel = getAirPumpMotorPower(); // update local power setting from driver + if ( ++airPumpDataPublicationTimerCounter >= getU32OverrideValue( &airPumpDataPublishInterval ) ) { AIR_PUMP_PAYLOAD_T data; data.h12State = getAirPumpState(); + data.h12Power = (U32)currentAirPumpPowerLevel; broadcastData( MSG_ID_TD_AIR_PUMP_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( AIR_PUMP_PAYLOAD_T ) ); airPumpDataPublicationTimerCounter = 0; Index: firmware/App/Controllers/AirPump.h =================================================================== diff -u -rf3a26c402a2ec88f5ee7dbb8eb7127ab5b4692aa -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Controllers/AirPump.h (.../AirPump.h) (revision f3a26c402a2ec88f5ee7dbb8eb7127ab5b4692aa) +++ firmware/App/Controllers/AirPump.h (.../AirPump.h) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -36,7 +36,8 @@ /// Payload record structure for air pump data broadcast message typedef struct { - U32 h12State; ///< Air Pump state status + U32 h12State; ///< Air pump state status + U32 h12Power; ///< Air pump power level setting } AIR_PUMP_PAYLOAD_T; /// Enumeration of air pump states. @@ -52,7 +53,7 @@ void initAirPump(void); void execAirPumpController(void); -void setAirPumpState( AIR_PUMP_STATE_T state ); +void setAirPumpState( AIR_PUMP_STATE_T state, U08 power ); AIR_PUMP_STATE_T getAirPumpState( void ); BOOL testAirPumpDataPublishIntervalOverride( MESSAGE_T *message ); Index: firmware/App/Controllers/AirTrap.c =================================================================== diff -u -r961784c895cb8f551a2623cd02dcbfe42d04b7c2 -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 961784c895cb8f551a2623cd02dcbfe42d04b7c2) +++ firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -26,7 +26,7 @@ #include "TaskGeneral.h" #include "Timers.h" #include "Utilities.h" -#include "Valve2Way.h" +#include "Valve3Way.h" /** * @addtogroup AirTrap @@ -93,7 +93,7 @@ { // Initialize level sensors and valve drivers initLevelSensors(); - init2WayValves(); + init3WayValves(); // Initialize controller variables resetAirTrap(); @@ -151,7 +151,7 @@ if ( TRUE == isAirTrapControlling() ) { pendingStopAirTrapController = TRUE; - set2WayValveState( H13_VALV, STATE_CLOSED ); // Always exit air trap valve control w/ valve closed. + set3WayValveState( H13_VALV, STATE_CLOSED ); // Always exit air trap valve control w/ valve closed. SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_FILL, STATE_CLOSED, 0 ); signalLowVenousPressureCheck(); // Venous pressure check should continue even after ending auto air trap control } @@ -258,7 +258,7 @@ if ( MODE_FAUL == getCurrentOperationMode() ) { airTrapControllerState = AIR_TRAP_MANUAL_CONTROL_STATE; - set2WayValveState( H13_VALV, STATE_CLOSED ); + set3WayValveState( H13_VALV, STATE_CLOSED ); SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_FILL, STATE_CLOSED, 0 ); pendingStartAirTrapController = FALSE; } @@ -308,7 +308,7 @@ if ( TRUE == pendingStartAirTrapController ) { pendingStartAirTrapController = FALSE; - set2WayValveState( H13_VALV, STATE_CLOSED ); + set3WayValveState( H13_VALV, STATE_CLOSED ); SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_FILL, STATE_CLOSED, 0 ); result = AIR_TRAP_VALVE_CLOSED_STATE; } @@ -342,7 +342,7 @@ if ( AIR_PUMP_STATE_ON == getAirPumpState() ) { - setAirPumpState( AIR_PUMP_STATE_OFF ); + setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); } } @@ -352,10 +352,10 @@ airTrapValveOpenAtStartOfTreatement = FALSE; if ( AIR_PUMP_STATE_ON == getAirPumpState() ) { - setAirPumpState( AIR_PUMP_STATE_OFF ); + setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); } - set2WayValveState( H13_VALV, STATE_OPEN ); + set3WayValveState( H13_VALV, STATE_OPEN ); fillStartTime = getMSTimerCount(); SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_FILL, STATE_OPEN, 0 ); result = AIR_TRAP_VALVE_OPEN_STATE; @@ -368,7 +368,7 @@ ( AIR_TRAP_LEVEL_FLUID == getLevelSensorState( H17_LEVL ) ) ) ) ) { - setAirPumpState( AIR_PUMP_STATE_OFF ); + setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); airPumpOnDelayStartTime = getMSTimerCount(); } @@ -378,7 +378,7 @@ if ( ( AIR_PUMP_STATE_OFF == getAirPumpState() ) && ( TRUE == didTimeout( airPumpOnDelayStartTime, AIR_PUMP_ON_DELAY_TIME_MS ) ) ) { - setAirPumpState( AIR_PUMP_STATE_ON ); + setAirPumpState( AIR_PUMP_STATE_ON, 100 ); // TODO - set this depending on level direction, make #define for it stopAirPumpStartTime = getMSTimerCount(); signalInitiatePressureStabilization( USE_SHORT_STABILIZATION_PERIOD ); } @@ -390,10 +390,10 @@ { if ( AIR_PUMP_STATE_ON == getAirPumpState() ) { - setAirPumpState( AIR_PUMP_STATE_OFF ); + setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); } - set2WayValveState( H13_VALV, STATE_OPEN ); + set3WayValveState( H13_VALV, STATE_OPEN ); fillStartTime = getMSTimerCount(); SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_FILL, STATE_OPEN, 0 ); result = AIR_TRAP_VALVE_OPEN_STATE; @@ -424,7 +424,7 @@ // Transition to closed valve state when fluid detected at upper level else if ( AIR_TRAP_LEVEL_FLUID == getRawLevelSensorState( H16_LEVL ) ) { - set2WayValveState( H13_VALV, STATE_CLOSED ); + set3WayValveState( H13_VALV, STATE_CLOSED ); airPumpOnDelayStartTime = u32DiffWithWrap( AIR_PUMP_ON_DELAY_ADJUST_AFTER_FILL, getMSTimerCount() ); signalLowVenousPressureCheck(); SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_TRAP_FILL, STATE_CLOSED, 0 ); @@ -454,8 +454,9 @@ data.h16State = getLevelSensorState( H16_LEVL ); data.h17RawState = getRawLevelSensorState( H17_LEVL ); data.h16RawState = getRawLevelSensorState( H16_LEVL ); - data.h13State = get2WayValveState( H13_VALV ); - data.controlling = isAirTrapControlling(); + data.h13State = get3WayValveState( H13_VALV ); + data.h20State = get3WayValveState( H20_VALV ); + data.controlling = isAirTrapControlling(); broadcastData( MSG_ID_TD_AIR_TRAP_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( AIR_TRAP_PAYLOAD_T ) ); airTrapDataPublicationTimerCounter = 0; Index: firmware/App/Controllers/AirTrap.h =================================================================== diff -u -rf3a26c402a2ec88f5ee7dbb8eb7127ab5b4692aa -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Controllers/AirTrap.h (.../AirTrap.h) (revision f3a26c402a2ec88f5ee7dbb8eb7127ab5b4692aa) +++ firmware/App/Controllers/AirTrap.h (.../AirTrap.h) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -40,7 +40,8 @@ U32 h16State; ///< Upper air trap level sensor state U32 h17RawState; ///< Raw Lower air trap level sensor state U32 h16RawState; ///< Raw Upper air trap level sensor state - U32 h13State; ///< Is air trap valve open or closed + U32 h13State; ///< Is air trap intake valve open or closed + U32 h20State; ///< Is air trap outlet valve open or closed BOOL controlling; ///< Flag indicates whether air trap level is being auto controlled } AIR_TRAP_PAYLOAD_T; Index: firmware/App/Drivers/GLXferPump.c =================================================================== diff -u -r87d705fcf977af12b7b034735fa5867f2daea2b9 -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Drivers/GLXferPump.c (.../GLXferPump.c) (revision 87d705fcf977af12b7b034735fa5867f2daea2b9) +++ firmware/App/Drivers/GLXferPump.c (.../GLXferPump.c) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -16,6 +16,7 @@ ***************************************************************************/ #include "AlarmMgmtTD.h" +#include "FpgaTD.h" #include "GLXferPump.h" #include "GPIO.h" #include "Messaging.h" @@ -29,7 +30,7 @@ // ********** private data ********** -static AIR_PUMP_MOTOR_STATE_T currentAirPumpMotorState; ///< Current air pump motor state (on/off). +static U08 currentAirPumpMotorPowerLevel; ///< Current air pump motor state: 0=off, 1..255=power level. // ********** private function prototypes ********** @@ -43,48 +44,42 @@ *************************************************************************/ void initGasLiqXferPumpDriver(void) { - currentAirPumpMotorState = AIR_PUMP_MOTOR_OFF; - setAirPumpMotorSignal( (PIN_SIGNAL_STATE_T)currentAirPumpMotorState ); + currentAirPumpMotorPowerLevel = AIR_PUMP_MOTOR_OFF; + setAirPumpMotorPowerLevel( currentAirPumpMotorPowerLevel ); } /*********************************************************************//** * @brief - * The setAirPumpMotorState function sets the air pump motor state to on or off. + * The setAirPumpMotorState function sets the air pump motor to the given + * power level. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if invalid state given. * @details \b Inputs: none * @details \b Outputs: currentAirPumpMotorState - * @param state State to set the air pump motor (on/off). + * @param power Power level for air pump (0=off, 1..255=lower to higher power level). * @return none. *************************************************************************/ -void setAirPumpMotorState( AIR_PUMP_MOTOR_STATE_T state ) +void setAirPumpMotorPower( U08 power ) { - if ( state < NUM_OF_AIR_PUMP_MOTOR_STATES ) + // if state is changing, set the air pump to the given on/off state and send event + if ( power != currentAirPumpMotorPowerLevel ) { - // if state is changing, set the air pump to the given on/off state and send event - if ( state != currentAirPumpMotorState ) - { - SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_PUMP_ON_OFF, (U32)currentAirPumpMotorState, (U32)state ); - setAirPumpMotorSignal( (PIN_SIGNAL_STATE_T)state ); - currentAirPumpMotorState = state; - } + SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_AIR_PUMP_ON_OFF, (U32)currentAirPumpMotorPowerLevel, (U32)power ); + setAirPumpMotorPowerLevel( power ); + currentAirPumpMotorPowerLevel = power; } - else - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_AIR_PUMP_INVALID_STATE, (U32)state ) - } } /*********************************************************************//** * @brief - * The getAirPumpMotorState function gets the current state of the air pump - * motor. + * The getAirPumpMotorState function gets the current set power level of the + * air pump motor. * @details \b Inputs: currentAirPumpMotorState * @details \b Outputs: none - * @return Current on/off state of the air pump motor. + * @return Current set power level of the air pump motor. *************************************************************************/ -AIR_PUMP_MOTOR_STATE_T getAirPumpMotorState( void ) +U08 getAirPumpMotorPower( void ) { - return currentAirPumpMotorState; + return currentAirPumpMotorPowerLevel; } @@ -112,14 +107,11 @@ // Verify payload length is valid if ( sizeof( U32 ) == message->hdr.payloadLen ) { - U32 state; + U32 power; - memcpy( &state, message->payload, sizeof(U32) ); - if ( state < NUM_OF_AIR_PUMP_MOTOR_STATES ) - { - setAirPumpMotorState( (AIR_PUMP_MOTOR_STATE_T)state ); - result = TRUE; - } + memcpy( &power, message->payload, sizeof(U32) ); + setAirPumpMotorPower( (U08)power ); + result = TRUE; } } Index: firmware/App/Drivers/GLXferPump.h =================================================================== diff -u -rd9b5f588d81e15ed3849222bed3362e15dbf4b0a -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Drivers/GLXferPump.h (.../GLXferPump.h) (revision d9b5f588d81e15ed3849222bed3362e15dbf4b0a) +++ firmware/App/Drivers/GLXferPump.h (.../GLXferPump.h) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -33,19 +33,13 @@ // ********** public definitions ********** -/// Enumeration of air pump motor states. -typedef enum AirPumpMotorStates -{ - AIR_PUMP_MOTOR_OFF = 0, ///< Air Pump Off. - AIR_PUMP_MOTOR_ON, ///< Air Pump On. - NUM_OF_AIR_PUMP_MOTOR_STATES, ///< Number of air pump motor states. -} AIR_PUMP_MOTOR_STATE_T; +#define AIR_PUMP_MOTOR_OFF 0 ///< Power level setting to turn the H12 air pump off. // ********** public function prototypes ********** void initGasLiqXferPumpDriver( void ); -void setAirPumpMotorState( AIR_PUMP_MOTOR_STATE_T state ); -AIR_PUMP_MOTOR_STATE_T getAirPumpMotorState( void ); +void setAirPumpMotorPower( U08 power ); +U08 getAirPumpMotorPower( void ); BOOL testSetAirPump( MESSAGE_T *message ); Index: firmware/App/Drivers/GPIO.c =================================================================== diff -u -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Drivers/GPIO.c (.../GPIO.c) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) +++ firmware/App/Drivers/GPIO.c (.../GPIO.c) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -50,9 +50,6 @@ #define SAFE_GIO_PORT_PIN 2U ///< GPIO pin ID on port B for safety shutdown input signal. #define SAFETY_GIO_PORT_PIN 3U ///< GPIO pin ID on port B for safety shutdown output signal -// hetPORT1 pin assignments -#define AIR_PUMP_GPIO_PIN 4U ///< GPIO pin ID on hetPORT1 for air pump motor state. - // MIBSPI5 port pin assignments for pins connected to CPLD #define GREEN_SPI5_PORT_MASK 0x00000200 ///< (CLK - re-purposed as output GPIO) for green alarm lamp signal. #define BLUE_SPI5_PORT_MASK 0x00000400 ///< (SIMO[0] - re-purposed as output GPIO) for blue alarm lamp signal. @@ -358,18 +355,4 @@ CLR_BACKUP_AUDIO_ENABLE() } -/*********************************************************************//** - * @brief - * The setAirPumpMotorSignal function sets the air pump output signal to - * the given pin level. - * @details \b Inputs: none - * @details \b Outputs: Air pump output signal set to given level. - * @param signal Signal level to set the air pump output to - * @return none - *************************************************************************/ -void setAirPumpMotorSignal( PIN_SIGNAL_STATE_T signal ) -{ - gioSetBit( hetPORT1, AIR_PUMP_GPIO_PIN, (U32)signal ); -} - /**@}*/ Index: firmware/App/Drivers/GPIO.h =================================================================== diff -u -r3a8cf075eb6f0d255f516ac26bac7fbaacfde14a -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Drivers/GPIO.h (.../GPIO.h) (revision 3a8cf075eb6f0d255f516ac26bac7fbaacfde14a) +++ firmware/App/Drivers/GPIO.h (.../GPIO.h) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -58,8 +58,6 @@ void setAlarmBuzzerSignal( void ); void clrAlarmBuzzerSignal( void ); -void setAirPumpMotorSignal( PIN_SIGNAL_STATE_T signal ); - /**@}*/ #endif Fisheye: Tag 552a7de419344b43a3307c61141c99bfbbee7345 refers to a dead (removed) revision in file `firmware/App/Drivers/Valve2Way.c'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 552a7de419344b43a3307c61141c99bfbbee7345 refers to a dead (removed) revision in file `firmware/App/Drivers/Valve2Way.h'. Fisheye: No comparison available. Pass `N' to diff? Index: firmware/App/Drivers/Valve3Way.c =================================================================== diff -u --- firmware/App/Drivers/Valve3Way.c (revision 0) +++ firmware/App/Drivers/Valve3Way.c (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -0,0 +1,161 @@ +/************************************************************************** +* +* Copyright (c) 2024-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 Valve3Way.c +* +* @author (last) Sean +* @date (last) 03-Oct-2024 +* +* @author (original) Sean +* @date (original) 03-Oct-2024 +* +***************************************************************************/ + +#include "AlarmMgmtTD.h" +#include "FpgaTD.h" +#include "GPIO.h" +#include "Messaging.h" +#include "Valve3Way.h" + +/** + * @addtogroup Valve3Way + * @{ + */ + +// ********** private definitions ********** + +/// Payload record structure for 2-way valve set request +typedef struct +{ + U32 valve; ///< which 3-way valve to set (0=H13, 1=H20) + U32 state; ///< 0=normally closed, 1=normally open +} VALVE_3_WAY_SET_CMD_PAYLOAD_T; + +// ********** private data ********** + +static OPN_CLS_STATE_T current3WayValveStates[ NUM_OF_3_WAY_VALVES ]; ///< Current 3-way valve states (open/closed). + +// ********** private function prototypes ********** + +/*********************************************************************//** + * @brief + * The init3WayValves function initializes the 3-way valve driver unit. + * @details \b Inputs: none + * @details \b Outputs: 3-way valve driver unit initialized. + * @return none + *************************************************************************/ +void init3WayValves(void) +{ + // Close all 3-way valves + current3WayValveStates[ H13_VALV ] = STATE_CLOSED; + current3WayValveStates[ H20_VALV ] = STATE_CLOSED; + setH13ValveState( STATE_CLOSED ); +} + +/*********************************************************************//** + * @brief + * The set3WayValveState function sets a given 3-way valve to a given state + * (normally open / normally closed). + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if invalid valve or state given. + * @details \b Inputs: none + * @details \b Outputs: current2WayValveStates[] + * @param valve ID of 3-way valve to set state for + * @param state ID of state to set valve to + * @return none. + *************************************************************************/ +void set3WayValveState( VALVE_3_WAY_T valve, OPN_CLS_STATE_T state ) +{ + if ( ( valve < NUM_OF_3_WAY_VALVES ) && ( state < NUM_OF_OPN_CLS_STATES ) ) + { + // if state is changing, set the valve to the given open/closed state + if ( state != current3WayValveStates[ valve ] ) + { + if ( H13_VALV == valve ) + { + setH13ValveState( state ); + } + else // H20_VALV is only other valve + { + setH20ValveState( state ); + } + current3WayValveStates[ valve ] = state; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_3_WAY_VALVE_INVALID_VALVE_OR_STATE1, + (((U32)valve << SHIFT_16_BITS_FOR_WORD_SHIFT) | (U32)state ) ) + } +} + +/*********************************************************************//** + * @brief + * The get3WayValveState function gets the current state of a given 3-way + * valve. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if invalid valve given. + * @details \b Inputs: current2WayValveStates[] + * @details \b Outputs: none + * @return Current state of the given 3-way valve. + *************************************************************************/ +OPN_CLS_STATE_T get3WayValveState( VALVE_3_WAY_T valve ) +{ + OPN_CLS_STATE_T result = STATE_CLOSED; + + if ( valve < NUM_OF_3_WAY_VALVES ) + { + result = current3WayValveStates[ valve ]; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_3_WAY_VALVE_INVALID_VALVE_OR_STATE2, (U32)valve ) + } + + return result; +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSet3WayValve function sets a given 3-way valve to a given state + * (Normally open / normally closed). + * @details \b Inputs: none + * @details \b Outputs: current2WayValveStates[] + * @param message set message from Dialin which includes the valve to set + * and the state to set the valve to. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testSet3WayValve( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // Verify tester has logged in with TD + if ( TRUE == isTestingActivated() ) + { + // Verify payload length is valid + if ( sizeof( VALVE_3_WAY_SET_CMD_PAYLOAD_T ) == message->hdr.payloadLen ) + { + VALVE_3_WAY_SET_CMD_PAYLOAD_T payload; + + memcpy( &payload, message->payload, sizeof(VALVE_3_WAY_SET_CMD_PAYLOAD_T) ); + if ( ( (VALVE_3_WAY_T)payload.valve < NUM_OF_3_WAY_VALVES ) && ( (OPN_CLS_STATE_T)payload.state < NUM_OF_OPN_CLS_STATES ) ) + { + set3WayValveState( (VALVE_3_WAY_T)payload.valve, (OPN_CLS_STATE_T)payload.state ); + result = TRUE; + } + } + } + + return result; +} + +/**@}*/ + Index: firmware/App/Drivers/Valve3Way.h =================================================================== diff -u --- firmware/App/Drivers/Valve3Way.h (revision 0) +++ firmware/App/Drivers/Valve3Way.h (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -0,0 +1,59 @@ +/************************************************************************** +* +* Copyright (c) 2024-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 Valve3Way.h +* +* @author (last) Sean +* @date (last) 03-Oct-2024 +* +* @author (original) Sean +* @date (original) 03-Oct-2024 +* +***************************************************************************/ + +#ifndef __VALVE_3_WAY_H__ +#define __VALVE_3_WAY_H__ + +// ********** public definitions ********** + +#include "TDCommon.h" + +/** + * @defgroup Valve3Way Valve3Way + * @brief 3 way valve driver unit. Provides low level functions + * to control a 3 way valve. 3-way valves have a common port + * (always open) and 2 other ports of which one will be open and + * the other closed. So air can flow through 1 of 2 possible paths: + * common to normally open port or common to normally closed port. + * When the valve is "CLOSED", the normally open port is open. + * When the valve is "OPEN", the normally closed port is open. + * + * @addtogroup Valve3Way + * @{ + */ + +// ********** public definitions ********** + +/// 3 way valve names +typedef enum valves3WayNames +{ + H13_VALV = 0, ///< Air trap intake valve + H20_VALV, ///< Air trap outlet valve + NUM_OF_3_WAY_VALVES ///< Number of 3 way valves +} VALVE_3_WAY_T; + +// ********** public function prototypes ********** + +void init3WayValves( void ); +void set3WayValveState( VALVE_3_WAY_T valve, OPN_CLS_STATE_T state ); +OPN_CLS_STATE_T get3WayValveState( VALVE_3_WAY_T valve ); + +BOOL testSet3WayValve( MESSAGE_T *message ); + +/**@}*/ + +#endif Index: firmware/App/Services/AlarmMgmtSWFaults.h =================================================================== diff -u -r051326e2671e8d5b3e99eaa109ea549e94a929f3 -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 051326e2671e8d5b3e99eaa109ea549e94a929f3) +++ firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -124,8 +124,8 @@ SW_FAULT_ID_PRES_LIMITS_INVALID_STATE = 93, SW_FAULT_ID_LEVEL_SENSOR_INVALID_SENSOR = 94, SW_FAULT_ID_AIR_TRAP_INVALID_STATE = 95, - SW_FAULT_ID_2_WAY_VALVE_INVALID_VALVE_OR_STATE1 = 96, - SW_FAULT_ID_2_WAY_VALVE_INVALID_VALVE_OR_STATE2 = 97, + SW_FAULT_ID_3_WAY_VALVE_INVALID_VALVE_OR_STATE1 = 96, + SW_FAULT_ID_3_WAY_VALVE_INVALID_VALVE_OR_STATE2 = 97, SW_FAULT_ID_VALVES_INVALID_VALVE1 = 98, SW_FAULT_ID_VALVES_INVALID_VALVE2 = 99, SW_FAULT_ID_VALVES_INVALID_VALVE3 = 100, @@ -143,7 +143,6 @@ SW_FAULT_ID_TD_VALVES_INVALID_STATE = 112, SW_FAULT_ID_BLOOD_FLOW_SET_TOO_HIGH = 113, SW_FAULT_ID_BLOOD_FLOW_INVALID_BLOOD_PUMP_STATE = 114, - SW_FAULT_ID_TD_AIR_PUMP_INVALID_STATE = 115, NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T; Index: firmware/App/Services/FpgaTD.c =================================================================== diff -u -r961784c895cb8f551a2623cd02dcbfe42d04b7c2 -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 961784c895cb8f551a2623cd02dcbfe42d04b7c2) +++ firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -50,6 +50,7 @@ #define FPGA_H4_HOME_BIT_MASK 0x04 ///< Bit mask for requesting a blood pump home operation. #define FPGA_H13_OPEN_BIT_MASK 0x01 ///< Bit mask for setting H13 valve position to open. +#define FPGA_H20_OPEN_BIT_MASK 0x02 ///< Bit mask for setting H20 valve position to open. #define FPGA_INPUT_VOLTAGE_SCALE 3.0F ///< FPGA source and aux voltage. #define FPGA_PVN_VOLTAGE_SCALE 1.0F ///< FPGA pvn voltage. @@ -143,8 +144,8 @@ typedef struct { U16 fpgaGenWrRd; ///< Reg 04. FPGA general write/read-back register (mirrored to a general read register in read page at addr 256). - U08 h13Control; ///< Reg 06. H13 valve control register. - U08 h13PWMEnable; ///< Reg 07. H13 valve PWM enable register. + U08 airTrapControl; ///< Reg 06. Air trap valve control register. + U08 airTrapPWMEnable; ///< Reg 07. Air trap valve PWM enable register. U16 h13PWMLowPeriod; ///< Reg 08. H13 PWM low signal period register. U16 h13PWMPeriod; ///< Reg 10. H13 PWM period register. U16 h13PWMPUllInTime; ///< Reg 12. H13 PWM pull in time register. @@ -704,16 +705,51 @@ { if ( STATE_OPEN == state ) { - fpgaActuatorSetPoints.h13Control |= FPGA_H13_OPEN_BIT_MASK; + fpgaActuatorSetPoints.airTrapControl |= FPGA_H13_OPEN_BIT_MASK; } else { - fpgaActuatorSetPoints.h13Control &= ~((U08)FPGA_H13_OPEN_BIT_MASK); + fpgaActuatorSetPoints.airTrapControl &= ~((U08)FPGA_H13_OPEN_BIT_MASK); } } /*********************************************************************//** * @brief + * The setH20ValveState function sets the command position for H20 valve. + * @note VBTControl register bit 0 will drive state of H13 valve (0=closed, 1=open). + * @details \b Inputs: fpgaActuatorSetPoints + * @details \b Outputs: fpgaActuatorSetPoints + * @param state : The valve state to command H13 valve to + * @return none + *************************************************************************/ +void setH20ValveState( OPN_CLS_STATE_T state ) +{ + if ( STATE_OPEN == state ) + { + fpgaActuatorSetPoints.airTrapControl |= FPGA_H20_OPEN_BIT_MASK; + } + else + { + fpgaActuatorSetPoints.airTrapControl &= ~((U08)FPGA_H20_OPEN_BIT_MASK); + } +} + +/*********************************************************************//** + * @brief + * The setAirPumpMotorPowerLevel function sets the air pump motor power level + * to 0 to turn pump off or 1..255 for varying power levels. + * @details \b Inputs: fpgaActuatorSetPoints.h12Control + * @details \b Outputs: fpgaActuatorSetPoints.h12Control + * @param power : The set power level to set the H12 air pump to. + * @return none + *************************************************************************/ +void setAirPumpMotorPowerLevel( U08 power ) +{ + fpgaActuatorSetPoints.h12Control = power; +} + +/*********************************************************************//** + * @brief * The H18BubbleDetected function determines whether H18 bubble detector * sensor is currently detecting a bubble. * @details \b Inputs: fpgaSensorReadings Index: firmware/App/Services/FpgaTD.h =================================================================== diff -u -rf3a26c402a2ec88f5ee7dbb8eb7127ab5b4692aa -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision f3a26c402a2ec88f5ee7dbb8eb7127ab5b4692aa) +++ firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -83,7 +83,10 @@ void clearFPGAVenousBubbleSelfTest( void ); void setH13ValveState( OPN_CLS_STATE_T state ); +void setH20ValveState( OPN_CLS_STATE_T state ); +void setAirPumpMotorPowerLevel( U08 power ); + void setH19Control( U08 controlBits ); U08 getH19Control( void ); void setH19Position( U16 setPoint ); Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r56100135135bb715d316b5fd002a4a4951b9334a -r552a7de419344b43a3307c61141c99bfbbee7345 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 56100135135bb715d316b5fd002a4a4951b9334a) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 552a7de419344b43a3307c61141c99bfbbee7345) @@ -34,7 +34,7 @@ #include "Switches.h" #include "SystemCommTD.h" #include "Utilities.h" -#include "Valve2Way.h" +#include "Valve3Way.h" #include "Valves.h" #include "Voltages.h" #include "WatchdogMgmt.h" @@ -151,7 +151,7 @@ &testLevelSensorOverride, &testRawLevelSensorOverride, &testAirTrapDataPublishIntervalOverride, - &testSet2WayValve, + &testSet3WayValve, &testSetValve, &testValveStatusOverride, &testValveEncoderPositionOverride,