Index: firmware/App/Services/FpgaTD.c =================================================================== diff -u -r3518e8a088c32e75c0c8960d5e629a7401095feb -r961784c895cb8f551a2623cd02dcbfe42d04b7c2 --- firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 3518e8a088c32e75c0c8960d5e629a7401095feb) +++ firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 961784c895cb8f551a2623cd02dcbfe42d04b7c2) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2024 Diality Inc. - All Rights Reserved. +* Copyright (c) 2024-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 +* @date (last) 30-Jul-2024 * -* @author (original) Dara Navaei -* @date (original) 05-Nov-2019 +* @author (original) Sean Nash +* @date (original) 30-Jul-2024 * ***************************************************************************/ @@ -37,17 +37,19 @@ // ********** private definitions ********** -#define FPGA_EXPECTED_ID 0x5A ///< Expected ID for HD FPGA. +#define FPGA_EXPECTED_ID 0x03 ///< Expected ID for TD 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 -#define FPGA_FLUID_LEAK_STATE_MASK 0x0040 ///< Bit mask for fluid leak detector. +#define FPGA_H4_ENABLE_BIT_MASK 0x01 ///< Bit mask for enabling the blood pump. +#define FPGA_H4_DIRECTION_REV_BIT_MASK 0x02 ///< Bit mask for setting the blood pump direction. +#define FPGA_H4_HOME_BIT_MASK 0x04 ///< Bit mask for requesting a blood pump home operation. -#define FPGA_VALVES_MIN_PWM_MODE_COUNT 2500 ///< FPGA valves minimum PWM in PWM mode in counts. +#define FPGA_H13_OPEN_BIT_MASK 0x01 ///< Bit mask for setting H13 valve position to open. #define FPGA_INPUT_VOLTAGE_SCALE 3.0F ///< FPGA source and aux voltage. #define FPGA_PVN_VOLTAGE_SCALE 1.0F ///< FPGA pvn voltage. @@ -57,172 +59,108 @@ #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 H9_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 FPGA_AIRTRAP_LEVEL_LOW_MASK 0x0008 ///< Bit mask for air trap lower level sensor. -#define FPGA_AIRTRAP_LEVEL_HIGH_MASK 0x0004 ///< Bit mask for air trap upper level sensor. +#define FPGA_AIRTRAP_LEVEL_LOW_H17_MASK 0x0008 ///< Bit mask for air trap lower level sensor. +#define FPGA_AIRTRAP_LEVEL_HIGH_H16_MASK 0x0004 ///< Bit mask for air trap upper level sensor. -#define FPGA_ADA_BUBBLE_STATUS_MASK 0x0001 ///< Bit mask for arterial air bubble detector input status. -#define FPGA_ADV_BUBBLE_STATUS_MASK 0x0002 ///< Bit mask for venous air bubble detector input status. -#define FPGA_ADA_BUBBLE_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_H18_BUBBLE_STATUS_MASK 0x0002 ///< Bit mask for venous air bubble detector input status. +#define FPGA_H18_BUBBLE_SELF_TEST_CMD 0x08 ///< Bit for venous air bubble detector self-test command. -#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. - // 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 + U16 fpgaGenWrRd; ///< Reg 256. FPGA general read-back register (mirrored from a general write register in write page at addr 4). + U08 errorCountProcessor; ///< Reg 258. Error count for processor communications. + U08 errorCountPC; ///< Reg 259. Error count for TBD. + U08 sPumpDACRdStatus; ///< Reg 260. Syringe pump DAC read status. + U08 BPHallStatus; ///< Reg 261. BP hall sensor status. + U16 sPumpDACSet; ///< Reg 262. Syringe pump DAC setting. + U16 sPumpDACEEProm; ///< Reg 264. Syringe pump DAC EEProm data. + U16 h14Pressure; ///< Reg 266. H14 raw pressure data. + S16 h14Temperature; ///< Reg 268. H14 raw temperature data. + U08 h14ReadCount; ///< Reg 270. H14 read count. + U08 h14ErrorCount; ///< Reg 271. H14 error count. + U16 h2Pressure; ///< Reg 272. H2 raw pressure data. + S16 h2Temperature; ///< Reg 274. H2 raw temperature data. + U08 h2ReadCount; ///< Reg 276. H2 read count. + U08 h2ErrorCount; ///< Reg 277. H2 error count. + S16 H1CmdPosition; ///< Reg 278. H1 commanded position (200 steps/rev). + S16 H1EncPosition; ///< Reg 280. H1 encoder position (1024 counts/rev). + U08 H1Status; ///< Reg 282. H1 status. + U08 reserved4; ///< Reg 283. Reserved and available for future use. + U08 BEMStatus; ///< Reg 284. BEM status. + U08 BEMEncStatus; ///< Reg 285. BEM encoder status. + S32 BEMEncPosition; ///< Reg 286. BEM encoder position. + S16 H4Period; ///< Reg 290. H4 measured period (10 uSec). + S16 H4Torque; ///< Reg 292. H4 measured torque. + S16 H4SpeedFromHall; ///< Reg 294. H4 measured speed from hall sensor(s). + S16 H19CmdPosition; ///< Reg 296. H19 commanded position (200 steps/rev). + S16 H19EncPosition; ///< Reg 298. H19 encoder position (1024 counts/rev). + U08 H19Status; ///< Reg 300. H19 status. + U08 BPStatus; ///< Reg 301. BP status. + U16 GPIOReg; ///< Reg 302. GPIO register. + U08 HEPStatus; ///< Reg 304. HEP status register. + U08 HEPAdcReadCount; ///< Reg 305. HEP ADC read counter. + U08 HEPAdcDacStatus; ///< Reg 306. HEP ADC/DAC status register. + U08 HEPEncStatus; ///< Reg 307. HEP encoder status register. + S32 HEPEncPosition; ///< Reg 308. HEP encoder position. + U16 HEPAdcCh0; ///< Reg 312. HEP ADC channel 0 reading. + U16 HEPAdcCh1; ///< Reg 314. HEP ADC channel 1 reading. + U16 HEPAdcCh2; ///< Reg 316. HEP ADC channel 2 reading. + U16 HEPAdcCh3; ///< Reg 318. HEP ADC channel 3 reading. + U16 fpgaAdcTemperature; ///< Reg 320. FPGA ADC temperature. + U16 fpga1msTimerCounter; ///< Reg 322. FPGA 1 millisecond timer counter. + U16 alarmBuzzerCurrentAdc; ///< Reg 324. Alarm buzzer current ADC reading. + U16 fpgaVccInternalAdc; ///< Reg 326. FPGA Vcc internal voltage ADC reading. + U16 fpgaCompatibilityRev; ///< Reg 328. Compatibility revision. + U08 VBTStatus; ///< Reg 330. VBT status register. + U08 VBTStatusPWM; ///< Reg 331. VBT PWM status register. + S16 ACPower1Current; ///< Reg 332. AC power current - 1. + S16 ACPower1Voltage; ///< Reg 334. AC power voltage - 1. + S16 ACPower2Current; ///< Reg 336. AC power current - 2. + S16 ACPower2Voltage; ///< Reg 338. AC power voltage - 2. + S16 ACPower3Current; ///< Reg 340. AC power current - 3. + S16 ACPower3Voltage; ///< Reg 342. AC power voltage - 3. + S32 ACHeaterTemp; ///< Reg 344. AC heater temperature. + U16 H4RotorHallSpeed; ///< Reg 348. H4 rotor speed from hall sensor. } 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. + U16 fpgaGenWrRd; ///< Reg 04. FPGA general write/read-back register (mirrored to a general read register in read page at addr 256). + U08 h13Control; ///< Reg 06. H13 valve control register. + U08 h13PWMEnable; ///< Reg 07. H13 valve PWM enable register. + U16 h13PWMLowPeriod; ///< Reg 08. H13 PWM low signal period register. + U16 h13PWMPeriod; ///< Reg 10. H13 PWM period register. + U16 h13PWMPUllInTime; ///< Reg 12. H13 PWM pull in time register. + U08 h12Control; ///< Reg 14. H12 Air pump control register. + U08 h5Control; ///< Reg 15. H5 ejector stepper motor control register. + U16 h5SetSpeed; ///< Reg 16. H5 ejector stepper motor step register. + U16 H4SetSpeed; ///< Reg 18. H4 Blood pump speed set register (RPM). + U08 H4Control; ///< Reg 20. H4 Blood pump control register. + U08 H19Control; ///< Reg 21. H19 control register. + U16 H19Position; ///< Reg 22. H19 position set register (200 steps/rev). + U16 H1Position; ///< Reg 24. H1 position set register (200 steps/rev). + U08 H1Control; ///< Reg 26. H1 control register. + U08 valveEncoderControl; ///< Reg 27. H1/H19 encoder control register. + U08 alarmControl; ///< Reg 28. Alarm audio control register. } FPGA_ACTUATORS_T; + #pragma pack(pop) // ********** private data ********** @@ -256,10 +194,9 @@ 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.VBAPWMFixed = FPGA_VALVES_MIN_PWM_MODE_COUNT; - fpgaActuatorSetPoints.VBVPWMFixed = FPGA_VALVES_MIN_PWM_MODE_COUNT; + // Set H1 and H19 to default configuration + disabled so they do not run immediately on power up + fpgaActuatorSetPoints.H1Control = FPGA_PINCH_VALVES_1_32_STEP | FPGA_PINCH_VALVES_DISABLE | FPGA_PINCH_VALVES_NOT_RESET | FPGA_PINCH_VALVES_NOT_SLEEP; + fpgaActuatorSetPoints.H19Control = FPGA_PINCH_VALVES_1_32_STEP | FPGA_PINCH_VALVES_DISABLE | FPGA_PINCH_VALVES_NOT_RESET | FPGA_PINCH_VALVES_NOT_SLEEP; // initialize FPGA comm failures windowed timer count initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES, MAX_FPGA_COMM_FAILURES, MAX_FPGA_COMM_FAILURES_WINDOW_MS); @@ -309,7 +246,7 @@ *************************************************************************/ U16 getFPGATimerCount( void ) { - return fpgaSensorReadings.fpgaTimerCount_ms; + return fpgaSensorReadings.fpga1msTimerCounter; } /*********************************************************************//** @@ -372,7 +309,7 @@ *************************************************************************/ U16 getFPGATemperature( void ) { - return fpgaSensorReadings.fpgaTemperature; + return fpgaSensorReadings.fpgaAdcTemperature; } /*********************************************************************//** @@ -384,7 +321,7 @@ *************************************************************************/ F32 getFPGAVcc( void ) { - F32 result = (F32)fpgaSensorReadings.fpgaIntVoltage * FPGA_INPUT_VOLTAGE_SCALE / (F32)BITS_12_FULL_SCALE; + F32 result = (F32)fpgaSensorReadings.fpgaVccInternalAdc * FPGA_INPUT_VOLTAGE_SCALE / (F32)BITS_12_FULL_SCALE; return result; } @@ -398,7 +335,7 @@ *************************************************************************/ F32 getFPGAVccAux( void ) { - F32 result = (F32)fpgaSensorReadings.fpgaAuxVoltage * FPGA_INPUT_VOLTAGE_SCALE / (F32)BITS_12_FULL_SCALE; + F32 result = 0.0F;//(F32)fpgaSensorReadings.fpgaAuxVoltage * FPGA_INPUT_VOLTAGE_SCALE / (F32)BITS_12_FULL_SCALE; return result; } @@ -412,7 +349,7 @@ *************************************************************************/ F32 getFPGAVpvn( void ) { - F32 result = (F32)fpgaSensorReadings.fpgaVpvn * FPGA_PVN_VOLTAGE_SCALE / (F32)BITS_12_FULL_SCALE; + F32 result = 0.0F;//(F32)fpgaSensorReadings.fpgaVpvn * FPGA_PVN_VOLTAGE_SCALE / (F32)BITS_12_FULL_SCALE; return result; } @@ -468,410 +405,256 @@ /*********************************************************************//** * @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 \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return Latest blood pump hall sensor count reading. + * The setH4Enabled function enables or disables the blood pump per + * the given flag. + * @details \b Inputs: none + * @details \b Outputs: Blood pump enabled or disabled (bit 0 of BP control register) + * @param enable TRUE if BP enable is requested, FALSE if BP disable is requested + * @return none *************************************************************************/ -U16 getFPGABloodPumpHallSensorCount( void ) +void setH4Enabled( BOOL enable ) { - return fpgaSensorReadings.bloodPumpHallSensorCount; + if ( TRUE == enable ) + { + fpgaActuatorSetPoints.H4Control |= FPGA_H4_ENABLE_BIT_MASK; + } + else + { + fpgaActuatorSetPoints.H4Control &= ~((U08)FPGA_H4_ENABLE_BIT_MASK); + } } /*********************************************************************//** * @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 \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest blood pump hall sensor status reading. - *************************************************************************/ -U08 getFPGABloodPumpHallSensorStatus( void ) -{ - return fpgaSensorReadings.bloodPumpHallSensorStatus; -} - -/*********************************************************************//** - * @brief - * The getFPGAArterialPressure function gets the latest arterial pressure reading. - * High byte indicates alarm status for ADC channel. - * @note Low 24-bits are channel reading. Subtract 2^23 from low 24 bits to get - * signed channel reading. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest arterial pressure reading - *************************************************************************/ -U32 getFPGAArterialPressure( void ) -{ - return fpgaSensorReadings.adc1Channel0; -} - -/*********************************************************************//** - * @brief - * The getFPGAArterialPressureReadCounter function gets the latest arterial - * pressure sensor read counter. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest arterial pressure sensor read counter - *************************************************************************/ -U08 getFPGAArterialPressureReadCounter( void ) -{ - return fpgaSensorReadings.adc1SequenceCount; -} - -/*********************************************************************//** - * @brief - * The getFPGAArterialPressureErrorCounter function gets the latest arterial - * pressure sensor error counter. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest arterial pressure sensor error counter - *************************************************************************/ -U08 getFPGAArterialPressureErrorCounter( void ) -{ - return fpgaSensorReadings.adc1ErrorCount; -} - -/*********************************************************************//** - * @brief - * The getFPGADVTArterialPressure function gets the latest arterial pressure reading. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest arterial pressure reading - *************************************************************************/ -U16 getFPGADVTArterialPressure( void ) -{ - return fpgaSensorReadings.arterialPressure; -} - -/*********************************************************************//** - * @brief - * The getFPGADVTArterialTemperature function gets the latest arterial pressure - * sensor temperature reading. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest arterial pressure sensor temperature reading - *************************************************************************/ -U16 getFPGADVTArterialTemperature( void ) -{ - return fpgaSensorReadings.arterialPressureTemperature; -} - -/*********************************************************************//** - * @brief - * The getFPGADVTArterialPressureReadCounter function gets the latest arterial - * pressure sensor read counter. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest arterial pressure sensor read counter - *************************************************************************/ -U08 getFPGADVTArterialPressureReadCounter( void ) -{ - return fpgaSensorReadings.arterialPressureReadCount; -} - -/*********************************************************************//** - * @brief - * The getFPGATDVTArterialPressureErrorCounter function gets the latest arterial - * pressure sensor error counter. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest 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 \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest venous pressure reading - *************************************************************************/ -U16 getFPGAVenousPressure( void ) -{ - return fpgaSensorReadings.venousPressure; -} - -/*********************************************************************//** - * @brief - * The getFPGAVenousPressureTemperature function gets the latest venous pressure - * sensor temperature reading. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest venous pressure sensor temperature reading - *************************************************************************/ -U16 getFPGAVenousPressureTemperature( void ) -{ - return fpgaSensorReadings.venousTemperature; -} - -/*********************************************************************//** - * @brief - * The getFPGAVenousPressureReadCounter function gets the latest venous pressure - * sensor read counter. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest venous pressure sensor read counter - *************************************************************************/ -U08 getFPGAVenousPressureReadCounter( void ) -{ - return fpgaSensorReadings.venousReadCounter; -} - -/*********************************************************************//** - * @brief - * The getFPGAVenousPressureErrorCounter function gets the latest venous pressure - * sensor error counter. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return latest 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. - * 0x40 - Sleep off - * 0x20 - Not reset - * 0x10 - Disable - * 0x08 - Reverse direction - * 0x01/02 - Microstep setting + * The setH4Direction function sets the direction for the blood pump + * motor to the given direction. * @details \b Inputs: none - * @details \b Outputs: fpgaActuatorSetPoints - * @param bitFlags Desired control bit settings for syringe pump + * @details \b Outputs: Blood pump motor direction is set (bit 1 of BP control register). + * 0 - CW (forward) + * 1 - CCW (reverse) + * @param dir the desired direction for the blood pump motor (fwd or rev) * @return none *************************************************************************/ -void setFPGASyringePumpControlFlags( U08 bitFlags ) +void setH4Direction( MOTOR_DIR_T dir ) { - fpgaActuatorSetPoints.syringePumpControl = bitFlags; + if ( MOTOR_DIR_REVERSE == dir ) + { + fpgaActuatorSetPoints.H4Control |= FPGA_H4_DIRECTION_REV_BIT_MASK; + } + else + { + fpgaActuatorSetPoints.H4Control &= ~((U08)FPGA_H4_DIRECTION_REV_BIT_MASK); + } } /*********************************************************************//** * @brief - * The setFPGASyringePumpADCandDACControlFlags function sets the syringe pump - * ADC/DAC control register per given bit flags. - * 0x04 - Write ADC setup - * 0x02 - Read DAC on ADC - * 0x01 - Enable DAC (not ADC) + * The homeH4 function sets the bit requesting that the blood pump + * be homed. * @details \b Inputs: none - * @details \b Outputs: fpgaActuatorSetPoints - * @param bitFlags ADC/DAC control bit settings for syringe pump + * @details \b Outputs: H4 pump home request is set (bit 2 of H4 control register). * @return none *************************************************************************/ -void setFPGASyringePumpADCandDACControlFlags( U08 bitFlags ) +void homeH4( void ) { - fpgaActuatorSetPoints.syringePumpADCandDACControl = bitFlags; + fpgaActuatorSetPoints.H4Control |= FPGA_H4_HOME_BIT_MASK; } /*********************************************************************//** * @brief - * The setFPGASyringePumpDACOutputLevel function sets the syringe pump force - * sensor DAC output level register to a given value. + * The resetH4HomeRequest function resets the fpga blood pump home + * request. + * @note This function should be called after request is made and transmission + * to FPGA is complete. * @details \b Inputs: none - * @details \b Outputs: fpgaActuatorSetPoints - * @param counts level to set syringe pump force sensor DAC to + * @details \b Outputs: H4 pump home request is cleared (bit 2 of H4 control register) * @return none *************************************************************************/ -void setFPGASyringePumpDACOutputLevel( U16 counts ) +void resetH4HomeRequest( void ) { - fpgaActuatorSetPoints.syringePumpDACOut = counts; + fpgaActuatorSetPoints.H4Control &= ~((U08)FPGA_H4_HOME_BIT_MASK); } /*********************************************************************//** * @brief - * The setFPGASyringePumpStepToggleTime function sets the syringe pump stepper - * toggle time register to a given period (in uSec). + * The setH4SetSpeed function sets the fpga blood pump set speed + * to the given speed (0..3000 RPM). * @details \b Inputs: none - * @details \b Outputs: fpgaActuatorSetPoints - * @param microSeconds toggle the stepper motor at this time interval to set pump speed + * @details \b Outputs: H4 set speed is set + * @param rpm the set point for the H4 pump speed (in RPM). * @return none *************************************************************************/ -void setFPGASyringePumpStepToggleTime( U32 microSeconds ) +void setH4SetSpeed( U16 rpm ) { - fpgaActuatorSetPoints.syringePumpStepToggleTime = microSeconds; + fpgaActuatorSetPoints.H4SetSpeed = rpm; } /*********************************************************************//** * @brief - * The getFPGASyringePumpStatus function gets the latest syringe pump status - * register reading. Bit 0 indicates a fault. + * The getH4Period function gets the latest blood pump period (in 10uSec) + * from the FPGA. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump status reading + * @return Latest blood pump period. *************************************************************************/ -U08 getFPGASyringePumpStatus( void ) +U16 getH4Period( void ) { - return fpgaSensorReadings.syringePumpStatus; + return fpgaSensorReadings.H4Period; } /*********************************************************************//** * @brief - * The getFPGASyringePumpADCReadCounter function gets the latest syringe pump - * ADC read counter. Counter is 8-bit and rolls over when exceeding 255. - * @details \b Inputs: fpgaSensorReadings + * The getBPStatus function gets the latest blood pump hall sensor status. + * Bit 0: 0=Forward pump direction detected, 1=Reverse pump direction detected + * Bit 1: 0=Correct pump direction detected, 1=Incorrect pump direction detected + * Bit 2..7: Running incorrect pump direction counter (wraps). + * @details \b Inputs: fpgaSensorReadings.BPHallStatus * @details \b Outputs: none - * @return Latest syringe pump ADC read counter + * @return Latest blood pump hall sensor status bits. *************************************************************************/ -U08 getFPGASyringePumpADCReadCounter( void ) +U08 getBPStatus( void ) { - return fpgaSensorReadings.syringePumpADCReadCounter; + return fpgaSensorReadings.BPHallStatus; } /*********************************************************************//** * @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 + * The getBloodPumpHallSensorCount 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 \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump ADC/DAC status reading + * @return Latest blood pump hall sensor count reading. *************************************************************************/ -U08 getFPGASyringePumpADCandDACStatus( void ) +U16 getBloodPumpHallSensorCount( void ) { - return fpgaSensorReadings.syringePumpADCandDACStatus; + return 0;//fpgaSensorReadings.bloodPumpHallSensorCount; } /*********************************************************************//** * @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) + * The getBloodPumpHallSensorStatus 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 \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump encoder status reading + * @return latest blood pump hall sensor status reading. *************************************************************************/ -U08 getFPGASyringePumpEncoderStatus( void ) +U08 getBloodPumpHallSensorStatus( void ) { - return fpgaSensorReadings.syringePumpEncoderStatus; + return 0;//fpgaSensorReadings.bloodPumpHallSensorStatus; } /*********************************************************************//** * @brief - * The getFPGASyringePumpEncoderPosition function gets the latest syringe pump - * encoder position reading. + * The getH2Pressure function gets the latest arterial 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 \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump encoder position reading + * @return latest arterial pressure reading *************************************************************************/ -U32 getFPGASyringePumpEncoderPosition( void ) +U16 getH2Pressure( void ) { - return fpgaSensorReadings.syringePumpEncPosition; + return fpgaSensorReadings.h2Pressure; } /*********************************************************************//** * @brief - * The getFPGASyringePumpADCChannel0 function gets the latest syringe pump ADC - * channel 0 register reading (syringe pump force sensor). + * The getH2Temperature function gets the latest arterial pressure + * sensor temperature reading. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump ADC channel 0 reading + * @return latest arterial pressure sensor temperature reading *************************************************************************/ -U16 getFPGASyringePumpADCChannel0( void ) +S16 getH2Temperature( void ) { - return fpgaSensorReadings.syringePumpAdcDataReadCh0; + return fpgaSensorReadings.h2Temperature; } /*********************************************************************//** * @brief - * The getFPGASyringePumpADCChannel1 function gets the latest syringe pump ADC - * channel 1 register reading (syringe detection switch). + * The getH2ReadCounter function gets the latest arterial + * pressure sensor read counter. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump ADC channel 1 reading + * @return latest arterial pressure sensor read counter *************************************************************************/ -U16 getFPGASyringePumpADCChannel1( void ) +U08 getH2ReadCounter( void ) { - return fpgaSensorReadings.syringePumpAdcDataReadCh1; + return fpgaSensorReadings.h2ReadCount; } /*********************************************************************//** * @brief - * The getFPGASyringePumpADCChannel2 function gets the latest syringe pump ADC - * channel 2 register reading (syringe pump home position sensor). + * The getH2ErrorCounter function gets the latest arterial + * pressure sensor error counter. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump ADC channel 2 reading + * @return latest arterial pressure sensor error counter *************************************************************************/ -U16 getFPGASyringePumpADCChannel2( void ) +U08 getH2ErrorCounter( void ) { - return fpgaSensorReadings.syringePumpAdcDataReadCh2; + return fpgaSensorReadings.h2ErrorCount; } /*********************************************************************//** * @brief - * The getFPGASyringePumpADCChannel3 function gets the latest syringe pump ADC - * channel 3 register reading. + * The getH14Pressure 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 \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump ADC channel 3 reading + * @return latest venous pressure reading *************************************************************************/ -U16 getFPGASyringePumpADCChannel3( void ) +U16 getH14Pressure( void ) { - return fpgaSensorReadings.syringePumpAdcDataReadCh3; + return fpgaSensorReadings.h14Pressure; } /*********************************************************************//** * @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 + * The getH14Temperature function gets the latest venous pressure + * sensor temperature reading. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump DAC status reading + * @return latest venous pressure sensor temperature reading *************************************************************************/ -U08 getFPGASyringePumpDACStatus( void ) +S16 getH14Temperature( void ) { - return fpgaSensorReadings.sPumpDACRdStatus; + return fpgaSensorReadings.h14Temperature; } /*********************************************************************//** * @brief - * The getFPGASyringePumpDACSetting function gets the latest syringe pump - * DAC setting. + * The getH14ReadCounter function gets the latest venous pressure + * sensor read counter. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump DAC setting + * @return latest venous pressure sensor read counter *************************************************************************/ -U16 getFPGASyringePumpDACSetting( void ) +U08 getH14ReadCounter( void ) { - return fpgaSensorReadings.sPumpDACSet; + return fpgaSensorReadings.h14ReadCount; } /*********************************************************************//** * @brief - * The getFPGASyringePumpDACStoredSetting function gets the latest syringe - * pump DAC setting stored in sensor's EEPROM. + * The getH14ErrorCounter function gets the latest venous pressure + * sensor error counter. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest syringe pump DAC setting stored in EEPROM + * @return latest venous pressure sensor error counter *************************************************************************/ -U16 getFPGASyringePumpDACStoredSetting( void ) +U08 getH14ErrorCounter( void ) { - return fpgaSensorReadings.sPumpDACEEProm; + return fpgaSensorReadings.h14ErrorCount; } /*********************************************************************//** @@ -884,7 +667,7 @@ *************************************************************************/ F32 getFPGABackupAlarmAudioCurrent( void ) { - U16 adcCnts = fpgaSensorReadings.backupAlarmAudioPeakCurrent; + U16 adcCnts = fpgaSensorReadings.alarmBuzzerCurrentAdc; F32 result = ( ( (F32)adcCnts / (F32)BITS_12_FULL_SCALE ) * FPGA_BACKUP_ALARM_AUDIO_CONVERT ) * (F32)MA_PER_AMP; return result; @@ -900,73 +683,54 @@ *************************************************************************/ void getFPGAAirTrapLevels( BOOL *airAtLower, BOOL *airAtUpper ) { - U16 fpgaGPIO = fpgaSensorReadings.fpgaGPIO; - U16 lower = fpgaGPIO & FPGA_AIRTRAP_LEVEL_LOW_MASK; - U16 upper = fpgaGPIO & FPGA_AIRTRAP_LEVEL_HIGH_MASK; + U16 fpgaGPIO = fpgaSensorReadings.GPIOReg; + U16 lower = fpgaGPIO & FPGA_AIRTRAP_LEVEL_LOW_H17_MASK; + U16 upper = fpgaGPIO & FPGA_AIRTRAP_LEVEL_HIGH_H16_MASK; *airAtLower = ( 0 == lower ? FALSE : TRUE ); *airAtUpper = ( 0 == upper ? FALSE : TRUE ); } /*********************************************************************//** * @brief - * The setFPGAValvesControlMode function sets the valves control mode. + * The setH13ValveState function sets the command position for H13 valve. + * @note VBTControl register bit 0 will drive state of H13 valve (0=closed, 1=open). * @details \b Inputs: fpgaActuatorSetPoints * @details \b Outputs: fpgaActuatorSetPoints - * @param bits : The bits to enable the PID controller of a valve + * @param state : The valve state to command H13 valve to * @return none *************************************************************************/ -void setFPGAValvesControlMode( U16 bits ) +void setH13ValveState( OPN_CLS_STATE_T state ) { - fpgaActuatorSetPoints.fpgaPIDControl = bits; + if ( STATE_OPEN == state ) + { + fpgaActuatorSetPoints.h13Control |= FPGA_H13_OPEN_BIT_MASK; + } + else + { + fpgaActuatorSetPoints.h13Control &= ~((U08)FPGA_H13_OPEN_BIT_MASK); + } } /*********************************************************************//** * @brief - * The getValvesStatus function reads the status of the valves. + * The H18BubbleDetected function determines whether H18 bubble detector + * sensor is currently detecting a bubble. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest status of the valves + * @return TRUE if latest H18 reading shows bubble detected, FALSE if not *************************************************************************/ -U16 getFPGAValvesStatus( void ) +BOOL H18BubbleDetected( void ) { - return fpgaSensorReadings.valveStatus; -} + U16 noBubbleDetected = 0; -/*********************************************************************//** - * @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 \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return Latest fluid leak detected status - *************************************************************************/ -BOOL noFPGAFluidLeakDetected( void ) -{ - U16 noFPGAFluidLeakDetected = fpgaSensorReadings.fpgaGPIO & FPGA_FLUID_LEAK_STATE_MASK; + noBubbleDetected = fpgaSensorReadings.GPIOReg & FPGA_H18_BUBBLE_STATUS_MASK; - return ( 0 == noFPGAFluidLeakDetected ? FALSE : TRUE ); + return ( 0 == noBubbleDetected ? TRUE : FALSE ); } /*********************************************************************//** * @brief - * The noFPGAVenousBubbleDetected function returns TRUE if no air bubble has - * been detected and FALSE if an air bubble has been detected. - * @details \b Inputs: fpgaSensorReadings - * @details \b Outputs: none - * @return Latest bubble detected status - *************************************************************************/ -BOOL noFPGAVenousBubbleDetected( void ) -{ - U16 noFPGABubbleDetected = 0; - - noFPGABubbleDetected = fpgaSensorReadings.fpgaGPIO & FPGA_ADV_BUBBLE_STATUS_MASK; - - return ( 0 != noFPGABubbleDetected ? TRUE : FALSE ); -} - -/*********************************************************************//** - * @brief * The setFPGAVenousBubbleSelfTest function sets the given air bubble detector into * self-test mode via the FPGA. * @details \b Inputs: none @@ -975,7 +739,7 @@ *************************************************************************/ void setFPGAVenousBubbleSelfTest( void ) { - fpgaActuatorSetPoints.fpgaSensorTest |= FPGA_ADV_BUBBLE_SELF_TEST_CMD; +// fpgaActuatorSetPoints.sensorTest |= FPGA_ADV_BUBBLE_SELF_TEST_CMD; } /*********************************************************************//** @@ -988,138 +752,239 @@ *************************************************************************/ void clearFPGAVenousBubbleSelfTest( void ) { - fpgaActuatorSetPoints.fpgaSensorTest &= ~FPGA_ADV_BUBBLE_SELF_TEST_CMD; +// fpgaActuatorSetPoints.sensorTest &= ~FPGA_ADV_BUBBLE_SELF_TEST_CMD; } /*********************************************************************//** * @brief - * The setValveBloodVenousPosition function sets the position of VBV - * in counts + * The setH19Control function sets the control bits for the venous pinch valve. + * Microstep setting: bits 0..2: + * 0=full step (100% torque) + * 1=1/2 step (100% torque) + * 2=1/16 step + * 3=1/32 step + * 4=full step (modified) + * 5=1/2 step (modified) + * 6=1/4 step + * 7=1/8 step + * Direction: bit 3 + * 0=forward + * 1=reverse + * Enable: bit 4 (active low) + * 0=enabled + * 1=disabled + * Reset: bit 5 (active low) + * 0=reset (set to 1 after power up) + * Sleep: bit 6 (active low) + * 0=sleep mode + * Reserved: bit 7 * @details \b Inputs: none * @details \b Outputs: fpgaActuatorSetPoints - * @param setPoint The next encoder position of the valve in counts + * @param controlBits The control bits to apply to the venous pinch valve. * @return none *************************************************************************/ -void setFPGAValveBloodVenousPosition( S16 setPoint ) +void setH19Control( U08 controlBits ) { - fpgaActuatorSetPoints.VBVSetPoint = setPoint; + fpgaActuatorSetPoints.H19Control = controlBits; } /*********************************************************************//** * @brief - * The getValveBloodVenousPosition function returns the current position - * of VBV in counts + * The getH19Control function gets the current control bits for the H19 valve. + * @details \b Inputs: fpgaActuatorSetPoints + * @details \b Outputs: none + * @return fpgaActuatorSetPoints.H19Control + *************************************************************************/ +U08 getH19Control( void ) +{ + return fpgaActuatorSetPoints.H19Control; +} + +/*********************************************************************//** + * @brief + * The setH19Position function sets the travel from current position for the + * H19 valve in counts (or microcounts if microstepping is set in control register). + * @details \b Inputs: none + * @details \b Outputs: fpgaActuatorSetPoints + * @param setPoint The target encoder position of the H19 valve in counts + * @return none + *************************************************************************/ +void setH19Position( U16 setPoint ) +{ + fpgaActuatorSetPoints.H19Position = setPoint; +} + +/*********************************************************************//** + * @brief + * The getH19EncoderPosition function reads the current encoder position of the + * H19 valve in counts. + * @note There are 1024 encoder counts per revolution. The encoder position + * register provides the number of steps traveled since last command given. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return The current encoder position of VBV + * @return The current encoder position of H19 valve *************************************************************************/ -S16 getFPGAValveBloodVenousPosition( void ) +S16 getH19EncoderPosition( void ) { - return fpgaSensorReadings.VBVPosition; + return fpgaSensorReadings.H19EncPosition; } /*********************************************************************//** * @brief - * The getFPGAValveBloodVenousCurrentCounts function returns the current - * of VBV in counts + * The getH19CmdPosition function returns the current amount of travel + * from the pre-command position in steps (or microsteps if microstepping is + * set in control register) for H19 valve. + * @note There are 200 steps per revolution * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return The latest current of VBV + * @return The commanded encoder position of H19 valve *************************************************************************/ -U16 getFPGAValveBloodVenousCurrentCounts( void ) +S16 getH19CmdPosition( void ) { - return fpgaSensorReadings.VBVCurrent; + return fpgaSensorReadings.H19CmdPosition; } -#ifdef DEBUG_ENABLED /*********************************************************************//** * @brief - * The setFPGAValveBloodVenousPWM function sets the PWM of VBV in counts. + * The getH19Status function reads the status of the venous pinch valve. + * @details \b Inputs: fpgaSensorReadings + * @details \b Outputs: none + * @return Latest status of the venous pinch valve + *************************************************************************/ +U16 getH19Status( void ) +{ + return fpgaSensorReadings.H19Status; +} + +/*********************************************************************//** + * @brief + * The setH1Control function sets the control bits for the arterial pinch valve. + * Microstep setting: bits 0..2: + * 0=full step (100% torque) + * 1=1/2 step (100% torque) + * 2=1/16 step + * 3=1/32 step + * 4=full step (modified) + * 5=1/2 step (modified) + * 6=1/4 step + * 7=1/8 step + * Direction: bit 3 + * 0=forward + * 1=reverse + * Enable: bit 4 (active low) + * 0=enabled + * 1=disabled + * Reset: bit 5 (active low) + * 0=reset (set to 1 after power up) + * Sleep: bit 6 (active low) + * 0=sleep mode + * Reserved: bit 7 * @details \b Inputs: none * @details \b Outputs: fpgaActuatorSetPoints - * @param count PWM counts to set for VBV + * @param controlBits The control bits to apply to the arterial pinch valve. * @return none *************************************************************************/ -void setFPGAValveBloodVenousPWM( U16 count ) +void setH1Control( U08 controlBits ) { - fpgaActuatorSetPoints.VBVPWMFixed = count; + fpgaActuatorSetPoints.H1Control = controlBits; } /*********************************************************************//** * @brief - * The getFPGAValveBloodVenousPWM function returns the PWM of VBV in counts. + * The getH1Control function gets the current control bits for the H1 valve. * @details \b Inputs: fpgaActuatorSetPoints * @details \b Outputs: none - * @return The PWM counts for VBV + * @return fpgaActuatorSetPoints.H1Control *************************************************************************/ -U16 getFPGAValveBloodVenousPWM( void ) +U08 getH1Control( void ) { - return fpgaSensorReadings.VBVPWMTarget; + return fpgaActuatorSetPoints.H1Control; } -#endif /*********************************************************************//** * @brief - * The setValveBloodArterialPosition function sets the position of VBA - * in counts + * The setH1Position function sets the travel from current position for the + * H1 valve in counts (or microcounts if microstepping is set in control register). * @details \b Inputs: none * @details \b Outputs: fpgaActuatorSetPoints - * @param setPoint The next position of the valve in counts + * @param setPoint The target encoder position of the H1 valve in counts * @return none *************************************************************************/ -void setFPGAValveBloodArterialPosition( S16 setPoint ) +void setH1Position( U16 setPoint ) { - fpgaActuatorSetPoints.VBASetPoint = setPoint; + fpgaActuatorSetPoints.H1Position = setPoint; } /*********************************************************************//** * @brief - * The getValveBloodArterialPosition function reads the current position - * of VBA in counts + * The getH1EncoderPosition function reads the current encoder position of the + * H1 valve in counts. + * @note There are 1024 encoder counts per revolution * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return The latest encoder position of VBA + * @return The latest encoder position of H1 valve *************************************************************************/ -S16 getFPGAValveBloodArterialPosition( void ) +S16 getH1EncoderPosition( void ) { - return fpgaSensorReadings.VBAPosition; + return fpgaSensorReadings.H1EncPosition; } /*********************************************************************//** * @brief - * The getFPGAValveBloodArterialCurrentCounts function reads the current - * of VBA in counts + * The getH1CmdPosition function returns returns the current amount of travel + * from the pre-command position in steps (or microsteps if microstepping is + * set in control register) for H1 valve. + * @note There are 200 steps per revolution * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return The latest current of VBA + * @return The commanded encoder position of H1 valve *************************************************************************/ -U16 getFPGAValveBloodArterialCurrentCounts( void ) +S16 getH1CmdPosition( void ) { - return fpgaSensorReadings.VBACurrent; + return fpgaSensorReadings.H1CmdPosition; } /*********************************************************************//** * @brief + * The getH1Status function reads the status of the arterial pinch valve. + * @details \b Inputs: fpgaSensorReadings + * @details \b Outputs: none + * @return Latest status of the arterial pinch valve + *************************************************************************/ +U16 getH1Status( void ) +{ + return fpgaSensorReadings.H1Status; +} + +/*********************************************************************//** + * @brief * The getFPGABoardTemperature function reads the FPGA board temperature. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none * @return The latest FPGA board temperature in ADC counts *************************************************************************/ U16 getFPGABoardTemperature( void ) { - return fpgaSensorReadings.fpgaTemperature; + return fpgaSensorReadings.fpgaAdcTemperature; } /*********************************************************************//** * The getFPGAFrontDoorStatus function returns the FPGA front door status * bit (0x10). * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return front door FPGA status bit (0x10 = Open, 0x00 = Closed) + * @return TRUE if front door is closed, FALSE if not. *************************************************************************/ -U16 getFPGAFrontDoorStatus( void ) +BOOL getFPGAFrontDoorClosedStatus( void ) { - return ( fpgaSensorReadings.fpgaGPIO & FRONT_DOOR_SWITCH_MASK ); + BOOL result = TRUE; + + if ( ( fpgaSensorReadings.GPIOReg & H9_SWITCH_MASK ) != 0 ) + { + result = FALSE; + } + + return result; } /*********************************************************************//** @@ -1131,7 +996,7 @@ *************************************************************************/ U32 getFPGAPBAADCTemperature( void ) { - return fpgaSensorReadings.adc1Channel1; + return fpgaSensorReadings.h2Temperature; } /*********************************************************************//** @@ -1143,7 +1008,7 @@ *************************************************************************/ U16 getFPGAInletFan1TogglePeriod( void ) { - return fpgaSensorReadings.fan1PulseTime; + return 0;//fpgaSensorReadings.fan1PulseTime; } /*********************************************************************//**