Communication method and device of USB protocol, storage medium and USB host

By initializing and managing four basic endpoint queues in the USB host controller, the problems of increased logic complexity and cost of USB host controller design in the prior art are solved, and compatibility with multiple slave devices and efficient data transmission are achieved.

CN120144518APending Publication Date: 2025-06-13ZHUHAI HUGE IC CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510287376.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-12
Publication Date
2025-06-13

AI Technical Summary

Technical Problem

While pursuing compatibility, existing USB host controller designs face problems such as increased logic complexity and increased chip costs.

Method used

By initializing 4 basic endpoint queues (interrupt transmission queue, synchronous transmission queue, batch transmission queue and control transmission queue), the queue data is dynamically managed to achieve flexible communication with many different types of slave devices.

Benefits of technology

It reduces the logic complexity and chip cost of USB host controllers, improves data transmission efficiency and system reliability, and supports the endpoint connection requirements of multiple slave devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120144518A_ABST
    Figure CN120144518A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a communication method and device of a USB protocol, a storage medium and a USB host, and relates to the field of communication. According to the method, four basic endpoint queues (interrupt, synchronization, batch and control transmission queues) are initialized, and empty queue data are created for each queue, so that communication between the USB host and the USB slave is managed. When a pipeline creation or data transmission request of an application layer is received, the scheme can generate or update queue data and add the queue data into a corresponding queue. The queue data comprises key information such as a state flag bit, a transceiving flag bit, an equipment address, an endpoint address, a data address and a data length. When an SOF time slot signal arrives, according to the scheme, a queue is polled according to the priority, queue head data is analyzed, and the data transmission direction is determined according to a receiving and transmitting flag bit. Through the mode, the USB host can flexibly communicate with various slave devices, meanwhile, the occupation of endpoint resources is reduced, and the logic complexity and the chip cost of the controller are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communications, and in particular to a USB protocol communication method, device, storage medium and USB host. Background Art

[0002] With the rapid development of information technology, the Universal Serial Bus (USB), as a widely used interface standard, has penetrated into various fields of computers and peripheral devices. USB technology not only supports high-speed data transmission, but also has convenient features such as hot plugging and plug-and-play, making it the preferred solution for connecting various electronic devices. Modern USB controller designs tend to integrate multiple endpoints to meet the needs of composite devices, which may contain multiple functions such as storage, communication, audio and video processing, etc.

[0003] In the USB communication architecture, the transmission of information depends on the USB communication pipe established directly between the master and the slave through the endpoints. As a USB slave device, its function and the required communication path are relatively fixed, so it usually has a clear endpoint configuration scheme and quantity requirements. These slave devices predefine the endpoint set required for data exchange with the host according to their respective design specifications, thereby simplifying the design complexity of the slave end.

[0004] However, for a USB host, the situation is quite different. The host needs to be able to communicate with many different types of slave devices, which may have different endpoint configurations and requirements. Therefore, the USB host controller faces a greater challenge when designing: it needs to be flexible enough to support the endpoint connection requirements of different slave devices. This means that the host controller must reserve or dynamically allocate a sufficient number of endpoint resources to ensure smooth communication with any slave device.

[0005] Currently, the mainstream approach to solving this problem is to design a USB host controller with a large number of endpoint resources. Although this approach can ensure compatibility with various slave devices, it also brings significant side effects. On the one hand, increasing the number of endpoints means that the logic complexity of the USB controller needs to be increased, which directly leads to an increase in the difficulty of controller design; on the other hand, the additional logic circuit will also occupy more chip area, thereby increasing the production cost of the chip.

[0006] In summary, the existing USB host controller design, while pursuing compatibility, also faces problems such as increased logic complexity and rising chip costs. Therefore, how to effectively optimize the design of the USB host controller, reduce unnecessary logic and area overhead, and reduce chip costs while ensuring compatibility with various slave devices has become a key issue that needs to be solved in the current development of USB technology. Summary of the Invention

[0007] The embodiments of the present application provide a communication method, apparatus, storage medium and USB host for the USB protocol, which can solve the problem of high hardware cost of the USB host controller in the prior art. The technical solutions are as follows:

[0008] In a first aspect, the embodiments of the present application provide a communication method for the USB protocol, and the method includes:

[0009] After startup, traverse all USB slaves attached to the USB host, initialize 4 endpoints, and create an empty queue for each of the 4 endpoints; the 4 queues are: an interrupt transfer queue, an isochronous transfer queue, a bulk transfer queue, and a control transfer queue;

[0010] Monitor the application layer;

[0011] Determine whether a pipe creation request is received from the application layer; the pipe creation request is used to establish a new USB communication pipe between the USB host and the first USB slave;

[0012] If so, generate queue data, and query the corresponding queue in the preset 4 queues according to the transfer type of the USB communication pipe, and add the generated queue data to the queue; the generated queue data includes: a status flag bit indicating an invalid state, a transceiver flag bit, the device address of the first USB slave, the endpoint address of the first USB slave, a data address, and a data length;

[0013] If not, determine whether a data sending request is received from the application layer; the data sending request is used to instruct the USB host to send data to the second USB host;

[0014] If so, query the corresponding queue in the preset 4 queues according to the transfer type of the data to be sent, and search for the corresponding queue data in the queried queue according to the endpoint address and device address of the second USB host, modify the status flag bit in the searched queue data to a valid state, and update the data address and data length in the searched queue data according to the data address and data length of the data to be sent;

[0015] If not, determine whether a data receiving request is received from the application layer, and the data receiving request is used to instruct the USB host to receive data from the third USB host;

[0016] If it is yes, query the corresponding queue in the preset 4 queues according to the transmission type of the data to be received, search for the corresponding queue data in the queried queue according to the endpoint address and device address of the third USB host, modify the status flag bit in the searched queue data to the valid state, and update the data address and data length in the searched queue data according to the storage address and data length of the data to be received;

