Index: firmware/App/Controllers/PresOccl.c =================================================================== diff -u -r437aa0eeb7df7ddc8ea58dd5623be2911f4cdff2 -rdd18920c6a8890cc3449128b8480aa33eb0955ec --- firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision 437aa0eeb7df7ddc8ea58dd5623be2911f4cdff2) +++ firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision dd18920c6a8890cc3449128b8480aa33eb0955ec) @@ -7,8 +7,8 @@ * * @file PresOccl.c * -* @author (last) Darren Cox -* @date (last) 08-Sep-2023 +* @author (last) Vinayakam Mani +* @date (last) 07-Mar-2024 * * @author (original) Sean * @date (original) 15-Jan-2020 @@ -40,12 +40,15 @@ // ********** private definitions ********** /// Default publication interval for pressure and occlusion data. -#define PRES_OCCL_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the pressure/occlusion data is published on the CAN bus. +#define PRES_OCCL_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the pressure/occlusion data is published on the CAN bus. +#define PRES_LIMIT_STABILIZATION_OFF ( 0 ) ///< pressure limit stabilization period off +#define PRES_LIMIT_STABILIZATION_2_TIME_MS ( 60 * MS_PER_SECOND ) ///< Duration of pressure limit second stage stabilization period (in ms) +#define PRES_LIMIT_STABILIZATION_TIME_MS ( 60 * MS_PER_SECOND ) ///< Duration of pressure limit stabilization period (in ms). +#define PRES_LIMIT_SHORT_STABILIZE_TIME_MS ( 10 * MS_PER_SECOND ) ///< Duration of pressure limit short stabilization period (in ms). +#define PRES_LIMIT_RESTABILIZE_TIME_MS ( 15 * SEC_PER_MIN * MS_PER_SECOND ) ///< Duration of pressure limit re-stabilize period (in ms). +/// Pressure Limit minimum stabilization time before short stabilization time activation +static const U32 PRES_LIMIT_MIN_STABILIZATION_TIME_IN_MS = ( PRES_LIMIT_STABILIZATION_TIME_MS - PRES_LIMIT_SHORT_STABILIZE_TIME_MS ); -#define PRES_LIMIT_STABILIZATION_TIME_MS ( 60 * MS_PER_SECOND ) ///< Duration of pressure limit stabilization period (in ms). -#define PRES_LIMIT_SHORT_STABILIZE_TIME_MS ( 10 * MS_PER_SECOND ) ///< Duration of pressure limit short stabilization period (in ms). -#define PRES_LIMIT_RESTABILIZE_TIME_MS ( 30 * SEC_PER_MIN * MS_PER_SECOND ) ///< Duration of pressure limit re-stabilize period (in ms). - #define ARTERIAL_PRESSURE_CONVERSION_OFFSET 0x800000 ///< Arterial pressure conversion coefficient. #define ARTERIAL_PRESSURE_V_BIAS ( 3.0F ) ///< Bias voltage for arterial pressure sensor. #define ARTERIAL_PRESSURE_SENSITIVITY ( 0.000005F ) ///< Sensitivity for arterial pressure sensor is 5 uV / mmHg @@ -78,14 +81,12 @@ #define VENOUS_PRESSURE_LIMIT_MAX_MMHG ( 400.0F ) ///< Maximum venous pressure limit (in mmHg). #define VENOUS_PRESSURE_LIMIT_MIN_MMHG ( 20.0F ) ///< Minimum venous pressure limit (in mmHg). #define VENOUS_PRESSURE_OCCL_OFFSET_MMHG ( 50.0F ) ///< Venous pressure occlusion threshold offset from max alarm limit (in mmHg). -#define VENOUS_PRES_AT_FILL_DELAY_MAX_BLOOD_VOL_ML ( 41.667F ) ///< Venous pressure low exemption delay after air trap fill maximum blood volume (in mL). +#define VENOUS_PRESSURE_EXEMPTION_PERIOD ( ( 2 * MS_PER_SECOND ) / \ + TASK_GENERAL_INTERVAL ) ///< Venous pressure low exemption period (in task interval) after fill for all blood flow rate -/// Venous pressure low exemption period (in task intervals) conversion factor (from Qb in mL/min) following an air trap fill. -static const U32 VENOUS_PRES_AT_FILL_DELAY_FACTOR = (U32)( VENOUS_PRES_AT_FILL_DELAY_MAX_BLOOD_VOL_ML * (F32)SEC_PER_MIN * ( (F32)MS_PER_SECOND / (F32)TASK_GENERAL_INTERVAL ) ); - #define MIN_TIME_BETWEEN_AIR_TRAP_FILL_EXEMPTIONS_MS ( 1200 ) ///< To monitor low Venous pressure in the defined interval in a case where continuous air fill event happens followed by exemption period to stabilize the pressure #define MIN_TIME_BETWEEN_AIR_TRAP_FILL_EXEMPTIONS_WINDOW ( MIN_TIME_BETWEEN_AIR_TRAP_FILL_EXEMPTIONS_MS / \ - TASK_GENERAL_INTERVAL ) ///< Low Venous pressure monitoring window between air fill events based on the task interval time + TASK_GENERAL_INTERVAL ) ///< Low Venous pressure monitoring window between air fill events based on the task interval time #define PSI_TO_MMHG ( 51.7149F ) ///< Conversion factor for converting PSI to mmHg. @@ -112,6 +113,7 @@ static const U32 EMPTY_SALINE_BAG_PERSISTENCE = ( 250 / TASK_GENERAL_INTERVAL ); ///< Time that saline bag looks empty before saying it is empty. #define PRES_ALARM_PERSISTENCE ( 1 * MS_PER_SECOND ) ///< Alarm persistence period for pressure alarms. +#define HIGH_VEN_PRES_ALARM_PERSISTENCE 500 ///< Alarm persistence period for high venous pressure alarm #define PRES_OCCL_ALARM_PERSISTENCE ( 3 * MS_PER_SECOND ) ///< Alarm persistence period for occlusion alarms #define VEN_OCCL_ALARM_PERSISTENCE 100 ///< Alarm persistence period for venous occlusion alarm. #define AIR_PUMP_TOLERANCE_TIMEOUT_MS (1 * MS_PER_SECOND ) ///< Time to allow increased maximum venous high limit @@ -177,7 +179,7 @@ static OVERRIDE_F32_T shortFilteredArterialPressure = { 0.0, 0.0, 0.0, 0 }; ///< Measured arterial pressure after short (1 s) filter. static F32 longFilteredVenousPressure; ///< Measured venous pressure after long (10 s) filter. static OVERRIDE_F32_T shortFilteredVenousPressure = { 0.0, 0.0, 0.0, 0 }; ///< Measured venous pressure after short (1 s) filter. -static BOOL useShortStabilizeTime; ///< Flag to use short stabilize time. +static STABILIZATION_PERIODS_T pressureStabilizeTime; ///< Pressure stabilization time based on system events such as airpump, treatment param changes etc., static BOOL resetFillExemptPeriod; ///< Flag to reset the exempt period after defined time expire. static BOOL lowVenousPressureExemptCheck; ///< low venous pressure exempt check flag based on the air trap valve status @@ -236,7 +238,7 @@ initPersistentAlarm( ALARM_ID_HD_ARTERIAL_PRESSURE_LOW, 0, PRES_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_HD_ARTERIAL_PRESSURE_HIGH, 0, PRES_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_HD_VENOUS_PRESSURE_LOW, 0, PRES_ALARM_PERSISTENCE ); - initPersistentAlarm( ALARM_ID_HD_VENOUS_PRESSURE_HIGH, 0, PRES_ALARM_PERSISTENCE ); + initPersistentAlarm( ALARM_ID_HD_VENOUS_PRESSURE_HIGH, 0, HIGH_VEN_PRES_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_HD_ARTERIAL_PRESSURE_OUT_OF_RANGE, 0, PRES_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_HD_VENOUS_PRESSURE_OUT_OF_RANGE, 0, PRES_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_HD_BP_OCCLUSION_OUT_OF_RANGE, 0, PRES_OCCL_ALARM_PERSISTENCE ); @@ -268,7 +270,7 @@ presOcclState = PRESSURE_WAIT_FOR_POST_STATE; presOcclPostState = PRESSURE_SELF_TEST_STATE_START; bloodPumpOcclusionAfterCartridgeInstall = 0; - useShortStabilizeTime = USE_NORMAL_STABILIZATION_PERIOD; + pressureStabilizeTime = USE_NORMAL_STABILIZATION_PERIOD; resetFillExemptPeriod = TRUE; lowVenousPressureExemptCheck = TRUE; } @@ -415,7 +417,7 @@ * will be in effect immediately (next monitor pass). If treatment paused, * resume will start a new stabilization period ending in another set of * stable pressures before windowed limits recalculated. - * @details Inputs: useShortStabilizeTime + * @details Inputs: pressureStabilizeTime * @details Outputs: stableArterialPressure, stableVenousPressure * @return none *************************************************************************/ @@ -426,7 +428,7 @@ S32 curArtPres; S32 curVenPres; - if ( USE_SHORT_STABILIZATION_PERIOD == useShortStabilizeTime ) + if ( USE_SHORT_STABILIZATION_PERIOD == pressureStabilizeTime ) { filtArt = getFilteredArterialPressure(); filtVen = getFilteredVenousPressure(); @@ -453,22 +455,33 @@ * was stable, a rate change will kick us back to stabilization state. * Else reset stabilize counter. * @details Inputs: currPresLimitsState - * @details Outputs: currPresLimitsState, stabilizationStartTimeMs, useShortStabilizeTime - * @param useShort Flag to use short stabilization period. Use defines: - * USE_NORMAL_STABILIZATION_PERIOD, USE_SHORT_STABILIZATION_PERIOD + * @details Outputs: currPresLimitsState, stabilizationStartTimeMs, pressureStabilizeTime + * @param stabilizationPeriod stabilization periods. Use defines: + * STABILIZATION_PERIOD_OFF, USE_NORMAL_STABILIZATION_PERIOD, USE_SHORT_STABILIZATION_PERIOD * @return none *************************************************************************/ -void signalInitiatePressureStabilization( BOOL useShort ) +void signalInitiatePressureStabilization( STABILIZATION_PERIODS_T stabilizationPeriod ) { - useShortStabilizeTime = useShort; - // User update of blood/dialysate flow rate or UF rate or initiates/resets a stabilization period (if we were in stabilization or stable state) if ( PRESSURE_LIMITS_STATE_STABILIZATION == currPresLimitsState ) { - stabilizationStartTimeMs = getMSTimerCount(); + U32 currentTime = getMSTimerCount(); + U32 expiredTime = u32DiffWithWrap( stabilizationStartTimeMs, currentTime ); + + // if pressure is already stabilized enough, assign the short stabilize time for the recent event ( air pump on). + // else,allow the ongoing stabilization to complete. + // allow Normal stabilization on a case when user updates flow rate or UF rate etc., + if ( ( expiredTime > PRES_LIMIT_MIN_STABILIZATION_TIME_IN_MS ) || + ( stabilizationPeriod == USE_NORMAL_STABILIZATION_PERIOD ) ) + { + pressureStabilizeTime = stabilizationPeriod; + stabilizationStartTimeMs = getMSTimerCount(); + } } - else if ( PRESSURE_LIMITS_STATE_STABLE == currPresLimitsState ) + else if ( ( PRESSURE_LIMITS_STATE_STABLE == currPresLimitsState ) || + ( PRESSURE_LIMITS_STATE_STABILIZATION_2 == currPresLimitsState ) ) { + pressureStabilizeTime = stabilizationPeriod; currPresLimitsState = PRESSURE_LIMITS_STATE_STABILIZATION; stabilizationStartTimeMs = getMSTimerCount(); } @@ -485,8 +498,10 @@ *************************************************************************/ static void determineArtVenPressureLimits( void ) { - if ( PRESSURE_LIMITS_STATE_STABLE == currPresLimitsState ) - { // apply pressure windows when stable + if ( ( PRESSURE_LIMITS_STATE_STABLE == currPresLimitsState ) || + ( PRESSURE_LIMITS_STATE_STABILIZATION_2 == currPresLimitsState ) ) + { + // apply pressure windows when stable S32 artOffset = getTreatmentParameterS32( TREATMENT_PARAM_ART_PRES_LIMIT_WINDOW ) / 2; // Arterial is symmetric S32 venMinOffset = getTreatmentParameterS32( TREATMENT_PARAM_VEN_PRES_LIMIT_ASYMMETRIC ); // Venous is asymmetric S32 venMaxOffset = getTreatmentParameterS32( TREATMENT_PARAM_VEN_PRES_LIMIT_WINDOW ) - venMinOffset; @@ -636,7 +651,7 @@ else if ( ( TREATMENT_DIALYSIS_STATE == currTxState ) || ( TREATMENT_STOP_STATE == currTxState ) ) { stabilizationStartTimeMs = getMSTimerCount(); - useShortStabilizeTime = USE_NORMAL_STABILIZATION_PERIOD; + pressureStabilizeTime = USE_NORMAL_STABILIZATION_PERIOD; currPresLimitsState = PRESSURE_LIMITS_STATE_STABILIZATION; } else if ( currTxState == TREATMENT_RECIRC_STATE ) @@ -646,10 +661,12 @@ break; case PRESSURE_LIMITS_STATE_STABILIZATION: - if ( USE_SHORT_STABILIZATION_PERIOD == useShortStabilizeTime ) + // update stabilization time + if ( USE_SHORT_STABILIZATION_PERIOD == pressureStabilizeTime ) { stabilizeTime = PRES_LIMIT_SHORT_STABILIZE_TIME_MS; } + // Normal stabilization period else { stabilizeTime = PRES_LIMIT_STABILIZATION_TIME_MS; @@ -667,12 +684,44 @@ { updatePressureLimitWindows(); stabilizationStartTimeMs = getMSTimerCount(); - useShortStabilizeTime = USE_NORMAL_STABILIZATION_PERIOD; + currPresLimitsState = PRESSURE_LIMITS_STATE_STABILIZATION_2; + pressureStabilizeTime = USE_NORMAL_STABILIZATION_PERIOD; + } + break; + + case PRESSURE_LIMITS_STATE_STABILIZATION_2: + // zero stabilize time for 15 mins once pressure limits adjust scenario + if ( STABILIZATION_PERIOD_OFF == pressureStabilizeTime ) + { + stabilizeTime = PRES_LIMIT_STABILIZATION_OFF; + } + //60 sec second stage stabilization + else + { + stabilizeTime = PRES_LIMIT_STABILIZATION_2_TIME_MS; + } + + // second stage stabilization helps to re determine the pressure due to UF control change etc., + if ( bpRunning != TRUE ) + { + currPresLimitsState = PRESSURE_LIMITS_STATE_IDLE; + } + else if ( ( currTxState != TREATMENT_DIALYSIS_STATE ) && ( currTxState != TREATMENT_STOP_STATE ) ) + { + currPresLimitsState = PRESSURE_LIMITS_STATE_WIDE; + } + else if ( TRUE == didTimeout( stabilizationStartTimeMs, stabilizeTime ) ) + { + updatePressureLimitWindows(); + stabilizationStartTimeMs = getMSTimerCount(); currPresLimitsState = PRESSURE_LIMITS_STATE_STABLE; + // Reset to normal period as default. + pressureStabilizeTime = USE_NORMAL_STABILIZATION_PERIOD; } break; case PRESSURE_LIMITS_STATE_STABLE: + // Pressure is re determined after every 15 minutes once and be remain in limited pressure windows. if ( bpRunning != TRUE ) { currPresLimitsState = PRESSURE_LIMITS_STATE_IDLE; @@ -684,8 +733,8 @@ else if ( TRUE == didTimeout( stabilizationStartTimeMs, PRES_LIMIT_RESTABILIZE_TIME_MS ) ) { stabilizationStartTimeMs = getMSTimerCount(); - useShortStabilizeTime = USE_NORMAL_STABILIZATION_PERIOD; - currPresLimitsState = PRESSURE_LIMITS_STATE_STABILIZATION; + pressureStabilizeTime = STABILIZATION_PERIOD_OFF; + currPresLimitsState = PRESSURE_LIMITS_STATE_STABILIZATION_2; } break; @@ -859,10 +908,9 @@ if ( pressureLimitsActive != FALSE ) { BOOL venPresLow, venPresHigh; - S32 qB = abs( getTargetBloodFlowRate() ); - U32 qBx = ( 0 == qB ? MIN_SET_BLOOD_FLOW_RATE : (U32)qB ); - // compute exemption period (in general task intervals) for low venous pressure alarms after air trap fills - U32 exemptPeriod = VENOUS_PRES_AT_FILL_DELAY_FACTOR / qBx; + + // Fixed exemption period (in general task intervals) for low venous pressure alarms after air trap fills + U32 exemptPeriod = VENOUS_PRESSURE_EXEMPTION_PERIOD; // minimumMonitoring Window helps to check and raise low venous pressure alarm on a case where repeated fill events occurrence. // During this interval, if another airtrap fill occurs, there is no exemptions provided to stabilize the pressure and low venous pressure being raised when it goes below threshold value. U32 minimumMonitoringWindow = exemptPeriod + MIN_TIME_BETWEEN_AIR_TRAP_FILL_EXEMPTIONS_WINDOW ; @@ -1015,8 +1063,8 @@ *************************************************************************/ void signalLowVenousPressureCheck( void ) { - // When flag set, low venous pressure exempt counter increments. - lowVenousPressureExemptCheck = TRUE; + // When flag set, low venous pressure exempt counter increments. + lowVenousPressureExemptCheck = TRUE; } /*********************************************************************//**