Index: firmware/App/Controllers/PresOccl.c =================================================================== diff -u -rd91a24c730aeb5cd7e3eba9ef4eca78e442911f8 -r1a685471524555a374854c0c9ec8e208e71fe2df --- firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision d91a24c730aeb5cd7e3eba9ef4eca78e442911f8) +++ firmware/App/Controllers/PresOccl.c (.../PresOccl.c) (revision 1a685471524555a374854c0c9ec8e208e71fe2df) @@ -8,7 +8,7 @@ * @file PresOccl.c * * @author (last) Sean Nash -* @date (last) 08-Sep-2020 +* @date (last) 24-Sep-2020 * * @author (original) Sean * @date (original) 15-Jan-2020 @@ -40,7 +40,9 @@ #define VENOUS_PRESSURE_OFFSET ( 1638 ) ///< Offset for 14-bit venous pressure sensor reading. #define VENOUS_PRESSURE_SCALE ( 14745 - VENOUS_PRESSURE_OFFSET ) ///< Scale for venous pressure sensor. #define VENOUS_PRESSURE_MIN ( 30.0 ) ///< Minimum of scale for venous pressure sensor reading (in TBD u/m). -#define VENOUS_PRESSURE_MAX ( 90.0 ) ///< Maximum of scale for venous pressure sensor reading (in TBD u/m). +#define VENOUS_PRESSURE_MAX ( 90.0 ) ///< Maximum of scale for venous pressure sensor reading (in TBD u/m). + +#define PSI_TO_MMHG ( 51.7149 ) ///< Conversion factor (mmHg/PSI) for converting PSI to mmHg. /// Defined states for the pressure and occlusion monitor state machine. typedef enum PresOccl_States @@ -64,8 +66,6 @@ static PRESSURE_STATE_T presOcclState = PRESSURE_INIT_STATE; ///< current state of pressure monitor state machine. static U32 presOcclDataPublicationTimerCounter = 0; ///< used to schedule pressure data publication to CAN bus. -static OVERRIDE_F32_T measuredBloodFlowRate = { 0.0, 0.0, 0.0, 0 }; ///< measured blood flow rate - static OVERRIDE_U32_T presOcclDataPublishInterval = { PRES_OCCL_DATA_PUB_INTERVAL, PRES_OCCL_DATA_PUB_INTERVAL, 0, 0 }; ///< interval (in ms) at which to publish pressure/occlusion data to CAN bus. 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. @@ -74,12 +74,8 @@ static OVERRIDE_F32_T dialOutPumpOcclusion = {0.0, 0.0, 0.0, 0 }; ///< measured dialysate outlet pump occlusion pressure. static PRESSURE_SELF_TEST_STATE_T presOcclSelfTestState = PRESSURE_SELF_TEST_STATE_START; ///< current pressure self-test state. -static U32 bloodPumpSelfTestTimerCount = 0; ///< timer counter for pressure self-test. +static U32 presOcclSelfTestTimerCount = 0; ///< timer counter for pressure self-test. -static F32 arterialPressureLowLimitmmHG = 0.0; ///< lower alarm limit for arterial pressure. -static F32 arterialPressureHighLimitmmHG = 0.0; ///< upper alarm limit for arterial pressure. -static F32 venousPressureLowLimitmmHG = 0.0; ///< lower alarm limit for venous pressure. -static F32 venousPressureHighLimitmmHG = 0.0; ///< upper alarm limit for venous pressure. // TODO - set thresholds for occlusions static F32 bloodPumpOcclusionPressureThresholdmmHG = 50.0; ///< pressure threshold for blood pump occlusion. static F32 dialInPumpOcclusionPressureThresholdmmHG = 50.0; ///< pressure threshold for dialysate inlet pump occlusion. @@ -96,9 +92,8 @@ /*********************************************************************//** * @brief * The initPresOccl function initializes the initPresOccl module. - * @details - * Inputs : none - * Outputs : initPresOccl module initialized. + * @details Inputs: none + * @details Outputs: Pressures and Occlusions module initialized. * @return none *************************************************************************/ void initPresOccl( void ) @@ -108,43 +103,10 @@ /*********************************************************************//** * @brief - * The setPressureLimits function sets the lower and upper alarm limits - * for a given pressure sensor. - * @details - * Inputs : none - * Outputs : pressure limits - * @param sensor pressure sensor we are setting limits for - * @param low lower alarm limit (mmHg) - * @param high upper alarm limit (mmHg) - * @return none - *************************************************************************/ -void setPressureLimits( PRESSURE_SENSORS_T sensor, F32 low, F32 high ) -{ - switch ( sensor ) // TODO - will low/high limits be range checked by caller or should we do it here? what are valid ranges? - { - case PRESSURE_SENSOR_ARTERIAL: - arterialPressureLowLimitmmHG = low; - arterialPressureHighLimitmmHG = high; - break; - - case PRESSURE_SENSOR_VENOUS: - venousPressureLowLimitmmHG = low; - venousPressureHighLimitmmHG = high; - break; - - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_PRES_OCCL_INVALID_PRES_SENSOR, sensor ) - break; - } -} - -/*********************************************************************//** - * @brief * The setOcclusionThreshold function sets the occlusion pressure threshold * for a given occlusion sensor. - * @details - * Inputs : none - * Outputs : pressure threshold + * @details Inputs: none + * @details Outputs: pressure threshold * @param sensor occlusion sensor we are setting threshold for * @param threshold pressure threshold above which indicates an occlusion (mmHg) * @return none @@ -174,9 +136,8 @@ /*********************************************************************//** * @brief * The execPresOccl function executes the pressure and occlusion monitor. - * @details - * Inputs : presOcclState - * Outputs : presOcclState + * @details Inputs: presOcclState + * @details Outputs: presOcclState * @return none *************************************************************************/ void execPresOccl( void ) @@ -205,9 +166,8 @@ * @brief * The handlePresOcclInitState function handles the pres/occl initialize state * of the pressure/occlusion monitor state machine. - * @details - * Inputs : TBD - * Outputs : TBD + * @details Inputs: none + * @details Outputs: none * @return next state *************************************************************************/ static PRESSURE_STATE_T handlePresOcclInitState( void ) @@ -221,9 +181,8 @@ * @brief * The handlePresOcclContReadState function handles the continuous read state * of the pressure/occlusion monitor state machine. - * @details - * Inputs : TBD - * Outputs : pressure sensor values updated + * @details Inputs: FPGA pressure/occlusion readings + * @details Outputs: pressure sensor values updated * @return next state *************************************************************************/ static PRESSURE_STATE_T handlePresOcclContReadState( void ) @@ -234,11 +193,13 @@ U16 venPres = getFPGAVenousPressure(); U16 bldOccl = getFPGABloodPumpOcclusion(); U16 dliOccl = getFPGADialInPumpOcclusion(); - U16 dloOccl = getFPGADialOutPumpOcclusion(); + U16 dloOccl = getFPGADialOutPumpOcclusion(); + F32 venPresPSI; // TODO - convert ADC counts to mmHg for each sensor arterialPressure.data = ARTERIAL_PRESSURE_V_PER_BIT * ( (F32)(artPres) / ( ARTERIAL_PRESSURE_SENSITIVITY / ARTERIAL_PRESSURE_V_BIAS ) ); - venousPressure.data = ( (F32)(venPres - VENOUS_PRESSURE_OFFSET) * (VENOUS_PRESSURE_MAX - VENOUS_PRESSURE_MIN) / (F32)VENOUS_PRESSURE_SCALE ) - VENOUS_PRESSURE_MIN; + venPresPSI = ( (F32)(venPres - VENOUS_PRESSURE_OFFSET) * (VENOUS_PRESSURE_MAX - VENOUS_PRESSURE_MIN) / (F32)VENOUS_PRESSURE_SCALE ) - VENOUS_PRESSURE_MIN; + venousPressure.data = venPresPSI * PSI_TO_MMHG; bloodPumpOcclusion.data = (F32)bldOccl; dialInPumpOcclusion.data = (F32)dliOccl; dialOutPumpOcclusion.data = (F32)dloOccl; @@ -257,9 +218,8 @@ * @brief * The checkPressureLimits function gets the pressure/occlusion data * publication interval. - * @details - * Inputs : occlusion pressures for the pumps - * Outputs : + * @details Inputs: occlusion pressures for the pumps + * @details Outputs: alarm(s) may be triggered * @return none *************************************************************************/ static void checkOcclusions( void ) @@ -291,29 +251,26 @@ * @brief * The getPublishPresOcclDataInterval function gets the pressure/occlusion data * publication interval. - * @details - * Inputs : presOcclDataPublishInterval - * Outputs : none + * @details Inputs: presOcclDataPublishInterval + * @details Outputs: none * @return the current pressure/occlusion data publication interval (in task intervals). *************************************************************************/ DATA_GET( U32, getPublishPresOcclDataInterval, presOcclDataPublishInterval ) /*********************************************************************//** * @brief * The getMeasuredArterialPressure function gets the current arterial pressure. - * @details - * Inputs : arterialPressure - * Outputs : none + * @details Inputs: arterialPressure + * @details Outputs: none * @return the current arterial pressure (in mmHg). *************************************************************************/ DATA_GET( F32, getMeasuredArterialPressure, arterialPressure ) /*********************************************************************//** * @brief * The getMeasuredVenousPressure function gets the measured venous pressure. - * @details - * Inputs : venousPressure - * Outputs : none + * @details Inputs: venousPressure + * @details Outputs: none * @return the current venous pressure (in mmHg). *************************************************************************/ DATA_GET( F32, getMeasuredVenousPressure, venousPressure ) @@ -322,9 +279,8 @@ * @brief * The getMeasuredBloodPumpOcclusion function gets the measured blood pump * occlusion pressure. - * @details - * Inputs : bloodPumpOcclusion - * Outputs : none + * @details Inputs: bloodPumpOcclusion + * @details Outputs: none * @return the current blood pump occlusion pressure (in mmHg). *************************************************************************/ DATA_GET( F32, getMeasuredBloodPumpOcclusion, bloodPumpOcclusion ) @@ -333,9 +289,8 @@ * @brief * The getMeasuredDialInPumpOcclusion function gets the measured dialysate * inlet pump occlusion pressure. - * @details - * Inputs : dialInPumpOcclusion - * Outputs : none + * @details Inputs: dialInPumpOcclusion + * @details Outputs: none * @return the current dialysis inlet pump occlusion pressure (in mmHg). *************************************************************************/ DATA_GET( F32, getMeasuredDialInPumpOcclusion, dialInPumpOcclusion ) @@ -344,9 +299,8 @@ * @brief * The getMeasuredDialOutPumpOcclusion function gets the measured dialysate * outlet pump occlusion pressure. - * @details - * Inputs : dialOutPumpOcclusion - * Outputs : none + * @details Inputs: dialOutPumpOcclusion + * @details Outputs: none * @return the current dialysis outlet pump occlusion pressure (in mmHg). *************************************************************************/ DATA_GET( F32, getMeasuredDialOutPumpOcclusion, dialOutPumpOcclusion ) @@ -355,9 +309,8 @@ * @brief * The publishPresOcclData function publishes pressure/occlusion data at the * set interval. - * @details - * Inputs : TBD - * Outputs : Pressure/occlusion data are published to CAN bus. + * @details Inputs: latest pressure and occlusion readings + * @details Outputs: Pressure/occlusion data are published to CAN bus. * @return none *************************************************************************/ static void publishPresOcclData( void ) @@ -380,9 +333,8 @@ * @brief * The execPresOcclTest function executes the state machine for the * PresOccl self-test. - * @details - * Inputs : none - * Outputs : none + * @details Inputs: none + * @details Outputs: none * @return the current state of the PresOccl self-test. *************************************************************************/ SELF_TEST_STATUS_T execPresOcclTest( void ) @@ -404,9 +356,8 @@ * @brief * The testSetPresOcclDataPublishIntervalOverride function overrides the * pressure and occlusion data publish interval. - * @details - * Inputs : none - * Outputs : presOcclDataPublishInterval + * @details Inputs: none + * @details Outputs: presOcclDataPublishInterval * @param value override pressure and occlusion data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -430,9 +381,8 @@ * @brief * The testResetPresOcclDataPublishIntervalOverride function resets the override * of the pressure and occlusion data publish interval. - * @details - * Inputs : none - * Outputs : presOcclDataPublishInterval + * @details Inputs: none + * @details Outputs: presOcclDataPublishInterval * @return TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetPresOcclDataPublishIntervalOverride( void ) @@ -453,9 +403,8 @@ * @brief * The testSetArterialPressureOverride function overrides the measured arterial * pressure. - * @details - * Inputs : none - * Outputs : arterialPressure + * @details Inputs: none + * @details Outputs: arterialPressure * @param value override arterial pressure (in mmHg) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -477,9 +426,8 @@ * @brief * The testResetArterialPressureOverride function resets the override of the * arterial pressure. - * @details - * Inputs : none - * Outputs : arterialPressure + * @details Inputs: none + * @details Outputs: arterialPressure * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetArterialPressureOverride( void ) @@ -500,9 +448,8 @@ * @brief * The testSetVenousPressureOverride function overrides the measured venous * pressure. - * @details - * Inputs : none - * Outputs : venousPressure + * @details Inputs: none + * @details Outputs: venousPressure * @param value override measured venous pressure with (in mmHg) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -524,9 +471,8 @@ * @brief * The testResetVenousPressureOverride function resets the override of the * venous pressure. - * @details - * Inputs : none - * Outputs : venousPressure + * @details Inputs: none + * @details Outputs: venousPressure * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetVenousPressureOverride( void ) @@ -547,9 +493,8 @@ * @brief * The testSetBloodPumpOcclusionOverride function overrides the measured * blood pump occlusion pressure.n - * @details - * Inputs : none - * Outputs : bloodPumpOcclusion + * @details Inputs: none + * @details Outputs: bloodPumpOcclusion * @param value override measured blood pump occlusion pressure with (in mmHg) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -571,9 +516,8 @@ * @brief * The testResetBloodPumpOcclusionOverride function resets the override of the * measured blood pump occlusion pressure. - * @details - * Inputs : none - * Outputs : bloodPumpOcclusion + * @details Inputs: none + * @details Outputs: bloodPumpOcclusion * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetBloodPumpOcclusionOverride( void ) @@ -594,9 +538,8 @@ * @brief * The testSetDialInPumpOcclusionOverride function overrides the measured * dialysate inlet pump occlusion pressure.n - * @details - * Inputs : none - * Outputs : dialInPumpOcclusion + * @details Inputs: none + * @details Outputs: dialInPumpOcclusion * @param value override measured dialysate inlet pump occlusion pressure (in mmHg) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -618,9 +561,8 @@ * @brief * The testResetDialInPumpOcclusionOverride function resets the override of the * measured dialysate inlet pump occlusion pressure. - * @details - * Inputs : none - * Outputs : dialInPumpOcclusion + * @details Inputs: none + * @details Outputs: dialInPumpOcclusion * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetDialInPumpOcclusionOverride( void ) @@ -641,9 +583,8 @@ * @brief * The testSetDialOutPumpOcclusionOverride function overrides the measured * dialysate outlet pump occlusion pressure. - * @details - * Inputs : none - * Outputs : dialOutPumpOcclusion + * @details Inputs: none + * @details Outputs: dialOutPumpOcclusion * @param value override measured dialysate outlet pump occlusion pressure (in mmHg) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -665,9 +606,8 @@ * @brief * The testResetDialOutPumpOcclusionOverride function resets the override of the * measured dialysate outlet pump occlusion pressure. - * @details - * Inputs : none - * Outputs : dialOutPumpOcclusion + * @details Inputs: none + * @details Outputs: dialOutPumpOcclusion * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetDialOutPumpOcclusionOverride( void )