Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -rf0c52f6adff7b61132953890a74f1c462b31eedf -ra111a84009c08c53cc058077ccb8fee95f00436d --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision f0c52f6adff7b61132953890a74f1c462b31eedf) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision a111a84009c08c53cc058077ccb8fee95f00436d) @@ -110,10 +110,15 @@ #define FLOW_SIG_STRGTH_ALARM_PERSIST ( 5 * MS_PER_SECOND ) #define MIN_FLOW_SIG_STRENGTH 0.9 ///< Minimum flow sensor signal strength (90%). -/// Blood flow read timeout alarm persistence. -#define BLOOD_FLOW_READ_TIMEOUT_PERSIST ( 2 * MS_PER_SECOND ) +/// Blood flow fast read timeout alarm persistence. +#define BLOOD_FLOW_FAST_READ_TO_PERSIST 100 +/// Blood flow slow read timeout alarm persistence. +#define BLOOD_FLOW_SLOW_READ_TO_PERSIST ( MS_PER_SECOND * 3 ) -#define BFM_SENSOR_PARAM_CORRUPT_STATUS 0x7 ///< Blood flow meter NVM parameter status. +#define DFM_SENSOR_CONNECTED_STATUS 0x02 ///< Blood flow meter connected status. +#define BFM_SENSOR_PARAM_CORRUPT_STATUS 0x07 ///< Blood flow meter NVM parameter status. + +#define PUMP_DIR_ERROR_COUNT_MASK 0x3F ///< Bit mask for pump direction error counter. /// Enumeration of blood pump controller states. typedef enum BloodPump_States @@ -134,15 +139,6 @@ NUM_OF_BLOOD_FLOW_SELF_TEST_STATES ///< Number of blood pump self-test states } BLOOD_FLOW_SELF_TEST_STATE_T; -/// Enumeration of blood flow read counters. -typedef enum BloodFlow_Read_Counters -{ - BLOOD_FLOW_READ_CTR_FAST_PACKET = 0, ///< Blood flow fast packet read counter - BLOOD_FLOW_READ_CTR_SLOW_PACKET, ///< Blood flow slow packet read counter - BLOOD_FLOW_READ_CTR_STATUS_PACKET, ///< Blood flow status packet read counter - NUM_OF_BLOOD_FLOW_READ_COUNTERS ///< Number of blood pump read counters. -} BLOOD_FLOW_READ_COUNTER_T; - // Pin assignments for pump stop and direction outputs #define STOP_CAN3_PORT_MASK 0x00000002 // (Tx - re-purposed as output GPIO for blood pump stop signal) #define DIR_CAN3_PORT_MASK 0x00000002 // (Rx - re-purposed as output GPIO for blood pump direction signal) @@ -197,7 +193,7 @@ static U08 lastBloodFlowFastPacketReadCtr = 0; ///< Previous read counter for the blood flow fast packets static U08 lastBloodFlowSlowPacketReadCtr = 0; ///< Previous read counter for the blood flow slow packets -static U08 lastBloodFlowStatusPacketReadCtr = 0; ///< Previous read counter for the blood flow status packets +static U08 lastBloodPumpDirectionCount = 0; ///< Previous pump direction error count reported by FPGA // ********** private function prototypes ********** @@ -251,7 +247,6 @@ MIN_BLOOD_PUMP_PWM_DUTY_CYCLE, MAX_BLOOD_PUMP_PWM_DUTY_CYCLE ); // Initialize persistent alarm for flow sensor - initPersistentAlarm( ALARM_ID_HD_BP_FLOW_READ_TIMEOUT_ERROR, 0, BLOOD_FLOW_READ_TIMEOUT_PERSIST ); initPersistentAlarm( ALARM_ID_BLOOD_PUMP_FLOW_VS_MOTOR_SPEED_CHECK, 0, BP_FLOW_VS_SPEED_PERSIST ); initPersistentAlarm( ALARM_ID_BLOOD_PUMP_OFF_CHECK, 0, BP_OFF_ERROR_PERSIST ); initPersistentAlarm( ALARM_ID_BLOOD_PUMP_MOTOR_SPEED_CHECK, 0, BP_MOTOR_SPEED_ERROR_PERSIST ); @@ -260,6 +255,8 @@ initPersistentAlarm( ALARM_ID_BLOOD_PUMP_ROTOR_SPEED_TOO_HIGH, 0, BP_MAX_ROTOR_SPEED_ERROR_PERSIST ); initPersistentAlarm( ALARM_ID_BLOOD_FLOW_SIGNAL_STRENGTH_TOO_LOW, 0, FLOW_SIG_STRGTH_ALARM_PERSIST ); initPersistentAlarm( ALARM_ID_BLOOD_PUMP_MC_CURRENT_CHECK, 0, BP_MAX_CURR_ERROR_DURATION_MS ); + initPersistentAlarm( ALARM_ID_HD_BP_FLOW_READ_TIMEOUT_ERROR, 0, BLOOD_FLOW_FAST_READ_TO_PERSIST ); + initPersistentAlarm( ALARM_ID_HD_BP_FLOW_SLOW_READ_TIMEOUT_ERROR, 0, BLOOD_FLOW_SLOW_READ_TO_PERSIST ); } /*********************************************************************//** @@ -454,29 +451,29 @@ #endif U08 fpReadCtr = getFPGABloodFlowFastPacketReadCounter(); U08 spReadCtr = getFPGABloodFlowSlowPacketReadCounter(); - U08 stpReadCtr = getFPGABloodFlowStatusPacketReadCounter(); U08 flowErrorCtr = getFPGABloodFlowErrorCounter(); + U08 flowStatus = getFPGABloodFlowMeterStatus(); + if ( flowStatus != DFM_SENSOR_CONNECTED_STATUS ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_BLOOD_FLOW_STATUS_SELF_TEST_FAILURE, (U32)flowStatus ); + } + #ifndef DISABLE_FPGA_COUNTER_CHECKS // Check for stale flow reading if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BP_FLOW_READ_TIMEOUT_ERROR, ( fpReadCtr == lastBloodFlowFastPacketReadCtr ) ) ) { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_BP_FLOW_READ_TIMEOUT_ERROR, (U32)BLOOD_FLOW_READ_CTR_FAST_PACKET ) + activateAlarmNoData( ALARM_ID_HD_BP_FLOW_READ_TIMEOUT_ERROR ); } - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BP_FLOW_READ_TIMEOUT_ERROR, ( spReadCtr == lastBloodFlowSlowPacketReadCtr ) ) ) + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BP_FLOW_SLOW_READ_TIMEOUT_ERROR, ( spReadCtr == lastBloodFlowSlowPacketReadCtr ) ) ) { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_BP_FLOW_READ_TIMEOUT_ERROR, (U32)BLOOD_FLOW_READ_CTR_SLOW_PACKET ) + activateAlarmNoData( ALARM_ID_HD_BP_FLOW_SLOW_READ_TIMEOUT_ERROR ); } -// if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BP_FLOW_READ_TIMEOUT_ERROR, ( stpReadCtr == lastBloodFlowStatusPacketReadCtr ) ) ) -// { -// SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_BP_FLOW_READ_TIMEOUT_ERROR, (U32)BLOOD_FLOW_READ_CTR_STATUS_PACKET ) -// } #endif // Record flow read counters for next time around lastBloodFlowFastPacketReadCtr = fpReadCtr; lastBloodFlowSlowPacketReadCtr = spReadCtr; - lastBloodFlowStatusPacketReadCtr = stpReadCtr; adcBloodPumpMCSpeedRPM.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpRPM)) * BP_SPEED_ADC_TO_RPM_FACTOR; adcBloodPumpMCCurrentmA.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpmA)) * BP_CURRENT_ADC_TO_MA_FACTOR; @@ -1058,7 +1055,15 @@ { MOTOR_DIR_T bpMCDir, bpDir; BOOL isDirIncorrect; + U08 dirErrorCnt = getFPGABloodPumpHallSensorStatus() & PUMP_DIR_ERROR_COUNT_MASK; + // Check pump direction error count + if ( lastBloodPumpDirectionCount != dirErrorCnt ) + { + lastBloodPumpDirectionCount = dirErrorCnt; + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_PUMP_DIRECTION_STATUS_ERROR, (U32)HD_PUMP_BLOOD_PUMP ) + } + bpMCDir = ( getMeasuredBloodPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); bpDir = ( getMeasuredBloodPumpSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE );