Index: firmware/App/Services/FPGA.c =================================================================== diff -u -rb7764e26a3460652da29b1f957706dfaca413226 -r796d5732ae78870d15ac5c86feee82229626034c --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision b7764e26a3460652da29b1f957706dfaca413226) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 796d5732ae78870d15ac5c86feee82229626034c) @@ -82,14 +82,18 @@ #define FPGA_AIRTRAP_LEVEL_HIGH_MASK 0x0004 ///< Bit mask for air trap upper level sensor. #define FPGA_FLUID_LEAK_STATE_MASK 0x0040 ///< Bit mask for fluid leak detector. + #define FPGA_BLOOD_LEAK_STATUS_MASK 0x1000 ///< Bit mask for blood leak detector. #define FPGA_BLOOD_LEAK_ZERO_STATE_MASK 0x2000 ///< Bit mask for blood leak detector zero. - #define FPGA_BLOOD_LEAK_ZERO_CMD 0x02 ///< Bit for blood leak detector zero command. #define FPGA_BLOOD_LEAK_SELF_TEST_CMD 0x01 ///< Bit for blood leak detector self test command. -#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_ADA_BUBBLE_STATUS_MASK 0x0001 ///< Bit mask for arterial air bubble detector input status. +#define FPGA_ADV_BUBBLE_STATUS_MASK 0x0002 ///< Bit mask for venous air bubble detector input status. +#define FPGA_ADA_BUBBLE_TEST_STATE_MASK 0x2000 ///< Bit mask for arterial air bubble detector self-test state. +#define FPGA_ADV_BUBBLE_TEST_STATE_MASK 0x4000 ///< Bit mask for venous air bubble detector self-test state. +#define FPGA_ADA_BUBBLE_SELF_TEST_CMD 0x01 ///< Bit for arterial air bubble detector self-test command. +#define FPGA_ADV_BUBBLE_SELF_TEST_CMD 0x02 ///< Bit for venous air bubble detector self-test command. // FPGA Sensors Record #pragma pack(push,1) @@ -1589,36 +1593,6 @@ /*********************************************************************//** * @brief - * The getFPGAArterialAirBubbleStatus function gets the latest arterial air - * bubble detector status. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return TRUE if air bubble is detected, otherwise FALSE - *************************************************************************/ -BOOL getFPGAArterialAirBubbleStatus( void ) -{ - U16 const status = fpgaSensorReadings.fpgaGPIO & FPGA_ADA_INPUT_STATUS_MASK; - - return ( 0 == status ? TRUE : FALSE ); -} - -/*********************************************************************//** - * @brief - * The getFPGAVenousAirBubbleStatus function gets the latest venous air - * bubble detector status. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return TRUE if air bubble is detected, otherwise FALSE - *************************************************************************/ -BOOL getFPGAVenousAirBubbleStatus( void ) -{ - U16 const status = fpgaSensorReadings.fpgaGPIO & FPGA_ADV_INPUT_STATUS_MASK; - - return ( 0 == status ? FALSE : TRUE ); -} - -/*********************************************************************//** - * @brief * The getDoorState function gets the current state of door switch. * @details Inputs: none * @details Outputs: none @@ -1756,6 +1730,102 @@ /*********************************************************************//** * @brief + * The noFPGABubbleDetected function returns TRUE if no air bubble has been + * detected and FALSE if an air bubble has been detected. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return noFPGABubbleDetected + *************************************************************************/ +BOOL noFPGABubbleDetected( BUBBLES_T bubble ) +{ + if ( bubble == ADA ) + { + U16 noFPGABubbleDetected = fpgaSensorReadings.fpgaGPIO & FPGA_ADA_BUBBLE_STATUS_MASK; + } + else if ( bubble == ADV ) + { + U16 noFPGABubbleDetected = fpgaSensorReadings.fpgaGPIO & FPGA_ADV_BUBBLE_STATUS_MASK; + } + else + { + // TODO: Should never reach here + } + + return ( 0 == noFPGABubbleDetected ? TRUE : FALSE ); +} + +/*********************************************************************//** + * @brief + * The FPGABubbleSelfTestDetected function returns TRUE if air bubble self-test + * has been detected and FALSE if no air bubble self-test has been detected. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGABubbleSelfTestDetected + *************************************************************************/ +BOOL FPGABubbleSelfTestDetected( BUBBLES_T bubble ) +{ + if ( bubble == ADA ) + { + U16 FPGABubbleSelfTestDetected = fpgaSensorReadings.fpgaGPIO & FPGA_ADA_BUBBLE_TEST_STATE_MASK; + } + else if ( bubble == ADV ) + { + U16 FPGABubbleSelfTestDetected = fpgaSensorReadings.fpgaGPIO & FPGA_ADV_BUBBLE_TEST_STATE_MASK; + } + else + { + // TODO: Should never reach here + } + + return ( 0 == FPGABubbleSelfTestDetected ? FALSE : TRUE ); +} + +/*********************************************************************//** + * @brief + * The setFPGABubbleSelfTest function sets the given air bubble detector into + * self-test mode via the FPGA. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGABubbleSelfTestDetected + *************************************************************************/ +void setFPGABubbleSelfTest( BUBBLES_T bubble ) +{ + if ( bubble == ADA ) + { + fpgaActuatorSetPoints.fpgaSensorTest |= FPGA_ADA_BUBBLE_SELF_TEST_CMD; + } + else if ( bubble == ADV ) + { + fpgaActuatorSetPoints.fpgaSensorTest |= FPGA_ADV_BUBBLE_SELF_TEST_CMD; + } +} + +/*********************************************************************//** + * @brief + * The clearFPGABubbleSelfTest function clears the given air bubble detector + * from self-test mode via the FPGA. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return none + *************************************************************************/ +void clearFPGABubbleSelfTest( BUBBLES_T bubble ) +{ + if ( bubble == ADA ) + { + fpgaActuatorSetPoints.fpgaSensorTest &= ~FPGA_ADA_BUBBLE_SELF_TEST_CMD; + } + else if ( bubble == ADV ) + { + fpgaActuatorSetPoints.fpgaSensorTest &= ~FPGA_ADV_BUBBLE_SELF_TEST_CMD; + } + else + { + // TODO: Should never reach here + } +} + +/*********************************************************************//** + * @brief * The setValveDialyzerInletPosition function sets the position of VDi * in counts * @details Inputs: fpgaActuatorSetPoints