Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r64f2edc1b7ec8edda7e500b10c09c2a54dc70fc9 -r395522dffef1348e176564925656012f529c1910 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 64f2edc1b7ec8edda7e500b10c09c2a54dc70fc9) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 395522dffef1348e176564925656012f529c1910) @@ -1,112 +1,357 @@ /************************************************************************** * -* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* Copyright (c) 2024-2026 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 (last) Dara Navaei +* @date (last) 31-Oct-2025 * -* @author (original) Sean -* @date (original) 30-Jul-2024 +* @author (original) Sean Nash +* @date (original) 01-Aug-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 "SystemCommTD.h" #include "TaskGeneral.h" +#include "Temperatures.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 ) + + +/*********************************************************************//** + * @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 +#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. + // 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(); // Monitor switches execSwitches(); -// // Monitor temperatures -// execTemperatures(); -// -// // Monitor processor RAM status -// execRAMMonitor(); - - // Run operation mode state machine + // Monitor temperatures + execTemperature(); + + // Monitor processor RAM status +// execRAMMonitor(); + + // Monitor blood pump/flow + execBloodFlowMonitor(); + + // Run operation mode state machine execOperationModes(); -// // Control air trap valve -// execAirTrapController(); -// -// // Control blood pump -// execBloodFlowController(); -// + // Control air trap valve + execAirTrapController(); + + // Control pinch valves + execValvesController(); + + // Control ejector + execEjectorController(); + + // Control blood pump + execBloodFlowController(); + // Control Air Pump execAirPumpController(); -// // Monitor/Control fan + // Monitor/Control fan // execFan(); -// -// // Manage NVDataMgmt process record state machine + + // 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_PINCH_VALVES +#if 0 + static U32 vlvCmd = 0; + S16 pos = getH19EncoderPosition(); + + readValves(); + // Get level sensor data + readAirTrapLevelSensors(); + if ( 1 == vlvCmd ) + { + setValveCmdChangePosition( H1_VALV, 896, MOTOR_DIR_FORWARD ); + setValveCmdChangePosition( H19_VALV, 1600, MOTOR_DIR_FORWARD ); + vlvCmd = 0; + } + if ( 2 == vlvCmd ) + { + setValveCmdChangePosition( H1_VALV, 0, MOTOR_DIR_FORWARD ); + setValveCmdChangePosition( H19_VALV, 0, MOTOR_DIR_FORWARD ); + vlvCmd = 0; + } +#endif +#if 1 + { + static BOOL homeValveCmd = FALSE; + static BOOL setValvePos = FALSE; + static BOOL homeBPCmd = FALSE; + static BOOL bpHomed = FALSE; + static BOOL bpRunCmd = FALSE; + static BOOL bpStopCmd = FALSE; + static U32 bpSetPt = 300; + static VALVE_POSITION_T setPos = VALVE_POSITION_A_INSERT_EJECT; // VALVE_POSITION_B_OPEN VALVE_POSITION_C_CLOSE VALVE_POSITION_A_INSERT_EJECT + + execValvesController(); + execBloodFlowMonitor(); + execBloodFlowController(); + + bpHomed = isPeristalticPumpHome(); + if ( TRUE == bpHomed ) + { + bpHomed = FALSE; + } + if ( TRUE == homeBPCmd ) + { + homeBloodPump(); + homeBPCmd = FALSE; + } + + if ( TRUE == bpRunCmd ) + { + setBloodPumpTargetFlowRate( bpSetPt, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + bpRunCmd = FALSE; + } + else if ( TRUE == bpStopCmd ) + { + setBloodPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + bpStopCmd = FALSE; + //signalBloodPumpHardStop(); + } + + 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 ); + extendEjector(); + 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 + // Set GPIO low to indicate general task has finished executing setCPLDLampGreen( PIN_SIGNAL_LOW ); #endif -} +} -/**@}*/ +/**@}*/