Index: firmware/App/Controllers/AirTrap.c =================================================================== diff -u -r37a8a58b766a496b39241dd7ae46dc10dbda35e4 -raf2674758d7b9dbe05e348b318845975b423509f --- firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 37a8a58b766a496b39241dd7ae46dc10dbda35e4) +++ firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision af2674758d7b9dbe05e348b318845975b423509f) @@ -17,7 +17,8 @@ #include "AirTrap.h" #include "AlarmMgmt.h" -#include "FPGA.h" +#include "FPGA.h" +#include "ModeTreatmentParams.h" #include "OperationModes.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" @@ -31,7 +32,9 @@ // ********** private definitions ********** -#define AIR_TRAP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< 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 ) ///< interval (ms/task time) at which the air trap data is published on the CAN bus. +#define AIR_TRAP_ILLEGAL_LEVELS_PERSISTENCE ( MS_PER_SECOND * 2 / TASK_PRIORITY_INTERVAL ) ///< persistence period for illegal level sensors fault. +#define VENOUS_LINE_VOLUME_ML ( 50.0 ) ///< TODO volume (in mL) of venous portion of blood circuit line. /// Defined states for the air trap controller state machine. typedef enum AirTrap_States @@ -65,7 +68,11 @@ static U32 airTrapSelfTestTimerCount = 0; ///< timer counter for air trap self-test. 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 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 airTrapIllegalLevelSensorsCtr = 0; ///< timer counter for illegal level sensor fault. // ********** private function prototypes ********** @@ -86,6 +93,7 @@ { resetAirTrap(); airTrapSelfTestState = AIR_TRAP_SELF_TEST_STATE_START; + airTrapIllegalLevelSensorsCtr = 0; } /*********************************************************************//** @@ -157,8 +165,8 @@ /*********************************************************************//** * @brief * The execAirTrapMonitor function executes the air trap monitor. - * @details Inputs: TBD - * @details Outputs: airTrapLevels[] + * @details Inputs: FPGA air trap levels GPIO pin levels, airTrapIllegalLevelSensorsCtr + * @details Outputs: airTrapLevels[], airTrapIllegalLevelSensorsCtr * @return none *************************************************************************/ void execAirTrapMonitor( void ) @@ -173,20 +181,73 @@ // check level readings are valid if ( ( TRUE == lower ) && ( FALSE == upper ) ) { - // TODO - fault if illegal level readings persist - // TODO - close valve and end valve control + if ( ++airTrapIllegalLevelSensorsCtr >= AIR_TRAP_ILLEGAL_LEVELS_PERSISTENCE ) + { + activateAlarmNoData( ALARM_ID_AIR_TRAP_ILLEGAL_LEVELS ); + } } + else + { + airTrapIllegalLevelSensorsCtr--; + } } /*********************************************************************//** * @brief + * The execAirTrapMonitorPriming function executes the air trap monitor + * for cartridge priming during pre-treatment mode. + * @details Inputs: airTrapLevels[], airTrapFillAlarmCtr + * @details Outputs: airTrapFillAlarmCtr + * @return none + *************************************************************************/ +void execAirTrapMonitorPriming( void ) +{ + // TODO - implement when priming sub-mode of pre-treatment mode is implemented. +} + +/*********************************************************************//** + * @brief + * The execAirTrapMonitorTreatment function executes the air trap monitor + * for treatment mode. + * @details Inputs: airTrapLevels[], airTrapFillAlarmCtr + * @details Outputs: airTrapFillAlarmCtr + * @return none + *************************************************************************/ +void execAirTrapMonitorTreatment( void ) +{ + // check air trap fill timeout during treatment + if ( airTrapControllerState > AIR_TRAP_MANUAL_CONTROL_STATE ) + { + if ( AIR_TRAP_LEVEL_AIR == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_LOWER ) ) + { + F32 bldFlowRate = (F32)getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ); // function will never return zero + F32 fillTimeoutMS = ( VENOUS_LINE_VOLUME_ML / bldFlowRate ) * (F32)SEC_PER_MIN * (F32)MS_PER_SECOND; + + if ( TRUE == didTimeout( fillStartTime, fillTimeoutMS ) ) + { + activateAlarmNoData( ALARM_ID_AIR_TRAP_ILLEGAL_LEVELS ); + setValveAirTrap( STATE_CLOSED ); + } + } + } +} + +/*********************************************************************//** + * @brief * The execAirTrapController function executes the air trap control state machine. * @details Inputs: airTrapControllerState * @details Outputs: airTrapControllerState * @return none *************************************************************************/ void execAirTrapController( void ) { + // if we've faulted, close valve and go to manual control + if ( MODE_FAUL == getCurrentOperationMode() ) + { + airTrapControllerState = AIR_TRAP_MANUAL_CONTROL_STATE; + pendingStartAirTrapController = FALSE; + } + // execute air trap state machine switch( airTrapControllerState ) { @@ -261,6 +322,7 @@ else if ( AIR_TRAP_LEVEL_AIR == getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_LOWER ) ) { setValveAirTrap( STATE_OPEN ); + fillStartTime = getMSTimerCount(); result = AIR_TRAP_VALVE_OPEN_STATE; }