[0017] If it is no, continue to execute the step of monitoring the application layer;

[0018] When the SOF time slot signal is detected, poll the 4 queues according to the preset priority, take out the queue head data of the polled queue, and parse the queue head data to obtain: status flag bit, transceiver flag bit, device address, endpoint address, data address and data length; judge whether the parsed status flag bit is in the valid state. If it is yes, determine the transceiver direction according to the parsed transceiver flag bit. If the transceiver direction is reception, receive data from the corresponding USB slave according to the parsed device address and endpoint address, and store the received data according to the parsed data length and storage address; if the transceiver direction is transmission, read the data to be transmitted according to the parsed data address and data length, and send the read data to be transmitted to the USB slave corresponding to the parsed port address and device address.

[0019] In a second aspect, an embodiment of the present application provides a communication device for a USB protocol, and the device includes:

[0020] An initialization unit, configured to, after startup, traverse all USB slaves connected to the USB host, initialize 4 endpoints, and create an empty queue for each of the 4 endpoints; the 4 queues are respectively: an interrupt transfer queue, an isochronous transfer queue, a bulk transfer queue, and a control transfer queue;

[0021] The application layer monitoring unit is used to monitor the application layer, determine whether a pipeline creation request from the application layer is received. The pipeline creation request is used to establish a new USB communication pipeline between the USB host and the first USB slave. If yes, queue data is generated, and the corresponding queue is queried from the preset 4 queues according to the transmission type of the USB communication pipeline, and the generated queue data is added to the queue. The generated queue data includes: a status flag bit indicating an invalid state, a transceiver flag bit, the device address of the first USB slave, the endpoint address of the first USB slave, a data address, and a data length. If no, it is determined whether a data sending request from the application layer is received. The data sending request is used to instruct the USB host to send data to the second USB host. If yes, the corresponding queue is queried from the preset 4 queues according to the transmission type of the data to be sent, and the corresponding queue data is searched in the queried queue according to the endpoint address and device address of the second USB host. The status flag bit in the searched queue data is modified to a valid state, and the data address and data length in the searched queue data are updated according to the data address and data length of the data to be sent. If no, it is determined whether a data receiving request from the application layer is received. The data receiving request is used to instruct the USB host to receive data from the third USB host. If yes, the corresponding queue is queried from the preset 4 queues according to the transmission type of the data to be received, and the corresponding queue data is searched in the queried queue according to the endpoint address and device address of the third USB host. The status flag bit in the searched queue data is modified to a valid state, and the data address and data length in the searched queue data are updated according to the storage address and data length of the data to be received. If no, the step of monitoring the application layer is continued to be executed.

[0022] The isochronous transfer unit is used to, when detecting the arrival of the SOF time slot signal, poll the 4 queues according to the preset priority, take out the queue header data of the polled queue, and parse the queue header data to obtain: a status flag bit, a transceiver flag bit, a device address, an endpoint address, a data address, and a data length. It is determined whether the parsed status flag bit is in a valid state. If yes, the transceiver direction is determined according to the parsed transceiver flag bit. If the transceiver direction is receive, data is received from the corresponding USB slave according to the parsed device address and endpoint address, and the received data is stored according to the parsed data length and storage address. If the transceiver direction is send, the data to be sent is read according to the parsed data address and data length, and the read data to be sent is sent to the USB slave corresponding to the parsed port address and device address.

[0023] In a third aspect, an embodiment of the present application provides a computer storage medium. The computer storage medium stores multiple instructions, and the instructions are suitable for being loaded and executed by a processor to perform the above method steps.

[0024] In a fourth aspect, an embodiment of the present application provides a USB host, which may include: a processor and a memory; wherein, the memory stores a computer program, and the computer program is adapted to be loaded and executed by the processor to perform the above method steps.

[0025] The beneficial effects brought by the technical solutions provided in some embodiments of the present application at least include:

[0026] Through technical effects in multiple aspects such as optimizing endpoint resource management, improving flexibility and compatibility, simplifying design complexity, enhancing data transmission efficiency, and improving system reliability, the problems faced by the USB host controller design in pursuing compatibility, such as increased logical complexity and rising chip costs, are effectively solved. This solution not only reduces the production cost of the chip, but also improves the performance and reliability of the USB host controller. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0028] Figure 1 is a schematic structural diagram of a USB communication system provided by an embodiment of the present application;

[0029] Figure 2 is a schematic flowchart of a communication method of a USB protocol provided by an embodiment of the present application;

[0030] Figure 3 is a schematic structural diagram of a communication device of a USB protocol provided by the present application;

[0031] Figure 4 is a schematic structural diagram of a USB host provided by the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0032] To make the objectives, technical solutions, and advantages of the present application clearer, the following will further describe the embodiments of the present application in detail with reference to the drawings.

[0033] As Figure 1 shown, the USB communication system may include: a USB host, a USB slave, and a USB HUB (USB hub).

[0034] Among them, the USB slave can be connected to the USB host through a USB HUB or directly to the USB host. The USB host usually refers to a computer or a device with a USB controller, which can initiate a USB connection and manage data transmission. The USB slave refers to various USB devices connected to the USB host, such as USB storage devices, USB network cards, etc. The USB hub is used to expand the connection ability of the USB host, through which more USB devices can be connected to the USB bus.

[0035] Among them, the USB host starts and initializes the USB connection, and identifies the USB slaves connected to the USB hub. The USB host identifies and configures the connected USB slave devices through the USB hub. Once the device is identified and configured, the USB host can perform data read and write operations with the USB slave through the USB hub. The USB host is responsible for managing and controlling all connected USB slaves, and communicating and exchanging data through the USB hub.

[0036] With this structure, the USB host can connect and manage multiple USB slave devices, and expand the connection ability through the USB hub, realizing flexible device connection and data transmission.

[0037] It should be understood that Figure 1 the numbers of the USB host, USB slave, and USB HUB in

