Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -rde5a0d43bdef611d963d11855bc958a8d8899a09 -ra3a01327c8fe80f65f6658ae6cbef4910a4a8033 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision de5a0d43bdef611d963d11855bc958a8d8899a09) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision a3a01327c8fe80f65f6658ae6cbef4910a4a8033) @@ -15,9 +15,7 @@ * ***************************************************************************/ -#ifndef _VECTORCAST_ - #include -#endif +#include #include "can.h" #include "etpwm.h" @@ -27,7 +25,8 @@ #include "PresOccl.h" #include "FPGA.h" -#include "InternalADC.h" +#include "InternalADC.h" +#include "NVDataMgmt.h" #include "OperationModes.h" #include "PIControllers.h" #include "SystemCommMessages.h" @@ -51,8 +50,8 @@ #define MIN_BLOOD_PUMP_PWM_DUTY_CYCLE 0.12 ///< controller will error if PWM duty cycle < 10%, so set min to 12% #define BP_CONTROL_INTERVAL ( 10000 / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the blood pump is controlled -#define BP_P_COEFFICIENT 0.00005 ///< P term for blood pump control -#define BP_I_COEFFICIENT 0.00015 ///< I term for blood pump control +#define BP_P_COEFFICIENT 0.00035 ///< P term for blood pump control +#define BP_I_COEFFICIENT 0.00035 ///< I term for blood pump control #define BP_HOME_RATE 100 ///< target pump speed (in estimate mL/min) for homing. #define BP_HOME_TIMEOUT_MS 10000 ///< maximum time allowed for homing to complete (in ms). @@ -80,7 +79,7 @@ #define BP_REV_PER_LITER 150.24 ///< rotor revolutions per liter #define BP_ML_PER_MIN_TO_PUMP_RPM_FACTOR ( BP_REV_PER_LITER / ML_PER_LITER ) ///< conversion factor from mL/min to motor RPM. #define BP_GEAR_RATIO 32.0 ///< blood pump motor to blood pump gear ratio -#define BP_MOTOR_RPM_TO_PWM_DC_FACTOR 0.00035 ///< ~28 BP motor RPM = 1% PWM duty cycle +#define BP_MOTOR_RPM_TO_PWM_DC_FACTOR 0.00028 ///< ~28 BP motor RPM = 1% PWM duty cycle #define BP_PWM_ZERO_OFFSET 0.1 ///< 10% PWM duty cycle = zero speed #define BP_PWM_FROM_ML_PER_MIN(rate) ( (rate) * BP_ML_PER_MIN_TO_PUMP_RPM_FACTOR * BP_GEAR_RATIO * BP_MOTOR_RPM_TO_PWM_DC_FACTOR + BP_PWM_ZERO_OFFSET ) ///< conversion factor from mL/min to estimated PWM duty cycle %. @@ -100,13 +99,13 @@ NUM_OF_BLOOD_PUMP_STATES ///< Number of blood pump states. } BLOOD_PUMP_STATE_T; -/// Enumeration of blood pump self test states. +/// Enumeration of blood pump self-test states. typedef enum BloodFlow_Self_Test_States { - BLOOD_FLOW_SELF_TEST_STATE_START = 0, ///< Blood pump self test start state. - BLOOD_FLOW_TEST_STATE_IN_PROGRESS, ///< Blood pump self test in progress state. - BLOOD_FLOW_TEST_STATE_COMPLETE, ///< Blood pump self test completed state. - NUM_OF_BLOOD_FLOW_SELF_TEST_STATES ///< Number of blood pump self test states. + BLOOD_FLOW_SELF_TEST_STATE_START = 0, ///< Blood pump self-test start state. + BLOOD_FLOW_TEST_STATE_IN_PROGRESS, ///< Blood pump self-test in progress state. + BLOOD_FLOW_TEST_STATE_COMPLETE, ///< Blood pump self-test completed state. + NUM_OF_BLOOD_FLOW_SELF_TEST_STATES ///< Number of blood pump self-test states. } BLOOD_FLOW_SELF_TEST_STATE_T; // pin assignments for pump stop and direction outputs @@ -133,7 +132,9 @@ static MOTOR_DIR_T bloodPumpDirection = MOTOR_DIR_FORWARD; ///< requested blood flow direction static MOTOR_DIR_T bloodPumpDirectionSet = MOTOR_DIR_FORWARD; ///< currently set blood flow direction static PUMP_CONTROL_MODE_T bloodPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< requested blood pump control mode. -static PUMP_CONTROL_MODE_T bloodPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set blood pump control mode. +static PUMP_CONTROL_MODE_T bloodPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set blood pump control mode. +static F32 bloodFlowCalGain = 1.0; ///< blood flow calibration gain. +static F32 bloodFlowCalOffset = 0.0; ///< blood flow calibration offset. static OVERRIDE_U32_T bloodFlowDataPublishInterval = { BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, 0 }; ///< Interval (in ms) at which to publish blood flow data to CAN bus static OVERRIDE_S32_T targetBloodFlowRate = { 0, 0, 0, 0 }; ///< requested blood flow rate @@ -165,8 +166,8 @@ static U32 bpCurrErrorDurationCtr = 0; ///< used for tracking persistence of bp current errors -static BLOOD_FLOW_SELF_TEST_STATE_T bloodPumpSelfTestState = BLOOD_FLOW_SELF_TEST_STATE_START; ///< current blood pump self test state -static U32 bloodPumpSelfTestTimerCount = 0; ///< timer counter for blood pump self test +static BLOOD_FLOW_SELF_TEST_STATE_T bloodPumpSelfTestState = BLOOD_FLOW_SELF_TEST_STATE_START; ///< current blood pump self-test state +static U32 bloodPumpSelfTestTimerCount = 0; ///< timer counter for blood pump self-test // ********** private function prototypes ********** @@ -220,9 +221,9 @@ * @details * Inputs : isBloodPumpOn, bloodPumpDirectionSet * Outputs : targetBloodFlowRate, bloodPumpdirection, bloodPumpPWMDutyCyclePct - * @param flowRate : new target blood flow rate - * @param dir : new blood flow direction - * @param mode : new control mode + * @param flowRate new target blood flow rate + * @param dir new blood flow direction + * @param mode new control mode * @return TRUE if new flow rate & dir are set, FALSE if not *************************************************************************/ BOOL setBloodPumpTargetFlowRate( U32 flowRate, MOTOR_DIR_T dir, PUMP_CONTROL_MODE_T mode ) @@ -274,15 +275,15 @@ } else // requested flow rate too high { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_BLOOD_FLOW_SET_TOO_HIGH, flowRate ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_BLOOD_FLOW_SET_TOO_HIGH, flowRate ) } } return result; } /*********************************************************************//** - * @brief signalBloodPumpHardStop + * @brief * The signalBloodPumpHardStop function stops the blood pump immediately. * @details * Inputs : none @@ -301,8 +302,8 @@ /*********************************************************************//** * @brief - * The signalBloodPumpRotorHallSensor function handles the blood pump rotor \n - * hall sensor detection. Calculates rotor speed (in RPM). Stops pump if \n + * The signalBloodPumpRotorHallSensor function handles the blood pump rotor + * hall sensor detection. Calculates rotor speed (in RPM). Stops pump if * there is a pending request to home the pump. * @details * Inputs : bpRotorRevStartTime, bpStopAtHomePosition @@ -360,7 +361,7 @@ { U16 bpRPM = getIntADCReading( INT_ADC_BLOOD_PUMP_SPEED ); U16 bpmA = getIntADCReading( INT_ADC_BLOOD_PUMP_MOTOR_CURRENT ); - F32 bpFlow = getFPGABloodFlow(); + F32 bpFlow = ( ( getFPGABloodFlow() * -1.0 ) * bloodFlowCalGain ) + bloodFlowCalOffset; // blood flow sensor installed backwards on HD adcBloodPumpMCSpeedRPM.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpRPM)) * BP_SPEED_ADC_TO_RPM_FACTOR; adcBloodPumpMCCurrentmA.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpmA)) * BP_CURRENT_ADC_TO_MA_FACTOR; @@ -417,14 +418,14 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_BLOOD_FLOW_INVALID_BLOOD_PUMP_STATE, bloodPumpState ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_BLOOD_FLOW_INVALID_BLOOD_PUMP_STATE, bloodPumpState ) break; } } /*********************************************************************//** * @brief - * The handleBloodPumpOffState function handles the blood pump off state \n + * The handleBloodPumpOffState function handles the blood pump off state * of the blood pump controller state machine. * @details * Inputs : targetBloodFlowRate, bloodPumpDirection @@ -453,7 +454,7 @@ /*********************************************************************//** * @brief - * The handleBloodPumpRampingUpState function handles the ramp up state \n + * The handleBloodPumpRampingUpState function handles the ramp up state * of the blood pump controller state machine. * @details * Inputs : bloodPumpPWMDutyCyclePctSet @@ -498,7 +499,7 @@ /*********************************************************************//** * @brief - * The handleBloodPumpRampingDownState function handles the ramp down state \n + * The handleBloodPumpRampingDownState function handles the ramp down state * of the blood pump controller state machine. * @details * Inputs : bloodPumpPWMDutyCyclePctSet @@ -541,7 +542,7 @@ /*********************************************************************//** * @brief - * The handleBloodPumpControlToTargetState function handles the "control to \n + * The handleBloodPumpControlToTargetState function handles the "control to * target" state of the blood pump controller state machine. * @details * Inputs : none @@ -573,12 +574,12 @@ /*********************************************************************//** * @brief - * The setBloodPumpControlSignalPWM function sets the PWM duty cycle for \n + * The setBloodPumpControlSignalPWM function sets the PWM duty cycle for * the blood pump to a given %. * @details * Inputs : none * Outputs : blood pump stop signal activated, PWM duty cycle zeroed - * @param newPWM : new duty cycle % to apply to PWM + * @param newPWM new duty cycle % to apply to PWM * @return none *************************************************************************/ static void setBloodPumpControlSignalPWM( F32 newPWM ) @@ -617,12 +618,12 @@ /*********************************************************************//** * @brief - * The setBloodPumpDirection function sets the set blood pump direction to \n + * The setBloodPumpDirection function sets the set blood pump direction to * the given direction. * @details * Inputs : bloodPumpState * Outputs : bloodPumpState - * @param dir : blood pump direction to set + * @param dir blood pump direction to set * @return none *************************************************************************/ static void setBloodPumpDirection( MOTOR_DIR_T dir ) @@ -640,19 +641,19 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_BLOOD_FLOW_INVALID_BLOOD_PUMP_DIRECTION, dir ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_BLOOD_FLOW_INVALID_BLOOD_PUMP_DIRECTION, dir ) break; } } /*********************************************************************//** * @brief - * The getPublishBloodFlowDataInterval function gets the blood flow data \n + * The getPublishBloodFlowDataInterval function gets the blood flow data * publication interval. * @details * Inputs : bloodFlowDataPublishInterval * Outputs : none - * @return the current blood flow data publication interval (in ms). + * @return the current blood flow data publication interval (in task intervals). *************************************************************************/ U32 getPublishBloodFlowDataInterval( void ) { @@ -668,12 +669,12 @@ /*********************************************************************//** * @brief - * The getTargetBloodFlowRate function gets the current target blood flow \n + * The getTargetBloodFlowRate function gets the current target blood flow * rate. * @details * Inputs : targetBloodFlowRate * Outputs : none -/ * @return the current target blood flow rate (in mL/min). + * @return the current target blood flow rate (in mL/min). *************************************************************************/ S32 getTargetBloodFlowRate( void ) { @@ -689,7 +690,7 @@ /*********************************************************************//** * @brief - * The getMeasuredBloodFlowRate function gets the measured blood flow \n + * The getMeasuredBloodFlowRate function gets the measured blood flow * rate. * @details * Inputs : measuredBloodFlowRate @@ -710,7 +711,7 @@ /*********************************************************************//** * @brief - * The getMeasuredBloodPumpRotorSpeed function gets the measured blood flow \n + * The getMeasuredBloodPumpRotorSpeed function gets the measured blood flow * rate. * @details * Inputs : bloodPumpRotorSpeedRPM @@ -731,7 +732,7 @@ /*********************************************************************//** * @brief - * The getMeasuredBloodPumpSpeed function gets the measured blood flow \n + * The getMeasuredBloodPumpSpeed function gets the measured blood flow * rate. * @details * Inputs : bloodPumpSpeedRPM @@ -752,7 +753,7 @@ /*********************************************************************//** * @brief - * The getMeasuredBloodPumpMCSpeed function gets the measured blood pump \n + * The getMeasuredBloodPumpMCSpeed function gets the measured blood pump * speed. * @details * Inputs : adcBloodPumpMCSpeedRPM @@ -773,7 +774,7 @@ /*********************************************************************//** * @brief - * The getMeasuredBloodPumpMCCurrent function gets the measured blood pump \n + * The getMeasuredBloodPumpMCCurrent function gets the measured blood pump * current. * @details * Inputs : adcBloodPumpMCCurrentmA @@ -794,17 +795,17 @@ /*********************************************************************//** * @brief - * The publishBloodFlowData function publishes blood flow data at the set \n + * The publishBloodFlowData function publishes blood flow data at the set * interval. * @details - * Inputs : target flow rate, measured flow rate, measured MC speed, \n + * Inputs : target flow rate, measured flow rate, measured MC speed, * measured MC current * Outputs : Blood flow data is published to CAN bus. * @return none *************************************************************************/ static void publishBloodFlowData( void ) { - // publish blood flow data on interval + // publish blood flow data on interval #ifndef FLOW_DEBUG if ( ++bloodFlowDataPublicationTimerCounter >= getPublishBloodFlowDataInterval() ) #endif @@ -838,8 +839,8 @@ /*********************************************************************//** * @brief - * The resetBloodFlowMovingAverage function re-sizes and re-initializes the \n - * blood flow moving average sample buffer. + * The resetBloodFlowMovingAverage function re-initializes the blood flow + * moving average sample buffer. * @details * Inputs : none * Outputs : flowReadingsTotal, flowReadingsIdx, flowReadingsCount all set to zero. @@ -855,12 +856,11 @@ /*********************************************************************//** * @brief - * The filterBloodFlowReadings function adds a new flow sample to the filter \n - * if decimation rate for current set point calls for it. + * The filterBloodFlowReadings function adds a new flow sample to the filter. * @details * Inputs : none - * Outputs : flowReadings[], flowReadingsIdx, flowReadingsCount - * @param flow : newest blood flow sample + * Outputs : flowReadings[], flowReadingsIdx, flowReadingsCount, flowReadingsTotal + * @param flow newest blood flow sample * @return none *************************************************************************/ static void filterBloodFlowReadings( F32 flow ) @@ -882,8 +882,8 @@ /*********************************************************************//** * @brief - * The updateBloodPumpSpeedAndDirectionFromHallSensors function calculates \n - * the blood pump motor speed and direction from hall sensor counter on \n + * The updateBloodPumpSpeedAndDirectionFromHallSensors function calculates + * the blood pump motor speed and direction from hall sensor counter on * a 1 second interval. * @details * Inputs : bpLastMotorHallSensorCount, bpMotorSpeedCalcTimerCtr, current count from FPGA @@ -921,8 +921,8 @@ /*********************************************************************//** * @brief - * The checkBloodPumpRotor function checks the rotor for the blood \n - * pump. If homing, this function will stop when hall sensor detected. If pump \n + * 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. * @details * Inputs : bpStopAtHomePosition, bpHomeStartTime, bpRotorRevStartTime @@ -956,7 +956,7 @@ /*********************************************************************//** * @brief - * The checkBloodPumpDirection function checks the set direction vs. \n + * The checkBloodPumpDirection function checks the set direction vs. * the direction implied by the sign of the measured MC speed. * @details * Inputs : @@ -982,11 +982,11 @@ /*********************************************************************//** * @brief - * The checkBloodPumpSpeeds function checks several aspects of the blood pump \n - * speed. \n - * 1. while pump is commanded off, measured motor speed should be < limit. \n - * 2. while pump is controlling, measured motor speed should be within allowed range of commanded speed. \n - * 3. measured motor speed should be within allowed range of measured rotor speed. \n + * The checkBloodPumpSpeeds function checks several aspects of the blood pump + * speed. + * 1. while pump is commanded off, measured motor speed should be < limit. + * 2. while pump is controlling, measured motor speed should be within allowed range of commanded speed. + * 3. measured motor speed should be within allowed range of measured rotor speed. * All 3 checks have a persistence time that must be met before an alarm is triggered. * @details * Inputs : targetBloodFlowRate, bloodPumpSpeedRPM, bloodPumpRotorSpeedRPM @@ -1023,10 +1023,10 @@ if ( BLOOD_PUMP_CONTROL_TO_TARGET_STATE == bloodPumpState ) { F32 cmdMotorSpeed = ( (F32)cmdRate / (F32)ML_PER_LITER ) * BP_REV_PER_LITER * BP_GEAR_RATIO; - F32 deltaMotorSpeed = FABS( measMotorSpeed - cmdMotorSpeed ); + F32 deltaMotorSpeed = fabs( measMotorSpeed - cmdMotorSpeed ); F32 measRotorSpeed = getMeasuredBloodPumpRotorSpeed(); F32 measMotorSpeedInRotorRPM = measMotorSpeed / BP_GEAR_RATIO; - F32 deltaRotorSpeed = FABS( measRotorSpeed - measMotorSpeedInRotorRPM ); + F32 deltaRotorSpeed = fabs( measRotorSpeed - measMotorSpeedInRotorRPM ); // check measured motor speed vs. commanded motor speed while controlling to target if ( deltaMotorSpeed > BP_MAX_MOTOR_SPEED_ERROR_RPM ) @@ -1068,9 +1068,9 @@ /*********************************************************************//** * @brief - * The checkBloodPumpFlowAgainstSpeed function checks the measured blood flow \n - * against the implied flow of the measured pump speed when in treatment mode \n - * and controlling to target flow. If a sufficient difference persists, a \n + * The checkBloodPumpFlowAgainstSpeed function checks the measured blood flow + * against the implied flow of the measured pump speed when in treatment mode + * and controlling to target flow. If a sufficient difference persists, a * flow vs. motor speed check error is triggered. * @details * Inputs : measuredBloodFlowRate, bloodPumpSpeedRPM, errorBloodFlowVsMotorSpeedPersistTimerCtr @@ -1085,7 +1085,7 @@ F32 flow = getMeasuredBloodFlowRate(); F32 speed = getMeasuredBloodPumpSpeed(); F32 impliedFlow = ( ( speed / BP_GEAR_RATIO ) / BP_REV_PER_LITER ) * (F32)ML_PER_LITER; - F32 delta = FABS( flow - impliedFlow ); + F32 delta = fabs( flow - impliedFlow ); if ( delta > BP_MAX_FLOW_VS_SPEED_DIFF_ML_MIN ) { @@ -1109,7 +1109,7 @@ /*********************************************************************//** * @brief - * The checkBloodPumpMCCurrent function checks the measured MC current vs. \n + * The checkBloodPumpMCCurrent function checks the measured MC current vs. * the set state of the blood pump (stopped or running). * @details * Inputs : @@ -1162,19 +1162,42 @@ /*********************************************************************//** * @brief - * The execBloodFlowTest function executes the state machine for the \n - * BloodFlow self test. + * The execBloodFlowTest function executes the state machine for the + * BloodFlow self-test. * @details * Inputs : none * Outputs : none - * @return the current state of the BloodFlow self test. + * @return the current state of the BloodFlow self-test. *************************************************************************/ SELF_TEST_STATUS_T execBloodFlowTest( void ) { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_FAILED; + CALIBRATION_DATA_T cal; + + switch ( bloodPumpSelfTestState ) + { + case BLOOD_FLOW_SELF_TEST_STATE_START: + // retrieve blood flow sensor calibration data + if ( TRUE == getCalibrationData( &cal ) ) + { + bloodFlowCalGain = cal.bloodFlowGain; + bloodFlowCalOffset = cal.bloodFlowOffset_mL_min; + bloodPumpSelfTestState = BLOOD_FLOW_TEST_STATE_COMPLETE; // TODO - implement rest of self-test(s) + result = SELF_TEST_STATUS_PASSED; + } + break; + + case BLOOD_FLOW_TEST_STATE_IN_PROGRESS: + break; + + case BLOOD_FLOW_TEST_STATE_COMPLETE: + break; + + default: + // TODO - s/w fault + break; + } - // TODO - implement self test(s) - return result; } @@ -1184,14 +1207,66 @@ *************************************************************************/ +/*********************************************************************//** + * @brief + * The setBloodFlowCalibration function sets the blood flow calibration + * factors and has them stored in non-volatile memory. + * @details + * Inputs : none + * Outputs : bloodFlowCalGain, bloodFlowCalOffset + * @param gain gain calibration factor for blood flow sensor + * @param offset offset calibration factor for blood flow sensor + * @return TRUE if calibration factors successfully set/stored, FALSE if not + *************************************************************************/ +BOOL setBloodFlowCalibration( F32 gain, F32 offset ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + CALIBRATION_DATA_T cal; + + getCalibrationData( &cal ); + // keep locally and apply immediately + bloodFlowCalGain = gain; + bloodFlowCalOffset = offset; + // also update calibration record in non-volatile memory + cal.bloodFlowGain = gain; + cal.bloodFlowOffset_mL_min = offset; + if ( TRUE == setCalibrationData( cal ) ) + { + result = TRUE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getBloodFlowCalibration function retrieves the current blood flow + * calibration factors. + * @details + * Inputs : bloodFlowCalGain, bloodFlowCalOffset + * Outputs : none + * @param gain value to populate with gain calibration factor for blood flow sensor + * @param offset value to populate with offset calibration factor for blood flow sensor + * @return none + *************************************************************************/ +void getBloodFlowCalibration( F32 *gain, F32 *offset ) +{ + *gain = bloodFlowCalGain; + *offset = bloodFlowCalOffset; +} + /*********************************************************************//** * @brief - * The testSetBloodFlowDataPublishIntervalOverride function overrides the \n + * The testSetBloodFlowDataPublishIntervalOverride function overrides the * blood flow data publish interval. * @details * Inputs : none * Outputs : bloodFlowDataPublishInterval - * @param value : override blood flow data publish interval with (in ms) + * @param value override blood flow data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetBloodFlowDataPublishIntervalOverride( U32 value ) @@ -1212,7 +1287,7 @@ /*********************************************************************//** * @brief - * The testResetBloodFlowDataPublishIntervalOverride function resets the override \n + * The testResetBloodFlowDataPublishIntervalOverride function resets the override * of the blood flow data publish interval. * @details * Inputs : none @@ -1235,15 +1310,16 @@ /*********************************************************************//** * @brief - * The testSetTargetBloodFlowRateOverride function overrides the target \n + * The testSetTargetBloodFlowRateOverride function overrides the target * blood flow rate. * @details * Inputs : none * Outputs : targetBloodFlowRate - * @param value : override target blood flow rate (in mL/min) + * @param value override target blood flow rate (in mL/min) + * @param ctrlMode override pump control mode to this mode (0 = closed loop, 1 = open loop) * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetTargetBloodFlowRateOverride( S32 value ) +BOOL testSetTargetBloodFlowRateOverride( S32 value, U32 ctrlMode ) { BOOL result = FALSE; @@ -1258,19 +1334,22 @@ else { dir = MOTOR_DIR_FORWARD; + } + if ( ctrlMode < NUM_OF_PUMP_CONTROL_MODES ) + { + targetBloodFlowRate.ovInitData = targetBloodFlowRate.data; // backup current target flow rate + targetBloodFlowRate.ovData = value; + targetBloodFlowRate.override = OVERRIDE_KEY; + result = setBloodPumpTargetFlowRate( abs(value), dir, (PUMP_CONTROL_MODE_T)ctrlMode ); } - targetBloodFlowRate.ovInitData = targetBloodFlowRate.data; // backup current target flow rate - targetBloodFlowRate.ovData = value; - targetBloodFlowRate.override = OVERRIDE_KEY; - result = setBloodPumpTargetFlowRate( ABS(value), dir, bloodPumpControlMode ); } return result; } /*********************************************************************//** * @brief - * The testResetTargetBloodFlowRateOverride function resets the override of the \n + * The testResetTargetBloodFlowRateOverride function resets the override of the * target blood flow rate. * @details * Inputs : none @@ -1295,12 +1374,12 @@ /*********************************************************************//** * @brief - * The testResetMeasuredBloodFlowRateOverride function overrides the measured \n + * The testResetMeasuredBloodFlowRateOverride function overrides the measured * blood flow rate. * @details * Inputs : none * Outputs : measuredBloodFlowRate - * @param value : override measured blood flow rate (in mL/min) + * @param value override measured blood flow rate (in mL/min) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredBloodFlowRateOverride( F32 value ) @@ -1319,7 +1398,7 @@ /*********************************************************************//** * @brief - * The testResetOffButtonStateOverride function resets the override of the \n + * The testResetOffButtonStateOverride function resets the override of the * measured blood flow rate. * @details * Inputs : none @@ -1342,12 +1421,12 @@ /*********************************************************************//** * @brief - * The testSetMeasuredBloodPumpRotorSpeedOverride function overrides the measured \n + * The testSetMeasuredBloodPumpRotorSpeedOverride function overrides the measured * blood pump rotor speed. * @details * Inputs : none * Outputs : bloodPumpRotorSpeedRPM - * @param value : override measured blood pump rotor speed (in RPM) + * @param value override measured blood pump rotor speed (in RPM) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredBloodPumpRotorSpeedOverride( F32 value ) @@ -1366,7 +1445,7 @@ /*********************************************************************//** * @brief - * The testResetMeasuredBloodPumpRotorSpeedOverride function resets the override of the \n + * The testResetMeasuredBloodPumpRotorSpeedOverride function resets the override of the * measured blood pump rotor speed. * @details * Inputs : none @@ -1389,12 +1468,12 @@ /*********************************************************************//** * @brief - * The testSetMeasuredBloodPumpSpeedOverride function overrides the measured \n + * The testSetMeasuredBloodPumpSpeedOverride function overrides the measured * blood pump motor speed. * @details * Inputs : none * Outputs : bloodPumpSpeedRPM - * @param value : override measured blood pump motor speed (in RPM) + * @param value override measured blood pump motor speed (in RPM) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredBloodPumpSpeedOverride( F32 value ) @@ -1413,7 +1492,7 @@ /*********************************************************************//** * @brief - * The testResetMeasuredBloodPumpSpeedOverride function resets the override of the \n + * The testResetMeasuredBloodPumpSpeedOverride function resets the override of the * measured blood pump motor speed. * @details * Inputs : none @@ -1436,12 +1515,12 @@ /*********************************************************************//** * @brief - * The testSetMeasuredBloodPumpMCSpeedOverride function overrides the measured \n + * The testSetMeasuredBloodPumpMCSpeedOverride function overrides the measured * blood pump motor speed. * @details * Inputs : none * Outputs : adcBloodPumpMCSpeedRPM - * @param value : override measured blood pump speed (in RPM) + * @param value override measured blood pump speed (in RPM) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredBloodPumpMCSpeedOverride( F32 value ) @@ -1460,7 +1539,7 @@ /*********************************************************************//** * @brief - * The testResetMeasuredBloodPumpMCSpeedOverride function resets the override of the \n + * The testResetMeasuredBloodPumpMCSpeedOverride function resets the override of the * measured blood pump motor speed. * @details * Inputs : none @@ -1483,12 +1562,12 @@ /*********************************************************************//** * @brief - * The testSetMeasuredBloodPumpMCCurrentOverride function overrides the measured \n + * The testSetMeasuredBloodPumpMCCurrentOverride function overrides the measured * blood pump motor current. * @details * Inputs : none * Outputs : adcBloodPumpMCCurrentmA - * @param value : override measured blood pump current (in mA) + * @param value override measured blood pump current (in mA) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredBloodPumpMCCurrentOverride( F32 value ) @@ -1507,7 +1586,7 @@ /*********************************************************************//** * @brief - * The testResetMeasuredBloodPumpMCCurrentOverride function resets the override of the \n + * The testResetMeasuredBloodPumpMCCurrentOverride function resets the override of the * measured blood pump motor current. * @details * Inputs : none