Index: firmware/App/Services/FPGA.c =================================================================== diff -u -rcd3f58205f4dab89291b29ee73b7fa9c31773abc -r08d27319b4b5f6f15e5de0758d9f528db1db6b3a --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision cd3f58205f4dab89291b29ee73b7fa9c31773abc) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 08d27319b4b5f6f15e5de0758d9f528db1db6b3a) @@ -8,8 +8,8 @@ * * @file FPGA.c * -* @author (last) Dara Navaei -* @date (last) 04-Aug-2022 +* @author (last) Dong Nguyen +* @date (last) 27-Sep-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -29,6 +29,7 @@ #include "OperationModes.h" #include "PersistentAlarm.h" #include "SystemCommMessages.h" +#include "Timers.h" #include "Utilities.h" /** @@ -94,9 +95,12 @@ #define FPGA_GPIO_POWER_STATUS_PIN 7 ///< FPGA GPIO power status pin. #define FPGA_READ_V3_START_BYTE_NUM 256 ///< FPGA V3 read sensors start byte number. #define FPGA_READ_V3_END_BYTE_NUM 430 ///< FPGA V3 read sensors end byte number. + /// FPGA size of V3 read bytes. #define FPGA_SIZE_OF_V3_READ_BYTES ( FPGA_READ_V3_END_BYTE_NUM - FPGA_READ_V3_START_BYTE_NUM ) +#define PROCESSOR_FPGA_CLOCK_DIFF_TOLERANCE 1 ///< Tolerance for processor clock speed check against FPGA clock. + // FPGA header struct. #pragma pack(push,1) typedef struct @@ -163,10 +167,10 @@ U08 fpgaTRoErrorCnt; ///< Reg 361. Redundant outlet temperature sensor error count U08 fpgaTDiReadCnt; ///< Reg 362. Dialysate inlet temperature sensor read count U08 fpgaTDiErrorCnt; ///< Reg 363. Dialysate inlet temperature sensor error count - U08 fpgaPrimaryHeaterFlags; ///< Reg 364. Primary heater flags - U08 fpgaPrimaryHeaterReadCnt; ///< Reg 365. Primary heater read count - U08 fpgaTrimmerHeaterFlags; ///< Reg 366. Trimmer heater flags - U08 fpgaTrimmerHeaterReadCnt; ///< Reg 367. Trimmer heater read count + U08 fpgaPrimaryHeaterFlags; ///< Reg 364. Primary heater flags (thermo-couple) + U08 fpgaPrimaryHeaterReadCnt; ///< Reg 365. Primary heater read count (thermo-couple) + U08 fpgaTrimmerHeaterFlags; ///< Reg 366. Trimmer heater flags (thermo-couple) + U08 fpgaTrimmerHeaterReadCnt; ///< Reg 367. Trimmer heater read count (thermo-couple) U08 fpgaCPoFault; ///< Reg 368. CPo conductivity sensor fault U08 fpgaCPoReadCnt; ///< Reg 369. CPo conductivity sensor read count @@ -239,6 +243,7 @@ U08 fpgaHeater1ADCErrorCount; ///< Reg 481. Heater 1 ADC error count U16 fpgaPowerSupply2; ///< Reg 482. Power supply 2 count U16 fpgaOnBoardThermistor; ///< Reg 484. Onboard thermistor + U08 fpgaDrainPumpDirection; ///< Reg 486. Drain pump direction } DG_FPGA_SENSORS_T; typedef struct @@ -343,6 +348,10 @@ static DG_FPGA_SENSORS_T fpgaSensorReadings; ///< DG FPGA sensors structure. static FPGA_ACTUATORS_T fpgaActuatorSetPoints; ///< FPGA actuator set points structure. static U08 fpgaReadByteSize; ///< FPGA read byte size. +#ifndef DEBUG_ENABLED +static U16 currentFPGATimerCount_ms; ///< Current FPGA timer count in ms. +static U32 currentTimerCount_ms; ///< Current processor timer count in ms. +#endif // ********** private function prototypes ********** @@ -578,8 +587,6 @@ fpgaState = handleFPGAReceiveHeaderState(); break; - // TODO - sensor/ADC init/configuration states - case FPGA_STATE_RCV_ALL_SENSORS: fpgaState = handleFPGAReceiveAllSensorsState(); break; @@ -643,8 +650,6 @@ fpgaState = handleFPGAReadHeaderState(); break; - // TODO - sensor/ADC init/configuration states - case FPGA_STATE_WRITE_ALL_ACTUATORS: fpgaState = handleFPGAWriteAllActuatorsState(); break; @@ -891,6 +896,38 @@ /*********************************************************************//** * @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 ) +{ +#ifndef DEBUG_ENABLED + 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() != DG_MODE_INIT ) + { + if ( abs( diffFPGATimerCount - diffTimerCount ) > PROCESSOR_FPGA_CLOCK_DIFF_TOLERANCE ) + { + if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_CLOCK_SPEED_ERROR ) ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_FPGA_CLOCK_SPEED_CHECK_FAILURE, diffFPGATimerCount, diffTimerCount ); + } + } + } + + currentFPGATimerCount_ms = newFPGATimerCount_ms; + currentTimerCount_ms = newTimerCount_ms; +#endif +} + +/*********************************************************************//** + * @brief * The setupDMAForWriteCmd function sets the byte count for the next DMA * write command to the FPGA. * @details Inputs: none @@ -2077,6 +2114,43 @@ /*********************************************************************//** * @brief + * The getFPGAInternalVccVoltage function gets the FPGA internal Vcc voltage. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return internal Vcc voltage + *************************************************************************/ +U16 getFPGAInternalVccVoltage( void ) +{ + return fpgaSensorReadings.fpgaADCVccInt; +} + +/*********************************************************************//** + * @brief + * The getFPGAInternalVccAuxilaryVoltage function gets the FPGA auxiliary + * Vcc voltage. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return auxiliary Vcc voltage + *************************************************************************/ +U16 getFPGAInternalVccAuxiliaryVoltage( void ) +{ + return fpgaSensorReadings.fpgaADCVccAux; +} + +/*********************************************************************//** + * @brief + * The getFPGAVPVNVoltage function gets the FPGA VPVN voltage. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return VPVN voltage + *************************************************************************/ +U16 getFPGAVPVNVoltage( void ) +{ + return fpgaSensorReadings.fpgaADCVPVN; +} + +/*********************************************************************//** + * @brief * The getFPGABaroReadCount function gets the FPGA barometric sensor read count. * @details Inputs: fpgaSensorReadings * @details Outputs: none @@ -2368,4 +2442,68 @@ return fpgaSensorReadings.fpgaHeaterGNDADC; } +/*********************************************************************//** + * @brief + * The getFPGAHeaterGateADCReadCount function returns the main primary heater + * voltage ADC read count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return main primary heater voltage ADC read count + *************************************************************************/ +U08 getFPGAHeaterGateADCReadCount( void ) +{ + return fpgaSensorReadings.fpgaHeater1ADCReadCount; +} + +/*********************************************************************//** + * @brief + * The getFPGAHeaterGateADCReadCount function returns the main primary heater + * voltage ADC error count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return main primary heater voltage ADC error count + *************************************************************************/ +U08 getFPGAHeaterGateADCErrorCount( void ) +{ + return fpgaSensorReadings.fpgaHeater1ADCErrorCount; +} + +/*********************************************************************//** + * @brief + * The getFPGADrainPumpCurrentFeedback function returns the drain pump current + * feedback. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return drain pump current feedback + *************************************************************************/ +U16 getFPGADrainPumpCurrentFeedback( void ) +{ + return fpgaSensorReadings.fpgaDrainPumpCurrentFeedback; +} + +/*********************************************************************//** + * @brief + * The getFPGADrainPumpSpeedFeedback function returns the drain pump speed + * feedback. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return drain pump speed feedback + *************************************************************************/ +U16 getFPGADrainPumpSpeedFeedback( void ) +{ + return fpgaSensorReadings.fpgaDrainPumpSpeedFeedback; +} + +/*********************************************************************//** + * @brief + * The getFPGADrainPumpDirection function returns the drain pump direction. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return drain pump direction + *************************************************************************/ +U08 getFPGADrainPumpDirection( void ) +{ + return fpgaSensorReadings.fpgaDrainPumpDirection; +} + /**@}*/