Method and apparatus for switching data paths based on USB roles

By dynamically switching the USB role, the adaptive selection between the Hub extension link and the bypass direct connection link is achieved, which solves the problems of long USB role switching time and signal degradation in the existing technology, and improves the switching efficiency and reliability of the vehicle system.

CN123115031APending Publication Date: 2026-11-17AUTOCHIPS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611355613.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-02
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In existing technologies, the single-USB dual-role device of the vehicle SoC needs to reinitialize the Hub chip when switching roles. The process is time-consuming and may cause connection interruption. Furthermore, the Hub chip is a critical single point of failure, resulting in insufficient system robustness and signal quality degradation in Device mode.

Method used

By acquiring the current USB role, the target data link is dynamically determined, and the data link selection module is controlled to disconnect non-target links and establish target links, thereby achieving adaptive switching between Hub extension links and bypass direct-connect links, reducing signal loss and improving switching efficiency.

Benefits of technology

In Host mode, it supports multiple interface expansion, while in Device mode, it reduces link nodes and signal loss, improves USB role switching efficiency and system reliability, and avoids connection interruptions caused by Hub chip malfunctions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123115031A_ABST
    Figure CN123115031A_ABST
Patent Text Reader

Abstract

This application relates to the field of computer technology, providing a method and apparatus for switching data paths based on USB roles. The method involves obtaining the current USB role, which is either Host mode or Device mode; determining a target data link and a non-target data link based on the current USB role; the target data link being one of a Hub extension link and a bypass direct link, and the non-target data link being the other of the same; and controlling a first data link selection module and a second data link selection module to disconnect the non-target data link and establish the target data link. Applying this technical solution can improve the efficiency of USB role switching.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method and apparatus for switching data paths based on USB roles. Background Technology

[0002] In intelligent cockpit systems, in-vehicle infotainment (IVI) systems need to support multiple Universal Serial Bus (USB) functional modes simultaneously. For example, when the vehicle is started, it can connect to a mobile phone in Device mode via USB interface to run the manufacturer's system functions, while switching to Host mode to connect peripherals such as USB flash drives and cameras when the vehicle is parked or in motion.

[0003] In existing technologies, for scenarios where a system-on-chip (SoC) dual-role device (DRD) controller needs to support both host and device modes simultaneously, a hub topology is often added between the SoC and the USB connector to expand multiple USB interfaces.

[0004] However, while the above solution can support multiple peripheral connections, the Hub chip needs to be reinitialized when switching roles, which takes a long time. Summary of the Invention

[0005] This application provides a method and apparatus for switching data paths based on USB roles, which improves the efficiency of USB role switching.

[0006] In a first aspect, embodiments of this application provide a method for switching data paths based on USB roles, including:

[0007] Obtain the current USB role, which is either Host mode or Device mode;

[0008] Based on the current USB role, a target data link and a non-target data link are determined. The target data link is one of a Hub extension link and a bypass direct link, and the non-target data link is the other of the Hub extension link and the bypass direct link. The Hub extension link and the bypass direct link are parallel links respectively set between the USB connector and the USB DRD controller. A Hub chip is connected in series on the Hub extension link. A first data link selection module is set on the USB DRD controller side, and a second data link selection module is set on the USB connector side. The first data link selection module and the second data link selection module are used to select to connect to the Hub extension link or the bypass direct link.

[0009] Control the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link.

[0010] In one or more embodiments, determining the target data link and non-target data link based on the current USB role includes:

[0011] If the current USB role is in Host mode, the target data link is determined to be the Hub extended link, and the non-target data link is the bypass direct connection link;

[0012] If the current USB role is Device mode, the target data link is determined to be the bypass direct link, and the non-target data link is the Hub extension link.

[0013] In one or more embodiments, controlling the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link includes:

[0014] If the target data link is the Hub extension link, control the first data link selection module to switch to the Hub extension link, enable the power supply of the Hub chip, and control the second data link selection module to switch to the Hub extension link after the Hub chip initialization is completed.

[0015] If the target data link is the bypass direct link, turn off the power to the Hub chip and control the first data link selection module and the second data link selection module to switch to the bypass direct link.

[0016] In one or more embodiments, the method further includes:

[0017] Control the output state of the VBUS pin of the USB connector according to the current USB role;

[0018] Specifically, if the current USB role is Host mode, the voltage output of the VBUS pin is enabled; if the current USB role is Device mode, the voltage output of the VBUS pin is disabled.

[0019] In one or more embodiments, controlling the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link includes:

[0020] The state machine of the link control controls the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link.

[0021] The state machine includes: IDLE state, PREPARE state, SWITCH state, LINK_READY state and ENUM state, and in the Host mode it also includes VBUS_ON state;

[0022] After acquiring the current USB role, the state machine sequentially transitions from the IDLE state to the PREPARE state, the SWITCH state, and the LINK_READY state. In Host mode, after the LINK_READY state, it further transitions to the VBUS_ON state, and finally to the ENUM state.

[0023] In one or more embodiments, the state machine further includes a RECOVERING state;

[0024] Accordingly, the method further includes:

[0025] If an abnormality is detected in the target data link during its establishment or operation, the state machine transitions to the RECOVERING state and shuts down the target data link.

[0026] Reacquire the current USB role and establish a new target data link based on the reacquired current USB role;

[0027] If multiple attempts to establish a new target data link fail, and the current USB role is in Host mode, the bypass direct connection is maintained as a security degradation state; if the current USB role is in Device mode, a link failure is reported and the system waits for a USB role switch or reset.

[0028] In one or more embodiments, the method further includes:

[0029] Periodic health monitoring is performed on the established target data link, including: Hub chip initialization status detection and / or signal integrity detection;

[0030] If the target data link is a Hub extension link and an abnormality is detected in the Hub chip, disconnect the Hub extension link and establish the bypass direct link, record the Hub abnormality event and periodically re-detect the Hub chip status, and disconnect the bypass direct link and re-establish the Hub extension link after the Hub chip returns to normal.

[0031] If the target data link is a bypass direct link and an abnormal signal integrity is detected, attempt to re-establish the bypass direct link. If the bypass direct link remains abnormal and the Hub chip is in normal condition, disconnect the bypass direct link and establish the Hub extended link.

[0032] Secondly, embodiments of this application provide a data path switching device based on USB roles, comprising:

[0033] The acquisition module is used to acquire the current USB role, which is either Host mode or Device mode;

[0034] The determination module is used to determine a target data link and a non-target data link based on the current USB role. The target data link is one of a Hub extension link and a bypass direct link, and the non-target data link is the other of the Hub extension link and the bypass direct link. The Hub extension link and the bypass direct link are parallel links respectively set between the USB connector and the USB DRD controller. A Hub chip is connected in series on the Hub extension link. A first data link selection module is set on the USB DRD controller side, and a second data link selection module is set on the USB connector side. The first data link selection module and the second data link selection module are used to select to connect to the Hub extension link or the bypass direct link.

[0035] The control module is used to control the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link.

[0036] In one or more embodiments, the determining module determines the target data link and non-target data link based on the current USB role, specifically for:

[0037] If the current USB role is in Host mode, the target data link is determined to be the Hub extended link, and the non-target data link is the bypass direct connection link;

[0038] If the current USB role is Device mode, the target data link is determined to be the bypass direct link, and the non-target data link is the Hub extension link.

[0039] In one or more embodiments, the control module controls the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link, specifically for:

[0040] If the target data link is the Hub extension link, control the first data link selection module to switch to the Hub extension link, enable the power supply of the Hub chip, and control the second data link selection module to switch to the Hub extension link after the Hub chip initialization is completed.

[0041] If the target data link is the bypass direct link, turn off the power to the Hub chip and control the first data link selection module and the second data link selection module to switch to the bypass direct link.

[0042] In one or more embodiments, the control module is further configured to:

[0043] Control the output state of the VBUS pin of the USB connector according to the current USB role;

[0044] Specifically, if the current USB role is Host mode, the voltage output of the VBUS pin is enabled; if the current USB role is Device mode, the voltage output of the VBUS pin is disabled.

