Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r051326e2671e8d5b3e99eaa109ea549e94a929f3 -r285b5d82539c96524c93703d52a66fff76fb64fc --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 051326e2671e8d5b3e99eaa109ea549e94a929f3) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 285b5d82539c96524c93703d52a66fff76fb64fc) @@ -22,53 +22,61 @@ #include "OperationModes.h" #include "Pressures.h" #include "Switches.h" -#include "SystemCommTD.h" +#include "SystemCommTD.h" #include "TaskGeneral.h" #include "Valves.h" #include "Voltages.h" #include "WatchdogMgmt.h" +#ifdef TEST_AIR_TRAP_ALPHA_TESTING +#include "GLXferPump.h" +#include "LevelSensors.h" +#include "Valve3Way.h" +#endif + /** * @addtogroup TaskGeneral * @{ */ // ********** private data ********** - - -/*********************************************************************//** - * @brief - * The taskGeneral function handles the scheduled General Task interrupt. - * Calls the executive functions for most monitors and controllers, the - * operation modes, the system communications, and alarms. - * @details \b Inputs: none - * @details \b Outputs: Executive functions running in general task are called. - * @return none - *************************************************************************/ -void taskGeneral( void ) + + +/*********************************************************************//** + * @brief + * The taskGeneral function handles the scheduled General Task interrupt. + * Calls the executive functions for most monitors and controllers, the + * operation modes, the system communications, and alarms. + * @details \b Inputs: none + * @details \b Outputs: Executive functions running in general task are called. + * @return none + *************************************************************************/ +void taskGeneral( void ) { #ifdef TASK_TIMING_OUTPUT_ENABLED // Set GPIO high to indicate general task has begun executing setCPLDLampGreen( PIN_SIGNAL_HIGH ); #endif - // Check in with watchdog manager - checkInWithWatchdogMgmt( TASK_GENERAL ); // Do this first to keep timing consistent with watchdog management + // Check in with watchdog manager + checkInWithWatchdogMgmt( TASK_GENERAL ); // Do this first to keep timing consistent with watchdog management - // Manage data received from other sub-systems + // Manage data received from other sub-systems +#ifndef TEST_AIR_TRAP_ALPHA_TESTING execSystemCommRx(); - +#endif + // Prevent most processing until UI has started communicating or if DG is active and alarm (ALARM_ID_HD_UI_COMM_POST_FAILED) is raised - // proceed to further operations since UI likely failed to come up. + // proceed to further operations since UI likely failed to come up. if ( ( TRUE == uiCommunicated() ) || ( ( FALSE == isOnlyCANNode() ) && ( TRUE == isAlarmActive( ALARM_ID_TD_UI_COMM_POST_FAILED ) ) ) ) { // Monitor voltages execVoltagesMonitor(); - // Monitor DD + // Monitor DD // execDDInterfaceMonitor(); - + // Monitor pressure sensors execPressure(); @@ -79,23 +87,23 @@ // execTemperatures(); // Monitor processor RAM status -// execRAMMonitor(); - +// execRAMMonitor(); + // Monitor blood pump/flow execBloodFlowMonitor(); - // Run operation mode state machine + // Run operation mode state machine execOperationModes(); // Control air trap valve execAirTrapController(); // Control pinch valves - execValvesController(); - - // Control blood pump - execBloodFlowController(); - + execValvesController(); + + // Control blood pump + execBloodFlowController(); + // Control Air Pump execAirPumpController(); @@ -105,17 +113,136 @@ // Manage NVDataMgmt process record state machine // execNVDataMgmtProcessRecord(); - // Manage alarm state + // Manage alarm state execAlarmMgmt(); - // Manage data to be transmitted to other sub-systems - execSystemCommTx(); - } - + // Manage data to be transmitted to other sub-systems + execSystemCommTx(); + } + + // ****************** Start Air Trap Test Code ************************ +#ifdef TEST_AIR_TRAP_ALPHA_TESTING +#if 0 + { + static U32 tmpCtr = 0; + + ++tmpCtr; + if ( tmpCtr == ( 5 * 20 ) ) + { + setAirPumpMotorPower( 255 ); + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); + } + else if ( tmpCtr == ( 10 * 20 ) ) + { + setAirPumpMotorPower( 0 ); + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + } + else if ( tmpCtr == ( 15 * 20 ) ) + { + setAirPumpMotorPower( 255 ); + set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); + } + else if ( tmpCtr >= ( 20 * 20 ) ) + { + setAirPumpMotorPower( 0 ); + set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + tmpCtr = 0; + } + } +#endif +#if 1 + static U32 ctr = 0; + static U32 sta = 0; + static BOOL start = TRUE; + static BOOL bpStart = FALSE; + static BOOL bpStop = FALSE; + + if ( FALSE == bpStart ) + { + setBloodPumpTargetRPM( 1000, MOTOR_DIR_FORWARD ); + bpStart = TRUE; + } + if ( TRUE == bpStop ) + { + signalBloodPumpHardStop(); + bpStop = FALSE; + } + + // Get level sensor data + readAirTrapLevelSensors(); + // Control blood pump + execBloodFlowController(); + execAirPumpController(); + + switch ( sta ) + { + case 0: + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + setAirPumpState( AIR_PUMP_STATE_ON, AIR_PUMP_MOTOR_OFF ); + + if ( TRUE == start ) + { + sta = 1; + // lower the level + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); + setAirPumpState( AIR_PUMP_STATE_ON, 255 ); + } + break; + case 1: + // look for air at high level and stop + if ( AIR_TRAP_LEVEL_AIR == getRawLevelSensorState( H16_LEVL ) ) + { + // stop lowering level + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); + ctr = 0; + sta = 2; + } + break; + case 2: + // stay low for 5 sec + if ( ++ctr > ( 5 * 20 ) ) + { + // raise the level + set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); + setAirPumpState( AIR_PUMP_STATE_ON, 255 ); + sta = 3; + } + break; + case 3: + // look for fluid at high level and stop + if ( AIR_TRAP_LEVEL_FLUID == getRawLevelSensorState( H16_LEVL ) ) + { + // stop raising level + set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); + ctr = 0; + sta = 4; + } + break; + case 4: + // stay high for 5 sec + if ( ++ctr > ( 5 * 20 ) ) + { + // lower the level + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); + setAirPumpState( AIR_PUMP_STATE_ON, 255 ); + sta = 1; + } + break; + default: + sta = 0; + break; + } +#endif +#endif + // ******************* End Air Trap Test Code ************************* + #ifdef TASK_TIMING_OUTPUT_ENABLED - // Set GPIO low to indicate general task has finished executing + // Set GPIO low to indicate general task has finished executing setCPLDLampGreen( PIN_SIGNAL_LOW ); #endif -} +} -/**@}*/ +/**@}*/