Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r2cc4f0cfc6512c942864d7d302cef5df375a2081 -rb7764e26a3460652da29b1f957706dfaca413226 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 2cc4f0cfc6512c942864d7d302cef5df375a2081) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision b7764e26a3460652da29b1f957706dfaca413226) @@ -81,10 +81,15 @@ #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_FLUIDLEAK_STATE_MASK 0x0040 ///< Bit mask for fluid leak detector. +#define FPGA_FLUID_LEAK_STATE_MASK 0x0040 ///< Bit mask for fluid leak detector. +#define FPGA_BLOOD_LEAK_STATUS_MASK 0x1000 ///< Bit mask for blood leak detector. +#define FPGA_BLOOD_LEAK_ZERO_STATE_MASK 0x2000 ///< Bit mask for blood leak detector zero. + +#define FPGA_BLOOD_LEAK_ZERO_CMD 0x02 ///< Bit for blood leak detector zero command. +#define FPGA_BLOOD_LEAK_SELF_TEST_CMD 0x01 ///< Bit for blood leak detector self test command. + #define FPGA_ADA_INPUT_STATUS_MASK 0x0001 ///< Bit mask for arterial air bubble detector input status. #define FPGA_ADV_INPUT_STATUS_MASK 0x0002 ///< Bit mask for venous air bubble detector input status. -#define FPGA_BLOOD_LEAK_STATUS_MASK 0x1000 ///< Bit mask for blood leak detector status. // FPGA Sensors Record #pragma pack(push,1) @@ -104,7 +109,7 @@ } FPGA_HEADER_T; // Read only on FPGA /// Record structure for FPGA continuous priority reads. -typedef struct // TODO - add all sensor readings to this structure per FPGA register map +typedef struct { U08 errorCountProcessor; ///< Reg 256. TBD. U08 errorCountPC; ///< Reg 257. TBD. @@ -170,13 +175,15 @@ 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 VSparePWMTarget; ///< Reg 378. PWM target duty cycle for Vspare pinch valve. - U16 SyringePumpStatus; ///< Reg 380. Syringe pump status register - U16 SyringePumpEncStatus; ///< Reg 382. Syringe pump encoder status - U32 SyringePumpEncPosition; ///< Reg 384. Syringe pump encoder position - U16 sPumpAdcDataReadChannel0; ///< Reg 388. - U16 sPumpAdcDataReadCh1; ///< Reg 390. - U16 sPumpAdcDataReadCh2; ///< Reg 392. - U16 sPumpAdcDataReadCh3; ///< Reg 394. + 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) @@ -190,7 +197,7 @@ } FPGA_SENSORS_T; /// Record structure for FPGA continuous priority writes. -typedef struct // TODO - add all actuator set points to this structure per FPGA register map +typedef struct { U08 fpgaSensorTest; ///< Reg 11. Blood leak and bubble detector sensor test register. U16 fpgaPIDControl; ///< Reg 12. Valve PID enables. @@ -204,12 +211,16 @@ 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 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. } FPGA_ACTUATORS_T; // TODO clean up the struct /// Record structure for FPGA async (as needed) reads. -typedef struct // TODO - add all sensor readings to this structure per FPGA register map +typedef struct { U16 fpgaDieTemp; ///< Reg 512. Internal FPGA die temperature. U16 fpgaADCVccVoltage; ///< Reg 514. Internal FPGA Vcc voltage. @@ -303,7 +314,7 @@ 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 + fpgaActuatorSetPoints.alarmControl = (U08)MIN_ALARM_VOLUME_ATTENUATION << 2; // Start alarm audio volume at maximum // Initialize fpga comm buffers memset( &fpgaWriteCmdBuffer, 0, FPGA_WRITE_CMD_BUFFER_LEN ); @@ -486,8 +497,6 @@ fpgaState = handleFPGAReceiveHeaderState(); break; - // TODO - sensor/ADC init/configuration states - case FPGA_STATE_RCV_ALL_SENSORS: fpgaState = handleFPGAReceiveAllSensorsState(); break; @@ -540,8 +549,6 @@ fpgaState = handleFPGAReadHeaderState(); break; - // TODO - sensor/ADC init/configuration states - case FPGA_STATE_WRITE_ALL_ACTUATORS: fpgaState = handleFPGAWriteAllActuatorsState(); break; @@ -1078,15 +1085,15 @@ U08 audioCmd = (U08)state; audioCmd |= ( (U08)volumeLevel << 2 ); - fpgaActuatorSetPoints.AlarmControl = audioCmd; + fpgaActuatorSetPoints.alarmControl = audioCmd; } else { U08 audioCmd = (U08)ALARM_PRIORITY_HIGH; // Set alarm audio to high priority, max volume for safety since s/w seems to be having trouble setting audio correctly audioCmd |= ( (U08)MIN_ALARM_VOLUME_ATTENUATION << 2 ); - fpgaActuatorSetPoints.AlarmControl = audioCmd; + fpgaActuatorSetPoints.alarmControl = audioCmd; // S/w fault to indicate issue w/ s/w SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_FPGA_INVALID_ALARM_AUDIO_PARAM, volumeLevel ) @@ -1333,6 +1340,184 @@ /*********************************************************************//** * @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 getFPGAAccelAxes function gets the accelerometer axis readings. * Axis readings are in ADC counts. 0.004 g per LSB. * @details Inputs: fpgaSensorReadings @@ -1414,7 +1599,7 @@ { U16 const status = fpgaSensorReadings.fpgaGPIO & FPGA_ADA_INPUT_STATUS_MASK; - return ( 0 == status ? FALSE : TRUE ); + return ( 0 == status ? TRUE : FALSE ); } /*********************************************************************//** @@ -1434,34 +1619,6 @@ /*********************************************************************//** * @brief - * The setFPGASensorTest function sets the sensor test output. - * @details Inputs: fpgaActuatorSetPoints - * @details Outputs: fpgaActuatorSetPoints - * @param sensorTest - * @return none - *************************************************************************/ -void setFPGASensorTest( U08 sensorTest ) -{ - fpgaActuatorSetPoints.fpgaSensorTest = sensorTest; -} - -/*********************************************************************//** - * @brief - * The getFPGABloodLeakDetectorStatus function gets the latest blood leak - * detector status. - * @details Inputs: fpgaSensorReadings - * @details Outputs: none - * @return TRUE if blood leak is detected, otherwise FALSE - *************************************************************************/ -BOOL getFPGABloodLeakDetectorStatus( void ) -{ - U16 const status = fpgaSensorReadings.fpgaGPIO & FPGA_BLOOD_LEAK_STATUS_MASK; - - return ( 0 == status ? FALSE : TRUE ); -} - -/*********************************************************************//** - * @brief * The getDoorState function gets the current state of door switch. * @details Inputs: none * @details Outputs: none @@ -1502,21 +1659,103 @@ /*********************************************************************//** * @brief - * The noFluidLeakDetected function returns TRUE if no fluid leak has been + * 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 noFluidLeakDetected + * @return noFPGAFluidLeakDetected *************************************************************************/ BOOL noFPGAFluidLeakDetected( void ) { - U16 noFluidLeakDetected = fpgaSensorReadings.fpgaGPIO & FPGA_FLUIDLEAK_STATE_MASK; + U16 noFPGAFluidLeakDetected = fpgaSensorReadings.fpgaGPIO & FPGA_FLUID_LEAK_STATE_MASK; - return ( 0 == noFluidLeakDetected ? FALSE : TRUE ); + return ( 0 == noFPGAFluidLeakDetected ? FALSE : TRUE ); } /*********************************************************************//** * @brief + * The noFPGABloodLeakDetected function returns TRUE if no blood leak has been + * detected and FALSE if a blood leak has been detected. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return noFPGABloodLeakDetected + *************************************************************************/ +BOOL noFPGABloodLeakDetected( void ) +{ + U16 noFPGABloodLeakDetected = fpgaSensorReadings.fpgaGPIO & FPGA_BLOOD_LEAK_STATUS_MASK; + + return ( 0 == noFPGABloodLeakDetected ? TRUE : FALSE ); +} + +/*********************************************************************//** + * @brief + * The FPGABloodLeakZeroDetected function returns TRUE if blood leak zeroing has + * been detected and FALSE if no blood leak zeroing has been detected. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGABloodLeakZeroDetected + *************************************************************************/ +BOOL FPGABloodLeakZeroDetected( void ) +{ + U16 FPGABloodLeakZeroDetected = fpgaSensorReadings.fpgaGPIO & FPGA_BLOOD_LEAK_ZERO_STATE_MASK; + + return ( 0 == FPGABloodLeakZeroDetected ? FALSE : TRUE ); +} + +/*********************************************************************//** + * @brief + * The setFPGABloodLeakZero function sets the Blood Leak detector into + * zeroing mode via the FPGA. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGABloodLeakZeroDetected + *************************************************************************/ +void setFPGABloodLeakZero( void ) +{ + fpgaActuatorSetPoints.fpgaSensorTest |= FPGA_BLOOD_LEAK_ZERO_CMD; +} + +/*********************************************************************//** + * @brief + * The clearFPGABloodLeakZero function clears the Blood Leak detector from + * zeroing mode via the FPGA. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return none + *************************************************************************/ +void clearFPGABloodLeakZero( void ) +{ + fpgaActuatorSetPoints.fpgaSensorTest &= ~FPGA_BLOOD_LEAK_ZERO_CMD; +} + +/*********************************************************************//** + * @brief + * The setFPGABloodLeakSelfTest function sets the Blood Leak detector into + * self-test mode via the FPGA. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGABloodLeakZeroDetected + *************************************************************************/ +void setFPGABloodLeakSelfTest( void ) +{ + fpgaActuatorSetPoints.fpgaSensorTest |= FPGA_BLOOD_LEAK_SELF_TEST_CMD; +} + +/*********************************************************************//** + * @brief + * The clearFPGABloodLeakSelfTest function clears the Blood Leak detector from + * self-test mode via the FPGA. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return none + *************************************************************************/ +void clearFPGABloodLeakSelfTest( void ) +{ + fpgaActuatorSetPoints.fpgaSensorTest &= ~FPGA_BLOOD_LEAK_SELF_TEST_CMD; +} + +/*********************************************************************//** + * @brief * The setValveDialyzerInletPosition function sets the position of VDi * in counts * @details Inputs: fpgaActuatorSetPoints