/**********************************************************************//** * * Copyright (c) 2020-2020 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 Valves.c * * @date 21-Apr-2020 * @author P. Montazemi * * @brief Valves source file. * **************************************************************************/ #include "AlarmMgmt.h" #include "FPGA.h" #include "OperationModes.h" #include "SystemCommMessages.h" #include "TaskPriority.h" #include "Timers.h" #include "Valves.h" /** * @addtogroup DGValves * @{ */ // ********** private definitions ********** //#define DEENERGIZED 0 //#define ENERGIZED 1 //#define INIT_VALVE_STATE 0b0000000000000000 /// Default publication interval for valve states #define VALVES_STATE_PUB_INTERVAL ( 500 / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the valves state is published on the CAN bus // ********** private data ********** static U32 valveStatePublicationTimerCounter = 0; ///< used to schedule valve state publication to CAN bus static OVERRIDE_U32_T valveStatePublishInterval = { VALVES_STATE_PUB_INTERVAL, VALVES_STATE_PUB_INTERVAL, 0, 0 }; ///< interval (in ms/task interval) at which to publish valves state to CAN bus static OVERRIDE_F32_T valves[ NUM_OF_VALVE_IDS ]; ///< Obtained state from valves // ********** private function prototypes ********** static void checkValves( void ); static void publishValvesState( void ); static DATA_GET_PROTOTYPE( U32, getPublishValvesStateInterval ); /**@}*/ /*********************************************************************//** * @brief * The initValves function initializes the Valves module. * @details * Inputs : none * Outputs : Valves module initialized. * @return none *************************************************************************/ void initValves( void ) { setFPGAValveStates( INIT_VALVES_STATES ) valvesStatePublicationTimerCounter = 0; valvesSelfTestTimerCount = 0; } /*********************************************************************//** * @brief * The execValves function executes the valve driver. * @details * Inputs : valvesState * Outputs : valvesState * @return none *************************************************************************/ void execValves( void ) { setFPGAValveStates( valvesStates ); // publish valves states on interval publishValvesStates(); } /*********************************************************************//** * @brief * The checkValveState function checks the validity of the requested valve state. * @details * Inputs : valveID, valveState * Outputs : none * @return none *************************************************************************/ static void checkValveState( void ) { /* TODO: compare the requested valve state to the allowable valves \n * states for a given valve; * - if checks, return True * - if not, return false */ } /*********************************************************************//** * @brief * The getPublishValveStateInterval function gets the valves states \n * publication interval. * @details * Inputs : valvesStatePublishInterval * Outputs : none * @return the current valves states publication interval (in task intervals). *************************************************************************/ U32 getPublishValvesStatesInterval( void ) { U32 result = valvesStatesPublishInterval.data; if ( OVERRIDE_KEY == valvesStatesPublishInterval.override ) { result = valvesStatesPublishInterval.ovData; } return result; } /*********************************************************************//** * @brief * The getValveState function gets the current valve state for given valve ID. * @details * Inputs : valveState * Outputs : none * @return the current valve state for given valve ID. *************************************************************************/ F32 getValveState( U32 valveID ) { BOOL valveState = DEENERGIZED; if ( valveID < NUM_OF_VALVE_IDS ) { if ( OVERRIDE_KEY == valves[ valveID ].override ) { valveState = valves[ valveID ].ovData; } else { valveState = valves[ valveID ].data; } } else { activateAlarmNoData( ALARM_ID_VALVE_STATE_ERROR ); } return valveState; } /*********************************************************************//** * * @brief * The publishValvesState function publishes DG valves state at the \n * set interval. * @details * Inputs : valvesStatePublicationTimerCounter * Outputs : DG valves states are published to CAN bus * @return none *************************************************************************/ static void publishValvesStates( void ) { // publish valve state on interval if ( ++valvesStatesPublicationTimerCounter >= getPublishValvesStatesInterval() ) { broadcastValvesState( getFPGAValveStates() ); valvesStatesPublicationTimerCounter = 0; } } /*********************************************************************//** * @brief * The execPressuresTest function executes the state machine for the \n * Pressures self test. * @details * Inputs : none * Outputs : none * @return the current state of the Pressures self test. *************************************************************************/ SELF_TEST_STATUS_T execPressuresTest( void ) { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_FAILED; // TODO - implement self test(s) return result; } /**@}*/ /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /*********************************************************************//** * @brief * The testSetPressuresDataPublishIntervalOverride function overrides the \n * pressure and occlusion data publish interval. * @details * Inputs : none * Outputs : pressuresDataPublishInterval * @param value : override pressure and occlusion data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetPressuresDataPublishIntervalOverride( U32 value ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { U32 intvl = value / TASK_PRIORITY_INTERVAL; result = TRUE; pressuresDataPublishInterval.ovData = intvl; pressuresDataPublishInterval.override = OVERRIDE_KEY; } return result; } /*********************************************************************//** * @brief * The testResetPressuresDataPublishIntervalOverride function resets the override \n * of the pressure and occlusion data publish interval. * @details * Inputs : none * Outputs : pressuresDataPublishInterval * @return TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetPressuresDataPublishIntervalOverride( void ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { result = TRUE; pressuresDataPublishInterval.override = OVERRIDE_RESET; pressuresDataPublishInterval.ovData = pressuresDataPublishInterval.ovInitData; } return result; } /*********************************************************************//** * @brief * The testSetDGPressureSensorOverride function overrides the value of the \n * specified pressure sensor with a given value. * Inputs : none * Outputs : pressures[] * @param sensor : ID of pressure sensor to override for * @param value : override value for the given pressure sensor ID * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetDGPressureSensorOverride( U32 sensor, F32 value ) { BOOL result = FALSE; if ( sensor < NUM_OF_PRESSURE_SENSORS ) { if ( TRUE == isTestingActivated() ) { result = TRUE; pressures[ sensor ].ovData = value; pressures[ sensor ].override = OVERRIDE_KEY; } } return result; } /*********************************************************************//** * @brief * The testResetDGPressureSensorOverride function resets the override of the \n * specified DG pressure sensor. * @details * Inputs : none * Outputs : pressures[] * @param value : ID of sensor to reset override pressure for * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testResetDGPressureSensorOverride( U32 sensor ) { BOOL result = FALSE; if ( sensor < NUM_OF_PRESSURE_SENSORS ) { if ( TRUE == isTestingActivated() ) { result = TRUE; pressures[ sensor ].override = OVERRIDE_RESET; pressures[ sensor ].ovData = pressures[ sensor ].ovInitData; } } return result; }