/************************************************************************** * * Copyright (c) 2019-2024 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 * * @author (last) Sean Nash * @date (last) 10-Sep-2023 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 * ***************************************************************************/ #include // For memset(), memcpy() #include "sci.h" #include "sys_dma.h" #include "Comm.h" #include "Compatible.h" #include "FPGA.h" #include "FpgaTD.h" #include "Messaging.h" #include "OperationModes.h" #include "PersistentAlarm.h" #include "Timers.h" #include "Utilities.h" /** * @addtogroup FpgaTD * @{ */ // ********** private definitions ********** #define FPGA_EXPECTED_ID 0x5A ///< Expected ID for HD FPGA. #define PROCESSOR_FPGA_CLOCK_DIFF_TOLERANCE 1 ///< Tolerance for processor clock speed check against FPGA clock. #define MAX_FPGA_COMM_FAILURES_WINDOW_MS ( 1 * SEC_PER_MIN * MS_PER_SECOND ) ///< FPGA comm failures window #define MAX_FPGA_COMM_FAILURES 3 ///< FPGA maximum comm failures per MAX_FPGA_COMM_FAILURES_WINDOW_MS #define MIN_POWER_ON_TIME_FOR_COMM_FAILS ( 1 * MS_PER_SECOND ) ///< Allow FPGA comm errors for first second after power-up // FPGA Sensors Record #pragma pack(push,1) /// Record structure for FPGA header read. typedef struct { U08 fpgaId; ///< Reg 0. FPGA ID code. Checked against expected value at power up to verify basic FPGA communication and operation. U08 fpgaRev; ///< Reg 1. FPGA revision (minor) being reported. U08 fpgaRevMajor; ///< Reg 2. FPGA revision (major) being reported. U08 fpgaRevLab; ///< Reg 3. FPGA revision (lab) being reported. U16 fpgaStatus; ///< Reg 4. FPGA status register. } FPGA_HEADER_T; // Read only on FPGA /// Record structure for FPGA continuous priority reads. typedef struct { U08 errorCountProcessor; ///< Reg 256. Error count for processor communications U08 errorCountPC; ///< Reg 257. TBD. U08 fpgaHWConfigReg; ///< Reg 258. Hardware configuration register (i.e. BETA or DVT) U08 sPumpDACRdStatus; ///< Reg 259. Syringe pump DAC read status. U16 sPumpDACSet; ///< Reg 260. Syringe pump DAC setting. U16 sPumpDACEEProm; ///< Reg 262. Syringe pump DAC EEProm data. U08 reserved4; ///< Reg 264. Reserved. U08 reserved5; ///< Reg 265. Reserved. U08 reserved6; ///< Reg 266. Reserved. U08 reserved7; ///< Reg 267. Reserved. F32 reserved8; ///< Reg 268. Reserved. U08 reserved9; ///< Reg 272. Reserved. U08 reserved10; ///< Reg 273. Reserved. U08 reserved11; ///< Reg 274. Reserved. U08 reserved12; ///< Reg 275. Reserved. 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 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. U32 adc1Channel0; ///< Reg 292. ADC1 channel 0 data. U32 adc1Channel1; ///< Reg 296. ADC1 channel 1 data. U32 reserved13; ///< Reg 300. Reserved. U32 reserved14; ///< Reg 304. Reserved. F32 reserved15; ///< Reg 308. Reserved. U08 adc1SequenceCount; ///< Reg 312. ADC1 round robin channel sequence count. U08 adc1ErrorCount; ///< Reg 313. ADC1 error count. U16 accelX; ///< Reg 314. Accelerometer X axis data. U16 accelY; ///< Reg 316. Accelerometer Y axis data. U16 accelZ; ///< Reg 318. Accelerometer Z axis data. U16 accelXMax; ///< Reg 320. Accelerometer X axis max data (since last read). U16 accelYMax; ///< Reg 322. Accelerometer Y axis max data (since last read). U16 accelZMax; ///< Reg 324. Accelerometer Z axis max data (since last read). U16 accelFaultRegister; ///< Reg 326. Accelerometer fault register. U16 accelSampleCounter; ///< Reg 328. Accelerometer sample count. U16 venousPressure; ///< Reg 330. Venous pressure sensor data. U16 venousTemperature; ///< Reg 332. Venous pressure sensor temperature. U08 venousReadCounter; ///< Reg 334. Venous pressure sensor read count. U08 dialOutPumpSensorStatus; ///< Reg 335. Dialysate outlet pump hall sensor status. U16 dialInPumpHallSensorCount; ///< Reg 336. Dialysate inlet pump hall sensor count. U16 dialOutPumpHallSensorCount; ///< Reg 338. Dialysate outlet pump hall sensor count. U32 reserved16; ///< Reg 340. Reserved. U32 reserved17; ///< Reg 344. Reserved. F32 reserved18; ///< Reg 348. Reserved. U16 fan1PulseTime; ///< Reg 352. Fan 1 pulse time in 2.5 uSec resolution. 0xFFFF if fan RPM < 500 RPM. U16 fan2PUlseTime; ///< Reg 354. Fan 2 pulse time in 2.5 uSec resolution. 0xFFFF if fan RPM < 500 RPM. U16 fpgaGPIO; ///< Reg 356. FPGA GPIO register. S16 VBAPosition; ///< Reg 358. Encoder position from VBA pinch valve. 0 until PID interface is enabled. S16 VBVPosition; ///< Reg 360. Encoder position from VBV pinch valve. 0 until PID interface is enabled. S16 VDiPosition; ///< Reg 362. Encoder position from VDi pinch valve. 0 until PID interface is enabled. S16 VDoPosition; ///< Reg 364. Encoder position from VDo pinch valve. 0 until PID interface is enabled. S16 fpgaIntVoltage; ///< Reg 366. Internal FPGA Vcc voltage. 3V range over 12 bits (0..4095). U16 valveStatus; ///< Reg 368. Valve status register. U16 VBAPWMTarget; ///< Reg 370. PWM target duty cycle for VBA pinch valve. U16 VBVPWMTarget; ///< Reg 372. PWM target duty cycle for VBV pinch valve. U16 VDiPWMTarget; ///< Reg 374. PWM target duty cycle for VDi pinch valve. U16 VDoPWMTarget; ///< Reg 376. PWM target duty cycle for VDo pinch valve. U16 fpgaAuxVoltage; ///< Reg 378. Internal FPGA Vcc Aux voltage. 3V range over 12 bits (0..4095). U08 syringePumpStatus; ///< Reg 380. Syringe pump status register. U08 syringePumpADCReadCounter; ///< Reg 381. Syringe pump ADC read counter. U08 syringePumpADCandDACStatus; ///< Reg 382. Syringe pump ADC and DAC status register. U08 syringePumpEncoderStatus; ///< Reg 383. Syringe pump encoder status register. U32 syringePumpEncPosition; ///< Reg 384. Syringe pump encoder position U16 syringePumpAdcDataReadCh0; ///< Reg 388. Syringe pump ADC channel 0 register (10 bit). U16 syringePumpAdcDataReadCh1; ///< Reg 390. Syringe pump ADC channel 1 register (10 bit). U16 syringePumpAdcDataReadCh2; ///< Reg 392. Syringe pump ADC channel 2 register (10 bit). U16 syringePumpAdcDataReadCh3; ///< Reg 394. Syringe pump ADC channel 3 register (10 bit). U16 VBASpeed; ///< Reg 396. VBA pinch valve speed (Register VAUX0) U16 VBVSpeed; ///< Reg 398. VBV pinch valve speed (Register VAUX1) U16 VBVCurrent; ///< Reg 400. VBV pinch valve current (Register VAUX2) U16 VDoCurrent; ///< Reg 402. VDo pinch valve current (Register VAUX3) U16 VBACurrent; ///< Reg 404. VBA pinch valve current (Register VAUX8) U16 VDiSpeed; ///< Reg 406. VDi pinch valve current (Register VAUX5) U16 VDoSpeed; ///< Reg 408. VDo pinch valve speed (Register VAUX10) U16 VDiCurrent; ///< Reg 410. VDi pinch valve current (Register VAUX13) U16 fpgaTemperature; ///< Reg 412. FPGA die temperature (deg C = counts x (503.975/4096) - 273.15). U16 fpgaVpvn; ///< Reg 414. FPGA pvn voltage. 1V range over 12 bits (0..4095). U16 fpgaTimerCount_ms; ///< Reg 416. Free running 1ms timer counter. Rolls over at 65535.Internal FPGA timer count in ms. U16 backupAlarmAudioPeakCurrent; ///< Reg 418. Piezo alarm peak ADC current in previous 10ms. 12 bit unsigned. U08 V1EncError; ///< Reg 420. Pinch valve V1 encoder error counter. U08 V2EncError; ///< Reg 421. Pinch valve V2 encoder error counter. U08 V3EncError; ///< Reg 422. Pinch valve V3 encoder error counter. U08 V4EncError; ///< Reg 423. Pinch valve V4 encoder error counter. U08 ADACounter; ///< Reg 424. ADA bubble counter. U08 ADVCounter; ///< Reg 425. ADV bubble counter. U08 reserved19; ///< Reg 426. Reserved. U08 reserved20; ///< Reg 427. Reserved. U08 VenousErrorCounter; ///< Reg 428. Venous error counter. U08 reserved21; ///< Reg 429. Reserved. U16 reserved22; ///< Reg 430. Reserved. U16 reserved23; ///< Reg 432. Reserved. U16 reserved24; ///< Reg 434. Reserved. U16 reserved25; ///< Reg 436. Reserved. U16 reserved26; ///< Reg 438. Reserved. 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 } FPGA_SENSORS_T; /// Record structure for FPGA continuous priority writes. typedef struct { U08 fpgaSensorTest; ///< Reg 11. Blood leak and bubble detector sensor test register. U16 fpgaPIDControl; ///< Reg 12. Valve PID enables. S16 VBASetPoint; ///< Reg 14. VBA pinch valve is commanded to this set point position. S16 VBVSetPoint; ///< Reg 16. VBV pinch valve is commanded to this set point position. S16 VDiSetPoint; ///< Reg 18. VDi pinch valve is commanded to this set point position. S16 VDoSetPoint; ///< Reg 20. VDo pinch valve is commanded to this set point position. S16 VSpareSetPoint; ///< Reg 22. VSpare pinch valve is commanded to this set point position. U16 VBAPWMFixed; ///< Reg 24. VBA PWM set to fixed current by setting fixed PWM duty cycle. Range 750 to 4250. < 2500 is reverse direction. U16 VBVPWMFixed; ///< Reg 26. VBV PWM set to fixed current by setting fixed PWM duty cycle. Range 750 to 4250. < 2500 is reverse direction. U16 VDiPWMFixed; ///< Reg 28. VDi PWM set to fixed current by setting fixed PWM duty cycle. Range 750 to 4250. < 2500 is reverse direction. U16 VDoPWMFixed; ///< Reg 30. VDo PWM set to fixed current by setting fixed PWM duty cycle. Range 750 to 4250. < 2500 is reverse direction. U16 VSparePWMFixed; ///< Reg 32. Vspare PWM set to fixed current by setting fixed PWM duty cycle. Range 750 to 4250. < 2500 is reverse direction. U08 alarmControl; ///< Reg 34. Alarm (audio) control register. U08 syringePumpControl; ///< Reg 35. Syringe pump control register. U32 syringePumpStepToggleTime; ///< Reg 36. Syringe pump step time toggle register. Sets time between step toggle which dictates stepper motor speed. U16 syringePumpDACOut; ///< Reg 40. Syringe pump DAC output level (12-bit). U08 syringePumpADCandDACControl; ///< Reg 42. Syringe pump ADC and DAC control register. U08 bloodLeakUARTControl; ///< Reg 43. Blood leak UART control. U08 bloodLeakFIFOTransmit; ///< Reg 44. Character word store in FIFO to be transmitted into blood leak UART interface. } FPGA_ACTUATORS_T; #pragma pack(pop) // ********** private data ********** // FPGA data static FPGA_HEADER_T fpgaHeader; ///< Record of last received FPGA header data. static FPGA_SENSORS_T fpgaSensorReadings; ///< Record of last received FPGA priority sensor data. static FPGA_ACTUATORS_T fpgaActuatorSetPoints; ///< Record of next transmitted FPGA priority actuator data. // FPGA Clock Speed Test static U16 currentFPGATimerCount_ms = 0; ///< Last read ms timer count from FPGA. static U32 currentTimerCount_ms = 0; ///< Last read ms timer count from processor. // ********** private function prototypes ********** /*********************************************************************//** * @brief * The initFpgaTD function initializes the TD FPGA module. * @details Inputs: none * @details Outputs: TD FPGA module initialized. * @return none *************************************************************************/ void initFpgaTD( void ) { // Initialize fpga driver initFPGA( (U08*)&fpgaHeader, (U08*)&fpgaSensorReadings, (U08*)&fpgaActuatorSetPoints, sizeof(FPGA_HEADER_T), sizeof(FPGA_SENSORS_T), sizeof(FPGA_ACTUATORS_T) ); // Initialize fpga data structures memset( &fpgaHeader, 0, sizeof(FPGA_HEADER_T) ); memset( &fpgaSensorReadings, 0, sizeof(FPGA_SENSORS_T) ); memset( &fpgaActuatorSetPoints, 0, sizeof(FPGA_ACTUATORS_T) ); fpgaActuatorSetPoints.alarmControl = (U08)MIN_ALARM_VOLUME_ATTENUATION << 2; // Start alarm audio volume at maximum // Set the HD valves fixed PWM mode to 2500, so if it was commanded to be in PWM mode rather than PID control // the valves will not move to 0 position // fpgaActuatorSetPoints.VDiPWMFixed = FPGA_VALVES_MIN_PWM_MODE_COUNT; // fpgaActuatorSetPoints.VDoPWMFixed = FPGA_VALVES_MIN_PWM_MODE_COUNT; // fpgaActuatorSetPoints.VBAPWMFixed = FPGA_VALVES_MIN_PWM_MODE_COUNT; // fpgaActuatorSetPoints.VBVPWMFixed = FPGA_VALVES_MIN_PWM_MODE_COUNT; // initialize FPGA comm failures windowed timer count initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES, MAX_FPGA_COMM_FAILURES, MAX_FPGA_COMM_FAILURES_WINDOW_MS); } /*********************************************************************//** * @brief * The execFPGATest function executes the FPGA self-test. * @details Inputs: fpgaHeader * @details Outputs: none * @return passed, or failed *************************************************************************/ SELF_TEST_STATUS_T execFPGATest( void ) { SELF_TEST_STATUS_T result; // check FPGA reported correct ID if ( FPGA_EXPECTED_ID == fpgaHeader.fpgaId ) { // Check FPGA compatibility w/ firmware if ( HD_FPGA_COMPATIBILITY_REV == fpgaSensorReadings.fpgaCompatibilityRev ) { result = SELF_TEST_STATUS_PASSED; } else { result = SELF_TEST_STATUS_FAILED; SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_FPGA_POST_TEST_FAILED, (U32)HD_FPGA_COMPATIBILITY_REV, (U32)fpgaSensorReadings.fpgaCompatibilityRev ) } } else { result = SELF_TEST_STATUS_FAILED; SET_ALARM_WITH_1_U32_DATA( ALARM_ID_TD_FPGA_POST_TEST_FAILED, (U32)fpgaHeader.fpgaId ) } return result; } /*********************************************************************//** * @brief * The getFPGATimerCount function gets the latest FPGA timer millisecond count. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last FPGA timer count *************************************************************************/ U16 getFPGATimerCount( void ) { return fpgaSensorReadings.fpgaTimerCount_ms; } /*********************************************************************//** * @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 ) { // DEBUG WARNING // It may be necessary to comment out the following // code to prevent the alarm from occurring while // debugging. U16 newFPGATimerCount_ms = getFPGATimerCount(); U32 newTimerCount_ms = getMSTimerCount(); U32 diffFPGATimerCount = (U32)u16DiffWithWrap( currentFPGATimerCount_ms, newFPGATimerCount_ms ); U32 diffTimerCount = u32DiffWithWrap( currentTimerCount_ms, newTimerCount_ms ); if ( getCurrentOperationMode() != 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_TD_FPGA_CLOCK_SPEED_CHECK_FAILURE, diffFPGATimerCount, diffTimerCount ); } } } currentFPGATimerCount_ms = newFPGATimerCount_ms; currentTimerCount_ms = newTimerCount_ms; } /*********************************************************************//** * @brief * The getFPGAVersions function gets the fpga version numbers. * @details Inputs: fpgaHeader * @details Outputs: none * @return none *************************************************************************/ void getFPGAVersions( U08 *Id, U08 *Maj, U08 *Min, U08 *Lab ) { *Id = fpgaHeader.fpgaId; *Min = fpgaHeader.fpgaRev; *Maj = fpgaHeader.fpgaRevMajor; *Lab = fpgaHeader.fpgaRevLab; } /*********************************************************************//** * @brief * The getFPGATemperature function gets the fpga internal die temperature. * @details Inputs: fpgaHeader * @details Outputs: none * @return current internal FPGA die temperature (in counts) *************************************************************************/ U16 getFPGATemperature( void ) { return fpgaSensorReadings.fpgaTemperature; } /*********************************************************************//** * @brief * The getFPGAVcc function gets the fpga input voltage. * @details Inputs: fpgaHeader * @details Outputs: none * @return current FPGA input voltage (in volts) *************************************************************************/ F32 getFPGAVcc( void ) { F32 result = 0.0;//(F32)fpgaSensorReadings.fpgaIntVoltage * FPGA_INPUT_VOLTAGE_SCALE / (F32)BITS_12_FULL_SCALE; return result; } /*********************************************************************//** * @brief * The getFPGAVccAux function gets the fpga aux. voltage. * @details Inputs: fpgaHeader * @details Outputs: none * @return current FPGA aux. voltage (in volts) *************************************************************************/ F32 getFPGAVccAux( void ) { F32 result = 0.0;//(F32)fpgaSensorReadings.fpgaAuxVoltage * FPGA_INPUT_VOLTAGE_SCALE / (F32)BITS_12_FULL_SCALE; return result; } /*********************************************************************//** * @brief * The getFPGAVpvn function gets the fpga pvn voltage. * @details Inputs: fpgaHeader * @details Outputs: none * @return current FPGA pvn voltage (in volts) *************************************************************************/ F32 getFPGAVpvn( void ) { F32 result = 0.0;//(F32)fpgaSensorReadings.fpgaVpvn * FPGA_PVN_VOLTAGE_SCALE / (F32)BITS_12_FULL_SCALE; return result; } /*********************************************************************//** * @brief * The setAlarmAudioState function sets the fpga audio control to the given * state and volume. * @details Inputs: none * @details Outputs: alarm audio state and attenuation set * @param state the state of alarm audio to command (3..5): * 0 - No alarm tone * 1 - Low priority alarm tone (c e) * 2 - Medium priority alarm tone (c f# c) * 3 - High priority alarm tone (c f# c - c f#) * 4 - Continuous test tone (e) * @param volumeLevel the level of attenuation to command (0..2): * 4 - 3 dB gain * 3 - 6 dB gain * 2 - 9 dB gain * 1 - 12 dB gain * 0 - 15 dB gain * @param volumeDivider further attenuation via divider (6..7): * 0 - Divide by 2 * 1 - Divide by 4 * 2 - Divide by 8 * 3 - Divide by 16 * @return none *************************************************************************/ void setAlarmAudioState( U32 state, U32 volumeLevel, U32 volumeDivider ) { // U08 audioCmd = (U08)state; // // audioCmd |= ( (U08)volumeLevel << FPGA_ALARM_AUDIO_VOLUME_SHIFT ); // audioCmd |= ( (U08)volumeDivider << FPGA_ALARM_AUDIO_DIVIDE_SHIFT ); // // if ( ( state <= NUM_OF_ALARM_PRIORITIES ) && ( volumeLevel <= MAX_ALARM_VOLUME_ATTENUATION ) ) // { // fpgaActuatorSetPoints.alarmControl = audioCmd; // } // else // { // // S/w fault to indicate issue w/ s/w // SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_INVALID_ALARM_AUDIO_PARAM, (U32)audioCmd ) // // Set alarm audio to high priority, max volume for safety since s/w seems to be having trouble setting audio correctly // audioCmd = (U08)ALARM_PRIORITY_HIGH; // audioCmd |= ( (U08)MIN_ALARM_VOLUME_ATTENUATION << FPGA_ALARM_AUDIO_VOLUME_SHIFT ); // fpgaActuatorSetPoints.alarmControl = audioCmd; // } } /*********************************************************************//** * @brief * The getFPGABloodPumpHallSensorCount function gets the latest blood pump * hall sensor count. Count is a 16 bit free running counter. If counter is * counting up, indicates motor is running in forward direction. If counter is * counting down, indicates motor is running in reverse direction. Counter will * wrap at 0/65535. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last blood pump hall sensor count reading. *************************************************************************/ U16 getFPGABloodPumpHallSensorCount( void ) { return fpgaSensorReadings.bloodPumpHallSensorCount; } /*********************************************************************//** * @brief * The getFPGABloodPumpHallSensorStatus function gets the latest blood pump * hall sensor status. * Bit 7 - Derived direction of the blood pump motor (0=Fwd, 1=Rev) * Bit 6 - Unused * Bit 5-0 - Direction error count since power-up (rolls over) * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last blood pump hall sensor status reading. *************************************************************************/ U08 getFPGABloodPumpHallSensorStatus( void ) { return fpgaSensorReadings.bloodPumpHallSensorStatus; } /*********************************************************************//** * @brief * The getFPGADialInPumpHallSensorCount function gets the latest dialysate inlet pump * hall sensor count. Count is a 16 bit free running counter. If counter is * counting up, indicates motor is running in forward direction. If counter is * counting down, indicates motor is running in reverse direction. Counter will * wrap at 0/65535. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last dialysate inlet pump hall sensor count reading. *************************************************************************/ U16 getFPGADialInPumpHallSensorCount( void ) { return fpgaSensorReadings.dialInPumpHallSensorCount; } /*********************************************************************//** * @brief * The getFPGADialInPumpHallSensorStatus function gets the latest dialysate inlet pump * hall sensor status. * Bit 7 - Derived direction of the dialysate inlet pump motor (0=Fwd, 1=Rev) * Bit 6 - Unused * Bit 5-0 - Direction error count since power-up (rolls over) * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last dialysate inlet pump hall sensor status reading. *************************************************************************/ U08 getFPGADialInPumpHallSensorStatus( void ) { return fpgaSensorReadings.dialInPumpHallSensorStatus; } /*********************************************************************//** * @brief * The getFPGADialOutPumpHallSensorCount function gets the latest dialysate outlet pump * hall sensor count. Count is a 16-bit free running counter. If counter is * counting up, indicates motor is running in forward direction. If counter is * counting down, indicates motor is running in reverse direction. Counter will * wrap at 0/65535. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last dialysate outlet pump hall sensor count reading. *************************************************************************/ U16 getFPGADialOutPumpHallSensorCount( void ) { return fpgaSensorReadings.dialOutPumpHallSensorCount; } /*********************************************************************//** * @brief * The getFPGADialOutPumpHallSensorStatus function gets the latest dialysate outlet pump * hall sensor status. * Bit 7 - Derived direction of the dialysate outlet pump motor (0=Fwd, 1=Rev) * Bit 6 - Unused * Bit 5-0 - Direction error count since power-up (rolls over) * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last dialysate outlet pump hall sensor status reading. *************************************************************************/ U08 getFPGADialOutPumpHallSensorStatus( void ) { return fpgaSensorReadings.dialOutPumpSensorStatus; } /*********************************************************************//** * @brief * The getFPGABloodPumpOcclusion function gets the latest blood occlusion reading. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last blood occlusion reading *************************************************************************/ U16 getFPGABloodPumpOcclusion( void ) { return fpgaSensorReadings.bloodOcclusionData; } /*********************************************************************//** * @brief * The getFPGABloodPumpOcclusionReadCounter function gets the latest blood * pump occlusion read counter. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last blood pump occlusion read counter *************************************************************************/ U08 getFPGABloodPumpOcclusionReadCounter( void ) { return fpgaSensorReadings.bloodOcclusionReadCount; } /*********************************************************************//** * @brief * The getFPGABloodPumpOcclusionErrorCounter function gets the latest blood * pump occlusion error counter. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last blood pump occlusion error counter *************************************************************************/ U08 getFPGABloodPumpOcclusionErrorCounter( void ) { return fpgaSensorReadings.bloodOcclusionErrorCount; } /*********************************************************************//** * @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 * signed channel reading. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last arterial pressure reading *************************************************************************/ U32 getFPGAArterialPressure( void ) { return fpgaSensorReadings.adc1Channel0; } /*********************************************************************//** * @brief * The getFPGAArterialPressureReadCounter function gets the latest arterial * pressure sensor read counter. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last arterial pressure sensor read counter *************************************************************************/ U08 getFPGAArterialPressureReadCounter( void ) { return fpgaSensorReadings.adc1SequenceCount; } /*********************************************************************//** * @brief * The getFPGAArterialPressureErrorCounter function gets the latest arterial * pressure sensor error counter. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last arterial pressure sensor error counter *************************************************************************/ U08 getFPGAArterialPressureErrorCounter( void ) { return fpgaSensorReadings.adc1ErrorCount; } /*********************************************************************//** * @brief * The getFPGADVTArterialPressure function gets the latest arterial pressure reading. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last arterial pressure reading *************************************************************************/ U16 getFPGADVTArterialPressure( void ) { return fpgaSensorReadings.arterialPressure; } /*********************************************************************//** * @brief * The getFPGADVTArterialTemperature function gets the latest arterial pressure * sensor temperature reading. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last arterial pressure sensor temperature reading *************************************************************************/ U16 getFPGADVTArterialTemperature( void ) { return fpgaSensorReadings.arterialPressureTemperature; } /*********************************************************************//** * @brief * The getFPGADVTArterialPressureReadCounter function gets the latest arterial * pressure sensor read counter. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last arterial pressure sensor read counter *************************************************************************/ U08 getFPGADVTArterialPressureReadCounter( void ) { return fpgaSensorReadings.arterialPressureReadCount; } /*********************************************************************//** * @brief * The getFPGATDVTArterialPressureErrorCounter function gets the latest arterial * pressure sensor error counter. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last arterial pressure sensor error counter *************************************************************************/ U08 getFPGATDVTArterialPressureErrorCounter( void ) { return fpgaSensorReadings.arterialPressureErrorCount; } /*********************************************************************//** * @brief * The getFPGAVenousPressure function gets the latest venous pressure reading. * The high 2 bits are status bits: 00=ok, 01=cmd mode, 10=stale data, 11=diag * The low 14 bits are data. Zero is at 1638. Values above are positive, * below are negative. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last venous pressure reading *************************************************************************/ U16 getFPGAVenousPressure( void ) { return fpgaSensorReadings.venousPressure; } /*********************************************************************//** * @brief * The getFPGAVenousPressureTemperature function gets the latest venous pressure * sensor temperature reading. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last venous pressure sensor temperature reading *************************************************************************/ U16 getFPGAVenousPressureTemperature( void ) { return fpgaSensorReadings.venousTemperature; } /*********************************************************************//** * @brief * The getFPGAVenousPressureReadCounter function gets the latest venous pressure * sensor read counter. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last venous pressure sensor read counter *************************************************************************/ U08 getFPGAVenousPressureReadCounter( void ) { return fpgaSensorReadings.venousReadCounter; } /*********************************************************************//** * @brief * The getFPGAVenousPressureErrorCounter function gets the latest venous pressure * sensor error counter. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last venous pressure sensor error counter *************************************************************************/ U08 getFPGAVenousPressureErrorCounter( void ) { return fpgaSensorReadings.VenousErrorCounter; } /*********************************************************************//** * @brief * The setFPGASyringePumpControlFlags function sets the syringe pump control * register per given bit flags. * @details Inputs: none * @details Outputs: fpgaActuatorSetPoints * @param bitFlags control bit settings for syringe pump * @return none *************************************************************************/ void setFPGASyringePumpControlFlags( U08 bitFlags ) { fpgaActuatorSetPoints.syringePumpControl = bitFlags; } /*********************************************************************//** * @brief * The setFPGASyringePumpADCandDACControlFlags function sets the syringe pump * ADC/DAC control register per given bit flags. * @details Inputs: none * @details Outputs: fpgaActuatorSetPoints * @param bitFlags ADC/DAC control bit settings for syringe pump * @return none *************************************************************************/ void setFPGASyringePumpADCandDACControlFlags( U08 bitFlags ) { fpgaActuatorSetPoints.syringePumpADCandDACControl = bitFlags; } /*********************************************************************//** * @brief * The setFPGASyringePumpDACOutputLevel function sets the syringe pump force * sensor DAC output level register to a given value. * @details Inputs: none * @details Outputs: fpgaActuatorSetPoints * @param counts level to set syringe pump force sensor DAC to * @return none *************************************************************************/ void setFPGASyringePumpDACOutputLevel( U16 counts ) { fpgaActuatorSetPoints.syringePumpDACOut = counts; } /*********************************************************************//** * @brief * The setFPGASyringePumpStepToggleTime function sets the syringe pump stepper * toggle time register to a given period (in uSec). * @details Inputs: none * @details Outputs: fpgaActuatorSetPoints * @param microSeconds toggle the stepper motor at this time interval to set pump speed * @return none *************************************************************************/ void setFPGASyringePumpStepToggleTime( U32 microSeconds ) { fpgaActuatorSetPoints.syringePumpStepToggleTime = microSeconds; } /*********************************************************************//** * @brief * The getFPGASyringePumpStatus function gets the latest syringe pump status * register reading. Bit 0 indicates a fault. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump status reading *************************************************************************/ U08 getFPGASyringePumpStatus( void ) { return fpgaSensorReadings.syringePumpStatus; } /*********************************************************************//** * @brief * The getFPGASyringePumpADCReadCounter function gets the latest syringe pump * ADC read counter. Counter is 8-bit and rolls over when exceeding 255. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump ADC read counter *************************************************************************/ U08 getFPGASyringePumpADCReadCounter( void ) { return fpgaSensorReadings.syringePumpADCReadCounter; } /*********************************************************************//** * @brief * The getFPGASyringePumpADCandDACStatus function gets the latest syringe pump * ADC/DAC status register reading. * Bit 7 = DAC write and read-back done * Bit 6 = I2C error on DAC data transfer * Bit 0..5 = count of I2C errors, rolls over after 63 * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump ADC/DAC status reading *************************************************************************/ U08 getFPGASyringePumpADCandDACStatus( void ) { return fpgaSensorReadings.syringePumpADCandDACStatus; } /*********************************************************************//** * @brief * The getFPGASyringePumpEncoderStatus function gets the latest syringe pump * encoder status register reading. * Bit 7 = direction (0=fwd, 1=rev) * Bit 0..5 = direction error count (# of errors after power up, rolls over after 63) * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump encoder status reading *************************************************************************/ U08 getFPGASyringePumpEncoderStatus( void ) { return fpgaSensorReadings.syringePumpEncoderStatus; } /*********************************************************************//** * @brief * The getFPGASyringePumpEncoderPosition function gets the latest syringe pump * encoder position reading. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump encoder position reading *************************************************************************/ U32 getFPGASyringePumpEncoderPosition( void ) { return fpgaSensorReadings.syringePumpEncPosition; } /*********************************************************************//** * @brief * The getFPGASyringePumpADCChannel0 function gets the latest syringe pump ADC * channel 0 register reading (syringe pump force sensor). * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump ADC channel 0 reading *************************************************************************/ U16 getFPGASyringePumpADCChannel0( void ) { return fpgaSensorReadings.syringePumpAdcDataReadCh0; } /*********************************************************************//** * @brief * The getFPGASyringePumpADCChannel1 function gets the latest syringe pump ADC * channel 1 register reading (syringe detection switch). * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump ADC channel 1 reading *************************************************************************/ U16 getFPGASyringePumpADCChannel1( void ) { return fpgaSensorReadings.syringePumpAdcDataReadCh1; } /*********************************************************************//** * @brief * The getFPGASyringePumpADCChannel2 function gets the latest syringe pump ADC * channel 2 register reading (syringe pump home position sensor). * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump ADC channel 2 reading *************************************************************************/ U16 getFPGASyringePumpADCChannel2( void ) { return fpgaSensorReadings.syringePumpAdcDataReadCh2; } /*********************************************************************//** * @brief * The getFPGASyringePumpADCChannel3 function gets the latest syringe pump ADC * channel 3 register reading. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump ADC channel 3 reading *************************************************************************/ U16 getFPGASyringePumpADCChannel3( void ) { return fpgaSensorReadings.syringePumpAdcDataReadCh3; } /*********************************************************************//** * @brief * The getFPGASyringePumpDACStatus function gets the latest syringe pump * DAC status. * Bit 0: PD0 * Bit 1: PD1 * Bit 2: POR * Bit 3: Ready (not busy) * Bits 4..7: N/A * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump DAC status reading *************************************************************************/ U08 getFPGASyringePumpDACStatus( void ) { return fpgaSensorReadings.sPumpDACRdStatus; } /*********************************************************************//** * @brief * The getFPGASyringePumpDACSetting function gets the latest syringe pump * DAC setting. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump DAC setting *************************************************************************/ U16 getFPGASyringePumpDACSetting( void ) { return fpgaSensorReadings.sPumpDACSet; } /*********************************************************************//** * @brief * The getFPGASyringePumpDACStoredSetting function gets the latest syringe * pump DAC setting stored in sensor's EEPROM. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return last syringe pump DAC setting stored in EEPROM *************************************************************************/ U16 getFPGASyringePumpDACStoredSetting( void ) { return fpgaSensorReadings.sPumpDACEEProm; } /*********************************************************************//** * @brief * The getFPGAAccelAxes function gets the accelerometer axis readings. * Axis readings are in ADC counts. 0.004 g per LSB. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @param x Populate this param with X axis reading * @param y Populate this param with Y axis reading * @param z Populate this param with Z axis reading * @return none *************************************************************************/ void getFPGAAccelAxes( S16 *x, S16 *y, S16 *z ) { *x = (S16)fpgaSensorReadings.accelX; *y = (S16)fpgaSensorReadings.accelY; *z = (S16)fpgaSensorReadings.accelZ; } /*********************************************************************//** * @brief * The getFPGAAccelMaxes function gets the maximum accelerometer axis readings. * from last FPGA read (every 10ms). * Axis readings are in ADC counts. 0.004 g per LSB. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @param x Populate this param with maximum X axis reading * @param y Populate this param with maximum Y axis reading * @param z Populate this param with maximum Z axis reading * @return none *************************************************************************/ void getFPGAAccelMaxes( S16 *xmax, S16*ymax, S16*zmax ) { *xmax = (S16)fpgaSensorReadings.accelXMax; *ymax = (S16)fpgaSensorReadings.accelYMax; *zmax = (S16)fpgaSensorReadings.accelZMax; } /*********************************************************************//** * @brief * The getFPGAAccelStatus function gets the accelerometer reading count * and error register values. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @param cnt Populate this param with latest sample counter value * @param err Populate this param with latest error * @return none *************************************************************************/ void getFPGAAccelStatus( U16 *cnt, U16 *err ) { *cnt = fpgaSensorReadings.accelSampleCounter; *err = fpgaSensorReadings.accelFaultRegister; } /*********************************************************************//** * @brief * The getFPGABackupAlarmAudioCurrent function gets the latest piezo alarm * audio current reading. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return Latest piezo alarm audio current reading *************************************************************************/ F32 getFPGABackupAlarmAudioCurrent( void ) { // U16 adcCnts = fpgaSensorReadings.backupAlarmAudioPeakCurrent; F32 result = 0.0;//( ( (F32)adcCnts / (F32)BITS_12_FULL_SCALE ) * FPGA_BACKUP_ALARM_AUDIO_CONVERT ) * (F32)MA_PER_AMP; return result; } /*********************************************************************//** * @brief * The getFPGAAirTrapLevels function gets the latest air trap level sensor * readings. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return none *************************************************************************/ void getFPGAAirTrapLevels( BOOL *airAtLower, BOOL *airAtUpper ) { // U16 fpgaGPIO = fpgaSensorReadings.fpgaGPIO; U16 lower = 0;//fpgaGPIO & FPGA_AIRTRAP_LEVEL_LOW_MASK; U16 upper = 0;//fpgaGPIO & FPGA_AIRTRAP_LEVEL_HIGH_MASK; *airAtLower = ( 0 == lower ? FALSE : TRUE ); *airAtUpper = ( 0 == upper ? FALSE : TRUE ); } /*********************************************************************//** * @brief * The setFPGAValvesControlMode function sets the valves control mode. * @details Inputs: fpgaActuatorSetPoints * @details Outputs: fpgaActuatorSetPoints * @param bits : The bits to enable the PID controller of a valve * @return none *************************************************************************/ void setFPGAValvesControlMode( U16 bits ) { fpgaActuatorSetPoints.fpgaPIDControl = bits; } /*********************************************************************//** * @brief * The getValvesStatus function reads the status of the valves * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return The status of the valves *************************************************************************/ U16 getFPGAValvesStatus( void ) { return fpgaSensorReadings.valveStatus; } /*********************************************************************//** * @brief * The noFPGAFluidLeakDetected function returns TRUE if no fluid leak has been * detected (dry) and FALSE if a fluid leak has been detected (wet). * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return noFPGAFluidLeakDetected *************************************************************************/ BOOL noFPGAFluidLeakDetected( void ) { U16 noFPGAFluidLeakDetected = 0;//fpgaSensorReadings.fpgaGPIO & FPGA_FLUID_LEAK_STATE_MASK; return ( 0 == noFPGAFluidLeakDetected ? FALSE : TRUE ); } /*********************************************************************//** * @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 = 0;//(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 * @details Outputs: none * @return none *************************************************************************/ void setFPGABloodLeakUARTControl( U08 value ) { fpgaActuatorSetPoints.bloodLeakUARTControl = value; } /*********************************************************************//** * @brief * The setFPGABloodLeakUARTTransmit function sets the blood leak sensor UART * transmit value. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return none *************************************************************************/ void setFPGABloodLeakUARTTransmit( U08 value ) { fpgaActuatorSetPoints.bloodLeakFIFOTransmit = value; } /*********************************************************************//** * @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 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( U32 bubble ) { U16 noFPGABubbleDetected = 0; // if ( bubble == ADV ) // { // noFPGABubbleDetected = fpgaSensorReadings.fpgaGPIO & FPGA_ADV_BUBBLE_STATUS_MASK; // } // else // { // SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_BUBBLE_ID, bubble ) // } return ( 0 != noFPGABubbleDetected ? TRUE : FALSE ); } /*********************************************************************//** * @brief * The setFPGABubbleSelfTest function sets the given air bubble detector into * self-test mode via the FPGA. * @details Inputs: none * @details Outputs: fpgaActuatorSetPoints * @return: none *************************************************************************/ void setFPGABubbleSelfTest( U32 bubble ) { // 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: none * @details Outputs: fpgaActuatorSetPoints * @return: none *************************************************************************/ void clearFPGABubbleSelfTest( U32 bubble ) { // if ( bubble == ADV ) // { // fpgaActuatorSetPoints.fpgaSensorTest &= ~FPGA_ADV_BUBBLE_SELF_TEST_CMD; // } // else // { // SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_BUBBLE_ID, bubble ) // } } /*********************************************************************//** * @brief * The setValveDialyzerInletPosition function sets the position of VDi * in counts * @details Inputs: fpgaActuatorSetPoints * @details Outputs: fpgaActuatorSetPoints * @param setPoint : Next position of the valve in counts * @return none *************************************************************************/ void setFPGAValveDialyzerInletPosition( S16 setPoint ) { fpgaActuatorSetPoints.VDiSetPoint = setPoint; } /*********************************************************************//** * @brief * The getValveDialyzerInletPosition function reads the current position * of VDi in counts * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return The current position of VDi *************************************************************************/ S16 getFPGAValveDialyzerInletPosition( void ) { return fpgaSensorReadings.VDiPosition; } /*********************************************************************//** * @brief * The getFPGAValveDialyzerInletCurrentCounts function reads the current \n * of VDi in counts * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return The current of VDi *************************************************************************/ U16 getFPGAValveDialyzerInletCurrentCounts( void ) { return fpgaSensorReadings.VDiCurrent; } #ifdef DEBUG_ENABLED /*********************************************************************//** * @brief * The setFPGAValveDialyzerInletPWM function sets the PWM of VDI in counts. * @details Inputs: fpgaActuatorSetPoints * @details Outputs: fpgaActuatorSetPoints * @param count which is the PWM of VDI in counts * @return none *************************************************************************/ void setFPGAValveDialyzerInletPWM( U16 count ) { fpgaActuatorSetPoints.VDiPWMFixed = count; } /*********************************************************************//** * @brief * The getFPGAValveDialyzerInletPWM function reads the current PWM target * of VDI. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return current PWM of VDI *************************************************************************/ U16 getFPGAValveDialyzerInletPWM( void ) { return fpgaSensorReadings.VDiPWMTarget; } #endif /*********************************************************************//** * @brief * The setFPGAValveDialyzerOutletPosition function sets the position of VDo * in counts * @details Inputs: fpgaActuatorSetPoints * @details Outputs: fpgaActuatorSetPoints * @param setPoint : Next position of the valve in counts * @return none *************************************************************************/ void setFPGAValveDialyzerOutletPosition( S16 setPoint ) { fpgaActuatorSetPoints.VDoSetPoint = setPoint; } /*********************************************************************//** * @brief * The getFPGAValveDialyzerOutletPosition function reads the current position * of VDo in counts * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return The current position of VDo *************************************************************************/ S16 getFPGAValveDialyzerOutletPosition( void ) { return fpgaSensorReadings.VDoPosition; } /*********************************************************************//** * @brief * The getFPGAValveDialyzerOutletCurrentCounts function reads the current * of VDo in counts * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return The current of VDo *************************************************************************/ U16 getFPGAValveDialyzerOutletCurrentCounts( void ) { return fpgaSensorReadings.VDoCurrent; } #ifdef DEBUG_ENABLED /*********************************************************************//** * @brief * The setFPGAValveDialyzerOutletPWM function sets the PWM of VDO in counts. * @details Inputs: fpgaActuatorSetPoints * @details Outputs: fpgaActuatorSetPoints * @param count which is the PWM of VDO in counts * @return none *************************************************************************/ void setFPGAValveDialyzerOutletPWM( U16 count ) { fpgaActuatorSetPoints.VDoPWMFixed = count; } /*********************************************************************//** * @brief * The getFPGAValveDialyzerOutletPWM function reads the current PWM target * of VDO. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return current PWM of VDO *************************************************************************/ U16 getFPGAValveDialyzerOutletPWM( void ) { return fpgaSensorReadings.VDoPWMTarget; } #endif /*********************************************************************//** * @brief * The setValveBloodVenousPosition function sets the position of VBV * in counts * @details Inputs: fpgaActuatorSetPoints * @details Outputs: fpgaActuatorSetPoints * @param setPoint : Next position of the valve in counts * @return none *************************************************************************/ void setFPGAValveBloodVenousPosition( S16 setPoint ) { fpgaActuatorSetPoints.VBVSetPoint = setPoint; } /*********************************************************************//** * @brief * The getValveBloodVenousPosition function reads the current position * of VBV in counts * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return The current position of VBV *************************************************************************/ S16 getFPGAValveBloodVenousPosition( void ) { return fpgaSensorReadings.VBVPosition; } /*********************************************************************//** * @brief * The getFPGAValveBloodVenousCurrentCounts function reads the current * of VBV in counts * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return The current of VBV *************************************************************************/ U16 getFPGAValveBloodVenousCurrentCounts( void ) { return fpgaSensorReadings.VBVCurrent; } #ifdef DEBUG_ENABLED /*********************************************************************//** * @brief * The setFPGAValveBloodVenousPWM function sets the PWM of VBV in counts. * @details Inputs: fpgaActuatorSetPoints * @details Outputs: fpgaActuatorSetPoints * @param count which is the PWM of VBV in counts * @return none *************************************************************************/ void setFPGAValveBloodVenousPWM( U16 count ) { fpgaActuatorSetPoints.VBVPWMFixed = count; } /*********************************************************************//** * @brief * The getFPGAValveBloodVenousPWM function returns the PWM of VBV in counts. * @details Inputs: fpgaActuatorSetPoints * @details Outputs: none * @return returns the PWM of VBV in counts *************************************************************************/ U16 getFPGAValveBloodVenousPWM( void ) { return fpgaSensorReadings.VBVPWMTarget; } #endif /*********************************************************************//** * @brief * The setValveBloodArterialPosition function sets the position of VBA * in counts * @details Inputs: fpgaActuatorSetPoints * @details Outputs: fpgaActuatorSetPoints * @param setPoint : Next position of the valve in counts * @return none *************************************************************************/ void setFPGAValveBloodArterialPosition( S16 setPoint ) { fpgaActuatorSetPoints.VBASetPoint = setPoint; } /*********************************************************************//** * @brief * The getValveBloodArterialPosition function reads the current position * of VBA in counts * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return The current position of VBA *************************************************************************/ S16 getFPGAValveBloodArterialPosition( void ) { return fpgaSensorReadings.VBAPosition; } /*********************************************************************//** * @brief * The getFPGAValveBloodArterialCurrentCounts function reads the current * of VBA in counts * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return The current of VBA *************************************************************************/ U16 getFPGAValveBloodArterialCurrentCounts( void ) { return fpgaSensorReadings.VBACurrent; } /*********************************************************************//** * @brief * The getFPGABoardTemperature function reads the FPGA board temperature. * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return Current FPGA board temperature *************************************************************************/ U16 getFPGABoardTemperature( void ) { return fpgaSensorReadings.fpgaTemperature; } /*********************************************************************//** * The getFPGAFrontDoorStatus function returns the FPGA front door status * bit. * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return front door FPGA status bit *************************************************************************/ U16 getFPGAFrontDoorStatus( void ) { return 0;//( fpgaSensorReadings.fpgaGPIO & FRONT_DOOR_SWITCH_MASK ); } /*********************************************************************//** * @brief * The getFPGAPBAADCTemperature function reads the PBA ADC temperature. * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return PBA ADC temperature *************************************************************************/ U32 getFPGAPBAADCTemperature( void ) { return fpgaSensorReadings.adc1Channel1; } /*********************************************************************//** * @brief * The getFPGAInletFan1TogglePeriod function reads the inlet fan 1 pulse time. * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return Inlet fan 1 pulse time *************************************************************************/ U16 getFPGAInletFan1TogglePeriod( void ) { return fpgaSensorReadings.fan1PulseTime; } /*********************************************************************//** * The getFPGAPumpTrackSwitchStatus function returns the FPGA pump track * switch status bit. * @details Inputs: none * @details Outputs: fpgaSensorReadings * @return pump track switch FPGA status bit *************************************************************************/ U16 getFPGAPumpTrackSwitchStatus( void ) { return 0;//( fpgaSensorReadings.fpgaGPIO & PUMP_TRACK_SWITCH_MASK ); } #ifndef _RELEASE_ /*********************************************************************//** * @brief * The getHardwareConfigStatus function returns the status of the hardware * configuration. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return status of the hardware configuration *************************************************************************/ HARDWARE_CONFIG_T getHardwareConfigStatus( void ) { HARDWARE_CONFIG_T configValue = (HARDWARE_CONFIG_T)fpgaSensorReadings.fpgaHWConfigReg; return configValue; } #endif #ifdef DEBUG_ENABLED /*********************************************************************//** * @brief * The setFPGAValveBloodArterialPWM function sets a PWM for VBA in counts. * @details Inputs: fpgaActuatorSetPoints * @details Outputs: fpgaActuatorSetPoints * @param count which is the PWM of VBA in counts * @return none *************************************************************************/ void setFPGAValveBloodArterialPWM( U16 count ) { fpgaActuatorSetPoints.VBAPWMFixed = count; } /*********************************************************************//** * @brief * The getFPGAValveBloodArterialPWM function returns the current PWM of * VBA in counts. * @details Inputs: fpgaSensorReadings * @details Outputs: none * @return current PWM of VBA in counts *************************************************************************/ U16 getFPGAValveBloodArterialPWM( void ) { return fpgaSensorReadings.VBAPWMTarget; } #endif /*********************************************************************//** * @brief * The checkFPGACommFailure function increments the FPGA comm failure * windowed timer and returns whether or not the number of failures in * the window have been reached. * @details Inputs: ms counter * @details Outputs: none * @return none *************************************************************************/ void checkFPGACommFailure( void ) { if ( getMSTimerCount() > MIN_POWER_ON_TIME_FOR_COMM_FAILS ) { if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES ) ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_FPGA_COMM_TIMEOUT, MAX_FPGA_COMM_FAILURES, (U32)fpgaSensorReadings.errorCountProcessor ) } } } /*********************************************************************//** * @brief * The checkFPGAFEOEFailure function increments the FPGA comm failure * windowed timer if an FE or OE error has occurred and returns whether * or not the number of failures in * the window have been reached. * @details Inputs: none * @details Outputs: none * @return TRUE if windowed count exceeded, else false. *************************************************************************/ BOOL checkFPGAFEOEFailure( void ) { BOOL status = false; BOOL FPGAFEOEError = getSci2FEOEError(); if ( TRUE == FPGAFEOEError) { if ( getMSTimerCount() > MIN_POWER_ON_TIME_FOR_COMM_FAILS ) { if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES ) ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_FPGA_COMM_TIMEOUT, MAX_FPGA_COMM_FAILURES, (U32)fpgaSensorReadings.errorCountProcessor ) status = TRUE; } } } return status; } /**@}*/