[0045] In one or more embodiments, the control module controls the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link, specifically for:

[0046] The state machine of the link control controls the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link.

[0047] The state machine includes: IDLE state, PREPARE state, SWITCH state, LINK_READY state and ENUM state, and in the Host mode it also includes VBUS_ON state;

[0048] After acquiring the current USB role, the state machine sequentially transitions from the IDLE state to the PREPARE state, the SWITCH state, and the LINK_READY state. In Host mode, after the LINK_READY state, it further transitions to the VBUS_ON state, and finally to the ENUM state.

[0049] In one or more embodiments, the state machine further includes a RECOVERING state;

[0050] Accordingly, the control module is also used for:

[0051] If an abnormality is detected in the target data link during its establishment or operation, the state machine transitions to the RECOVERING state and shuts down the target data link.

[0052] Reacquire the current USB role and establish a new target data link based on the reacquired current USB role;

[0053] If multiple attempts to establish a new target data link fail, and the current USB role is in Host mode, the bypass direct connection is maintained as a security degradation state; if the current USB role is in Device mode, a link failure is reported and the system waits for a USB role switch or reset.

[0054] In one or more embodiments, the control module is further configured to:

[0055] Periodic health monitoring is performed on the established target data link, including: Hub chip initialization status detection and / or signal integrity detection;

[0056] If the target data link is a Hub extension link and an abnormality is detected in the Hub chip, disconnect the Hub extension link and establish the bypass direct link, record the Hub abnormality event and periodically re-detect the Hub chip status, and disconnect the bypass direct link and re-establish the Hub extension link after the Hub chip returns to normal.

[0057] If the target data link is a bypass direct link and an abnormal signal integrity is detected, attempt to re-establish the bypass direct link. If the bypass direct link remains abnormal and the Hub chip is in normal condition, disconnect the bypass direct link and establish the Hub extended link.

[0058] Thirdly, embodiments of this application provide an electronic device, including: a memory and a processor;

[0059] The memory stores computer-executed instructions;

[0060] The processor executes computer execution instructions stored in the memory, causing the processor to perform the first aspect and / or various possible implementations of the first aspect as described above.

[0061] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the first aspect and / or various possible implementations of the first aspect.

[0062] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the first aspect and / or various possible implementations of the first aspect.

[0063] The present application provides a method and apparatus for switching data paths based on USB roles. The method obtains the current USB role, which is either Host mode or Device mode. Based on the current USB role, it determines a target data link and a non-target data link. The target data link is one of a Hub extension link and a bypass direct link, and the non-target data link is the other of the same two links. The Hub extension link and the bypass direct link are parallel links connected between the USB connector and the USB DRD controller, respectively. A Hub chip is connected in series on the Hub extension link. A first data link selection module is provided on the USB DRD controller side, and a second data link selection module is provided on the USB connector side. The first and second data link selection modules are used to select whether to connect to the Hub extension link or the bypass direct link. The method controls the first and second data link selection modules to disconnect the non-target data link and establish the target data link. In this technical solution, the current USB role is first obtained, and the target data link and non-target data link are determined based on the current USB role. Then, the first data link selection module set on the USB DRD controller side and the second data link selection module set on the USB connector side are controlled to disconnect the non-target data link and establish the target data link. Thus, in Host mode, the data link extended by the Hub is selected to support multi-interface expansion, and in Device mode, the direct data link bypassing the Hub is selected to reduce link nodes and signal loss. This achieves optimal data path selection based on USB role, eliminates unnecessary signal degradation links in Device mode from the root, and improves link switching efficiency. Attached Figure Description

[0064] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0065] Figure 1 A schematic diagram of the structure of the USB role-based data path switching system provided in this application;

[0066] Figure 2 A flowchart illustrating the USB role-based data path switching method provided in this application. Figure 1 ;

[0067] Figure 3 A flowchart illustrating the USB role-based data path switching method provided in this application. Figure 2 ;

[0068] Figure 4 A schematic diagram of the USB data link linkage control state machine provided in this application;

[0069] Figure 5 This is the Host mode state sequence diagram provided in this application;

[0070] Figure 6 The Device mode state timing diagram provided in this application;

[0071] Figure 7 A flowchart illustrating the USB role-based data path switching method provided in this application. Figure 3 ;

[0072] Figure 8 A schematic diagram of the structure of the USB role-based data path switching device provided in this application;

[0073] Figure 9 A schematic diagram of the structure of the electronic device provided in this application.

[0074] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0075] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0076] In a smart cockpit system, the IVI (Internet Vision) needs to support multiple USB function modes simultaneously. For example, when the vehicle is started, the IVI can connect to a mobile phone in Device mode via USB interface to run the manufacturer's system functions. At the same time, when the vehicle is parked or in motion, it needs to switch to Host mode to connect to peripherals such as USB flash drives and cameras.

[0077] Due to pin resource and cost limitations of automotive SoC chips, only one USB DRD controller is typically integrated.

[0078] In existing technologies, the following technical solutions are often adopted:

[0079] (1) Direct USB Hub Expansion Interface Solution: The Host and Device share the Hub data path, which is the most common implementation method in current automotive systems. This solution adds a Hub topology between the SoC and the USB connector, and expands multiple USB interfaces through the Hub's downlink port.

[0080] (2) Using a separate USB controller: Some high-end platforms use two separate USB controllers to support Host and Device modes respectively. One controller is dedicated to Host peripheral expansion, and the other is dedicated to Device mode connection. However, this solution requires additional chip pins and PHY resources, which is costly.

[0081] (3) Using a simple USB MUX for physical path switching: Some solutions use a USB MUX switch to perform a simple two-to-one switching between Host and Device paths, but the MUX can only switch signal paths and cannot support the multi-interface expansion requirements in Host mode.

[0082] In other words, the following problems often exist in the above process:

[0083] 1) Device mode signal path is not optimal:

[0084] In existing solutions, regardless of whether the current USB role is Host or Device, USB data signals must pass through the Hub chip. When the role is Device, this design that forces forwarding through the Hub introduces an unnecessary USB topology. As a primary active repeater, the Hub inevitably introduces impedance discontinuities and signal reflections, leading to high-frequency signal attenuation. In high-speed USB mode, the eye diagram quality is significantly reduced, affecting the connection stability of Device mode applications.

[0085] 2) Lack of link-level dynamic reconfiguration capabilities:

[0086] The existing hardware connection is static, and the role switching depends on the software reset and re-enumeration of the Hub. The switching process is not an atomic operation at the link layer, which takes a long time and may cause connection interruption.

[0087] 3) Insufficient system robustness:

[0088] In the existing solution, the Hub becomes a critical single point of failure, and there is no backup path. When the Hub chip malfunctions, it cannot automatically switch to the backup data path, causing both Host and Device modes to fail simultaneously.

[0089] 4) Inefficient role switching:

[0090] Switching from Device mode to Host mode requires a power-on reset to initialize the Hub chip, configure the Hub registers, and wait for the Hub to become ready. This process typically takes tens to hundreds of milliseconds. During this time, the USB link is unavailable, and if Hub initialization fails, the entire USB subsystem will be unrecoverable.

[0091] 5) Poor energy efficiency:

[0092] In existing solutions, even if the current role is Device and the Hub function is not required, the Hub chip is still enabled, consuming static current and dynamic power consumption, which affects the system energy efficiency in battery-powered vehicle scenarios.

[0093] To address the technical problems existing in the prior art, the inventors of this application propose the following: In the prior art, the USB data path adopts a fixed topology that forwards data via a hub, and it is impossible to dynamically adjust the data path according to the USB role. If a dynamic data link reconfiguration method based on USB Role awareness can be constructed, in a single USB DRD controller scenario, the target data link can be dynamically determined according to the detected USB role (Host or Device). In Host mode, a data link extended via a hub is selected to support multi-interface expansion, and in Device mode, a direct data link bypassing the hub is selected to reduce link nodes. This would solve the above-mentioned technical problems and achieve adaptive optimal selection of the data link.

