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 ) ) // {