USB device hot plug detection method, device, equipment and readable storage medium
By obtaining the level status of the differential line at the USB device interface before the SOF packet, and judging and updating the connection status, the problem of inaccurate detection after hot-swap USB devices is solved, ensuring timely update of system status and data transmission continuity.
Patent Information
- Application Number
- CN202111584348.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-22
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2041-12-22
AI Technical Summary
In the prior art, USB devices cannot accurately detect whether the interface is connected to the device after hot plugging, resulting in misjudgment of the system and affecting normal use.
In the first set time before sending the SOF packet, obtain the level status of the differential line at the USB device interface, and determine whether the level status within the current time and the previous second set time are low to determine the device connection status and update the recorded connection status.
It realizes accurate detection of hot plugging of USB devices, avoids system misjudgment, and ensures timely update of device status and continuity of data transmission.
Smart Images

Figure CN114281625B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of device detection technology, and in particular to a method, apparatus, device and readable storage medium for detecting hot plugging of a USB device. Background Art
[0002] Hot plugging refers to inserting or removing a module from a system without turning off the system power supply, thereby improving the stability of the system. Currently, hot plugging technology has been applied to various fields. For example, the USB interface provided on the computer that people use daily can realize hot plugging function, and devices such as hard disks and USB flash drives can be connected or removed at any time through the USB (Universal Serial Bus) interface. However, after hot plugging a device, if it is not possible to accurately detect whether the USB interface is still connected to a device, it may cause the module circuit around the USB interface to misjudge, thereby causing the computer end to always maintain its original working state, affecting normal use. Therefore, how to detect the hot plugging of USB devices has always been a problem that people pay attention to. Summary of the Invention
[0003] In view of this, the present application provides a USB device hot plug detection method, apparatus, device and readable storage medium to facilitate detection of USB device hot plug.
[0004] In order to achieve the above objectives, the following solutions are proposed:
[0005] A method for detecting hot plugging of a USB device, comprising:
[0006] obtaining, within a first set time period before sending a start of frame (SOF) packet, a current level state of a differential line of a universal serial bus (USB) device interface, wherein the USB device interface is used to connect a USB device;
[0007] If the level states of the differential lines of the USB device interface end are both low at the current moment and within the second set time period before the current moment, it is determined that the USB device interface end is not connected to the USB device at the current moment; otherwise, it is determined that the USB device interface end is connected to the USB device at the current moment, and the first set time period is greater than the second set time period;
[0008] The connection status of the USB device interface terminal at the current moment is determined to update the recorded connection status of the USB device interface terminal, where the connection status includes connected and unconnected.
[0009] Optionally, the method further includes:
[0010] When it is determined that the USB device interface is currently connected to a USB device, device information of the USB device connected to the USB device interface is recorded.
[0011] Optionally, the method further includes:
[0012] When the recorded connection status of the USB device interface is updated from unconnected to connected, determining whether there is device information of a USB device connected to the USB device interface within a third set time period before the current moment;
[0013] If the device information does not exist, initializing the USB device currently connected to the USB device interface;
[0014] If the device information exists, determining whether the device information of the USB device currently connected to the USB device interface is consistent with the existing device information;
[0015] If the two device information are consistent, obtaining the data transmission task and data transmission progress corresponding to the device information, and performing data transmission based on the data transmission task and the data transmission progress;
[0016] If the two device information are inconsistent, a reset operation is performed, and an initialization operation is performed on the USB device connected to the USB device interface.
[0017] Optionally, obtaining the current level state of the differential line of the universal serial bus (USB) device interface includes:
[0018] Sending a command for reading the level status of the differential line of the USB device interface end to the physical layer PHY chip, so that the PHY chip reads the level status of the differential line of the USB device interface end based on the command;
[0019] Receive the level status of the differential line of the USB device interface end sent by the PHY chip.
[0020] Optionally, the method further includes:
[0021] When the recorded connection status of the USB device interface is updated from connected to unconnected, issuing a first prompt message to prompt the user that the USB device has been removed from the USB device interface;
[0022] When the recorded connection status of the USB device interface is updated from unconnected to connected, a second prompt message is sent to prompt the user that a USB device is connected to the USB device interface.
[0023] A USB device hot plug detection device, comprising:
[0024] a level status acquiring unit, which acquires the level status of the differential line of the USB device interface end at the current moment within a first set time period before sending the frame start SOF packet, wherein the USB device interface end is used to connect the USB device;
[0025] a connection status determining unit, configured to determine that no USB device is connected to the USB device interface at the current moment if the level states of the differential lines of the USB device interface are both low at the current moment and within a second set time period before the current moment; otherwise, determine that the USB device interface is connected to the USB device at the current moment, and the first set time period is greater than the second set time period;
[0026] The connection status updating unit is used to update the recorded connection status of the USB device interface terminal using the determined connection status of the USB device interface terminal at the current moment, where the connection status includes connected and unconnected.
[0027] Optionally, the device further comprises:
[0028] The device information recording unit is used to record the device information of the USB device connected to the USB device interface end when it is determined that the USB device interface end is connected to the USB device at the current moment.
[0029] Optionally, the device further comprises:
[0030] a judgment processing unit, configured to, when the recorded connection status of the USB device interface end is updated from unconnected to connected, determine whether device information of a USB device connected to the USB device interface end exists within a third set time period before a current moment; if the device information does not exist, perform an initialization operation on the USB device connected to the USB device interface end; if the device information exists, determine whether the device information of the USB device connected to the USB device interface end at a current moment is consistent with the existing device information; if the two pieces of device information are consistent, obtain a data transmission task and a data transmission progress corresponding to the device information, and perform data transmission based on the data transmission task and the data transmission progress; if the two pieces of device information are inconsistent, perform a reset operation, and perform an initialization operation on the USB device connected to the USB device interface end.
[0031] A USB device hot plug detection device, comprising: a memory and a processor;
[0032] The memory is used to store programs;
[0033] The processor is used to execute the program to implement the various steps of the aforementioned USB device hot plug detection method.
[0034] A readable storage medium stores a computer program, which, when executed by a processor, implements the various steps of the aforementioned USB device hot plug detection method.
[0035] As can be seen from the above technical solutions, the embodiments of the present application provide a method, apparatus, device and readable storage medium for detecting hot plugging of a USB device. Within a first set time period before sending a SOF (Start of Frame) packet, the level state of the differential line of the USB device interface end at the current moment is obtained. If the level state of the differential line of the USB device interface end at the current moment and within a second set time period before the current moment is low, it is determined that the USB device interface end is not connected to a USB device at the current moment. Otherwise, it is determined that the USB device interface end is connected to a USB device at the current moment. The connection state of the USB device interface end determined at the current moment is used to update the recorded connection state of the USB device interface end, and the connection state includes connected and unconnected. In the present application, by obtaining the level state of the differential line of the USB device interface end and judging whether the level state can remain low at the current moment and within the second set time period before the current moment, it is determined whether the USB device interface end is connected to a USB device at the current moment. Then, the connection state of the USB device interface end determined at the current moment is used to update the recorded connection state of the USB device interface end, thereby realizing detection of hot plugging of a USB device. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without any creative work.
[0037] Figure 1 A flow chart of a USB device hot plug detection method provided in an embodiment of the present application;
[0038] Figure 2 A schematic structural diagram of a USB device hot plug detection device provided in an embodiment of the present application;
[0039] Figure 3 This is a hardware structure block diagram of a USB device hot plug detection device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0040] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0041] Figure 1 A flow chart of a USB device hot plug detection method provided in an embodiment of the present application, the method may include the following steps:
[0042] Step S100: within a first set time period before sending the SOF packet, obtaining the current level state of the differential line of the USB device interface.
[0043] The USB device interface is used to connect to a USB device.
[0044] Specifically, the USB controller can periodically send SOF packets to the USB device interface. Between two SOF packets, the USB controller can send command packets such as SETUP, IN, and OUT. The USB device must respond with a command packet before sending the next SOF packet. For USB 1.1 interfaces, the USB controller sends SOF packets at an interval of 1ms. For USB 2.0 interfaces, the USB controller sends SOF packets at an interval of 125μs.
[0045] Because the USB controller does not send command packets to the USB device interface and the USB device does not send reply command packets to the USB controller during a period of time before each SOF packet, this period of time can be set as a first set duration. During the first set duration of time before each SOF packet, the current level state of the differential line at the USB device interface is obtained, which is the level state when no data is being transmitted on the differential line.
[0046] Step S101: Determine whether the level states of the differential lines at the USB device interface end are all low at the current moment and within a second set time period before the current moment.
[0047] Specifically, the USB device interface may include two differential lines. After the USB device interface is connected to the USB device, the differential lines may be connected to the data transmission lines of the USB device. After the USB device is connected to the USB device interface and powered on, the voltage levels of the two data transmission lines of the USB device may be both high, or one high and the other low, thereby distinguishing between full-speed USB devices, low-speed USB devices, and high-speed USB devices. When the voltage levels of the differential lines of the USB device interface are both low, it can be determined that no USB device is connected to the USB device interface.
[0048] To reduce interference from abnormal level changes, a second set time period may be set, where the second set time period is less than the first set time period. If the level of the differential line at the USB device interface is low at the current time and within the second set time period before the current time, step S102 is executed. If the level of the differential line at the USB device interface is high at the current time and within the second set time period before the current time, step S103 is executed.
[0049] Step S102: Determine that the USB device interface is not connected to a USB device at the current moment.
[0050] Specifically, since the level states of the differential lines of the USB device interface are all low at the current moment and within the second set time period before the current moment, it can be determined that the USB device interface is not connected to the USB device at the current moment.
[0051] Step S103: Determine whether the USB device interface is connected to a USB device at the current moment.
[0052] Specifically, if the level of the differential lines at the USB device interface is high at the current moment and within a second predetermined time period before the current moment, it can be determined that a USB device is currently connected to the USB device interface. Furthermore, based on the level of the two differential lines at the time of the high level, it can be determined whether the connected USB device is a full-speed USB device, a low-speed USB device, or a high-speed USB device.
[0053] Step S104: using the determined current connection status of the USB device interface, update the recorded connection status of the USB device interface.
[0054] The connection status includes connected and disconnected.
[0055] Specifically, in the above steps, when the USB device interface is not connected to the USB device, it can be determined that the connection state of the USB device interface is currently disconnected, and the recorded connection state of the USB device interface can be updated to disconnected. When the USB device interface is connected to the USB device, it can be determined that the connection state of the USB device interface is currently connected, and the recorded connection state of the USB device interface can be updated to connected.
[0056] During the update process, you can directly replace the recorded connection status with the latest connection status, or you can first compare the latest connection status with the recorded connection status. Only when the two connection statuses are different, will they be replaced. If they are the same, no change will be made.
[0057] In the above embodiment, a method for detecting hot plugging of a USB device is provided. The method obtains the level status of the differential line of the USB device interface end at the current moment within a first set time period before sending an SOF packet. If the level status of the differential line of the USB device interface end at the current moment and within a second set time period before the current moment is low, it is determined that the USB device interface end is not connected to a USB device at the current moment. Otherwise, it is determined that the USB device interface end is connected to a USB device at the current moment. The connection status of the USB device interface end determined at the current moment is used to update the recorded connection status of the USB device interface end. The connection status includes connected and unconnected. In the present application, by obtaining the level status of the differential line of the USB device interface end and judging whether the level status can remain low at the current moment and within the second set time period before the current moment, it is determined whether the USB device interface end is connected to a USB device at the current moment. The connection status of the USB device interface end determined at the current moment is then used to update the recorded connection status of the USB device interface end, thereby realizing detection of hot plugging of a USB device.
[0058] In actual use, USB devices have special device information, such as the USB device code or name, which can be used to accurately identify USB devices. Based on this, in some embodiments of the present application, the device information of the USB connected to the USB device interface segment can be recorded, thereby facilitating the unified management of USB device-related data.
[0059] Specifically, in the above embodiment, by determining that the level states of the differential lines of the USB device interface are both low at the current moment and within the second set time period before the current moment, it can be determined that the USB device interface is connected to the USB device at the current moment. When it is determined that the USB device interface is connected to the USB device at the current moment, device information of the USB device connected to the USB device interface can be recorded.
[0060] In the above embodiment, by recording the device information of the USB device connected to the USB device interface when determining that the USB device is connected to the USB device at the current moment, it is convenient to uniformly manage the data related to the USB device during subsequent data interaction.
[0061] During the use of a USB device, the USB device may be accidentally disconnected due to collision, movement, etc., causing the connection status of the USB device interface to change from connected to disconnected, thereby causing data transmission anomalies. Based on this, in some embodiments of the present application, after executing step S104 and using the determined current connection status of the USB device interface to update the recorded connection status of the USB device interface, it is also possible to determine whether there is a data transmission task that needs to be continued by determining whether there is recorded device information of a USB device connected to the USB device interface within a third set time period before the current moment. Specifically, this may include:
[0062] S11. When the recorded connection status of the USB device interface is updated from unconnected to connected, determine whether there is device information of a USB device connected to the USB device interface within a third set time period before the current moment.
[0063] Specifically, when the recorded connection status of the USB device interface is updated from unconnected to connected, it can be determined that the USB device interface is currently connected to the USB device. After determining that the USB device interface is currently connected to the USB device, device information of the USB device connected to the USB device interface within a third set time period before the current time can be searched. If the device information does not exist, S12 is executed; if the device information exists, S13 is executed.
[0064] The third set time period may be determined by counting the time it takes for the user to reinsert the USB device into the USB device interface after the USB device is accidentally disconnected, and taking the average of all the counted times.
[0065] S12: Initialize the USB device currently connected to the USB device interface.
[0066] Specifically, if there is no device information of a USB device connected to the USB device interface end within the third set time period before the current moment, it can be determined that there is no data transmission task that needs to be continued. Therefore, the USB device connected to the USB device interface end at the current moment can be initialized.
[0067] S13: Determine whether the device information of the USB device currently connected to the USB device interface is consistent with the existing device information.
[0068] Specifically, if there is device information of a USB device connected to the USB device interface end within the third set time period before the current moment, then the device information of the USB device connected to the USB device interface end within the third set time period before the current moment can be obtained, and it is determined whether the device information of the USB device connected to the USB device interface end at the current moment is consistent with the device information existing within the third set time period before the current moment. If the two device information are consistent, execute S14; if the two device information are inconsistent, execute S15.
[0069] S14. Acquire a data transmission task and a data transmission progress corresponding to the device information, and perform data transmission based on the data transmission task and the data transmission progress.
[0070] Specifically, if the device information of the USB device currently connected to the USB device interface is consistent with the recorded device information, the data transfer task and data transfer progress corresponding to the device information can be obtained, and data transfer can be performed based on the data transfer task and data transfer progress. This allows the data transfer task of the USB device corresponding to the device information to be continued, and data transfer can be performed based on the previous data transfer progress.
[0071] S15: Execute a reset operation and initialize the USB device connected to the USB device interface.
[0072] Specifically, the reset operation can delete data information associated with the USB device interface, where the data information may include device information of the USB device connected to the USB device interface, as well as corresponding data transfer tasks and data transfer progress. After the reset operation, the USB device interface is in a state waiting for a USB device to be inserted. Because a USB device is currently connected to the USB device interface, the USB device connected to the USB device interface can be initialized after the reset operation is performed.
[0073] In the above embodiment, by determining whether there is device information of a USB device connected to the USB device interface end within a third set time period before the current moment, when there is device information of a USB device connected to the USB device interface end, if the device information of the USB device connected to the USB device interface end at the current moment is consistent with the device information, the data transmission task and data transmission progress corresponding to the device information can be obtained, and data transmission can be performed based on the data transmission task and data transmission progress. In this way, after the USB device is accidentally disconnected, if the user can reinsert the USB into the USB device interface end within a period of time, the previous transmission task can be continued, thereby avoiding data transmission abnormalities caused by accidental disconnection of the USB device.
[0074] In some embodiments of the present application, the process of executing step S100 and obtaining the current level state of the differential line of the USB device interface terminal within the first set time period before sending the SOF packet is introduced. The process may include:
[0075] S21 . Send a command to the PHY chip to read the level status of the differential line at the USB device interface.
[0076] Specifically, when obtaining a command for the level status of the differential line at the USB device interface end, a command for reading the level status of the differential line at the USB device interface end can be first sent to a PHY (physical layer) chip, so that the PHY chip can read the level status of the differential line at the USB device interface end based on the command. Among them, the PHY chip can realize the conversion between ULPI interface signals and USB interface signals. ULPI refers to UTMI+Low Pin Interface, which is a simplified pin version of UTMI (USB2.0 Transceiver Macrocell Interface, USB2.0 high-speed device detection protocol). UTMI is a protocol for communication between a USB controller and a PHY chip.
[0077] S22: Receive the level status of the differential line of the USB device interface end sent by the PHY chip.
[0078] Specifically, after sending a command to read the level status of the differential lines of the USB device interface end to the PHY chip, the PHY chip can obtain the levels of the two differential lines of the USB device interface end, and then return the level status of the differential lines of the USB device interface end to the USB controller.
[0079] In the above embodiment, by sending a command to the PHY chip to read the level status of the differential line of the USB device interface end, the PHY chip can read according to the command and finally return the read level status, thereby obtaining the level status of the differential line of the USB device interface end.
[0080] Considering that in actual use, a slight deviation of the USB device may cause the connection status between the USB device interface and the USB device to change, and such a slight deviation is difficult to detect with the naked eye, resulting in the user being unable to promptly detect and take appropriate measures when the connection status changes. Based on this, in some embodiments of the present application, a prompt message can be sent to the user when the connection status between the USB device interface and the USB device changes, thereby achieving the effect of prompting the user.
[0081] Specifically, when the recorded connection status of the USB device interface is updated from connected to disconnected, a first prompt message may be issued to prompt the user that the USB device has been removed from the USB device interface. When the recorded connection status of the USB device interface is updated from disconnected to connected, a second prompt message may be issued to prompt the user that a USB device is connected to the USB device interface.
[0082] In the above embodiment, by issuing a first prompt message when the recorded connection status of the USB device interface end is updated from connected to disconnected, and issuing a second prompt message when the recorded connection status of the USB device interface end is updated from disconnected to connected, the user can be promptly reminded when the connection relationship between the USB device interface end and the USB device changes, so that the user can understand the current connection status of the USB device and perform corresponding processing.
[0083] The following describes a USB device hot plug detection apparatus provided in an embodiment of the present application. The USB device hot plug detection apparatus described below and the USB device hot plug detection method described above can refer to each other.
[0084] Figure 2 A schematic structural diagram of a USB device hot plug detection device provided in an embodiment of the present application, wherein the USB device hot plug detection device may include:
[0085] The level state acquisition unit 10 acquires the level state of the differential line of the USB device interface end at the current moment within a first set time period before sending the frame start SOF packet, where the USB device interface end is used to connect the USB device;
[0086] a connection status determining unit 20 for determining that no USB device is connected to the USB device interface at the current moment if the level states of the differential lines of the USB device interface at the current moment and within a second set time period before the current moment are both low; otherwise, determining that the USB device interface at the current moment is connected to the USB device, and the first set time period is greater than the second set time period;
[0087] The connection status updating unit 30 is configured to update the recorded connection status of the USB device interface terminal using the determined connection status of the USB device interface terminal at the current moment, where the connection status includes connected and disconnected.
[0088] In the above embodiment, a USB device hot plug detection device is provided, wherein the level state acquisition unit 10 acquires the level state of the differential line of the USB device interface end at the current moment within a first set time period before sending an SOF packet. If the level state of the differential line of the USB device interface end at the current moment and within a second set time period before the current moment is low, the connection state determination unit 20 determines that the USB device interface end is not connected to the USB device at the current moment; otherwise, it determines that the USB device interface end is connected to the USB device at the current moment. The connection state update unit 30 uses the determined connection state of the USB device interface end at the current moment to update the recorded connection state of the USB device interface end, where the connection state includes connected and not connected. In the present application, by acquiring the level state of the differential line of the USB device interface end and judging whether the level state can remain low at the current moment and within the second set time period before the current moment, it is determined whether the USB device interface end is connected to the USB device at the current moment, and then using the determined connection state of the USB device interface end at the current moment to update the recorded connection state of the USB device interface end, thereby achieving USB device hot plug detection.
[0089] Optionally, the USB device hot plug detection device may further include:
[0090] The device information recording unit is used to record the device information of the USB device connected to the USB device interface end when it is determined that the USB device interface end is connected to the USB device at the current moment.
[0091] Optionally, the USB device hot plug detection device may further include:
[0092] a judgment processing unit, configured to, when the recorded connection status of the USB device interface end is updated from unconnected to connected, determine whether device information of a USB device connected to the USB device interface end exists within a third set time period before a current moment; if the device information does not exist, perform an initialization operation on the USB device connected to the USB device interface end; if the device information exists, determine whether the device information of the USB device connected to the USB device interface end at a current moment is consistent with the existing device information; if the two pieces of device information are consistent, obtain a data transmission task and a data transmission progress corresponding to the device information, and perform data transmission based on the data transmission task and the data transmission progress; if the two pieces of device information are inconsistent, perform a reset operation, and perform an initialization operation on the USB device connected to the USB device interface end.
[0093] Optionally, the process of the level status acquiring unit 10 acquiring the level status of the differential line of the USB device interface at the current moment may include:
[0094] Sending a command for reading the level status of the differential line of the USB device interface end to the physical layer PHY chip, so that the PHY chip reads the level status of the differential line of the USB device interface end based on the command;
[0095] Receive the level status of the differential line of the USB device interface end sent by the PHY chip.
[0096] Optionally, the USB device hot plug detection device may further include:
[0097] a first prompt information sending unit, configured to send a first prompt information when the recorded connection status of the USB device interface is updated from connected to disconnected, so as to prompt the user that the USB device has been removed from the USB device interface;
[0098] The second prompt information sending unit is used to send a second prompt information when the recorded connection status of the USB device interface end is updated from unconnected to connected, so as to prompt the user that a USB device is connected to the USB device interface end.
[0099] The present invention also provides a USB device hot plug detection device. Figure 3 The hardware structure diagram of the USB device hot plug detection device is shown. Figure 3 ,The hardware structure of the USB device hot plug detection device may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4;
[0100] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;
[0101] The processor 1 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention;
[0102] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;
[0103] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to implement each processing flow in the aforementioned USB device hot plug detection method.
[0104] An embodiment of the present application further provides a storage medium, which can store a program suitable for execution by a processor, wherein the program is used to implement each processing flow in the aforementioned USB device hot plug detection method.
[0105] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0106] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined with each other, and the same or similar parts can be referenced to each other.
[0107] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for detecting hot plugging of a USB device, characterized in that: include: obtaining, within a first set time period before sending a start of frame (SOF) packet, a current level state of a differential line of a universal serial bus (USB) device interface, wherein the USB device interface is used to connect a USB device; If the level states of the differential lines of the USB device interface end are both low at the current moment and within the second set time period before the current moment, it is determined that the USB device interface end is not connected to the USB device at the current moment; otherwise, it is determined that the USB device interface end is connected to the USB device at the current moment, and the first set time period is greater than the second set time period; Using the determined current connection state of the USB device interface, the recorded connection state of the USB device interface is updated, where the connection state includes connected and unconnected; When it is determined that the USB device interface is currently connected to a USB device, recording device information of the USB device connected to the USB device interface; When the recorded connection status of the USB device interface is updated from unconnected to connected, determining whether there is device information of a USB device connected to the USB device interface within a third set time period before the current moment; If the device information does not exist, initializing the USB device currently connected to the USB device interface; If the device information exists, determining whether the device information of the USB device currently connected to the USB device interface is consistent with the existing device information; If the two device information are consistent, obtaining the data transmission task and data transmission progress corresponding to the device information, and performing data transmission based on the data transmission task and the data transmission progress; If the two device information are inconsistent, a reset operation is performed, and an initialization operation is performed on the USB device connected to the USB device interface.
2. The method according to claim 1, characterized in that The step of obtaining the current level state of the differential line of the USB device interface terminal includes: Sending a command for reading the level status of the differential line of the USB device interface end to the physical layer PHY chip, so that the PHY chip reads the level status of the differential line of the USB device interface end based on the command; Receive the level status of the differential line of the USB device interface end sent by the PHY chip.
3. The method according to any one of claims 1-2, characterized in that The method also includes: When the recorded connection status of the USB device interface is updated from connected to unconnected, issuing a first prompt message to prompt the user that the USB device has been removed from the USB device interface; When the recorded connection status of the USB device interface is updated from unconnected to connected, a second prompt message is sent to prompt the user that a USB device is connected to the USB device interface.
4. A USB device hot plug detection device, characterized in that: include: a level status acquiring unit, which acquires the level status of the differential line of the USB device interface end at the current moment within a first set time period before sending the frame start SOF packet, wherein the USB device interface end is used to connect the USB device; a connection status determining unit, configured to determine that no USB device is connected to the USB device interface at the current moment if the level states of the differential lines of the USB device interface are both low at the current moment and within a second set time period before the current moment; otherwise, determine that the USB device interface is connected to the USB device at the current moment, and the first set time period is greater than the second set time period; a connection status updating unit, configured to update the recorded connection status of the USB device interface terminal using the determined connection status of the USB device interface terminal at the current moment, wherein the connection status includes connected and disconnected; a device information recording unit, configured to record device information of the USB device connected to the USB device interface terminal when it is determined that the USB device interface terminal is currently connected to the USB device; a determination processing unit configured to, when the recorded connection status of the USB device interface is updated from unconnected to connected, determine whether device information of a USB device connected to the USB device interface exists within a third set time period before a current moment; If the device information does not exist, initializing the USB device connected to the USB device interface; If device information exists, determine whether the device information of the USB device currently connected to the USB device interface is consistent with the existing device information; if the two device information are consistent, obtain the data transmission task and data transmission progress corresponding to the device information, and perform data transmission based on the data transmission task and the data transmission progress; if the two device information are inconsistent, perform a reset operation, and initialize the USB device connected to the USB device interface.
5. A USB device hot plug detection device, characterized in that: include: memory and processor; The memory is used to store programs; The processor is used to execute the program to implement the various steps of the USB device hot plug detection method according to any one of claims 1 to 3.
6. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the USB device hot plug detection method according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Method and device of detecting connection of USB (Universal Serial Bus) equipment and host and USB equipment
CN108628789A