/************************************************************************** * * Copyright (c) 2024-2024 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 TaskGeneral.c * * @author (last) Sean * @date (last) 30-Jul-2024 * * @author (original) Sean * @date (original) 30-Jul-2024 * ***************************************************************************/ #include "AirPump.h" #include "AirTrap.h" #include "BloodFlow.h" #include "Ejector.h" #include "Messaging.h" #include "OperationModes.h" #include "Pressures.h" #include "Switches.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 #ifdef TEST_PINCH_VALVES #include "FpgaTD.h" #include "LevelSensors.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 ) { #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 // Manage data received from other sub-systems #ifndef TEST_AIR_TRAP_ALPHA_TESTING #ifndef TEST_PINCH_VALVES execSystemCommRx(); #endif #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. if ( ( TRUE == uiCommunicated() ) || ( ( FALSE == isOnlyCANNode() ) && ( TRUE == isAlarmActive( ALARM_ID_TD_UI_COMM_POST_FAILED ) ) ) ) { // Monitor voltages execVoltagesMonitor(); // Monitor DD // execDDInterfaceMonitor(); // Monitor pressure sensors execPressure(); // Monitor switches execSwitches(); // Monitor temperatures // execTemperatures(); // Monitor processor RAM status // execRAMMonitor(); // Monitor blood pump/flow execBloodFlowMonitor(); // Run operation mode state machine execOperationModes(); // Control air trap valve execAirTrapController(); // Control pinch valves execValvesController(); // Control ejector execEjectorController(); // Control blood pump execBloodFlowController(); // Control Air Pump execAirPumpController(); // Monitor/Control fan // execFan(); // Manage NVDataMgmt process record state machine // execNVDataMgmtProcessRecord(); // Manage alarm state execAlarmMgmt(); // Manage data to be transmitted to other sub-systems execSystemCommTx(); } // ****************** Start Air Trap Test Code ************************ #ifdef TEST_PINCH_VALVES #if 0 static BOOL vlvCmd = FALSE; S16 pos = getH19EncoderPosition(); readValves(); // Get level sensor data readAirTrapLevelSensors(); if ( TRUE == vlvCmd ) { setValveCmdChangePosition( H1_VALV, 500, MOTOR_DIR_FORWARD ); // s/b ~30 deg //setValveCmdChangePosition( H19_VALV, 2000, MOTOR_DIR_FORWARD ); vlvCmd = FALSE; } #endif #if 1 { static BOOL homeValveCmd = FALSE; static BOOL setValvePos = FALSE; static VALVE_POSITION_T setPos = VALVE_POSITION_A_INSERT_EJECT; // VALVE_POSITION_B_OPEN VALVE_POSITION_C_CLOSE VALVE_POSITION_A_INSERT_EJECT execValvesController(); if ( TRUE == homeValveCmd ) { homeValve( H1_VALV, FALSE, FALSE ); homeValveCmd = FALSE; } if ( TRUE == setValvePos ) { setValvePosition( H1_VALV, setPos ); setValvePos = FALSE; } } #endif #endif #ifdef TEST_AIR_TRAP_ALPHA_TESTING #if 0 { static U32 tmpCtr = 0; ++tmpCtr; if ( tmpCtr == ( 5 * 20 ) ) { setAirPumpMotorPower( 250 ); 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( 250 ); 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( 1200, MOTOR_DIR_FORWARD ); // homeEjector(); // retractEjector(); bpStart = TRUE; } if ( TRUE == bpStop ) { signalBloodPumpHardStop(); setAirPumpState( AIR_PUMP_STATE_ON, AIR_PUMP_MOTOR_OFF ); set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); bpStop = FALSE; } // Get level sensor data readAirTrapLevelSensors(); execSwitches(); // Control blood pump execBloodFlowMonitor(); execBloodFlowController(); execEjectorController(); 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, 250 ); } break; case 1: // look for air at low 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: #if 1 // 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, 25 ); sta = 3; } #endif 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: #if 0 // look for air at high level if ( AIR_TRAP_LEVEL_AIR == getRawLevelSensorState( H16_LEVL ) ) { // start raising level set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); setAirPumpState( AIR_PUMP_STATE_ON, 100 ); sta = 3; } #endif #if 1 // 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, 100 ); sta = 1; } #endif 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 setCPLDLampGreen( PIN_SIGNAL_LOW ); #endif } /**@}*/