Index: firmware/App/Controllers/AirTrap.c =================================================================== diff -u -r6d044be7a5c4ef961c2d2569d88be95c9bd86be6 -rfa4f2bfd1ec6a4f007b23789b002429125d7f1a8 --- firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 6d044be7a5c4ef961c2d2569d88be95c9bd86be6) +++ firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision fa4f2bfd1ec6a4f007b23789b002429125d7f1a8) @@ -55,14 +55,17 @@ // ********** private data ********** -static AIR_TRAP_STATE_T airTrapControllerState = AIR_TRAP_INIT_STATE; ///< current state of air trap controller state machine. +static AIR_TRAP_STATE_T airTrapControllerState; ///< current state of air trap controller state machine. static U32 airTrapDataPublicationTimerCounter = 0; ///< used to schedule air trap data publication to CAN bus. static OVERRIDE_U32_T airTrapDataPublishInterval = { AIR_TRAP_DATA_PUB_INTERVAL, AIR_TRAP_DATA_PUB_INTERVAL, 0, 0 }; ///< interval (in ms) at which to publish air trap data to CAN bus. -static OVERRIDE_U32_T arterialPressure[ NUM_OF_AIR_TRAP_LEVEL_SENSORS ]; ///< detected air trap level for each level sensor. +static OVERRIDE_U32_T airTrapLevels[ NUM_OF_AIR_TRAP_LEVEL_SENSORS ]; ///< detected air trap level for each level sensor. -static AIR_TRAP_SELF_TEST_STATE_T airTrapSelfTestState = AIR_TRAP_SELF_TEST_STATE_START; ///< current air trap self-test state. -static U32 airTrapSelfTestTimerCount = 0; ///< timer counter for air trap self-test. +static AIR_TRAP_SELF_TEST_STATE_T airTrapSelfTestState; ///< current air trap self-test state. +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. // ********** private function prototypes ********** @@ -74,46 +77,108 @@ /*********************************************************************//** * @brief - * The initPresOccl function initializes the initPresOccl module. + * The initAirTrap function initializes the Air Trap module. * @details * Inputs : none - * Outputs : initPresOccl module initialized. + * Outputs : Air Trap module initialized. * @return none *************************************************************************/ void initAirTrap( void ) { + resetAirTrap(); + airTrapSelfTestState = AIR_TRAP_SELF_TEST_STATE_START; +} +/*********************************************************************//** + * @brief + * The resetAirTrap function resets certain parts of the air trap module + * between treatments. + * @details + * Inputs : none + * Outputs : Air Trap module reset. + * @return none + *************************************************************************/ +void resetAirTrap( void ) +{ + airTrapControllerState = AIR_TRAP_INIT_STATE; + pendingStartAirTrapController = FALSE; + pendingStopAirTrapController = FALSE; } +/*********************************************************************//** + * @brief + * The startAirTrapControl function requests a start to air trap control. + * @details + * Inputs : airTrapControllerState + * Outputs : pendingStartAirTrapController + * @return none + *************************************************************************/ void startAirTrapControl( void ) { - + if ( FALSE == isAirTrapControlling() ) + { + pendingStartAirTrapController = TRUE; + } } +/*********************************************************************//** + * @brief + * The endAirTrapControl function requests a stop to air trap control. + * @details + * Inputs : airTrapControllerState + * Outputs : pendingStopAirTrapController + * @return none + *************************************************************************/ void endAirTrapControl( void ) { + if ( TRUE == isAirTrapControlling() ) + { + pendingStopAirTrapController = TRUE; + } +} +/*********************************************************************//** + * @brief + * The isAirTrapControlling function determines whether the air trap is + * currently controlling. + * @details + * Inputs : airTrapControllerState + * Outputs : none + * @return TRUE if air trap is currently controlling, FALSE if not. + *************************************************************************/ +BOOL isAirTrapControlling( void ) +{ + BOOL result = FALSE; + + if ( airTrapControllerState >= AIR_TRAP_VALVE_CLOSED_STATE ) + { + result = TRUE; + } + + return result; } /*********************************************************************//** * @brief - * The execPresOccl function executes the pressure and occlusion monitor. + * The execAirTrapMonitor function executes the air trap monitor. * @details - * Inputs : presOcclState - * Outputs : presOcclState + * Inputs : TBD + * Outputs : airTrapLevels[] * @return none *************************************************************************/ void execAirTrapMonitor( void ) { + // TODO - get latest level readings + // TODO - fault if illegal level readings persist } /*********************************************************************//** * @brief - * The execPresOccl function executes the pressure and occlusion monitor. + * The execAirTrapController function executes the air trap control state machine. * @details - * Inputs : presOcclState - * Outputs : presOcclState + * Inputs : airTrapControllerState + * Outputs : airTrapControllerState * @return none *************************************************************************/ void execAirTrapController( void ) @@ -142,8 +207,8 @@ /*********************************************************************//** * @brief - * The handlePresOcclInitState function handles the pres/occl initialize state - * of the pressure/occlusion monitor state machine. + * The handleAirTrapManualControlState function handles the manual control + * state of the air trap. * @details * Inputs : TBD * Outputs : TBD @@ -158,47 +223,27 @@ /*********************************************************************//** * @brief - * The handlePresOcclContReadState function handles the continuous read state - * of the pressure/occlusion monitor state machine. + * The handleAirTrapValveClosedState function handles the valve closed state + * of the air trap. * @details * Inputs : TBD - * Outputs : pressure sensor values updated + * Outputs : TBD * @return next state *************************************************************************/ static AIR_TRAP_STATE_T handleAirTrapValveClosedState( void ) { AIR_TRAP_STATE_T result = AIR_TRAP_VALVE_CLOSED_STATE; -// S32 artPres = getFPGAArterialPressure(); -// U16 venPres = getFPGAVenousPressure(); -// U16 bldOccl = getFPGABloodPumpOcclusion(); -// U16 dliOccl = getFPGADialInPumpOcclusion(); -// U16 dloOccl = getFPGADialOutPumpOcclusion(); -// -// // 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; -// bloodPumpOcclusion.data = (F32)bldOccl; -// dialInPumpOcclusion.data = (F32)dliOccl; -// dialOutPumpOcclusion.data = (F32)dloOccl; -// -// // TODO - any filtering required??? -// -// // check for occlusions -// checkOcclusions(); -// -// // TODO - any other checks - return result; } /*********************************************************************//** * @brief - * The handlePresOcclContReadState function handles the continuous read state - * of the pressure/occlusion monitor state machine. + * The handleAirTrapValveOpenState function handles the valve open state of + * the air trap. * @details * Inputs : TBD - * Outputs : pressure sensor values updated + * Outputs : TBD * @return next state *************************************************************************/ static AIR_TRAP_STATE_T handleAirTrapValveOpenState( void ) @@ -210,33 +255,29 @@ /*********************************************************************//** * @brief - * The publishPresOcclData function publishes pressure/occlusion data at the - * set interval. + * The publishAirTrapData function publishes air trap data at the set interval. * @details - * Inputs : TBD - * Outputs : Pressure/occlusion data are published to CAN bus. + * Inputs : airTrapLevels[] + * Outputs : if broadcast is due, send air trap data * @return none *************************************************************************/ static void publishAirTrapData( void ) { // publish pressure/occlusion data on interval if ( ++airTrapDataPublicationTimerCounter >= getPublishAirTrapDataInterval() ) { -// F32 artPres = getMeasuredArterialPressure(); -// F32 venPres = getMeasuredVenousPressure(); -// F32 bpOccl = getMeasuredBloodPumpOcclusion(); -// F32 diOccl = getMeasuredDialInPumpOcclusion(); -// F32 doOccl = getMeasuredDialOutPumpOcclusion(); -// -// broadcastPresOcclData( artPres, venPres, bpOccl, diOccl, doOccl ); -// presOcclDataPublicationTimerCounter = 0; + AIR_TRAP_LEVELS_T lowLevel = getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_LOWER ); + AIR_TRAP_LEVELS_T highLevel = getAirTrapLevel( AIR_TRAP_LEVEL_SENSOR_UPPER ); + +// broadcastAirTrapData( (U32)lowLevel, (U32)highLevel ); + airTrapDataPublicationTimerCounter = 0; } } /*********************************************************************//** * @brief - * The execPresOcclTest function executes the state machine for the - * PresOccl self-test. + * The execAirTrapTest function executes the state machine for the air trap + * self-test. * @details * Inputs : none * Outputs : none @@ -251,33 +292,53 @@ /*********************************************************************//** * @brief - * The getPublishPresOcclDataInterval function gets the pressure/occlusion data - * publication interval. + * The getAirTrapLevel function gets the current reading for the given + * level sensor. * @details - * Inputs : presOcclDataPublishInterval + * Inputs : airTrapLevels[] * Outputs : none - * @return the current pressure/occlusion data publication interval (in task intervals). + * @param sensor ID of level sensor to get reading for + * @return the current level sensor reading for the given sensor (air or fluid). *************************************************************************/ AIR_TRAP_LEVELS_T getAirTrapLevel( AIR_TRAP_LEVEL_SENSORS_T sensor ) { AIR_TRAP_LEVELS_T result; + if ( sensor < NUM_OF_AIR_TRAP_LEVEL_SENSORS ) + { + result = (AIR_TRAP_LEVELS_T)airTrapLevels[ sensor ].data; + if ( OVERRIDE_KEY == airTrapLevels[ sensor ].override ) + { + result = (AIR_TRAP_LEVELS_T)airTrapLevels[ sensor ].ovData; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, 0, (U32)sensor ) // TODO - 1st param s/b a unique enum from AlarmMgmt.h + result = AIR_TRAP_LEVEL_AIR; + } + return result; } /*********************************************************************//** * @brief - * The getPublishPresOcclDataInterval function gets the pressure/occlusion data + * The getPublishAirTrapDataInterval function gets the air trap data * publication interval. * @details - * Inputs : presOcclDataPublishInterval + * Inputs : airTrapDataPublishInterval * Outputs : none - * @return the current pressure/occlusion data publication interval (in task intervals). + * @return the current air trap data publication interval (in task intervals). *************************************************************************/ static U32 getPublishAirTrapDataInterval( void ) { - U32 result; + U32 result = airTrapDataPublishInterval.data; + if ( OVERRIDE_KEY == airTrapDataPublishInterval.override ) + { + result = airTrapDataPublishInterval.ovData; + } + return result; } @@ -289,67 +350,102 @@ /*********************************************************************//** * @brief - * The testSetPresOcclDataPublishIntervalOverride function overrides the - * pressure and occlusion data publish interval. + * The testSetAirTrapDataPublishIntervalOverride function overrides the + * air trap data publish interval. * @details * Inputs : none - * Outputs : presOcclDataPublishInterval + * Outputs : airTrapDataPublishInterval * @param value override pressure and occlusion data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetAirTrapDataPublishIntervalOverride( U32 value ) { BOOL result = FALSE; + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + airTrapDataPublishInterval.ovData = value; + airTrapDataPublishInterval.override = OVERRIDE_KEY; + } + return result; } /*********************************************************************//** * @brief - * The testResetPresOcclDataPublishIntervalOverride function resets the override - * of the pressure and occlusion data publish interval. + * The testResetAirTrapDataPublishIntervalOverride function resets the override + * of the air trap data publish interval. * @details * Inputs : none - * Outputs : presOcclDataPublishInterval + * Outputs : airTrapDataPublishInterval * @return TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetAirTrapDataPublishIntervalOverride( void ) { BOOL result = FALSE; + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + airTrapDataPublishInterval.override = OVERRIDE_RESET; + airTrapDataPublishInterval.ovData = airTrapDataPublishInterval.ovInitData; + } + return result; } /*********************************************************************//** * @brief - * The testSetArterialPressureOverride function overrides the measured arterial - * pressure. + * The testSetArterialPressureOverride function overrides the measured level + * for a given level sensor. * @details * Inputs : none - * Outputs : arterialPressure - * @param value override arterial pressure (in mmHg) + * Outputs : airTrapLevels[] + * @param sensor ID of level sensor to override + * @param value override level sensor with this * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetAirTrapLevelOverride( AIR_TRAP_LEVEL_SENSORS_T sensor, AIR_TRAP_LEVELS_T level ) { BOOL result = FALSE; + if ( sensor < NUM_OF_AIR_TRAP_LEVEL_SENSORS ) + { + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + airTrapLevels[ sensor ].ovData = (U32)level; + airTrapLevels[ sensor ].override = OVERRIDE_KEY; + } + } + return result; } /*********************************************************************//** * @brief - * The testResetArterialPressureOverride function resets the override of the - * arterial pressure. + * The testResetAirTrapLevelOverride function resets the override of the + * level sensor. * @details * Inputs : none - * Outputs : arterialPressure + * Outputs : airTrapLevels[] * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetAirTrapLevelOverride( AIR_TRAP_LEVEL_SENSORS_T sensor ) { BOOL result = FALSE; + if ( sensor < NUM_OF_AIR_TRAP_LEVEL_SENSORS ) + { + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + airTrapLevels[ sensor ].override = OVERRIDE_RESET; + airTrapLevels[ sensor ].ovData = airTrapLevels[ sensor ].ovInitData; + } + } + return result; }