USB-A interface and serial port dynamic switching and protection system based on analog switch

Through analog switches and dynamic priority scheduling algorithms, combined with a multi-dimensional electrical protection mechanism, flexible switching and coordinated protection between the USB-A interface and the serial port are achieved, solving the problem of insufficient switching and protection coordination in existing technologies and improving communication reliability and stability.

CN120803998AActive Publication Date: 2025-10-17BEIJING SATECOMM SCI & TECH CO LTD

Patent Information

Application Number
CN202511318764.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-16
Publication Date
2025-10-17
Estimated Expiration
2045-09-16

AI Technical Summary

Technical Problem

In the existing technology, the dynamic switching between the USB-A interface and the serial port lacks a hierarchical protection mechanism for power overcurrent, overvoltage and signal anti-interference, and the switching and protection are not coordinated enough, resulting in easy damage to the interface and back-end circuits and insufficient communication reliability.

Method used

It adopts a dynamic switching and protection system between USB-A interface and serial port based on analog switch, including main control unit, analog switch unit, hierarchical protection unit, protocol adapter unit and status detection unit. Through dynamic priority scheduling algorithm and multi-dimensional electrical protection mechanism, it realizes flexible switching and coordinated protection between USB-A interface and serial port.

Benefits of technology

It enhances the flexibility and adaptability of interface switching, reduces the risk of hardware damage, improves communication reliability and stability, and ensures the coordination of USB-A interface and serial port communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120803998A_ABST
    Figure CN120803998A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of communication, in particular to a USB-A interface and serial port dynamic switching and protection system based on an analog switch. Comprising a main control unit, the main control unit is used for planning dynamic switching and conflict coordination of a USB-A interface and a serial port as a whole, generating a conflict-free channel switching control instruction by integrating a dynamic priority scheduling algorithm and combining a USB data transmission real-time load, a serial port communication request emergency degree and a device historical interaction record fed back by a state detection unit, and sending the conflict-free channel switching control instruction to the state detection unit; the analog switch unit is driven to complete channel gating; an analog switch unit; a grading protection unit; a protocol adaptation unit; and a state detection unit. Priority scheduling is carried out by means of the main control unit in combination with multi-dimensional parameters such as the transmission load of the USB-A interface and the communication emergency degree of the serial port UART, communication channels of the USB-A interface and the serial port can be flexibly switched, the flexibility and adaptability of interface switching are enhanced, and the problem of switching limitation caused by a single triggering condition is solved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application relates to the technical field of communication, in particular to a USB-A interface and serial port dynamic switching and protection system based on an analog switch. BACKGROUND

[0002] The USB-A interface and the serial port are commonly used communication interfaces in electronic devices. In actual application scenarios, the communication channel needs to be dynamically switched according to the data transmission load of the USB-A interface, the communication request urgency of the serial port and other requirements, so as to avoid interface conflicts. At the same time, the USB-A interface is prone to risks such as power overcurrent, overvoltage and signal high-frequency interference under the conditions of live insertion and complex electromagnetic environment, and needs to be equipped with protection measures to ensure the stability of interface communication and the reliability of backend hardware. This is the core basic problem that needs to be solved in the current application of this type of interface.

[0003] For example, Chinese patent CN202311376986.8 discloses a multifunctional interface and switching system in the form of USB. The system includes a serial port module, a CPLD, a serial-USB conversion circuit, a USB HUB, a USB switch chip, a USB Type A interface and a BMC. Through the combination of software and hardware, the USB Type A interface can realize the functions of CPU serial port, BMC serial port, BMC USB HOST and BMC virtual network, thereby improving the interface utilization rate and operation convenience. For another example, Chinese patent CN201710087535.0 discloses a communication device and a switching method for USB and serial port. The communication device includes a main processor (integrating a USB unit and a UART unit), a USB port and a switching unit connecting the two. The switching unit realizes switching by detecting the level signal of the USB port ID pin. When the level is the first level, the USB port is connected to the USB unit, and when the level is the second level, the USB port is connected to the UART unit. No additional software intervention is required, which reduces the processor workload and improves the switching convenience.

[0004] Although the above technical solutions have corresponding design advantages, they still have the following technical defects: first, the protection mechanism is missing. CN202311376986.8 improves the utilization rate of the USB-TypeA interface, but does not design a hierarchical protection mechanism for power overcurrent, overvoltage and signal anti-interference during the dynamic switching process of the USB-TypeA interface and the serial port. The interface and the backend circuit are prone to damage under complex working conditions. Second, the switching and protection coordination is insufficient. CN201710087535.0 only relies on the single condition of the level of the USB port ID pin for switching, cannot conduct intelligent priority scheduling in combination with multi-dimensional parameters such as USB transmission real-time load and serial port communication urgency, and lacks electrical protection design for the serial port UART, which is insufficient in communication reliability. SUMMARY

[0005] The purpose of the present invention is to provide a USB-A interface and serial port dynamic switching and protection system based on an analog switch to solve the problems raised in the above background technology.

[0006] To solve the above technical problems, the present invention aims to provide a USB-A interface and serial port dynamic switching and protection system based on an analog switch, comprising: The main control unit is used to coordinate the dynamic switching and conflict coordination between the USB-A interface and the serial port, and integrates the dynamic priority scheduling algorithm, combined with the real-time load of USB data transmission and the serial port feedback from the status detection unit. The urgency of the communication request and the historical interaction records of the device are used to generate conflict-free channel switching control instructions and drive the analog switch unit to complete channel selection; The analog switch unit is used to establish a physical channel selection path between the USB-A interface and the serial port, and the USB-A interface or the serial port is switched through an analog switch circuit of a switchable signal path. The signal is transmitted to the public interface and the conduction state is switched according to the control instruction of the main control unit; A hierarchical protection unit, which is used to implement multi-dimensional electrical protection for the USB-A interface. This unit forms a coordinated power and signal protection mechanism by connecting an overcurrent protection device in series with the USB-A interface power path, an overvoltage suppression device in parallel with the power end, and a high-frequency interference filter device across the signal path. The protocol adapter unit is used to achieve dynamic compatibility between USB and serial port protocols. By integrating a switchable protocol parsing circuit, the signal encoding and decoding logic of the corresponding protocol is loaded based on the instructions of the main control unit to complete the signal format conversion; The status detection unit is used to collect the interface connection and operation status, and monitor the USB-A interface plug-in signal, serial port Communication request signal and power supply status signal, and convert the detection results into electrical signals and transmit them to the main control unit; The power management unit is used to provide stable power supply for the main control unit, analog switch unit, hierarchical protection unit, protocol adaptation unit and status detection unit. Through the integrated voltage conversion circuit and voltage stabilization circuit, it connects to the external input power supply and performs multi-level voltage regulation to output a stable voltage that adapts to working requirements.

[0007] As a further improvement of this technical solution, the main control unit includes a parameter quantization module, a priority scheduling module and an instruction output module, wherein: The parameter quantization module is used to collect the USB real-time transmission parameters output by the state detection unit and the serial port Request parameters and convert them into quantifiable values; The priority scheduling module calculates the priority and determines the conflict of the quantified USB and serial port parameters through a dynamic priority scheduling algorithm. The instruction output module generates channel switching control instructions that conform to the hardware interface specifications of the analog switch unit based on the priority scheduling results.

[0008] As a further improvement of the technical solution, the parameter quantification module includes a USB load quantification submodule and a serial port urgency quantification submodule, wherein: The USB load quantification submodule is used to generate USB load quantification values , which are converted from the transmission load proportion based on the USB real-time transmission rate in combination with the protocol nominal rate corresponding to the protocol type (such as USB2.0, USB1.1, etc.) followed by the USB-A interface. The serial port urgency quantification submodule is used to generate serial port urgency quantification values , which are mapped from the serial port emergency level identification bit conforming to the industry standard in the serial port request signal through analysis. The higher the emergency level, the larger the corresponding numerical value.

[0009] As a further improvement of the technical solution, the priority scheduling module calculates the priority and determines the conflict of the quantified USB and serial port parameters through a dynamic priority scheduling algorithm, including the following steps: S120.1, obtain the USB load quantification values and serial port urgency quantification values output by the parameter quantification module, and calculate the initial priority of the USB interface and serial port in combination with the preset USB load weight and serial port urgency weight (initial weights are set through a hardware configuration interface). S120.2, dynamically adjust the weights based on the continuous monitoring results of the state detection unit: If the USB transmission rate meets the high load characteristics defined by its protocol type for N consecutive times, increase and simultaneously decrease , so that the adjusted does not exceed the maximum weight limit of the hardware adaptation. If the serial port sends the highest emergency level request conforming to the industry standard for M consecutive times, increase and simultaneously decrease​​ , after adjustment Do not exceed the maximum weight limit of hardware adaptation; S120.3. Calculating USB and Serial Ports If the priority difference is greater than or equal to the conflict threshold ( Based on the nominal switching time specified in the analog switch unit hardware specification, to ensure stable communication after signal switching), the high-priority channel is directly determined to be the current selected channel; if the priority difference < , then the USB data frame interval obtained by calling the status detection unit is consistent with the serial port Request timeout, give priority to channels that "need to complete the response before the timeout"; S120.4, real-time monitoring of USB load quantification value Serial port emergency quantization value If any quantized value exceeds its physical definition range (such as the USB load quantized value exceeds the maximum transmission capacity of the corresponding protocol), the current weight adjustment logic is frozen and the existing priority calculation method is maintained until the status detection unit feeds back an abnormality release signal.

