Index: firmware/App/Controllers/SyringePump.c =================================================================== diff -u -ra6b123cfdbca851389cfd5cc1b753386e156e960 -rc1e18c14a172586f47ebcf027bce9669beded986 --- firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision a6b123cfdbca851389cfd5cc1b753386e156e960) +++ firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision c1e18c14a172586f47ebcf027bce9669beded986) @@ -173,6 +173,7 @@ #define SYRINGE_PUMP_DAC_TIMER ( 200 / TASK_PRIORITY_INTERVAL ) ///< Syringe pump DAC timer between retries. #define SYRINGE_PUMP_OCCLUSION_PERSISTENCE 50 ///< Syringe pump occlusion persistence timer in milliseconds. #define SYRINGE_PUMP_EMPTY_FORCE_COUNT 5 ///< Syringe pump empty force voltage count persistence. + /// Defined states for the syringe pump control state machine. typedef enum SyringePump_States { @@ -210,8 +211,6 @@ static OVERRIDE_U32_T syringePumpADCReadCtr = {0, 0, 0, 0}; ///< Syringe pump ADC read counter reported by FPGA. static OVERRIDE_F32_T syringePumpDACVref = { 0.0, 0.0, 0.0, 0 };; ///< DAC Vref setting for force sensor. -static BOOL requireSyringeDetection; ///< Flag indicating whether syringe detection is required in the current state. - static F32 syringePumpSetRate; ///< Set rate for syringe pump (in mL/hr). static F32 forceAtEndOfSeek; ///< Force sensor reading in Volts at the end of seek. static U32 syringePumpSetToggleTime; ///< Set rate for syringe pump (in uSec/toggle). @@ -244,10 +243,8 @@ static BOOL syringePumpPrimeCompleted; ///< Flag indicates prime operation was completed. static BOOL syringePumpPreLoadCompleted; ///< Flag indicates preload operation was completed. static U32 syringePumpStateStartTime; ///< Time current syringe pump state started. - static BOOL syringePumpDACVrefWriteInProgress; ///< Flag indicates DAC Vref write is in progress. - static U32 syringePumpStallCtr; ///< Counts time when position is not changing during ramp. static U32 syringePumpStallRetryCount; ///< Counts pump ramp up stall retries. static TD_HEPARIN_FORCE_SENSOR_CAL_RECORD_T forceSensorCalRecord; ///< TD heparin force sensor calibration record. @@ -257,6 +254,9 @@ static U32 syringePumpEmptyForceCount; ///< Counter for empty syringe detection. +// TODO: Remove the following code when NVM is implemented. +//static BOOL spumpCalibrated; ///< Flag to ensure that calibration request is made only once. + // ********** private function prototypes ********** static void execSyringePumpMonitor( void ); @@ -308,45 +308,43 @@ { U32 i; - syringePumpState = SYRINGE_PUMP_INIT_STATE; - heparinDeliveryState = HEPARIN_STATE_OFF; - requireSyringeDetection = FALSE; - syringePumpSetRate = 0.0; - syringePumpSetToggleTime = 0; - syringePumpSafetyVolumeDelivered = 0.0; - syringePumpVolumeStartPosition = 0; - syringePumpHomePositionOffset = 0; - syringePumpLastPosition = 0; - syringePumpStopLastPosition = 0; - syringePumpVolumeRequired = 0.0; + syringePumpState = SYRINGE_PUMP_INIT_STATE; + heparinDeliveryState = HEPARIN_STATE_OFF; + syringePumpSetRate = 0.0; + syringePumpSetToggleTime = 0; + syringePumpSafetyVolumeDelivered = 0.0; + syringePumpVolumeStartPosition = 0; + syringePumpHomePositionOffset = 0; + syringePumpLastPosition = 0; + syringePumpStopLastPosition = 0; + syringePumpVolumeRequired = 0.0; syringePumpControllerMeasuredDirection = MOTOR_DIR_FORWARD; - syringePumpEncoderMeasuredDirection = MOTOR_DIR_FORWARD; + syringePumpEncoderMeasuredDirection = MOTOR_DIR_FORWARD; syringePumpDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; - syringePumpSpeedCalcTimerCounter = 0; - syringePumpRampTimerCtr = 0; - syringePumpStopPositionTimerCounter = 0; - syringePumpSafetyVolumeDelivered = 0.0; - syringePumpStateStartTime = getMSTimerCount(); + syringePumpSpeedCalcTimerCounter = 0; + syringePumpRampTimerCtr = 0; + syringePumpStopPositionTimerCounter = 0; + syringePumpSafetyVolumeDelivered = 0.0; + syringePumpPositionKnown = FALSE; + syringePumpPlungerFound = FALSE; + syringeVolumeAdequate = FALSE; + syringePumpPrimeCompleted = FALSE; + syringePumpPreLoadCompleted = FALSE; + syringePumpRampUpPct = 0.0; + syringePumpEmptyForceCount = 0; + syringePumpStallCtr = 0; + syringePumpStallRetryCount = 0; + syringePumpDACRetryCount = 0; + syringePumpDACRetryTimer = 0; + syringePumpMotorSpeedCalcIdx = 0; + syringePumpStateStartTime = getMSTimerCount(); - syringePumpPositionKnown = FALSE; - syringePumpPlungerFound = FALSE; - syringeVolumeAdequate = FALSE; - syringePumpPrimeCompleted = FALSE; - syringePumpPreLoadCompleted = FALSE; - syringePumpRampUpPct = 0.0; - syringePumpEmptyForceCount = 0; // Zero pump position counts buffer - syringePumpMotorSpeedCalcIdx = 0; for ( i = 0; i < SYRINGE_PUMP_SPEED_CALC_BUFFER_LEN; i++ ) { syringePumpLastPositions[ i ] = 0; } - syringePumpStallCtr = 0; - syringePumpStallRetryCount = 0; - syringePumpDACRetryCount = 0; - syringePumpDACRetryTimer = 0; - // Initialize persistent alarms initPersistentAlarm( ALARM_ID_TD_SYRINGE_PUMP_ENCODER_DIRECTION_ERROR, 0, SYRINGE_PUMP_DIR_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_TD_SYRINGE_PUMP_CONTROLLER_DIRECTION_ERROR, 0, SYRINGE_PUMP_DIR_ALARM_PERSISTENCE ); @@ -359,13 +357,20 @@ // Reset request flags resetSyringePumpRequestFlags(); + + // TODO: Remove the following code when NVM is implemented. +// forceSensorCalRecord.tdHeparinForceSensorDACVoltage = 0.1; +// forceSensorCalRecord.calibrationTime = 1; +// spumpCalibrated = FALSE; } /*********************************************************************//** * @brief * The execSyringePump function executes the syringe pump control state machine. - * @details \b Inputs: syringePumpState - * @details \b Outputs: syringePumpState + * @details \b Alarms: ALARM_ID_TD_SOFTWARE_FAULT if exec state is invalid + * @details \b Inputs: syringePumpState, syringePumpDACRetryCount + * @details \b Outputs: syringePumpState, syringePumpDACRetryTimer, + * syringePumpLastPosition * @return none *************************************************************************/ void execSyringePump( void ) @@ -484,12 +489,17 @@ BOOL accepted = FALSE; REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_NONE; + // Check if the current mode is treatment mode. if ( MODE_TREA == getCurrentOperationMode() ) { - if ( ( TREATMENT_DIALYSIS_STATE == getTreatmentState() ) && ( getTreatmentState() != TREATMENT_SALINE_BOLUS_STATE ) ) + // Check if the current state is dialysis and not saline bolus. + if ( ( TREATMENT_DIALYSIS_STATE == getTreatmentState() ) && + ( getTreatmentState() != TREATMENT_SALINE_BOLUS_STATE ) ) { + // Check of the command is to pause the heparin dispensing if ( HEPARIN_CMD_PAUSE == cmd ) { + // while heparin is being dispensed if ( HEPARIN_STATE_DISPENSING == heparinDeliveryState ) { stopSyringePump(); @@ -501,8 +511,10 @@ rejReason = REQUEST_REJECT_REASON_HEPARIN_PAUSE_INVALID_IN_THIS_STATE; } } + // Check of the command is to resume the heparin dispensing else if ( HEPARIN_CMD_RESUME == cmd ) { + // while heparin dispensing is paused if ( HEPARIN_STATE_PAUSED == heparinDeliveryState ) { accepted = TRUE; @@ -562,7 +574,7 @@ /*********************************************************************//** * @brief * The setHeparinCompleted function requests Heparin state be set to completed - - * indicates we have entered the Heparin pre-stop period of this treatment. + * indicates the Heparin delivery duration has elapsed, of this treatment. * @details \b Inputs: none * @details \b Outputs: heparinDeliveryState * @return none @@ -599,19 +611,21 @@ /*********************************************************************//** * @brief * The stopSyringePump function requests syringe pump be stopped. - * @details \b Inputs: none + * @details \b Inputs: syringePumpState, heparinDeliveryState * @details \b Outputs: syringePumpSetRate, syringePumpState, heparinDeliveryState * @return TRUE if request accepted, FALSE if not *************************************************************************/ void stopSyringePump( void ) { setFPGASyringePumpStepToggleTime( SYRINGE_PUMP_MICROSTEP_TOGGLE_TIME_FOR_STOP ); - if ( ( syringePumpState != SYRINGE_PUMP_CONFIG_FORCE_SENSOR_STATE ) && ( syringePumpState != SYRINGE_PUMP_OFF_STATE ) ) + if ( ( syringePumpState != SYRINGE_PUMP_CONFIG_FORCE_SENSOR_STATE ) && + ( syringePumpState != SYRINGE_PUMP_OFF_STATE ) ) { syringePumpState = SYRINGE_PUMP_OFF_STATE; syringePumpSetRate = 0.0; } - if ( ( HEPARIN_STATE_INITIAL_BOLUS == heparinDeliveryState ) || ( HEPARIN_STATE_DISPENSING == heparinDeliveryState ) ) + if ( ( HEPARIN_STATE_INITIAL_BOLUS == heparinDeliveryState ) || + ( HEPARIN_STATE_DISPENSING == heparinDeliveryState ) ) { if ( HEPARIN_STATE_INITIAL_BOLUS == heparinDeliveryState ) { @@ -631,7 +645,7 @@ * The retractSyringePump function requests retract operation. * @details \b Inputs: syringePumpState * @details \b Outputs: syringePumpSetRate, syringePumpRetractRequested, heparinDeliveryState - * @return TRUE if request accepted, FALSE if not + * @return syringePumpRetractRequested - TRUE if request accepted, FALSE if not *************************************************************************/ BOOL retractSyringePump( void ) { @@ -648,13 +662,14 @@ /*********************************************************************//** * @brief * The preloadSyringePlunger function requests plunger preload operation. - * @details \b Inputs: syringePumpState + * @details \b Inputs: syringePumpState, syringePumpPositionKnown, heparinDeliveryState * @details \b Outputs: syringePumpSetRate, syringePumpPreloadRequested - * @return TRUE if request accepted, FALSE if not + * @return syringePumpPreloadRequested -TRUE if request accepted, FALSE if not *************************************************************************/ BOOL preloadSyringePlunger( void ) { - if ( MODE_SERV == getCurrentOperationMode() ) // Allow syringe pump operations in Service Mode. + // Allow syringe pump operations in Service Mode. + if ( MODE_SERV == getCurrentOperationMode() ) { heparinDeliveryState = HEPARIN_STATE_STOPPED; } @@ -675,17 +690,20 @@ /*********************************************************************//** * @brief * The seekSyringePlunger function requests plunger seek operation. - * @details \b Inputs: syringePumpState + * @details \b Inputs: syringePumpState, syringePumpPositionKnown, + * heparinDeliveryState * @details \b Outputs: syringePumpSetRate, syringePumpSeekRequested - * @return TRUE if request accepted, FALSE if not + * @return syringePumpSeekRequested - TRUE if request accepted, FALSE if not *************************************************************************/ BOOL seekSyringePlunger( void ) { - if ( MODE_SERV == getCurrentOperationMode() ) // Allow syringe pump operations in Service Mode. + // Allow syringe pump operations in Service Mode. + if ( MODE_SERV == getCurrentOperationMode() ) { heparinDeliveryState = HEPARIN_STATE_STOPPED; } - if ( ( SYRINGE_PUMP_OFF_STATE == syringePumpState ) && ( TRUE == syringePumpPositionKnown ) ) + if ( ( SYRINGE_PUMP_OFF_STATE == syringePumpState ) && + ( TRUE == syringePumpPositionKnown ) ) { if ( ( heparinDeliveryState != HEPARIN_STATE_OFF ) || ( TRUE == getTestConfigStatus( TEST_CONFIG_ENABLE_SYRINGE_PUMP_TESTING ) ) ) @@ -701,22 +719,28 @@ /*********************************************************************//** * @brief * The primeSyringePump function requests a prime operation. - * @details \b Inputs: syringePumpState - * @details \b Outputs: syringePumpSetRate, syringePumpPrimeRequested - * @return TRUE if request accepted, FALSE if not + * @details \b Inputs: syringePumpState, syringePumpPositionKnown, + * syringePumpPlungerFound + * @details \b Outputs: syringePumpSetRate, syringePumpPrimeRequested, + * heparinDeliveryState, forceAtEndOfSeek + * @return syringePumpPrimeRequested TRUE if request accepted, FALSE if not *************************************************************************/ BOOL primeSyringePump( void ) { - if ( MODE_SERV == getCurrentOperationMode() ) // Allow syringe pump operations in Service Mode. + // Allow syringe pump operations in Service Mode. + if ( MODE_SERV == getCurrentOperationMode() ) { heparinDeliveryState = HEPARIN_STATE_STOPPED; } - if ( ( SYRINGE_PUMP_OFF_STATE == syringePumpState ) && ( TRUE == syringePumpPositionKnown ) ) + if ( ( SYRINGE_PUMP_OFF_STATE == syringePumpState ) && + ( TRUE == syringePumpPositionKnown ) ) { - if ( ( ( heparinDeliveryState != HEPARIN_STATE_OFF ) && ( TRUE == syringePumpPlungerFound ) ) || + if ( ( ( heparinDeliveryState != HEPARIN_STATE_OFF ) && + ( TRUE == syringePumpPlungerFound ) ) || ( TRUE == getTestConfigStatus( TEST_CONFIG_ENABLE_SYRINGE_PUMP_TESTING ) ) ) { - forceAtEndOfSeek = getSyringePumpForceV(); // Get the force sensor reading when syringe pump prime has been requested (after seek) + // Get the force sensor reading when syringe pump prime has been requested (after seek) + forceAtEndOfSeek = getSyringePumpForceV(); syringePumpSetRate = SYRINGE_PUMP_PRIME_RATE; syringePumpPrimeRequested = TRUE; resetHeparinVolumeDelivered(); @@ -730,16 +754,21 @@ * @brief * The checkForPrimeOcclusion function checks the force sensor for excessive * pressure. Would indicate occlusion or jam or empty syringe. - * @details \b Inputs: syringePumpMeasForce.data, syringePumpPosition.data + * @details \b Inputs: syringePumpMeasForce.data, syringePumpPosition.data, + * forceAtEndOfSeek, syringePumpState * @details \b Outputs: alarm triggered if max force detected * @param stopPump flag passed in by caller indicating whether pump should be stopped * @return TRUE if pump should be stopped, FALSE if not *************************************************************************/ BOOL checkForSyringeOcclusion( BOOL stopPump ) { BOOL result = stopPump; - F32 currentForceV = getSyringePumpForceV(); // Read the force sensor at the end of the priming - F32 forceDelta = currentForceV - forceAtEndOfSeek; // Occlusion is detected if force at end of prime is > than force at end of seek by 0.5 volts or more + + // Read the force sensor at the end of the priming + F32 currentForceV = getSyringePumpForceV(); + + // Occlusion is detected if force at end of prime is > than force at end of seek by 0.5 volts or more + F32 forceDelta = currentForceV - forceAtEndOfSeek; BOOL occlusionDetected = FALSE; // Checking for occlusion in dry self tests without persistence @@ -772,9 +801,10 @@ /*********************************************************************//** * @brief * The startHeparinBolus function requests Heparin bolus delivery. - * @details \b Inputs: syringePumpState - * @details \b Outputs: syringePumpSetRate, syringePumpBolusRequested - * @return TRUE if request accepted, FALSE if not + * @details \b Inputs: syringePumpState, syringePumpPrimeCompleted + * @details \b Outputs: syringePumpSetRate, syringePumpBolusRequested, + * heparinDeliveryState + * @return syringePumpBolusRequested - TRUE if request accepted, FALSE if not *************************************************************************/ BOOL startHeparinBolus( void ) { @@ -783,13 +813,15 @@ // If valid to start a bolus, kick it off if ( FALSE == isSyringePumpHome() ) { - if ( MODE_SERV == getCurrentOperationMode() ) // Allow syringe pump operations in Service Mode. + // Allow syringe pump operations in Service Mode. + if ( MODE_SERV == getCurrentOperationMode() ) { heparinDeliveryState = HEPARIN_STATE_STOPPED; } if ( SYRINGE_PUMP_OFF_STATE == syringePumpState ) { - if ( ( ( TRUE == syringePumpPrimeCompleted ) && ( HEPARIN_STATE_STOPPED == heparinDeliveryState ) ) || + if ( ( ( TRUE == syringePumpPrimeCompleted ) && + ( HEPARIN_STATE_STOPPED == heparinDeliveryState ) ) || ( TRUE == getTestConfigStatus( TEST_CONFIG_ENABLE_SYRINGE_PUMP_TESTING ) ) ) { // if user set a Heparin bolus volume and not complete, start now @@ -818,22 +850,27 @@ * @brief * The startHeparinContinuous function requests Heparin continuous delivery. * @details \b Inputs: syringePumpState - * @details \b Outputs: syringePumpSetRate, syringePumpContinuousRequested - * @return TRUE if request accepted, FALSE if not + * @details \b Outputs: syringePumpSetRate, syringePumpContinuousRequested, + * heparinDeliveryState + * @return syringePumpContinuousRequested - TRUE if request accepted, FALSE if not *************************************************************************/ BOOL startHeparinContinuous( void ) { F32 flowRate = getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_DELIVERY_RATE ); - if ( ( flowRate >= MIN_HEPARIN_CONTINUOUS_RATE ) && ( flowRate <= MAX_HEPARIN_CONTINUOUS_RATE ) && ( FALSE == isSyringePumpHome() ) ) + if ( ( flowRate >= MIN_HEPARIN_CONTINUOUS_RATE ) && + ( flowRate <= MAX_HEPARIN_CONTINUOUS_RATE ) && + ( FALSE == isSyringePumpHome() ) ) { - if ( MODE_SERV == getCurrentOperationMode() ) // Allow syringe pump operations in Service Mode. + // Allow syringe pump operations in Service Mode. + if ( MODE_SERV == getCurrentOperationMode() ) { heparinDeliveryState = HEPARIN_STATE_STOPPED; } if ( SYRINGE_PUMP_OFF_STATE == syringePumpState ) { - if( ( ( HEPARIN_STATE_STOPPED == heparinDeliveryState ) || ( HEPARIN_STATE_PAUSED == heparinDeliveryState ) ) || + if( ( ( HEPARIN_STATE_STOPPED == heparinDeliveryState ) || + ( HEPARIN_STATE_PAUSED == heparinDeliveryState ) ) || ( TRUE == getTestConfigStatus( TEST_CONFIG_ENABLE_SYRINGE_PUMP_TESTING ) ) ) { syringePumpSetRate = flowRate; @@ -857,9 +894,10 @@ /*********************************************************************//** * @brief * The setSyringePumpDACVref function requests to set the DAC Vref setting. - * @details \b Inputs: none + * @details \b Inputs: forceSensorCalRecord.tdHeparinForceSensorDACVoltage, + * syringePumpState * @details \b Outputs: syringePumpDACVrefSetRequested, syringePumpDACVref - * @return TRUE if request accepted, FALSE if not + * @return syringePumpDACVrefSetRequested - TRUE if request accepted, FALSE if not *************************************************************************/ BOOL setSyringePumpDACVref( void ) { @@ -883,25 +921,11 @@ /*********************************************************************//** * @brief - * The syringeDetectionRequired function sets a flag indicating whether - * the syringe detection is required in current state. - * @details \b Inputs: none - * @details \b Outputs: requireSyringeDetection - * @param req True if syringe detection is required in the current state - * @return none - *************************************************************************/ -void syringeDetectionRequired( BOOL req ) -{ - requireSyringeDetection = req; -} - -/*********************************************************************//** - * @brief * The syringePumpVerifyForceSensorDACCalibration function verifies that the * syringe pump force sensor DAC has been calibrated and is reporting no force * as would be expected when fully retracted (caller should not call this function * until the syringe pump is homed first). - * @details \b Inputs: none + * @details \b Inputs: forceSensorCalRecord.tdHeparinForceSensorDACVoltage * @details \b Outputs: * @return none *************************************************************************/ @@ -949,7 +973,8 @@ { BOOL result = FALSE; - if ( ( syringePumpState <= SYRINGE_PUMP_OFF_STATE ) || ( syringePumpState >= SYRINGE_PUMP_CONFIG_FORCE_SENSOR_STATE ) ) + if ( ( syringePumpState <= SYRINGE_PUMP_OFF_STATE ) || + ( syringePumpState >= SYRINGE_PUMP_CONFIG_FORCE_SENSOR_STATE ) ) { result = TRUE; } @@ -1038,10 +1063,11 @@ return getF32OverrideValue( &syringePumpVolumeDelivered ); } - /*********************************************************************//** * @brief * The execSyringePumpMonitor function executes the syringe pump monitor. + * @details \b Alarms: ALARM_ID_TD_SYRINGE_PUMP_RUNNING_WHILE_BP_OFF_ERROR, + * ALARM_ID_TD_SYRINGE_PUMP_FAULT * @details \b Inputs: FPGA syringe pump readings * @details \b Outputs: Alarm(s) may be triggered * @return none @@ -1140,21 +1166,36 @@ * @brief * The handleSyringePumpOffState function handles the off state * of the syringe pump control state machine. - * @details \b Inputs: syringePumpRetractRequested, syringePumpSeekRequested, - * syringePumpPrimeRequested, syringePumpBolusRequested, syringePumpContinuousRequested, - * syringePumpDACVrefSetRequested,syringePumpStopPositionTimerCounter,syringePumpStopLastPosition - * @details \b Outputs: Pump speed and direction set if pump command initiated + * @details \b Alarms: ALARM_ID_TD_SYRINGE_PUMP_NOT_STOPPED_ERROR + * @details \b Inputs: syringePumpRetractRequested, syringePumpPreloadRequested, + * syringePumpSeekRequested, syringePumpPrimeRequested, syringePumpBolusRequested, + * syringePumpContinuousRequested, syringePumpDACVrefSetRequested, + * syringePumpStopPositionTimerCounter,syringePumpStopLastPosition, + * syringePumpDACRetryCount, syringePumpDACRetryTimer, syringePumpDACVref + * @details \b Outputs: Pump speed and direction set if pump command initiated, + * heparinDeliveryState, syringePumpDACVrefWriteInProgress, syringePumpStateStartTime, + * syringePumpStallRetryCount, syringePumpStallCtr, syringePumpRampTimerCtr * @return next state *************************************************************************/ static SYRINGE_PUMP_STATE_T handleSyringePumpOffState( void ) { SYRINGE_PUMP_STATE_T result = SYRINGE_PUMP_OFF_STATE; + + // TODO: Remove the following code when NVM is implemented. + //Calibrate the force sensor. +// if ( FALSE == spumpCalibrated ) +// { +// setSyringePumpDACVref(); +// spumpCalibrated = TRUE; +// } + // Check the encoder position every 50ms interval after pump off state transition. if ( ++syringePumpStopPositionTimerCounter >= SYRINGE_PUMP_STOP_POSITION_CHECK_INTERVAL ) { // Check position is not changing while stopped - if ( ( syringePumpStopLastPosition != getSyringePumpPosition() ) && ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_SYRINGE_PUMP_OFF_ERROR ) ) ) + if ( ( syringePumpStopLastPosition != getSyringePumpPosition() ) && + ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_SYRINGE_PUMP_OFF_ERROR ) ) ) { #ifndef _RELEASE_ // if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_SYRINGE_PUMP_ALARMS ) != SW_CONFIG_ENABLE_VALUE ) @@ -1251,8 +1292,12 @@ * @brief * The handleSyringePumpRetractState function handles the retract state * of the syringe pump control state machine. - * @details \b Inputs: syringePumpMeasHome.data - * @details \b Outputs: Syringe pump ramped up to retract rate, alarm conditions checked + * @details \b Inputs: syringePumpMeasHome.data, syringePumpPositionKnown, syringePumpPosition + * @details \b Outputs: Syringe pump ramped up to retract rate, alarm conditions checked, + * syringePumpPosition, syringePumpVolumeStartPosition, syringePumpPositionKnown, + * syringePumpVolumeDelivered, syringePumpSafetyVolumeDelivered, syringePumpPlungerFound, + * syringeVolumeAdequate, syringePumpPrimeCompleted, syringePumpPreLoadCompleted, + * syringePumpVolumeRequired * @return next state *************************************************************************/ static SYRINGE_PUMP_STATE_T handleSyringePumpRetractState( void ) @@ -1312,8 +1357,11 @@ * The handleSyringePumpPreLoadState function handles the PreLoad plunger state * of the syringe pump control state machine. Move to position that limits * loadable Heparin volume to amount needed for treatment. - * @details \b Inputs: syringePumpMeasForce.data - * @details \b Outputs: syringePumpVolumeRequired, Syringe pump moved to preload position, alarm conditions checked + * @details \b Inputs: syringePumpPosition, syringePumpMeasForce.data, + * treatmentParameters + * @details \b Outputs: syringePumpVolumeRequired, syringePumpSafetyVolumeDelivered, + * syringePumpVolumeStartPosition, syringePumpPreLoadCompleted + * Syringe pump moved to preload position, alarm conditions checked * @return next state *************************************************************************/ static SYRINGE_PUMP_STATE_T handleSyringePumpPreLoadState( void ) @@ -1368,8 +1416,11 @@ * @brief * The handleSyringePumpSeekState function handles the seek plunger state * of the syringe pump control state machine. - * @details \b Inputs: syringePumpMeasForce.data - * @details \b Outputs: Syringe pump ramped up to seek rate, alarm conditions checked + * @details \b Inputs: syringePumpMeasForce.data, syringePumpPosition, syringePumpMeasForce, + * treatmentParameters, + * @details \b Outputs: Syringe pump ramped up to seek rate, alarm conditions checked, + * syringePumpVolumeDelivered, syringePumpSafetyVolumeDelivered, syringePumpVolumeStartPosition, + * syringePumpPlungerFound, syringeVolumeAdequate * @return next state *************************************************************************/ static SYRINGE_PUMP_STATE_T handleSyringePumpSeekState( void ) @@ -1436,8 +1487,12 @@ * @brief * The handleSyringePumpPrimeState function handles the prime state * of the syringe pump control state machine. - * @details \b Inputs: syringePumpVolumeDelivered, syringePumpStateStartTime - * @details \b Outputs: Syringe pump ramped up to prime rate, alarm conditions checked + * @details \b Alarms: ALARM_ID_TD_SYRINGE_PUMP_PRIME_TIMEOUT + * @details \b Inputs: syringePumpVolumeDelivered, syringePumpStateStartTime, + * syringePumpPosition + * @details \b Outputs: Syringe pump ramped up to prime rate, alarm conditions checked, + * syringePumpPrimeCompleted, syringePumpVolumeDelivered, syringePumpSafetyVolumeDelivered, + * syringePumpVolumeStartPosition * @return next state *************************************************************************/ static SYRINGE_PUMP_STATE_T handleSyringePumpPrimeState( void ) @@ -1488,7 +1543,8 @@ * @brief * The handleSyringePumpBolusState function handles the bolus delivery state * of the syringe pump control state machine. - * @details \b Inputs: set bolus volume, syringePumpVolumeDelivered.data + * @details \b Inputs: set bolus volume, syringePumpVolumeDelivered.data, + * treatmentParameters, syringePumpVolumeStartPosition * @details \b Outputs: Syringe pump ramped up to set bolus rate, alarm conditions checked * @return next state *************************************************************************/ @@ -1581,7 +1637,8 @@ * The handleSyringePumpCalibrateForceSensorState function handles the * calibrate force sensor state of the syringe pump control state machine. * of the syringe pump control state machine. - * @details \b Inputs: DAC status, syringePumpDACRetryCount + * @details \b Alarms: ALARM_ID_TD_SYRINGE_PUMP_DAC_WRITE_ERROR + * @details \b Inputs: syringePumpADCandDACStatus, syringePumpDACRetryCount * @details \b Outputs: syringePumpDACVrefWriteInProgress, ADC read mode restored * syringePumpDACRetryCount, syringePumpDACRetryTimer * @return next state @@ -1681,8 +1738,8 @@ * @brief * The getHeparinBolusTargetRate function gets the heparin bolus target * flow rate. - * @details \b Inputs: getHeparinBolusTargetRate - * @details \b Outputs: getHeparinBolusTargetRate + * @details \b Inputs: heparinBolusTargetRate + * @details \b Outputs: none * @return the current target heparin bolus flow rate (in mL/hour). *************************************************************************/ static F32 getHeparinBolusTargetRate( void ) @@ -1745,7 +1802,10 @@ * @brief * The checkDirection function checks the measured direction of the syringe * pump vs. the given expected direction. - * @details \b Inputs: syringePumpMeasForce.data, syringePumpPosition.data + * @details \b Alarms: ALARM_ID_TD_SYRINGE_PUMP_ENCODER_DIRECTION_ERROR, + * ALARM_ID_TD_SYRINGE_PUMP_CONTROLLER_DIRECTION_ERROR + * @details \b Inputs: syringePumpMeasForce.data, syringePumpPosition.data, + * syringePumpEncoderMeasuredDirection, syringePumpControllerMeasuredDirection * @details \b Outputs: alarm triggered if max force detected * @param stopPump flag passed in by caller indicating whether pump should be stopped * @param expDir expected direction of syringe pump @@ -1787,8 +1847,10 @@ * @brief * The checkSyringeEmpty function checks the force sensor position * to determine if the syringe pump is empty. + * @details \b Alarms: ALARM_ID_TD_SYRINGE_PUMP_SYRINGE_EMPTY * @details \b Inputs: syringePumpMeasForce.data, syringePumpPosition.data - * @details \b Outputs: alarm triggered if position is empty. + * @details \b Outputs: alarm triggered if position is empty., + * heparinDeliveryState * @param stopPump flag passed in by caller indicating whether pump should be stopped * @return TRUE if pump should be stopped, FALSE if not *************************************************************************/ @@ -1809,7 +1871,8 @@ // If near empty position, assume syringe is empty // Check for force threshold over some time and within SYRINGE_PUMP_HW_TOLERANCE_POS of empty if ( ( pos >= SYRINGE_PUMP_EMPTY_POS ) || - ( ( syringePumpEmptyForceCount >= SYRINGE_PUMP_EMPTY_FORCE_COUNT ) && ( pos >= ( SYRINGE_PUMP_EMPTY_POS - SYRINGE_PUMP_HW_TOLERANCE_POS ) ) ) ) + ( ( syringePumpEmptyForceCount >= SYRINGE_PUMP_EMPTY_FORCE_COUNT ) && + ( pos >= ( SYRINGE_PUMP_EMPTY_POS - SYRINGE_PUMP_HW_TOLERANCE_POS ) ) ) ) { heparinDeliveryState = HEPARIN_STATE_EMPTY; SET_ALARM_WITH_2_F32_DATA( ALARM_ID_TD_SYRINGE_PUMP_SYRINGE_EMPTY, (F32)pos, force ) @@ -1824,6 +1887,7 @@ * The checkMaxTravel function checks whether a maximum travel (position) * has been exceeded. This threshold is state dependent so the calling function * must provide the maximum position to apply. + * @details \b Alarms: ALARM_ID_TD_SYRINGE_PUMP_OVER_TRAVEL_ERROR * @details \b Inputs: syringePumpPosition.data * @details \b Outputs: alarm triggered if beyond given max position * @param stopPump flag passed in by caller indicating whether pump should be stopped @@ -1848,6 +1912,7 @@ * @brief * The checkMeasRate function checks whether the measured rate is within a * given margin of the set rate (in mL/hr). + * @details \b Alarms: ALARM_ID_TD_SYRINGE_PUMP_SPEED_ERROR * @details \b Inputs: syringePumpMeasRate.data, syringePumpSetRate * @details \b Outputs: alarm triggered if measured and set rates deviate too much * @param stopPump flag passed in by caller indicating whether pump should be stopped @@ -1885,6 +1950,7 @@ * and the safety volume delivered have diverged too much. The threshold * is state dependent so the calling function must provide the tolerance (in +/- %) * to apply. + * @details \b Alarms: ALARM_ID_TD_SYRINGE_PUMP_VOLUME_ERROR * @details \b Inputs: syringePumpVolumeDelivered.data, syringePumpSafetyVolumeDelivered * @details \b Outputs: alarm triggered if measured and expected volume deviate too much * @param stopPump flag passed in by caller indicating whether pump should be stopped @@ -1915,8 +1981,11 @@ * The checkForStall function checks whether the syringe pump has stalled. * If stall detected, the ramp up will be restarted up to 3 times. * If cannot resolve the stall within 3 retries, a stall fault is triggered. - * @details \b Inputs: syringePumpMeasRate.data, syringePumpStallCtr, syringePumpStallRetryCount - * @details \b Outputs: syringePumpStallCtr, syringePumpStallRetryCount + * @details \b Alarms: ALARM_ID_TD_SYRINGE_PUMP_STALL + * @details \b Inputs: syringePumpMeasRate.data, syringePumpState, + * syringePumpStallCtr, syringePumpStallRetryCount + * @details \b Outputs: syringePumpStallCtr, syringePumpStallRetryCount, + * syringePumpSetToggleTime, syringePumpRampTimerCtr, syringePumpRampUpToggleTime, * @param stopPump flag passed in by caller indicating whether pump should be stopped * @return TRUE if pump should be stopped, FALSE if not *************************************************************************/ @@ -1955,8 +2024,11 @@ * @brief * The resetSyringePumpRequestFlags function resets request flags. * @details \b Inputs: none - * @details \b Out\b Outputs:quest flags reset - * @return TRUE if request accepted, FALSE if not + * @details \b Out\b Outputs:quest flags reset, + * syringePumpRetractRequested, syringePumpSeekRequested, syringePumpPreloadRequested, + * syringePumpPrimeRequested, syringePumpBolusRequested, syringePumpContinuousRequested, + * syringePumpDACVrefSetRequested + * @return none *************************************************************************/ static void resetSyringePumpRequestFlags( void ) { @@ -1992,7 +2064,8 @@ * Motor speed is inversely proportional to the toggle time. * Smaller the toggle time, faster the speed of the motor. * @details \b Inputs: syringePumpRampTimerCtr, syringePumpSetToggleTime - * @details \b Outputs: syringePumpRampUpToggleTime + * @details \b Outputs: syringePumpRampUpToggleTime, + * syringePumpRampUpPct * @return none *************************************************************************/ static void rampSyringePump( void ) @@ -2006,6 +2079,7 @@ // Calculate the new toggle time and update the FPGA with the new speed. syringePumpRampUpToggleTime = (U32)( (F32)SYRINGE_PUMP_START_RAMP_SPEED / ( (F32)( syringePumpRampTimerCtr * syringePumpRampTimerCtr * syringePumpRampTimerCtr ) / (F32)SYRINGE_PUMP_RAMP_DIVISOR ) ); + syringePumpRampUpPct = (F32)syringePumpSetToggleTime / (F32)syringePumpRampUpToggleTime; if ( syringePumpRampUpToggleTime > syringePumpSetToggleTime ) @@ -2025,7 +2099,8 @@ * The calcStepperToggleTimeForTargetRate function calculates the stepper * toggle period for a given rate. * @details \b Inputs: none - * @details \b Outputs: syringePumpSetToggleTime, syringePumpRampUpToggleTime + * @details \b Outputs: syringePumpSetToggleTime, syringePumpRampUpToggleTime, + * syringePumpStallCtr, syringePumpStallRetryCount * @param rate the rate (in mL/hr) to calculate stepper toggle period for * @return none *************************************************************************/ @@ -2053,7 +2128,8 @@ * @brief * The calcMeasRate function calculates the measured rate from a given delta * position in last 1 second. - * @details \b Inputs: syringePumpLastPositions[], syringePumpSpeedCalcTimerCounter + * @details \b Inputs: syringePumpPosition, syringePumpLastPositions[], + * syringePumpSpeedCalcTimerCounter, syringePumpMotorSpeedCalcIdx * @details \b Outputs: syringePumpMeasRate, syringePumpSpeedCalcTimerCounter * @return none *************************************************************************/ @@ -2081,7 +2157,7 @@ * @brief * The calcSafetyVolumeDelivered function calculates the safety volume from * commanded rate over time (last 10 ms). - * @details \b Inputs: syringePumpSetRate + * @details \b Inputs: syringePumpRampUpPct, syringePumpSetRate * @details \b Outputs: syringePumpSafetyVolumeDelivered * @return none *************************************************************************/ @@ -2095,8 +2171,9 @@ * The sendHeparinCommandResponse function constructs a Heparin command response * to the UI and queues the msg for transmit on the * appropriate CAN channel. - * @details Inputs: none - * @details Outputs: Heparin command response msg constructed and queued. + * @details \b Message \b Sent: MSG_ID_TD_HEPARIN_PAUSE_RESUME_RESPONSE + * @details \b Inputs: none + * @details \b Outputs: Heparin command response msg constructed and queued. * @param accepted flag indicating whether request was accepted * @param rejReason rejection reason code * @return TRUE if msg successfully queued for transmit, FALSE if not @@ -2117,7 +2194,8 @@ * @brief * The publishSyringePumpData function publishes syringe pump data at the * set interval. - * @details \b Inputs: latest syringe pump data, syringePumpDataPublicationTimerCounter + * @details \b Inputs: latest syringe pump data, syringePumpDataPublicationTimerCounter, + * syringePumpDataPublishInterval * @details \b Outputs: syringePumpDataPublicationTimerCounter * @return none *************************************************************************/ @@ -2163,8 +2241,9 @@ * operation. * @details \b Inputs: none * @details \b Outputs: pump operation request is handled - * @param opParams record containing the requested operation and its parameters - * @return TRUE if override successful, FALSE if not + * @param message set message from Dialin which includes + * opParams the requested operation and its parameters + * @return TRUE if request is successful, FALSE if not *************************************************************************/ BOOL testSyringePumpOperationRequest( MESSAGE_T *message ) { @@ -2228,7 +2307,8 @@ * syringe pump data publish interval. * @details \b Inputs: none * @details \b Outputs: syringePumpDataPublishInterval - * @param value override syringe pump data publish interval with (in ms) + * @param message Override message from Dialin which includes + * syringe pump data publish interval (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSyringePumpDataPublishIntervalOverride( MESSAGE_T *message ) @@ -2244,7 +2324,8 @@ * rate of the syringe pump. * @details \b Inputs: none * @details \b Outputs: syringePumpMeasRate - * @param value override syringe pump measured rate with this value (in mL/hr) + * @param message Override message from Dialin which includes + * syringe pump measured rate (in mL/hr) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSyringePumpMeasuredRateOverride( MESSAGE_T *message ) @@ -2260,7 +2341,8 @@ * force analog signal of the syringe pump. * @details \b Inputs: none * @details \b Outputs: syringePumpMeasForce - * @param value override syringe pump measured force signal with this value (in V) + * @param message Override message from Dialin which includes + * syringe pump measured force signal (in V) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSyringePumpMeasuredForceOverride( MESSAGE_T *message ) @@ -2274,9 +2356,10 @@ * @brief * The testSyringePumpMeasuredHomeOverride function overrides the measured * home analog signal of the syringe pump. - * @details \b Inputs: syringePumpMeasHome + * @details \b Inputs: none * @details \b Outputs: syringePumpMeasHome - * @param value override syringe pump measured home signal with this value (in V) + * @param message Override message from Dialin which includes + * syringe pump measured home signal (in V) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSyringePumpMeasuredHomeOverride( MESSAGE_T *message ) @@ -2290,10 +2373,10 @@ * @brief * The testSyringePumpMeasuredPositionOverride function overrides the measured * position of the syringe pump. - * @details \b Inputs: syringePumpPosition + * @details \b Inputs: none * @details \b Outputs: syringePumpPosition - * @param message Override message from Dialin which includes the override - * value to override the syringe pump measured position (in encoder counts) + * @param message Override message from Dialin which includes + * the syringe pump measured position (in encoder counts) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSyringePumpMeasuredPositionOverride( MESSAGE_T *message ) @@ -2307,10 +2390,10 @@ * @brief * The testSyringePumpMeasuredVolumeOverride function overrides the measured * rate of the syringe pump measured volume delivered. - * @details \b Inputs: syringePumpVolumeDelivered + * @details \b Inputs: none * @details \b Outputs: syringePumpVolumeDelivered - * @param message Override message from Dialin which includes the override - * value to override the syringe pump measured volume (in mL). + * @param message Override message from Dialin which includes + * the syringe pump measured volume (in mL). * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSyringePumpMeasuredVolumeOverride( MESSAGE_T *message ) @@ -2326,7 +2409,8 @@ * status. * @details \b Inputs: none * @details \b Outputs: syringePumpStatus - * @param status override syringe pump status with this value + * @param message Override message from Dialin which includes + * syringe pump status * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSyringePumpStatusOverride( MESSAGE_T *message ) @@ -2342,7 +2426,8 @@ * pump encoder status. * @details \b Inputs: none * @details \b Outputs: syringePumpEncoderStatus - * @param status override syringe pump encoder status with this value + * @param message Override message from Dialin which includes + * syringe pump encoder status * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSyringePumpEncoderStatusOverride( MESSAGE_T *message ) @@ -2358,7 +2443,8 @@ * pump ADC and DAC status. * @details \b Inputs: none * @details \b Outputs: syringePumpADCandDACStatus - * @param status override syringe pump ADC and DAC status with this value + * @param message Override message from Dialin which includes + * syringe pump ADC and DAC status * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSyringePumpADCandDACStatusOverride( MESSAGE_T *message ) @@ -2374,7 +2460,8 @@ * pump ADC read counter. * @details \b Inputs: none * @details \b Outputs: syringePumpADCReadCtr - * @param ctr override syringe pump ADC read counter with this value + * @param message Override message from Dialin which includes + * syringe pump ADC read counter * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSyringePumpADCReadCounterOverride( MESSAGE_T *message ) @@ -2386,32 +2473,33 @@ /*********************************************************************//** * @brief - * The testSyringePumpDACVrefOverride function overrides the syringe - * pumpDAC Vref setting. + * The testHeparinBolusTargetRateOverride function overrides the + * heparine bolus target rate. * @details \b Inputs: none - * @details \b Outputs: syringePumpDACVref - * @param vref override syringePumpDACVref with this value + * @details \b Outputs: heparinBolusTargetRate + * @param: message Override message from Dialin which includes + * heparin bolus target rate (in mL/hour) * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSyringePumpDACVrefOverride( MESSAGE_T *message ) +BOOL testHeparinBolusTargetRateOverride( MESSAGE_T *message ) { - BOOL result = f32Override( message, &syringePumpDACVref ); + BOOL result = f32Override( message, &heparinBolusTargetRate ); return result; } /*********************************************************************//** * @brief - * The testHeparinBolusTargetRateOverride function overrides the - * heparine bolus target rate. - * @details \b Inputs: heparinBolusTargetRate - * @details \b Outputs: heparinBolusTargetRate - * @param: value : override heparinBolusTargetRate (in mL/hour) - * @return TRUE if override successful, FALSE if not + * The testCalibrateForceSensor function handles a + * request message to set the syringe pump DAC reference voltage. + * @details Inputs: none + * @details Outputs: none + * @param message : a pointer to the message to handle + * @return TRUE if request accepted successfully, FALSE if not *************************************************************************/ -BOOL testHeparinBolusTargetRateOverride( MESSAGE_T *message ) +BOOL testCalibrateForceSensor( MESSAGE_T *message ) { - BOOL result = f32Override( message, &heparinBolusTargetRate ); + BOOL result = setSyringePumpDACVref(); return result; }