Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r29a2c3c7d7618489c0ada9f98e1d30226b455392 -r94dab74a6432263dc4569e0cf8f9fa0b01bf1917 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 29a2c3c7d7618489c0ada9f98e1d30226b455392) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 94dab74a6432263dc4569e0cf8f9fa0b01bf1917) @@ -7,8 +7,8 @@ * * @file FPGA.c * -* @author (last) Dara Navaei -* @date (last) 04-Jan-2022 +* @author (last) Michael Garthwaite +* @date (last) 08-Aug-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -80,8 +80,8 @@ #define MAX_COMM_ERROR_RETRIES 5 ///< Maximum consecutive FPGA communication error retries. -#define FPGA_INPUT_VOLTAGE_SCALE 3.0 ///< FPGA source and aux voltage. -#define FPGA_PVN_VOLTAGE_SCALE 1.0 ///< FPGA pvn voltage. +#define FPGA_INPUT_VOLTAGE_SCALE 3.0F ///< FPGA source and aux voltage. +#define FPGA_PVN_VOLTAGE_SCALE 1.0F ///< FPGA pvn voltage. #define FPGA_ADC1_AUTO_READ_ENABLE 0x01 ///< Auto-read enable bit for ADC1 control register. @@ -91,7 +91,9 @@ #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_ST_BIT_INDEX 12 ///< Bit index for the blood leak self test status bit. #define FPGA_BLOOD_LEAK_ZERO_STATE_MASK 0x2000 ///< Bit mask for blood leak detector zero. +#define FPAG_BLOOD_LEAK_ZERO_BIT_INDEX 13 ///< Bit index for the blood leak zero status bit. #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. @@ -100,14 +102,14 @@ #define FPGA_ADA_BUBBLE_SELF_TEST_CMD 0x04 ///< Bit for arterial air bubble detector self-test command. #define FPGA_ADV_BUBBLE_SELF_TEST_CMD 0x08 ///< Bit for venous air bubble detector self-test command. -#define FPGA_PBO_TEMP_DIVISOR 2047.0 ///< Used in conversion of PBo temperature reading to deg C. -#define FPGA_PBO_TEMP_GAIN 200.0 ///< Used in conversion of PBo temperature reading to deg C. -#define FPGA_PBO_TEMP_OFFSET 50.0 ///< Used in conversion of PBo temperature reading to deg C. +#define FPGA_PBO_TEMP_DIVISOR 2047.0F ///< Used in conversion of PBo temperature reading to deg C. +#define FPGA_PBO_TEMP_GAIN 200.0F ///< Used in conversion of PBo temperature reading to deg C. +#define FPGA_PBO_TEMP_OFFSET 50.0F ///< Used in conversion of PBo temperature reading to deg C. #define FPGA_ALARM_AUDIO_VOLUME_SHIFT 3 ///< Shift alarm audio volume 3 bits to left before writing to register. #define FPGA_ALARM_AUDIO_DIVIDE_SHIFT 6 ///< Shift alarm audio volume divider 6 bits to left before writing to register. -#define FPGA_BACKUP_ALARM_AUDIO_CONVERT 0.4 ///< Converts backup (piezo) alarm audio ADC volts to amps. +#define FPGA_BACKUP_ALARM_AUDIO_CONVERT 0.4F ///< Converts backup (piezo) alarm audio ADC volts to amps. #define FRONT_DOOR_SWITCH_MASK 0x0010 ///< Front door switch bit mask. Bit 4 of the GPIO register. #define PUMP_TRACK_SWITCH_MASK 0x0020 ///< Pump track switch bit mask. Bit 5 of the GPIO register. @@ -229,15 +231,24 @@ U08 BLeakCounter; ///< Reg 427. Blood leak counter. U08 PBoErrorCount; ///< Reg 428. PBo error count. U08 bloodLeakZeroedStatus; ///< Reg 429. Blood leak and sensor zeored status. - U16 bloodDetectSetPoint; ///< Reg 430. Blood leak stored set point value. - U16 bloodDetectLevel; ///< Reg 432. Blood leak detection stored level value. - U16 bloodStCount; ///< Reg 434. Blood leak St Count. - U16 bloodLEDIntensity; ///< Reg 436. Blood leak LED intensity. - U16 bloodRdCounter; ///< Reg 438. Blood leak register counter. + U16 bloodLeakDetectSetPoint; ///< Reg 430. Blood leak stored set point value. + U16 bloodLeakDetectLevel; ///< Reg 432. Blood leak detection stored level value. + U16 bloodLeakStCount; ///< Reg 434. Blood leak St Count. + U16 bloodLeakLEDIntensity; ///< Reg 436. Blood leak LED intensity. + U16 bloodLeakRdCounter; ///< Reg 438. Blood leak register counter. U16 arterialPressure; ///< Reg 440. Arterial pressure sensor. U16 arterialPressureTemperature; ///< Reg 442. Arterial pressure sensor temperature. U08 arterialPressureReadCount; ///< Reg 444. Arterial pressure sensor read count. U08 arterialPressureErrorCount; ///< Reg 445. Arterial pressure sensor error count. + U08 bloodLeakTxFIFOCount; ///< Reg 446. Blood leak transmit FIFO count. + U08 bloodLeakRxErrorCount; ///< Reg 447. Blood leak receive error count. + U16 bloodLeakRxFIFOCount; ///< Reg 448. Blood leak receive FIFO count. + U08 bloodLeakRxFIFODataOut; ///< Reg 450. Blood leak receive FIFO data out. + U08 dummyByte; ///< Reg 451. Dummy byte to meet the even of the data. + U16 fpgaCompatibilityRev; ///< Reg 452. Compatibility revisions + U08 bloodLeakSelfTestErrorCounter; ///< Reg 452. Blood leak self test error counter. + U08 bloodLeakZeroErrorCounter; ///< Reg 453. Blood leak zero error counter. + } FPGA_SENSORS_T; /// Record structure for FPGA continuous priority writes. @@ -922,25 +933,18 @@ { SELF_TEST_STATUS_T result; - // Check FPGA reported correct ID + // check FPGA reported correct ID if ( FPGA_EXPECTED_ID == fpgaHeader.fpgaId ) { // Check FPGA compatibility w/ firmware - if ( fpgaHeader.fpgaRevMajor > MIN_HD_FPGA_MAJOR ) + if ( HD_FPGA_COMPATIBILITY_REV == fpgaSensorReadings.fpgaCompatibilityRev ) { result = SELF_TEST_STATUS_PASSED; } else { - if ( ( MIN_HD_FPGA_MAJOR == fpgaHeader.fpgaRevMajor ) && ( fpgaHeader.fpgaRev >= MIN_HD_FPGA_MINOR ) ) - { - result = SELF_TEST_STATUS_PASSED; - } - else - { - result = SELF_TEST_STATUS_FAILED; - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_FPGA_POST_TEST_FAILED, (U32)fpgaHeader.fpgaRevMajor, (U32)fpgaHeader.fpgaRev ) - } + result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_FPGA_POST_TEST_FAILED, (U32)HD_FPGA_COMPATIBILITY_REV, (U32)fpgaSensorReadings.fpgaCompatibilityRev ) } } else @@ -1925,21 +1929,6 @@ /*********************************************************************//** * @brief - * The getDoorState function gets the current state of door switch. - * @details Inputs: none - * @details Outputs: none - * @return current door state - *************************************************************************/ -OPN_CLS_STATE_T getFPGADoorState( void ) -{ - // TODO: Get actual door state from FPGA or GPIO - BOOL const status = 0x0; - - return ( 0 == status ? STATE_CLOSED : STATE_OPEN ); -} - -/*********************************************************************//** - * @brief * The setFPGAValvesControlMode function sets the valves control mode. * @details Inputs: fpgaActuatorSetPoints * @details Outputs: fpgaActuatorSetPoints @@ -1995,21 +1984,6 @@ /*********************************************************************//** * @brief - * The FPGABloodLeakZeroDetected function returns TRUE if blood leak zeroing has - * been detected and FALSE if no blood leak zeroing has been detected. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return FPGABloodLeakZeroDetected - *************************************************************************/ -BOOL FPGABloodLeakZeroDetected( void ) -{ - U16 FPGABloodLeakZeroDetected = fpgaSensorReadings.fpgaGPIO & FPGA_BLOOD_LEAK_ZERO_STATE_MASK; - - return ( 0 == FPGABloodLeakZeroDetected ? FALSE : TRUE ); -} - -/*********************************************************************//** - * @brief * The setFPGABloodLeakZero function sets the Blood Leak detector into * zeroing mode via the FPGA. * @details Inputs: none @@ -2062,6 +2036,34 @@ /*********************************************************************//** * @brief + * The getFPGABloodLeakZeroStatus function returns the blood leak sensor's + * zero status bit. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return blood leak sensor zero status bit + *************************************************************************/ +U08 getFPGABloodLeakZeroStatus( void ) +{ + U08 zeroStatus = (U08)( ( fpgaSensorReadings.fpgaGPIO & FPGA_BLOOD_LEAK_ZERO_STATE_MASK ) >> FPAG_BLOOD_LEAK_ZERO_BIT_INDEX ); + return zeroStatus; +} + +/*********************************************************************//** + * @brief + * The getFPGABloodLeakStatus function returns the blood leak sensor's + * blood detection status bit. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return blood leak sensor self test status bit + *************************************************************************/ +U08 getFPGABloodLeakStatus( void ) +{ + U08 selfTestStatus = (U08)( ( fpgaSensorReadings.fpgaGPIO & FPGA_BLOOD_LEAK_STATUS_MASK ) >> FPGA_BLOOD_LEAK_ST_BIT_INDEX ); + return selfTestStatus; +} + +/*********************************************************************//** + * @brief * The setFPGABloodLeakUARTControl function sets the blood leak sensor UART * control value. * @details Inputs: fpgaSensorReadings @@ -2133,7 +2135,7 @@ *************************************************************************/ U16 getFPGABloodLeakDetectSetPoint( void ) { - return fpgaSensorReadings.bloodDetectSetPoint; + return fpgaSensorReadings.bloodLeakDetectSetPoint; } /*********************************************************************//** @@ -2145,7 +2147,7 @@ *************************************************************************/ U16 getFPGABloodLeakDetectLevel( void ) { - return fpgaSensorReadings.bloodDetectLevel; + return fpgaSensorReadings.bloodLeakDetectLevel; } /*********************************************************************//** @@ -2157,7 +2159,7 @@ *************************************************************************/ U16 getFPGABloodLeakStCount( void ) { - return fpgaSensorReadings.bloodStCount; + return fpgaSensorReadings.bloodLeakStCount; } /*********************************************************************//** @@ -2169,7 +2171,7 @@ *************************************************************************/ U16 getFPGABloodLeakLEDIntensity( void ) { - return fpgaSensorReadings.bloodLEDIntensity; + return fpgaSensorReadings.bloodLeakLEDIntensity; } /*********************************************************************//** @@ -2182,11 +2184,89 @@ *************************************************************************/ U16 getFPGABloodLeakRegisterCounter( void ) { - return fpgaSensorReadings.bloodRdCounter; + return fpgaSensorReadings.bloodLeakRdCounter; } /*********************************************************************//** * @brief + * The getFPGABloodLeakTxFIFOCount function returns the blood leak transmit + * FIFO count. + * @details Inputs: none + * @details Outputs: none + * @return fpgaSensorReadings.bloodLeakTxFIFOCount + *************************************************************************/ +U08 getFPGABloodLeakTxFIFOCount( void ) +{ + return fpgaSensorReadings.bloodLeakTxFIFOCount; +} + +/*********************************************************************//** + * @brief + * The getFPGABloodLeakRxFIFOCount function returns the blood leak receive + * FIFO count. + * @details Inputs: none + * @details Outputs: none + * @return fpgaSensorReadings.bloodLeakRxFIFOCount + *************************************************************************/ +U16 getFPGABloodLeakRxFIFOCount( void ) +{ + return fpgaSensorReadings.bloodLeakRxFIFOCount; +} + +/*********************************************************************//** + * @brief + * The getFPGABloodLeakRxErrorCount function returns the blood leak receive + * error count. + * @details Inputs: none + * @details Outputs: none + * @return fpgaSensorReadings.bloodLeakRxErrorCount + *************************************************************************/ +U08 getFPGABloodLeakRxErrorCount( void ) +{ + return fpgaSensorReadings.bloodLeakRxErrorCount; +} + +/*********************************************************************//** + * @brief + * The getFPGABloodLeakRxFIFODataOut function returns the blood leak receive + * FIFO data out. + * @details Inputs: none + * @details Outputs: none + * @return fpgaSensorReadings.bloodLeakRxFIFODataOut + *************************************************************************/ +U08 getFPGABloodLeakRxFIFODataOut( void ) +{ + return fpgaSensorReadings.bloodLeakRxFIFODataOut; +} + +/*********************************************************************//** + * @brief + * The getFPGABloodLeakSelfTestErrorCounter function returns the blood leak + * self test error counter. + * @details Inputs: none + * @details Outputs: none + * @return fpgaSensorReadings.bloodLeakSelfTestErrorCounter + *************************************************************************/ +U08 getFPGABloodLeakSelfTestErrorCounter( void ) +{ + return fpgaSensorReadings.bloodLeakSelfTestErrorCounter; +} + +/*********************************************************************//** + * @brief + * The getFPGABloodLeakZeroErrorCounter function returns the blood leak + * zero error counter. + * @details Inputs: none + * @details Outputs: none + * @return fpgaSensorReadings.bloodLeakZeroErrorCounter + *************************************************************************/ +U08 getFPGABloodLeakZeroErrorCounter( void ) +{ + return fpgaSensorReadings.bloodLeakZeroErrorCounter; +} + +/*********************************************************************//** + * @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