Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -ra4e46c97c83207cc4babf4caad15160ff329507b -rfff308d96794e7df7e91149173c3760ff3fda10c --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision a4e46c97c83207cc4babf4caad15160ff329507b) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision fff308d96794e7df7e91149173c3760ff3fda10c) @@ -59,7 +59,7 @@ /// interval (ms/task time) at which the blood pump speed is calculated (every 40 ms). #define BP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) /// number of hall sensor counts kept in buffer to hold last 1 second of count data. -#define BP_SPEED_CALC_BUFFER__LEN ( 1000 / BP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) +#define BP_SPEED_CALC_BUFFER_LEN ( 1000 / BP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) #define BP_HALL_EDGE_COUNTS_PER_REV 48 ///< number of hall sensor edge counts per motor revolution. #define BP_MAX_ROTOR_SPEED_RPM 100.0 ///< maximum rotor speed allowed for blood pump. @@ -140,8 +140,9 @@ 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 +/// Interval (in ms) at which to publish blood flow data to CAN bus +static OVERRIDE_U32_T bloodFlowDataPublishInterval = { BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, 0 }; +static S32 targetBloodFlowRate = 0; ///< requested blood flow rate static OVERRIDE_F32_T measuredBloodFlowRate = { 0.0, 0.0, 0.0, 0 }; ///< measured blood flow rate static OVERRIDE_F32_T bloodPumpRotorSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump rotor speed static OVERRIDE_F32_T bloodPumpSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump motor speed @@ -154,7 +155,7 @@ static BOOL bpStopAtHomePosition = FALSE; ///< stop blood pump at next home position static U32 bpHomeStartTime = 0; ///< when did blood pump home command begin? (in ms) -static U16 bpLastMotorHallSensorCounts[ BP_SPEED_CALC_BUFFER__LEN ]; ///< last hall sensor count for the blood pump motor +static U16 bpLastMotorHallSensorCounts[ BP_SPEED_CALC_BUFFER_LEN ]; ///< last hall sensor count for the blood pump motor static U32 bpMotorSpeedCalcIdx = 0; ///< index into 1 second buffer of motor speed hall sensor counts static MOTOR_DIR_T bpMotorDirectionFromHallSensors = MOTOR_DIR_FORWARD; ///< pump direction according to hall sensor count static U32 bpMotorSpeedCalcTimerCtr = 0; ///< counter determines interval for calculating blood pump motor speed from hall sensor count. @@ -215,7 +216,7 @@ // zero motor hall sensors counts buffer bpMotorSpeedCalcIdx = 0; - for ( i = 0; i < BP_SPEED_CALC_BUFFER__LEN; i++ ) + for ( i = 0; i < BP_SPEED_CALC_BUFFER_LEN; i++ ) { bpLastMotorHallSensorCounts[ i ] = 0; } @@ -249,7 +250,7 @@ if ( flowRate <= MAX_BLOOD_FLOW_RATE ) { resetBloodFlowMovingAverage(); - targetBloodFlowRate.data = ( dir == MOTOR_DIR_FORWARD ? (S32)flowRate : (S32)flowRate * -1 ); + targetBloodFlowRate = ( dir == MOTOR_DIR_FORWARD ? (S32)flowRate : (S32)flowRate * -1 ); bloodPumpDirection = dir; bloodPumpControlMode = mode; // set PWM duty cycle target to an estimated initial target to ramp to based on target flow rate - then we'll control to flow when ramp completed @@ -304,7 +305,7 @@ *************************************************************************/ void signalBloodPumpHardStop( void ) { - targetBloodFlowRate.data = 0; + targetBloodFlowRate = 0; stopBloodPump(); bloodPumpState = BLOOD_PUMP_OFF_STATE; bloodPumpPWMDutyCyclePct = 0.0; @@ -449,7 +450,7 @@ BLOOD_PUMP_STATE_T result = BLOOD_PUMP_OFF_STATE; // if we've been given a flow rate, setup ramp up and transition to ramp up state - if ( getTargetBloodFlowRate() != 0 ) + if ( targetBloodFlowRate != 0 ) { // set initial PWM duty cycle bloodPumpPWMDutyCyclePctSet = BP_PWM_ZERO_OFFSET + MAX_BLOOD_PUMP_PWM_STEP_UP_CHANGE; @@ -478,7 +479,7 @@ BLOOD_PUMP_STATE_T result = BLOOD_PUMP_RAMPING_UP_STATE; // have we been asked to stop the blood pump? - if ( 0 == getTargetBloodFlowRate() ) + if ( 0 == targetBloodFlowRate ) { // start ramp down to stop bloodPumpPWMDutyCyclePctSet -= MAX_BLOOD_PUMP_PWM_STEP_DN_CHANGE; @@ -570,7 +571,7 @@ { if ( bloodPumpControlModeSet == PUMP_CONTROL_MODE_CLOSED_LOOP ) { - F32 tgtFlow = (F32)getTargetBloodFlowRate(); + F32 tgtFlow = (F32)targetBloodFlowRate; F32 actFlow = getMeasuredBloodFlowRate(); F32 newPWM; @@ -681,27 +682,6 @@ /*********************************************************************//** * @brief - * 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). - *************************************************************************/ -S32 getTargetBloodFlowRate( void ) -{ - S32 result = targetBloodFlowRate.data; - - if ( OVERRIDE_KEY == targetBloodFlowRate.override ) - { - result = targetBloodFlowRate.ovData; - } - - return result; -} - -/*********************************************************************//** - * @brief * The getMeasuredBloodFlowRate function gets the measured blood flow * rate. * @details @@ -822,7 +802,7 @@ if ( ++bloodFlowDataPublicationTimerCounter >= getPublishBloodFlowDataInterval() ) #endif { - S32 flowStPt = (S32)getTargetBloodFlowRate(); + S32 flowStPt = targetBloodFlowRate; F32 measFlow = getMeasuredBloodFlowRate(); F32 measRotSpd = getMeasuredBloodPumpRotorSpeed(); F32 measSpd = getMeasuredBloodPumpSpeed(); @@ -907,7 +887,7 @@ if ( ++bpMotorSpeedCalcTimerCtr >= BP_SPEED_CALC_INTERVAL ) { U16 bpMotorHallSensorCount = getFPGABloodPumpHallSensorCount(); - U32 nextIdx = INC_WRAP( bpMotorSpeedCalcIdx, 0, BP_SPEED_CALC_BUFFER__LEN - 1 ); + U32 nextIdx = INC_WRAP( bpMotorSpeedCalcIdx, 0, BP_SPEED_CALC_BUFFER_LEN - 1 ); U16 incDelta = ( bpMotorHallSensorCount >= bpLastMotorHallSensorCounts[ nextIdx ] ? \ bpMotorHallSensorCount - bpLastMotorHallSensorCounts[ nextIdx ] : \ ( HEX_64_K - bpLastMotorHallSensorCounts[ nextIdx ] ) + bpMotorHallSensorCount ); @@ -1012,7 +992,7 @@ static void checkBloodPumpSpeeds( void ) { F32 measMotorSpeed = getMeasuredBloodPumpSpeed(); - S32 cmdRate = getTargetBloodFlowRate(); + S32 cmdRate = targetBloodFlowRate; // check for pump running while commanded off if ( 0 == cmdRate ) @@ -1353,7 +1333,7 @@ } if ( ctrlMode < NUM_OF_PUMP_CONTROL_MODES ) { - targetBloodFlowRate.data = value; + targetBloodFlowRate = value; result = setBloodPumpTargetFlowRate( abs(value), dir, (PUMP_CONTROL_MODE_T)ctrlMode ); } }