Index: firmware/App/Controllers/PresOccl.c =================================================================== diff -u -rf7b149d8b8c9ea6ac58e4739101693d251d7a355 -r6419179374edcd65da462de84e8aeaefb7e20320 --- firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision f7b149d8b8c9ea6ac58e4739101693d251d7a355) +++ firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision 6419179374edcd65da462de84e8aeaefb7e20320) @@ -57,11 +57,13 @@ #define VENOUS_PRESSURE_STALE_DATA 2 ///< Venous pressure status bits indicate data is stale (no new data since last fpga read). #define VENOUS_PRESSURE_DIAG_CONDITION 3 ///< Venous pressure status bits diagnostic condition (alarm). -#define MAX_TIME_BETWEEN_VENOUS_READINGS ( 500 / TASK_GENERAL_INTERVAL ) ///< Maximum time without fresh inline venous pressure reading. +static const U32 MAX_TIME_BETWEEN_VENOUS_READINGS = ( 500 / TASK_GENERAL_INTERVAL ); ///< Maximum time without fresh inline venous pressure reading. #define OCCLUSION_THRESHOLD 25000 ///< Threshold above which an occlusion is detected. #define CARTRIDGE_LOADED_THRESHOLD 5000 ///< Threshold above which a cartridge is considered loaded. +#define EMPTY_SALINE_BAG_THRESHOLD_MMHG -300.0 ///< Threshold below which the saline bag is considered empty (in mmHg). TODO - get real threshold from Systems +static const U32 EMPTY_SALINE_BAG_PERSISTENCE = ( 250 / TASK_GENERAL_INTERVAL ); ///< Time that saline bag looks empty before saying it is empty. /// Occlusion sensors minimum pressure reading limit when no cartridge is loaded. #define OCCLUSION_NO_CARTRIDGE_PRESSURE_READING_MIN 2000 /// Occlusion sensors maximum pressure reading limit when cartridge is considered loaded. @@ -100,6 +102,7 @@ static OVERRIDE_U32_T dialOutPumpOcclusion = {0, 0, 0, 0 }; ///< Measured dialysate outlet pump occlusion pressure. static U32 staleVenousPressureCtr = 0; ///< Timer counter for stale venous pressure reading. +static U32 emptySalineBagCtr = 0; ///< Timer counter for empty bag detection. // ********** private function prototypes ********** @@ -115,9 +118,9 @@ /*********************************************************************//** * @brief - * The initPresOccl function initializes the initPresOccl module. + * The initPresOccl function initializes the PresOccl module. * @details Inputs: none - * @details Outputs: initPresOccl module initialized. + * @details Outputs: PresOccl module initialized. * @return none *************************************************************************/ void initPresOccl( void ) @@ -154,6 +157,35 @@ return result; } +/*********************************************************************//** + * @brief + * The isSalineBagEmpty function determines whether the saline bag is empty. + * It is assumed that this function will only be called from mode handling + * (General Task) when pumping (BP) from the saline bag. + * Determination is based on pressure going below a negative threshold. + * @details Inputs: arterial line pressure + * @details Outputs: none + * @return TRUE if arterial line pressure is below threshold, FALSE if not. + *************************************************************************/ +BOOL isSalineBagEmpty( void ) +{ + BOOL result = FALSE; + + if ( getMeasuredArterialPressure() < EMPTY_SALINE_BAG_THRESHOLD_MMHG ) + { + if ( ++emptySalineBagCtr >= EMPTY_SALINE_BAG_PERSISTENCE ) + { + result = TRUE; + } + } + else + { + emptySalineBagCtr = 0; + } + + return result; +} + /*********************************************************************//** * @brief * The execPresOccl function executes the pressure and occlusion monitor. @@ -185,7 +217,7 @@ /*********************************************************************//** * @brief - * The handlePresOcclInitState function handles the pres/occl initialize state + * The handlePresOcclInitState function handles the initialize state * of the pressure/occlusion monitor state machine. * @details Inputs: TBD * @details Outputs: TBD @@ -295,8 +327,6 @@ *************************************************************************/ static void convertOcclusionPressures( void ) { - // TODO - any filtering required??? - // Occlusion sensor values have no unit - take as is bloodPumpOcclusion.data = (U32)getFPGABloodPumpOcclusion(); dialInPumpOcclusion.data = (U32)getFPGADialInPumpOcclusion(); @@ -401,7 +431,6 @@ U32 diOccl = getMeasuredDialInPumpOcclusion(); U32 doOccl = getMeasuredDialOutPumpOcclusion(); - // TODO - add persistence #ifndef DISABLE_PRESSURE_CHECKS if ( bpOccl > OCCLUSION_THRESHOLD ) { @@ -429,7 +458,7 @@ * @details Outputs: none * @return the current pressure/occlusion data publication interval (in task intervals). *************************************************************************/ -U32 getPublishPresOcclDataInterval( void ) +static U32 getPublishPresOcclDataInterval( void ) { U32 result = presOcclDataPublishInterval.data; @@ -569,13 +598,11 @@ * @brief * The execPresOcclTest function executes the PresOccl self-test. * @details Inputs: none - * @details Outputs: none - * @return the result of the PresOccl self-test. + * @details Outputs: Triggers fault when test case fails + * @return none *************************************************************************/ -SELF_TEST_STATUS_T execPresOcclTest( void ) +void execPresOcclTest( void ) { - SELF_TEST_STATUS_T result = SELF_TEST_STATUS_PASSED; - U32 const bpPressure = getMeasuredBloodPumpOcclusion(); U32 const dialysateInPressure = getMeasuredDialInPumpOcclusion(); U32 const dialysateOutPressure = getMeasuredDialOutPumpOcclusion(); @@ -584,30 +611,28 @@ if ( ( bpPressure <= OCCLUSION_NO_CARTRIDGE_PRESSURE_READING_MIN ) || ( bpPressure >= OCCLUSION_THRESHOLD ) ) { - result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_BP_OCCLUSION_SELF_TEST_FAILURE, bpPressure ); } if ( ( dialysateInPressure <= OCCLUSION_NO_CARTRIDGE_PRESSURE_READING_MIN ) || ( dialysateInPressure >= OCCLUSION_THRESHOLD ) ) { - result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DIP_OCCLUSION_SELF_TEST_FAILURE, dialysateInPressure ); } if ( ( dialysateOutPressure <= OCCLUSION_NO_CARTRIDGE_PRESSURE_READING_MIN ) || ( dialysateOutPressure >= OCCLUSION_THRESHOLD ) ) { - result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DOP_OCCLUSION_SELF_TEST_FAILURE, dialysateOutPressure ); } if ( ( arterialPressure <= ARTERIAL_PRESSURE_SELF_TEST_MIN ) || ( arterialPressure >= ARTERIAL_PRESSURE_SELF_TEST_MAX ) ) { - result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_ARTERIAL_PRESSURE_SELF_TEST_FAILURE, arterialPressure ); } if ( ( venousPressure <= VENOUS_PRESSURE_SELF_TEST_MIN ) || ( venousPressure >= VENOUS_PRESSURE_SELF_TEST_MAX ) ) { - result = SELF_TEST_STATUS_FAILED; + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_VENOUS_PRESSURE_SELF_TEST_FAILURE, venousPressure ); } - - return result; } /*********************************************************************//** @@ -621,6 +646,7 @@ { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_PASSED; +#ifndef DISABLE_OCCLUSION_SELF_TEST U32 const bpPressure = getMeasuredBloodPumpOcclusion(); U32 const dialysateInPressure = getMeasuredDialInPumpOcclusion(); U32 const dialysateOutPressure = getMeasuredDialOutPumpOcclusion(); @@ -652,6 +678,7 @@ activateAlarmNoData( ALARM_ID_CARTRIDGE_INSTALLED_IMPROPERLY ); } } +#endif return result; }