#include "FPGA.h" #include "Switches.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" /** * @addtogroup Switches * @{ */ // ********** private definitions ********** #define SWITCHES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the switches data is published on the CAN bus. #define SWITCHES_FPGA_STATUS_CHECK_INTERVAL ( MS_PER_SECOND / ( 5 * TASK_GENERAL_INTERVAL ) ) ///< Switches FPGA status check interval. // ********** private data ********** static U32 switchesDataPublicationCounter; ///< Switches data publication counter. static OVERRIDE_U32_T switchesDataPublishInterval = { SWITCHES_DATA_PUB_INTERVAL, SWITCHES_DATA_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish switches data to CAN bus. static OVERRIDE_U32_T switchStatus[ NUM_OF_DOORS_AND_CAPS ]; ///< Switches status array. static U32 switchesFPGAStatusCheckCounter; ///< Switches FPGA status check counter. // ********** private function prototypes ********** static void publishSwitchesData( void ); static U32 getPublishSwitchesDataInterval( void ); /*********************************************************************//** * @brief * The initSwitches function initializes the switches module. * @details Inputs: none * @details Outputs: switchesDataPublicationCounter, switchStatus * @return none *************************************************************************/ void initSwitches( void ) { U08 i; switchesDataPublicationCounter = 0; switchesFPGAStatusCheckCounter = 0; // Initialize all the switches for ( i = 0; i < NUM_OF_DOORS_AND_CAPS; i++ ) { switchStatus[ i ].data = (U32)STATE_CLOSED; } } /*********************************************************************//** * @brief * The execSwitches function executes the switches executive. * @details Inputs: switchesFPGAStatusCheckCounter * @details Outputs: switchStatus, switchesFPGAStatusCheckCounter * @return none *************************************************************************/ void execSwitches( void ) { if ( ++switchesFPGAStatusCheckCounter > SWITCHES_FPGA_STATUS_CHECK_INTERVAL ) { switchStatus[ FRONT_DOOR ].data = (U32)( getFPGAFrontDoorStatus() != 0 ? STATE_CLOSED : STATE_OPEN ); switchesFPGAStatusCheckCounter = 0; } publishSwitchesData(); } /*********************************************************************//** * @brief * The getSwitchStatus function returns the status of the called switch. * @details Inputs: switchStatus * @details Outputs: switchStatus * @param switchId which is the switch that its status is requested * @return switch status *************************************************************************/ OPN_CLS_STATE_T getSwitchStatus( SWITCH_T switchId ) { U32 status; if ( switchId < NUM_OF_DOORS_AND_CAPS ) { if ( OVERRIDE_KEY == switchStatus[ switchId ].override ) { status = switchStatus[ switchId ].ovData; } else { status = switchStatus[ switchId ].data; } } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_SWITCH_ID, (U32)switchId ) } return (OPN_CLS_STATE_T)status; } // ********** private functions ********** /*********************************************************************//** * @brief * The publishSwitchesData function broadcasts the switches data at the * publication interval. * @details Inputs: switchesDataPublicationCounter * @details Outputs: switchesDataPublicationCounter * @return none *************************************************************************/ static void publishSwitchesData( void ) { if ( ++switchesDataPublicationCounter > getPublishSwitchesDataInterval() ) { SWITCHES_DATA_T data; data.frontDoor = (U32)getSwitchStatus( FRONT_DOOR ); switchesDataPublicationCounter = 0; broadcastSwitchesData( &data ); } } /*********************************************************************//** * @brief * The getPublishSwitchesDataInterval function returns the data * publication interval either from the data or from the override. * @details Inputs: switchesDataPublishInterval * @details Outputs: none * @return data publish interval *************************************************************************/ static U32 getPublishSwitchesDataInterval( void ) { U32 result = switchesDataPublishInterval.data; if ( OVERRIDE_KEY == switchesDataPublishInterval.override ) { result = switchesDataPublishInterval.ovData; } return result; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /*********************************************************************//** * @brief * The testSetSwitchesDataPublishIntervalOverride function overrides * the switches publish data interval. * @details Inputs: switchesDataPublishInterval * @details Outputs: switchesDataPublishInterval * @param value switches data broadcast interval (in ms) to override * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetSwitchesDataPublishIntervalOverride( U32 value ) { BOOL result = FALSE; if ( isTestingActivated() ) { U32 interval = value / TASK_GENERAL_INTERVAL; result = TRUE; switchesDataPublishInterval.ovData = interval; switchesDataPublishInterval.override = OVERRIDE_KEY; } return result; } /*********************************************************************//** * @brief * The testResetSwitchesDataPublishIntervalOverrid function resets * the override value of switches publish data interval. * @details Inputs: switchesDataPublishInterval * @details Outputs: switchesDataPublishInterval * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testResetSwitchesDataPublishIntervalOverrid( void ) { BOOL result = FALSE; if ( isTestingActivated() ) { result = TRUE; switchesDataPublishInterval.override = OVERRIDE_RESET; switchesDataPublishInterval.ovData = switchesDataPublishInterval.ovInitData; } return result; } /*********************************************************************//** * @brief * The testSetSwitchesStatusOverride function sets the override status * for a specific switch. * @details Inputs: none * @details Outputs: switchStatus * @param switchId switch index * @param status switch status to override if testing is activated * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetSwitchesStatusOverride( U32 switchId, U32 status ) { BOOL result = FALSE; if ( switchId < NUM_OF_DOORS_AND_CAPS ) { if ( isTestingActivated() ) { result = TRUE; switchStatus[ switchId ].ovData = status; switchStatus[ switchId ].override = OVERRIDE_KEY; } } return result; } /*********************************************************************//** * @brief * The testResetSwitchesStatusOverride function resets the override * status of a specified switch. * @details Inputs: none * @details Outputs: switchStatus * @param switchId switch index * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testResetSwitchesStatusOverride( U32 switchId ) { BOOL result = FALSE; if ( switchId < NUM_OF_DOORS_AND_CAPS ) { if ( isTestingActivated() ) { result = TRUE; switchStatus[ switchId ].override = OVERRIDE_RESET; switchStatus[ switchId ].ovData = switchStatus[ switchId ].ovInitData; } } return result; } /**@}*/