/************************************************************************** * * 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: msTimerCount * @details \b Outputs: alarmStartedAt[] * @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 = FALSE; TEST_OVERRIDE_ARRAY_PAYLOAD_T override; OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &override ); // Verify tester has logged in with TD and override type is valid if ( ( TRUE == isTestingActivated() ) && ( ovType != OVERRIDE_INVALID ) && ( ovType < NUM_OF_OVERRIDE_TYPES ) ) { U32 sensor = override.index; // Verify bubble detector index of override if ( sensor < NUM_OF_BUBBLE_DETECTORS ) { if ( OVERRIDE_OVERRIDE == ovType ) { U32 value = override.state.u32; if ( value < NUM_OF_BUBBLE_DETECTION_STATES ) { result = TRUE; currentBubbleState[ sensor ].ovData = value; currentBubbleState[ sensor ].override = OVERRIDE_KEY; } } else { result = TRUE; currentBubbleState[ sensor ].override = OVERRIDE_RESET; currentBubbleState[ sensor ].ovData = currentBubbleState[ sensor ].ovInitData; } } } return result; } /**@}*/