Index: firmware/App/Monitors/Bubbles.c =================================================================== diff -u -re69d7ce1c9d88695e25e8ea94529dffdd8592434 -re24a98a344ba13ceb0663b415268a7e1dd5ce99e --- firmware/App/Monitors/Bubbles.c (.../Bubbles.c) (revision e69d7ce1c9d88695e25e8ea94529dffdd8592434) +++ firmware/App/Monitors/Bubbles.c (.../Bubbles.c) (revision e24a98a344ba13ceb0663b415268a7e1dd5ce99e) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* Copyright (c) 2024-2025 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 Bubbles.c * -* @author (last) Sean -* @date (last) 07-Aug-2024 +* @author (last) Sean Nash +* @date (last) 29-Aug-2025 * -* @author (original) Sean -* @date (original) 07-Aug-2024 +* @author (original) Sean Nash +* @date (original) 11-Sep-2024 * ***************************************************************************/ @@ -32,12 +32,14 @@ #define BUBBLE_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the air bubble detector data is published on the CAN bus. #define BUBBLE_TIMEOUT_MS 500 ///< Air bubble detector timeout for self-test (15 ms extended edge detection) +#define BUBBLE_SELF_TEST_RECOVERY_MS 100 ///< Timeout offset (in ms) for sensor to return to normal mode after self-test completed. #define DATA_PUBLISH_COUNTER_START_COUNT 70 ///< Data publish counter start count. /// Defined states for the air bubble detectors state machine. typedef enum BubbleStates { - BUBBLE_NORMAL_STATE = 0, ///< Normal state + BUBBLE_DISABLED_STATE = 0, ///< Disabled state + BUBBLE_ENABLED_STATE, ///< Enabled state BUBBLE_SELF_TEST_STATE, ///< Self-test state NUM_OF_BUBBLE_STATES ///< Number of bubble detector states } BUBBLE_STATES_T; @@ -51,12 +53,13 @@ static BOOL bubblesSelfTestRequested[ NUM_OF_BUBBLE_DETECTORS ]; ///< Air bubble detectors self-test requested flags. static BOOL bubbleDetectionEnabled[ NUM_OF_BUBBLE_DETECTORS ]; ///< Flag indicates whether air bubble alarm detection is enabled. -static OVERRIDE_U32_T bubblesDataPublishInterval = { BUBBLE_PUB_INTERVAL, BUBBLE_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish air bubble detectors data on CAN bus. +static OVERRIDE_U32_T bubblesDataPublishInterval; ///< Interval (in ms) at which to publish air bubble detectors data on CAN bus. static U32 bubblesDataPublicationTimerCounter; ///< Timer counter used to schedule air bubble detectors data publication to CAN bus. // ********** private function prototypes ********** -static BUBBLE_STATES_T handleBubbleNormalState( BUBBLE_DETECTOR_T bubble ); +static BUBBLE_STATES_T handleBubbleEnabledState( BUBBLE_DETECTOR_T bubble ); +static BUBBLE_STATES_T handleBubbleDisabledState( BUBBLE_DETECTOR_T bubble ); static BUBBLE_STATES_T handleBubbleSelfTestState( BUBBLE_DETECTOR_T bubble ); static void publishBubblesData( void ); @@ -78,13 +81,16 @@ // initialize unit data for ( bubble = (BUBBLE_DETECTOR_T)0; bubble < NUM_OF_BUBBLE_DETECTORS; bubble++ ) { - bubblesState[ bubble ] = BUBBLE_NORMAL_STATE; + bubblesState[ bubble ] = BUBBLE_DISABLED_STATE; bubblesSelfTestStatus[ bubble ] = SELF_TEST_STATUS_IN_PROGRESS; bubblesSelfTestRequested[ bubble ] = FALSE; bubblesSelfTestStartTime[ bubble ] = 0; - bubbleDetectionEnabled[ bubble ] = TRUE; + bubbleDetectionEnabled[ bubble ] = FALSE; } - + bubblesDataPublishInterval.data = BUBBLE_PUB_INTERVAL; + bubblesDataPublishInterval.ovData = BUBBLE_PUB_INTERVAL; + bubblesDataPublishInterval.ovInitData = 0; + bubblesDataPublishInterval.override = OVERRIDE_RESET; bubblesDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; } @@ -111,10 +117,14 @@ // Execute the air bubble detector state machine switch( bubblesState[ bubble ] ) { - case BUBBLE_NORMAL_STATE: - bubblesState[ bubble ] = handleBubbleNormalState( bubble ); + case BUBBLE_ENABLED_STATE: + bubblesState[ bubble ] = handleBubbleEnabledState( bubble ); break; + case BUBBLE_DISABLED_STATE: + bubblesState[ bubble ] = handleBubbleDisabledState( bubble ); + break; + case BUBBLE_SELF_TEST_STATE: bubblesState[ bubble ] = handleBubbleSelfTestState( bubble ); break; @@ -190,29 +200,28 @@ /*********************************************************************//** * @brief - * The handleBubbleNormalState function handles a given air bubble module - * in normal state. + * The handleBubbleEnabledState function handles a given air bubble module + * in enabled state. * @details \b Alarm: ALARM_ID_TD_VENOUS_BUBBLE_DETECTED if venous bubble detected. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given bubble sensor is invalid. * @details \b Inputs: none * @details \b Outputs: bubblesSelfTestStatus - * @param bubble ID of bubble detector to execute normal state for + * @param bubble ID of bubble detector to execute enabled state for * @return next state *************************************************************************/ -static BUBBLE_STATES_T handleBubbleNormalState( BUBBLE_DETECTOR_T bubble ) +static BUBBLE_STATES_T handleBubbleEnabledState( BUBBLE_DETECTOR_T bubble ) { - BUBBLE_STATES_T state = BUBBLE_NORMAL_STATE; + BUBBLE_STATES_T state = BUBBLE_ENABLED_STATE; if ( bubble < NUM_OF_BUBBLE_DETECTORS ) { // check for bubble detection #ifndef _RELEASE_ -// if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_BUBBLE_ALARMS ) != SW_CONFIG_ENABLE_VALUE ) +// if ( getSoftwareConfigStatus( SW_CONFIG_DISABLED_BUBBLE_ALARMS ) != SW_CONFIG_ENABLE_VALUE ) #endif { // Check for venous bubble alarm if enabled. - if ( ( BUBBLE_DETECTED == getBubbleDetectedState( bubble ) ) && - ( bubbleDetectionEnabled[ bubble ] != FALSE ) ) + if ( ( BUBBLE_DETECTED == getBubbleDetectedState( bubble ) )) { activateAlarmNoData( ALARM_ID_TD_VENOUS_BUBBLE_DETECTED ); } @@ -231,6 +240,11 @@ } bubblesSelfTestStartTime[ bubble ] = getMSTimerCount(); } + else if ( FALSE == bubbleDetectionEnabled[ bubble ] ) + { + state = BUBBLE_DISABLED_STATE; + + } } else { @@ -242,6 +256,47 @@ /*********************************************************************//** * @brief + * The handleBubbleDisabledState function handles a given air bubble module + * in disable state. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given bubble sensor is invalid. + * @details \b Inputs: none + * @details \b Outputs: bubblesSelfTestStatus + * @param bubble ID of bubble detector to execute disable state for + * @return next state + *************************************************************************/ +static BUBBLE_STATES_T handleBubbleDisabledState( BUBBLE_DETECTOR_T bubble ) +{ + BUBBLE_STATES_T state = BUBBLE_DISABLED_STATE; + + if ( bubble < NUM_OF_BUBBLE_DETECTORS ) + { + // if self-test requested, initiate self-test + if ( TRUE == bubblesSelfTestRequested[ bubble] ) + { + state = BUBBLE_SELF_TEST_STATE; + bubblesSelfTestRequested[ bubble ] = FALSE; + bubblesSelfTestStatus[ bubble ] = SELF_TEST_STATUS_IN_PROGRESS; + + if ( H18_BBLD == bubble ) + { + setFPGAVenousBubbleSelfTest(); + } + bubblesSelfTestStartTime[ bubble ] = getMSTimerCount(); + } + else if ( bubbleDetectionEnabled[ bubble ] != FALSE ) + { + state = BUBBLE_ENABLED_STATE; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_BUBBLES_INVALID_SENSOR_ID3, bubble ) + } + + return state; +} +/*********************************************************************//** + * @brief * The handleBubbleSelfTestState function handles a given air bubble detector * in self-test state. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given bubble sensor is invalid. @@ -276,9 +331,16 @@ { // Air bubble self-test finished, wait for self-test faked air bubble detector clear if ( ( NO_BUBBLE_DETECTED == getBubbleDetectedState( bubble ) ) || - ( TRUE == didTimeout( bubblesSelfTestStartTime[ bubble ], BUBBLE_TIMEOUT_MS + 100 ) ) ) + ( TRUE == didTimeout( bubblesSelfTestStartTime[ bubble ], BUBBLE_TIMEOUT_MS + BUBBLE_SELF_TEST_RECOVERY_MS ) ) ) { - state = BUBBLE_NORMAL_STATE; + if ( bubbleDetectionEnabled[ bubble ] != FALSE ) + { + state = BUBBLE_ENABLED_STATE; + } + else + { + state = BUBBLE_DISABLED_STATE; + } } } } @@ -305,8 +367,8 @@ { BUBBLES_DATA_T bubbleData; - bubbleData.statusH18 = (U32)getBubbleDetectedState( H18_BBLD ); - bubbleData.stateH18 = (U32)bubblesState[ H18_BBLD ]; + bubbleData.h18Status = (U32)getBubbleDetectedState( H18_BBLD ); + bubbleData.h18State = (U32)bubblesState[ H18_BBLD ]; broadcastData( MSG_ID_TD_BUBBLES_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&bubbleData, sizeof( BUBBLES_DATA_T ) ); bubblesDataPublicationTimerCounter = 0; }