[0094] and then, Figure 1 A schematic diagram of the structure of the USB role-based data path switching system provided in this application is shown below. Figure 1 As shown, the system includes: a USB DRD controller, a first data link selection module, a hub chip, a second data link selection module, a USB connector, a link control module, a hub power control module, and a VBUS control module.

[0095] The USB DRD controller is a dual-role USB controller that can operate in either Host or Device mode. One end of the first data link selection module is connected to the USB DRD controller, and the other end is connected to both the first end of the Hub expansion link and the first end of the bypass direct connection link. One end of the second data link selection module is connected to the USB connector, and the other end is connected to both the second end of the Hub expansion link and the second end of the bypass direct connection link. The Hub expansion link and the bypass direct connection link are two parallel data links connected between the USB DRD controller and the USB connector. The Hub expansion link has a Hub chip connected in series, while the bypass direct connection link connects directly without passing through the Hub chip.

[0096] As the implementing entity of this application, the link control module is connected to the first data link selection module, the second data link selection module, the hub power control module, and the VBUS control module, respectively. It outputs link switching control signals, hub power control signals, and VBUS control signals according to the current USB role. The hub power control module is connected to the hub chip and controls the power enable and disable of the hub chip. The VBUS control module is connected to the VBUS pin of the USB connector and controls the voltage output of the VBUS pin.

[0097] In addition, the switching system also includes a Role detection module, which can be connected to the CC / ID pin of the USB connector.

[0098] In other words, the current USB role can be detected by the Role detection module.

[0099] As an example, in Host mode, the data path is:

[0100] USB DRD controller → First data link selection module → Hub extension link → Hub chip → Second data link selection module → USB connector. At this time, the Hub extension link is the target data link in the following embodiments, and the bypass direct-connect link is a non-target data link in the following embodiments and is disconnected; the Hub power control module enables the power supply of the Hub chip, and the VBUS control module enables the voltage output of the VBUS pin to power the external USB device.

[0101] As another example, in Device mode, the data path is:

[0102] USB DRD controller → First data link selection module → Bypass direct link → Second data link selection module → USB connector. At this time, the bypass direct link is the target data link, and the Hub extension link is a non-target data link and is disconnected; the Hub power control module turns off the power supply of the Hub chip to reduce power consumption, and the VBUS control module turns off the voltage output of the VBUS pin, with VBUS provided by the external Host device.

[0103] Furthermore, this application protects the following innovative aspects:

[0104] Innovation 1: Dynamic reconfiguration of data links based on USB Role: Dynamically determine the target data link, control the link status, close non-target data links, and establish the target data link based on the detected USB role (Host or Device).

[0105] Correspondingly, if multi-port expansion is not required in Host mode and only signal relay enhancement is needed, the active components on the Hub extension link can be replaced with Redriver (signal re-drive chip) or Repeater (signal relay chip). In this case, Host mode only supports single device connection, but a longer signal transmission distance can be obtained. The functions of the first data link selection module and the second data link selection module can be implemented by devices such as analog switches, USB dedicated signal switches, or Crossbar (cross matrix switch). The Crossbar solution is suitable for expansion scenarios that require more than two data links.

[0106] Innovation 2: Automatic bypass of the hub in Device mode for optimal data path selection: This is not a simple bypass operation, but rather automatically selects the optimal data path based on the role: In Device mode, it automatically identifies the direct connection path as the optimal path, bypassing the hub to reduce link nodes and signal loss; in Host mode, it automatically identifies the path extended via the hub as the optimal path, supporting multi-interface expansion. This optimizes the fixed topology forced through the hub into a role-adaptive optimal topology.

[0107] Innovation 3: USB Data Link Interlocking Control State Machine: Defines the link control states, and the state transition rules strictly define the entire process from role detection to link establishment. The state machine covers the interlocking control of data link selection, hub power control, and VBUS.

[0108] Innovation 4: Dynamic Optimal Data Path Selection and Fault Fallback: In addition to selecting data paths based on the role, a link health monitoring mechanism is established: In Host mode, when the Hub fails, it automatically falls back to the Bypass path as a safety degradation, switching back to the Hub extended link after the Hub recovers; in Device mode, when the Bypass fails, it automatically retryes rebuilding the Bypass path, reporting the link failure after multiple failures. This elevates simple switching to path optimization and fault-tolerant recovery algorithms, achieving adaptive optimal selection of data links and improving system reliability.

[0109] Innovation 5: A single USB DRD controller enables multiple logical USB interfaces: Through dynamic reconfiguration of the data link, a single USB DRD controller can be extended into multiple USB Host interfaces in Host mode via Hub expansion, and directly connected as a Device interface via Bypass in Device mode. This achieves multiple logical interfaces reused by the same physical controller without the need for additional USB PHY resources.

[0110] The above list of system embodiments and innovations is only a brief introduction to the solutions involved in this application. The following detailed description uses specific embodiments to illustrate the technical solutions of this application and how these solutions solve the aforementioned technical problems. The implementing entity of this technical solution is an electronic device, namely the link control module mentioned above.

[0111] The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.

[0112] Figure 2 A flowchart illustrating the USB role-based data path switching method provided in this application. Figure 1 ,like Figure 2 As shown, the method includes:

[0113] Step 21: Obtain the current USB role;

[0114] The current USB role is either Host mode or Device mode;

[0115] In this step, in order to determine which data link should be selected to match the device corresponding to the inserted USB connector, it is necessary to first obtain the current USB role of the device.

[0116] The current USB role can be detected by the Role detection module. For example, the current USB role can be determined as Host mode or Device mode based on changes in the ID pin state, CC pin configuration, or software configuration.

[0117] Optionally, the Role detection module can monitor changes in USB roles in real time, and when a role switching request is detected, it will pass the relevant information of the current USB role to the link control module.

[0118] In addition, if the Role detection module has not yet determined the current USB role, then the current data link state remains unchanged, or the default bypass direct link connection is maintained, and step 22 is executed after the role is determined.

[0119] Step 22: Determine the target data link and non-target data links based on the current USB role;

[0120] Among them, the target data link is one of the Hub extension link and the bypass direct link, and the non-target data link is the other of the Hub extension link and the bypass direct link;

[0121] In this step, after obtaining the current USB role, the data link that should be established is determined based on the current USB role, denoted as the target data link, and the data link that should be disconnected is denoted as the non-target data link.

[0122] Optionally, the implementation of step 22 may include any of the following:

[0123] Item 1: If the current USB role is in Host mode, determine the target data link as the Hub extension link and the non-target data link as the bypass direct link.

[0124] In this implementation, in Host mode, multiple USB interfaces need to be expanded through the Hub chip to support the connection of various peripherals. Therefore, the data link expanded through the Hub can be selected as the target data link.

[0125] Item 2: If the current USB role is Device mode, determine that the target data link is a bypass direct link and the non-target data link is a Hub extension link.

[0126] In this implementation, in Device mode, the extension function of the Hub is not required. The bypass direct link can provide the shortest signal path and avoid the signal degradation introduced by the Hub as an active repeater. Therefore, the bypass direct link can be selected as the target data link.

[0127] Step 23: Control the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link.

[0128] In this step, after determining the target data link and the non-target data link, control signals are sent to the first data link selection module and the second data link selection module to control the two selection modules to disconnect the non-target data link and establish the target data link.

[0129] The switching timing of the first data link selection module and the second data link selection module is determined according to the type of the target data link: if the target data link is a Hub extension link, the two selection modules switch in stages; if the target data link is a bypass direct link, the two selection modules can switch simultaneously.

[0130] Since the first data link selection module is located on the USB DRD controller side and the second data link selection module is located on the USB connector side, the coordinated action of the two selection modules can ensure that during the link switching process, both the USB DRD controller side and the USB connector side switch to the target data link simultaneously, and there will be no link inconsistency or signal conflict caused by unilateral switching.

[0131] Optionally, the implementation of step 23 may include:

