Index: firmware/App/Controllers/AirTrap.c =================================================================== diff -u -r34d0843fa73e79ba3b085dd4aaa393a1ec126fd4 -r6a8d904f4316ed9d9f2f14f99afde63bef38eace --- firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 34d0843fa73e79ba3b085dd4aaa393a1ec126fd4) +++ firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 6a8d904f4316ed9d9f2f14f99afde63bef38eace) @@ -1,20 +1,21 @@ /************************************************************************** * -* Copyright (c) 2020-2022 Diality Inc. - All Rights Reserved. +* Copyright (c) 2020-2023 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file AirTrap.c * -* @author (last) Michael Garthwaite -* @date (last) 21-Oct-2022 +* @author (last) Dara Navaei +* @date (last) 13-Dec-2022 * * @author (original) Sean Nash * @date (original) 16-Sep-2020 * ***************************************************************************/ +#include "AirPump.h" #include "AirTrap.h" #include "AlarmMgmt.h" #include "FPGA.h" @@ -33,10 +34,11 @@ // ********** private definitions ********** /// Interval (ms/task time) at which the air trap data is published on the CAN bus. -#define AIR_TRAP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) +#define AIR_TRAP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +#define AIR_PUMP_UPPER_LEVEL_PERSISTENCE ( 100 / TASK_GENERAL_INTERVAL ) ///< Persistence time for air pump operation after air trap upper level reads air. /// Persistence period for illegal level sensors fault. -static const U32 AIR_TRAP_ILLEGAL_LEVELS_PERSISTENCE = ( MS_PER_SECOND * 2 / TASK_PRIORITY_INTERVAL ); -static const U32 AIR_TRAP_UPPER_LEVEL_PERSISTENCE = ( MS_PER_SECOND * 2 / TASK_PRIORITY_INTERVAL ); +static const U32 AIR_TRAP_ILLEGAL_LEVELS_PERSISTENCE = ( MS_PER_SECOND * 2 / TASK_GENERAL_INTERVAL ); +static const U32 AIR_TRAP_UPPER_LEVEL_PERSISTENCE = ( MS_PER_SECOND * 2 / TASK_GENERAL_INTERVAL ); /// Volume (in mL) of venous portion of blood circuit line. TODO - get actual volume from Systems. #define VENOUS_LINE_VOLUME_ML ( 200.0F ) @@ -66,8 +68,9 @@ static U32 fillStartTime = 0; ///< Time stamp for start of air trap fill. +static U32 airPumpUpperLevelCtr = 0; ///< Timer count for air pump persistence. static U32 airTrapUpperLevelCtr = 0; ///< Timer count for upper level persistence. -static U32 airTrapIllegalLevelSensorsCtr = 0; ///< Timer counter for illegal level sensor fault. +static U32 airTrapIllegalLevelSensorsCtr = 0; ///< Timer counter for illegal level sensor fault. // ********** private function prototypes ********** @@ -89,6 +92,7 @@ resetAirTrap(); airTrapIllegalLevelSensorsCtr = DATA_PUBLISH_COUNTER_START_COUNT; + airPumpUpperLevelCtr = 0; for ( i = 0; i < NUM_OF_AIR_TRAP_LEVEL_SENSORS; i++ ) { @@ -181,8 +185,9 @@ airTrapLevels[ AIR_TRAP_LEVEL_SENSOR_LOWER ].data = (U32)( TRUE == lower ? AIR_TRAP_LEVEL_AIR : AIR_TRAP_LEVEL_FLUID ); airTrapLevels[ AIR_TRAP_LEVEL_SENSOR_UPPER ].data = (U32)( TRUE == upper ? AIR_TRAP_LEVEL_AIR : AIR_TRAP_LEVEL_FLUID ); - if ( AIR_TRAP_LEVEL_FLUID == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_UPPER ) && - MODE_TREA == getCurrentOperationMode() ) + if ( ( MODE_TREA == getCurrentOperationMode() ) && + ( AIR_TRAP_LEVEL_FLUID == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_UPPER ) ) && + ( AIR_TRAP_VALVE_OPEN_STATE == airTrapControllerState ) ) { if ( ++airTrapUpperLevelCtr >= AIR_TRAP_UPPER_LEVEL_PERSISTENCE ) { @@ -341,9 +346,54 @@ pendingStopAirTrapController = FALSE; result = AIR_TRAP_MANUAL_CONTROL_STATE; } + //Turn on air pump if fluid reaches upper level. + else if ( AIR_TRAP_LEVEL_FLUID == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_UPPER ) ) + { +#ifndef _RELEASE_ + if ( SW_CONFIG_DISABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_AIR_PUMP ) ) +#endif + { + if ( AIR_PUMP_STATE_OFF == getAirPumpState() ) + { + setAirPumpState( AIR_PUMP_STATE_ON ); + } + } + } + + else if ( ( AIR_TRAP_LEVEL_AIR == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_UPPER ) ) ) + { + +#ifndef _RELEASE_ + if ( SW_CONFIG_DISABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_AIR_PUMP ) ) +#endif + { + if ( AIR_PUMP_STATE_ON == getAirPumpState() ) + { + airPumpUpperLevelCtr++; + // Turn air pump off once we detect air at upper level and exceed persistence + // But first, open the air valve. + if ( airPumpUpperLevelCtr >= AIR_PUMP_UPPER_LEVEL_PERSISTENCE ) + { + setAirPumpState( AIR_PUMP_STATE_OFF ); + airPumpUpperLevelCtr = 0; + } + } + } + } + // Transition to open valve state when air detected at lower level else if ( AIR_TRAP_LEVEL_AIR == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_LOWER ) ) { +#ifndef _RELEASE_ + if ( SW_CONFIG_DISABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_AIR_PUMP ) ) +#endif + { + if ( AIR_PUMP_STATE_ON == getAirPumpState() ) + { + setAirPumpState( AIR_PUMP_STATE_OFF ); + airPumpUpperLevelCtr = 0; + } + } setValveAirTrap( STATE_OPEN ); fillStartTime = getMSTimerCount(); result = AIR_TRAP_VALVE_OPEN_STATE; @@ -370,13 +420,12 @@ pendingStopAirTrapController = FALSE; result = AIR_TRAP_MANUAL_CONTROL_STATE; } - // Transition to closed valve state when fluid detected at upper level + // Transition to closed valve state when fluid detected at lower level else if ( AIR_TRAP_LEVEL_FLUID == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_LOWER ) ) { setValveAirTrap( STATE_CLOSED ); result = AIR_TRAP_VALVE_CLOSED_STATE; } - return result; }