[0010] As a further improvement of the present technical solution, the analog switch unit includes a control interface module, a channel switching module and a signal transmission module, wherein: The control interface module is used to receive the channel switching control instruction output by the main control unit, and convert the 8-bit channel identifier, 8-bit switching delay parameter, and 8-bit CRC check code contained in the instruction into a control signal that conforms to the logic level of the analog switch circuit; The channel switching module includes at least two independent single-pole double-throw switch circuits, one of which corresponds to the power supply and signal path of the USB-A interface, and the other corresponds to the serial port. The sending and receiving signal paths of the control interface module are used to switch the switch on and off state through the control signal output by the control interface module; The signal transmission module is used to connect the channel switching module and the public interface, and the circuit impedance of the signal transmission module matches the USB-A interface and the serial port. The characteristic impedance requirements are met to ensure signal transmission without reflection attenuation.

[0011] As a further improvement of the present technical solution, the channel switching module includes a USB channel submodule, a serial port channel submodule and an interlock logic submodule, wherein: The USB channel submodule uses 4 independent analog switches (corresponding to the USB VCC, D+, D-, and GND signals respectively). The switch on-resistance meets the low-loss transmission requirements of USB differential signals, and the off-isolation resistance meets the signal isolation requirements between channels. The serial port channel submodule adopts two independent analog switches (corresponding to the transmission signal TXD and the receiving signal RXD of the serial port respectively), supports the level range specified by the serial port protocol, and the switching time of the switch meets the timing requirements corresponding to the serial port communication rate; The interlocking logic submodule is used to prevent the USB channel and the serial port channel from being turned on at the same time: when it is detected that the control signal of the USB channel submodule is in the on state, the control signal of the serial port channel submodule is automatically locked in the off state; when it is detected that the control signal of the serial port channel submodule is in the on state, the control signal of the USB channel submodule is automatically locked in the off state, and the interlocking response time meets the timing constraints of channel switching.

[0012] As a further improvement of the technical solution, the signal transmission module includes an impedance matching submodule and a signal filtering submodule, wherein: The impedance matching submodule adjusts impedance by connecting precision resistors in series, specifically including: connecting matching resistors in series on the D+ and D- signal lines of the USB channel, and connecting corresponding matching resistors in series on the signal lines of the serial port channel according to the protocol type, to ensure that the impedance of each channel meets the characteristic impedance standard specified by the interface protocol; The signal filtering submodule is used to cross-connect a filter capacitor between the D+ and D- signals of the USB channel and the ground, and connect an RC low-pass filter circuit in series on the signal path of the serial port channel to suppress high-frequency interference signals and meet the requirements of the interface protocol for signal integrity.

[0013] As a further improvement of the technical solution, the hierarchical protection unit includes a power overcurrent protection module, a power overvoltage suppression module, a signal anti-interference filter module, and a protection state linkage module, wherein: The power overcurrent protection module is connected in series in the power path of the USB-A interface, matches the maximum interface power current specified by the USB protocol through a self-resetting fuse, and when the current of the power path exceeds the rated threshold and the duration meets the USB power supply safety timing requirements, the fuse is automatically switched to a high resistance state to cut off the current; after the current falls below the rated threshold and the safety reset timing is maintained, the fuse is automatically restored to a low resistance on state; The power overvoltage suppression module is connected in parallel to the power end of the USB-A interface, uses a TVS transient suppression diode as the core device, responds at a speed that meets the USB power end transient overvoltage protection requirements, and clamps the voltage to adapt to the safety threshold of the USB power nominal voltage; when a transient overvoltage occurs at the power end, the diode quickly conducts to discharge the inrush current; The signal anti-interference filter module is used for cross connection in the signal path of the USB-A interface, adopts a combined structure of a common mode inductor and a ceramic capacitor, wherein the common mode inductor is connected in series in the signal path and the common mode impedance characteristic is adapted to the high-frequency interference suppression requirement of USB signal transmission, and the ceramic capacitor is connected across each signal and the GND respectively to suppress the high-frequency differential mode interference and common mode interference in the signal path, so that the signal is ensured to meet the signal integrity standard of the USB protocol. The protection state linkage module is electrically connected with the power overcurrent protection module and the power overvoltage suppression module, monitors the on-off state of the power overcurrent protection module through the current sampling circuit and monitors the clamping state of the power overvoltage suppression module through the voltage sampling circuit, and converts the on-off state and the clamping state into a standard digital level (the protection trigger output high level and the normal output low level), which is fed back to the main control unit through an independent pin. After receiving the signal, the main control unit suspends the USB channel switching until the protection is removed.

[0014] As a further improvement of the technical solution, the protocol adaptation unit comprises a protocol selection module, a USB protocol analysis module, a serial port protocol analysis module and a signal format conversion module, wherein: The protocol selection module is electrically connected with the main control unit and is used for receiving the protocol adaptation instruction output by the main control unit (100) and executing the following operations according to the protocol type identifier (corresponding to USB or serial port protocol) in the instruction: if the instruction is USB protocol adaptation, enabling the USB protocol analysis module and turning off the power supply of the serial port protocol analysis module; if the instruction is serial port protocol adaptation, enabling the serial port protocol analysis module and turning off the power supply of the USB protocol analysis module. The USB protocol analysis module analyzes the original signal of the USB interface through a hardware circuit, loads the signal encoding logic (such as Manchester encoding of USB differential signal) and decoding logic (such as level judgment of differential signal and synchronous clock extraction) corresponding to USB2.0 and USB1.1 protocols, and converts the signal of the USB interface into parallel signals conforming to the data format of the main control unit. The serial port protocol analysis module is used for loading the frame structure analysis logic and the baud rate adaptation logic corresponding to RS232 and RS485 serial port protocols, identifying the start bit, data bit, check bit and stop bit in the serial port signal, adjusting the sampling clock period according to the protocol, and converting the serial port serial signal into serial data frames. The signal format conversion module is used for receiving the parallel signals output by the USB protocol analysis module and the serial data frames output by the serial port protocol analysis module, and uniformly converting them into 8-bit data format recognizable by the main control unit, and the conversion delay is not more than the channel switching time of the analog switch unit.

