Index: firmware/App/Drivers/PeristalticPump.c =================================================================== diff -u -r036a75d76ab01912646a480b935d97187a231a19 -r52e1d4487a69a1ef0475321084527c0ba86c0892 --- firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision 036a75d76ab01912646a480b935d97187a231a19) +++ firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision 52e1d4487a69a1ef0475321084527c0ba86c0892) @@ -38,6 +38,10 @@ #define H4_HZ_TO_RPM(h) ((h) * H4_HZ_TO_RPM_SCALAR) ///< Blood pump Hz to RPM conversion macro. #define H4_ZERO_SPEED_PERIOD 0xFFFF ///< Blood pump period reported when pump is stopped. +#define H4_HOME_SPEED_RPM 400 ///< Blood pump set speed for rotor homing operation. + +#define H6_STATUS_HOME_BIT_POS 0x1 ///< Bit position in H6 status register that indicates whether rotor is in home position. + // ********** private data ********** static S32 pumpSetSpeedRPM; ///< Current set speed for the pump (in RPM). Negative indicates reverse direction. @@ -64,7 +68,6 @@ pumpMeasSpeedRPM.override = OVERRIDE_RESET; setH4Direction( MOTOR_DIR_FORWARD ); - resetH4HomeRequest(); setH4SetSpeed( 0 ); setH4Enabled( TRUE ); } @@ -102,11 +105,11 @@ pumpMeasSpeedRPM.data = 0.0F; } - // clear home command if previously requested - if ( TRUE == pumpHomeRequested ) + // monitor home command status if in progress, stop pump if rotor in home position + if ( ( TRUE == pumpHomeRequested ) && ( TRUE == isPeristalticPumpHome() ) ) { pumpHomeRequested = FALSE; - resetH4HomeRequest(); + setPeristalticPumpSetSpeed( 0 ); } } @@ -115,12 +118,36 @@ * The cmdPeristalticPumpHome function initiates a pump home operation. * @details \b Inputs: none * @details \b Outputs: pumpHomeRequested, FPGA + * @return TRUE if home operation is initiated, FALSE if not + *************************************************************************/ +BOOL cmdPeristalticPumpHome( void ) +{ + BOOL result = FALSE; + + if ( ( 0 == pumpSetSpeedRPM ) && ( pumpHomeRequested != TRUE ) ) + { + result = TRUE; + pumpHomeRequested = TRUE; + setPeristalticPumpSetSpeed( H4_HOME_SPEED_RPM ); + } + + return result; +} + +/*********************************************************************//** + * @brief + * The isPeristalticPumpHome function determines whether the rotor is currently + * in the home position. + * @details \b Inputs: FPGA + * @details \b Outputs: none * @return none *************************************************************************/ -void cmdPeristalticPumpHome( void ) +BOOL isPeristalticPumpHome( void ) { - pumpHomeRequested = TRUE; - homeH4(); + U08 status = getH6Status() & H6_STATUS_HOME_BIT_POS; + BOOL result = ( status != 0 ? TRUE : FALSE ); + + return result; } /*********************************************************************//** Index: firmware/App/Drivers/PeristalticPump.h =================================================================== diff -u -r56100135135bb715d316b5fd002a4a4951b9334a -r52e1d4487a69a1ef0475321084527c0ba86c0892 --- firmware/App/Drivers/PeristalticPump.h (.../PeristalticPump.h) (revision 56100135135bb715d316b5fd002a4a4951b9334a) +++ firmware/App/Drivers/PeristalticPump.h (.../PeristalticPump.h) (revision 52e1d4487a69a1ef0475321084527c0ba86c0892) @@ -43,7 +43,8 @@ S32 getPeristalticPumpSetSpeed( void ); F32 getPeristalticPumpMeasSpeed( void ); -void cmdPeristalticPumpHome( void ); +BOOL cmdPeristalticPumpHome( void ); +BOOL isPeristalticPumpHome( void ); BOOL testSetPeristalticPumpSetSpeed( MESSAGE_T *message ); Index: firmware/App/Modes/ModeTxParams.c =================================================================== diff -u -r44756f72f2b493444495fcb3067c691dda9a7920 -r52e1d4487a69a1ef0475321084527c0ba86c0892 --- firmware/App/Modes/ModeTxParams.c (.../ModeTxParams.c) (revision 44756f72f2b493444495fcb3067c691dda9a7920) +++ firmware/App/Modes/ModeTxParams.c (.../ModeTxParams.c) (revision 52e1d4487a69a1ef0475321084527c0ba86c0892) @@ -92,6 +92,12 @@ } DIALIN_SET_TX_PARAM_PAYLOAD_T; #pragma pack(pop) +/// Dialyzer volume data record structure. +typedef struct { + U32 bloodVolume; ///< Blood volume of the dialyzer in mL. + U32 dialysateVolume; ///< Dialysate volume of the dialyzer in mL. +} DIALYZER_VOLUME_DATA_T; + // ********** private data ********** static TD_TREATMENT_PARAMS_MODE_STATE_T currentTreatmentParamsState; ///< Current state of treatment parameters mode state machine. @@ -121,6 +127,16 @@ { CRITICAL_DATA_TYPE_F32, {.sFlt=0.0}, {.sFlt=8.0}, {.sFlt=0.0} }, // TREATMENT_PARAM_UF_VOLUME }; +/// Dialyzer volumes (blood and dialysate) table in mL for each type of dialyzer. +const DIALYZER_VOLUME_DATA_T dialyzerVolumeTable[ NUM_OF_DIALYZER_TYPES ] = + { { 82, 170 }, // DIALYZER_TYPE_BBRAUN_PRO_13H + { 100, 200 }, // DIALYZER_TYPE_BBRAUN_PRO_16H + { 120, 257 }, // DIALYZER_TYPE_BBRAUN_PRO_19H + { 87, 233 }, // DIALYZER_TYPE_FRESENIUS_OPTIFLUX_F160NRE + { 102, 280 }, // DIALYZER_TYPE_FRESENIUS_OPTIFLUX_F180NRE + { 113, 348 }, // DIALYZER_TYPE_FRESENIUS_OPTIFLUX_F200NRE + { 142, 304 } }; // DIALYZER_TYPE_FRESENIUS_OPTIFLUX_F250NRE + // Current treatment parameter values static CRITICAL_DATA_T treatmentParameters[ NUM_OF_TREATMENT_PARAMS ]; ///< Treatment parameters. static CRITICAL_DATAS_T stagedParams[ NUM_OF_TREATMENT_PARAMS ]; ///< Temporary staged treatment parameters for validation and awaiting user confirmation. @@ -891,6 +907,58 @@ /*********************************************************************//** * @brief + * The getDialyzerBloodVolume function gets the blood side volume (in mL) + * for a given dialyzer type. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given dialyzer type is invalid + * @details \b Inputs : dialyzerVolumeTable[] + * @details \b Outputs : none + * @param dialyzer The type of dialyzer to get the blood side volume for + * @return The blood side volume for the given dialyzer type + *************************************************************************/ +U32 getDialyzerBloodVolume( DIALYZER_TYPE_T dialyzer ) +{ + U32 result = 0; + + if ( dialyzer < NUM_OF_DIALYZER_TYPES ) + { + result = dialyzerVolumeTable[ dialyzer ].bloodVolume; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_DIALYZER_TYPE_INVALID1, (U32)dialyzer ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getDialyzerDialysateVolume function gets the dialysate side volume (in mL) + * for a given dialyzer type. + * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given dialyzer type is invalid + * @details \b Inputs : dialyzerVolumeTable[] + * @details \b Outputs : none + * @param dialyzer The type of dialyzer to get the dialysate side volume for + * @return The dialysate side volume for the given dialyzer type + *************************************************************************/ +U32 getDialyzerDialysateVolume( DIALYZER_TYPE_T dialyzer ) +{ + U32 result = 0; + + if ( dialyzer < NUM_OF_DIALYZER_TYPES ) + { + result = dialyzerVolumeTable[ dialyzer ].dialysateVolume; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_DIALYZER_TYPE_INVALID2, (U32)dialyzer ) + } + + return result; +} + +/*********************************************************************//** + * @brief * The isTreatmentParamInRange function determines whether a given treatment * parameter is in range. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given param is invalid Index: firmware/App/Modes/ModeTxParams.h =================================================================== diff -u -r44756f72f2b493444495fcb3067c691dda9a7920 -r52e1d4487a69a1ef0475321084527c0ba86c0892 --- firmware/App/Modes/ModeTxParams.h (.../ModeTxParams.h) (revision 44756f72f2b493444495fcb3067c691dda9a7920) +++ firmware/App/Modes/ModeTxParams.h (.../ModeTxParams.h) (revision 52e1d4487a69a1ef0475321084527c0ba86c0892) @@ -102,6 +102,9 @@ BOOL isTreatmentParamInRange( TREATMENT_PARAM_T param, CRITICAL_DATAS_T value ); // Check range for a proposed treatment parameter value +U32 getDialyzerBloodVolume( DIALYZER_TYPE_T dialyzer ); // Get the blood side volume for a given dialyzer type +U32 getDialyzerDialysateVolume( DIALYZER_TYPE_T dialyzer ); // Get the dialysate side volume for a given dialyzer type + BOOL testSetTreatmentParameter( MESSAGE_T *message ); // Set a specific treatment parameter value BOOL testTxParamsRequest( MESSAGE_T *message ); // Request to publish current treatment parameters Index: firmware/App/Services/AlarmMgmtSWFaults.h =================================================================== diff -u -r036a75d76ab01912646a480b935d97187a231a19 -r52e1d4487a69a1ef0475321084527c0ba86c0892 --- firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 036a75d76ab01912646a480b935d97187a231a19) +++ firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 52e1d4487a69a1ef0475321084527c0ba86c0892) @@ -162,6 +162,8 @@ SW_FAULT_ID_MODE_TREATMENT_INVALID_STATE = 131, SW_FAULT_ID_TX_DIALYSIS_INVALID_STATE1 = 132, SW_FAULT_ID_TX_DIALYSIS_INVALID_STATE2 = 133, + SW_FAULT_ID_DIALYZER_TYPE_INVALID1 = 134, + SW_FAULT_ID_DIALYZER_TYPE_INVALID2 = 135, NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T; Index: firmware/App/Services/FpgaTD.c =================================================================== diff -u -r036a75d76ab01912646a480b935d97187a231a19 -r52e1d4487a69a1ef0475321084527c0ba86c0892 --- firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 036a75d76ab01912646a480b935d97187a231a19) +++ firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 52e1d4487a69a1ef0475321084527c0ba86c0892) @@ -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. @@ -88,7 +87,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 +102,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 H5Status; ///< Reg 284. H5 motor status. + U08 H5EncStatus; ///< Reg 285. H5 encoder status. + S32 H5EncPosition; ///< Reg 286. H5 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. + 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 +135,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. @@ -475,34 +474,6 @@ /*********************************************************************//** * @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 @@ -530,53 +501,36 @@ /*********************************************************************//** * @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 - * @details \b Outputs: none - * @return latest blood pump hall sensor status reading. - *************************************************************************/ -U08 getBloodPumpHallSensorStatus( void ) -{ - return 0;//fpgaSensorReadings.bloodPumpHallSensorStatus; -} - -/*********************************************************************//** - * @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, Index: firmware/App/Services/FpgaTD.h =================================================================== diff -u -r036a75d76ab01912646a480b935d97187a231a19 -r52e1d4487a69a1ef0475321084527c0ba86c0892 --- firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision 036a75d76ab01912646a480b935d97187a231a19) +++ firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision 52e1d4487a69a1ef0475321084527c0ba86c0892) @@ -58,13 +58,11 @@ void setH4Enabled( BOOL enable ); void setH4Direction( MOTOR_DIR_T dir ); -void homeH4( void ); -void resetH4HomeRequest( void ); void setH4SetSpeed( U16 rpm ); U16 getH4Period( void ); -U16 getBloodPumpHallSensorCount( void ); -U08 getBloodPumpHallSensorStatus( void ); +S16 getH4RotorCount( void ); +U08 getH6Status( void ); U16 getH2Pressure( void ); S16 getH2Temperature( void );