/************************************************************************** * * 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 Valve2Way.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 "Valve2Way.h" /** * @addtogroup Valve2Way * @{ */ // ********** private definitions ********** /// Payload record structure for 2-way valve set request typedef struct { U32 valve; ///< which 2-way valve to set (0=VBT) U32 state; ///< 0=closed, 1=open } VALVE_2_WAY_SET_CMD_PAYLOAD_T; // ********** private data ********** static OPN_CLS_STATE_T current2WayValveStates[ NUM_OF_2_WAY_VALVES ]; ///< Current 2-way valve states (open/closed). // ********** private function prototypes ********** /*********************************************************************//** * @brief * The init2WayValves function initializes the 2-way valve driver unit. * @details \b Inputs: none * @details \b Outputs: 2-way valve driver unit initialized. * @return none *************************************************************************/ void init2WayValves(void) { // Close all 2-way valves current2WayValveStates[ H13_VALV ] = STATE_CLOSED; setH13ValveState( STATE_CLOSED ); } /*********************************************************************//** * @brief * The set2WayValveState function sets a given 2-way valve to a given state * (open/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 2-way valve to set state for * @param state ID of state to set valve to * @return none. *************************************************************************/ void set2WayValveState( VALVE_2_WAY_T valve, OPN_CLS_STATE_T state ) { if ( ( valve < NUM_OF_2_WAY_VALVES ) && ( state < NUM_OF_OPN_CLS_STATES ) ) { if ( H13_VALV == valve ) { // if state is changing, set the valve to the given open/closed state if ( state != current2WayValveStates[ valve ] ) { setH13ValveState( state ); current2WayValveStates[ valve ] = state; } } } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_2_WAY_VALVE_INVALID_VALVE_OR_STATE1, (((U32)valve << SHIFT_16_BITS_FOR_WORD_SHIFT) | (U32)state ) ) } } /*********************************************************************//** * @brief * The get2WayValveState function gets the current state of a given 2-way * valve. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if invalid valve given. * @details \b Inputs: current2WayValveStates[] * @details \b Outputs: none * @return Current open/closed state of the given 2-way valve. *************************************************************************/ OPN_CLS_STATE_T get2WayValveState( VALVE_2_WAY_T valve ) { OPN_CLS_STATE_T result = STATE_CLOSED; if ( valve < NUM_OF_2_WAY_VALVES ) { result = current2WayValveStates[ valve ]; } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_2_WAY_VALVE_INVALID_VALVE_OR_STATE2, (U32)valve ) } return result; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /*********************************************************************//** * @brief * The testSet2WayValve function sets a given 2-way valve to a given state (open/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 testSet2WayValve( MESSAGE_T *message ) { BOOL result = FALSE; // Verify tester has logged in with TD if ( TRUE == isTestingActivated() ) { // Verify payload length is valid if ( sizeof( VALVE_2_WAY_SET_CMD_PAYLOAD_T ) == message->hdr.payloadLen ) { VALVE_2_WAY_SET_CMD_PAYLOAD_T payload; memcpy( &payload, message->payload, sizeof(VALVE_2_WAY_SET_CMD_PAYLOAD_T) ); if ( ( (VALVE_2_WAY_T)payload.valve < NUM_OF_2_WAY_VALVES ) && ( (OPN_CLS_STATE_T)payload.state < NUM_OF_OPN_CLS_STATES ) ) { set2WayValveState( (VALVE_2_WAY_T)payload.valve, (OPN_CLS_STATE_T)payload.state ); result = TRUE; } } } return result; } /**@}*/