Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -rde5a0d43bdef611d963d11855bc958a8d8899a09 -ra3a01327c8fe80f65f6658ae6cbef4910a4a8033 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision de5a0d43bdef611d963d11855bc958a8d8899a09) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision a3a01327c8fe80f65f6658ae6cbef4910a4a8033) @@ -15,16 +15,15 @@ * ***************************************************************************/ -#ifndef _VECTORCAST_ - #include -#endif +#include #include "etpwm.h" #include "gio.h" #include "mibspi.h" #include "FPGA.h" #include "InternalADC.h" +#include "NVDataMgmt.h" #include "OperationModes.h" #include "PIControllers.h" #include "SystemCommMessages.h" @@ -48,8 +47,8 @@ #define MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.12 ///< controller will error if PWM duty cycle < 10%, so set min to 12% #define DIP_CONTROL_INTERVAL ( 10000 / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the dialIn pump is controlled -#define DIP_P_COEFFICIENT 0.00005 ///< P term for dialIn pump control -#define DIP_I_COEFFICIENT 0.00015 ///< I term for dialIn pump control +#define DIP_P_COEFFICIENT 0.00035 ///< P term for dialIn pump control +#define DIP_I_COEFFICIENT 0.00035 ///< I term for dialIn pump control #define DIP_HOME_RATE 100 ///< target pump speed (in estimate mL/min) for homing. #define DIP_HOME_TIMEOUT_MS 10000 ///< maximum time allowed for homing to complete (in ms). @@ -77,7 +76,7 @@ #define DIP_REV_PER_LITER 150.24 ///< rotor revolutions per liter #define DIP_ML_PER_MIN_TO_PUMP_RPM_FACTOR ( DIP_REV_PER_LITER / ML_PER_LITER ) ///< #define DIP_GEAR_RATIO 32.0 ///< dialIn pump motor to dialIn pump gear ratio -#define DIP_MOTOR_RPM_TO_PWM_DC_FACTOR 0.00035 ///< ~28 BP motor RPM = 1% PWM duty cycle +#define DIP_MOTOR_RPM_TO_PWM_DC_FACTOR 0.00028 ///< ~28 BP motor RPM = 1% PWM duty cycle #define DIP_PWM_ZERO_OFFSET 0.1 ///< 10% PWM duty cycle = zero speed #define DIP_PWM_FROM_ML_PER_MIN(rate) ( (rate) * DIP_ML_PER_MIN_TO_PUMP_RPM_FACTOR * DIP_GEAR_RATIO * DIP_MOTOR_RPM_TO_PWM_DC_FACTOR + DIP_PWM_ZERO_OFFSET ) ///< @@ -97,13 +96,13 @@ NUM_OF_DIAL_IN_PUMP_STATES ///< Number of dialysate inlet pump states. } DIAL_IN_PUMP_STATE_T; -/// Enumeration of dialysate inlet self test states. +/// Enumeration of dialysate inlet self-test states. typedef enum DialInFlow_Self_Test_States { - DIAL_IN_FLOW_SELF_TEST_STATE_START = 0, ///< Start state for the dialysate inlet pump self test. - DIAL_IN_FLOW_TEST_STATE_IN_PROGRESS, ///< Test in progress state for the dialysate inlet pump self test. - DIAL_IN_FLOW_TEST_STATE_COMPLETE, ///< Test completed state for the dialysate inlet pump self test. - NUM_OF_DIAL_IN_FLOW_SELF_TEST_STATES ///< Number of dialysate inlet pump self test states. + DIAL_IN_FLOW_SELF_TEST_STATE_START = 0, ///< Start state for the dialysate inlet pump self-test. + DIAL_IN_FLOW_TEST_STATE_IN_PROGRESS, ///< Test in progress state for the dialysate inlet pump self-test. + DIAL_IN_FLOW_TEST_STATE_COMPLETE, ///< Test completed state for the dialysate inlet pump self-test. + NUM_OF_DIAL_IN_FLOW_SELF_TEST_STATES ///< Number of dialysate inlet pump self-test states. } DIAL_IN_FLOW_SELF_TEST_STATE_T; // pin assignments for pump stop and direction outputs @@ -127,10 +126,12 @@ static BOOL isDialInPumpOn = FALSE; ///< dialIn pump is currently running static F32 dialInPumpPWMDutyCyclePct = 0.0; ///< initial dialIn pump PWM duty cycle static F32 dialInPumpPWMDutyCyclePctSet = 0.0; ///< currently set dialIn pump PWM duty cycle -static MOTOR_DIR_T dialInPumpDirection = MOTOR_DIR_FORWARD; ///< requested dialIn flow direction -static MOTOR_DIR_T dialInPumpDirectionSet = MOTOR_DIR_FORWARD; ///< currently set dialIn flow direction +static MOTOR_DIR_T dialInPumpDirection = MOTOR_DIR_FORWARD; ///< requested dialysate flow direction +static MOTOR_DIR_T dialInPumpDirectionSet = MOTOR_DIR_FORWARD; ///< currently set dialysate flow direction static PUMP_CONTROL_MODE_T dialInPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< requested dialIn pump control mode. static PUMP_CONTROL_MODE_T dialInPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP;///< currently set dialIn pump control mode. +static F32 dialInFlowCalGain = 1.0; ///< dialysate flow calibration gain. +static F32 dialInFlowCalOffset = 0.0; ///< dialysate flow calibration offset. static OVERRIDE_U32_T dialInFlowDataPublishInterval = { DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, 0 }; ///< interval (in ms) at which to publish dialIn flow data to CAN bus static OVERRIDE_S32_T targetDialInFlowRate = { 0, 0, 0, 0 }; ///< requested dialIn flow rate @@ -162,8 +163,8 @@ static U32 dipCurrErrorDurationCtr = 0; ///< used for tracking persistence of dip current errors -static DIAL_IN_FLOW_SELF_TEST_STATE_T dialInPumpSelfTestState = DIAL_IN_FLOW_SELF_TEST_STATE_START; ///< current dialIn pump self test state -static U32 dialInPumpSelfTestTimerCount = 0; ///< timer counter for dialIn pump self test +static DIAL_IN_FLOW_SELF_TEST_STATE_T dialInPumpSelfTestState = DIAL_IN_FLOW_SELF_TEST_STATE_START; ///< current dialIn pump self-test state +static U32 dialInPumpSelfTestTimerCount = 0; ///< timer counter for dialIn pump self-test // ********** private function prototypes ********** @@ -217,9 +218,9 @@ * @details * Inputs : isDialInPumpOn, dialInPumpDirectionSet * Outputs : targetDialInFlowRate, dialInPumpdirection, dialInPumpPWMDutyCyclePct - * @param flowRate : new target dialIn flow rate - * @param dir : new dialIn flow direction - * @param mode : new control mode + * @param flowRate new target dialIn flow rate + * @param dir new dialIn flow direction + * @param mode new control mode * @return TRUE if new flow rate & dir are set, FALSE if not *************************************************************************/ BOOL setDialInPumpTargetFlowRate( U32 flowRate, MOTOR_DIR_T dir, PUMP_CONTROL_MODE_T mode ) @@ -271,7 +272,7 @@ } else // requested flow rate too high { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_DIAL_IN_FLOW_SET_TOO_HIGH, flowRate ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_DIAL_IN_FLOW_SET_TOO_HIGH, flowRate ) } } @@ -298,8 +299,8 @@ /*********************************************************************//** * @brief - * The signalDialInPumpRotorHallSensor function handles the dialysate inlet pump rotor \n - * hall sensor detection. Calculates rotor speed (in RPM). Stops pump if \n + * The signalDialInPumpRotorHallSensor function handles the dialysate inlet pump rotor + * hall sensor detection. Calculates rotor speed (in RPM). Stops pump if * there is a pending request to home the pump. * @details * Inputs : dipRotorRevStartTime, dipStopAtHomePosition @@ -357,7 +358,7 @@ { U16 dipRPM = getIntADCReading( INT_ADC_DIAL_IN_PUMP_SPEED ); U16 dipmA = getIntADCReading( INT_ADC_DIAL_IN_PUMP_MOTOR_CURRENT ); - F32 dipFlow = getFPGADialysateFlow(); + F32 dipFlow = ( getFPGADialysateFlow() * dialInFlowCalGain ) + dialInFlowCalOffset; adcDialInPumpMCSpeedRPM.data = (F32)(SIGN_FROM_12_BIT_VALUE(dipRPM)) * DIP_SPEED_ADC_TO_RPM_FACTOR; adcDialInPumpMCCurrentmA.data = (F32)(SIGN_FROM_12_BIT_VALUE(dipmA)) * DIP_CURRENT_ADC_TO_MA_FACTOR; @@ -414,14 +415,14 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_DIAL_IN_FLOW_INVALID_DIAL_IN_PUMP_STATE, dialInPumpState ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_DIAL_IN_FLOW_INVALID_DIAL_IN_PUMP_STATE, dialInPumpState ) break; } } /*********************************************************************//** * @brief - * The handleDialInPumpOffState function handles the dialIn pump off state \n + * The handleDialInPumpOffState function handles the dialIn pump off state * of the dialIn pump controller state machine. * @details * Inputs : targetDialInFlowRate, dialInPumpDirection @@ -450,7 +451,7 @@ /*********************************************************************//** * @brief - * The handleDialInPumpRampingUpState function handles the ramp up state \n + * The handleDialInPumpRampingUpState function handles the ramp up state * of the dialIn pump controller state machine. * @details * Inputs : dialInPumpPWMDutyCyclePctSet @@ -495,7 +496,7 @@ /*********************************************************************//** * @brief - * The handleDialInPumpRampingDownState function handles the ramp down state \n + * The handleDialInPumpRampingDownState function handles the ramp down state * of the dialIn pump controller state machine. * @details * Inputs : dialInPumpPWMDutyCyclePctSet @@ -538,7 +539,7 @@ /*********************************************************************//** * @brief - * The handleDialInPumpControlToTargetState function handles the "control to \n + * The handleDialInPumpControlToTargetState function handles the "control to * target" state of the dialIn pump controller state machine. * @details * Inputs : none @@ -570,12 +571,12 @@ /*********************************************************************//** * @brief - * The setDialInPumpControlSignalPWM function sets the PWM duty cycle for \n + * The setDialInPumpControlSignalPWM function sets the PWM duty cycle for * the dialysate inlet pump to a given %. * @details * Inputs : none * Outputs : dialIn 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 setDialInPumpControlSignalPWM( F32 newPWM ) @@ -614,12 +615,12 @@ /*********************************************************************//** * @brief - * The setDialInPumpDirection function sets the set dialIn pump direction to \n + * The setDialInPumpDirection function sets the set dialIn pump direction to * the given direction. * @details * Inputs : dialInPumpState * Outputs : dialInPumpState - * @param dir : dialIn pump direction to set + * @param dir dialIn pump direction to set * @return none *************************************************************************/ static void setDialInPumpDirection( MOTOR_DIR_T dir ) @@ -637,94 +638,164 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_DIAL_IN_FLOW_INVALID_DIAL_IN_PUMP_DIRECTION, dir ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_DIAL_IN_FLOW_INVALID_DIAL_IN_PUMP_DIRECTION, dir ) break; } } /*********************************************************************//** * @brief - * The getPublishDialInFlowDataInterval function gets the dialIn flow data \n + * The getPublishDialInFlowDataInterval function gets the dialIn flow data * publication interval. * @details * Inputs : dialInFlowDataPublishInterval * Outputs : none - * @return the current dialIn flow data publication interval (in ms). + * @return the current dialIn flow data publication interval (in task intervals). *************************************************************************/ -DATA_GET( U32, getPublishDialInFlowDataInterval, dialInFlowDataPublishInterval ) +U32 getPublishDialInFlowDataInterval( void ) +{ + U32 result = dialInFlowDataPublishInterval.data; + + if ( OVERRIDE_KEY == dialInFlowDataPublishInterval.override ) + { + result = dialInFlowDataPublishInterval.ovData; + } + + return result; +} /*********************************************************************//** * @brief - * The getTargetDialInFlowRate function gets the current target dialIn flow \n + * The getTargetDialInFlowRate function gets the current target dialIn flow * rate. * @details * Inputs : targetDialInFlowRate * Outputs : none * @return the current target dialIn flow rate (in mL/min). *************************************************************************/ -DATA_GET( S32, getTargetDialInFlowRate, targetDialInFlowRate ) +S32 getTargetDialInFlowRate( void ) +{ + S32 result = targetDialInFlowRate.data; + + if ( OVERRIDE_KEY == targetDialInFlowRate.override ) + { + result = targetDialInFlowRate.ovData; + } + + return result; +} /*********************************************************************//** * @brief - * The getMeasuredDialInFlowRate function gets the measured dialIn flow \n + * The getMeasuredDialInFlowRate function gets the measured dialIn flow * rate. * @details * Inputs : measuredDialInFlowRate * Outputs : none -/ * @return the current dialIn flow rate (in mL/min). + * @return the current dialIn flow rate (in mL/min). *************************************************************************/ -DATA_GET( F32, getMeasuredDialInFlowRate, measuredDialInFlowRate ) +F32 getMeasuredDialInFlowRate( void ) +{ + F32 result = measuredDialInFlowRate.data; + + if ( OVERRIDE_KEY == measuredDialInFlowRate.override ) + { + result = measuredDialInFlowRate.ovData; + } + + return result; +} /*********************************************************************//** * @brief - * The getMeasuredDialInPumpRotorSpeed function gets the measured dialIn flow \n + * The getMeasuredDialInPumpRotorSpeed function gets the measured dialIn flow * rate. * @details * Inputs : dialInPumpRotorSpeedRPM * Outputs : none * @return the current dialIn flow rate (in mL/min). *************************************************************************/ -DATA_GET( F32, getMeasuredDialInPumpRotorSpeed, dialInPumpRotorSpeedRPM ) +F32 getMeasuredDialInPumpRotorSpeed( void ) +{ + F32 result = dialInPumpRotorSpeedRPM.data; + + if ( OVERRIDE_KEY == dialInPumpRotorSpeedRPM.override ) + { + result = dialInPumpRotorSpeedRPM.ovData; + } + + return result; +} /*********************************************************************//** * @brief - * The getMeasuredDialInPumpSpeed function gets the measured dialIn flow \n + * The getMeasuredDialInPumpSpeed function gets the measured dialIn flow * rate. * @details * Inputs : dialInPumpSpeedRPM * Outputs : none * @return the current dialIn flow rate (in mL/min). *************************************************************************/ -DATA_GET( F32, getMeasuredDialInPumpSpeed, dialInPumpSpeedRPM ) +F32 getMeasuredDialInPumpSpeed( void ) +{ + F32 result = dialInPumpSpeedRPM.data; + + if ( OVERRIDE_KEY == dialInPumpSpeedRPM.override ) + { + result = dialInPumpSpeedRPM.ovData; + } + + return result; +} /*********************************************************************//** * @brief - * The getMeasuredDialInPumpMCSpeed function gets the measured dialIn pump \n + * The getMeasuredDialInPumpMCSpeed function gets the measured dialIn pump * speed. * @details * Inputs : adcDialInPumpMCSpeedRPM * Outputs : none * @return the current dialIn pump speed (in RPM). *************************************************************************/ -DATA_GET( F32, getMeasuredDialInPumpMCSpeed, adcDialInPumpMCSpeedRPM ) +F32 getMeasuredDialInPumpMCSpeed( void ) +{ + F32 result = adcDialInPumpMCSpeedRPM.data; + + if ( OVERRIDE_KEY == adcDialInPumpMCSpeedRPM.override ) + { + result = adcDialInPumpMCSpeedRPM.ovData; + } + + return result; +} /*********************************************************************//** * @brief - * The getMeasuredDialInPumpMCCurrent function gets the measured dialIn pump \n + * The getMeasuredDialInPumpMCCurrent function gets the measured dialIn pump * current. * @details * Inputs : adcDialInPumpMCCurrentmA * Outputs : none -/ * @return the current dialIn pump current (in mA). + * @return the current dialIn pump current (in mA). *************************************************************************/ -DATA_GET( F32, getMeasuredDialInPumpMCCurrent, adcDialInPumpMCCurrentmA ) +F32 getMeasuredDialInPumpMCCurrent( void ) +{ + F32 result = adcDialInPumpMCCurrentmA.data; + + if ( OVERRIDE_KEY == adcDialInPumpMCCurrentmA.override ) + { + result = adcDialInPumpMCCurrentmA.ovData; + } + + return result; +} /*********************************************************************//** * @brief - * The publishDialInFlowData function publishes dialIn flow data at the set \n + * The publishDialInFlowData function publishes dialIn 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 : DialIn flow data is published to CAN bus. * @return none @@ -748,11 +819,12 @@ /*********************************************************************//** * @brief - * The resetDialInFlowMovingAverage function resets the properties of the \n + * The resetDialInFlowMovingAverage function resets the properties of the * dialIn flow moving average sample buffer. * @details * Inputs : none * Outputs : flowReadingsTotal, flowReadingsIdx, flowReadingsCount all set to zero. + * @return none *************************************************************************/ static void resetDialInFlowMovingAverage( void ) { @@ -764,11 +836,10 @@ /*********************************************************************//** * @brief - * The filterDialInFlowReadings function adds a new flow sample to the filter \n - * if decimation rate for current set point calls for it. + * The filterDialInFlowReadings function adds a new flow sample to the filter. * @details * Inputs : none - * Outputs : flowReadings[], flowReadingsIdx, flowReadingsCount + * Outputs : flowReadings[], flowReadingsIdx, flowReadingsCount, flowReadingsTotal * @return none *************************************************************************/ static void filterDialInFlowReadings( F32 flow ) @@ -790,8 +861,8 @@ /*********************************************************************//** * @brief - * The updateDialInPumpSpeedAndDirectionFromHallSensors function calculates \n - * the dialysate inlet pump motor speed and direction from hall sensor counter on \n + * The updateDialInPumpSpeedAndDirectionFromHallSensors function calculates + * the dialysate inlet pump motor speed and direction from hall sensor counter on * a 1 second interval. * @details * Inputs : dipLastMotorHallSensorCount, dipMotorSpeedCalcTimerCtr, current count from FPGA @@ -829,8 +900,8 @@ /*********************************************************************//** * @brief - * The checkDialInPumpRotor function checks the rotor for the dialysate inlet \n - * pump. If homing, this function will stop when hall sensor detected. If pump \n + * The checkDialInPumpRotor function checks the rotor for the dialysate inlet + * 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 : dipStopAtHomePosition, dipHomeStartTime, dipRotorRevStartTime @@ -856,7 +927,7 @@ /*********************************************************************//** * @brief - * The checkDialInPumpDirection function checks the set direction vs. \n + * The checkDialInPumpDirection function checks the set direction vs. * the direction implied by the sign of the measured MC speed. * @details * Inputs : adcDialInPumpMCSpeedRPM, dialInPumpDirectionSet, dialInPumpState @@ -882,11 +953,11 @@ /*********************************************************************//** * @brief - * The checkDialInPumpSpeeds function checks several aspects of the dialysate \n - * inlet pump 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 checkDialInPumpSpeeds function checks several aspects of the dialysate + * inlet 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 : targetDialInFlowRate, dialInPumpSpeedRPM, dialInPumpRotorSpeedRPM @@ -923,10 +994,10 @@ if ( DIAL_IN_PUMP_CONTROL_TO_TARGET_STATE == dialInPumpState ) { F32 cmdMotorSpeed = ( (F32)cmdRate / (F32)ML_PER_LITER ) * DIP_REV_PER_LITER * DIP_GEAR_RATIO; - F32 deltaMotorSpeed = FABS( measMotorSpeed - cmdMotorSpeed ); + F32 deltaMotorSpeed = fabs( measMotorSpeed - cmdMotorSpeed ); F32 measRotorSpeed = getMeasuredDialInPumpRotorSpeed(); F32 measMotorSpeedInRotorRPM = measMotorSpeed / DIP_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 > DIP_MAX_MOTOR_SPEED_ERROR_RPM ) @@ -968,9 +1039,9 @@ /*********************************************************************//** * @brief - * The checkDialInPumpFlowAgainstSpeed function checks the measured dialysate 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 checkDialInPumpFlowAgainstSpeed function checks the measured dialysate 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 : measuredDialInFlowRate, dialInPumpSpeedRPM, errorDialInFlowVsMotorSpeedPersistTimerCtr @@ -985,7 +1056,7 @@ F32 flow = getMeasuredDialInFlowRate(); F32 speed = getMeasuredDialInPumpSpeed(); F32 impliedFlow = ( ( speed / DIP_GEAR_RATIO ) / DIP_REV_PER_LITER ) * (F32)ML_PER_LITER; - F32 delta = FABS( flow - impliedFlow ); + F32 delta = fabs( flow - impliedFlow ); if ( delta > DIP_MAX_FLOW_VS_SPEED_DIFF_ML_MIN ) { @@ -1009,7 +1080,7 @@ /*********************************************************************//** * @brief - * The checkDialInPumpMCCurrent function checks the measured MC current vs. \n + * The checkDialInPumpMCCurrent function checks the measured MC current vs. * the set state of the dialIn pump (stopped or running). * @details * Inputs : dialInPumpState, dipCurrErrorDurationCtr, adcDialInPumpMCCurrentmA @@ -1062,19 +1133,42 @@ /*********************************************************************//** * @brief - * The execDialInFlowTest function executes the state machine for the \n - * DialInFlow self test. + * The execDialInFlowTest function executes the state machine for the + * DialInFlow self-test. * @details * Inputs : none * Outputs : none - * @return the current state of the DialInFlow self test. + * @return the current state of the DialInFlow self-test. *************************************************************************/ SELF_TEST_STATUS_T execDialInFlowTest( void ) { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_FAILED; - - // TODO - implement self test(s) - + CALIBRATION_DATA_T cal; + + switch ( dialInPumpSelfTestState ) + { + case DIAL_IN_FLOW_SELF_TEST_STATE_START: + // retrieve blood flow sensor calibration data + if ( TRUE == getCalibrationData( &cal ) ) + { + dialInFlowCalGain = cal.dialysateFlowGain; + dialInFlowCalOffset = cal.dialysateFlowOffset_mL_min; + dialInPumpSelfTestState = DIAL_IN_FLOW_TEST_STATE_COMPLETE; // TODO - implement rest of self-test(s) + result = SELF_TEST_STATUS_PASSED; + } + break; + + case DIAL_IN_FLOW_TEST_STATE_IN_PROGRESS: + break; + + case DIAL_IN_FLOW_TEST_STATE_COMPLETE: + break; + + default: + // TODO - s/w fault + break; + } + return result; } @@ -1084,14 +1178,66 @@ *************************************************************************/ +/*********************************************************************//** + * @brief + * The setDialInFlowCalibration function sets the dialysate flow calibration + * factors and has them stored in non-volatile memory. + * @details + * Inputs : none + * Outputs : dialInFlowCalGain, dialInFlowCalOffset + * @param gain gain calibration factor for dialysate flow sensor + * @param offset offset calibration factor for dialysate flow sensor + * @return TRUE if calibration factors successfully set/stored, FALSE if not + *************************************************************************/ +BOOL setDialInFlowCalibration( F32 gain, F32 offset ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + CALIBRATION_DATA_T cal; + + getCalibrationData( &cal ); + // keep locally and apply immediately + dialInFlowCalGain = gain; + dialInFlowCalOffset = offset; + // also update calibration record in non-volatile memory + cal.dialysateFlowGain = gain; + cal.dialysateFlowOffset_mL_min = offset; + if ( TRUE == setCalibrationData( cal ) ) + { + result = TRUE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getDialInFlowCalibration function retrieves the current dialysate flow + * calibration factors. + * @details + * Inputs : dialInFlowCalGain, dialInFlowCalOffset + * Outputs : none + * @param gain value to populate with gain calibration factor for dialysate flow sensor + * @param offset value to populate with offset calibration factor for dialysate flow sensor + * @return none + *************************************************************************/ +void getDialInFlowCalibration( F32 *gain, F32 *offset ) +{ + *gain = dialInFlowCalGain; + *offset = dialInFlowCalOffset; +} + /*********************************************************************//** * @brief - * The testSetDialInFlowDataPublishIntervalOverride function overrides the \n + * The testSetDialInFlowDataPublishIntervalOverride function overrides the * dialIn flow data publish interval. * @details * Inputs : none * Outputs : dialInFlowDataPublishInterval - * @param value : override dialIn flow data publish interval with (in ms) + * @param value override dialIn flow data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetDialInFlowDataPublishIntervalOverride( U32 value ) @@ -1112,7 +1258,7 @@ /*********************************************************************//** * @brief - * The testResetDialInFlowDataPublishIntervalOverride function resets the override \n + * The testResetDialInFlowDataPublishIntervalOverride function resets the override * of the dialIn flow data publish interval. * @details * Inputs : none @@ -1135,15 +1281,16 @@ /*********************************************************************//** * @brief - * The testSetTargetDialInFlowRateOverride function overrides the target \n - * dialysate inlet flow rate. \n + * The testSetTargetDialInFlowRateOverride function overrides the target + * dialysate inlet flow rate.n * @details * Inputs : none * Outputs : targetDialInFlowRate - * @param value : override target dialysate inlet flow rate (in mL/min) + * @param value override target dialysate inlet 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 testSetTargetDialInFlowRateOverride( S32 value ) +BOOL testSetTargetDialInFlowRateOverride( S32 value, U32 ctrlMode ) { BOOL result = FALSE; @@ -1159,18 +1306,21 @@ { dir = MOTOR_DIR_FORWARD; } - targetDialInFlowRate.ovInitData = targetDialInFlowRate.data; // backup current target flow rate - targetDialInFlowRate.ovData = value; - targetDialInFlowRate.override = OVERRIDE_KEY; - result = setDialInPumpTargetFlowRate( ABS(value), dir, dialInPumpControlMode ); + if ( ctrlMode < NUM_OF_PUMP_CONTROL_MODES ) + { + targetDialInFlowRate.ovInitData = targetDialInFlowRate.data; // backup current target flow rate + targetDialInFlowRate.ovData = value; + targetDialInFlowRate.override = OVERRIDE_KEY; + result = setDialInPumpTargetFlowRate( abs(value), dir, (PUMP_CONTROL_MODE_T)ctrlMode ); + } } return result; } /*********************************************************************//** * @brief - * The testResetTargetDialInFlowRateOverride function resets the override of the \n + * The testResetTargetDialInFlowRateOverride function resets the override of the * target dialysate inlet flow rate. * @details * Inputs : none @@ -1195,12 +1345,12 @@ /*********************************************************************//** * @brief - * The testResetMeasuredDialInFlowRateOverride function overrides the measured \n + * The testResetMeasuredDialInFlowRateOverride function overrides the measured * dialIn flow rate. * @details * Inputs : none * Outputs : measuredDialInFlowRate - * @param value : override measured dialIn flow rate (in mL/min) + * @param value override measured dialIn flow rate (in mL/min) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredDialInFlowRateOverride( F32 value ) @@ -1219,7 +1369,7 @@ /*********************************************************************//** * @brief - * The testResetMeasuredDialInFlowRateOverride function resets the override of the \n + * The testResetMeasuredDialInFlowRateOverride function resets the override of the * measured dialIn flow rate. * @details * Inputs : none @@ -1242,12 +1392,12 @@ /*********************************************************************//** * @brief - * The testSetMeasuredDialInPumpRotorSpeedOverride function overrides the measured \n + * The testSetMeasuredDialInPumpRotorSpeedOverride function overrides the measured * dialIn pump rotor speed. * @details * Inputs : none * Outputs : dialInPumpRotorSpeedRPM - * @param value : override measured dialIn pump rotor speed (in RPM) + * @param value override measured dialIn pump rotor speed (in RPM) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredDialInPumpRotorSpeedOverride( F32 value ) @@ -1266,7 +1416,7 @@ /*********************************************************************//** * @brief - * The testResetMeasuredDialInPumpRotorSpeedOverride function resets the override of the \n + * The testResetMeasuredDialInPumpRotorSpeedOverride function resets the override of the * measured dialIn pump rotor speed. * @details * Inputs : none @@ -1289,12 +1439,12 @@ /*********************************************************************//** * @brief - * The testSetMeasuredDialInPumpSpeedOverride function overrides the measured \n + * The testSetMeasuredDialInPumpSpeedOverride function overrides the measured * dialIn pump motor speed. * @details * Inputs : none * Outputs : dialInPumpSpeedRPM - * @param value : override measured dialIn pump motor speed (in RPM) + * @param value override measured dialIn pump motor speed (in RPM) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredDialInPumpSpeedOverride( F32 value ) @@ -1313,7 +1463,7 @@ /*********************************************************************//** * @brief - * The testResetMeasuredDialInPumpSpeedOverride function resets the override of the \n + * The testResetMeasuredDialInPumpSpeedOverride function resets the override of the * measured dialIn pump motor speed. * @details * Inputs : none @@ -1336,12 +1486,12 @@ /*********************************************************************//** * @brief - * The testSetMeasuredDialInPumpMCSpeedOverride function overrides the measured \n + * The testSetMeasuredDialInPumpMCSpeedOverride function overrides the measured * dialIn pump motor speed. * @details * Inputs : none * Outputs : adcDialInPumpMCSpeedRPM - * @param value : override measured dialIn pump speed (in RPM) + * @param value override measured dialIn pump speed (in RPM) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredDialInPumpMCSpeedOverride( F32 value ) @@ -1360,7 +1510,7 @@ /*********************************************************************//** * @brief - * The testResetMeasuredDialInPumpMCSpeedOverride function resets the override of the \n + * The testResetMeasuredDialInPumpMCSpeedOverride function resets the override of the * measured dialIn pump motor speed. * @details * Inputs : none @@ -1383,12 +1533,12 @@ /*********************************************************************//** * @brief - * The testSetMeasuredDialInPumpMCCurrentOverride function overrides the measured \n + * The testSetMeasuredDialInPumpMCCurrentOverride function overrides the measured * dialIn pump motor current. * @details * Inputs : none * Outputs : adcDialInPumpMCCurrentmA - * @param value : override measured dialIn pump current (in mA) + * @param value override measured dialIn pump current (in mA) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredDialInPumpMCCurrentOverride( F32 value ) @@ -1407,7 +1557,7 @@ /*********************************************************************//** * @brief - * The testResetMeasuredDialInPumpMCCurrentOverride function resets the override of the \n + * The testResetMeasuredDialInPumpMCCurrentOverride function resets the override of the * measured dialIn pump motor current. * @details * Inputs : none