[0038] are only illustrative. According to the implementation requirements, they can be any number. Figure 2 Figure 1 The communication method of the USB protocol provided by the embodiment of the present application will be introduced in detail below in conjunction with the attached

[0039] Figure 2 Please refer to Figure 2

[0040] which is a schematic flowchart of a communication method of the USB protocol provided by the embodiment of the present application. As

[0041] S201. After startup, traverse all USB slaves attached to the USB host, initialize 4 endpoints, and create an empty queue for each of the 4 endpoints; the 4 queues are: the interrupt transfer queue, the isochronous transfer queue, the bulk transfer queue, and the control transfer queue.

[0041] Among them, after the USB host powers on or resets, the internal control logic starts running, initializes the hardware interface and software driver, and prepares to communicate with the USB slave. The USB host sends specific detection signals or commands through its USB interface to scan and identify all connected USB slaves. After each USB slave receives the detection signal, it responds and sends its device descriptor, including information such as device type, manufacturer, and product serial number. The USB host receives and parses these descriptors, and establishes and maintains a list of connected USB slaves. For each identified USB slave, the USB host initializes 4 logical endpoints (such as endpoints 0, 1, 2, and 3) according to its device descriptor and configuration descriptor. These endpoints are the basic units of USB communication and are used for data sending and receiving. Each endpoint has a unique address and attributes, such as transfer type, direction, and maximum packet size.

[0042] The USB host creates an empty queue for each endpoint to store pending data transfer requests. These queues are divided into four types: interrupt transfer queue, isochronous transfer queue, bulk transfer queue, and control transfer queue, corresponding to the four transfer types of USB respectively. Each queue contains several queue entries, and each queue entry is used to store a specific data transfer request.

[0043] S202, Monitor the application layer.

[0044] Among them, the USB host continuously monitors requests from the upper-layer application through its application layer interface (such as API or driver interface). These requests include creating a new pipe, sending data, receiving data, or querying device status, etc.

[0045] S203, Determine whether a pipe creation request from the application layer is received; the pipe creation request is used to establish a new USB communication pipe between the USB host and the first USB slave.

[0046] Among them, the USB host checks its receive buffer to see if there is a pipe creation request from the application layer. If the request is received, the USB host parses the request content and extracts the device address, endpoint address of the USB slave for which the pipe needs to be established, and the type of the pipe (such as control pipe, interrupt pipe, etc.).

[0047] S204, If yes, generate queue data, and query the corresponding queue in the preset 4 queues according to the transfer type of the USB communication pipe, and add the generated queue data to the queue; the generated queue data includes: a status flag bit indicating an invalid state, a transceiver flag bit, the device address of the first USB slave, the endpoint address of the first USB slave, the data address, and the data length.

[0048] Among them, the USB host generates corresponding queue data items according to the request content, including a status flag (initially set to "invalid"), a transceiver flag (set according to the pipe type), the device address of the target USB slave, the endpoint address, the data address (initially empty or set to the default address), and the data length (initially set to 0 or the default value). The USB host queries the corresponding queue in the preset 4 queues according to the type of the pipe (such as control, interrupt, isochronous, bulk). The generated queue data item is added to the end of the queried queue.

[0049] For example: Suppose the application layer requests to create a control pipe for communicating with endpoint 0 of a USB slave with a device address of 0x01. The USB host will generate a queue data item, add it to the end of the control transfer queue, and set the status flag to "invalid", the transceiver flag to "send" (assuming the control pipe is mainly used for the host to send commands to the slave), the device address to 0x01, the endpoint address to 0, and the data address and data length are initialized to the default values.

[0050] S205. If the answer is no, determine whether a data sending request from the application layer is received; the data sending request is used to instruct the USB host to send data to the second USB host.

[0051] Among them, the USB host checks its receive buffer to see if there is a data sending request from the application layer. If the request is received, the USB host parses the request content and extracts information such as the device address of the target USB slave, the endpoint address, the address and length of the data to be sent, etc.

[0052] S206. If the answer is yes, query the corresponding queue in the preset 4 queues according to the transfer type of the data to be sent, and search for the corresponding queue data in the queried queue according to the endpoint address and device address of the second USB host. Modify the status flag in the searched queue data to the valid state, and update the data address and data length in the searched queue data according to the data address and data length of the data to be sent.

[0053] Among them, the USB host queries the corresponding queue in the preset 4 queues according to the transfer type of the data to be sent (such as control, interrupt, isochronous, bulk). In the queried queue, the USB host searches for the corresponding queue data item according to the device address and endpoint address of the target USB slave. If a matching queue data item is found, continue to process; otherwise, return an error or execute other error handling logic. The USB host modifies the status flag in the searched queue data item to "valid", indicating that the data transfer request has been activated. Update the data address and data length fields in the queue data item according to the address and length of the data to be sent.

[0054] For example: Assume that the application layer requests to send a piece of data to endpoint 1 of a USB slave with a device address of 0x01. The USB host will search for the queue data item with a device address of 0x01 and an endpoint address of 1 in the bulk transfer queue. After finding it, it will modify its status flag to "valid" and update the data address and data length fields according to the address and length of the data to be sent.

[0055] S207. If the answer is no, determine whether a data reception request from the application layer is received. The data reception request is used to instruct the USB host to receive data from a third USB host.

[0056] Among them, the USB host checks its reception buffer to see if there is a data reception request from the application layer. If the request is received, the USB host parses the request content and extracts information such as the device address of the source USB slave, the endpoint address, and the storage address and length of the received data.

[0057] S208. If the answer is yes, query the corresponding queue in the preset 4 queues according to the transfer type of the data to be received, and search for the corresponding queue data in the queried queue according to the endpoint address and device address of the third USB host. Modify the status flag in the searched queue data to the valid state, and update the data address and data length in the searched queue data according to the storage address and data length of the data to be received.

