Index: firmware/App/Services/FpgaTD.c =================================================================== diff -u -r036a75d76ab01912646a480b935d97187a231a19 -r50f4b79164155c1bc375dd3ff0e8588f934dc729 --- firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 036a75d76ab01912646a480b935d97187a231a19) +++ firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 50f4b79164155c1bc375dd3ff0e8588f934dc729) @@ -47,7 +47,6 @@ #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_H13_OPEN_BIT_MASK 0x01 ///< Bit mask for setting H13 valve position to open. #define FPGA_H20_OPEN_BIT_MASK 0x02 ///< Bit mask for setting H20 valve position to open. @@ -60,15 +59,27 @@ #define FPGA_BACKUP_ALARM_AUDIO_CONVERT 0.4F ///< Converts backup (piezo) alarm audio ADC volts to amps. -#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 H9_SWITCH_MASK 0x0001 ///< Front door switch bit mask. Bit 0 of the GPIO register. #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_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. +/// Control bits to run syringe pump in reverse direction // TODO - move to syringe pump controller unit when implemented. +static const U08 SYRINGE_PUMP_CONTROL_RUN_REVERSE = SYRINGE_PUMP_CONTROL_SLEEP_OFF | + SYRINGE_PUMP_CONTROL_NOT_RESET | + SYRINGE_PUMP_CONTROL_ENABLE | + SYRINGE_PUMP_CONTROL_REVERSE_DIR | + SYRINGE_PUMP_CONTROL_32TH_STEP; +/// Control bits to run syringe pump in forward direction // TODO - move to syringe pump controller unit when implemented. +static const U08 SYRINGE_PUMP_CONTROL_RUN_FORWARD = SYRINGE_PUMP_CONTROL_SLEEP_OFF | + SYRINGE_PUMP_CONTROL_NOT_RESET | + SYRINGE_PUMP_CONTROL_ENABLE | + SYRINGE_PUMP_CONTROL_FORWARD_DIR | + SYRINGE_PUMP_CONTROL_32TH_STEP; + // FPGA Sensors Record #pragma pack(push,1) @@ -88,7 +99,7 @@ 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. + U08 h6HallStatus; ///< Reg 261. H6 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. @@ -103,16 +114,16 @@ S16 H1EncPosition; ///< Reg 280. H1 encoder position (1024 counts/rev). U08 H1Status; ///< Reg 282. H1 status. U08 reserved1; ///< 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. + U08 reserved2; ///< Reg 284. Reserved and available for future use. + U08 reserved3; ///< Reg 285. Reserved and available for future use. + S32 reserved4; ///< Reg 286. Reserved and available for future use. 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. + U08 H4Status; ///< Reg 301. H4 status. U16 GPIOReg; ///< Reg 302. GPIO register. U08 HEPStatus; ///< Reg 304. HEP status register. U08 HEPAdcReadCount; ///< Reg 305. HEP ADC read counter. @@ -136,8 +147,8 @@ 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. + S16 H4RotorHallCount; ///< Reg 344. H4 rotor count from hall sensor. + U08 H6RotorStatus; ///< Reg 346. H6 rotor status. } FPGA_SENSORS_T; /// Record structure for FPGA continuous priority writes. @@ -151,7 +162,7 @@ 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 NotUsed; ///< Reg 16. Reserved. 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. @@ -167,6 +178,7 @@ U16 syrPumpDACData; ///< Reg 38. Syringe pump DAC data (12 bits). U16 syrPumpDACControl; ///< Reg 40. Syringe pump ADC and DAC control register. U16 h12Period; ///< Reg 42. H12 Air pump time period for each count in PWM register. + U32 h5SetSpeed; ///< Reg 44. H5 ejector motor set speed. } FPGA_ACTUATORS_T; #pragma pack(pop) @@ -475,38 +487,10 @@ /*********************************************************************//** * @brief - * The homeH4 function sets the bit requesting that the blood pump - * be homed. - * @details \b Inputs: none - * @details \b Outputs: H4 pump home request is set (bit 2 of H4 control register). - * @return none - *************************************************************************/ -void homeH4( void ) -{ - fpgaActuatorSetPoints.H4Control |= FPGA_H4_HOME_BIT_MASK; -} - -/*********************************************************************//** - * @brief - * 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: H4 pump home request is cleared (bit 2 of H4 control register) - * @return none - *************************************************************************/ -void resetH4HomeRequest( void ) -{ - fpgaActuatorSetPoints.H4Control &= ~((U08)FPGA_H4_HOME_BIT_MASK); -} - -/*********************************************************************//** - * @brief * The setH4SetSpeed function sets the fpga blood pump set speed * to the given speed (0..3000 RPM). * @details \b Inputs: none - * @details \b Outputs: H4 set speed is set + * @details \b Outputs: fpgaActuatorSetPoints * @param rpm the set point for the H4 pump speed (in RPM). * @return none *************************************************************************/ @@ -530,53 +514,84 @@ /*********************************************************************//** * @brief - * 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 + * The getH6Status function gets the latest blood pump hall sensor status. + * Bit 0: 1=Magnet is detected (used for homing in forward direction) + * Bit 1: 0=Reverse pump direction detected, 1=Forward pump direction detected + * Bit 2..7: Not used. + * @details \b Inputs: fpgaSensorReadings.h6HallStatus * @details \b Outputs: none * @return Latest blood pump hall sensor status bits. *************************************************************************/ -U08 getBPStatus( void ) +U08 getH6Status( void ) { - return fpgaSensorReadings.BPHallStatus; + return fpgaSensorReadings.h6HallStatus; } /*********************************************************************//** * @brief - * 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 + * The getH4RotorCount function gets the latest blood pump + * hall sensor count. Count is number of ms between rotor revolutions. + * If direction is forward, the count will be positive. If direction is + * reverse, the count will be negative. + * @details \b Inputs: fpgaSensorReadings.H4RotorHallCount * @details \b Outputs: none * @return Latest blood pump hall sensor count reading. *************************************************************************/ -U16 getBloodPumpHallSensorCount( void ) +S16 getH4RotorCount( void ) { - return 0;//fpgaSensorReadings.bloodPumpHallSensorCount; + return fpgaSensorReadings.H4RotorHallCount; } /*********************************************************************//** * @brief - * 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 + * The setH5ControlFlags function sets the control flags for the H5 ejector + * stepper motor. + * @note Bit 0 - MS1 (bit 1 of microstepping configuration setting) + * Bit 1 - MS2 (bit 2 of microstepping configuration setting) + * Bit 2 - MS3 (bit 3 of microstepping configuration setting) + * Bit 3 - Direction (1=forward, 0=reverse) + * Bit 4 - Disable (0=enabled, 1=disabled) + * Bit 5 - Reset (0=reset, 1=not reset) + * Bit 6 - Sleep (0=sleep, 1=not sleep) + * Bit 7 - Reserved + * @details \b Inputs: none + * @details \b Outputs: fpgaActuatorSetPoints.h5Control + * @param ctrl Bit flags for H5 stepper motor control + * @return none + *************************************************************************/ +void setH5ControlFlags( U08 ctrl ) +{ + fpgaActuatorSetPoints.h5Control = ctrl; +} + +/*********************************************************************//** + * @brief + * The getH5ControlFlags function gets the currently set control flags for + * the H5 ejector stepper motor. + * @details \b Inputs: fpgaActuatorSetPoints.h5Control * @details \b Outputs: none - * @return latest blood pump hall sensor status reading. + * @return Currently set control flags for H5 ejector motor *************************************************************************/ -U08 getBloodPumpHallSensorStatus( void ) +U08 getH5ControlFlags( void ) { - return 0;//fpgaSensorReadings.bloodPumpHallSensorStatus; + return fpgaActuatorSetPoints.h5Control; } /*********************************************************************//** * @brief + * The setH5StepToggleTime function sets the ejector motor set speed step + * toggle time (in uSec). + * @details \b Inputs: none + * @details \b Outputs: fpgaActuatorSetPoints.h5SetSpeed + * @return latest arterial pressure reading + *************************************************************************/ +void setH5StepToggleTime( U32 microSeconds ) +{ + fpgaActuatorSetPoints.h5SetSpeed = microSeconds; +} + +/*********************************************************************//** + * @brief * 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, @@ -761,29 +776,29 @@ /*********************************************************************//** * @brief - * The setAirPumpMotorPowerLevel function sets the air pump motor power level + * The setH12AirPumpMotorPowerLevel function sets the air pump motor power level * to 0 to turn pump off or 1..255 for varying power levels. * @details \b Inputs: fpgaActuatorSetPoints.h12Control * @details \b Outputs: fpgaActuatorSetPoints.h12Control * @param power The set power level to set the H12 air pump to. * @return none *************************************************************************/ -void setAirPumpMotorPowerLevel( U08 power ) +void setH12AirPumpMotorPowerLevel( U08 power ) { fpgaActuatorSetPoints.h12Control = power; } /*********************************************************************//** * @brief - * The setAirPumpMotorPWMCntTime function sets the air pump motor PWM count + * The setH12AirPumpMotorPWMCntTime function sets the air pump motor PWM count * time in increments of 10 nS. The PWM period will then be 255 x given * value x 10 nS. * @details \b Inputs: fpgaActuatorSetPoints.h12Period * @details \b Outputs: fpgaActuatorSetPoints.h12Period * @param tenNS The time associated with each PWM count in power level setting. * @return none *************************************************************************/ -void setAirPumpMotorPWMCntTime( U16 tenNS ) +void setH12AirPumpMotorPWMCntTime( U16 tenNS ) { fpgaActuatorSetPoints.h12Period = tenNS; } @@ -1045,13 +1060,13 @@ } /*********************************************************************//** - * The getFPGAFrontDoorStatus function returns the FPGA front door status + * The getH9FrontDoorClosedStatus function returns the FPGA front door status * bit (0x10). * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none * @return TRUE if front door is closed, FALSE if not. *************************************************************************/ -BOOL getFPGAFrontDoorClosedStatus( void ) +BOOL getH9FrontDoorClosedStatus( void ) { BOOL result = TRUE;