Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -rc0273c73da6b6dee4ad6f1d54cb6c6f27a262b5b -r3ded5ffcbcade3f1da5d40c52936ab5f97fc6ec9 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision c0273c73da6b6dee4ad6f1d54cb6c6f27a262b5b) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 3ded5ffcbcade3f1da5d40c52936ab5f97fc6ec9) @@ -27,7 +27,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" @@ -133,7 +134,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 @@ -360,7 +363,7 @@ { U16 bpRPM = getIntADCReading( INT_ADC_BLOOD_PUMP_SPEED ); U16 bpmA = getIntADCReading( INT_ADC_BLOOD_PUMP_MOTOR_CURRENT ); - F32 bpFlow = getFPGABloodFlow(); + F32 bpFlow = ( getFPGABloodFlow() + bloodFlowCalOffset ) * bloodFlowCalGain; 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; @@ -652,7 +655,7 @@ * @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 ) { @@ -838,8 +841,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 \n + * moving average sample buffer. * @details * Inputs : none * Outputs : flowReadingsTotal, flowReadingsIdx, flowReadingsCount all set to zero. @@ -855,11 +858,10 @@ /*********************************************************************//** * @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 + * Outputs : flowReadings[], flowReadingsIdx, flowReadingsCount, flowReadingsTotal * @param flow : newest blood flow sample * @return none *************************************************************************/ @@ -1172,9 +1174,32 @@ 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,6 +1209,59 @@ *************************************************************************/ +/*********************************************************************//** + * @brief + * The setBloodFlowCalibration function sets the blood flow calibration \n + * 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; + + if ( TRUE == 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 \n + * 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