Index: firmware/App/Controllers/SyringePump.c =================================================================== diff -u -rf20a9bea362aeea79a6d57f0a9e7035162c39f7f -r5fef605363d4f8023b3db2989b097b6c5f58db1a --- firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision f20a9bea362aeea79a6d57f0a9e7035162c39f7f) +++ firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision 5fef605363d4f8023b3db2989b097b6c5f58db1a) @@ -167,12 +167,16 @@ /// Interval (in ms) at which to publish syringe pump data to CAN bus. static OVERRIDE_U32_T syringePumpDataPublishInterval = { SYRINGE_PUMP_DATA_PUB_INTERVAL, SYRINGE_PUMP_DATA_PUB_INTERVAL, 0, 0 }; -static OVERRIDE_F32_T syringePumpMeasRate = {0.0, 0.0, 0.0, 0 }; ///< Measured rate for syringe pump (in mL/hr). -static OVERRIDE_F32_T syringePumpMeasForce = {0.0, 0.0, 0.0, 0 }; ///< Measured driver force (in V). -static OVERRIDE_F32_T syringePumpMeasSyringeDetectionSwitch = {0, 0, 0, 0 }; ///< Measured syringe detect switch (in V). -static OVERRIDE_F32_T syringePumpMeasHome = {0.0, 0.0, 0.0, 0 }; ///< Measured optical home (in V). -static OVERRIDE_S32_T syringePumpPosition = {0, 0, 0, 0 }; ///< Encoder based position (in steps). -static OVERRIDE_F32_T syringePumpVolumeDelivered = {0.0, 0.0, 0.0, 0 }; ///< Measured volume delivered (in mL). +static OVERRIDE_F32_T syringePumpMeasRate = { 0.0, 0.0, 0.0, 0 }; ///< Measured rate for syringe pump (in mL/hr). +static OVERRIDE_F32_T syringePumpMeasForce = { 0.0, 0.0, 0.0, 0 }; ///< Measured driver force (in V). +static OVERRIDE_F32_T syringePumpMeasSyringeDetectionSwitch = { 0, 0, 0, 0 }; ///< Measured syringe detect switch (in V). +static OVERRIDE_F32_T syringePumpMeasHome = { 0.0, 0.0, 0.0, 0 }; ///< Measured optical home (in V). +static OVERRIDE_S32_T syringePumpPosition = { 0, 0, 0, 0 }; ///< Encoder based position (in steps). +static OVERRIDE_F32_T syringePumpVolumeDelivered = { 0.0, 0.0, 0.0, 0 }; ///< Measured volume delivered (in mL). +static OVERRIDE_U32_T syringePumpStatus = {0, 0, 0, 0}; ///< Syringe pump status reported by FPGA. +static OVERRIDE_U32_T syringePumpEncoderStatus = {0, 0, 0, 0}; ///< Syringe pump encoder status reported by FPGA. +static OVERRIDE_U32_T syringePumpADCandDACStatus = {0, 0, 0, 0}; ///< Syringe pump ADC and DAC status reported by FPGA. +static OVERRIDE_U32_T syringePumpADCReadCtr = {0, 0, 0, 0}; ///< Syringe pump ADC read counter reported by FPGA. static F32 syringePumpSetRate; ///< Set rate for syringe pump (in mL/hr). static U32 syringePumpSetToggleTime; ///< Set rate for syringe pump (in uSec/toggle). @@ -212,6 +216,10 @@ static F32 getSyringePumpSyringeDetectorV( void ); static F32 getSyringePumpHomeDetectorV( void ); static F32 getSyringePumpForceV( void ); +static U08 getSyringePumpStatus( void ); +static U08 getSyringePumpEncoderStatus( void ); +static U08 getSyringePumpADCReadCounter( void ); +static U08 getSyringePumpADCandDACStatus( void ); static SYRINGE_PUMP_STATE_T handleSyringePumpInitState( void ); static SYRINGE_PUMP_STATE_T handleSyringePumpOffState( void ); static SYRINGE_PUMP_STATE_T handleSyringePumpRetractState( void ); @@ -719,6 +727,83 @@ /*********************************************************************//** * @brief + * The getSyringePumpForceV function gets the current syringe pump force. + * @details Inputs: syringePumpMeasForce + * @details Outputs: none + * @return the current syringe pump force (in V). + *************************************************************************/ +static U08 getSyringePumpStatus() +{ + U08 result = (U08)(syringePumpStatus.data & MASK_OFF_U32_MSBS); + + if ( OVERRIDE_KEY == syringePumpStatus.override ) + { + result = (U08)(syringePumpStatus.ovData & MASK_OFF_U32_MSBS); + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getSyringePumpForceV function gets the current syringe pump force. + * @details Inputs: syringePumpMeasForce + * @details Outputs: none + * @return the current syringe pump force (in V). + *************************************************************************/ +static U08 getSyringePumpEncoderStatus() +{ + U08 result = (U08)(syringePumpEncoderStatus.data & MASK_OFF_U32_MSBS); + + if ( OVERRIDE_KEY == syringePumpEncoderStatus.override ) + { + result = (U08)(syringePumpEncoderStatus.ovData & MASK_OFF_U32_MSBS); + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getSyringePumpForceV function gets the current syringe pump force. + * @details Inputs: syringePumpMeasForce + * @details Outputs: none + * @return the current syringe pump force (in V). + *************************************************************************/ +static U08 getSyringePumpADCReadCounter() +{ + U08 result = (U08)(syringePumpADCReadCtr.data & MASK_OFF_U32_MSBS); + + if ( OVERRIDE_KEY == syringePumpADCReadCtr.override ) + { + result = (U08)(syringePumpADCReadCtr.ovData & MASK_OFF_U32_MSBS); + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getSyringePumpADCandDACStatus function gets the current syringe pump + * ADC and DAC status reported by the FPGA. + * @details Inputs: syringePumpADCandDACStatus + * @details Outputs: none + * @return the current syringe pump ADC and DAC status. + *************************************************************************/ +static U08 getSyringePumpADCandDACStatus() +{ + U08 result = (U08)(syringePumpADCandDACStatus.data & MASK_OFF_U32_MSBS); + + if ( OVERRIDE_KEY == syringePumpADCandDACStatus.override ) + { + result = (U08)(syringePumpADCandDACStatus.ovData & MASK_OFF_U32_MSBS); + } + + return result; +} + +/*********************************************************************//** + * @brief * The isSyringeDetected function determines whether a syringe is currently * detected. * @details Inputs: syringePumpMeasSyringeDetectionSwitch @@ -827,10 +912,13 @@ static void execSyringePumpMonitor( void ) { S32 encPosition = getFPGASyringePumpEncoderPosition(); - U08 pmpStatus = getFPGASyringePumpStatus(); - U08 encStatus = getFPGASyringePumpEncoderStatus(); - U08 adcReadCtr = getFPGASyringePumpADCReadCounter(); + // Get latest FPGA status + syringePumpStatus.data = (U32)getFPGASyringePumpStatus(); + syringePumpEncoderStatus.data = (U32)getFPGASyringePumpEncoderStatus(); + syringePumpADCandDACStatus.data = (U32)getFPGASyringePumpADCandDACStatus(); + syringePumpADCReadCtr.data = (U32)getFPGASyringePumpADCReadCounter(); + // Get latest ADC data and convert to V syringePumpMeasHome.data = ( (F32)getFPGASyringePumpADCChannel2() * SYRINGE_PUMP_ADC_REF_V ) / SYRINGE_PUMP_ADC_FULL_SCALE_BITS; syringePumpMeasSyringeDetectionSwitch.data = ( (F32)getFPGASyringePumpADCChannel1() * SYRINGE_PUMP_ADC_REF_V ) / SYRINGE_PUMP_ADC_FULL_SCALE_BITS; @@ -844,7 +932,7 @@ // Calculate measured rate (mL/hr) calcMeasRate(); // Get measured direction - syringePumpControllerMeasuredDirection = ( ( encStatus & SYRINGE_PUMP_ENCODER_DIRECTION_BIT ) != 0 ? MOTOR_DIR_REVERSE : MOTOR_DIR_FORWARD ); + syringePumpControllerMeasuredDirection = ( ( getSyringePumpEncoderStatus() & SYRINGE_PUMP_ENCODER_DIRECTION_BIT ) != 0 ? MOTOR_DIR_REVERSE : MOTOR_DIR_FORWARD ); // Calculate direction from encoder position relative to last syringePumpEncoderMeasuredDirection = ( getSyringePumpPosition() - syringePumpLastPosition >= 0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); @@ -863,17 +951,17 @@ { // Check ADC read is fresh (takes FPGA a while to configure ADC so don't check until after init/POST mode if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_SYRINGE_PUMP_ADC_ERROR, - ( ( getCurrentOperationMode() > MODE_INIT ) && ( lastSyringePumpADCReadCtr == adcReadCtr ) ) ) ) + ( ( getCurrentOperationMode() > MODE_INIT ) && ( lastSyringePumpADCReadCtr == getSyringePumpADCReadCounter() ) ) ) ) { activateAlarmNoData( ALARM_ID_HD_SYRINGE_PUMP_ADC_ERROR ); } - lastSyringePumpADCReadCtr = adcReadCtr; + lastSyringePumpADCReadCtr = getSyringePumpADCReadCounter(); // Check pump status - if ( pmpStatus != 0 ) + if ( getSyringePumpStatus() != 0 ) { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_SYRINGE_PUMP_FAULT, (U32)pmpStatus ); + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_SYRINGE_PUMP_FAULT, (U32)getSyringePumpStatus() ); } } } @@ -1136,9 +1224,6 @@ // Has syringe been removed? stopPump = checkSyringeRemoved( stopPump ); - // Check for occlusion - stopPump = checkOcclusionOrEmpty( stopPump ); - // Check max position > empty + 0.5 mL stopPump = checkMaxTravel( stopPump, SYRINGE_PUMP_EMPTY_POS + SYRINGE_PUMP_EMPTY_POS_MARGIN ); @@ -1309,10 +1394,10 @@ static SYRINGE_PUMP_STATE_T handleSyringePumpCalibrateForceSensorState( void ) { SYRINGE_PUMP_STATE_T result = SYRINGE_PUMP_CONFIG_FORCE_SENSOR_STATE; - U08 adcDACStatus= getFPGASyringePumpADCandDACStatus(); + U08 adcDACStatus= getSyringePumpADCandDACStatus(); // Wait for DAC setting write to EEPROM to complete - if ( ( getFPGASyringePumpADCandDACStatus() & SYRINGE_PUMP_ADC_DAC_ERROR_COUNT_DAC_WR_DONE ) != 0 ) + if ( ( adcDACStatus & SYRINGE_PUMP_ADC_DAC_ERROR_COUNT_DAC_WR_DONE ) != 0 ) { syringePumpDACVrefWriteInProgress = FALSE; // Switch back from DAC to ADC control @@ -1617,6 +1702,10 @@ data.heparinDeliveryState = (U32)heparinDeliveryState; data.syringePumpVolumeDelivered = getSyringePumpVolumeDelivered(); data.syringePumpSafetyVolume = syringePumpSafetyVolumeDelivered; + data.syringePumpStatus = ( (U32)getSyringePumpStatus() << SHIFT_24_BITS ) | + ( (U32)getSyringePumpEncoderStatus() << SHIFT_16_BITS_FOR_WORD_SHIFT ) | + ( (U32)getSyringePumpADCandDACStatus() << SHIFT_8_BITS_FOR_BYTE_SHIFT ) | + ( (U32)getSyringePumpADCReadCounter() ); broadcastSyringePumpData( data ); broadcastHeparinData( data.syringePumpVolumeDelivered ); @@ -2002,4 +2091,184 @@ return result; } +/*********************************************************************//** + * @brief + * The testSetSyringePumpStatus function overrides the syringe pump + * status. + * @details Inputs: none + * @details Outputs: syringePumpStatus + * @param status override syringe pump status with this value + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetSyringePumpStatus( U32 status ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + syringePumpStatus.ovData = status; + syringePumpStatus.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetSyringePumpStatus function resets the override of the + * syringe pump status. + * @details Inputs: none + * @details Outputs: syringePumpStatus + * @return TRUE if reset successful, FALSE if not + *************************************************************************/ +BOOL testResetSyringePumpStatus( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + syringePumpStatus.override = OVERRIDE_RESET; + syringePumpStatus.ovData = syringePumpStatus.ovInitData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testSetSyringePumpEncoderStatus function overrides the syringe + * pump encoder status. + * @details Inputs: none + * @details Outputs: syringePumpEncoderStatus + * @param status override syringe pump encoder status with this value + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetSyringePumpEncoderStatus( U32 status ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + syringePumpEncoderStatus.ovData = status; + syringePumpEncoderStatus.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetSyringePumpEncoderStatus function resets the override + * of the syringe pump encoder status. + * @details Inputs: none + * @details Outputs: syringePumpEncoderStatus + * @return TRUE if reset successful, FALSE if not + *************************************************************************/ +BOOL testResetSyringePumpEncoderStatus( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + syringePumpEncoderStatus.override = OVERRIDE_RESET; + syringePumpEncoderStatus.ovData = syringePumpEncoderStatus.ovInitData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testSetSyringePumpADCandDACStatus function overrides the syringe + * pump ADC and DAC status. + * @details Inputs: none + * @details Outputs: syringePumpADCandDACStatus + * @param status override syringe pump ADC and DAC status with this value + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetSyringePumpADCandDACStatus( U32 status ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + syringePumpADCandDACStatus.ovData = status; + syringePumpADCandDACStatus.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetSyringePumpADCandDACStatus function resets the override + * of the syringe pump ADC and DAC status. + * @details Inputs: none + * @details Outputs: syringePumpADCandDACStatus + * @return TRUE if reset successful, FALSE if not + *************************************************************************/ +BOOL testResetSyringePumpADCandDACStatus( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + syringePumpADCandDACStatus.override = OVERRIDE_RESET; + syringePumpADCandDACStatus.ovData = syringePumpADCandDACStatus.ovInitData; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testSetSyringePumpADCReadCounter function overrides the syringe + * pump ADC read counter. + * @details Inputs: none + * @details Outputs: syringePumpADCReadCtr + * @param ctr override syringe pump ADC read counter with this value + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetSyringePumpADCReadCounter( U32 ctr ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + syringePumpADCReadCtr.ovData = ctr; + syringePumpADCReadCtr.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetSyringePumpADCReadCounter function resets the override + * of the syringe pump ADC read counter. + * @details Inputs: none + * @details Outputs: syringePumpADCReadCtr + * @return TRUE if reset successful, FALSE if not + *************************************************************************/ +BOOL testResetSyringePumpADCReadCounter( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + syringePumpADCReadCtr.override = OVERRIDE_RESET; + syringePumpADCReadCtr.ovData = syringePumpADCReadCtr.ovInitData; + } + + return result; +} + /**@}*/