[0058] Among them, the USB host queries the corresponding queue in the preset 4 queues according to the transfer type of the data to be received. In the queried queue, the USB host searches for the corresponding queue data item according to the device address and endpoint address of the source USB slave. If a matching queue data item is found, continue the processing; otherwise, return an error or execute other error handling logic. The USB host modifies the status flag in the searched queue data item to "valid", indicating that the data reception request has been activated. Update the data address and data length fields in the queue data item according to the storage address and length of the received data.

[0059] For example: Assume that the application layer requests to receive a piece of data from endpoint 2 of a USB slave with a device address of 0x02 and store the data in a specified memory address. The USB host will search for the queue data item with a device address of 0x02 and an endpoint address of 2 in the interrupt transfer queue. After finding it, it will modify its status flag to "valid" and update the data address and data length fields according to the storage address and length of the received data.

[0060] Among them, if the USB host does not receive any data sending or receiving requests, it will continue to monitor the application layer, that is, continue to execute the steps of S202, waiting for new requests to arrive. This is usually a loop or event-driven process, and the USB host will continuously check its receive buffer to respond to requests from the application layer.

[0061] S209. When a SOF time slot signal arrives, poll 4 queues according to a preset priority, take out the queue header data of the polled queue, and parse the queue header data to obtain: status flag bit, transceiver flag bit, device address, endpoint address, data address, and data length; determine whether the parsed status flag bit is in a valid state. If so, determine the transceiver direction according to the parsed transceiver flag bit. If the transceiver direction is receive, receive data from the corresponding USB slave according to the parsed device address and endpoint address, and store the received data according to the parsed data length and storage address; if the transceiver direction is send, read the data to be sent according to the parsed data address and data length, and send the read data to be sent to the USB slave corresponding to the parsed port address and device address.

[0062] Among them, the USB host continuously monitors the signals on the USB bus. When a SOF (Start of Frame) time slot signal arrives, it indicates the start of a new frame. The SOF signal is a periodic signal of the USB bus, used to synchronize the communication between the host and the slave. The USB host polls 4 queues according to a preset priority, and sequentially checks the queue header data items (i.e., the first data item in the queue) of each queue. The priority can be determined according to factors such as transmission type, device address, and endpoint address. The USB host parses the queue header data item and extracts information such as status flag bit, transceiver flag bit, device address, endpoint address, data address, and data length. The USB host determines whether the parsed status flag bit is "valid". If so, continue to process the queue header data item; otherwise, skip the queue header data item and continue to poll the next queue. According to the parsed transceiver flag bit, the USB host determines the transceiver direction of the data. If it is the receive direction, perform the receive operation; if it is the send direction, perform the send operation. If it is the receive direction, the USB host sends a receive data request to the corresponding USB slave according to the parsed device address and endpoint address. When the slave responds and sends data, the USB host receives the data and stores the data at the specified memory address according to the parsed data address and data length. If it is the send direction, the USB host reads the data to be sent according to the parsed data address and data length. Then, send the read data to be sent to the USB slave corresponding to the parsed device address and endpoint address.

[0063] For example: Assume that during the polling process, the USB host discovers that the status flag bit of the queue header data item in the control transfer queue is "valid" and the transmit / receive flag bit is "transmit". The USB host will read the data to be transmitted according to the data address and data length, and then send the data to the USB slave corresponding to the device address and endpoint address specified in the queue header data item. If the transmit / receive flag bit is "receive", the USB host will send a receive data request to the specified device address and endpoint address and wait for the response and data transmission from the slave.

[0064] It should be noted that the first USB slave, the second USB slave, and the third USB slave in this embodiment can be the same USB slave or different USB slaves, which is specifically determined according to the actual transmission requirements.

[0065] Among them, the SOF (Start Of Frame) time slot signal is generated periodically at intervals of 1 millisecond (ms), rather than 1 second. This characteristic ensures time synchronization and frame division in USB communication. The SOF packet marks the start of each frame, and all USB devices synchronize to the same time reference by parsing the SOF packet. It contains frame number information, which is used by the device to identify the sequence number of the current frame, thereby enabling synchronous communication.

[0066] Furthermore, after the USB host receives data from the USB slave, it first parses the data packet to extract key information such as the data length and storage address. Store the data according to the data length and storage address. Determine how much storage space needs to be allocated for the received data according to the parsed data length. According to the parsed storage address, store the received data accurately in the specified memory location. This step ensures the correct storage of the data and provides a basis for subsequent data processing and use. Before or after storing the data, data integrity verification can be performed, such as checksum, CRC check, etc., to ensure that the received data is not damaged or lost. If the data integrity verification fails, error handling can be performed, such as requesting retransmission of the data, recording error logs, etc. After the data is successfully stored and (optionally) passes the integrity verification, the USB host sends a receive success feedback message to the corresponding USB slave. The receive success feedback message can be a simple acknowledgment signal, such as an ACK (Acknowledgment) packet, indicating that the data has been successfully received and stored. This step is crucial for the reliability and stability of USB communication. It ensures that the USB slave knows that the data it sent has been successfully received, so that subsequent operations or data transmissions can be carried out.