[0015] As a further improvement of the present technical solution, the status detection unit includes a USB status detection module, a serial port status detection module, a power supply status detection module and a status signal processing module, wherein: The USB status detection module is used to monitor the device access status of the USB-A interface and determine whether a USB device is inserted by detecting the voltage difference between the D+ and D- lines (the D+ voltage is higher than the D- voltage when the USB device is inserted, and the two voltages tend to be the same when the USB device is unplugged). The monitoring cycle is synchronized with the scheduling cycle of the main control unit; The serial port status detection module is used to monitor the serial port The communication request status of the device is detected by detecting the level jump of the serial port request signal line (such as RTS line) (high level indicates serial port The device initiates a communication request (a low level indicates no request) to identify the request and record the duration of the request signal to filter out instantaneous interference; The power supply status detection module is used to monitor the USB-A interface and the serial port The power supply status is detected by collecting the voltage at the power supply end through the voltage divider resistor and comparing it with the preset voltage threshold to determine whether the power supply is normal; The status signal processing module is used to convert the analog detection signals output by the USB status detection module, the serial port status detection module, and the power supply status detection module into standard TTL digital levels (a high level indicates an abnormal status or a request, and a low level indicates a normal status or no request), and transmit them to the main control unit through three independent pins. The signal transmission delay is less than the instruction generation cycle of the main control unit.

[0016] As a further improvement of the present technical solution, the power management unit 600 is used to provide stable power supply for the main control unit 100, the analog switch unit 200, the hierarchical protection unit 300, the protocol adapter unit 400 and the status detection unit 500. A basic input protection component is set at its input end, and a self-recovery fuse that adapts to the rated current of the external power supply is connected in series to prevent overcurrent, and a TVS transient suppression diode that adapts to the input voltage range is connected in parallel to resist transient overvoltage. At the same time, a filter capacitor is connected after the protection circuit to filter out the high-frequency noise of the input power supply; then a voltage conversion is formed through a DC-DC converter with a wide input range. The component converts the external input power into a system intermediate bus voltage such as 12V. The converter uses conventional PWM modulation to achieve the conversion, and a capacitor is connected in parallel at the output to suppress ripple. A multi-channel voltage stabilization component is then designed based on a low-voltage difference linear regulator. The 3.3V voltage is output to power logic circuits such as the main control unit 100 and the status detection unit 500, and the 5V voltage is output to power the USB path of the analog switch unit 200 and the hierarchical protection unit 300. Auxiliary voltages such as ±12V required by special units such as serial ports can also be generated through a small converter as needed, and interference between different voltage domains can be avoided through diode isolation.

[0017] Compared with the prior art, the application has the following beneficial effects: 1. The application relies on a master control unit to carry out priority scheduling in combination with multi-dimensional parameters such as transmission load of the USB-A interface and communication urgency of the serial port UART, can flexibly switch the communication channels of the USB-A interface and the serial port according to actual communication needs, enhances the flexibility and adaptability of interface switching, and solves the switching limitation problem caused by a single triggering condition; 2. The hierarchical protection unit of the application not only sets power overcurrent protection, power overvoltage suppression and signal anti-interference filtering modules for the USB-A interface, but also cooperatively protects the electrical safety of the serial port UART through protection state linkage, reduces the case of hardware damage caused by power abnormalities, signal interference and the like during dynamic switching and communication of the USB-A interface and the serial port, and improves the overall communication reliability of the system; 3. The protocol adaptation unit of the application can parse and format convert the communication protocols of the USB-A interface and the serial port UART, cooperate with the state detection unit to obtain interface states in real time, enable the master control unit to more accurately master the interface operating conditions, provide a more reliable basis for dynamic switching and hierarchical protection, and further ensure the stability and coordination of USB-A interface and serial port communication. BRIEF DESCRIPTION OF DRAWINGS

[0018] Figure 1 The figure is a schematic diagram of the system framework of the application; The meanings of the various reference numerals in the figure are as follows: 100, master control unit; 110, parameter quantization module; 111, USB load quantization sub-module, 112, serial port urgency quantization sub-module; 120, priority scheduling module; 130, instruction output module; 200, analog switch unit; 210, control interface module; 220, channel switching module; 221, USB channel sub-module; 222, serial port channel sub-module; 223, interlocking logic sub-module; 230, signal transmission module; 231, impedance matching sub-module; 232, signal filtering sub-module; 300, hierarchical protection unit; 310, power overcurrent protection module; 320, power overvoltage suppression module; 330, signal anti-interference filtering module; 340, protection state linkage module; 400, protocol adaptation unit; 410, protocol selection module; 420, USB protocol parsing module; 430, serial port protocol parsing module; 440, signal format conversion module; 500, state detection unit; 510, USB state detection module; 520, serial port state detection module; 530, power supply state detection module; 540, state signal processing module; 600, power management unit. DETAILED DESCRIPTION

[0019] The following will provide a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.

[0020] like Figure 1 As shown, this embodiment provides a USB-A interface and serial port dynamic switching and protection system based on an analog switch, including: The main control unit 100 is used to coordinate the dynamic switching and conflict coordination between the USB-A interface and the serial port, and integrates the dynamic priority scheduling algorithm, combined with the real-time load of USB data transmission and the serial port feedback from the status detection unit 500. The urgency of the communication request and the historical interaction records of the device are used to generate a conflict-free channel switching control instruction and drive the analog switch unit 200 to complete the channel selection; In this embodiment, the main control unit 100 includes a parameter quantization module 110, a priority scheduling module 120, and an instruction output module 130, wherein: The parameter quantization module 110 is used to collect the USB real-time transmission parameters output by the state detection unit 500 and the serial port Request parameters and convert them into computable quantitative values; The priority scheduling module 120 uses a dynamic priority scheduling algorithm to schedule the quantified USB and serial ports. Parameters are used for priority calculation and conflict determination; The instruction output module 130 generates a channel switching control instruction that complies with the hardware interface specification of the analog switch unit 200 according to the priority scheduling result.

[0021] As a further explanation of this embodiment, the instruction output module 130 of this embodiment specifically includes: reading the hardware interface specification of the analog switch unit 200 (such as the SPI interface communication protocol), converting the priority determination result output by the priority scheduling module 120 into a channel switching control instruction that complies with the specification (for example, "0x01" corresponds to the USB channel selection instruction, and "0x02" corresponds to the serial port channel selection instruction); sending the control instruction to the analog switch unit 200 through the hardware interface (such as the GPIO pin) to drive it to complete the selection operation of the specified communication channel; and recording the switching instruction and the corresponding USB load weight at the same time. , USB interface priority 、Serial port UART priority The parameters are used to provide device historical interaction record support for weight adjustment of the subsequent priority scheduling module 120.

[0022] In the embodiment, the parameter quantification module 110 includes a USB load quantification submodule 111 and a serial port emergency quantification submodule 112, wherein: The USB load quantification submodule 111 is used to generate a USB load quantification value , which is converted from the transmission load proportion based on the USB real-time transmission rate in combination with the protocol nominal rate corresponding to the protocol type (such as USB2.0, USB1.1, etc.) followed by the USB-A interface. ; The serial port emergency quantification submodule 112 is used to generate a serial port emergency quantification value , which is mapped from the serial port emergency level in the serial port request signal by analyzing the emergency level identification bit conforming to the industry standard.

[0023] As a further description of the embodiment, in the USB load quantification submodule 111 of the embodiment: first, the state detection unit 500 collects the total number of USB data bytes (the collection interval configured by the timer of the master control unit 100) according to the system scheduling period (the total number of bytes transmitted by the USB-A interface ), and then calculates the USB real-time transmission rate (the actual transmission rate of the USB-A interface) according to the following formula: ; and then generates the USB load quantification value (indicating the percentage of transmission load to the protocol nominal rate, taking values 0-100) by the following formula in combination with the protocol nominal rate matching the USB-A interface protocol (such as 480 for USB2.0 and 12 for USB1.1, pre-stored by the hardware configuration interface): ; if , it is forcibly set to 0, , it is forcibly set to 100.

[0024] As a further description of the embodiment, the serial port emergency quantification submodule 112 of the embodiment specifically includes: analyzing the emergency level identification bit conforming to GB / T19892-2005 in the 3-5 bits of the serial port UART request signal, converting the 3-bit binary identification bit into the serial port emergency level (1 is the lowest and 5 is the highest, taking values 1-5); and then generating the serial port emergency quantification value by the formula ​​​​​(Values 10-50, the higher the value of the higher level of emergency), if the identification bit is 000 (no emergency level) is defaulted , the identification bit is 110-111 (out of the specification level) is defaulted .

[0025] In this embodiment, the priority scheduling module 120 carries out priority calculation and conflict determination through a dynamic priority scheduling algorithm, including the following steps: S120.1, obtaining the USB load quantization value and the serial port emergency quantization value output by the parameter quantization module 110 , , combining the preset USB load weight and the serial port emergency weight ( , the initial weight is set through a hardware configuration interface), calculating the initial priority of the USB interface and the serial port ; S120.2, dynamically adjusting the weight according to the continuous monitoring result of the state detection unit 500: If the USB transmission rate is detected for N consecutive times to meet the high load characteristics defined by its protocol type, increase and simultaneously decrease , the adjusted does not exceed the maximum weight limit of hardware adaptation; If the serial port sends the highest emergency level request meeting the industry specification for M consecutive times, increase and simultaneously decrease , the adjusted does not exceed the maximum weight limit of hardware adaptation; S120.3, calculating the priority difference of the USB and the serial port , if the priority difference ≥ conflict threshold ( determined based on the nominal switching time in the hardware specification book of the analog switch unit 200, to ensure that the signal is switched and stable communication is established), then directly determine the high-priority channel as the current gating channel; if the priority difference is less than , then the USB data frame interval and the serial port request timeout time obtained by the state detection unit 500 are called to preferentially select the channel that needs to complete the response before the timeout time; S120.4, real-time monitoring of the USB load quantization value and the serial port emergency quantization value If any quantization value exceeds its physical definition range (such as the USB load quantization value exceeds the maximum transmission capacity of the corresponding protocol), the current weight adjustment logic is frozen and the existing priority calculation method is maintained until the status detection unit 500 feeds back an abnormality release signal.

[0026] As a further explanation of this embodiment, the initial priority calculation in the priority scheduling module 120 of this embodiment includes the following steps: first, clearly define the parameters: (USB load weight, initial 0.5, maximum 0.8, hardware configuration interface setting), (Serial port urgency weight, determined by Derivation, maximum 0.8), (USB interface priority, value range 0-80), (Serial UART priority, value 0-40); then obtain the output of parameter quantization module 110 and , calculate the initial priority of USB interface and serial port UART respectively according to the following formula; ; .

[0027] As a further explanation of this embodiment, the dynamic adjustment of weights in the priority scheduling module 120 of this embodiment specifically includes: first clarifying the parameter definition: (weight adjustment step, pre-stored in the hardware firmware), N (USB high load continuous detection times, hardware configuration interface can be modified), M (serial port highest emergency level continuous detection times, hardware configuration interface can be modified); if the USB high load is detected N times in a row (such as ), then press , increase and simultaneously reduce , and after adjustment No more than 0.8; if the highest emergency level request of the serial port is detected M times in succession (i.e. ), then press Increase and simultaneously reduce , and after adjustment Not exceeding 0.8.

[0028] Further, in the priority scheduling module 120 of the embodiment, the default value of the serial port highest emergency level continuous detection number M is set to 2, which is determined based on the technical characteristics of the highest emergency level request of the serial port UART, that is, the highest emergency level request needs to consider the response timeliness and anti-transient interference ability, and continuous detection for 2 times can avoid single false triggering (such as false emergency request caused by signal fluctuation), while not delaying the channel switching of the emergency task; at the same time, the value of M can be modified through a hardware configuration interface (such as the I2C configuration pin of the master control unit 100) to adapt to the emergency response requirements in different scenes (for example, in an industrial control scene with higher response speed requirements, M can be adjusted to 1), and the adjustment of M needs to be matched with the weight adjustment step (0.1) coordination, ensure that when the serial port emergency request triggers the weight adjustment, , the increase amplitude matches the request emergency degree, avoiding sudden changes in priority.

[0029] Further, the default value of the USB high load continuous detection number N is set to 3, which is designed in combination with the transmission characteristics of the USB-A interface, that is, there is transient high load fluctuation in USB transmission (such as frame interval fluctuation in batch data transmission), and continuous detection for 3 times can exclude the interference of transient load peaks, ensuring that the "high load" determined is in a continuous state (needs to meet , that is, the transmission load is more than 80% of the nominal rate of the protocol); the value of N supports modification through a hardware configuration interface, for example, in a scene with high requirements for USB data transmission stability (such as continuous file transmission), N can be adjusted to 4 to further reduce the false judgment probability; at the same time, the value of N needs to be matched with the system scheduling period , to ensure that the total time length of continuous detection does not exceed the timeout time of the USB protocol (such as the timeout time of USB2.0 batch transmission), avoiding affecting normal data transmission.

[0030] Further, for the value of , it needs to adapt to the upper limit requirements of the USB load weight (initial 0.5, maximum 0.8 for hardware adaptation) and the serial port emergency degree weight (initial 0.5, maximum 0.8 for hardware adaptation), to ensure that after multiple adjustments, the weights do not exceed the limit, while matching the determination logic of the USB high load continuous detection number N (default 3 times) and the serial port highest emergency level continuous detection number M (default 2 times), so that the weight after continuous detection can be reasonably increased to the demand threshold and not exceed the limit; it also needs to ensure the stability of priority calculation, avoiding that the overly large priority of the USB interface , the priority of the serial port UART Sudden changes in traffic flow will cause frequent channel switching, and the system scheduling cycle needs to be adapted to ensure that within the total duration of N / M consecutive detections, the weight adjustment can be used to promptly respond to communication needs in high-load or high-emergency scenarios.

[0031] As a further explanation of this embodiment, the conflict determination in the priority scheduling module 120 of this embodiment is specifically implemented by combining parameter comparison: first, the relevant parameters are clarified: is the priority difference, calculated using the following formula: ; is the conflict threshold, based on the nominal switching time of the chip used in the analog switch unit 200 (The nominal switching time and chip model match, which is pre-stored in the hardware configuration interface) to calculate and ensure the signal is stable after switching; is the USB data frame interval, collected by the status detection unit 500; It is the serial port UART request timeout, which is pre-stored in the serial port protocol. Afterwards, if , directly select the high priority channel as the current selection channel; if , just compare and , give priority to the channel that "needs to complete the response before the timeout period", that is, if Select the USB channel, otherwise select the serial port channel.

[0032] As a further explanation of this embodiment, the effectiveness monitoring in the priority scheduling module 120 of this embodiment specifically includes: real-time monitoring of the USB load quantization value Serial port emergency quantization value The numerical validity of It needs to be within the physically reasonable range of 0-100. It needs to be in the quantization range of 10-50; if any quantization value exceeds the corresponding range, the current weight adjustment logic is immediately frozen and the existing priority calculation method is maintained until the state detection unit 500 feedbacks the abnormality relief signal, and then the weight dynamic adjustment function is restored.

[0033] The analog switch unit 200 is used to establish a physical channel selection path between the USB-A interface and the serial port, and to switch the USB-A interface or the serial port through an analog switch circuit that can switch the signal path. The signal is transmitted to the public interface and the conduction state is switched according to the control instruction of the main control unit 100; In this embodiment, the analog switch unit 200 includes a control interface module 210, a channel switching module 220 and a signal transmission module 230, wherein: The control interface module 210 is used to receive the channel switching control instruction output by the main control unit 100, and convert the 8-bit channel identifier, 8-bit switching delay parameter, and 8-bit CRC check code contained in the instruction into a control signal that conforms to the logic level of the analog switch circuit; As a further illustration of this embodiment, the control interface module 210 of this embodiment communicates with the main control unit 100 using an SPI interface. The communication parameters must be consistent with the SPI configuration of the main control unit 100: the clock polarity is set to 0 (the clock signal is low when idle), the clock phase is set to 0 (data is sampled on the rising edge of the clock), and the communication rate matches the SPI output rate of the main control unit 100 (e.g., 1 MHz to ensure that there is no packet loss during instruction transmission). Furthermore, the 8-bit instruction register and 8-bit status register integrated within the control interface module 210 need to implement a two-way interaction of "instruction latch-status return" through hardware circuits: Latch logic of the 8-bit instruction register: After the main control unit 100 sends a 1-byte channel switching instruction (including an 8-bit channel identifier, an 8-bit switching delay parameter, and an 8-bit CRC check code), the instruction register is latched by the falling edge of the SPI chip select signal to avoid parameter errors caused by signal fluctuations during instruction transmission; 8-bit status register feedback mechanism: The status register collects the current conduction status of the channel switching module 220 in real time (e.g., "0x01" indicates USB channel conduction, "0x02" indicates serial port channel conduction, and "0x00" indicates no channel conduction). The main control unit 100 can read the status value through the SPI read instruction. The reading cycle is synchronized with the status detection cycle of the main control unit 100 (e.g., 100 μs); Parsing rules for command parameters: In the 8-bit channel identifier, "0x01" corresponds to the USB channel selection instruction, and "0x02" corresponds to the serial port channel selection instruction; the unit of the 8-bit switching delay parameter is μs (value range 1-255μs), which is used to set the delay time from the output of the control signal to the actual action of the switch (adapting to the action timing of different switch chips); the 8-bit CRC check code adopts the CRC-8 standard algorithm, and the check value is calculated by the 16-bit data of "channel identifier + switching delay". If the command register detects that the check code does not match, the control signal is not output, and the "error flag bit" (7th bit) of the status register is set to 1, prompting the main control unit 100 to resend the instruction.

[0034] The channel switching module 220 includes at least two independent single-pole double-throw switch circuits, one of which corresponds to the power supply and signal path of the USB-A interface, and the other corresponds to the serial port. The sending and receiving signal paths are switched to the on state of the switch by the control signal output by the control interface module 210; The signal transmission module 230 is used to connect the channel switching module 220 and the public interface, and the circuit impedance of the signal transmission module 230 matches the characteristic impedance requirements of the USB-A interface and the serial port , so as to ensure that the signal transmission is not attenuated by reflection.

[0035] In the embodiment, the channel switching module 220 comprises a USB channel submodule 221, a serial port channel submodule 222 and an interlocking logic submodule 223, wherein: The USB channel submodule 221 adopts four independent analog switches (corresponding to the VCC, D+, D- and GND signals of the USB, respectively), and the on-resistance of the switches meets the low-loss transmission requirements of the USB differential signals, and the off-isolation resistance meets the signal isolation requirements between the channels; As a further description of the embodiment, the USB channel submodule 221 adopts four independent analog switches, which correspond to the VCC (power supply), D+ (differential signal positive), D- (differential signal negative) and GND (ground) signals of the USB-A interface, respectively, and the switch chip needs to meet the following characteristics: On-resistance requirement: the on-resistance of the two switches corresponding to the D+ and D- differential signals needs to be ≤5Ω (to meet the low-loss transmission requirements of the USB protocol for differential signals, so as to avoid communication errors caused by signal attenuation); the on-resistance of the two switches corresponding to the VCC and GND needs to be ≤1Ω (to reduce the voltage drop in the power transmission process, so as to ensure stable power supply of the USB device); Off-isolation resistance requirement: the off-isolation resistance of all switches needs to be ≥10MΩ (to avoid signal crosstalk of the non-conducting channel, for example, when the USB channel is off, the serial port signal will not interfere with the USB line through the isolation resistance); Circuit connection mode: the VCC path switch is connected in series between the VCC pin of the USB-A interface and the VCC pin of the public interface, and a self-resetting fuse is connected in series in front of the switch (adapted to the maximum working current of the USB device, such as 2A), to prevent overcurrent damage to the switch chip; the D+ and D- path switches are directly connected in series between the corresponding signal lines, and test points need to be reserved at both ends of the switches, to facilitate measurement of signal integrity during debugging.

[0036] The serial port channel submodule 222 adopts two independent analog switches (corresponding to the transmission signal TXD and the reception signal RXD of the serial port , respectively), supports the level range specified in the serial port protocol, and the switching time of the switches meets the timing requirements corresponding to the serial port communication rate; As a further description of the embodiment, the serial port channel submodule 222 adopts two independent analog switches, which correspond to the TXD (transmission signal) and RXD (reception signal) of the serial port UART, respectively, and the hardware configuration thereof needs to adapt to the protocol characteristics of the serial port UART: Level range support: The switch chip needs to be compatible with the TTL level or RS232 level commonly used in serial UART, and the specific selection is determined according to the actual application scenario (such as RS232 level commonly used in industrial control scenario, TTL level commonly used in embedded device scenario); Switching time constraint: The switching time of the switch (from the trigger of the control signal to the complete conduction / cutoff of the switch) needs to match the communication rate requirement of the serial UART, ensuring that it matches the communication rate requirement of the serial UART (such as 104us per bit of data transmission time corresponding to 9600bps, and 10us switching time will not affect the data timing); Signal protection measures: 1-way TVS transient suppression diode (breakdown voltage adapted to serial level, such as 5V TVS tube for TTL level) is connected in parallel across the TXD and RXD signal lines on both sides of the switch to prevent damage to the switch chip caused by transient high voltage during live insertion.

[0037] The interlocking logic submodule 223 is used to prevent the USB channel and the serial channel from being turned on at the same time: When it is detected that the control signal of the USB channel submodule 221 is in the on state, the control signal of the serial channel submodule 222 is automatically locked in the off state; when it is detected that the control signal of the serial channel submodule 222 is in the on state, the control signal of the USB channel submodule 221 is automatically locked in the off state, and the interlocking response time meets the timing constraints of channel switching.

[0038] As a further illustration of this embodiment, the interlocking logic submodule 223 realizes the "mutually exclusive conduction" of the USB channel and the serial channel through a hardware logic circuit, avoiding signal conflicts and hardware damage caused by the simultaneous conduction of the two channels, and its implementation logic is as follows: Control signal detection method: The interlocking logic submodule 223 uses two voltage comparators to collect the control signal levels of the USB channel submodule 221 and the serial channel submodule 222 (such as high level indicating "on instruction" and low level indicating "off instruction"), and the threshold voltage of the comparator is set to 1 / 2 of the power supply voltage (such as 1.65V threshold for 3.3V power supply), ensuring accurate level detection; Interlocking response mechanism: When the comparator detects that the USB channel control signal is high, it forcibly pulls down the serial channel control signal through an AND gate circuit (locks it in the off state); when it detects that the serial channel control signal is high, it forcibly pulls down the USB channel control signal for the same reason; the interlocking response time needs to be less than the switching action time of the channel switching module 220 (such as 10us), ensuring that the interlocking is completed before the switch is fully turned on; Fault protection logic: if two control signals are detected to be high at the same time (an abnormal scenario), the interlocking logic submodule 223 will force both control signals to be low, and send an "interlocking fault" signal to the state register of the control interface module 210 (set the 6th bit of the state register to 1), prompting the host unit 100 to troubleshoot the instruction abnormality.

[0039] In the present embodiment, the signal transmission module 230 includes an impedance matching submodule 231 and a signal filtering submodule 232, wherein: The impedance matching submodule 231 achieves impedance adjustment by connecting precise resistors in series, specifically including: connecting matching resistors in series on the D+ and D- signal lines of the USB channel, and connecting corresponding matching resistors in series on the signal lines of the serial port channel according to the protocol type, to ensure that the impedance of each channel meets the characteristic impedance standard specified by the interface protocol; As a further illustration of the present embodiment, the impedance matching submodule 231 achieves impedance adjustment by connecting precise resistors (with a precision of 1%, meeting the impedance error requirements of the interface protocol) in series. The resistance value needs to be determined according to the characteristic impedance standard of the interface protocol, specifically including: Impedance matching of the USB channel: the D+ and D- differential signal lines of the USB-A interface need to meet the 90Ω±10% characteristic impedance requirement, so 1-way 10Ω precise resistors are connected in series on the D+ and D- signal lines (if the PCB trace impedance has been designed as 80Ω, the total impedance after connecting a 10Ω resistor is 90Ω, which meets the protocol requirements); the VCC and GND signal lines do not need to be additionally connected with resistors, and their impedance is determined by the cross-sectional area and length of the wire (e.g., the impedance of a 24AWG wire is about 0.08Ω / meter, meeting the low impedance requirement for power transmission); Impedance matching of the serial port channel: the characteristic impedance of the serial port UART is determined according to the protocol type, such as 75Ω characteristic impedance for RS232 protocol and 120Ω characteristic impedance for RS485 protocol, so precise resistors matching the characteristic impedance need to be connected in series on the TXD and RXD signal lines (e.g., 15Ω resistors are connected in series in the RS232 scenario, adapting to the 60Ω impedance of the PCB trace, with a total impedance of 75Ω); the series position of the resistors needs to be close to the common interface end, to reduce the impedance mutation on the signal transmission path.

[0040] The signal filtering submodule 232 is used to cross-connect a filtering capacitor between the D+ and D- signals and the ground of the USB channel, and connect an RC low-pass filter circuit in series on the signal path of the serial port channel, to suppress high-frequency interference signals and meet the signal integrity requirements of the interface protocol; As a further illustration of the present embodiment, the signal filtering submodule 232 suppresses high-frequency interference through differential filtering circuits according to the signal characteristics of USB and serial ports, to ensure signal integrity: USB channel filtering: between the D+ and D- signal lines of the USB channel and the ground, each is connected with a high-frequency filtering capacitor (the capacitance is adapted to the USB protocol EMI suppression requirements), which is used to filter out high-frequency interference above 100 MHz, and the capacitor is arranged close to the public interface end to shorten the filtering path; Serial port channel filtering: on the TXD and RXD signal paths of the serial port channel, each is connected with an RC low-pass filter circuit, and the cutoff frequency is determined according to the highest communication rate of the serial port (for example, for a rate of 115,200 bps, the cutoff frequency is about 100 kHz), so as to avoid interference signals affecting serial port data transmission; Component selection: high-frequency characteristic ceramic capacitors are selected for filtering capacitors, and precise resistors with stable resistance are selected for filtering resistors, to ensure long-term reliable filtering effect.

[0041] The hierarchical protection unit 300 is used to realize multi-dimensional electrical protection of the USB-A interface, and a cooperative protection mechanism of power supply and signal is formed by connecting an overcurrent protection device in series in the power supply path of the USB-A interface, connecting an overvoltage suppression device in parallel at the power supply end, and connecting a high-frequency interference filter device across the signal path. In this embodiment, the hierarchical protection unit 300 includes a power overcurrent protection module 310, a power overvoltage suppression module 320, a signal anti-interference filtering module 330, and a protection state linkage module 340, wherein: The power overcurrent protection module 310 is used to be connected in series in the power supply path of the USB-A interface, and the maximum interface power supply current specified by the USB protocol is matched through a self-resetting fuse; when the current of the power supply path exceeds the rated threshold and the duration meets the USB power supply safety timing requirements, the fuse is automatically switched to a high resistance state to cut off the current; after the current falls below the rated threshold and the safety reset timing is maintained, the fuse is automatically restored to a low resistance conduction state; As a further description of this embodiment, the power overcurrent protection module 310 of this embodiment takes a self-resetting fuse as the core device, which is connected in series in the VCC power supply path of the USB-A interface (one end is connected to the USB-A interface VCC pin, and the other end is connected to the VCC input of the back-end power supply circuit), and the device selection and action logic need to strictly adapt to the USB protocol requirements, which are as follows: Self-resetting fuse selection basis: the rated current is determined according to the protocol followed by the USB-A interface, for example, the USB2.0 protocol specifies that the maximum power supply current of the interface is 500 mA, and the USB3.0 protocol is 900 mA, and the rated current of the fuse needs to be 10%-20% higher than the maximum current of the protocol (for example, a fuse with a rated current of 600 mA is selected in the USB2.0 scenario), to avoid false triggering of overcurrent protection during normal power supply; the normal temperature conduction resistance of the fuse needs to be ≤50 mΩ, to reduce the power transmission voltage drop and ensure stable power supply of the USB device; Overcurrent action timing: when the power path current exceeds the rated threshold (such as 600mA) and the duration meets the USB power supply safety timing requirements (such as ≥100μs, matching the instantaneous current fluctuation characteristics of USB devices), the fuse quickly switches to a high resistance state (resistance ≥1kΩ) due to the Joule heating effect, cutting off the power path; after the current falls below the rated threshold (such as ≤500mA) and maintains a safe reset timing (such as ≥1s, ensuring that the fault is completely eliminated), the fuse temperature drops, automatically restoring the low resistance conduction state (restoring to the initial conduction resistance), without the need for manual intervention; Circuit protection design: a 1-way LED indicator lamp (with a 1kΩ current limiting resistor in series) is connected in parallel across the fuse, when the fuse triggers overcurrent protection and switches to a high resistance state, the indicator lamp lights up due to the voltage difference across the two terminals, providing a direct indication of the overcurrent fault; the indicator lamp goes out after the fault is recovered, facilitating troubleshooting by operation and maintenance.

[0042] The power overvoltage suppression module 320 is connected in parallel across the power supply end of the USB-A interface, using a TVS transient voltage suppression diode as the core device, with a response speed that meets the USB power supply end transient overvoltage protection requirements, and a clamping voltage that adapts to the safety threshold of the USB power supply nominal voltage; when a transient overvoltage occurs at the power supply end, the diode quickly conducts to discharge the surge current; As a further description of the present embodiment, the power overvoltage suppression module 320 of the present embodiment uses a TVS transient voltage suppression diode as the core device, connected in parallel between VCC and GND of the USB-A interface (close to the power supply end of the USB-A interface, shortening the transient surge path), with device parameters and action logic adapted to the USB power supply characteristics, specifically including: TVS tube selection requirements: the response speed needs to meet the rapid protection requirements of the USB power supply end transient overvoltage, avoiding the breakdown of the back-end circuit after the surge voltage; the clamping voltage needs to adapt to the safety threshold of the USB power supply nominal voltage, for example, when the USB-A interface nominal power voltage is 5V, the clamping voltage is set to 6-7.5V (to prevent overvoltage damage to the device, and to avoid false triggering due to normal voltage fluctuations); the peak pulse power of the TVS tube needs to adapt to common power transient surge power, such as static electricity during plugging; Overvoltage action logic: when a transient overvoltage (such as a spike voltage caused by static electricity during plugging) occurs at the power supply end of the USB-A interface, the TVS tube enters a nanosecond-level fast conduction state, discharging the surge current to GND, and clamping the power supply end voltage within the set safety threshold (such as 7V); after the transient overvoltage disappears and the power supply voltage falls to the nominal value (5V), the TVS tube automatically returns to the off state, without affecting normal power supply; Auxiliary protection: a 1-way magnetic bead is connected in series between the TVS tube and the USB-A interface, suppressing high-frequency surge signals and preventing interference with other circuits when the surge is discharged through the TVS tube.

[0043] The signal anti-interference filter module 330 is used to cross the signal path of the USB-A interface, adopts a combination structure of common mode inductance and ceramic capacitor, wherein: the common mode inductance is connected in series in the signal path and the common mode impedance characteristic is adapted to the high frequency interference suppression requirement of USB signal transmission, and the ceramic capacitor is respectively crossed between each signal and GND to suppress the high frequency differential mode interference and common mode interference in the signal path, so as to ensure that the signal meets the signal integrity standard of USB protocol; As a further description of the embodiment, the signal anti-interference filter module 330 of the embodiment adopts a combination of "common mode inductance + ceramic capacitor" and is crossed in the D+, D- signal path of the USB-A interface, specifically: Common mode inductance: connected in series in the D+, D- path, common mode impedance ≥ 1kΩ at 100MHz to suppress high frequency common mode interference, rated current ≥ 100mA, differential mode impedance ≤ 5Ω to avoid affecting signal transmission; Ceramic capacitor: 0.01-0.1μF (such as 0.047μF) X7R material capacitor is crossed between D+ and GND and between D- and GND to filter out high frequency differential mode interference, and the capacitance deviation is ≤ 5% to ensure the balance of differential signals; Layout: the filter elements are arranged close to the USB-A interface to ensure that the interference is filtered out before entering the rear-end circuit.

[0044] The protection state linkage module 340 is electrically connected with the power overcurrent protection module 310 and the power overvoltage suppression module 320, monitors the on-off state of the power overcurrent protection module 310 through a current sampling circuit, monitors the clamping state of the power overvoltage suppression module 320 through a voltage sampling circuit, and converts the on-off state and the clamping state into standard digital levels (protection trigger output high level, normal output low level), which are fed back to the main control unit 100 through independent pins. After receiving the signals, the main control unit 100 suspends the USB channel switching until the protection is removed.

[0045] As a further description of the embodiment, the protection state linkage module 340 of the embodiment monitors the power protection state and feeds back to the main control unit 100 to realize cooperative control, which specifically includes: Sampling circuit: current sampling is collected by a 10mΩ resistor, and voltage sampling is collected by a voltage dividing resistor; State conversion: the sampling signals are converted into 3.3V standard digital levels (protection trigger output high level, normal output low level) by a voltage comparator, and the comparator threshold is set to 0.5V (to distinguish the overcurrent state) and 2V (to distinguish the overvoltage state) respectively; Feedback and linkage: the status is fed back to the main control unit 100 through two independent GPIO pins, and the main control unit 100 suspends the USB channel switching after receiving a high level (protection trigger), and restores the switching function until the signal returns to low and the delay is greater than or equal to 500us.

[0046] The protocol adaptation unit 400 is used to realize the dynamic compatibility of USB and serial port protocols. By integrating a switchable protocol analysis circuit, the signal coding and decoding logic corresponding to the protocol is loaded based on the instruction of the main control unit 100, and the signal format conversion is completed. In this embodiment, the protocol adaptation unit 400 includes a protocol selection module 410, a USB protocol analysis module 420, a serial port protocol analysis module 430, and a signal format conversion module 440, wherein: The protocol selection module 410 is electrically connected with the main control unit 100, and is used to receive the protocol adaptation instruction output by the main control unit 100, and to enable the USB or serial port protocol analysis module corresponding to the protocol type identification in the instruction. The protocol performs the following operations: if the instruction is USB protocol adaptation, the USB protocol analysis module 420 is enabled and the power supply of the serial port protocol analysis module 430 is turned off; if the instruction is serial port protocol adaptation, the serial port protocol analysis module 430 is enabled and the power supply of the USB protocol analysis module 420 is turned off. The protocol performs the following operations: if the instruction is USB protocol adaptation, the USB protocol analysis module 420 is enabled and the power supply of the serial port protocol analysis module 430 is turned off; if the instruction is serial port protocol adaptation, the serial port protocol analysis module 430 is enabled and the power supply of the USB protocol analysis module 420 is turned off. As a further description of this embodiment, the protocol selection module 410 of this embodiment uses a dual-channel power supply switch chip (supporting 3.3V power supply, on-resistance ≤50mΩ) to control the power supply of the USB protocol analysis module 420 and the serial port protocol analysis module 430 respectively; the chip enable end is connected with the GPIO pin of the main control unit 100 to receive an 8-bit protocol adaptation instruction (“0x01” corresponds to USB protocol, “0x02” corresponds to serial port protocol). After the instruction is stored in the module register through the SPI interface, the logic circuit controls the power supply of the corresponding module according to the instruction: the enable end is high when the target module is enabled, and the enable end is low when the non-target module is turned off, the switching delay is ≤10us, and the module power consumption is ≤10uA in the off state.

[0047] The USB protocol analysis module 420 analyzes the original signal of the USB interface through a hardware circuit, loads the signal coding logic corresponding to the USB2.0 and USB1.1 protocols such as the Manchester coding and decoding logic of the USB differential signal, and converts the signal of the USB interface into a parallel signal conforming to the data format of the main control unit 100. As a further illustration of the present embodiment, the input end of the USB protocol analysis module 420 of the present embodiment is connected in series with a resistance matched with the characteristic impedance of the USB differential line, and the D+ and D- differential signals are converted into single-ended signals by a high-speed differential receiver, supporting USB 2.0 (high-speed / full-speed mode) and USB 1.1 (low-speed mode). A built-in Manchester encoder decoder extracts a synchronous clock (the frequency is adaptively adjusted according to the transmission rate) through a phase-locked loop, and after level judgment of the differential signals, the signals are converted into parallel signals through a shift register, and then output to the signal format conversion module 440 through a data buffer. The output delay meets the high-speed transmission requirement of the USB protocol.

[0048] The serial port protocol analysis module 430 is used to load the RS232 and RS485 serial ports corresponding to the frame structure analysis logic and the baud rate adaptation logic, identify the start bit, data bit, check bit and stop bit in the serial port signal, and adjust the sampling clock period according to the protocol, convert the serial port serial signal into a serial data frame; As a further illustration of the present embodiment, the serial port protocol analysis module 430 of the present embodiment receives signals through a level conversion chip (which can support RS232 and TTL level conversion), identifies the start bit (low level) through edge detection, samples the data bit (5-8 bits optional), check bit (odd check / even check / no check optional) and stop bit (1-2 bits optional) in sequence according to the frame structure, and the sampling point is located at the middle time of each bit signal to reduce noise interference. At the same time, a built-in baud rate generator supports standard baud rates from 1200bps to 115200bps, and the sampling clock period is adjusted by the preconfigured parameters of the main control unit 100 (the error meets the serial port protocol requirement), the analyzed data is packaged into a serial data frame (including a frame valid flag), and output to the signal format conversion module 440.

[0049] The signal format conversion module 440 is used to receive the parallel signals output by the USB protocol analysis module 420 and the serial data frame output by the serial port protocol analysis module 430, and uniformly convert them into 8-bit data format recognizable by the main control unit 100. The conversion delay does not exceed the channel switching time of the analog switch unit 200.

[0050] As a further illustration of the present embodiment, when the signal format conversion module 440 receives the parallel signals of the USB protocol analysis module 420, it processes them in a slicing manner; when it receives the serial data frame of the serial port protocol analysis module 430, it extracts the valid data bits (high bits are filled with 0 when there are less than 8 bits, and slicing processing is performed when there are more than 8 bits). After conversion, they are uniformly converted into 8-bit format of "1-bit start bit + 8-bit data bit + 1-bit stop bit", the timing is synchronized with the read clock of the main control unit 100, the total conversion delay does not exceed the channel switching time of the analog switch unit 200, and a built-in buffer is used to prevent data overflow.

[0051] The state detection unit 500 is configured to collect interface connection and operation states, monitor USB-A interface plugging signals, serial port communication request signals and power supply state signals, and convert the detection results into electrical signals and transmit the electrical signals to the main control unit 100. In this embodiment, the state detection unit 500 includes a USB state detection module 510, a serial port state detection module 520, a power supply state detection module 530 and a state signal processing module 540, wherein: The USB state detection module 510 is configured to monitor the device access state of the USB-A interface, and determine whether a USB device is plugged in by detecting the voltage difference of the D+ and D- lines (the voltage of the D+ line is higher than that of the D- line when the USB device is plugged in, and the voltages of the two lines tend to be consistent when the USB device is unplugged), and the monitoring period is synchronized with the scheduling period of the main control unit 100. As a further description of this embodiment, the USB state detection module 510 of this embodiment monitors the device access state of the USB-A interface through a voltage comparison circuit, and specifically as follows: Circuit configuration: The D+ and D- signal lines are respectively connected in series with adaptive voltage dividing resistors (the resistance values are determined according to the signal level range of the USB protocol), and the signal voltage is reduced to the input range (such as 0-3.3V) of the comparator; the two signals are respectively connected to the non-inverting and inverting terminals of the differential voltage comparator, and the output terminal of the comparator is connected to the state signal processing module 540. Detection logic: When the USB device is plugged in, the voltage of the D+ line (about 3.3V) is higher than that of the D- line (about 0V), and the comparator outputs a high level; when the device is unplugged, the voltages of the D+ and D- lines both tend to 0V, and the comparator outputs a low level. Period synchronization: The detection period of the USB state detection module 510 is triggered by the timer of the main control unit 100, and is consistent with the system scheduling period (such as 1ms), so as to ensure that the state monitoring and the scheduling logic are time-matched; the detection circuit is internally provided with a 100nF filtering capacitor to filter out high-frequency noise on the signal line and avoid false judgments caused by transient voltage fluctuations.

[0052] The serial port state detection module 520 is configured to monitor the communication request state of the serial port device, identify the request by detecting the level jump (high level indicates that the serial port device initiates a communication request, and low level indicates no request) of the serial port request signal line (such as the RTS line), and record the duration of the request signal to filter out transient interference. As a further description of this embodiment, the serial port state detection module 520 of this embodiment identifies the communication request of the serial port device through level jump detection and duration judgment, and specifically includes the following contents: Signal conditioning: the RTS line of the serial port is connected to the serial port state detection module 520 after being shaped by a Schmitt trigger. The threshold voltage of the trigger is adapted to the high / low level standard of the serial port to eliminate the glitch interference of the signal edge; Request identification: the serial port state detection module 520 is internally provided with an edge detection circuit. When the RTS line is detected to jump from low level to high level, a counter is started to record the duration of the high level. If the duration exceeds the preset interference filtering threshold (such as 50 μs, which can be configured by the host unit 100), it is determined to be a valid communication request. If the duration is insufficient, it is determined to be transient interference, and the request signal is not triggered. State maintenance: after a valid request is identified, the serial port state detection module 520 outputs a high level, until the RTS line jumps back to low level, to ensure that the host unit 100 can stably capture the request state.

[0053] The power supply state detection module 530 is used to monitor the power supply state of the USB-A interface and the serial port . The voltage at the power supply end is collected by a voltage dividing resistor, compared with a preset voltage threshold, and the normality of the power supply is judged. As a further description of the embodiment, the power supply state detection module 530 of the embodiment monitors the power supply state by voltage division sampling and threshold comparison, and independently detects the power supply end of the USB-A interface and the serial port , respectively. The specific design is as follows: Sampling circuit: each power supply end (such as the 5V power supply of USB and the 3.3V power supply of the serial port) is connected in series with two voltage dividing resistors (the resistance ratio is determined according to the nominal voltage of the power supply and the input range of the sampling chip), and the power supply voltage is proportionally reduced to a safe sampling range (such as 0-3.3V). The sampling point is connected to the voltage comparator through a 10kΩ current limiting resistor. Threshold setting: the reference voltage end of the comparator is connected to a preset threshold (determined according to the allowable fluctuation range of the nominal voltage of the power supply, such as the normal threshold of the USB 5V power supply is set to 4.5-5.5V, and the corresponding comparison threshold after sampling is 3.0-3.6V). When the sampling voltage exceeds the threshold range, the comparator outputs high level (indicating abnormal power supply), and vice versa (indicating normal). Isolation design: the two detection branches are isolated by an optocoupler to avoid interference between different power supply domains and ensure the independence of the detection signal.

[0054] The state signal processing module 540 is used to convert the analog detection signals output by the USB state detection module 510, the serial port state detection module 520 and the power supply state detection module 530 into standard TTL digital levels (high level indicating abnormal state or request, low level indicating normal or no request), and transmit them to the host unit 100 through three independent pins. The signal transmission delay is less than the instruction generation period of the host unit 100.

[0055] As a further illustration of this embodiment, the status signal processing module 540 of this embodiment converts the outputs of the USB status detection module 510, the serial port status detection module 520, and the power supply status detection module 530 into standard TTL signals through level conversion and signal shaping, and transmits the signals to the main control unit 100. Specifically, the following steps are performed: Level conversion: Receives analog or quasi-digital signals output by the USB status detection module 510, serial port status detection module 520, and power supply status detection module 530, and converts them to 3.3VTTL level via a transistor inverter or a dedicated level conversion chip to ensure compatibility with the IO port level of the main control unit 100; Signal distribution: The three converted status signals (corresponding to USB access, serial port request, and power supply status) are transmitted through independent PCB traces. Each signal is connected in series with a 100Ω matching resistor and arranged close to the IO port of the main control unit 100 to reduce signal attenuation and crosstalk during transmission. Delay control: The total delay in signal conversion and transmission of the USB status detection module 510, the serial port status detection module 520, and the power supply status detection module 530 is achieved by shortening the circuit path and selecting high-speed conversion components, ensuring that the delay is less than the instruction generation cycle of the main control unit 100, thereby preventing the status signal lag from affecting the scheduling decision.

[0056] The power management unit 600 is used to provide stable power supply for the main control unit 100, the analog switch unit 200, the hierarchical protection unit 300, the protocol adaptation unit 400 and the status detection unit 500. Through the integrated voltage conversion circuit and the voltage stabilization circuit, it is connected to the external input power supply and performs multi-level voltage regulation to output a stable voltage that adapts to the working requirements.

[0057] Furthermore, the power management unit 600 is also equipped with a monitoring component, which samples the output voltage of each channel through resistor voltage division, compares it with the preset threshold value adapted to the normal range of each voltage through the voltage comparator, and feeds the monitoring result back to the main control unit 100 through the signal line. When the power supply is abnormal, it triggers basic protection logic such as suspending the power supply of non-essential units; the overall circuit adopts an independent PCB routing layout to reduce the interference of power supply noise on other units, thereby meeting the basic power supply stability requirements of the system.

[0058] Those skilled in the art will appreciate that the process of implementing all or part of the steps of the above embodiments may be accomplished by hardware, or by instructing related hardware through a program.

[0059] The above shows and describes the basic principles, main features and advantages of the present application. Those skilled in the art should understand that the present application is not limited to the above-mentioned embodiments, and the above-mentioned embodiments and descriptions in the specification are only preferred examples of the present application and are not intended to limit the present application. Various changes and improvements can be made to the present application without departing from the spirit and scope of the present application, and these changes and improvements all fall within the scope of the claimed present application. The scope of protection of the present application is defined by the appended claims and their equivalents.

Claims

1. USB-A interface and serial port dynamic switching and protection system based on analog switch, characterized by: include: The main control unit (100) is used to coordinate the dynamic switching and conflict coordination between the USB-A interface and the serial port, and integrates the dynamic priority scheduling algorithm, combined with the USB data transmission real-time load and serial port feedback of the status detection unit (500). The urgency of the communication request and the historical interaction record of the device are used to generate a conflict-free channel switching control instruction and drive the analog switch unit (200) to complete the channel gating; The analog switch unit (200) is used to establish a physical channel selection path between the USB-A interface and the serial port, and to switch the USB-A interface or the serial port through an analog switch circuit capable of switching the signal path. The signal is transmitted to the common interface, and the conduction state is switched according to the control instruction of the main control unit (100); A hierarchical protection unit (300) is used to implement multi-dimensional electrical protection of the USB-A interface, by connecting an overcurrent protection device in series to the USB-A interface power path, connecting an overvoltage suppression device in parallel to the power end, and connecting a high-frequency interference filter device across the signal path, thereby forming a coordinated protection mechanism for power and signal; A protocol adapter unit (400) is used to achieve dynamic compatibility between USB and serial port protocols, and completes signal format conversion by integrating a switchable protocol analysis circuit and loading signal encoding and decoding logic of the corresponding protocol based on instructions from the main control unit (100); The state detection unit (500) is used to collect the interface connection and operation status, and monitor the USB-A interface plug-in signal, serial port Communication request signal and power supply status signal, and converting the detection result into an electrical signal and transmitting it to the main control unit (100); A power management unit (600) is used to provide stable power supply to the main control unit (100), the analog switch unit (200), the hierarchical protection unit (300), the protocol adaptation unit (400) and the status detection unit (500), and is connected to an external input power supply and performs multi-stage voltage regulation through an integrated voltage conversion circuit and a voltage stabilization circuit to output a stable voltage adapted to working requirements.

2. The USB-A interface and serial port dynamic switching and protection system based on analog switch according to claim 1, characterized in that: The main control unit (100) comprises a parameter quantization module (110), a priority scheduling module (120) and an instruction output module (130), wherein: The parameter quantization module (110) is used to collect the USB real-time transmission parameters output by the state detection unit (500) and the serial port Request parameters and convert them into computable quantitative values; The priority scheduling module (120) uses a dynamic priority scheduling algorithm to schedule the quantified USB and serial ports. Parameters are used for priority calculation and conflict determination; The instruction output module (130) generates a channel switching control instruction that complies with the hardware interface specification of the analog switch unit (200) according to the priority scheduling result.

3. The USB-A interface and serial port dynamic switching and protection system based on analog switch according to claim 2, characterized in that: The parameter quantization module (110) includes a USB load quantization submodule (111) and a serial port emergency quantization submodule (112), wherein: The USB load quantization submodule (111) is used to generate a USB load quantization value , combined with the protocol nominal rate corresponding to the protocol type followed by the USB-A interface, based on the USB real-time transmission rate, the transmission load ratio is converted into ; The serial port emergency quantization submodule (112) is used to generate a serial port emergency quantization value , by parsing the serial port The emergency level identification bit in the request signal complies with industry standards, and the serial port Urgency is mapped to The higher the emergency level, the The larger the corresponding value.

4. The USB-A interface and serial port dynamic switching and protection system based on analog switch according to claim 3, characterized in that: The priority scheduling module (120) performs priority calculation and conflict determination using a dynamic priority scheduling algorithm, including the following steps: S120.

1. Obtain the USB load quantization value output by the parameter quantization module (110) and serial port emergency quantization value , combined with the preset USB load weight Serial port urgency weight , calculate USB interface and serial port Initial priority of S120.

2. Dynamically adjust the weight according to the continuous monitoring results of the status detection unit (500): If the USB transfer rate is detected to be consistent with the high load characteristics defined by its protocol type for N consecutive times, the and simultaneously reduce , after adjustment Do not exceed the maximum weight limit of hardware adaptation; If the serial port is detected M times in a row Send the highest emergency request that meets industry standards, then increase and simultaneously reduce , after adjustment Do not exceed the maximum weight limit of hardware adaptation; S120.

3. Calculating USB and Serial Ports If the priority difference is greater than or equal to the conflict threshold , then directly determine the high priority channel as the current selection channel; If the priority difference < , then the USB data frame interval obtained by calling the status detection unit (500) is consistent with the serial port Request timeout, give priority to channels that "need to complete the response before the timeout"; S120.4, real-time monitoring of USB load quantification value Serial port emergency quantization value If any quantized value exceeds its physical definition range, the current weight adjustment logic is frozen and the existing priority calculation method is maintained until the state detection unit (500) feeds back an abnormality release signal.

5. The USB-A interface and serial port dynamic switching and protection system based on analog switch according to claim 4, characterized in that: The analog switch unit (200) comprises a control interface module (210), a channel switching module (220) and a signal transmission module (230), wherein: The control interface module (210) is used to receive a channel switching control instruction output by the main control unit (100), and convert the 8-bit channel identifier, 8-bit switching delay parameter, and 8-bit CRC check code contained in the instruction into a control signal that conforms to the logic level of the analog switch circuit; The channel switching module (220) includes at least two independent single-pole double-throw switch circuits, one of which corresponds to the power supply and signal path of the USB-A interface, and the other corresponds to the serial port. The transmitting and receiving signal paths of the switch are switched to a conducting state through a control signal output by the control interface module (210); The signal transmission module (230) is used to connect the channel switching module (220) and the public interface, and the circuit impedance of the signal transmission module (230) matches the USB-A interface and the serial port. The characteristic impedance requirements are met to ensure signal transmission without reflection attenuation.

6. The USB-A interface and serial port dynamic switching and protection system based on analog switch according to claim 5, characterized in that: The channel switching module (220) includes a USB channel submodule (221), a serial port channel submodule (222) and an interlocking logic submodule (223), wherein: The USB channel submodule (221) uses 4 independent analog switches, the switch on-resistance meets the low-loss transmission requirements of USB differential signals, and the off-isolation resistance meets the signal isolation requirements between channels; The serial port channel submodule (222) uses a 2-way independent analog switch to support the serial port The level range specified by the protocol and the switching time meet the serial port Timing requirements corresponding to the communication rate; The interlock logic submodule (223) is used to prevent the USB channel from The channels are turned on simultaneously: when the control signal of the USB channel submodule (221) is detected to be in the on state, the control signal of the serial port channel submodule (222) is automatically locked to the off state; when the control signal of the serial port channel submodule (222) is detected to be in the on state, the control signal of the USB channel submodule (221) is automatically locked to the off state, and the interlock response time meets the timing constraint of the channel switching.

7. The USB-A interface and serial port dynamic switching and protection system based on analog switch according to claim 6, characterized in that: The signal transmission module (230) comprises an impedance matching submodule (231) and a signal filtering submodule (232), wherein: The impedance matching submodule (231) realizes impedance adjustment by connecting precision resistors in series, specifically including: connecting matching resistors in series on the D+ and D- signal lines of the USB channel, Connect matching resistors in series on the signal lines of the channels according to the protocol type to ensure that the impedance of each channel meets the characteristic impedance standards specified by its interface protocol. The signal filtering submodule (232) is used to connect a filtering capacitor between the D+ and D- signals of the USB channel and the ground, An RC low-pass filter circuit is connected in series on the signal path of the channel to suppress high-frequency interference signals and meet the signal integrity requirements of the interface protocol.

8. The USB-A interface and serial port dynamic switching and protection system based on analog switch according to claim 7, characterized in that: The hierarchical protection unit (300) comprises a power supply overcurrent protection module (310), a power supply overvoltage suppression module (320), a signal anti-interference filtering module (330) and a protection status linkage module (340), wherein: The power overcurrent protection module (310) is used to be connected in series to the power path of the USB-A interface, and matches the maximum power supply current of the interface specified by the USB protocol through a resettable fuse; when the current in the power path exceeds the rated threshold and the duration meets the USB power supply safety timing requirements, the fuse is automatically switched to a high-resistance state to cut off the current; after the current falls back below the rated threshold and maintains the safety reset timing, the fuse is automatically restored to a low-resistance conduction state; The power supply overvoltage suppression module (320) is used to be connected in parallel to the power supply end of the USB-A interface, with a TVS transient suppression diode as a core component. The response speed meets the transient overvoltage protection requirements of the USB power supply end, and the clamping voltage adapts to the safety threshold of the USB power supply nominal voltage. When a transient overvoltage occurs at the power supply end, the diode is quickly turned on to discharge the surge current. The signal anti-interference filtering module (330) is used to bridge the signal path of the USB-A interface, and adopts a combined structure of a common-mode inductor and a ceramic capacitor, wherein: the common-mode inductor is connected in series in the signal path, and the common-mode impedance characteristics are adapted to the high-frequency interference suppression requirements of USB signal transmission, and the ceramic capacitors are respectively bridged between each signal path and GND to suppress high-frequency differential-mode interference and common-mode interference in the signal path, ensuring that the signal complies with the signal integrity standard of the USB protocol; The protection state linkage module (340) is electrically connected to the power overcurrent protection module (310) and the power overvoltage suppression module (320), and monitors the on / off state of the power overcurrent protection module (310) through a current sampling circuit, and monitors the clamping state of the power overvoltage suppression module (320) through a voltage sampling circuit; and converts the on / off state and the clamping state into standard digital levels, and feeds back to the main control unit (100) via independent pins. After receiving the signal, the main control unit (100) suspends USB channel switching until the protection is released.

9. The USB-A interface and serial port dynamic switching and protection system based on analog switch according to claim 8, characterized in that: The protocol adaptation unit (400) comprises a protocol selection module (410), a USB protocol analysis module (420), a serial port protocol analysis module (430) and a signal format conversion module (440), wherein: The protocol selection module (410) is electrically connected to the main control unit (100) and is used to receive the protocol adaptation instruction output by the main control unit (100), and perform the following operations according to the protocol type identifier in the instruction: if the instruction is USB protocol adaptation, the USB protocol parsing module (420) is enabled and the power supply of the serial port protocol parsing module (430) is turned off; if the instruction is serial port If the protocol is adapted, the serial port protocol parsing module (430) is enabled and the power supply of the USB protocol parsing module (420) is turned off; The USB protocol parsing module (420) parses the original signal of the USB interface through a hardware circuit, loads the signal encoding logic and decoding logic corresponding to the USB2.0 and USB1.1 protocols, and converts the signal of the USB interface into a parallel signal that conforms to the data format of the main control unit (100); The serial port protocol parsing module (430) is used to load RS232 and RS485 serial ports. Frame structure parsing logic and baud rate adaptation logic corresponding to the protocol, identifying the serial port The start bit, data bit, check bit, and stop bit in the signal are adjusted according to the sampling clock cycle of the protocol. Convert serial signals into serial data frames; The signal format conversion module (440) is used to receive the parallel signal output by the USB protocol analysis module (420) and the serial data frame output by the serial port protocol analysis module (430), and uniformly convert them into an 8-bit data format recognizable by the main control unit (100), with the conversion delay not exceeding the channel switching time of the analog switch unit (200).

10. The USB-A interface and serial port dynamic switching and protection system based on analog switch according to claim 9, characterized in that: The state detection unit (500) comprises a USB state detection module (510), a serial port state detection module (520), a power supply state detection module (530) and a state signal processing module (540), wherein: The USB status detection module (510) is used to monitor the device access status of the USB-A interface and determine whether the USB device is inserted by detecting the voltage difference between the D+ and D- lines. The monitoring cycle is synchronized with the scheduling cycle of the main control unit (100); The serial port status detection module (520) is used to monitor the serial port status. The communication request status of the device is detected by detecting the level jump of the serial port request signal line to identify the request and record the duration of the request signal to filter out transient interference; The power supply status detection module (530) is used to monitor the USB-A interface and the serial port The power supply status is detected by collecting the voltage at the power supply end through the voltage divider resistor and comparing it with the preset voltage threshold to determine whether the power supply is normal; The status signal processing module (540) is used to convert the analog detection signals output by the USB status detection module (510), the serial port status detection module (520), and the power supply status detection module (530) into standard TTL digital levels, and transmit them to the main control unit (100) via three independent pins. The signal transmission delay is less than the instruction generation cycle of the main control unit (100).

Citation Information

Patent Citations

  • Method for switching communication equipment and USB with serial port

    CN108459982A

  • Universal serial bus (USB) type multifunctional interface and switching system

    CN117609127A

  • Protocol interface circuit switching method for data acquisition and transmission of unmanned ship

    CN120523768A

  • And analog switch supports switching of USB and serial port communication

    CN210605695U

  • Device for switching between communication modes

    US20160335212A1

Cited By

  • CAN bus wake-up device and CAN bus communication chip

    CN121356937A

  • Robot system high-speed signal converter and driving program

    CN121356938A

  • Simulation system and method

    CN122064339A