[0132] Item 1: If the target data link is a Hub extension link, control the first data link selection module to switch to the Hub extension link, enable the power supply of the Hub chip, and control the second data link selection module to switch to the Hub extension link after the Hub chip initialization is completed.

[0133] In this implementation, if the target data link is a Hub extension link (i.e., the current USB role is Host mode), the following steps are executed in order:

[0134] (1) Control the first data link selection module to switch to the Hub extended link direction, and connect the USBDRD controller to the upstream port of the Hub chip;

[0135] (2) Enable the power supply of the Hub chip. The Hub chip starts power-on initialization. The USBDRD controller, as the Host, detects the Hub chip and completes enumeration.

[0136] (3) After the Hub chip is initialized, control the second data link selection module to switch to the Hub extension link direction, connect the downstream port of the Hub chip to the USB connector, and establish a data path extended by the Hub.

[0137] Since multiple USB ports need to be expanded through the Hub chip in Host mode, connecting the upstream port of the Hub to the Host first and then enabling the Hub power ensures that the Hub can be enumerated by the upstream Host immediately after power-on initialization, shortening the waiting time from Hub readiness to recognition, and avoiding the Hub entering an uncertain state of downstream port floating when the upstream is not connected; connecting the downstream port of the Hub to the USB connector after the Hub initialization is completed can prevent downstream external devices from being falsely detected before the Hub is ready.

[0138] Item 2: If the target data link is a bypass direct link, turn off the power of the Hub chip and control the first data link selection module and the second data link selection module to switch to the bypass direct link.

[0139] If the target data link is a bypass direct link (i.e., the current USB role is Device mode), execute in the following order:

[0140] (1) Turn off the power to the Hub chip. The Hub chip will stop working when powered off. Since the Hub's extended functions are not required in Device mode, turning off the power to the Hub chip can eliminate the static current and dynamic power consumption of the Hub chip in non-essential working states, thereby optimizing system-level power consumption in battery-powered vehicle scenarios;

[0141] (2) Control the first data link selection module and the second data link selection module to switch to the bypass direct link direction to establish the direct data path of the bypass Hub.

[0142] Since the bypass direct link in Device mode does not pass through the Hub chip, turning off the Hub power before switching the link ensures that the Hub chip is powered off before the bypass link is established. This avoids interference from the Hub chip to the bypass signal and reduces system power consumption.

[0143] Furthermore, the method may also include controlling the output state of the VBUS pin of the USB connector according to the current USB role.

[0144] Specifically, if the current USB role is Host mode, the voltage output of the VBUS pin is enabled; if the current USB role is Device mode, the voltage output of the VBUS pin is disabled.

[0145] In this implementation, the Voltage Bus (VBUS) is the power pin in the USB interface. In the USB specification, the host device needs to supply power to the connected device through VBUS, while the device does not need to output voltage through VBUS (VBUS is provided by the external host).

[0146] Therefore, after determining the current USB role, the output state of the VBUS pins of the USB connector is controlled by the VBUS control module:

[0147] If the current USB role is Host mode, enable the voltage output of the VBUS pin to provide power to the connected external USB device (such as a USB flash drive, camera, etc.); if the current USB role is Device mode, disable the voltage output of the VBUS pin. In this case, the external Host device supplies power to this device through VBUS, avoiding conflicts between the VBUS output of this device and the VBUS output of the external Host.

[0148] Furthermore, the method may also include (steps 2 and 3 can be performed based on the actual situation):

[0149] Step 1: Perform periodic health monitoring on the established target data link. Health monitoring includes: Hub chip initialization status detection and / or signal integrity detection.

[0150] In this implementation, the link health monitoring module performs periodic health monitoring on the established target data link during normal operation of the data link (e.g., ENUM state) to ensure the continuous reliability of the link.

[0151] The health monitoring includes at least one of the following: Hub chip initialization status detection and signal integrity detection.

[0152] Correspondingly, Hub chip initialization status detection is used to monitor whether the Hub chip is operating normally, such as whether the Hub chip's register read / write is normal, and whether the Hub chip's downlink ports are working properly. Signal integrity detection is used to monitor whether the signal quality of the data link meets the requirements, such as detecting the eye diagram quality and bit error rate of the USB signal.

[0153] Step 2: If the target data link is a Hub extension link and a Hub chip abnormality is detected, disconnect the Hub extension link and establish a bypass direct link. Record Hub abnormal events and periodically re-check the Hub chip status. After the Hub chip returns to normal, disconnect the bypass direct link and re-establish the Hub extension link.

[0154] In this implementation, when the target data link is a Hub extension link (i.e., currently operating in Host mode) and a Hub chip malfunction is detected, the following processing is performed:

[0155] 1. Disconnect the Hub expansion link and establish a bypass direct link: The link control module controls the first data link selection module and the second data link selection module to switch from the Hub expansion link to the bypass direct link, while simultaneously turning off the power to the Hub chip. At this time, although the multi-interface expansion capability is lost in Host mode, at least one usable data path is retained.

[0156] 2. Record Hub Abnormal Events: Record information such as the time and type of Hub chip abnormality in the system log to facilitate subsequent fault analysis and diagnosis.

[0157] 3. Periodically re-check the status of the Hub chip: During the operation of the bypass direct link, the link health monitoring module periodically re-checks the status of the Hub chip to determine whether the Hub chip has returned to normal.

[0158] 4. After the Hub chip returns to normal, disconnect the bypass direct connection link and re-establish the Hub expansion link: When the Hub chip is detected to have returned to normal, the link control module controls the first data link selection module and the second data link selection module to switch from the bypass direct connection link back to the Hub expansion link, and at the same time enables the power supply of the Hub chip to restore the multi-interface expansion capability in Host mode.

[0159] Step 3: If the target data link is a bypass direct link and an abnormal signal integrity is detected, attempt to re-establish the bypass direct link; if multiple attempts to re-establish the bypass direct link fail, report the link failure and wait for the USB role to switch or reset.

[0160] In this implementation, when the target data link is a bypass direct link (i.e., currently operating in Device mode) and a signal integrity anomaly is detected, the following processing is performed:

[0161] 1. Attempt to re-establish the bypass direct link: The link control module first attempts to re-establish the bypass direct link.

[0162] 2. If the bypass direct link continues to malfunction, report a link fault: Since the upstream and downstream ports of the USB Hub chip are fixed, in Device mode, the external Host needs to be connected to the upstream port of the Hub, and this device needs to be connected to the downstream port of the Hub. The upstream of the Hub is fixed to the USB DRD controller side, and the downstream is fixed to the USB connector side, which cannot be used in reverse. Therefore, the bypass direct link is the usable data path in Device mode. If multiple attempts to rebuild the bypass direct link fail, the link control module reports a link fault and waits for the USB role to switch or the system to reset before re-establishing the link.

[0163] The data path switching method based on USB role provided in this application involves obtaining the current USB role, which is either Host mode or Device mode; determining the target data link and non-target data link based on the current USB role; the target data link is one of a Hub extension link and a bypass direct link, and the non-target data link is the other of the Hub extension link and the bypass direct link. The Hub extension link and the bypass direct link are parallel links set between the USB connector and the USB DRD controller, respectively, and a Hub chip is connected in series on the Hub extension link; a first data link selection module is provided on the USB DRD controller side, and a second data link selection module is provided on the USB connector side. The first data link selection module and the second data link selection module are used to select whether to connect to the Hub extension link or the bypass direct link; controlling the first data link selection module and the second data link selection module disconnects the non-target data link and establishes the target data link. In this technical solution, the current USB role is first obtained, and the target data link and non-target data link are determined based on the current USB role. Then, the first data link selection module set on the USB DRD controller side and the second data link selection module set on the USB connector side are controlled to disconnect the non-target data link and establish the target data link. Thus, in Host mode, the data link extended by the Hub is selected to support multi-interface expansion, and in Device mode, the direct data link bypassing the Hub is selected to reduce link nodes and signal loss. This achieves optimal data path selection based on USB role, eliminates unnecessary signal degradation links in Device mode from the root, and improves link switching efficiency.