[0067] Further, during the USB communication process, first, the received instruction or data packet is parsed to extract the port address, device address of the target USB slave, and the data length of the data to be sent. According to the parsed data length, the corresponding data to be sent is read from the memory. The read data to be sent is sent to the USB slave corresponding to the parsed port address and device address through the USB bus. After sending the data, the USB host starts timing and waits to receive a successful reception feedback message (such as an ACK packet) from the USB slave. Within a preset duration (such as the timeout time specified by the USB protocol), the USB host determines whether it has received the successful reception feedback message returned by the corresponding USB slave. If the successful reception feedback message returned by the corresponding USB slave is not received within the preset duration, the data to be sent is retransmitted according to the preset number of retransmissions. Setting of the number of retransmissions: The preset number of retransmissions is usually defined by the USB protocol or the device manufacturer to ensure the reliability of communication. For example, in USB control transfers, the number of retransmissions is usually limited to 3 times. During the retransmission process, the USB host will resend the previously unacknowledged data packets. After each retransmission, the USB host will wait again for the successful reception feedback message and decide whether to continue retransmitting according to the situation of the feedback message. If the successful reception feedback message is still not received within the preset number of retransmissions, the USB host may take other error handling measures, such as recording error logs, notifying the upper-layer application, etc. In some cases, the USB host may abandon the data transfer task or attempt to communicate with other USB slaves. If the successful reception feedback message is successfully received within the preset duration, it indicates that the data transfer is successful, and the USB host can continue to process the subsequent data transfer tasks. The USB host should continuously monitor the status of data transfer and record the results of each data transfer (such as success, failure, number of retransmissions, etc.). These records are of great significance for subsequent data analysis, error troubleshooting, and performance optimization.

[0068] After the USB host sends data to the USB slave, it waits to receive a successful reception feedback message to confirm the reliability of data transfer. If the feedback message is not received within the preset duration, the data to be sent is retransmitted according to the preset number of retransmissions. The retransmission mechanism is one of the important means to ensure the reliability of data transfer in USB communication, and it can effectively reduce the problem of data loss caused by transmission errors or interference.

[0069] In some embodiments of the present application, the priority sizes of the preset 4 queues are: interrupt transfer queue > isochronous transfer queue > bulk transfer queue > control transfer queue.

[0070] Among them, during the USB communication process, in order to effectively manage different types of data transfer requests, the USB host usually presets four queues, which are respectively used to handle interrupt transfers, isochronous transfers, bulk transfers, and control transfers. According to the USB protocol and actual application requirements, the priority levels of these four queues are usually set as: interrupt transfer queue > isochronous transfer queue > bulk transfer queue > control transfer queue.

[0071] The interrupt transfer queue has the highest priority and is used to handle data transfer requests from devices that need to be responded to in a timely manner, such as input devices like keyboards and mice. The data generated by these devices is small and non - continuous, but it needs to be transmitted to the host in a timely manner so that the host can respond promptly. Interrupt transfers use a timed polling method to send and receive data, and the host asks the device at set time intervals whether there is data to be transferred. This transfer method ensures the real - time nature of the data, but has low requirements for data volume and transmission bandwidth.

[0072] The isochronous transfer queue has the second - highest priority and is used to handle data transfer requests for scenarios with extremely high requirements for real - time performance but relatively low requirements for data accuracy, such as cameras, USB speakers, etc. Isochronous transfers provide a guaranteed bandwidth and interval time for the transfer of streaming data with strict timing and strong fault tolerance. It does not retry data errors and does not respond to handshake packets at the hardware level. Therefore, there may be certain errors in the transmitted data, but for some applications with extremely high requirements for real - time performance, occasional errors are tolerable.

[0073] The bulk transfer queue has a lower priority and is used to handle large - volume data transfer requests, such as reading a large amount of data from a device or writing a large amount of data to a device, such as printers, USB flash drives, etc. Bulk transfers ensure error - free data transfer between the host and the device through error detection and retry. It is mainly used in scenarios where there are low requirements for the real - time performance of data transfer but high requirements for reliability. When accessing the USB bus, bulk transfers have the lowest priority compared to other transfer types.

[0074] The control transfer queue has the lowest priority and is used to handle operation requests related to device configuration and management, such as setting up USB devices, reading device information, and initializing devices. Control transfers are two - way transfers and are a transfer method that all USB devices must support. It has high reliability and priority to ensure that the normal configuration and management of the device can be carried out first. However, compared with data transfer, the data volume of control transfers is usually small, and the requirements for real - time performance are also not high.

[0075] In some embodiments of the present application, the length of the status flag bit in the queue data item is 1 bit, the length of the transceiver flag bit is 1 bit, the length of the device address is 7 bits, the length of the endpoint address is 4 bits, the length of the data address is equal to the data length of the address bus, and the data length is 16 bits or 32 bits.

[0076] Among them, the length of the status flag bit is 1 bit, which is used to identify the status of the queue data item, such as valid or invalid. When the status flag bit is "valid", it means that the data item is currently waiting to be processed; when the status flag bit is "invalid", it means that the data item is currently not in use or has been processed.

[0077] The length of the transceiver flag bit is 1 bit, which is used to identify the direction of data transmission, that is, send or receive. When the transceiver flag bit is "send", it means that the data item is used to send data; when the transceiver flag bit is "receive", it means that the data item is used to receive data.

[0078] The length of the device address is 7 bits, which is used to identify the device in USB communication. Each USB device will be assigned a unique address during the enumeration process, and this address is used to identify the target of data transmission or reception during communication. The maximum value that can be represented by 7-bit binary is 127, so the USB host can manage up to 127 USB devices at most.

[0079] The length of the endpoint address is 4 bits, which is used to identify the endpoints inside the USB device. Each USB device can have multiple endpoints, and each endpoint is used to process different types of data transmission. The maximum value that can be represented by 4-bit binary is 15, so each USB device can have up to 16 endpoints at most.

[0080] The length of the data address is equal to the data length of the address bus, which is used to identify the target address of data transmission. The length of the data address depends on the width of the system address bus. For example, the data address length of a 32-bit address bus is 32 bits.

[0081] The length of the data length is 16 bits or 32 bits, which is used to identify the length of the data field. The specific value of the data length depends on the transmission type and speed mode of USB communication. For example, in the USB 2.0 protocol, the maximum packet length of a low-speed device is 8 bytes, the maximum packet length of a full-speed device is 1023 bytes, and the maximum packet length of a high-speed device is 1024 bytes. The length of the data length field can be 16 bits or 32 bits, depending on the system design and implementation.

[0082] In some embodiments of the present application, the reading of the data to be sent according to the parsed data address and data length, and the sending of the read data to be sent to the USB slave corresponding to the parsed port address and device address include:

[0083] Read the data to be sent according to the parsed data address and data length, perform integrity verification on the read data to be sent, and after the verification passes, send the data to be sent to the USB slave corresponding to the parsed port address and device address.

[0084] Among them, during the USB communication process, first parse the data address and data length fields in the received data packet. The data address is used to indicate the location of the data to be sent in the memory, and the data length is used to indicate the number of bytes of the data to be sent. According to the parsed data address and data length, read the corresponding data to be sent from the memory. Perform integrity verification on the read data to be sent to ensure the accuracy and integrity of the data. Common verification methods include parity check, cyclic redundancy check (CRC), etc. The parity check is used to check whether the number of "1"s in the data is odd or even, and an additional parity bit is attached during transmission. The receiving party verifies the integrity of the data by calculating the number of "1"s again. The cyclic redundancy check (CRC) is used to calculate the checksum of the data through polynomial division and attach it to the checksum field during transmission. The receiving party uses the same algorithm to calculate the checksum of the received data and compares it with the sent checksum to verify the integrity of the data.

[0085] If the verification fails, it indicates that an error may have occurred during data transmission or reading. At this time, error handling can be performed, such as resending requests, recording error logs, etc. If the integrity verification passes, send the data to be sent to the USB slave corresponding to the parsed port address and device address. In USB communication, the port address is used to identify the physical or logical port on the USB host, and the data is sent to the USB slave through this port. The device address is used to identify a specific device in USB communication, and the data is sent to the USB slave with this device address. Before sending the data, the data packet can also be formatted according to the requirements of the USB protocol, such as adding a synchronization field, packet identifier field (PID), address field, endpoint field, data field, and checksum field, etc. After receiving the data, the USB slave usually sends a handshake packet to the USB host to confirm the correct reception of the data. If the USB host does not receive the handshake packet or the handshake packet indicates a reception failure within the preset time, error handling can be performed, such as resending the data, recording the error log, or taking other remedial measures.

[0086] During the USB communication process, reading the data to be sent according to the parsed data address and data length is a crucial first step. Performing integrity verification on the read data to be sent can ensure the accuracy and integrity of the data, reducing the risk of transmission errors and data loss. After the verification passes, the data to be sent is sent to the USB slave corresponding to the parsed port address and device address to complete the data transmission process. During the entire transmission process, transmission confirmation and error handling are also required to ensure the reliability and stability of data transmission.

[0087] The present application has the following beneficial effects:

[0088] By initializing only 4 basic endpoint queues (interrupt transfer queue, isochronous transfer queue, bulk transfer queue, and control transfer queue), this solution significantly reduces the number of reserved or dynamically allocated endpoints, thereby reducing the logical complexity of the USB host controller. This method avoids the need to configure a large number of dedicated endpoints for each possible slave device, reduces the chip area occupancy, and thus reduces the production cost.

[0089] Despite the reduced number of endpoints, through the queue management method, this solution can still support communication with multiple different types of slave devices. By dynamically adding and managing pipe creation requests and data transfer requests in the queue, the USB host can flexibly adapt to the endpoint configurations and requirements of different slave devices.

[0090] Through a unified queue management mechanism, this solution simplifies the design process of the USB host controller. The structured design of the queue data (including status flag bits, transmit and receive flag bits, device address, endpoint address, data address, and data length) makes the data transmission process clearer and more controllable. Through the priority polling mechanism, this solution can ensure that critical data (such as control transfer data) is processed in a timely manner, improving the efficiency and response speed of data transmission. When the SOF (Start of Frame) time slot signal arrives, polling the queue according to the preset priority ensures the orderliness and timeliness of data transmission. Through the effective management of the status flag bits, this solution can accurately track the status of data transmission, avoiding chaos and loss during the data transmission process. The introduction of the transmit and receive flag bits makes the data transmission direction clear, further enhancing the accuracy and reliability of data transmission.

[0091] The following is an embodiment of the device of the present application, which can be used to execute the method embodiment of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the method embodiment of the present application.

[0092] Please refer to Figure 3, which shows a schematic structural diagram of a communication device of the USB protocol provided by an exemplary embodiment of the present application, hereinafter referred to as device 3. This device 4 can be implemented as all or part of a USB host through software, hardware, or a combination of both. Device 3 includes: an initialization unit 301, an application layer monitoring unit 302, and an isochronous transfer unit 303.

[0093] The initialization unit 301 is configured to, after startup, traverse all USB slaves connected to the USB host, initialize 4 endpoints, and create an empty queue for each of the 4 endpoints; the 4 queues are respectively: an interrupt transfer queue, an isochronous transfer queue, a bulk transfer queue, and a control transfer queue;

[0094] The application layer monitoring unit 302 is configured to monitor the application layer; determine whether a pipe creation request is received from the application layer; the pipe creation request is used to establish a new USB communication pipe between the USB host and the first USB slave; if so, generate queue data, and query the corresponding queue in the preset 4 queues according to the transfer type of the USB communication pipe, and add the generated queue data to the queue; the generated queue data includes: a status flag bit indicating an invalid state, a transceiver flag bit, the device address of the first USB slave, the endpoint address of the first USB slave, a data address, and a data length; if not, determine whether a data sending request is received from the application layer; the data sending request is used to instruct the USB host to send data to the second USB host; if so, query the corresponding queue in the preset 4 queues according to the transfer type of the data to be sent, and search for the corresponding queue data in the queried queue according to the endpoint address and device address of the second USB host, modify the status flag bit in the searched queue data to a valid state, and update the data address and data length in the searched queue data according to the data address and data length of the data to be sent; if not, determine whether a data receiving request is received from the application layer, the data receiving request is used to instruct the USB host to receive data from the third USB host; if so, query the corresponding queue in the preset 4 queues according to the transfer type of the data to be received, and search for the corresponding queue data in the queried queue according to the endpoint address and device address of the third USB host, modify the status flag bit in the searched queue data to a valid state, and update the data address and data length in the searched queue data according to the storage address and data length of the data to be received; if not, continue to execute the step of monitoring the application layer;

