Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u --- firmware/App/Controllers/BloodLeak.c (revision 0) +++ firmware/App/Controllers/BloodLeak.c (revision 70b000b9a49b56f1e5d41aebddf4ed97a01faa0b) @@ -0,0 +1,261 @@ +/************************************************************************** +* +* Copyright (c) 2019-2021 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 BloodLeak.c +* +* @author (last) Peman Montazemi +* @date (last) 18-Mar-2021 +* +* @author (original) Peman Montazemi +* @date (original) 18-Mar-2021 +* +***************************************************************************/ + +#include "AlarmMgmt.h" +#include "BloodLeak.h" +#include "FPGA.h" +#include "OperationModes.h" +#include "SystemCommMessages.h" +#include "TaskPriority.h" +#include "Timers.h" + +/** + * @addtogroup BloodLeak + * @{ + */ + +// ********** private definitions ********** + +#define BLOOD_LEAK_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the blood leak data is published on the CAN bus. + +// ********** private data ********** + +static U32 bloodLeakStatePublicationTimerCounter = 0; ///< Timer counter used to schedule blood leak publication to CAN bus. + +/// Interval (in ms) at which to publish blood leak data to CAN bus. +static OVERRIDE_U32_T bloodLeakStatePublishInterval = { BLOOD_LEAK_PUB_INTERVAL, BLOOD_LEAK_PUB_INTERVAL, 0, 0 }; +static OVERRIDE_U32_T bloodLeakState; ///< Detected blood leak state for blood leak detector. + +// ********** private function prototypes ********** + +static void publishBloodLeakState( void ); +static U32 getPublishBloodLeakStateInterval( void ); + +/*********************************************************************//** + * @brief + * The initBloodLeak function initializes the Blood Leak module. + * @details Inputs: none + * @details Outputs: Blood Leak module initialized. + * @return none + *************************************************************************/ +void initBloodLeak( void ) +{ + bloodLeakState.data = BLOOD_LEAK_NOT_DETECTED; +} + +/*********************************************************************//** + * @brief + * The execBloodLeak function executes the blood leak monitor. + * @details Inputs: FPGA blood leak state GPIO pin state + * @details Outputs: bloodLeakState + * @return none + *************************************************************************/ +void execBloodLeak( void ) +{ + BOOL noBloodLeakDetected = noFPGABloodLeakDetected(); + + if ( getCurrentOperationMode() != MODE_INIT ) + { + // Get latest state reading + if ( TRUE == noBloodLeakDetected ) + { + bloodLeakState.data = BLOOD_LEAK_NOT_DETECTED; + } + else + { + bloodLeakState.data = BLOOD_LEAK_DETECTED; + } + + // Check state reading and act upon + if ( BLOOD_LEAK_DETECTED == getBloodLeakState() ) + { + activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_DETECTED ); + } + else // BLOOD_LEAK_NOT_DETECTED == getBloodLeakState() + { + clearAlarmCondition( ALARM_ID_HD_BLOOD_LEAK_DETECTED ); + } + } + + // Publish blood leak state if due + publishBloodLeakState(); +} + +/*********************************************************************//** + * @brief + * The getBloodLeakState function gets the current reading for the blood + * leak detector. + * @details Inputs: bloodLeakState + * @details Outputs: none + * @param none + * @return the current blood leak state. + *************************************************************************/ +BLOOD_LEAK_STATES_T getBloodLeakState( void ) +{ + BLOOD_LEAK_STATES_T result = (BLOOD_LEAK_STATES_T)bloodLeakState.data; + + if ( OVERRIDE_KEY == bloodLeakState.override ) + { + result = (BLOOD_LEAK_STATES_T)bloodLeakState.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getPublishBloodLeakStateInterval function gets the blood leak state + * publication interval. + * @details Inputs: bloodLeakStatePublishInterval + * @details Outputs: none + * @return the current blood leak state publication interval (in task intervals). + *************************************************************************/ +static U32 getPublishBloodLeakStateInterval( void ) +{ + U32 result = bloodLeakStatePublishInterval.data; + + if ( OVERRIDE_KEY == bloodLeakStatePublishInterval.override ) + { + result = bloodLeakStatePublishInterval.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The publishBloodLeakState function publishes blood leak state at the set interval. + * @details Inputs: bloodLeakState + * @details Outputs: if broadcast is due, send blood leak state + * @return none + *************************************************************************/ +static void publishBloodLeakState( void ) +{ + // Publish blood leak state on interval + if ( ++bloodLeakStatePublicationTimerCounter >= getPublishBloodLeakStateInterval() ) + { + BLOOD_LEAK_STATES_T state = getBloodLeakState(); + + broadcastBloodLeakState( state ); + bloodLeakStatePublicationTimerCounter = 0; + } +} + + +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + +/*********************************************************************//** + * @brief + * The testSetBloodLeakStatePublishIntervalOverride function overrides the + * blood leak state publish interval. + * @details Inputs: none + * @details Outputs: bloodLeakStatePublishInterval + * @param value override blood leak state publish interval with (in ms) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetBloodLeakStatePublishIntervalOverride( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + U32 intvl = value / TASK_PRIORITY_INTERVAL; + + result = TRUE; + bloodLeakStatePublishInterval.ovData = intvl; + bloodLeakStatePublishInterval.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetBloodLeakStatePublishIntervalOverride function resets the override + * of the blood leak state publish interval. + * @details Inputs: none + * @details Outputs: bloodLeakStatePublishInterval + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetBloodLeakStatePublishIntervalOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + bloodLeakStatePublishInterval.override = OVERRIDE_RESET; + bloodLeakStatePublishInterval.ovData = bloodLeakStatePublishInterval.ovInitData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testSetBloodLeakStateOverride function overrides the state + * of the blood leak detector. + * @details Inputs: none + * @details Outputs: bloodLeakState + * @param none + * @param state override blood leak detector with this + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetBloodLeakStateOverride( BLOOD_LEAK_STATES_T state ) +{ + BOOL result = FALSE; + + if ( ( state < NUM_OF_BLOOD_LEAK_STATES ) ) + { + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + bloodLeakState.ovData = (U32)state; + bloodLeakState.override = OVERRIDE_KEY; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetBloodLeakStateOverride function resets the override of the + * blood leak detector. + * @details Inputs: none + * @details Outputs: bloodLeakState + * @param none + * @return TRUE if reset successful, FALSE if not + *************************************************************************/ +BOOL testResetBloodLeakStateOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + bloodLeakState.override = OVERRIDE_RESET; + bloodLeakState.ovData = bloodLeakState.ovInitData; + } + + return result; +} + +/**@}*/ Index: firmware/App/Controllers/BloodLeak.h =================================================================== diff -u --- firmware/App/Controllers/BloodLeak.h (revision 0) +++ firmware/App/Controllers/BloodLeak.h (revision 70b000b9a49b56f1e5d41aebddf4ed97a01faa0b) @@ -0,0 +1,58 @@ +/************************************************************************** +* +* Copyright (c) 2019-2021 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 BloodLeak.h +* +* @author (last) Peman Montazemi +* @date (last) 18-Mar-2021 +* +* @author (original) Peman Montazemi +* @date (original) 18-Mar-2021 +* +***************************************************************************/ + +#ifndef __BLOOD_LEAK_H__ +#define __BLOOD_LEAK_H__ + +#include "HDCommon.h" + +/** + * @defgroup BloodLeak BloodLeak + * @brief Blood Leak detector monitor module. Monitors the + * blood leak detector. + * + * INTROTEK - Blood Component Detector Part No. 105-0002 + * + * @addtogroup BloodLeak + * @{ + */ + +// ********** public definitions ********** + +/// Enumeration of blood leak detector states. +typedef enum BloodLeakDetectorStates +{ + BLOOD_LEAK_DETECTED = 0, ///< Blood leak detector senses blood + BLOOD_LEAK_NOT_DETECTED, ///< Blood leak detector does not sense any blood + NUM_OF_BLOOD_LEAK_STATES ///< Number of blood leak detector states +} BLOOD_LEAK_STATES_T; + +// ********** public function prototypes ********** + +void initBloodLeak( void ); +void execBloodLeak( void ); + +BLOOD_LEAK_STATES_T getBloodLeakState( void ); + +BOOL testSetBloodLeakStatePublishIntervalOverride( U32 value ); +BOOL testResetBloodLeakStatePublishIntervalOverride( void ); +BOOL testSetBloodLeakStateOverride( BLOOD_LEAK_STATES_T state ); +BOOL testResetBloodLeakStateOverride( void ); + +/**@}*/ + +#endif Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r2cc4f0cfc6512c942864d7d302cef5df375a2081 -r70b000b9a49b56f1e5d41aebddf4ed97a01faa0b --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 2cc4f0cfc6512c942864d7d302cef5df375a2081) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 70b000b9a49b56f1e5d41aebddf4ed97a01faa0b) @@ -82,6 +82,7 @@ #define FPGA_AIRTRAP_LEVEL_HIGH_MASK 0x0004 ///< Bit mask for air trap upper level sensor. #define FPGA_FLUIDLEAK_STATE_MASK 0x0040 ///< Bit mask for fluid leak detector. +#define FPGA_BLOODLEAK_STATE_MASK 0x0040 ///< Bit mask for blood leak detector. #define FPGA_ADA_INPUT_STATUS_MASK 0x0001 ///< Bit mask for arterial air bubble detector input status. #define FPGA_ADV_INPUT_STATUS_MASK 0x0002 ///< Bit mask for venous air bubble detector input status. #define FPGA_BLOOD_LEAK_STATUS_MASK 0x1000 ///< Bit mask for blood leak detector status. @@ -1517,6 +1518,21 @@ /*********************************************************************//** * @brief + * The noBloodLeakDetected function returns TRUE if no blood leak has been + * detected (dry) and FALSE if a blood leak has been detected. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return noBloodLeakDetected + *************************************************************************/ +BOOL noFPGABloodLeakDetected( void ) +{ + U16 noBloodLeakDetected = fpgaSensorReadings.fpgaGPIO & FPGA_BLOODLEAK_STATE_MASK; + + return ( 0 == noBloodLeakDetected ? FALSE : TRUE ); +} + +/*********************************************************************//** + * @brief * The setValveDialyzerInletPosition function sets the position of VDi * in counts * @details Inputs: fpgaActuatorSetPoints Index: firmware/App/Services/FPGA.h =================================================================== diff -u -r2cc4f0cfc6512c942864d7d302cef5df375a2081 -r70b000b9a49b56f1e5d41aebddf4ed97a01faa0b --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision 2cc4f0cfc6512c942864d7d302cef5df375a2081) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision 70b000b9a49b56f1e5d41aebddf4ed97a01faa0b) @@ -86,6 +86,7 @@ U16 getFPGAValvesStatus( void ); BOOL noFPGAFluidLeakDetected( void ); +BOOL noFPGABloodLeakDetected( void ); void setFPGAValveDialyzerInletPosition( S16 setPoint ); S16 getFPGAValveDialyzerInletPosition( void ); Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r2cc4f0cfc6512c942864d7d302cef5df375a2081 -r70b000b9a49b56f1e5d41aebddf4ed97a01faa0b --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 2cc4f0cfc6512c942864d7d302cef5df375a2081) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 70b000b9a49b56f1e5d41aebddf4ed97a01faa0b) @@ -7,8 +7,8 @@ * * @file SystemCommMessages.c * -* @author (last) Sean Nash -* @date (last) 14-Oct-2020 +* @author (last) Peman Montazemi +* @date (last) 18-Mar-2021 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -20,9 +20,9 @@ #include "reg_system.h" #include "Accel.h" -#include "AlarmLamp.h" +#include "AlarmLamp.h" #include "Buttons.h" -#include "DGInterface.h" +#include "DGInterface.h" #include "FPGA.h" #include "ModePreTreat.h" #include "ModeStandby.h" @@ -1434,6 +1434,35 @@ /***********************************************************************//** * @brief + * The broadcastBloodLeakState function constructs an HD blood leak state msg to \n + * be broadcasted and queues the msg for transmit on the appropriate CAN channel. + * @details Inputs: none + * @details Outputs: blood leak state msg constructed and queued + * @param state blood leak state + * @return TRUE if msg successfully queued for transmit, FALSE if not + *************************************************************************/ +BOOL broadcastBloodLeakState( BLOOD_LEAK_STATES_T state ) +{ + BOOL result; + MESSAGE_T msg; + U08 *payloadPtr = msg.payload; + U32 leakState = (U32)state; + + // Create a message record + blankMessage( &msg ); + msg.hdr.msgID = MSG_ID_HD_BLOOD_LEAK_STATE; + msg.hdr.payloadLen = sizeof( U32 ); + + memcpy( payloadPtr, &leakState, sizeof( U32 ) ); + + // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer + result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_BROADCAST, ACK_NOT_REQUIRED ); + + return result; +} + +/***********************************************************************//** + * @brief * The broadcastPrimeData function constructs a prime data msg to \n * be broadcast and queues the msg for transmit on the appropriate CAN channel. * @details Inputs: none @@ -4231,6 +4260,70 @@ /*********************************************************************//** * @brief + * The handleSetBloodLeakBroadcastIntervalOverrideRequest function handles a + * request to override the blood leak state broadcast interval. + * @details Inputs: none + * @details Outputs: message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetBloodLeakBroadcastIntervalOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_PAYLOAD_T payload; + BOOL result = FALSE; + + // Verify payload length + if ( sizeof( TEST_OVERRIDE_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetBloodLeakStatePublishIntervalOverride( (U32)( payload.state.u32 ) ); + } + else + { + result = testResetBloodLeakStatePublishIntervalOverride(); + } + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief + * The handleSetBloodLeakStateDetectorOverrideRequest function handles a request to + * override the blood leak detector state. + * @details Inputs: none + * @details Outputs: message handled + * @param message : a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetBloodLeakStateDetectorOverrideRequest( MESSAGE_T *message ) +{ + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + BOOL result = FALSE; + + // Verify payload length + if ( sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) ); + if ( FALSE == payload.reset ) + { + result = testSetBloodLeakStateOverride( ( BLOOD_LEAK_STATES_T)( payload.state.u32 ) ); + } + else + { + result = testResetBloodLeakStateOverride(); + } + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief * The handleHDSoftwareResetRequest function handles a request to reset the * HD firmware processor. * @details Inputs: none Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r2cc4f0cfc6512c942864d7d302cef5df375a2081 -r70b000b9a49b56f1e5d41aebddf4ed97a01faa0b --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 2cc4f0cfc6512c942864d7d302cef5df375a2081) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 70b000b9a49b56f1e5d41aebddf4ed97a01faa0b) @@ -21,6 +21,7 @@ #include "HDCommon.h" #include "AirTrap.h" #include "BloodFlow.h" +#include "BloodLeak.h" #include "BloodPrime.h" #include "DGInterface.h" #include "DialInFlow.h" @@ -280,6 +281,9 @@ // MSG_ID_HD_FLUID_LEAK_STATE BOOL broadcastFluidLeakState( FLUID_LEAK_STATES_T state ); +// MSG_ID_HD_BLOOD_LEAK_STATE +BOOL broadcastBloodLeakState( BLOOD_LEAK_STATES_T state ); + // MSG_ID_HD_PRIMING_STATUS_DATA BOOL broadcastPrimeData( PRIMING_DATA_PAYLOAD_T *primeDataPtr ); Index: firmware/source/sys_main.c =================================================================== diff -u -ree4aba56d1581f160a48fe51326b93c50bdd892d -r70b000b9a49b56f1e5d41aebddf4ed97a01faa0b --- firmware/source/sys_main.c (.../sys_main.c) (revision ee4aba56d1581f160a48fe51326b93c50bdd892d) +++ firmware/source/sys_main.c (.../sys_main.c) (revision 70b000b9a49b56f1e5d41aebddf4ed97a01faa0b) @@ -66,6 +66,7 @@ #include "AirTrap.h" #include "AlarmLamp.h" #include "BloodFlow.h" +#include "BloodLeak.h" #include "Buttons.h" #include "CommBuffers.h" #include "CPLD.h" @@ -191,6 +192,7 @@ initDialOutFlow(); initValves(); initFluidLeak(); + initBloodLeak(); // Initialize modes initOperationModes(); // Initialize async interrupt handlers