[0164] Based on the above embodiments, Figure 3 A flowchart illustrating the USB role-based data path switching method provided in this application. Figure 2 ,like Figure 3 As shown, step 23 may include:

[0165] Step 31: Through the state machine of link control, control the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link;

[0166] The state machine includes: Idle state, Prepare state, Switch state, Link Ready state, and Enumeration Complete state. In Host mode, it also includes: VBUS ON state.

[0167] For example, the IDLE state is the initial state after power-on, waiting for the USB role detection result; the PREPARE state indicates that the current USB role has been obtained, and preparation for link switching has begun, closing non-target data links; the SWITCH state executes the switching action of the first data link selection module and the second data link selection module, and controls the Hub power supply accordingly; the LINK_READY state indicates that the physical data link is connected and the target link has been established; the VBUS_ON state is only present in Host mode, VBUS power is enabled, and power is supplied to peripherals; the ENUM state indicates that USB enumeration is complete and the link enters normal working state.

[0168] In addition, the state machine also includes a recovery state, which is triggered when an anomaly is detected during link establishment or operation, and the process enters the anomaly recovery procedure.

[0169] Correspondingly, after acquiring the current USB role, the state machine sequentially transitions from the IDLE state to the PREPARE state, SWITCH state, and LINK_READY state; in Host mode, it further transitions to the VBUS_ON state after the LINK_READY state, and finally to the ENUM state.

[0170] As an example, Figure 4 A schematic diagram of the USB data link linkage control state machine provided in this application is shown below. Figure 4 As shown, the state machine includes the following states: IDLE, PREPARE, SWITCH, LINK_READY, VBUS_ON, ENUM, and RECOVERING.

[0171] The state transition rules are as follows: Host mode transition sequence: IDLE→PREPARE→SWITCH→LINK_READY→VBUS_ON→ENUM; Device mode transition sequence: IDLE→PREPARE→SWITCH→LINK_READY→ENUM (no VBUS_ON state).

[0172] In addition, abnormal transition: In the LINK_READY, VBUS_ON or ENUM states, if the link health monitoring module detects an abnormality in the target data link, the state machine transitions to the RECOVERING state, closes the current abnormal link, re-detects the USB role and attempts to rebuild the target link; if multiple reconstructions fail, in Host mode, the bypass direct connection link is kept connected as a safety degradation state, and in Device mode, the link fault is reported and the USB role is waited for switching or reset.

[0173] Optionally, each state of the above state machine can be described:

[0174] 1) IDLE State: The initial state of the state machine, indicating that there is currently no ongoing link establishment or switching operation. When the Role detection module detects the current USB role or a role switching request, the state machine transitions from the IDLE state to the PREPARE state. After power-on initialization, the state machine defaults to the IDLE state.

[0175] 2) PREPARE State: In this state, the link control module determines the target data link and non-target data links based on the current USB role and performs preparation operations, including shutting down non-target data links and controlling the power state of the hub chip according to the target data link type. After the preparation operations are completed, the state machine transitions from the PREPARE state to the SWITCH state.

[0176] 3) SWITCH State: In this state, the link control module controls the first data link selection module and the second data link selection module to switch to the target data link direction, establishing a physical connection to the target data link. After the link switch is completed, the state machine transitions from the SWITCH state to the LINK_READY state.

[0177] 4) LINK_READY state: In this state, it indicates that the physical connection of the target data link has been established and the link is ready. At this time, the subsequent transition path of the state machine varies depending on the current USB role:

[0178] If the current USB role is Host mode, the state machine transitions from the LINK_READY state to the VBUS_ON state; if the current USB role is Device mode, the state machine transitions directly from the LINK_READY state to the ENUM state.

[0179] 5) VBUS_ON state: This state exists only in Host mode. In this state, the link control module enables the voltage output of the VBUS pin of the USB connector through the VBUS control module to power the connected external USB device. After the power supply stabilizes, the state machine transitions from the VBUS_ON state to the ENUM state.

[0180] 6) ENUM State: In this state, it indicates that the USB enumeration process has been completed and the data link has entered normal working condition. In Host mode, the external USB device has completed enumeration and can perform data transfer; in Device mode, this device, acting as a USB Device, has completed enumeration and can perform data transfer with the external Host.

[0181] For example, Figure 5The Host mode state sequence diagram provided in this application is as follows: Figure 5 As shown, the timing relationships between signals and states in Host mode are as follows:

[0182] 1) During the T1 period: The Role Detect signal is valid (a Host role request is detected, such as a change in the ID pin state or software configuration). After a delay of T1, the state machine transitions from the IDLE state to the PREPARE state.

[0183] 2) T2 period: After entering the PREPARE state, after a delay of T2, the state machine enters the SWITCH state, and the first data link selection module completes the switch to the Hub extended link direction;

[0184] 3) T3 period: After entering the SWITCH state, after a delay of T3, the Hub power enable signal becomes valid, and the Hub chip begins power-on initialization;

[0185] 4) T4 period: After the Hub is initialized, after a delay of T4, the second data link selection module switches to the Hub extended link direction, and the state machine enters the LINK_READY state, indicating that the physical link is connected;

[0186] 5) T5 period: After entering the LINK_READY state, after a delay of T5, the VBUSON signal becomes valid, the state machine enters the VBUS_ON state, and begins to supply power to the external USB device;

[0187] 6) T6 period: After the power supply is stable, after a delay of T6, the USB enumeration is completed, the state machine enters the ENUM state, and the Host mode data link is established.

[0188] In other words, in Host mode, the first data link selection module switches first, the Hub chip is powered on later, and the second data link selection module switches after the Hub is ready, ensuring that the Hub chip has completed initialization before the link is fully connected, thus avoiding enumeration failure.

[0189] Correspondingly, the data link establishment process in Host mode can be:

[0190] Step 1, Role Detection: The Role Detection Module detects a Host role request (such as an ID pin status change or software configuration) and determines the current USB role as Host mode.

[0191] Step 2, Target Decision: The link control module determines the target link as the Hub extension link and the non-target link as a bypass direct link.

[0192] Step 3, State Transition (IDLE→PREPARE): The state machine transitions from the IDLE state to the PREPARE state.

[0193] Step 4: Close non-target links: Ensure that bypass direct links are disconnected.

[0194] Step 5, State Transition (PREPARE→SWITCH): The state machine transitions to the SWITCH state.

[0195] Step 6, Upstream Link Switching: The first data link selection module switches to the Hub extended link direction, connecting the USBDRD controller to the upstream port of the Hub chip.

[0196] Step 7, Hub Enable: The Hub power control module enables the Hub chip, the Hub chip starts power-on initialization, and the USBDRD controller, as the Host, detects the Hub chip and completes enumeration.

[0197] Step 8, Downstream Link Switching: After the Hub chip is initialized, the second data link selection module switches to the Hub extended link direction, connecting the downstream port of the Hub chip to the USB connector.

[0198] Step 9, State Transition (SWITCH→LINK_READY): After the Hub initialization is complete and the upstream and downstream links have been switched, the state machine transitions to the LINK_READY state, indicating that the physical link is connected.

[0199] Step 10, VBUS Power On: The VBUS control module turns on the VBUS power supply to provide power to external USB devices.

[0200] Step 11, State Transition (LINK_READY→VBUS_ON): The state machine transitions to the VBUS_ON state.

[0201] Step 12, Enumeration: Wait for the USB enumeration to complete.

[0202] Step 13, State Transition (VBUS_ON→ENUM): The state machine transitions to the ENUM state, and the Host mode data link is established.

[0203] For example, Figure 6 The Device mode state timing diagram provided in this application is as follows: Figure 6 As shown, the timing relationships between signals and states in Device mode are as follows:

[0204] 1) During the T1 period: The RoleDetect signal is valid (a Device role request is detected). After a delay of T1, the state machine transitions from the IDLE state to the PREPARE state.

[0205] 2) T2 period: After entering PREPARE state, after a delay of T2, the Hub power off signal becomes valid, and the Hub chip is powered off;

