Index: firmware/App/Controllers/PresOccl.c =================================================================== diff -u -r2c8547abb99803d8e09918db0e4c66d45c9a15ad -r6e3cc2783dd177a3e53589fcc73ff56f05da20d9 --- firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision 2c8547abb99803d8e09918db0e4c66d45c9a15ad) +++ firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision 6e3cc2783dd177a3e53589fcc73ff56f05da20d9) @@ -20,6 +20,7 @@ #include "AlarmMgmt.h" #include "BloodFlow.h" #include "FPGA.h" +#include "ModeTreatment.h" #include "ModeTreatmentParams.h" #include "NVDataMgmt.h" #include "OperationModes.h" @@ -146,6 +147,7 @@ static OVERRIDE_F32_T arterialPressure = {0.0, 0.0, 0.0, 0 }; ///< Measured arterial pressure. static OVERRIDE_F32_T venousPressure = {0.0, 0.0, 0.0, 0 }; ///< Measured venous pressure. static OVERRIDE_U32_T bloodPumpOcclusion = {0, 0, 0, 0 }; ///< Measured blood pump occlusion pressure. +static PRESSURE_LIMITS_STATES_T currPresLimitsState; ///< Current pressure limits state. static S32 stableArterialPressure; ///< Arterial pressure that limit window is based on (in mmHg). static S32 stableVenousPressure; ///< Venous pressure that limit window is based on (in mmHg). static S32 currentArterialMaxLimit; ///< Maximum arterial pressure limit (in mmHg). @@ -189,6 +191,7 @@ static void checkVenousPressureInRange( void ); static void checkOcclusions( void ); static void publishPresOcclData( void ); +static void determineArtVenPressureLimits( void ); static void filterInlinePressureReadings( F32 artPres, F32 venPres ); /*********************************************************************//** @@ -218,12 +221,11 @@ initFPGAPersistentAlarm( FPGA_PERS_ERROR_VENOUS_PRESSURE_SESNOR, ALARM_ID_HD_VENOUS_SENSOR_FPGA_FAULT, PRES_SENSORS_FPGA_ERROR_TIMEOUT_MS, PRES_SENSORS_FPGA_ERROR_TIMEOUT_MS ); + setPressureLimitsToOuterBounds(); + + currPresLimitsState = PRESSURE_LIMITS_STATE_STABILIZATION; stableArterialPressure = 0; stableVenousPressure = 0; - currentArterialMaxLimit = 0; - currentArterialMinLimit = 0; - currentVenousMaxLimit = 0; - currentVenousMinLimit = 0; longFilteredArterialPressure = 0.0F; shortFilteredArterialPressure = 0.0F; shortFilteredVenousPressure = 0.0F; @@ -333,6 +335,80 @@ venPressureLimitDelayStart = getMSTimerCount(); } +/*********************************************************************//** + * @brief + * The setPressureLimitsToOuterBounds function sets the min/max pressure + * limits for arterial and venous pressure to their outer boundaries. + * @details Inputs: none + * @details Outputs: currentArterialMaxLimit, currentArterialMinLimit, + * currentVenousMaxLimit, currentVenousMinLimit + * @return none + *************************************************************************/ +void setPressureLimitsToOuterBounds( void ) +{ + currentArterialMaxLimit = (S32)ARTERIAL_PRESSURE_LIMIT_MAX_MMHG; + currentArterialMinLimit = (S32)ARTERIAL_PRESSURE_LIMIT_MIN_MMHG; + currentVenousMaxLimit = (S32)VENOUS_PRESSURE_LIMIT_MAX_MMHG; + currentVenousMinLimit = (S32)VENOUS_PRESSURE_LIMIT_MIN_MMHG; +} + +/*********************************************************************//** + * @brief + * The updatePressureLimitWindows function updates the pressure limit + * stable pressure levels when windows set/changed by user. + * If treatment in progress, windowed limits around new stable pressures + * 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: none + * @details Outputs: stableArterialPressure, stableVenousPressure, + * currPresLimitsState + * @param artPresWin new arterial pressure limit window setting + * @param venPresWin new venous pressure limit window setting + * @param venPresAsym new venous pressure limit asymmetric setting + * @return none + *************************************************************************/ +void updatePressureLimitWindows( S32 artPresWin, S32 venPresWin, S32 venPresAsym ) +{ + F32 filtArt = getFilteredArterialPressure(); + F32 filtVen = getFilteredVenousPressure(); + S32 curArtPres = FLOAT_TO_INT_WITH_ROUND( filtArt ); + S32 curVenPres = FLOAT_TO_INT_WITH_ROUND( filtVen ); + + stableArterialPressure = curArtPres; + stableVenousPressure = curVenPres; + // User update of pressure window(s) initiates a stabilization period + currPresLimitsState = PRESSURE_LIMITS_STATE_STABILIZATION; +} + +/*********************************************************************//** + * @brief + * The determineArtVenPressureLimits function determines current pressure + * limits based on whether we are in stabilization or stable situation. + * @details Inputs: currPresLimitsState + * @details Outputs: currentArterialMaxLimit, currentArterialMinLimit, + * currentVenousMaxLimit, currentVenousMinLimit + * @return none + *************************************************************************/ +static void determineArtVenPressureLimits( void ) +{ + 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; + + if ( PRESSURE_LIMITS_STATE_STABLE == currPresLimitsState ) + { // apply pressure windows when stable + currentArterialMaxLimit = stableArterialPressure + artOffset; + currentArterialMinLimit = stableArterialPressure - artOffset; + currentVenousMaxLimit = stableVenousPressure + venMaxOffset; + currentVenousMinLimit = stableVenousPressure - venMinOffset; + } + else + { // apply outer limits when stabilizing + setPressureLimitsToOuterBounds(); + } +} + /*********************************************************************//** * @brief * The execPresOccl function executes the pressure and occlusion monitor. @@ -400,6 +476,9 @@ // Read latest occlusion pressures convertOcclusionPressures(); + // Set arterial/venous pressure limits according to current pressure limits state + determineArtVenPressureLimits(); + // Check in-line pressures are in range checkArterialPressureInRange(); checkVenousPressureInRange(); @@ -879,8 +958,12 @@ PRESSURE_OCCLUSION_DATA_T data; data.arterialPressure = shortFilteredArterialPressure; - data.venousPressure = shortFilteredVenousPressure; - data.bldPumpOcclusion = getMeasuredBloodPumpOcclusion(); + data.venousPressure = shortFilteredVenousPressure; + data.bldPumpOcclusion = getMeasuredBloodPumpOcclusion(); + data.artMinLimit = currentArterialMinLimit; + data.artMaxLimit = currentArterialMaxLimit; + data.venMinLimit = currentVenousMinLimit; + data.venMaxLimit = currentVenousMaxLimit; broadcastData( MSG_ID_PRESSURE_OCCLUSION_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data, sizeof( PRESSURE_OCCLUSION_DATA_T ) ); presOcclDataPublicationTimerCounter = 0;