[0095] The synchronous transmission unit 303 is used to poll 4 queues according to the preset priority when detecting the arrival of the SOF time slot signal, extract the queue head data of the polled queue, and parse the queue head data to obtain: status flag bit, transceiver flag bit, device address, endpoint address, data address, and data length; determine whether the parsed status flag bit is in a valid state, if so, determine the transceiver direction according to the parsed transceiver flag bit, if the transceiver direction is reception, receive data from the corresponding USB slave according to the parsed device address and endpoint address, and store the received data according to the parsed data length and storage address; if the transceiver direction is transmission, read the data to be transmitted according to the parsed data address and data length, and send the read data to be transmitted to the USB slave corresponding to the parsed port address and device address.

[0096] In one or more possible embodiments, the priority sizes of the preset 4 queues are: interrupt transfer queue > synchronous transfer queue > bulk transfer queue > control transfer queue.

[0097] In one or more possible embodiments, the length of the status flag bit is 1 bit, the length of the transceiver flag bit is 1 bit, the length of the device address is 7 bits, the length of the endpoint address is 4 bits, the length of the data address is equal to the data length of the address bus, and the data length is 16 bits or 32 bits.

[0098] In one or more possible embodiments, the step of reading the data to be transmitted according to the parsed data address and data length, and sending the read data to be transmitted to the USB slave corresponding to the parsed port address and device address includes:

[0099] Read the data to be transmitted according to the parsed data address and data length, perform integrity verification on the read data to be transmitted, and after the verification passes, send the data to be transmitted to the USB slave corresponding to the parsed port address and device address.

[0100] In one or more possible embodiments, the SOF time slot signal is generated periodically at intervals of 1 millisecond.

[0101] In one or more possible embodiments, the step of storing the received data according to the parsed data length and storage address further includes:

[0102] Send a reception success feedback message to the corresponding USB slave.

[0103] In one or more possible embodiments, the step of sending the read data to be transmitted to the USB slave corresponding to the parsed port address and device address further includes:

[0104] If a reception success feedback message returned by the corresponding USB slave is not received within a preset duration, the data to be sent is retransmitted according to the preset number of retransmission times.

[0105] It should be noted that when the device 4 provided in the above embodiment executes the communication method of the USB protocol, only the division of the above functional modules is used for illustration. In practical applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the above functions. In addition, the communication device of the USB protocol provided in the above embodiment and the embodiment of the communication method of the USB protocol belong to the same concept. The implementation process is detailed in the method embodiment and will not be repeated here.

[0106] The serial numbers of the embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.

[0107] The embodiment of the present application also provides a computer storage medium, which can store multiple instructions. The instructions are suitable for being loaded and executed by a processor to perform the method steps of the embodiment as described above Figure 2 The specific execution process can refer to Figure 2 the specific description of the embodiment shown and will not be elaborated here.

[0108] The present application also provides a computer program product. The computer program product stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the communication method of the USB protocol as described in each of the above embodiments.

[0109] Please refer to Figure 4 which is a schematic structural diagram of a USB host provided by an embodiment of the present application. As Figure 4 shown, the USB host 400 may include: at least one processor 401, at least one USB interface 403, a memory 404, and at least one communication bus 402.

[0110] Among them, the communication bus 402 is used to realize the connection and communication between these components.

[0111] Among them, the USB interface 403 may optionally include a standard USB2.0 interface or a USB3.0 interface or other types of USB interfaces.

[0112] Among them, the processor 401 may include one or more processing cores. The processor 401 connects various parts within the entire USB host 400 through various interfaces and lines. By running or executing instructions, programs, code sets, or instruction sets stored in the memory 404, and by invoking the data stored in the memory 404, it executes various functions of the USB host 400 and processes data. Optionally, the processor 401 may be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), or programmable logic array (PLA). The processor 401 may integrate one or a combination of several of a central processing unit (CPU), a graphics processing unit (GPU), and a modem, etc. Among them, the CPU mainly processes the operating system, user interface, application programs, etc.; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communication. It can be understood that the above-mentioned modem may not be integrated into the processor 401 and may be implemented separately by a single chip.

[0113] Among them, the memory 404 may include random access memory (RAM) and may also include read-only memory. Optionally, the memory 404 includes a non-transitory computer-readable storage medium. The memory 404 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 404 may include a program storage area and a data storage area. Among them, the program storage area may store instructions for implementing the operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store the data involved in the above-mentioned various method embodiments. Optionally, the memory 404 may also be at least one storage device located far from the aforementioned processor 401. As Figure 4 shown, the memory 404, as a computer storage medium, may include an operating system, a network communication module, a user interface module, and application programs.

[0114] In Figure 4 the USB host 400 shown, the processor 401 may be used to invoke the application programs stored in the memory 404 and specifically execute as Figure 2The method shown, for the specific process, reference can be made to Figure 2 as shown, which will not be elaborated here.

[0115] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above various methods. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory, or a random access memory, etc.

[0116] The above-disclosed are only the preferred embodiments of the present application. Of course, the scope of the rights of the present application cannot be limited thereby. Therefore, equivalent changes made according to the claims of the present application still fall within the scope covered by the present application.

Claims

