Communication processing methods, communication processing systems and electronic devices
By employing a dynamic adaptive UART time-division multiplexing communication scheme, combined with an EWMA prediction model and a hardware analog switch isolation mechanism, the problem of insufficient bandwidth and resource waste in multi-device communication of traditional UART interfaces is solved, achieving efficient and reliable multi-device communication, which is particularly suitable for resource-constrained embedded devices.
Patent Information
- Application Number
- CN202611223876.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-12
- Publication Date
- 2026-11-17
AI Technical Summary
In multi-device communication scenarios, traditional UART interfaces cannot dynamically adjust the communication duration according to the actual load. This leads to insufficient bandwidth for high-priority devices when the load increases suddenly, causing communication delays or packet loss. Meanwhile, low-load devices are idle due to fixed time slice allocation, making it difficult to balance the real-time requirements of multiple devices with the efficient utilization of hardware resources.
A dynamic and adaptive UART time-division multiplexing communication scheme is adopted. By monitoring the channel utilization rate in real time, and combining the Exponential Weighted Moving Average (EWMA) prediction model with a dynamic smoothing coefficient adjustment mechanism based on the utilization rate change rate, the connection duration of high-priority devices is intelligently calculated and the remaining duration is automatically allocated to low-priority devices. At the same time, it integrates hardware analog switches to physically isolate signals of multiple devices, handshake instruction timeout judgment, and dual-buffered data management combining DMA and CPU polling to realize intelligent time-division multiplexing of UART interface among multiple devices.
It achieves the goal of ensuring the communication bandwidth requirements of high-priority devices while avoiding resource idleness of low-load devices, improving the communication efficiency and system robustness of multiple devices under a single UART interface, and is suitable for resource-constrained embedded device scenarios.
Smart Images