[0206] 3) T3 period: After the Hub is powered off, after a delay of T3, the state machine enters the SWITCH state, and the first data link selection module and the second data link selection module begin to switch to the bypass direct link direction.

[0207] 4) T4 period: After the link switch is completed, the state machine enters the LINK_READY state after a delay of T4.

[0208] 5) T5 period: After entering the LINK_READY state, after a delay of T5, the VBUSOFF signal becomes valid, and the internal HostVBUS output is turned off (VBUS is provided by the external Host in Device mode).

[0209] 6) T6 period: After a delay of T6, Device mode initialization is completed, the state machine enters the ENUM state, and the Device mode data link is established.

[0210] Among them, internal VBUS enable (VBUS_OUT_EN): pulled low (disabled) at time T2; internal VBUS voltage (VBUS_SENSE): simulated waveform, gradually decreasing after T2, and dropping to the safety threshold at time T2'; external VBUS detection (EXT_VBUS_DET): goes high when VBUS is valid after external host is inserted; D+ pull-up enable (DP_PULLUP_EN): enabled after external VBUS is detected, starting Device enumeration.

[0211] In other words, in Device mode, the Hub power is turned off first, and then the two-level data link selection module switching is performed to ensure that the Hub chip is powered off before the bypass link is established. This avoids interference from the Hub chip to the bypass signal and reduces system power consumption. Device mode has no VBUS_ON state, and the state machine transitions directly from LINK_READY to ENUM.

[0212] Correspondingly, the data link establishment process in Device mode can be:

[0213] Step 1, Role Detection: The Role detection module detects the Device role request and determines the current USB role as Device mode.

[0214] Step 2, Target Decision: The link control module determines that the target link is a bypass direct link, and the non-target link is a Hub extension link.

[0215] Step 3, State Transition (IDLE→PREPARE): The state machine transitions from the IDLE state to the PREPARE state.

[0216] Step 4: Shut down non-target links: Ensure that the Hub extension links are disconnected.

[0217] Step 5, Hub Disable: The Hub power control module shuts down the Hub chip, the Hub chip stops working due to power failure, and unnecessary power consumption is eliminated.

[0218] Step 6, State Transition (PREPARE→SWITCH): The state machine transitions to the SWITCH state.

[0219] Step 7, Link Switching: The first data link selection module switches to the bypass direct link direction; the second data link selection module switches to the bypass direct link direction.

[0220] Step 8, State Transition (SWITCH→LINK_READY): After the link switch is completed, the state machine transitions to the LINK_READY state, indicating that the physical link is now connected.

[0221] Step 9, VBUS shutdown: The VBUS control module shuts down Host VBUS (VBUS is provided by an external Host in Device mode).

[0222] Step 10, State Transition (LINK_READY→ENUM): The state machine transitions to the ENUM state, and the Device mode data link is established.

[0223] For example, in one possible implementation, in the state machine described above:

[0224] 1) Entry conditions (can enter the RECOVERING state):

[0225] SWITCH status: Link switching timeout (e.g., the selected module action exceeds the preset threshold) or signal integrity detection failure;

[0226] LINK_READY state: The link is connected, but the enumeration timed out;

[0227] VBUS_ON state: VBUS output is abnormal (e.g., overcurrent, insufficient voltage).

[0228] ENUM status: Link health monitoring is abnormal during operation (Hub register read / write failure / bit error rate exceeds threshold);

[0229] When the state machine is in the ENUM state, if the Role detection module detects a USB role switching request (e.g., ID pin state change, CC pin renegotiation, or software-triggered role switching), the state machine performs the following operations: (1) notifies the USB driver layer to suspend the current data transmission; (2) closes the current data link and VBUS output; (3) the state machine transitions from the ENUM state to the IDLE state, waits for the new role detection result, and then re-establishes the link; in addition, if a USB role switching request is detected in the ENUM state, the state machine transitions from the ENUM state to the IDLE state.

[0230] And, ENUM state: indicates that the USB enumeration process has been completed and the data link has entered normal working state. This state is divided into two working sub-states according to the current USB role: (1) Host enumeration sub-state: this device is the host, the external USB device has been enumerated, and data transmission from host to device can be performed; (2) Device enumeration sub-state: this device is the USB device, it has been enumerated by the external host, and data transmission from device to host can be performed.

[0231] 2) Exit conditions:

[0232] RECOVERING→PREPARE: The current abnormal link has been closed and the current USB role has been reacquired;

[0233] RECOVERING: Retry the shutdown operation if the abnormal link fails to close or the role fails to be reacquired.

[0234] 3) In addition, in the SWITCH state, if the link switching times out or the signal integrity detection fails, the state machine will transition from the SWITCH state to the RECOVERING state.

[0235] The USB role-based data path switching method provided in this application controls a first data link selection module and a second data link selection module through a link control state machine to disconnect non-target data links and establish target data links. The state machine includes: IDLE state, PREPARE state, SWITCH state, LINK_READY state, and ENUM state; in Host mode, it also includes a VBUS_ON state. After acquiring the current USB role, the state machine sequentially transitions from the IDLE state to the PREPARE state, SWITCH state, and LINK_READY state. In Host mode, it further transitions to the VBUS_ON state after the LINK_READY state, and finally to the ENUM state. In this technical solution, the state machine breaks down the link switching into sequentially executed stages and binds specific hardware actions to each stage, enabling the switching process to be executed atomically at the physical link level. This eliminates the need for software reset and re-enumeration of the Hub, thereby achieving controllable switching timing, significantly reduced switching time, conflict-free Hub power supply and VBUS linkage, and improved switching reliability.

[0236] Based on the above embodiments, Figure 7 A flowchart illustrating the USB role-based data path switching method provided in this application. Figure 3 ,like Figure 7 As shown, the method may further include:

[0237] Step 71: If an abnormality is detected in the target data link during its establishment or operation, the state machine transitions to the RECOVERING state and shuts down the target data link.

[0238] In this implementation, the RECOVERING state is used to handle abnormal situations that occur during the establishment or operation of the target data link.

[0239] When the link health monitoring module detects an anomaly in the target data link, the state machine transitions from the current state (e.g., LINK_READY, VBUS_ON, or ENUM state) to the RECOVERING state, and executes the anomaly recovery process.

[0240] In RECOVERING state, first shut down the target data link that is currently experiencing an anomaly.

[0241] Step 72: Reacquire the current USB role and establish a new target data link based on the reacquired current USB role;

[0242] In this implementation, the current USB role is reacquired, and a new target data link is established according to the normal process based on the reacquired current USB role.

[0243] That is, the state machine establishes a new target data path from the RECOVERING state through PREPARE→SWITCH→LINK_READY.

[0244] Optionally, step 72 can be implemented by: reacquiring the current USB role and determining the recovery path, i.e., the new target data link, based on the current USB role and the exception type.

[0245] 1) If the current USB role is in Host mode and the exception type is Hub chip exception, the recovery path is: establish a bypass direct connection link as a degradation path, and periodically check the Hub chip status.

[0246] 2) If the current USB role is in Host mode and the exception type is a temporary link exception that is not related to the Hub, the recovery path is: re-establish the Hub extension link according to the normal procedure;

[0247] 3) If the current USB role is in Device mode, the recovery path is: try to re-establish the bypass direct link.

[0248] Step 73: If multiple attempts to establish a new target data link fail, if the current USB role is in Host mode, maintain the bypass direct connection as a security degradation state; if the current USB role is in Device mode, report the link failure and wait for USB role switching or reset.

[0249] In this implementation, if multiple attempts to establish a new target data link fail, the bypass direct link is kept connected as a safe state.

[0250] Because the bypass direct link does not pass through the Hub chip, it has a simple structure and high reliability. In Host mode, as a safe default state, it can ensure that at least one usable data path is maintained, preventing the entire USB subsystem from failing completely. However, in Device mode, since the upstream and downstream ports of the USB Hub chip are fixed (upstream to Host, downstream to Device), the Hub is fixedly connected to the USB DRD controller side upstream and the USB connector side downstream, and cannot be used in reverse. Therefore, the bypass direct link is the only usable data path in Device mode. If it continues to be abnormal, a fault must be reported and the USB role must be switched or the system reset must be performed.

