Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -rb88a8fd2c5fca8f055d6df1437635692388fcb0d -rae3240cfb3237c01472168fee0bfc6beb34e0ed9 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision b88a8fd2c5fca8f055d6df1437635692388fcb0d) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision ae3240cfb3237c01472168fee0bfc6beb34e0ed9) @@ -92,6 +92,7 @@ typedef enum BloodPump_States { BLOOD_PUMP_OFF_STATE = 0, ///< Blood pump off state + BLOOD_PUMP_HOMING_STATE, ///< Blood pump homing state BLOOD_PUMP_RAMPING_UP_STATE, ///< Blood pump ramping up state BLOOD_PUMP_RAMPING_DN_STATE, ///< Blood pump ramping down state BLOOD_PUMP_CONTROL_TO_TARGET_STATE, ///< Blood pump controlling to target state @@ -136,14 +137,15 @@ static U32 bpControlTimerCounter; ///< Determines when to perform control on blood flow. static OVERRIDE_U32_T bloodPumpRotorCounter; ///< Running counter for blood pump rotor revolutions. -static BOOL bpStopAtHomePosition; ///< Stop blood pump at next home position. +static BOOL bpHomeRequested; ///< Flag indicating a home operation has been requested. static U32 bpHomeStartTime; ///< When did blood pump home command begin? (in ms). //static TD_PUMPS_CAL_RECORD_T bloodPumpCalRecord; ///< Blood pump calibration record. // ********** private function prototypes ********** static BLOOD_PUMP_STATE_T handleBloodPumpOffState( void ); +static BLOOD_PUMP_STATE_T handleBloodPumpHomingState( void ); static BLOOD_PUMP_STATE_T handleBloodPumpRampingUpState( void ); static BLOOD_PUMP_STATE_T handleBloodPumpRampingDownState( void ); static BLOOD_PUMP_STATE_T handleBloodPumpControlToTargetState( void ); @@ -183,8 +185,8 @@ bloodPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; bpControlTimerCounter = 0; bloodFlowDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + bpHomeRequested = FALSE; bpHomeStartTime = 0; - bpStopAtHomePosition = FALSE; // Initialize overrides bloodFlowDataPublishInterval.data = BLOOD_FLOW_DATA_PUB_INTERVAL; @@ -366,21 +368,21 @@ * @brief * The homeBloodPump function initiates a blood pump home operation. * @details \b Inputs: bloodPumpState - * @details \b Outputs: bpStopAtHomePosition, bpHomeStartTime, blood pump started (slow) - * @return none + * @details \b Outputs: bpHomeRequested + * @return TRUE if home request accepted, FALSE if not *************************************************************************/ BOOL homeBloodPump( void ) { - BOOL result = FALSE; - if ( BLOOD_PUMP_OFF_STATE == bloodPumpState ) { - bpStopAtHomePosition = TRUE; - bpHomeStartTime = getMSTimerCount(); - result = setBloodPumpTargetRPM( BP_HOME_SPEED, MOTOR_DIR_FORWARD ); + bpHomeRequested = TRUE; } + else + { + bpHomeRequested = FALSE; + } - return result; + return bpHomeRequested; } /*********************************************************************//** @@ -511,6 +513,10 @@ bloodPumpState = handleBloodPumpOffState(); break; + case BLOOD_PUMP_HOMING_STATE: + bloodPumpState = handleBloodPumpHomingState(); + break; + case BLOOD_PUMP_RAMPING_UP_STATE: bloodPumpState = handleBloodPumpRampingUpState(); break; @@ -536,8 +542,9 @@ * @brief * The handleBloodPumpOffState function handles the blood pump off state * of the blood pump controller state machine. - * @details \b Inputs: targetBloodFlowRate, bloodPumpDirection - * @details \b Outputs: bloodPumpPWMDutyCyclePctSet, bloodPumpDirectionSet, isBloodPumpOn + * @details \b Inputs: targetBloodFlowRate, bpHomeRequested + * @details \b Outputs: bloodPumpSetSpeedRPM, isBloodPumpOn, bpHomeRequested, + * bpHomeStartTime * @return next state *************************************************************************/ static BLOOD_PUMP_STATE_T handleBloodPumpOffState( void ) @@ -553,6 +560,21 @@ isBloodPumpOn = TRUE; result = BLOOD_PUMP_RAMPING_UP_STATE; } + // If home requested, initiate homing operation + else if ( TRUE == bpHomeRequested ) + { + BOOL homeOK = FALSE; + + bpHomeRequested = FALSE; + bpHomeStartTime = getMSTimerCount(); + homeOK = cmdPeristalticPumpHome(); + if ( TRUE == homeOK ) + { + isBloodPumpOn = TRUE; + bloodPumpSetSpeedRPM = H4_HOME_SPEED_RPM; + result = BLOOD_PUMP_HOMING_STATE; + } + } else { isBloodPumpOn = FALSE; @@ -565,6 +587,33 @@ /*********************************************************************//** * @brief + * The handleBloodPumpHomingState function handles the blood pump homing state + * of the blood pump controller state machine. + * @details \b Inputs: bpHomeStartTime + * @details \b Outputs: Blood pump stopped if complete or timed out + * @return next state + *************************************************************************/ +static BLOOD_PUMP_STATE_T handleBloodPumpHomingState( void ) +{ + BLOOD_PUMP_STATE_T result = BLOOD_PUMP_HOMING_STATE; + + if ( isPumpHomeInProgress() != TRUE ) + { + signalBloodPumpHardStop(); + result = BLOOD_PUMP_OFF_STATE; + } + else if ( TRUE == didTimeout( bpHomeStartTime, BP_HOME_TIMEOUT_MS ) ) + { + cancelPeristalticPumpHome(); + signalBloodPumpHardStop(); + result = BLOOD_PUMP_OFF_STATE; + } + + return result; +} + +/*********************************************************************//** + * @brief * The handleBloodPumpRampingUpState function handles the ramp up state * of the blood pump controller state machine. * @details \b Inputs: bloodPumpRampToSpeedRPM, bloodPumpSetSpeedRPM @@ -812,8 +861,7 @@ /*********************************************************************//** * @brief * The checkBloodPumpRotor function checks the rotor for the blood - * pump. If homing, this function will stop when hall sensor detected. If pump - * is off or running very slowly, rotor speed will be set to zero. + * pump. If pump is off or running very slowly, rotor speed will be set to zero. * @details \b Alarm: ALARM_ID_HD_BLOOD_PUMP_ROTOR_SPEED_TOO_HIGH if rotor speed * is too high. * @details \b Inputs: bpStopAtHomePosition, bpHomeStartTime, bpRotorRevStartTime, @@ -826,13 +874,6 @@ { // F32 rotorSpeed = getMeasuredBloodPumpRotorSpeed(); // -// // If homing, check timeout -// if ( ( TRUE == bpStopAtHomePosition ) && ( TRUE == didTimeout( bpHomeStartTime, BP_HOME_TIMEOUT_MS ) ) ) -// { -// signalBloodPumpHardStop(); -// bpStopAtHomePosition = FALSE; -// } -// // // Ensure rotor speed below maximum // if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BLOOD_PUMP_ROTOR_SPEED_TOO_HIGH, bpRotorSpeedTooFastPulseCount >= BP_MIN_ROTOR_PULSES_FOR_MAX_SPEED ) ) // { Index: firmware/App/Drivers/PeristalticPump.c =================================================================== diff -u -raa6d45143096dfab776ce2ed7c775cfe2dd6db18 -rae3240cfb3237c01472168fee0bfc6beb34e0ed9 --- firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision aa6d45143096dfab776ce2ed7c775cfe2dd6db18) +++ firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision ae3240cfb3237c01472168fee0bfc6beb34e0ed9) @@ -43,8 +43,6 @@ #define H4_ROT_PERIOD_TO_HZ(p) ( 1.0F / (F32)((S32)(p) * H4_ROT_PERIOD_SEC) ) ///< Blood pump rotor period to Hz conversion macro. #define H4_ROT_PERIOD_TO_RPM(p) ((H4_ROT_PERIOD_TO_HZ(p)) * (F32)SEC_PER_MIN) ///< Blood pump rotor period to RPM conversion macro. -#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 ********** @@ -153,6 +151,18 @@ /*********************************************************************//** * @brief + * The cancelPeristalticPumpHome function cancels a pump home operation. + * @details \b Inputs: none + * @details \b Outputs: pumpHomeInProgress + * @return none + *************************************************************************/ +void cancelPeristalticPumpHome( void ) +{ + pumpHomeInProgress = FALSE; +} + +/*********************************************************************//** + * @brief * The isPeristalticPumpHome function determines whether the rotor is currently * in the home position. * @details \b Inputs: FPGA @@ -161,14 +171,27 @@ *************************************************************************/ BOOL isPeristalticPumpHome( void ) { - U08 status = getH6Status() & H6_STATUS_HOME_BIT_POS; - BOOL result = ( status != 0 ? TRUE : FALSE ); + U08 status = getH6RotorStatus() & H6_STATUS_HOME_BIT_POS; + BOOL result = ( status != 0 ? FALSE : TRUE ); return result; } /*********************************************************************//** * @brief + * The isPumpHomeInProgress function determines whether a home operation is + * currently in progress. + * @details \b Inputs: pumpHomeInProgress + * @details \b Outputs: none + * @return pumpHomeInProgress + *************************************************************************/ +BOOL isPumpHomeInProgress( void ) +{ + return pumpHomeInProgress; +} + +/*********************************************************************//** + * @brief * The setPeristalticPumpSetSpeed function sets the target pump speed (in RPM). * @note A negative set speed indicates reverse (CCW) direction. * @details \b Alarm: ALARM_ID_TD_SOFTWARE_FAULT if given set speed is out Index: firmware/App/Drivers/PeristalticPump.h =================================================================== diff -u -raa6d45143096dfab776ce2ed7c775cfe2dd6db18 -rae3240cfb3237c01472168fee0bfc6beb34e0ed9 --- firmware/App/Drivers/PeristalticPump.h (.../PeristalticPump.h) (revision aa6d45143096dfab776ce2ed7c775cfe2dd6db18) +++ firmware/App/Drivers/PeristalticPump.h (.../PeristalticPump.h) (revision ae3240cfb3237c01472168fee0bfc6beb34e0ed9) @@ -33,6 +33,7 @@ // ********** public definitions ********** +#define H4_HOME_SPEED_RPM 400 ///< Blood pump set speed for rotor homing operation. // ********** public function prototypes ********** @@ -45,7 +46,9 @@ F32 getPeristalticPumpMeasRotorSpeed( void ); BOOL cmdPeristalticPumpHome( void ); +void cancelPeristalticPumpHome( void ); BOOL isPeristalticPumpHome( void ); +BOOL isPumpHomeInProgress( void ); /**@}*/ Index: firmware/App/Services/FpgaTD.c =================================================================== diff -u -r51f42cd88bd9c50ed9096a2d1d8ff859a95aff95 -rae3240cfb3237c01472168fee0bfc6beb34e0ed9 --- firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision 51f42cd88bd9c50ed9096a2d1d8ff859a95aff95) +++ firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision ae3240cfb3237c01472168fee0bfc6beb34e0ed9) @@ -149,6 +149,8 @@ S16 ACPower3Voltage; ///< Reg 342. AC power voltage - 3. S16 H4RotorHallCount; ///< Reg 344. H4 rotor count from hall sensor. U08 H6RotorStatus; ///< Reg 346. H6 rotor status. + U08 reserved5; ///< + U16 h12Speed; ///< Reg 348. H12 speed (in RPM). } FPGA_SENSORS_T; /// Record structure for FPGA continuous priority writes. @@ -529,6 +531,21 @@ /*********************************************************************//** * @brief + * The getH6RotorStatus function gets the latest blood pump hall sensor status. + * Bit 0: 0=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.H6RotorStatus + * @details \b Outputs: none + * @return Latest blood pump hall sensor status bits. + *************************************************************************/ +U08 getH6RotorStatus( void ) +{ + return fpgaSensorReadings.H6RotorStatus; +} + +/*********************************************************************//** + * @brief * 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 @@ -1117,7 +1134,9 @@ { if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES ) ) { +#ifndef TEST_DEBUGGER SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_FPGA_COMM_TIMEOUT, MAX_FPGA_COMM_FAILURES, (U32)fpgaSensorReadings.errorCountProcessor ) +#endif } } } @@ -1143,7 +1162,9 @@ { if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_COMM_FAILURES ) ) { +#ifndef TEST_DEBUGGER SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_FPGA_COMM_TIMEOUT, MAX_FPGA_COMM_FAILURES, (U32)fpgaSensorReadings.errorCountProcessor ) +#endif } } } Index: firmware/App/Services/FpgaTD.h =================================================================== diff -u -r51f42cd88bd9c50ed9096a2d1d8ff859a95aff95 -rae3240cfb3237c01472168fee0bfc6beb34e0ed9 --- firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision 51f42cd88bd9c50ed9096a2d1d8ff859a95aff95) +++ firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision ae3240cfb3237c01472168fee0bfc6beb34e0ed9) @@ -73,6 +73,7 @@ S16 getH4RotorCount( void ); U08 getH6Status( void ); +U08 getH6RotorStatus( void ); void setH5ControlFlags( U08 ctrl ); U08 getH5ControlFlags( void ); Index: firmware/App/Services/SystemCommTD.c =================================================================== diff -u -ra5560a2917aa62bcafd8e6a81041ace723237109 -rae3240cfb3237c01472168fee0bfc6beb34e0ed9 --- firmware/App/Services/SystemCommTD.c (.../SystemCommTD.c) (revision a5560a2917aa62bcafd8e6a81041ace723237109) +++ firmware/App/Services/SystemCommTD.c (.../SystemCommTD.c) (revision ae3240cfb3237c01472168fee0bfc6beb34e0ed9) @@ -181,6 +181,9 @@ *************************************************************************/ BOOL uiCommunicated( void ) { +#ifdef TEST_DEBUGGER + uiDidCommunicate = TRUE; +#endif return uiDidCommunicate; } @@ -251,7 +254,9 @@ // if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_UI_COMM_ALARMS ) != SW_CONFIG_ENABLE_VALUE ) #endif { +#ifndef TEST_UI_ONLY activateAlarmNoData( ALARM_ID_TD_UI_COMM_TIMEOUT ); +#endif } } Index: firmware/App/TDCommon.h =================================================================== diff -u -rb88a8fd2c5fca8f055d6df1437635692388fcb0d -rae3240cfb3237c01472168fee0bfc6beb34e0ed9 --- firmware/App/TDCommon.h (.../TDCommon.h) (revision b88a8fd2c5fca8f055d6df1437635692388fcb0d) +++ firmware/App/TDCommon.h (.../TDCommon.h) (revision ae3240cfb3237c01472168fee0bfc6beb34e0ed9) @@ -34,6 +34,7 @@ // #define TASK_TIMING_OUTPUT_ENABLED 1 // Re-purposes alarm lamp pins for task timing // #define TEST_AIR_TRAP_ALPHA_TESTING 1 // Alpha unit air trap testing // #define TEST_PINCH_VALVES 1 // Alpha unit pinch valve testing +// #define TEST_DEBUGGER 1 // Alpha test with debugger // #define TEST_UI_ONLY 1 // Alpha test with TD and UI only - no DD // #define TEST_NO_PINCH_VALVES 1 // Alpha test with no pinch valve functionality // #define TEST_USE_OFF_AS_STOP_BUTTON 1 // Alpha test re-purposing off button as a stop button