Figure CN123123290A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, specifically to a communication processing method, a communication processing system, and an electronic device. Background Technology
[0002] In multi-device communication scenarios, traditional single Universal Asynchronous Receiver / Transmitter (UART) interfaces typically use a fixed time slice allocation method.
[0003] However, this can lead to insufficient bandwidth when the load on high-priority devices suddenly increases, causing communication delays or packet loss, while low-load devices suffer from resource waste due to fixed time slice allocation, making it difficult to balance the real-time requirements of multiple devices with the efficient utilization of hardware resources. Summary of the Invention
[0004] This application provides a communication processing method, a communication processing system, and an electronic device to alleviate the aforementioned technical problems.
[0005] In a first aspect, this application provides a communication processing method, which includes: determining a first connection duration in a subsequent total cycle based on the channel utilization rate of the current total cycle, wherein the total cycle is a fixed duration, the first connection duration is the duration of a UART interface connected to a first device at a first baud rate, and the channel utilization rate is the utilization rate of the first channel formed by the UART interface connected to the first device at the first baud rate in the current total cycle; determining a second connection duration in a subsequent total cycle based on the duration difference between the total cycle and the first connection duration, wherein the second connection duration is the duration of a UART interface connected to a second device at a second baud rate; and switching the connection between the UART interface and the first device or the second device in the subsequent total cycle based on the first connection duration and the second connection duration.
[0006] Secondly, this application also provides a communication processing system, which includes a first duration determination module, a second duration determination module, and a switching module. The first duration determination module is used to determine the first connection duration in the next total cycle based on the channel utilization rate of the current total cycle. The total cycle is a fixed duration, the first connection duration is the duration of the UART interface connecting to the first device at a first baud rate, and the channel utilization rate is the utilization rate of the first channel formed by the UART interface connecting to the first device at the first baud rate in the current total cycle. The second duration determination module is used to determine the second connection duration in the next total cycle based on the duration difference between the total cycle and the first connection duration. The second connection duration is the duration of the UART interface connecting to the second device at a second baud rate. The switching module is used to switch the connection between the UART interface and the first device or the second device in the next total cycle based on the first connection duration and the second connection duration.
[0007] Thirdly, this application also provides an electronic device, which includes a timer, a control unit, a UART interface, a first device, a second device, and a switching switch; the timer is used to divide a total cycle and trigger an interrupt signal in each total cycle; the control unit is used to respond to the interrupt signal and calculate a first connection duration and a second connection duration in the next total cycle; the switching switch is controlled by the control unit and is used to switch the connection between the UART interface and the first device or the second device within the total cycle according to the first connection duration and the second connection duration; the UART interface is configured to communicate with the first device at a first baud rate during the first connection duration and to communicate with the second device at a second baud rate during the second connection duration, wherein the first baud rate is higher than the second baud rate.
[0008] The communication processing method, communication processing system, and electronic device provided in this application dynamically determine the connection duration of the first device in the next total cycle based on the channel utilization rate of the first channel in the current total cycle, and automatically allocate the connection duration of the second device in the next total cycle according to the difference between the total cycle and the connection duration of the first device. This enables intelligent time-division multiplexing of the UART interface among multiple devices, thereby flexibly adjusting resource allocation according to the actual load. It not only ensures the communication bandwidth requirements of high-priority devices, but also avoids resource idleness of low-load devices, effectively improving the communication efficiency and system robustness of multiple devices under a single UART interface. Attached Figure Description
[0009] The technical solution and other beneficial effects of this application will become apparent from the following detailed description of specific embodiments in conjunction with the accompanying drawings.
[0010] Figure 1 This is a flowchart illustrating the communication processing method provided in an embodiment of this application.
[0011] Figure 2 This is a schematic diagram of the communication processing system provided in an embodiment of this application.
[0012] Figure 3 A schematic block diagram of an electronic device provided in an embodiment of this application.
[0013] Figure 4 This is a schematic diagram illustrating the multiplexing of the UART interface provided in an embodiment of this application.
[0014] Figure 5 This is a first schematic diagram of mode switching provided in an embodiment of this application.
[0015] Figure 6 This is a second schematic diagram of mode switching provided in an embodiment of this application.
[0016] Figure 7This is a schematic diagram of the buffer management logic provided in the embodiments of this application.
[0017] Figure 8 This is a schematic diagram illustrating the dynamic switching process of time slices provided in an embodiment of this application. Detailed Implementation
[0018] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0019] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Features thus defined as "first" or "second" may explicitly or implicitly include one or more of the stated features. In the description of this application, "multiple" means two or more unless otherwise explicitly specified.
[0020] In multi-device communication scenarios, traditional single UART interfaces use a fixed time-slice allocation mechanism, which cannot dynamically adjust the communication duration of each device according to the actual load. This results in high-priority devices (such as WiFi modules) experiencing communication delays or packet loss due to insufficient bandwidth when the load suddenly increases, while low-load devices (such as motor debugging interfaces) are left idle due to the fixed time-slice allocation.
[0021] Meanwhile, the lack of an intelligent online device detection mechanism makes it easy for invalid connections to occupy the communication window, and there is a risk of signal crosstalk when multiple devices share the UART. The hardware resource utilization is low and the system robustness is insufficient, making it difficult to meet the dual requirements of real-time performance and reliability for pin-limited embedded devices (such as air conditioner inverter indoor units).
[0022] This application proposes a dynamic adaptive UART time-division multiplexing communication scheme. By monitoring the channel utilization rate of the first channel in real time, and combining the exponentially weighted moving average (EWMA) prediction model with a dynamic smoothing coefficient adjustment mechanism based on the utilization rate change rate, the scheme intelligently calculates the connection duration of high-priority devices in the next cycle and automatically allocates the remaining duration to low-priority devices.
[0023] It integrates hardware analog switches for physical isolation of multi-device signals, a protocol identification mechanism for handshake instruction timeout judgment, dual-buffered data management combining DMA and CPU polling, and an exception handling strategy for automatic reset and boundary protection for overload errors. While ensuring real-time communication of high-priority devices, it maximizes the utilization of UART interface resources and achieves efficient and reliable compatibility of a single interface with heterogeneous devices, especially suitable for resource-constrained embedded scenarios.
[0024] like Figure 1 As shown, this embodiment provides a communication processing method, which includes the following steps: Step S10: Determine the first connection duration in the next total cycle based on the channel utilization rate of the current total cycle. Here, the total cycle is a fixed duration, the first connection duration is the duration of the UART interface connecting to the first device at the first baud rate, and the channel utilization rate is the utilization rate of the first channel formed by the UART interface connecting to the first device at the first baud rate in the current total cycle.
[0025] Step S20: Determine the second connection duration in the next total cycle based on the duration difference between the total cycle and the first connection duration. The second connection duration is the duration for which the UART interface connects to the second device at the second baud rate.
[0026] Step S30: Based on the first connection duration and the second connection duration, switch the connection between the UART interface and the first or second device in the next total cycle.
[0027] It is understood that the communication processing method provided in this embodiment dynamically determines the connection duration of the first device in the next total cycle based on the channel utilization rate of the first channel in the current total cycle, and automatically allocates the connection duration of the second device in the next total cycle according to the difference between the total cycle and the connection duration of the first device. This enables intelligent time-division multiplexing of the UART interface among multiple devices, thereby flexibly adjusting resource allocation according to the actual load. This ensures the communication bandwidth requirements of high-priority devices while avoiding resource idleness of low-load devices, effectively improving the communication efficiency and system robustness of multiple devices under a single UART interface.
[0028] It should be noted that the fixed duration of the total period can be any one of 50ms to 200ms, such as 80ms, 100ms, 120ms, 150ms or 180ms.
[0029] In some embodiments, determining the first connection duration in the next total cycle based on the channel utilization of the current total cycle includes: calculating the channel utilization of the current total cycle; determining a smoothing coefficient based on the channel utilization of the current total cycle; and determining the first connection duration in the next total cycle based on the smoothing coefficient, a first difference, and the channel utilization.
[0030] It should be noted that the embodiment calculates the channel utilization rate of the first channel in the current total cycle in real time, dynamically determines the smoothing coefficient accordingly, and then predicts the first connection duration of the next cycle based on the smoothing coefficient, the first difference, and the channel utilization rate, thereby achieving adaptive adjustment of the communication bandwidth of high-priority devices.
[0031] This prediction mechanism based on exponentially weighted moving average (EWMA) not only uses a smoothing coefficient to give the system a memory inertia of historical load to maintain the stability of time slice allocation, but also ensures the system's agile response to burst traffic through real-time feedback of channel utilization. It effectively avoids the problems of insufficient bandwidth under high load and idle resources under low load in traditional fixed allocation strategies, thereby significantly improving the overall resource utilization of the UART interface while ensuring real-time communication.
[0032] In some embodiments, calculating the channel utilization rate for the current total period includes: obtaining the traffic volume of the first channel in the current total period; and determining the channel utilization rate based on the traffic volume, the first baud rate, and the first connection duration of the current total period.
[0033] It should be noted that this embodiment obtains the actual communication volume of the first channel and accurately calculates the channel utilization rate by combining the first baud rate and the current first connection duration, thereby realizing a quantitative characterization of the actual load of high-priority devices.
[0034] This calculation method based on actual throughput can accurately reflect the current busy level of the communication link, avoiding the deviation of subjective settings or simple counting. It provides a reliable objective basis for the dynamic adjustment of the smoothing coefficient, thereby ensuring that the system can accurately allocate bandwidth according to the actual data traffic. This not only prevents the squeezing of low-priority device resources caused by over-allocation, but also avoids network congestion caused by insufficient allocation, significantly improving the resource utilization efficiency and system stability of a single UART interface when multiple devices work together.
[0035] In some embodiments, determining the smoothing coefficient based on the channel utilization of the current total period includes: obtaining the change in utilization based on the difference between the channel utilization of the current total period and the channel utilization of the previous total period; and determining the smoothing coefficient based on the change in utilization, the base offset, the scaling factor, and the nonlinear mapping function.
[0036] It should be noted that this embodiment introduces the difference between the current and previous cycle channel utilization rates as a variable, and combines the base offset, scaling factor and nonlinear mapping function to jointly determine the smoothing coefficient, thereby achieving an adaptive response to the system load fluctuation characteristics.
[0037] This mechanism allows the smoothing coefficient to be dynamically adjusted based on the severity of traffic changes (ΔU). When traffic is stable, a larger base offset provides system inertia, preventing overreaction and ensuring the stability of time slice allocation. When traffic changes abruptly, a nonlinear mapping function (such as Sigmoid) combined with a scaling factor can quickly fine-tune the smoothing coefficient, enhancing the system's sensitivity to sudden situations. This achieves the best balance between inertial stability and agile response, effectively preventing oscillations or lags in bandwidth allocation and significantly improving the system's robustness in multi-device communication environments.
[0038] In some embodiments, determining the first connection duration in the subsequent total cycle based on a smoothing coefficient, a first difference, and channel utilization includes: calculating a first product between the smoothing coefficient and the first connection duration in the previous total cycle; calculating a second product between the first difference, channel utilization, and the total cycle, where the first difference is the difference between 1 and the smoothing coefficient; and determining the first connection duration in the subsequent total cycle based on the sum of the first product and the second product.
[0039] It should be noted that this embodiment determines the first connection duration of the next cycle by integrating historical experience and real-time load. It uses a smoothing coefficient to perform a weighted summation of the connection duration of the previous cycle (historical inertia) and the product of the current channel utilization and the total cycle (real-time demand), thereby achieving a smooth transition and accurate prediction of bandwidth allocation.
[0040] This Exponentially Weighted Moving Average (EWMA) mechanism effectively avoids drastic fluctuations in duration caused by instantaneous traffic fluctuations, ensuring the stability of system operation. At the same time, it can keep up with the actual load change trend, maximizing the resource utilization of the UART interface while ensuring the communication bandwidth requirements of high-priority devices. It is particularly suitable for embedded multi-device communication scenarios with stringent requirements for real-time performance and reliability.
[0041] In some embodiments, the method for determining the smoothing coefficient further includes: when the channel utilization rate of the current total cycle is greater than the first preset utilization rate, and the difference between the channel utilization rate of the current total cycle and the channel utilization rate of the previous total cycle is greater than the second preset utilization rate, the smoothing coefficient is determined to be a preset coefficient.
[0042] It should be noted that this embodiment sets a dual threshold triggering mechanism. When the current channel utilization rate exceeds the first preset utilization rate and the change in utilization rate exceeds the second preset utilization rate, the smoothing coefficient is forcibly locked to the preset coefficient, thereby realizing a rapid emergency response to sudden high load scenarios.
[0043] This mechanism can quickly reduce the smoothing coefficient when network traffic surges, break the original inertial allocation mode, prioritize the bandwidth needs of high-priority devices, and avoid bandwidth allocation lag caused by over-reliance on historical data. This effectively prevents communication congestion and data loss, significantly improves the stability and reliability of the system under extreme conditions, and is particularly suitable for embedded device communication scenarios with stringent real-time requirements.
[0044] In some embodiments, after determining the first connection duration in the next total cycle based on the channel utilization of the current total cycle, the method further includes: when the first connection duration in the next total cycle is less than a first preset duration, setting the first connection duration in the next total cycle equal to the first preset duration. After determining the second connection duration in the next total cycle based on the duration difference between the total cycle and the first connection duration, when the first connection duration in the next total cycle is greater than the second preset duration, setting the first connection duration in the next total cycle equal to the second preset duration. Wherein, the first preset duration is less than the second preset duration, and the second preset duration is less than the total cycle.
[0045] It should be noted that this embodiment sets upper and lower limits (first preset duration and second preset duration) for the first connection duration to impose hard constraints on the dynamic calculation results, effectively preventing the risk of high-priority devices monopolizing communication resources or low-priority devices being completely starved under extreme load conditions.
[0046] This boundary protection mechanism ensures that the system always operates within a preset safety window, regardless of how drastically the channel utilization fluctuates. This avoids WiFi communication interruptions due to excessively short time slices and prevents motors from malfunctioning due to compressed time slices. Thus, it achieves the best balance between dynamic flexibility and system stability, making it particularly suitable for embedded control scenarios with limited resources and stringent reliability requirements.
[0047] In some embodiments, the communication processing method further includes: detecting an overload error flag on the UART bus. When the overload error flag indicates a data overflow or verification failure, the UART bus is automatically reset and the abnormal data is discarded.
[0048] It should be noted that this embodiment constructs a hardware-level security protection mechanism for the underlying communication by monitoring the UART bus overload error (ORE) flag bit in real time and automatically resetting the bus and discarding abnormal data when data overflow or verification failure is detected.
[0049] This proactive anomaly handling effectively blocks the propagation and accumulation of erroneous data caused by electromagnetic interference, timing errors, or sudden traffic surges in the system, preventing system deadlocks or crashes caused by error accumulation. It ensures the self-repair capability and continuous availability of the communication link in high-noise industrial environments (such as air conditioning inverter control), significantly improving the robustness and anti-interference capability of the entire time-division multiplexing system.
[0050] like Figure 2 As shown, this embodiment also provides a communication processing system, which includes a first duration determination module 10, a second duration determination module 20, and a switching module 30. The first duration determination module 10 is used to determine the first connection duration in the next total cycle based on the channel utilization rate of the current total cycle. The total cycle is a fixed duration, the first connection duration is the duration of the UART44 interface connected to the first device 45 at a first baud rate, and the channel utilization rate is the utilization rate of the first channel formed by the UART44 interface connected to the first device 45 at the first baud rate in the current total cycle. The second duration determination module 20 is used to determine the second connection duration in the next total cycle based on the duration difference between the total cycle and the first connection duration. The second connection duration is the duration of the UART44 interface connected to the second device 46 at a second baud rate. The switching module 30 is used to switch the connection between the UART44 interface and the first device 45 or the second device 46 in the next total cycle based on the first connection duration and the second connection duration.
[0051] It is understood that the communication processing system provided in this embodiment can also dynamically determine the connection duration of the first device 45 in the next total cycle based on the channel utilization rate of the first channel in the current total cycle, and automatically allocate the connection duration of the second device 46 in the next total cycle according to the difference between the total cycle and the connection duration of the first device 45. This can realize intelligent time-division multiplexing of the UART44 interface among multiple devices, thereby flexibly adjusting resource allocation according to the actual load. This ensures the communication bandwidth requirements of high-priority devices and avoids resource idleness of low-load devices, effectively improving the communication efficiency and system robustness of multiple devices under a single UART44 interface.
[0052] like Figure 3As shown, this embodiment also provides an electronic device, which includes a timer 41, a control unit 42, a UART 44 interface, a first device 45, a second device 46, and a switching switch 47. The timer 41 is used to divide the total cycle and trigger an interrupt signal in each total cycle. The control unit 42 is used to respond to the interrupt signal and calculate a first connection duration and a second connection duration in the next total cycle. The switching switch 47, controlled by the control unit 42, is used to switch the connection between the UART 44 interface and the first device 45 or the second device 46 within the total cycle according to the first connection duration and the second connection duration. The UART 44 interface is configured to communicate with the first device 45 at a first baud rate during the first connection duration and with the second device 46 at a second baud rate during the second connection duration, wherein the first baud rate is higher than the second baud rate.
[0053] It is understood that, since the electronic device provided in this embodiment executes the above-described communication processing method, it can also dynamically determine the connection duration of the first device 45 in the next total cycle based on the channel utilization rate of the first channel in the current total cycle, and automatically allocate the connection duration of the second device 46 in the next total cycle according to the difference between the total cycle and the connection duration of the first device 45. This enables intelligent time-division multiplexing of the UART44 interface among multiple devices, thereby flexibly adjusting resource allocation according to the actual load. This ensures the communication bandwidth requirements of high-priority devices while avoiding resource idleness of low-load devices, effectively improving the communication efficiency and system robustness of multiple devices under a single UART44 interface.
[0054] In other embodiments, such as Figure 3 As shown, the electronic device also includes a storage medium 43 connected to the control unit 42. The storage medium 43 may be used, but is not limited to, for storing the communication processing method described above.
[0055] It should be noted that the electronic device can be, but is not limited to, an air conditioner, and can also broadly cover various resource-constrained embedded terminals, including but not limited to smart door locks, environmental monitoring nodes and voice interaction panels in the smart home field; programmable logic controller (PLC) expansion modules, distributed sensor acquisition devices and motor servo drives in the industrial control field; portable monitors, infusion pumps and blood glucose meters in the medical and health field; and smart wearable devices, drone flight control systems and electronic price tags in the consumer electronics field. These devices all face the common pain points of limited pin count of the main control chip and the need to connect WiFi / Bluetooth communication modules and debugging / sensing peripherals simultaneously. By applying the time-division multiplexing and dynamic bandwidth adjustment technology of this application, the real-time performance of high-priority communication links and stable monitoring of low-power peripherals can be ensured without increasing hardware costs, significantly improving system integration and operational reliability.
[0056] In some embodiments, such as Figure 3As shown, the electronic device also includes a first resistor R1 and a first capacitor C1. The first end of the first resistor R1 is connected to the UART44 interface, and the second end of the first resistor R1 is connected to the toggle switch 47. The first end of the first capacitor C1 is connected to the second end of the first resistor R1 and the toggle switch 47, and the second end of the first capacitor C1 is connected to the ground terminal.
[0057] It should be noted that in this embodiment, an RC filter circuit is formed by connecting a first resistor R1 in series and a first capacitor C1 in parallel between the UART44 interface and the switching switch 47, which effectively suppresses high-frequency electromagnetic interference and signal reflection, and significantly improves the signal integrity of the communication link.
[0058] This hardware-level filtering design not only absorbs voltage spikes and ringing effects generated when the switching switch 47 operates, preventing electrostatic discharge or surge impacts from damaging the UART44 transceiver of the main control chip, but also filters out common-mode noise in environments with strong electromagnetic interference (such as when the air conditioner inverter compressor is working), ensuring stable transmission of handshake commands and data frames, thereby significantly reducing the bit error rate and enhancing the long-term operational reliability of the system in high-noise industrial environments.
[0059] In some embodiments, such as Figure 3 As shown, storage medium 43 also stores a double-buffering management program. When the double-buffering management program is executed by control unit 42, the processing priority of Wi-Fi data received by the Wi-Fi module is higher than the processing priority of motor data received by the motor debugging interface. Wi-Fi data is written to the circular buffer via direct memory access, while motor data is read by the central processing unit through polling.
[0060] It should be noted that this embodiment achieves optimized system resource allocation and real-time response to critical tasks by defining high-priority attributes for WiFi data and implementing differentiated buffer management strategies. Direct Memory Access (DMA) is used to directly write high-priority WiFi data into a circular buffer, completely freeing up the CPU's computing power to focus on core control logic. This avoids system blockage caused by frequent CPU interruptions processing large data streams. Simultaneously, the CPU polling method is used to process low-priority motor data. While ensuring the normal operation of motor monitoring functions, this maximizes the utilization of limited hardware resources, effectively solving the data conflict and processing bottleneck problems of a single UART44 interface in multi-device concurrent communication scenarios, and significantly improving the real-time performance and operating efficiency of the embedded system.
[0061] In some embodiments, such as Figure 3 and Figure 4As shown, switch 47 is an analog switch. Its first terminal is connected to the UART44 interface, its second terminal is connected to the first device 45, its third terminal is connected to the second device 46, and its control terminal is connected to the control unit 42. The first device 45 is a Wi-Fi module, and the second device 46 is a motor debugging interface.
[0062] It should be noted that this embodiment uses an analog switch as a physical switching hub. The control unit 42 precisely selects the WiFi module or the motor debugging interface, thereby achieving physical layer isolation and dynamic adaptation of a single UART44 interface to heterogeneous devices.
[0063] This hardware-level switching mechanism not only completely eliminates signal crosstalk and electrical conflicts when multiple devices share the bus, ensuring the independence and stability of high-speed WiFi communication (high baud rate) and low-speed motor debugging (low baud rate), but also effectively suppresses damage to the main control chip from electrostatic discharge and surge impact by physically disconnecting the connection of unselected devices. It significantly improves the system's anti-interference capability and long-term operational reliability in complex electromagnetic environments, perfectly adapting to embedded application scenarios with limited pin resources.
[0064] The analog switch model can be, but is not limited to, 74HC4052. With its low on-resistance (<100Ω) and wide voltage operating range (2V to 10V), it can be adapted to the 3.3V or 5V main control logic level commonly found in air conditioner inverter indoor units. At the same time, its bandwidth of up to 500MHz and nanosecond-level (ns) switching speed ensure that the signal waveform is not distorted at the moment of switching, and can perfectly carry high baud rate (such as 115200bps) WiFi data streams. Thus, while achieving physical layer electrical isolation, it ensures the signal integrity of high-speed communication and the long-term operational reliability of the system.
[0065] In some embodiments, the control unit is further configured to perform the following within the second connection duration: send a handshake command to the second device; start a timeout timer; and if a matching response is received from the second device within a preset timeout window, lock the second connection duration and maintain communication; if no matching response is received, determine that the second device is offline and forcibly switch the UART interface to the first device.
[0066] It should be noted that this embodiment achieves dynamic verification and intelligent management of the online status of the second device by executing handshake instructions and timeout determination mechanisms within the second connection duration.
[0067] This proactive detection mechanism can effectively identify the actual connection status of low-priority devices such as motor debugging interfaces, avoiding invalid communication window occupation caused by device offline or poor contact, thereby dynamically recovering valuable UART bandwidth resources and allocating them in full to high-priority WiFi modules.
[0068] Meanwhile, through the hard constraint of the preset timeout window, the system can quickly respond to device disconnection events within milliseconds and force a switch of communication links, preventing system blockage or deadlock caused by waiting for unresponsive devices, and significantly improving the fault tolerance capability and overall communication efficiency of the multi-device time-sharing multiplexing system.
[0069] This solution employs time-division multiplexing and double-buffering mechanisms to achieve multi-functional sharing of a single UART interface. Its specific hardware connection and data interaction architecture is as follows: Figure 4 As shown: The UART transmitter (MCU_UART1_TX) of the microcontroller (MCU) is connected to the input of the 74HC4052 analog switch via a UART transmission signal. The analog switch achieves dynamic channel switching under the action of the control signal.
[0070] In terms of specific channel configuration, Channel A is defined as a high-speed channel, connected to the WiFi module, with a communication baud rate set to 115200bps. The WiFi module receives data and then performs further wireless transmission. Channel B is defined as a low-speed channel, connected to the motor debugging interface, with a communication baud rate set to 9600bps. The motor debugging interface receives data and uses it for motor control.
[0071] At the control logic level, the control unit is connected to the S0 / S1 pins of the 74HC4052 via GPIO, and the channel selection is determined by the change of logic level.
[0072] During operation, the UART interface automatically switches its working mode according to a preset timing sequence: when Channel A is selected, it enters WiFi communication mode, where high-priority WiFi data is directly written to the circular buffer via DMA, achieving high-speed transmission without CPU intervention and ensuring real-time performance. When Channel B is selected, it enters motor debugging mode, where low-priority motor data is read by the CPU in a polling manner and a timeout clearing mechanism is set.
[0073] The dual-buffer management system, in conjunction with a priority arbiter, ensures that WiFi data is processed in real time, while motor data is processed with a delayed response. Abnormal data is automatically discarded through CRC checksum and timeout mechanism to avoid system congestion.
[0074] This system uses hardware timer interrupts to drive UART time-division multiplexing, enabling dynamic switching of a single hardware serial port at different baud rates (115200bps WiFi mode / 9600bps motor mode). Its core principle is based on time-slice polling and automatic protocol identification. The specific software logic timing control flow is as follows: Figure 5 As shown: The process begins with the system initialization phase, first executing the "Initialize Timer: 100ms Period" operation to set the system-level time base. The system then enters a loop waiting state until a "timer interrupt is triggered." Once the interrupt condition is met, the system immediately executes the "Switch Mode" operation, changing the current communication operating state.
[0075] Next, the system determines the subsequent execution path based on the "current mode" of the node: If determined to be "Mode 1" (High-speed WiFi mode): The system executes "Configure UART: 115200bps WiFi mode", completes dynamic reconfiguration of the baud rate (switching time is approximately 12μs), and then enters the "Execute WiFi Communication" stage to handle network data transmission tasks such as MQTT protocol. After completion, the process returns to the interrupt detection point.
[0076] If the system is determined to be in "Mode 2" (low-speed motor debugging mode): the system first executes "send motor handshake command AA55". Then it enters the crucial response detection stage: "Received a valid response?". If no response is received (No): The system determines that the motor interface is offline or there is a conflict, executes "switch back to WiFi mode" to ensure the availability of high-priority communication links, and then the process returns to the interruption detection point.
[0077] If a valid response is received (Yes): The system executes "Lock Motor Debugging Mode," maintaining the current low-speed communication state to perform "Motor Monitoring." During this period, the system continuously monitors the USART's ORE (Overload Error) flag. Once an abnormal data conflict is detected, the conflict protection mechanism is immediately triggered to reset the bus, and the system exits this mode at an appropriate time, automatically reverting to WiFi mode to ensure overall system stability.
[0078] Figure 6 The timing diagram shows in detail the fully automatic handshake and fallback mechanism for time-division multiplexing of a single UART interface driven by a hardware timer interrupt (100ms period). The system achieves seamless switching and secure isolation between high-speed and low-speed devices through state machine logic. The entire cycle is divided into a 100ms WiFi-dominated window and a 20ms motor detection window. The specific interaction flow is as follows: `alt` is a standard combination segment marker in timing diagrams, representing an alternative branch structure used to define two mutually exclusive execution paths: When the MCU sends a handshake command, if it detects that the motor device returns a matching response (0x55 0xAA) within a preset timeout window (20ms), it executes the "handshake successful" branch (locking the motor debug mode). If no response is received, it executes the "handshake failed" branch (forcibly reverting to WiFi mode).
[0079] This structure clearly presents the system's dynamic verification process of the online status of motor equipment through visualized condition judgment logic, ensuring that the availability of the communication link can still be maintained in abnormal scenarios (such as equipment offline or poor contact).
[0080] The "Set Mode Flag" is a status variable used internally by the MCU to record the current UART operating mode. When the MCU successfully receives a matching response from the motor device within a 20ms timeout window, it sets this flag to 1 (locking the motor debugging mode). At this time, the system pauses cycle switching and continuously maintains a baud rate of 9600bps for motor monitoring. If no response is received, the flag is cleared (default WiFi mode), triggering a forced switchback to 115200bps.
[0081] This flag serves as the core anchor point for system status, enabling the coordinated control of hardware switching (analog switch) and software logic (baud rate configuration, data processing priority) to ensure the accuracy and stability of mode switching during time-sharing multiplexing of multiple devices.
[0082] During the [WiFi-Motor Mode Switching] phase, the Timer triggers a timed interrupt every 100ms. Upon response, the Control Unit (MCU) immediately switches the UART interface from high-speed WiFi mode to low-speed motor debugging mode by reconfiguring the baud rate (9600) to ensure no electrical signal conflicts.
[0083] Entering the handshake phase: The MCU sends a fixed handshake command AA 55 to the Motor via UART; if the physical link is connected, the Motor will return a response code 55 AA in a very short time. After the MCU receives the interrupt, it immediately sets the mode flag, and the system is locked into the motor debugging state.
[0084] The [Timeout Handling] branch provides crucial exception safety protection: if the MCU does not receive any response from the Motor within 20ms after sending the command (i.e., the no response (20ms) condition is met), the system will determine that the motor interface is offline or in a occupied state, force a switchback operation of 115200bps, and reset the UART to high-bandwidth WiFi communication mode.
[0085] This closed-loop logic of "active detection + failure fallback", combined with precise dynamic baud rate reconfiguration, ensures real-time communication while effectively avoiding the waste of system bandwidth and potential communication deadlock risks caused by invalid debugging windows.
[0086] Figure 7This demonstrates a hardware-software collaborative data flow and processing logic architecture shared by multiple devices using a single UART interface. This architecture extends from the hardware abstraction layer to the application service layer from top to bottom. The core entry point of the system is the top-level "UART interface (time-division multiplexed WiFi / motor)". The data stream collected by this physical interface first enters the "MCU kernel DMA controller" for low-level hardware scheduling. Subsequently, the data flows into the "double-buffered management logic" located in RAM for distribution and storage. For high-priority WiFi services, the system adopts a "[High Priority] WiFi Data Buffer\n-Circular Queue\n-DMA Automatic Write" mechanism to achieve zero-copy high-speed caching of data and ensure the real-time performance of network data.
[0087] For low-priority motor control operations, a "[low-priority] motor parameter buffer\nMn-timeout clear" mechanism is adopted, which is handled by the CPU and automatically clears the old data when no new data is written to prevent resource blockage.
[0088] The dual-buffer management logic ultimately aggregates the data to the "priority arbitrator," which serves as the system's scheduling hub. It distributes and processes the data according to a preset priority strategy: high-priority paths forward the data losslessly to the "wifi application layer" to ensure real-time response, while low-priority paths are directed to the "motor debugging interface" for delayed processing.
[0089] The entire architecture, without requiring any changes to the underlying hardware, achieves efficient management of heterogeneous communication and automatic isolation of abnormal data within the MCU through the division of labor and cooperation between DMA and CPU, as well as a hierarchical caching mechanism. This perfectly meets the high reliability requirements of resource-constrained embedded systems for multi-protocol communication.
[0090] Figure 8 This paper systematically demonstrates the complete workflow of the adaptive time-slice dynamic scheduling algorithm based on exponentially weighted moving average (EWMA) in this scheme. The closed-loop control system realizes time-division multiplexing of high and low speed devices with a single UART interface with a complete cycle of 100ms (T_cycle=100ms). After the algorithm starts, it first executes "system initialization" and "parameter preset" (setting the initial smoothing coefficient α=0.9, WiFi minimum bandwidth time slice TWiFi_min=50ms, WiFi maximum time slice TWiFi_max=90ms), and then "starts the timer" to enter the cyclic scheduling.
[0091] Whenever a "timer interrupt" is triggered, the system executes three core operations in the interrupt service routine: The first step is "data acquisition," which involves reading the UART receive counter (UART_RX_CNT) to obtain the actual number of bytes communicated via WiFi and reading the number of bytes of motor parameters via ADC.
[0092] Secondly, based on the collected data, the utilization rate is calculated to obtain the WiFi channel utilization rate (U_wifi) and the motor channel utilization rate (U_motor).
[0093] Third, the system performs real-time assessments for "burst traffic?". If burst traffic is detected, the system immediately activates "emergency mode" and executes three mandatory measures: resetting the smoothing coefficient to α=0.7, enabling DMA double buffering to improve throughput efficiency, and forcibly locking the minimum WiFi bandwidth. It then skips regular prediction and directly proceeds to boundary checks. If there is no burst traffic, the system enters the "dynamic parameter adjustment" phase, adjusting parameters based on changes in utilization (ΔU=U_current). U_prev), the smoothing coefficient α = 0.8 + 0.1 is dynamically calculated using the Sigmoid function. sigmoid(ΔU) is used to adaptively balance response speed and smoothness.
[0094] Next, the system uses the EWMA prediction model to perform "time slice prediction", calculating the WiFi time slice T_wifi for the next cycle = α × T_prev + (1 α)×U_wifi×T_cycle, and motor time slice T_motor=T_cycle T_wifi.
[0095] The system then enters the "boundary check" stage to ensure system stability: if the predicted T_wifi < 50ms, it is forcibly corrected to T_wifi = 50ms (T_motor = 50ms); if 50ms ≤ T_wifi ≤ 90ms, the predicted value is maintained; if T_wifi > 90ms, it is forcibly limited to T_wifi = 90ms (T_motor = 10ms).
[0096] Then, a "hardware reconfiguration" process is executed to issue new time slice parameters.
[0097] Finally, through the "state saving" step, the actual connection duration T_WiFi and channel utilization U_WiFi calculated in the current cycle are updated and assigned to the historical variables T_prev and U_prev respectively, providing the necessary historical benchmark data for the next round of EWMA prediction algorithm, thereby constructing a closed-loop control logic with "memory" function.
[0098] The system then "returns to interrupt waiting state", actively suspends the current process and releases CPU control until the next 100ms hardware timer interrupt is triggered again.
[0099] This interrupt-driven round-robin mechanism not only ensures microsecond-level precision in time slice switching but also minimizes power consumption when the system is idle. Combined with lightweight state storage (total RAM usage <2KB), it enables long-term, stable, and adaptive intelligent scheduling of multi-device communication bandwidth in resource-constrained embedded environments.
[0100] T_cycle represents the complete time cycle of the system, set to 100ms. It forms the basic time axis for time-division multiplexing of a single UART interface. The entire communication scheduling is based on this cycle, and by alternately allocating time slices within a single cycle, hardware resource sharing between the WiFi module and the motor control interface is achieved.
[0101] α is the dynamic smoothing coefficient of the EWMA (Exponential Weighted Moving Average) algorithm, with an initial preset value of 0.9. It determines the algorithm's dependence on historical data and its sensitivity to changes in new data; during operation, this value is dynamically adjusted between 0.7 and 0.9 according to the rate of change (ΔU) of communication utilization, in order to achieve a balance between predictive smoothness and response speed.
[0102] WiFi_min is the lower limit threshold for the WiFi communication backup time slice, set to 50ms. During the boundary check phase, if the algorithm predicts that the WiFi time slice for the current period is less than this value, the system will forcibly correct it to this minimum value. This is intended to prevent the motor control from causing the WiFi link to drop or severely deteriorate the communication quality due to excessive bandwidth consumption.
[0103] WiFi_max is the upper limit threshold for WiFi communication time slices, set to 90ms. It also plays a role in the boundary check process. If the predicted time slice exceeds this value, the system will forcibly limit the WiFi occupancy time to 90ms, thereby ensuring that at least 10ms of hard time window is left for the motor control task, meeting the basic requirements of real-time detection of the underlying hardware.
[0104] T_prev is a variable recording the actual WiFi usage time of the previous historical period. At the end of each interruption process, it is updated to the actual value of the current period (T_prev=T_wifi) and used as the historical benchmark term in the EWMA prediction formula for the next period, enabling the algorithm to make smooth predictions.
[0105] U_prev is a variable recording the channel utilization rate of the previous historical period. It is updated to the current WiFi utilization rate (U_prev=U_wifi) during the state saving process. It is mainly used to calculate the difference in utilization rate (ΔU) between the current period and the previous period, thereby triggering the dynamic adaptive adjustment of the smoothing coefficient α.
[0106] `wifi_bytes` represents the actual number of WiFi data bytes received by the UART interface during the current interrupt cycle. The system obtains this value by reading the underlying hardware registers; it is the core raw input data for calculating the actual load utilization of the current WiFi channel.
[0107] `motor_bytes` represents the number of bytes of motor control parameters collected during the current interrupt cycle. The system reads this value through an ADC or other data interface to quantify the data flow intensity on the motor side, and then calculates the current utilization rate of the motor channel as an auxiliary consideration for scheduling decisions.
[0108] U_wifi represents the WiFi channel utilization rate for the current period. It is calculated as the ratio of the actual number of bytes received to the theoretical maximum throughput, directly reflecting the current level of WiFi traffic on the UART bus and serving as the direct basis for determining the time slice allocation ratio for the next period.
[0109] U_motor represents the motor channel utilization rate for the current cycle. Its calculation method is similar to U_wifi, reflecting the transmission load of motor control data. Although this parameter is calculated in the graph, it is not directly involved in core prediction; it is mainly used to assist the system in assessing the overall bus load and diagnosing potential abnormal states.
[0110] ΔU is the change in utilization rate, which is equal to the difference between the current period's utilization rate and the previous period's utilization rate (ΔU = U_current). U_prev). It is the key factor driving the dynamic fine-tuning of the smoothing coefficient α. When the load fluctuates drastically, the change of this parameter will trigger a decrease in the value of α, thereby enabling the algorithm to respond quickly to changes.
[0111] T_wifi is the time slice length allocated to WiFi communication in the next cycle, predicted and calculated using the EWMA algorithm. This value is generated during the prediction phase, then undergoes boundary checks to ensure it falls within the safe range of [50ms, 90ms], and finally takes effect via a hardware reconfiguration command.
[0112] T_motor is the calculated time slice length allocated to motor control for the next cycle. It is always equal to the full cycle minus the WiFi time slice (T_motor = T_cycle). T_wifi plays a passive adjustment role in time slice allocation. The higher the proportion of WiFi, the lower its proportion. It also reaches its minimum value of 10ms when WiFi takes the maximum value.
[0113] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0114] This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only for the purpose of helping to understand the technical solutions and core ideas of this application. Those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. These modifications or substitutions will not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A communication processing method, characterized in that, The communication processing method includes: The first connection duration in the next total cycle is determined based on the channel utilization rate of the current total cycle. The total cycle is a fixed duration. The first connection duration is the duration of the UART interface connected to the first device at a first baud rate. The channel utilization rate is the utilization rate of the first channel formed by the UART interface connected to the first device at the first baud rate in the current total cycle. Based on the duration difference between the total cycle and the first connection duration, the second connection duration in the subsequent total cycle is determined, whereby the second connection duration is the duration during which the UART interface connects to the second device at the second baud rate. Based on the first connection duration and the second connection duration in the subsequent total cycle, the connection between the UART interface and the first device or the second device is switched.
2. The communication processing method according to claim 1, characterized in that, The determination of the first connection duration in the next total cycle based on the channel utilization rate of the current total cycle includes: Obtain the communication volume of the first channel in the current total cycle; The channel utilization rate is determined based on the communication volume, the first baud rate, and the first connection duration of the current total cycle. The change in utilization rate is obtained based on the difference between the channel utilization rate of the current total cycle and the channel utilization rate of the previous total cycle. Based on the utilization rate change, the base offset, the scaling factor, and the nonlinear mapping function, the smoothing coefficient is determined. The first connection duration in the subsequent total cycle is determined based on the smoothing coefficient, the first difference, and the channel utilization rate, wherein the first difference is the difference between 1 and the smoothing coefficient.
3. The communication processing method according to claim 2, characterized in that, The determination of the first connection duration in the subsequent total cycle based on the smoothing coefficient, the first difference, and the channel utilization includes: Calculate the first product between the smoothing coefficient and the first connection duration in the previous total period; Calculate the second product between the first difference, the channel utilization rate, and the total cycle; The sum of the first product and the second product is set as the first connection duration in the subsequent total cycle.
4. The communication processing method according to claim 2, characterized in that, The method for determining the smoothing coefficient also includes: When the channel utilization rate of the current total cycle is greater than the first preset utilization rate, and the difference between the channel utilization rate of the current total cycle and the channel utilization rate of the previous total cycle is greater than the second preset utilization rate, the smoothing coefficient is set to a preset coefficient.
5. The communication processing method according to any one of claims 1-4, characterized in that, After determining the first connection duration in the next total cycle based on the channel utilization rate of the current total cycle, the method further includes: When the first connection duration in the subsequent total cycle is less than the first preset duration, the first connection duration in the subsequent total cycle is set to be equal to the first preset duration. After determining the second connection duration in the subsequent total period based on the duration difference between the total period and the first connection duration, the method further includes: When the first connection duration in the subsequent total cycle is greater than the second preset duration, the first connection duration in the subsequent total cycle is set to be equal to the second preset duration. Wherein, the first preset duration is less than the second preset duration, and the second preset duration is less than the total period.
6. A communication processing system, characterized in that, The communication processing system includes: The first duration determination module is used to determine the first connection duration in the next total period based on the channel utilization rate of the current total period. The total period is a fixed duration. The first connection duration is the duration of the UART interface connected to the first device at a first baud rate. The channel utilization rate is the utilization rate of the first channel formed by the UART interface connected to the first device at the first baud rate in the current total period. The second duration determination module is used to determine the second connection duration in the next total period based on the duration difference between the total period and the first connection duration, wherein the second connection duration is the duration for which the UART interface is connected to the second device at the second baud rate; The switching module is used to switch the connection between the UART interface and the first device or the second device in the next total cycle according to the first connection duration and the second connection duration.
7. An electronic device, characterized in that, The electronic device includes a timer, a control unit, a UART interface, a first device, a second device, and a switch; The timer is used to divide the total period and trigger an interrupt signal in each total period; The control unit is used to respond to the interrupt signal and calculate the first connection duration and the second connection duration in the next total cycle. The switching switch is controlled by the control unit and is used to switch the connection between the UART interface and the first device or the second device within the total cycle according to the first connection duration and the second connection duration. The UART interface is configured to communicate with the first device at a first baud rate during the first connection duration and with the second device at a second baud rate during the second connection duration, wherein the first baud rate is higher than the second baud rate.
8. The electronic device according to claim 7, characterized in that, The switch is an analog switch. The first end of the analog switch is connected to the UART interface, the second end of the analog switch is connected to the first device, the third end of the analog switch is connected to the second device, and the control end of the analog switch is connected to the control unit. The first device is a Wi-Fi module, and the second device is a motor debugging interface.
9. The electronic device according to claim 8, characterized in that, The electronic device further includes a storage medium that stores a double-buffering management program, which is implemented when executed by the control unit: The processing priority of the Wi-Fi data received by the Wi-Fi module is higher than that of the motor data received by the motor debugging interface; the Wi-Fi data is written to the circular buffer through direct memory access, and the motor data is read by the central processing unit in a polling manner.
10. The electronic device according to claim 8, characterized in that, The control unit is also configured to execute during the second connection duration: Send a handshake command to the second device; Start a timeout timer. If a matching response is received from the second device within the preset timeout window, lock the second connection duration and maintain communication. If no matching response is received, the second device is determined to be offline, and the UART interface is forcibly switched to the first device.
