Index: firmware/App/Controllers/AirTrap.c =================================================================== diff -u -r2a3a47ca90ad19851a30c52f6999a56d5f578783 -r0a4dcd288d4347b85baaa0b07da568b6add5eac7 --- firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 2a3a47ca90ad19851a30c52f6999a56d5f578783) +++ firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 0a4dcd288d4347b85baaa0b07da568b6add5eac7) @@ -1,85 +1,88 @@ /************************************************************************** * -* Copyright (c) 2019-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) Dara Navaei -* @date (last) 04-Jan-2022 +* @date (last) 13-Dec-2022 * * @author (original) Sean Nash * @date (original) 16-Sep-2020 * ***************************************************************************/ - -#include "AirTrap.h" -#include "AlarmMgmt.h" + +#include "AirTrap.h" +#include "AlarmMgmt.h" #include "FPGA.h" -#include "ModeTreatmentParams.h" -#include "OperationModes.h" -#include "SystemCommMessages.h" +#include "ModeTreatmentParams.h" +#include "OperationModes.h" +#include "SystemCommMessages.h" #include "TaskGeneral.h" -#include "TaskPriority.h" -#include "Timers.h" - -/** - * @addtogroup AirTrap - * @{ - */ - -// ********** private definitions ********** +#include "TaskPriority.h" +#include "Timers.h" -/// 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 ) +/** + * @addtogroup AirTrap + * @{ + */ + +// ********** 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_GENERAL_INTERVAL ) /// 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 ); + /// Volume (in mL) of venous portion of blood circuit line. TODO - get actual volume from Systems. -#define VENOUS_LINE_VOLUME_ML ( 200.0 ) -#define DATA_PUBLISH_COUNTER_START_COUNT 7 ///< Data publish counter start count. - -/// Defined states for the air trap controller state machine. -typedef enum AirTrap_States -{ - AIR_TRAP_INIT_STATE = 0, ///< Initialization state +#define VENOUS_LINE_VOLUME_ML ( 200.0F ) +#define DATA_PUBLISH_COUNTER_START_COUNT 7 ///< Data publish counter start count. + +/// Defined states for the air trap controller state machine. +typedef enum AirTrap_States +{ + AIR_TRAP_INIT_STATE = 0, ///< Initialization state AIR_TRAP_MANUAL_CONTROL_STATE, ///< Manually control air trap valve state AIR_TRAP_VALVE_CLOSED_STATE, ///< Valve closed state - until air detected at lower level - AIR_TRAP_VALVE_OPEN_STATE, ///< Valve open state - until fluid detected at upper level - NUM_OF_AIR_TRAP_STATES ///< Number of air trap controller states -} AIR_TRAP_STATE_T; - -// ********** private data ********** - -static AIR_TRAP_STATE_T airTrapControllerState; ///< Current state of air trap controller state machine. -static U32 airTrapDataPublicationTimerCounter; ///< Used to schedule air trap data publication to CAN bus. - + AIR_TRAP_VALVE_OPEN_STATE, ///< Valve open state - until fluid detected at upper level + NUM_OF_AIR_TRAP_STATES ///< Number of air trap controller states +} AIR_TRAP_STATE_T; + +// ********** private data ********** + +static AIR_TRAP_STATE_T airTrapControllerState; ///< Current state of air trap controller state machine. +static U32 airTrapDataPublicationTimerCounter; ///< Used to schedule air trap data publication to CAN bus. + /// Interval (in ms) at which to publish air trap data to CAN bus. -static OVERRIDE_U32_T airTrapDataPublishInterval = { AIR_TRAP_DATA_PUB_INTERVAL, AIR_TRAP_DATA_PUB_INTERVAL, 0, 0 }; -static OVERRIDE_U32_T airTrapLevels[ NUM_OF_AIR_TRAP_LEVEL_SENSORS ]; ///< Detected air trap level for each level sensor. +static OVERRIDE_U32_T airTrapDataPublishInterval = { AIR_TRAP_DATA_PUB_INTERVAL, AIR_TRAP_DATA_PUB_INTERVAL, 0, 0 }; +static OVERRIDE_U32_T airTrapLevels[ NUM_OF_AIR_TRAP_LEVEL_SENSORS ]; ///< Detected air trap level for each level sensor. static BOOL pendingStartAirTrapController = FALSE; ///< Flag indicates an air trap controller start request is pending. static BOOL pendingStopAirTrapController = FALSE; ///< Flag indicates an air trap controller stop request is pending. static U32 fillStartTime = 0; ///< Time stamp for start of air trap fill. +static U32 airTrapUpperLevelCtr = 0; ///< Timer count for upper level persistence. static U32 airTrapIllegalLevelSensorsCtr = 0; ///< Timer counter for illegal level sensor fault. - -// ********** private function prototypes ********** - -static AIR_TRAP_STATE_T handleAirTrapManualControlState( void ); -static AIR_TRAP_STATE_T handleAirTrapValveClosedState( void ); + +// ********** private function prototypes ********** + +static AIR_TRAP_STATE_T handleAirTrapManualControlState( void ); +static AIR_TRAP_STATE_T handleAirTrapValveClosedState( void ); static AIR_TRAP_STATE_T handleAirTrapValveOpenState( void ); -static void publishAirTrapData( void ); - -/*********************************************************************//** - * @brief - * The initAirTrap function initializes the Air Trap module. - * @details Inputs: none - * @details Outputs: Air Trap module initialized. - * @return none - *************************************************************************/ +static void publishAirTrapData( void ); + +/*********************************************************************//** + * @brief + * The initAirTrap function initializes the Air Trap module. + * @details Inputs: none + * @details Outputs: Air Trap module initialized. + * @return none + *************************************************************************/ void initAirTrap( void ) { U32 i; @@ -178,6 +181,27 @@ 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 ( ++airTrapUpperLevelCtr >= AIR_TRAP_UPPER_LEVEL_PERSISTENCE ) + { +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_ILLEGAL_AIR_TRAP_ALARM ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + activateAlarmNoData( ALARM_ID_HD_AIR_TRAP_OVERFILL ); + } + } + } + else + { + if ( airTrapUpperLevelCtr > 0 ) + { + airTrapUpperLevelCtr = 0; + } + } + // Check level readings are valid if ( ( AIR_TRAP_LEVEL_AIR == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_LOWER ) ) && ( AIR_TRAP_LEVEL_FLUID == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_UPPER ) ) ) @@ -220,7 +244,9 @@ if ( TRUE == didTimeout( fillStartTime, fillTimeoutMS ) ) { +#ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_AIR_TRAP_LEVELING_ALARM ) != SW_CONFIG_ENABLE_VALUE ) +#endif { activateAlarmNoData( ALARM_ID_AIR_TRAP_FILL_DURING_TREATMENT ); } @@ -345,7 +371,7 @@ result = AIR_TRAP_MANUAL_CONTROL_STATE; } // Transition to closed valve state when fluid detected at upper level - else if ( AIR_TRAP_LEVEL_FLUID == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_UPPER ) ) + else if ( AIR_TRAP_LEVEL_FLUID == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_LOWER ) ) { setValveAirTrap( STATE_CLOSED ); result = AIR_TRAP_VALVE_CLOSED_STATE; @@ -525,4 +551,4 @@ return result; } -/**@}*/ +/**@}*/