Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r285b5d82539c96524c93703d52a66fff76fb64fc -r395522dffef1348e176564925656012f529c1910 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 285b5d82539c96524c93703d52a66fff76fb64fc) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 395522dffef1348e176564925656012f529c1910) @@ -1,29 +1,31 @@ /************************************************************************** * -* 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 "TaskGeneral.h" +#include "Temperatures.h" #include "Valves.h" #include "Voltages.h" #include "WatchdogMgmt.h" @@ -34,6 +36,11 @@ #include "Valve3Way.h" #endif +#ifdef TEST_PINCH_VALVES +#include "FpgaTD.h" +#include "LevelSensors.h" +#endif + /** * @addtogroup TaskGeneral * @{ @@ -63,8 +70,10 @@ // 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. @@ -84,7 +93,7 @@ execSwitches(); // Monitor temperatures -// execTemperatures(); + execTemperature(); // Monitor processor RAM status // execRAMMonitor(); @@ -101,6 +110,9 @@ // Control pinch valves execValvesController(); + // Control ejector + execEjectorController(); + // Control blood pump execBloodFlowController(); @@ -121,6 +133,80 @@ } // ****************** 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 { @@ -129,7 +215,7 @@ ++tmpCtr; if ( tmpCtr == ( 5 * 20 ) ) { - setAirPumpMotorPower( 255 ); + setAirPumpMotorPower( 250 ); set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); } else if ( tmpCtr == ( 10 * 20 ) ) @@ -139,7 +225,7 @@ } else if ( tmpCtr == ( 15 * 20 ) ) { - setAirPumpMotorPower( 255 ); + setAirPumpMotorPower( 250 ); set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); } else if ( tmpCtr >= ( 20 * 20 ) ) @@ -159,19 +245,28 @@ if ( FALSE == bpStart ) { - setBloodPumpTargetRPM( 1000, MOTOR_DIR_FORWARD ); +// 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(); - // Control blood pump + execSwitches(); + // Control blood pump + execBloodFlowMonitor(); execBloodFlowController(); + execEjectorController(); execAirPumpController(); switch ( sta ) @@ -186,11 +281,11 @@ sta = 1; // lower the level set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); - setAirPumpState( AIR_PUMP_STATE_ON, 255 ); + setAirPumpState( AIR_PUMP_STATE_ON, 250 ); } break; case 1: - // look for air at high level and stop + // look for air at low level and stop if ( AIR_TRAP_LEVEL_AIR == getRawLevelSensorState( H16_LEVL ) ) { // stop lowering level @@ -201,14 +296,16 @@ } 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, 255 ); + setAirPumpState( AIR_PUMP_STATE_ON, 25 ); sta = 3; } +#endif break; case 3: // look for fluid at high level and stop @@ -222,14 +319,26 @@ } 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, 255 ); + setAirPumpState( AIR_PUMP_STATE_ON, 100 ); sta = 1; } +#endif break; default: sta = 0;