/************************************************************************** * * 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 BubbleDetector.c * * @author (last) Sean * @date (last) 22-Aug-2024 * * @author (original) Sean * @date (original) 22-Aug-2024 * ***************************************************************************/ #include "BubbleDetector.h" #include "FpgaTD.h" #include "Messaging.h" /** * @addtogroup BubbleDetector * @{ */ // ********** private definitions ********** // ********** private data ********** /// Current bubble detected states (overrideable). static OVERRIDE_U32_T currentBubbleState[ NUM_OF_BUBBLE_DETECTORS ]; // ********** private function prototypes ********** /*********************************************************************//** * @brief * The initBubbleDetector function initializes the BubbleDetector unit. * @details \b Inputs: none * @details \b Outputs: Bubble Detector unit is initialized. * @return none *************************************************************************/ void initBubbleDetector( void ) { currentBubbleState[ BUBBLE_DETECTOR_ADV ].data = NO_BUBBLE_DETECTED; currentBubbleState[ BUBBLE_DETECTOR_ADV ].ovData = NO_BUBBLE_DETECTED; currentBubbleState[ BUBBLE_DETECTOR_ADV ].ovInitData = NO_BUBBLE_DETECTED; currentBubbleState[ BUBBLE_DETECTOR_ADV ].override = OVERRIDE_RESET; } /*********************************************************************//** * @brief * The readBubbleDetector function gets the current bubble detected state * for a all bubble detector sensors from the FPGA. * @note This function should be called periodically to maintain fresh * sensor readings for all bubble detectors. * @details \b Inputs: FPGA * @details \b Outputs: none * @return none *************************************************************************/ void readBubbleDetectors( void ) { BOOL bubble; bubble = ADVBubbleDetected(); // read current sensor state from FPGA currentBubbleState[ BUBBLE_DETECTOR_ADV ].data = (U32)( FALSE == bubble ? NO_BUBBLE_DETECTED : BUBBLE_DETECTED ); } /*********************************************************************//** * @brief * The getBubbleDetectedState function gets the current bubble detected state * for a given bubble detector sensor. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given sensor is invalid. * @details \b Inputs: currentBubbleState * @details \b Outputs: none * @param sensor ID of bubble detector sensor to get state for. * @return The current state of the given bubble detector sensor. *************************************************************************/ BUBBLE_STATE_T getBubbleDetectedState( BUBBLE_DETECTOR_T sensor ) { BUBBLE_STATE_T result = NO_BUBBLE_DETECTED; if ( sensor < NUM_OF_BUBBLE_DETECTORS ) { result = (BUBBLE_STATE_T)currentBubbleState[ sensor ].data; if ( OVERRIDE_KEY == currentBubbleState[ sensor ].override ) { result = (BUBBLE_STATE_T)currentBubbleState[ sensor ].ovData; } } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_BUBBLE_DETECTOR_INVALID_SENSOR, sensor ) } return result; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /*********************************************************************//** * @brief * The testBubbleDetectOverride function overrides the bubble detect state * for a given bubble detector. * @details \b Inputs: none * @details \b Outputs: currentBubbleState[] * @param message Override message from Dialin which includes an ID of * the sensor to override and the state to override the sensor to. * @return TRUE if override request is successful, FALSE if not *************************************************************************/ BOOL testBubbleDetectOverride( MESSAGE_T *message ) { BOOL result = u32ArrayOverride( message, ¤tBubbleState[0], NUM_OF_BUBBLE_DETECTORS - 1, 0, NUM_OF_BUBBLE_DETECTION_STATES - 1 ); return result; } /**@}*/