/************************************************************************** * * 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 3-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 VALVE_3WAY_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 ] = VALVE_3WAY_COMMON_TO_CLOSED_STATE; current3WayValveStates[ H20_VALV ] = VALVE_3WAY_COMMON_TO_CLOSED_STATE; setH13ValveState( VALVE_3WAY_COMMON_TO_CLOSED_STATE ); } /*********************************************************************//** * @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, VALVE_3WAY_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. *************************************************************************/ VALVE_3WAY_STATE_T get3WayValveState( VALVE_3_WAY_T valve ) { VALVE_3WAY_STATE_T result = VALVE_3WAY_COMMON_TO_CLOSED_STATE; 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 ) && ( (VALVE_3WAY_STATE_T)payload.state < NUM_OF_OPN_CLS_STATES ) ) { set3WayValveState( (VALVE_3_WAY_T)payload.valve, (VALVE_3WAY_STATE_T)payload.state ); result = TRUE; } } } return result; } /**@}*/