Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r844f98879b7425c207b58562e623ab960adbc357 -r8bd1ae47aa13a843aa8abd6321ddc050deacb4a6 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 844f98879b7425c207b58562e623ab960adbc357) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 8bd1ae47aa13a843aa8abd6321ddc050deacb4a6) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* 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 FPGA.c +* @file FPGA.c * -* @author (last) Peman Montazemi -* @date (last) 15-Feb-2021 +* @author (last) Quang Nguyen +* @date (last) 30-Aug-2021 * -* @author (original) Dara Navaei -* @date (original) 05-Nov-2019 +* @author (original) Dara Navaei +* @date (original) 05-Nov-2019 * ***************************************************************************/ @@ -23,8 +23,10 @@ #include "Comm.h" #include "Compatible.h" #include "FPGA.h" +#include "OperationModes.h" #include "PersistentAlarm.h" #include "SystemCommMessages.h" +#include "Timers.h" #include "Utilities.h" /** @@ -110,6 +112,8 @@ #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. +#define PROCESSOR_FPGA_CLOCK_DIFF_TOLERANCE 1 ///< Tolerance for processor clock speed check against FPGA clock. + // FPGA Sensors Record #pragma pack(push,1) /// Record structure for FPGA header read. @@ -147,12 +151,12 @@ U16 bloodOcclusionData; ///< Reg 276. Blood pump occlusion sensor data. U08 bloodOcclusionReadCount; ///< Reg 278. Blood pump occlusion sensor read count. U08 bloodOcclusionErrorCount; ///< Reg 279. Blood pump occlusion sensor error count. - U16 dialysateInOcclusionData; ///< Reg 280. Dialysate inlet pump occlusion sensor data. - U08 dialysateInOcclusionReadCount; ///< Reg 282. Dialysate inlet pump occlusion sensor read count. - U08 dialysateInOcclusionErrorCount; ///< Reg 283. Dialysate inlet pump occlusion sensor error count. - U16 dialysateOutOcclusionData; ///< Reg 284. Dialysate outlet pump occlusion sensor data. - U08 dialysateOutOcclusionReadCount; ///< Reg 286. Dialysate outlet pump occlusion sensor read count. - U08 dialysateOutOcclusionErrorCount; ///< Reg 287. Dialysate outlet pump occlusion sensor error count. + U16 obsolete1; ///< Reg 280. Unused. + U08 obsolete2; ///< Reg 282. Unused. + U08 obsolete3; ///< Reg 283. Unused. + U16 obsolete4; ///< Reg 284. Unused. + U08 obsolete5; ///< Reg 286. Unused. + U08 obsolete6; ///< Reg 287. Unused. U16 bloodPumpHallSensorCount; ///< Reg 288. Blood pump hall sensor count. U08 bloodPumpHallSensorStatus; ///< Reg 290. Blood pump hall sensor status. U08 dialInPumpHallSensorStatus; ///< Reg 291. Dialysate inlet pump hall sensor status. @@ -299,6 +303,9 @@ static FPGA_SENSORS_ASYNC_T fpgaSensorReadingsAsync; ///< Record of last received async (as needed) FPGA sensor data. #endif +static U16 currentFPGATimerCount_ms; ///< Current FPGA timer count in ms. +static U32 currentTimerCount_ms; ///< Current processor timer count in ms. + // ********** private function prototypes ********** static FPGA_STATE_T handleFPGAReadHeaderState( void ); @@ -924,6 +931,33 @@ /*********************************************************************//** * @brief + * The execFPGAClockSpeedTest function verifies the processor clock speed + * against the FPGA clock. + * @details Inputs: fpgaHeader + * @details Outputs: none + * @return passed, or failed + *************************************************************************/ +void execFPGAClockSpeedTest( void ) +{ + U16 const newFPGATimerCount_ms = getFPGATimerCount(); + U32 const newTimerCount_ms = getMSTimerCount(); + U32 const diffFPGATimerCount = (U32)u16DiffWithWrap( currentFPGATimerCount_ms, newFPGATimerCount_ms ); + U32 const diffTimerCount = u32DiffWithWrap( currentTimerCount_ms, newTimerCount_ms ); + + if ( getCurrentOperationMode() > MODE_INIT ) + { + if ( abs( diffFPGATimerCount - diffTimerCount ) > PROCESSOR_FPGA_CLOCK_DIFF_TOLERANCE ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_FPGA_CLOCK_SPEED_CHECK_FAILURE, diffFPGATimerCount, diffTimerCount ); + } + } + + currentFPGATimerCount_ms = newFPGATimerCount_ms; + currentTimerCount_ms = newTimerCount_ms; +} + +/*********************************************************************//** + * @brief * The consumeUnexpectedData function checks to see if a byte is sitting in * the SCI2 received data register. * @details Inputs: fpgaHeader @@ -1246,82 +1280,6 @@ /*********************************************************************//** * @brief - * The getFPGABloodFlow function gets the latest blood flow reading. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return last blood flow reading - *************************************************************************/ -F32 getFPGABloodFlow( void ) -{ - return fpgaSensorReadings.bloodFlowLast; -} - -/*********************************************************************//** - * @brief - * The getFPGABloodFlowMeterStatus function gets the blood flow meter status. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return current blood flow meter status - *************************************************************************/ -U08 getFPGABloodFlowMeterStatus( void ) -{ - return fpgaSensorReadings.bloodFlowMeterDeviceStatus; -} - -/*********************************************************************//** - * @brief - * The getFPGABloodFlowFastPacketReadCounter function gets the blood - * flow meter fast packet read counter. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return current blood flow meter fast packet read counter - *************************************************************************/ -U08 getFPGABloodFlowFastPacketReadCounter( void ) -{ - return fpgaSensorReadings.bloodFlowMeterDataPktCount; -} - -/*********************************************************************//** - * @brief - * The getFPGABloodFlowSlowPacketReadCounter function gets the blood - * flow meter slow packet read counter. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return current blood flow meter slow packet read counter - *************************************************************************/ -U08 getFPGABloodFlowSlowPacketReadCounter( void ) -{ - return ( fpgaSensorReadings.bloodFlowMeterSlowPktCounts & MASK_OFF_NIBBLE_LSB ) >> SHIFT_BITS_BY_4; -} - -/*********************************************************************//** - * @brief - * The getFPGABloodFlowStatusPacketReadCounter function gets the blood - * flow meter status packet read counter. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return current blood flow meter status packet read counter - *************************************************************************/ -U08 getFPGABloodFlowStatusPacketReadCounter( void ) -{ - return ( fpgaSensorReadings.bloodFlowMeterSlowPktCounts & MASK_OFF_NIBBLE_MSB ); -} - -/*********************************************************************//** - * @brief - * The getFPGABloodFlowErrorCounter function gets the blood flow meter - * error counter. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return current blood flow meter error counter - *************************************************************************/ -U08 getFPGABloodFlowErrorCounter( void ) -{ - return fpgaSensorReadings.bloodFlowMeterErrorCount; -} - -/*********************************************************************//** - * @brief * The getFPGADialysateFlow function gets the latest dialysate flow reading. * @details Inputs: fpgaSensorReadings * @details Outputs: none @@ -1506,32 +1464,6 @@ /*********************************************************************//** * @brief - * The getFPGADialInPumpOcclusion function gets the latest dialysate - * inlet occlusion reading. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return last dialysate inlet occlusion reading - *************************************************************************/ -U16 getFPGADialInPumpOcclusion( void ) -{ - return fpgaSensorReadings.dialysateInOcclusionData; -} - -/*********************************************************************//** - * @brief - * The getFPGADialOutPumpOcclusion function gets the latest dialysate - * outlet occlusion reading. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return last dialysate outlet occlusion reading - *************************************************************************/ -U16 getFPGADialOutPumpOcclusion( void ) -{ - return fpgaSensorReadings.dialysateOutOcclusionData; -} - -/*********************************************************************//** - * @brief * The getFPGABloodPumpOcclusionReadCounter function gets the latest blood * pump occlusion read counter. * @details Inputs: fpgaSensorReadings @@ -1545,32 +1477,6 @@ /*********************************************************************//** * @brief - * The getFPGADialInPumpOcclusionReadCounter function gets the latest dialysate - * inlet pump occlusion read counter. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return last dialysate inlet pump occlusion read counter - *************************************************************************/ -U08 getFPGADialInPumpOcclusionReadCounter( void ) -{ - return fpgaSensorReadings.dialysateInOcclusionReadCount; -} - -/*********************************************************************//** - * @brief - * The getFPGADialOutPumpOcclusionReadCounter function gets the latest dialysate - * outlet pump occlusion read counter. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return last dialysate outlet pump occlusion read counter - *************************************************************************/ -U08 getFPGADialOutPumpOcclusionReadCounter( void ) -{ - return fpgaSensorReadings.dialysateOutOcclusionReadCount; -} - -/*********************************************************************//** - * @brief * The getFPGABloodPumpOcclusionErrorCounter function gets the latest blood * pump occlusion error counter. * @details Inputs: fpgaSensorReadings @@ -1584,32 +1490,6 @@ /*********************************************************************//** * @brief - * The getFPGADialInPumpOcclusionErrorCounter function gets the latest dialysate - * inlet pump occlusion error counter. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return last dialysate inlet pump occlusion error counter - *************************************************************************/ -U08 getFPGADialInPumpOcclusionErrorCounter( void ) -{ - return fpgaSensorReadings.dialysateInOcclusionErrorCount; -} - -/*********************************************************************//** - * @brief - * The getFPGADialOutPumpOcclusionErrorCounter function gets the latest dialysate - * outlet pump occlusion error counter. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return last dialysate outlet pump occlusion error counter - *************************************************************************/ -U08 getFPGADialOutPumpOcclusionErrorCounter( void ) -{ - return fpgaSensorReadings.dialysateOutOcclusionErrorCount; -} - -/*********************************************************************//** - * @brief * The getFPGAArterialPressure function gets the latest arterial pressure reading. * High byte indicates alarm status for ADC channel. * Low 24-bits are channel reading. Subtract 2^23 from low 24 bits to get