[0251] The recovery process of this application embodiment is described in detail below, taking into account three specific abnormal scenarios:

[0252] Scenario 1: Fallback when Hub initialization fails.

[0253] 1. During the Host mode establishment process, after the Hub power is enabled, the link health monitoring module detects the Hub initialization status;

[0254] 2. If Hub initialization times out or fails, the state machine transitions from LINK_READY to RECOVERING state;

[0255] 3. The link control module triggers the fallback policy: shuts down the Hub extended link and switches to the bypass direct link;

[0256] 4. The state machine establishes a bypass path from RECOVERING through PREPARE→SWITCH→LINK_READY;

[0257] 5. Record Hub malfunction events and wait for recovery;

[0258] 6. Regularly recheck the Hub's health status;

[0259] The method for periodically re-checking the Hub's health status during the operation of the bypass direct link is as follows:

[0260] (1) The link control module sends a temporary enable signal to the Hub power control module according to a preset period (e.g., every 5 seconds) to power on the Hub chip for a short time;

[0261] (2) After power-on, the link health monitoring module reads the ID register and status register of the Hub chip through the first data link selection module to determine whether the Hub chip is responding normally;

[0262] (3) If the Hub chip responds normally, it is determined that the problem has been resolved, and the link control module executes the process of switching back to the Hub extended link; if the Hub chip does not respond or returns an error, the Hub power is turned off and the system waits for the next detection cycle.

[0263] (4) In order to avoid interference to the running bypass direct link during short-term power-on, the second data link selection module remains in the bypass direct link direction during the temporary power-on detection of the Hub chip, and the downstream port of the Hub is not connected to the USB connector.

[0264] 7. If the Hub returns to normal, re-detect the Role and restore the Hub extension link according to the normal procedure.

[0265] Through the aforementioned fallback mechanism, when the Hub chip fails to initialize, it can automatically switch to the bypass direct link as a backup path, ensuring that at least one usable data path is retained in Host mode, thus preventing the Hub from becoming a single point of failure and causing the entire USB subsystem to fail.

[0266] Scenario 2: Abnormal recovery during role switching.

[0267] 1. During role switching, the state machine is in the SWITCH state;

[0268] 2. If the link switching times out or the signal integrity detection fails;

[0269] Signal integrity detection can be achieved through one or more of the following methods:

[0270] (1) Protocol layer indirect detection: Count the number of data packet retransmissions, CRC errors and link disconnection reconnection within a certain time window of the USB link. When the above indicators exceed the preset threshold, it is determined that the signal integrity is abnormal.

[0271] (2) Built-in monitoring of USB controller: If the USB DRD controller or Hub chip has a built-in Received Signal Strength Indicator (RSSI) or Eye Diagram Monitoring Register, the signal quality can be evaluated by reading the value of the register;

[0272] (3) Dedicated monitoring circuit: Add a high-speed signal comparator or eye diagram monitoring chip to the data link to perform hardware monitoring of the eye diagram opening of D+ / D- or Super Speed ​​signals.

[0273] 3. The state machine transitions to the RECOVERING state;

[0274] 4. The link control module shuts down the currently abnormal link;

[0275] 5. Re-inspect the current Role;

[0276] 6. Re-establish the target link based on the Role;

[0277] 7. If multiple attempts fail, keep the Bypass path as a safe state.

[0278] Through the above-mentioned abnormal recovery mechanism, when a link switching timeout or signal integrity detection failure occurs during the role switching process, the target link can be automatically retried to be established, and after multiple failures, it will be downgraded to a bypass direct link, thus ensuring the robustness of the role switching process.

[0279] Scenario 3: Recovery when the Bypass path is abnormal.

[0280] 1. During Device mode operation, the link health monitoring module detected an abnormal signal integrity in the Bypass path;

[0281] 2. The state machine transitions to the RECOVERING state;

[0282] 3. Try to re-establish the bypass path, for example, by reconfiguring the data link selection module or retraining the link to eliminate temporary signal interference;

[0283] 4. If multiple attempts to rebuild the bypass direct link fail, due to the fixed upstream and downstream port directions of the USB Hub chip (the upstream port is fixedly connected to the first data link selection module on the USB DRD controller side, and the downstream port is fixedly connected to the second data link selection module on the USB connector side), the Hub extension link only supports unidirectional topology communication from the USB DRD controller side (Host end) to the USB connector side (Device end). It cannot be used in reverse in Device mode (i.e., the external Host device is connected to the USB connector side and cannot communicate with the Device on the USB DRD controller side through the Hub extension link). Therefore, the bypass direct link is the only available data path in Device mode. At this time, the link control module reports a link failure and waits for the USB role to switch or the system to reset before attempting to re-establish the bypass direct link. If the role switches to Host mode, the Hub extension link is established according to the normal procedure; if Device mode is maintained, the attempt to rebuild the bypass direct link continues.

[0284] 5. If the USB role switches to Host mode or the bypass link returns to normal after a system reset, the state machine will return to the ENUM state via PREPARE→SWITCH→LINK_READY.

[0285] Through the above recovery mechanism, when the bypass direct link in Device mode experiences signal integrity abnormalities, it first attempts to re-establish the bypass direct link. If the abnormality persists and the Hub chip is in normal condition, it switches to the Hub extended link as a backup Device data path, thus ensuring the connection reliability in Device mode.

[0286] The USB role-based data path switching method provided in this application, when an anomaly is detected in the target data link during its establishment or operation, transitions the state machine to the RECOVERING state, shutting down the target data link; reacquires the current USB role and establishes a new target data link based on the reacquired current USB role; if multiple attempts to establish a new target data link fail, in the current USB role in Host mode, the bypass direct connection is maintained as a safety degradation state; in the current USB role in Device mode, a link failure is reported and the system waits for USB role switching or reset. This technical solution adds a RECOVERING state to the state machine and specifies that after an anomaly is triggered, a recovery process of shutting down the abnormal link, reacquiring the role, and rebuilding the target link is automatically executed. Furthermore, in the event of multiple rebuild failures, the system maintains the connection of the simplest bypass direct connection, enabling autonomous primary / backup path switching rather than overall failure when the Hub or link is abnormal. This eliminates single-point-of-failure in the Hub, automates anomaly recovery, and provides a backup in extreme cases.

[0287] Based on the above embodiments, Figure 8 A schematic diagram of the structure of the USB role-based data path switching device provided in this application is shown below. Figure 8 As shown, the device includes:

[0288] Module 81 is used to obtain the current USB role, which is either Host mode or Device mode.

[0289] The determination module 82 is used to determine the target data link and the non-target data link based on the current USB role. The target data link is one of the Hub extension link and the bypass direct link, and the non-target data link is the other of the Hub extension link and the bypass direct link. The Hub extension link and the bypass direct link are parallel links set between the USB connector and the USB DRD controller, respectively. A Hub chip is connected in series on the Hub extension link. A first data link selection module is set on the USB DRD controller side, and a second data link selection module is set on the USB connector side. The first data link selection module and the second data link selection module are used to select whether to connect to the Hub extension link or the bypass direct link.

[0290] The control module 83 is used to control the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link.

[0291] In one or more embodiments, the determining module 82 determines the target data link and non-target data link based on the current USB role, specifically for:

[0292] If the current USB role is in Host mode, the target data link is determined to be the Hub extension link, and the non-target data link is determined to be the bypass direct link;

[0293] If the current USB role is Device mode, the target data link is determined to be a bypass direct link, and the non-target data link is a Hub extension link.

[0294] In one or more embodiments, the control module 83 controls the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link, specifically for:

[0295] If the target data link is a Hub extension link, control the first data link selection module to switch to the Hub extension link, enable the power supply of the Hub chip, and control the second data link selection module to switch to the Hub extension link after the Hub chip initialization is completed.