1. A communication method of USB protocol, characterized in that: include: After startup, it traverses all USB slaves connected to the USB host, initializes four endpoints, and creates an empty queue for each of the four endpoints; the four queues are: interrupt transmission queue, synchronous transmission queue, bulk transmission queue, and control transmission queue; Monitoring application layer; Determining whether a pipe creation request from the application layer is received; the pipe creation request is used to establish a new USB communication pipe between the USB host and the first USB slave; If yes, generate queue data, and query the corresponding queue in the preset four queues according to the transmission type of the USB communication channel, and add the generated queue data to the queue; The generated queue data includes: a status flag indicating an invalid state, a transceiver flag, a device address of the first USB slave, an endpoint address of the first USB slave, a data address and a data length; If not, determining whether a data sending request from the application layer is received; the data sending request is used to instruct the USB host to send data to the second USB host; If yes, query the corresponding queue in the preset four queues according to the transmission type of the data to be sent, and search the corresponding queue data in the queried queue according to the endpoint address and the device address of the second USB host, modify the status flag in the searched queue data to a valid state, and update the data address and data length in the searched queue data according to the data address and data length of the data to be sent; If not, determining whether a data receiving request from the application layer is received, the data receiving request being used to instruct the USB host to receive data from a third USB host; If yes, query the corresponding queue in the preset four queues according to the transmission type of the data to be received, and search the corresponding queue data in the queried queue according to the endpoint address and the device address of the third USB host, modify the status flag in the searched queue data to a valid state, and update the data address and data length in the searched queue data according to the storage address and data length of the data to be received; If no, continue to perform the steps of monitoring the application layer; When the arrival of the SOF time slot signal is detected, four queues are polled according to the preset priority, the queue head data of the polled queue is taken out, and the queue head data is parsed to obtain: status flag, transceiver flag, device address, endpoint address, data address and data length; it is determined whether the parsed status flag is in a valid state, if so, the transceiver direction is determined according to the parsed transceiver flag, if the transceiver direction is receiving, data is received from the corresponding USB slave according to the parsed device address and endpoint address, and the received data is stored according to the parsed data length and storage address; if the transceiver direction is sending, the data to be sent is read according to the parsed data address and data length, and the read data to be sent is sent to the USB slave corresponding to the parsed port address and device address.

2. The method according to claim 1, characterized in that The priority levels of the four preset queues are: interrupt transmission queue > synchronous transmission queue > bulk transmission queue > control transmission queue.

3. The method according to claim 1 or 2, characterized in that: The length of the status flag is 1 bit, the length of the transmit and receive flag is 1 bit, the length of the device address is 7 bits, the length of the endpoint address is 4 bits, the length of the data address is equal to the data length of the address bus, and the data length is 16 bits or 32 bits.

4. The method according to claim 3, characterized in that: The method of reading the data to be sent according to the parsed data address and data length, and sending the read data to be sent to the USB slave corresponding to the parsed port address and device address, comprises: The data to be sent is read according to the parsed data address and data length, and the integrity check is performed on the read data to be sent. After the check passes, the data to be sent is sent to the USB slave corresponding to the parsed port address and device address.

5. The method according to claim 1, 2 or 4, characterized in that: The SOF time slot signal is generated periodically at intervals of 1 millisecond.

6. The method according to claim 5, characterized in that The step of storing the received data according to the parsed data length and storage address also includes: Send a successful reception feedback message to the corresponding USB slave.

7. The method according to claim 6, characterized in that Send the read data to be sent to the USB slave corresponding to the parsed port address and device address, and also include: If the receiving success feedback message returned by the corresponding USB slave is not received within the preset time, the data to be sent is resent according to the preset number of retransmissions.

8. A USB protocol communication device, characterized in that: include: The initialization unit is used to traverse all USB slaves connected to the USB host after startup, initialize four endpoints, and create an empty queue for each of the four endpoints; the four queues are: interrupt transmission queue, synchronous transmission queue, bulk transmission queue and control transmission queue; An application layer monitoring unit, used for monitoring the application layer; determining whether a pipe creation request from the application layer is received; the pipe creation request is used for establishing a new USB communication pipe between the USB host and the first USB slave; if yes, generating queue data, and querying a corresponding queue in four preset queues according to a transmission type of the USB communication pipe, and adding the generated queue data to the queue; The generated queue data includes: a status flag indicating an invalid state, a transceiver flag, a device address of the first USB slave, an endpoint address of the first USB slave, a data address and a data length; if not, determining whether a data transmission request from the application layer is received; the data transmission request is used to instruct the USB host to send data to the second USB host; if yes, querying a corresponding queue in the preset four queues according to the transmission type of the data to be sent, and searching for corresponding queue data in the queried queue according to the endpoint address and device address of the second USB host, modifying the status flag in the searched queue data to a valid state, and searching for corresponding queue data in the queried queue data according to the data address and data length of the data to be sent. The method comprises: updating the data address and data length in the searched queue data according to the length; if not, determining whether a data receiving request from the application layer is received, wherein the data receiving request is used to instruct the USB host to receive data from the third USB host; if yes, querying the corresponding queue in the preset four queues according to the transmission type of the data to be received, and searching the corresponding queue data in the queried queue according to the endpoint address and device address of the third USB host, modifying the status flag in the searched queue data to a valid state, and updating the data address and data length in the searched queue data according to the storage address and data length of the data to be received; if not, continuing to execute the step of monitoring the application layer; The synchronous transmission unit is used to detect the arrival of the SOF time slot signal, poll four queues according to the preset priority, take out the queue head data of the polled queue, and parse the queue head data to obtain: status flag, transceiver flag, device address, endpoint address, data address and data length; judge whether the parsed status flag is in a valid state, if so, determine the transceiver direction according to the parsed transceiver flag, if the transceiver direction is receiving, receive data from the corresponding USB slave according to the parsed device address and endpoint address, and store the received data according to the parsed data length and storage address; if the transceiver direction is sending, read the data to be sent according to the parsed data address and data length, and send the read data to be sent to the USB slave corresponding to the parsed port address and device address.

9. A computer storage medium, characterized in that: The computer storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 7.

10. A USB host, characterized in that: include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps as claimed in any one of claims 1 to 7.

Citation Information

Cited By

  • Program loading system and method based on USB interface

    CN121209992A

  • A program loading system and method based on USB interface

    CN121209992B