Index: firmware/App/Controllers/SyringePump.c =================================================================== diff -u -rf01452c199716de698eaf90e692b9bb847d739c3 -rbaadbfda2c0b0a51ee830ec5de414604f9a3971e --- firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision f01452c199716de698eaf90e692b9bb847d739c3) +++ firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision baadbfda2c0b0a51ee830ec5de414604f9a3971e) @@ -82,8 +82,8 @@ #define SYRINGE_PUMP_PRIME_VOLUME_ML 0.353 ///< Target syringe prime volume (in mL). #define SYRINGE_PUMP_MAX_VOL_ERROR_ML 0.1 ///< Maximum Heparin volume error (in mL). #define SYRINGE_PUMP_MAX_RATE_ERROR_ML_HR 0.1 ///< Maximum Heparin delivery rate error (in mL/hr). -#define TEN_PCT_OVER_ALLOWANCE 1.1 ///< Allow ten percent over target before alarming on over travel. -#define FIVE_PCT_OVER_ALLOWANCE 1.05 ///< Allow five percent over target before alarming on over travel. +#define TEN_PCT_OVER_ALLOWANCE 1.1 ///< Allow 10 percent over target before alarming on over travel. +#define FIVE_PCT_OVER_ALLOWANCE 1.05 ///< Allow 5 percent over target before alarming on over travel. /// Expected position of empty in relation to home postion. #define SYRINGE_PUMP_EMPTY_POS ( SYRINGE_ENCODER_COUNTS_PER_ML * 11.0 ) @@ -132,6 +132,10 @@ SYRINGE_PUMP_CONTROL_FORWARD_DIR | SYRINGE_PUMP_CONTROL_32TH_STEP; +#define SYRINGE_PUMP_DAC_WRITE_ERROR_BIT 0x40 ///< Syringe pump DAC write error bit flag in FPGA register. +#define SYRINGE_PUMP_ENCODER_DIRECTION_ERROR_BITS 0x3F ///< Syringe pump encoder direction error counter bits in FPGA register. +#define SYRINGE_PUMP_ENCODER_DIRECTION_BIT 0x80 ///< Syringe pump encoder direction bit in FPGA register. + /// Defined states for the syringe pump control state machine. typedef enum SyringePump_States { @@ -179,7 +183,8 @@ static S32 syringePumpVolumeStartPosition; ///< Start position for the current volume calculation. static S32 syringePumpHomePositionOffset; ///< FPGA reported position when at home postion. static S32 syringePumpPosition1SecAgo; ///< Position recorded at last 1 Hz speed check. -static MOTOR_DIR_T syringePumpMeasuredDirection; ///< Measured direction of syringe pump. +static MOTOR_DIR_T syringePumpControllerMeasuredDirection; ///< Measured direction of syringe pump per controller. +static MOTOR_DIR_T syringePumpEncoderMeasuredDirection; ///< Measured direction of syringe pump per encoder position relative to previous. static BOOL syringePumpRetractRequested; ///< Flag indicates a retract operation is requested. static BOOL syringePumpSeekRequested; ///< Flag indicates a plunger seek operation is requested. @@ -225,7 +230,7 @@ static BOOL checkOcclusionOrEmpty( BOOL stopPump ); static BOOL checkSyringeRemoved( BOOL stopPump ); static BOOL checkMaxTravel( BOOL stopPump, S32 maxPos ); -static BOOL checkMaxMeasRate( BOOL stopPump, F32 pctMargin ); +static BOOL checkMeasRate( BOOL stopPump, F32 pctMargin ); static BOOL checkVolumeVsSafetyVolume( BOOL stopPump, F32 pctMargin ); static void publishSyringePumpData( void ); @@ -248,7 +253,8 @@ syringePumpVolumeStartPosition = 0; syringePumpHomePositionOffset = 0; syringePumpPosition1SecAgo = 0; - syringePumpMeasuredDirection = MOTOR_DIR_FORWARD; + syringePumpControllerMeasuredDirection = MOTOR_DIR_FORWARD; + syringePumpEncoderMeasuredDirection = MOTOR_DIR_FORWARD; syringePumpDataPublicationTimerCounter = 0; syringePumpSelfTestTimerCount = 0; @@ -340,7 +346,7 @@ rejReason = REQUEST_REJECT_REASON_NOT_IN_TREATMENT_MODE; } - sendHeparinCommandResponse( (U32)accepted, (U32)rejReason, (U32)heparinDeliveryState ); + sendHeparinCommandResponse( (U32)accepted, (U32)rejReason ); return accepted; } @@ -751,7 +757,7 @@ { 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; } @@ -798,7 +804,6 @@ U08 pmpStatus = getFPGASyringePumpStatus(); U08 encStatus = getFPGASyringePumpEncoderStatus(); U08 adcReadCtr = getFPGASyringePumpADCReadCounter(); - U08 adcDACStatus= getFPGASyringePumpADCandDACStatus(); // Get latest ADC data and convert to V syringePumpMeasHome.data = ( (F32)getFPGASyringePumpADCChannel2() * SYRINGE_PUMP_ADC_REF_V ) / SYRINGE_PUMP_ADC_FULL_SCALE_BITS; @@ -812,8 +817,12 @@ // Calculate measured rate (mL/hr) calcMeasRate(); // Get measured direction - syringePumpMeasuredDirection = ( ( encStatus & 0x80 ) != 0 ? MOTOR_DIR_REVERSE : MOTOR_DIR_FORWARD ); + syringePumpControllerMeasuredDirection = ( ( encStatus & SYRINGE_PUMP_ENCODER_DIRECTION_BIT ) != 0 ? MOTOR_DIR_REVERSE : MOTOR_DIR_FORWARD ); + // TODO - calc direction from encoder pos relative to last + // syringePumpEncoderMeasuredDirection = TBD; + // TODO - check if syringe pump is on while BP is off (w/ a little persistence). + if ( syringePumpDACVrefWriteInProgress != TRUE ) { // Check ADC read is fresh @@ -824,7 +833,7 @@ lastSyringePumpADCReadCtr = adcReadCtr; // Check encoder direction error. // TODO check direction in states - if ( ( encStatus & 0x3F ) != 0) + if ( ( encStatus & SYRINGE_PUMP_ENCODER_DIRECTION_ERROR_BITS ) != 0) { // TODO - alarm? } @@ -1022,11 +1031,15 @@ syringePumpPrimeCompleted = FALSE; result = SYRINGE_PUMP_OFF_STATE; } - else if ( syringePumpMeasuredDirection != MOTOR_DIR_REVERSE ) + else if ( syringePumpControllerMeasuredDirection != MOTOR_DIR_REVERSE ) { // TODO - alarm w/ some persistence } - // TODO - if position know from prior retract, ensure we don't go lower than -TBD position + else if ( syringePumpEncoderMeasuredDirection != MOTOR_DIR_REVERSE ) + { + // TODO - alarm w/ some persistence + } + // TODO - if position known from prior retract, ensure we don't go lower than -TBD position return result; } @@ -1154,7 +1167,7 @@ stopPump = checkOcclusionOrEmpty( stopPump ); // Check for commanded vs. meas. rate - stopPump = checkMaxMeasRate( stopPump, SYRINGE_PUMP_RATE_CHECK_MARGIN ); + stopPump = checkMeasRate( stopPump, SYRINGE_PUMP_RATE_CHECK_MARGIN ); // Check position > max travel stopPump = checkMaxTravel( stopPump, syringePumpVolumeStartPosition + ( bolusVol * FIVE_PCT_OVER_ALLOWANCE * SYRINGE_ENCODER_COUNTS_PER_ML ) ); @@ -1195,7 +1208,7 @@ stopPump = checkMaxTravel( stopPump, SYRINGE_PUMP_EMPTY_POS + SYRINGE_PUMP_EMPTY_POS_MARGIN ); // Check for commanded vs. meas. rate - stopPump = checkMaxMeasRate( stopPump, SYRINGE_PUMP_RATE_CHECK_MARGIN ); + stopPump = checkMeasRate( stopPump, SYRINGE_PUMP_RATE_CHECK_MARGIN ); // Check volume vs. safety volume stopPump = checkVolumeVsSafetyVolume( stopPump, SYRINGE_PUMP_VOLUME_CHECK_MARGIN ); @@ -1222,6 +1235,7 @@ static SYRINGE_PUMP_STATE_T handleSyringePumpCalibrateForceSensorState( void ) { SYRINGE_PUMP_STATE_T result = SYRINGE_PUMP_CONFIG_FORCE_SENSOR_STATE; + U08 adcDACStatus= getFPGASyringePumpADCandDACStatus(); // Wait for DAC setting write to EEPROM to complete if ( ( getFPGASyringePumpADCandDACStatus() & SYRINGE_PUMP_ADC_DAC_ERROR_COUNT_DAC_WR_DONE ) != 0 ) @@ -1232,7 +1246,13 @@ // Back to off state result = SYRINGE_PUMP_OFF_STATE; } + // Check DAC write error + else if ( ( adcDACStatus & SYRINGE_PUMP_DAC_WRITE_ERROR_BIT ) != 0 ) + { + // TODO - alarm + } + return result; } @@ -1324,16 +1344,15 @@ /*********************************************************************//** * @brief - * The checkMaxMeasRate function checks whether the measured rate is exceeding - * a maximum rate (in mL/hr). This threshold is state dependent so the calling - * function must provide the maximum rate to apply. + * The checkMeasRate function checks whether the measured rate is within a + * given margin of the set rate (in mL/hr). * @details Inputs: syringePumpMeasRate.data, syringePumpSetRate * @details Outputs: alarm triggered if measured and set rates deviate too much * @param stopPump flag passed in by caller indicating whether pump should be stopped * @param pctMargin percent tolerance allowed between set and measured rate * @return TRUE if pump should be stopped, FALSE if not *************************************************************************/ -static BOOL checkMaxMeasRate( BOOL stopPump, F32 pctMargin ) +static BOOL checkMeasRate( BOOL stopPump, F32 pctMargin ) { BOOL result = stopPump; F32 rate = getSyringePumpMeasRate(); Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r9055124b17389e04131b44c00915c33c72db3ae6 -rbaadbfda2c0b0a51ee830ec5de414604f9a3971e --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 9055124b17389e04131b44c00915c33c72db3ae6) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision baadbfda2c0b0a51ee830ec5de414604f9a3971e) @@ -476,25 +476,22 @@ * @details Outputs: Heparin command response msg constructed and queued. * @param accepted flag indicating whether request was accepted * @param rejReason rejection reason code - * @param heparinDeliveryState current Heparin delivery state * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ -BOOL sendHeparinCommandResponse( U32 accepted, U32 rejReason, U32 heparinDeliveryState ) +BOOL sendHeparinCommandResponse( U32 accepted, U32 rejReason ) { BOOL result; MESSAGE_T msg; U08 *payloadPtr = msg.payload; // Create a message record blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_HD_PRESSURE_LIMITS_CHANGE_RESPONSE; - msg.hdr.payloadLen = sizeof( U32 ) * 3; + msg.hdr.msgID = MSG_ID_HD_HEPARIN_PAUSE_RESUME_RESPONSE; + msg.hdr.payloadLen = sizeof( U32 ) * 2; memcpy( payloadPtr, &accepted, sizeof( U32 ) ); payloadPtr += sizeof( U32 ); memcpy( payloadPtr, &rejReason, sizeof( U32 ) ); - payloadPtr += sizeof( U32 ); - memcpy( payloadPtr, &heparinDeliveryState, sizeof( U32 ) ); // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_HD_2_UI, ACK_REQUIRED ); Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r9055124b17389e04131b44c00915c33c72db3ae6 -rbaadbfda2c0b0a51ee830ec5de414604f9a3971e --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 9055124b17389e04131b44c00915c33c72db3ae6) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision baadbfda2c0b0a51ee830ec5de414604f9a3971e) @@ -163,7 +163,7 @@ void handleHeparinCommandRequest( MESSAGE_T *message ); // MSG_ID_HD_HEPARIN_PAUSE_RESUME_RESPONSE -BOOL sendHeparinCommandResponse( U32 accepted, U32 rejReason, U32 heparinDeliveryState ); +BOOL sendHeparinCommandResponse( U32 accepted, U32 rejReason ); // MSG_ID_UI_SAMPLE_WATER_CMD void handleSampleWaterCmd( MESSAGE_T *message );