[0296] If the target data link is a bypass direct link, turn off the power to the Hub chip and control the first data link selection module and the second data link selection module to switch to the bypass direct link.

[0297] In one or more embodiments, the control module 83 is further configured to:

[0298] Control the output state of the VBUS pin of the USB connector according to the current USB role;

[0299] Specifically, if the current USB role is Host mode, the voltage output of the VBUS pin is enabled; if the current USB role is Device mode, the voltage output of the VBUS pin is disabled.

[0300] In one or more embodiments, the control module 83 controls the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link, specifically for:

[0301] The state machine of the link control controls the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link.

[0302] The state machine includes: IDLE state, PREPARE state, SWITCH state, LINK_READY state, and ENUM state. In Host mode, it also includes VBUS_ON state.

[0303] After acquiring the current USB role, the state machine transitions sequentially from the IDLE state to the PREPARE state, SWITCH state, and LINK_READY state. In Host mode, after the LINK_READY state, it further transitions to the VBUS_ON state, and finally to the ENUM state.

[0304] In one or more embodiments, the state machine further includes a RECOVERING state;

[0305] Correspondingly, control module 83 is also used for:

[0306] If an anomaly is detected in the target data link during its establishment or operation, the state machine transitions to the RECOVERING state and shuts down the target data link.

[0307] Reacquire the current USB role and establish a new target data link based on the reacquired current USB role;

[0308] If multiple attempts to establish a new target data link fail, in the current USB role of Host mode, maintain the bypass direct connection as a security degradation state; in the current USB role of Device mode, report the link failure and wait for USB role switching or reset.

[0309] In one or more embodiments, the control module 83 is further configured to:

[0310] Periodic health monitoring is performed on the established target data link. The health monitoring includes: Hub chip initialization status detection and / or signal integrity detection.

[0311] If the target data link is a Hub extension link and a Hub chip malfunction is detected, disconnect the Hub extension link and establish a bypass direct link. Record Hub malfunction events and periodically re-check the Hub chip status. Once the Hub chip returns to normal, disconnect the bypass direct link and re-establish the Hub extension link.

[0312] If the target data link is a bypass direct link and an abnormal signal integrity is detected, attempt to re-establish the bypass direct link. If the bypass direct link continues to be abnormal and the Hub chip is in normal condition, disconnect the bypass direct link and establish a Hub extended link.

[0313] It should be noted that the division of the various modules in the above device is merely a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical element, or they can be physically separated. Furthermore, these modules can be implemented entirely in software through processing element calls, or entirely in hardware. Alternatively, some modules can be implemented through processing element calls in software, while others can be implemented in hardware. Moreover, these modules can be integrated together or implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. During implementation, each step of the above method or each of the above modules can be completed through the integrated logic circuits in the hardware of the processor element or through software instructions.

[0314] As can be seen from the above, the USB role-based data path switching device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.

[0315] Figure 9 A schematic diagram of the structure of the electronic device provided in this application. Figure 9 As shown, the electronic device provided in this embodiment includes at least one processor 91 and a memory 92.

[0316] Optionally, the electronic device also includes a communication component 93.

[0317] The processor 91, memory 92, and communication component 93 are connected via bus 94.

[0318] In a specific implementation, at least one processor 91 executes computer execution instructions stored in memory 92, causing at least one processor 91 to perform the above-described method.

[0319] The specific implementation process of processor 91 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.

[0320] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.

[0321] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.

[0322] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0323] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0324] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.

[0325] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.

[0326] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.

[0327] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0328] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0329] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0330] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0331] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0332] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.

Claims

1. A method for switching data paths based on USB roles, characterized in that, include: Obtain the current USB role, which is either Host mode or Device mode; Based on the current USB role, determine the target data link and non-target data link; The target data link is one of the Hub extension link and the bypass direct link, and the non-target data link is the other of the Hub extension link and the bypass direct link. The Hub extension link and the bypass direct link are parallel links respectively set between the USB connector and the USB DRD controller. A Hub chip is connected in series on the Hub extension link. A first data link selection module is set on the USB DRD controller side, and a second data link selection module is set on the USB connector side. The first data link selection module and the second data link selection module are used to select to connect to the Hub extension link or the bypass direct link. Control the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link.

2. The method according to claim 1, characterized in that, The step of determining the target data link and non-target data link based on the current USB role includes: If the current USB role is in Host mode, the target data link is determined to be the Hub extended link, and the non-target data link is the bypass direct link; If the current USB role is Device mode, the target data link is determined to be the bypass direct link, and the non-target data link is the Hub extension link.

3. The method according to claim 1 or 2, characterized in that, The control of the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link includes: If the target data link is the Hub extension link, control the first data link selection module to switch to the Hub extension link, enable the power supply of the Hub chip, and control the second data link selection module to switch to the Hub extension link after the Hub chip initialization is completed. If the target data link is the bypass direct link, turn off the power to the Hub chip and control the first data link selection module and the second data link selection module to switch to the bypass direct link.

4. The method according to claim 1 or 2, characterized in that, The method further includes: Control the output state of the VBUS pin of the USB connector according to the current USB role; Specifically, if the current USB role is Host mode, the voltage output of the VBUS pin is enabled; if the current USB role is Device mode, the voltage output of the VBUS pin is disabled.

5. The method according to claim 1 or 2, characterized in that, The control of the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link includes: The state machine of the link control controls the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link. The state machine includes: IDLE state, PREPARE state, SWITCH state, LINK_READY state and ENUM state, and in the Host mode it also includes VBUS_ON state; After acquiring the current USB role, the state machine sequentially transitions from the IDLE state to the PREPARE state, the SWITCH state, and the LINK_READY state. In Host mode, after the LINK_READY state, it further transitions to the VBUS_ON state, and finally to the ENUM state.

6. The method according to claim 5, characterized in that, The state machine also includes: the RECOVERING state; Accordingly, the method further includes: If an abnormality is detected in the target data link during its establishment or operation, the state machine transitions to the RECOVERING state and shuts down the target data link. Reacquire the current USB role and establish a new target data link based on the reacquired current USB role; If multiple attempts to establish a new target data link fail, and the current USB role is in Host mode, the bypass direct connection is maintained as a security degradation state; if the current USB role is in Device mode, a link failure is reported and the system waits for a USB role switch or reset.

7. The method according to claim 1 or 2, characterized in that, The method further includes: Periodic health monitoring is performed on the established target data link, including: Hub chip initialization status detection and / or signal integrity detection; If the target data link is a Hub extension link and an abnormality is detected in the Hub chip, disconnect the Hub extension link and establish the bypass direct link, record the Hub abnormality event and periodically re-detect the Hub chip status, and disconnect the bypass direct link and re-establish the Hub extension link after the Hub chip returns to normal. If the target data link is a bypass direct link and an abnormal signal integrity is detected, attempt to re-establish the bypass direct link. If the bypass direct link remains abnormal and the Hub chip is in normal condition, disconnect the bypass direct link and establish the Hub extended link.

8. A data path switching device based on USB roles, characterized in that, include: The acquisition module is used to acquire the current USB role, which is either Host mode or Device mode; The determination module is used to determine the target data link and non-target data link based on the current USB role; The target data link is one of the Hub extension link and the bypass direct link, and the non-target data link is the other of the Hub extension link and the bypass direct link. The Hub extension link and the bypass direct link are parallel links respectively set between the USB connector and the USB DRD controller. A Hub chip is connected in series on the Hub extension link. A first data link selection module is set on the USB DRD controller side, and a second data link selection module is set on the USB connector side. The first data link selection module and the second data link selection module are used to select to connect to the Hub extension link or the bypass direct link. The control module is used to control the first data link selection module and the second data link selection module to disconnect the non-target data link and establish the target data link.

9. An electronic device, characterized in that, include: Memory, processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-7.

10. A computer-readable storage medium / computer program product, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-7; The computer program product includes a computer program that, when executed by a processor, is used to implement the method as described in any one of claims 1-7.