Data transmission method and device based on USB2.0 protocol, storage medium and USB host
By increasing Max Packet Size and cross-frame transmission mechanism, the data transmission of USB2.0 protocol is optimized, and the problem of inefficiency caused by Max Packet Size limitation and protocol overhead is solved, and higher data transmission rate and bandwidth utilization are achieved.
Patent Information
- Application Number
- CN202510511472.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-08-01
AI Technical Summary
In the Full Speed mode of the USB2.0 protocol, bandwidth resources are seriously wasted due to the inefficiency of transmission due to Max Packet Size limitations and protocol overhead.
By increasing the actual Max Packet Size and configuring the maximum number of cross-frames, combining the cross-frame transmission mechanism, optimizing the packet structure and transmission method, reducing protocol overhead, and making full use of frame resources.
It significantly improves data transmission rate and bandwidth utilization, reduces protocol overhead, enhances system flexibility and stability, and avoids packet loss.
Smart Images

Figure CN120407487A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular, to a data transmission method, apparatus, storage medium, and USB host based on the USB2.0 protocol. Background Art
[0002] USB (Universal Serial Bus), as an interface standard widely used for data transmission between computers and external devices, has become an indispensable communication interface in modern electronic devices due to its advantages such as plug-and-play, high transmission rate, and wide compatibility. As an important milestone in the development of USB technology, the USB2.0 protocol has a theoretical maximum transmission rate of up to 480 Mbps (60 MB / s), which has greatly promoted the development of high-speed data transmission applications. However, in practical applications, the transmission efficiency of the USB2.0 protocol is restricted by various factors, among which the Max Packet Size (maximum packet size) limitation and the resulting protocol overhead are one of the key factors affecting the transmission efficiency.
[0003] According to the USB2.0 protocol specification, the Max Packet Size in the Full Speed mode is strictly limited to 64 bytes. Although this limitation simplifies the protocol design and reduces the complexity of hardware implementation, it also brings significant protocol overhead problems. Specifically, in the USB2.0 Full Speed mode, each 64-byte data packet transmission requires an additional 13-byte protocol interaction overhead, which includes necessary information such as a synchronization field, PID (Packet Identifier), CRC (Cyclic Redundancy Check) for data content verification, and SOF (Start of Frame). Although these additional information is crucial for ensuring the reliability and correctness of data transmission, it also occupies valuable bus bandwidth resources to a certain extent.
[0004] Due to the limitation of the Max Packet Size and the existence of protocol overhead, the actual transmission efficiency in the USB2.0 Full Speed mode is much lower than the theoretical maximum value. Calculating with an additional 13-byte protocol overhead for each 64-byte data packet, the total size of each data transmission is 77 bytes (64 + 13 bytes). In a frame (Microframe, each SOF frame in the USB2.0 Full Speed mode contains one frame), theoretically, data can be transmitted up to 19 times at most (limited by the frame structure and scheduling mechanism of the USB2.0 protocol), and the corresponding data transmission rate is 64 * 19 = 1216 Byte / ms, which is converted to 1216000 Byte / s (about 1.16MB / s). This value is much lower than the theoretical maximum transmission rate of the USB2.0 protocol, indicating that there is significant bandwidth waste in the existing technical solutions. Specifically, since each data packet needs to carry 13 bytes of protocol overhead, while the actual effective data transmission is only 64 bytes, it results in about 37 bytes (calculated proportionally. Here, with a 64-byte data packet and 13-byte overhead, the actual effective payload of each 64-byte data packet is 64 bytes. However, due to the existence of 13-byte protocol overhead, the actual effective data transmitted each time is reduced, wasting some bus bandwidth.
[0005] To improve the transmission efficiency, it is necessary to further study reducing protocol overhead, optimizing the data packet structure, or adopting a more efficient data encoding method to make full use of the bus bandwidth resources. Summary of the Invention
[0006] The embodiments of the present application provide a data transmission method, device, storage medium, and USB host based on the USB2.0 protocol, which can solve the problem of low USB data transmission rate in the prior art. The technical solutions are as follows:
[0007] In the first aspect, the embodiments of the present application provide a data transmission method based on the USB2.0 protocol, and the method includes:
[0008] Configure the actual Max Packet Size according to the default Max Packet Size corresponding to the USB2.0 protocol type, and configure the maximum number of cross-frames; wherein, the actual Max Packet Size is greater than the default Max Packet Size;
[0009] Generate one or more data packets of the actual Max Packet Size according to the data to be transmitted;
[0010] Receive a data transmission request; the data transmission request is used to transmit a data packet of the actual Max Packet Size;
[0011] Determine whether the remaining time interval of the current frame is sufficient to transmit the data packet;
[0012] If yes, transmit the data packet in the current frame;
[0013] If no, continue to determine whether the current cross-frame cumulative quantity is equal to 0;
[0014] If yes, do not respond to the data transmission request, reset the current cross-frame cumulative quantity to the maximum cross-frame quantity, and the USB host sends a SOF packet at the end of the remaining time interval of the current frame;
[0015] If no, transmit the data packet in a cross-frame manner in the remaining time interval of the current frame and the next frame, and subtract 1 from the current cross-frame cumulative quantity; wherein, at the end of the current frame, the USB host does not send a SOF packet.
[0016] In a second aspect, an embodiment of the present application provides a data transmission device based on the USB2.0 protocol. The device includes:
[0017] A configuration unit, configured to configure the actual Max Packet Size according to the default Max Packet Size corresponding to the USB2.0 protocol type, and configure the maximum cross-frame quantity; wherein, the actual Max Packet Size is greater than the default Max Packet Size;
[0018] A splitting unit, configured to generate one or more data packets with the size of the actual Max Packet Size according to the data to be transmitted;
[0019] A receiving unit, configured to receive a data transmission request; the data transmission request is used to transmit a data packet with the size of an actual Max Packet Size;
[0020] A judging unit, configured to judge whether the remaining time interval of the current frame is sufficient to transmit the data packet;
[0021] A transmitting unit, configured to, if the judgment result of the judging unit is yes, transmit the data packet in the current frame;
[0022] A statistical unit, configured to, if the judgment result of the judging unit is no, continue to judge whether the current cross-frame cumulative quantity is equal to 0;
[0023] A resetting unit, configured to, if the judgment result of the statistical unit is yes, not respond to the data transmission request, reset the current cross-frame cumulative quantity to the maximum cross-frame quantity, and the USB host sends a SOF packet at the end of the remaining time interval of the current frame;
[0024] The transmission unit is further configured to, if the judgment result of the statistical unit is negative, transmit data packets in a cross-frame manner in the remaining time interval of the current frame and the next frame, and decrement the current cross-frame cumulative count by 1; wherein, at the end of the current frame, the USB host does not send a SOF packet.
[0025] In a third aspect, an embodiment of the present application provides a computer storage medium storing multiple instructions adapted to be loaded and executed by a processor to perform the above method steps.
[0026] 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 adapted to be loaded and executed by the processor to perform the above method steps.
[0027] The beneficial effects brought by the technical solutions provided by some embodiments of the present application at least include:
[0028] By setting the actual Max Packet Size to be greater than the USB2.0 protocol default value, the proportion of protocol overhead in each data packet is reduced, thereby increasing the proportion of effective data transmission. Under the same bandwidth condition, more effective data can be transmitted, significantly improving the data transmission rate. Allowing data packets to be continuously transmitted in multiple frames (including cross-frames) makes full use of frame resources and avoids bandwidth waste caused by the limitation of the number of transmissions within a single frame. By reasonably configuring the maximum cross-frame count, the complete transmission of data packets is ensured while optimizing bandwidth allocation.
[0029] When judging whether the remaining time interval of the current frame is sufficient to transmit a data packet, choose to transmit within the current frame or use the cross-frame method according to the actual situation. This dynamic allocation mechanism ensures the maximization of frame resource utilization and avoids the idle of bandwidth resources. During the cross-frame transmission process, by adjusting the current cross-frame cumulative count, it is achieved that no SOF packet is sent at the end of the current frame (only sent when the cross-frame cumulative count is reset), thereby reducing unnecessary protocol overhead and further improving bandwidth utilization.
[0030] According to specific application scenarios and requirements, the actual Max Packet Size and the maximum cross-frame count can be flexibly configured to adapt to different data transmission requirements. This flexibility enables the system to better handle various complex scenarios and improves the adaptability and stability of the system. Through the cross-frame transmission mechanism and reasonable cross-frame cumulative count management, the complete transmission of data packets is ensured, avoiding the problem of data packet loss caused by the limitation of the number of transmissions within a frame, and improving the reliability of data transmission.
[0031] By increasing the Max Packet Size and optimizing the cross-frame transmission mechanism, the protocol interaction overhead in each data packet is reduced, thus lowering the overall protocol processing burden of the system. Due to the improvement of data transmission efficiency and the optimization of resource utilization, the system can respond to data transmission requests faster, enhancing the overall performance of the system and the user experience.
[0032] In summary, through the flexible configuration of the actual Max Packet Size and the maximum number of cross frames, combined with the cross-frame transmission mechanism and the dynamic frame time allocation strategy, this technical solution significantly improves the data transmission efficiency and resource utilization rate under the USB2.0 protocol, while enhancing the flexibility and stability of the system and reducing the system overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] 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 the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0034] Figure 1 It is a schematic diagram of the architecture of the USB communication system provided by the embodiment of the present application;
[0035] Figure 2 It is a schematic flowchart of the data transmission method based on the USB2.0 protocol provided by the embodiment of the present application;
[0036] Figure 3 It is a schematic diagram of the timing of data transmission provided by the embodiment of the present application;
[0037] Figure 4 It is a schematic diagram of the structure of a data transmission device based on the USB2.0 protocol provided by the present application;
[0038] Figure 5 It is a schematic diagram of the structure of a USB host provided by the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0039] 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 in conjunction with the drawings.
[0040] As Figure 1 shown, the USB communication system may include: a USB host, a USB slave, and a USB HUB (USB hub).
[0041] 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.
[0042] 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 communicates and exchanges data through the USB hub.
[0043] With this structure, the USB host can connect and manage multiple USB slave devices, and expand the connection ability through the USB hub to achieve flexible device connection and data transmission.
[0044] It should be understood that Figure 1 the numbers of the USB host, USB slave, and USB HUB in
[0045] are only illustrative. According to the implementation requirements, they can be any number. Figure 2 Next, the data transmission method based on the USB2.0 protocol provided by the embodiments of the present application will be introduced in detail in combination with the attached Figure 1 figures. Among them, the data transmission device based on the USB2.0 protocol in the embodiments of the present application can be
[0046] the USB host shown in Figure 2 . Please refer to Figure 2 , which is a schematic flowchart of a data transmission method based on the USB2.0 protocol provided by the embodiments of the present application. As
[0047] shown, the method of the embodiments of the present application may include the following steps:
[0048] Among them, the USB host first obtains the corresponding default Max Packet Size value of this type from the protocol specification according to the USB2.0 protocol type. For example, for high-speed devices, the default Max Packet Size of the full-speed endpoint (Bulk endpoint) is 64 bytes.
[0049] According to system requirements or specific application scenarios, multiply the default Max Packet Size by a coefficient greater than 1 (such as 1.5, 2, etc.) to obtain the actual Max Packet Size. For example, if the default Max Packet Size is 64 bytes, after multiplying by the coefficient 2, the actual Max Packet Size becomes 128 bytes.
[0050] The USB host determines a suitable maximum number of cross frames based on factors such as system performance and real-time requirements of data transmission. This number represents the maximum number of frames allowed to cross during a data transmission process. For example, set the maximum number of cross frames to 3.
[0051] In some embodiments of the present application, the USB host displays a configuration interface on the USB host and configures the actual Max Packet Size and the maximum number of cross frames based on the configuration instructions of the user for the configuration interface.
[0052] Among them, after the USB host is connected to the USB host, the USB host detects a scenario where data transmission parameter configuration is required (such as the first connection, user actively triggers configuration, etc.). The USB host calls system resources and pops up a configuration interface on the display screen of the USB host.
[0053] Display the default Max Packet Size (the default value under the USB2.0 Full speed protocol is 64 bytes), and explain that the actual Max Packet Size is set based on the default value. Provide adjustable options, such as by means of a slider, a digital input box, etc., to allow the user to multiply the default Max Packet Size by 2 (i.e., set it to 128 bytes) or other appropriate multiples (depending on system support). Display an explanation of the impact of setting different actual Max Packet Sizes on data transmission performance, such as "Setting it to 128 bytes can improve transmission efficiency, but may increase the risk of transmission delay".
[0054] Provide preset options for the user to choose, such as 2, 3, 4, etc. Explain the meaning of each option, such as "Selecting 3 means allowing the packet to be transmitted across a maximum of 3 frames. A larger number of cross frames may improve the continuity of data transmission, but will increase the system resource occupancy". After the user completes the configuration, click the "Confirm" button to save the settings, and click the "Cancel" button to abandon this configuration.
[0055] The user interacts with the configuration interface through the input devices (such as touch screens, keyboards, mice, etc.) of the USB host. When the user adjusts the settings of the actual Max Packet Size and the maximum number of cross frames, the USB host transmits the user's operation instructions to the USB host in real time.
[0056] After receiving the user configuration instructions, the USB host parses the instructions to obtain the values of the actual MaxPacket Size and the maximum number of cross frames set by the user. Perform a legality check on the values input by the user. For example, check whether the actual MaxPacket Size is within the range supported by the system, and whether the maximum number of cross frames is a valid positive integer, etc.
[0057] According to the value of the actual Max Packet Size set by the user, the USB host updates the relevant parameters in the system. For example, modify the register settings of the USB controller to adjust the maximum transmission size of the data packet to the value specified by the user. Store the value of the maximum number of cross frames set by the user in the system configuration file or the relevant memory area. During subsequent data transmission, the USB host controls the cross-frame transmission behavior of the data packet according to this value.
[0058] If the parameter configuration is successful, the USB host displays a prompt message of "Configuration successful" on the configuration interface of the USB host. Some simple test functions can be provided to allow the user to verify whether the configuration takes effect. For example, send a test data packet and display the transmission situation of the data packet. If the parameter configuration fails, the USB host displays a prompt message of "Configuration failed" on the configuration interface and explains the reason for the failure, such as "The actual Max Packet Size setting exceeds the range supported by the system" "The maximum number of cross frames setting is invalid", etc. Allow the user to re-perform the configuration operation.
[0059] S202. Generate one or more data packets of the actual Max Packet Size according to the data to be transmitted.
[0060] Among them, the USB host obtains the complete data stream to be transmitted from the application layer software, memory buffer or other data sources. These data may be the file content generated by the user application, the data packets transmitted over the network, etc. For example, when the user transfers a local file to an external storage device through the USB interface, the USB host reads the data of the file from the file system of the operating system.
[0061] According to the size of the actual Max Packet Size, the data to be transmitted is initially divided into one or more data blocks. The size of each data block is as close as possible to the actual Max Packet Size, but the last data block may be smaller than the actual Max Packet Size. For example, if the length of the data to be transmitted is 500 bytes and the actual Max Packet Size is 128 bytes, then after initial division, 4 data blocks are obtained. The first 3 data blocks are 128 bytes in size, and the last data block is 116 bytes in size.
[0062] Judge the size of the last data block: After completing the initial division, check the size of the last data block.
[0063] Fill the last data packet:
[0064] Determine the filling method: According to the USB2.0 protocol specification or specific application requirements, determine the filling rule. Common filling methods include filling with all 0s, filling with all 1s, filling with a specific pattern (such as 0xFF), etc. For example, some devices may require filling with all 0s to ensure data compatibility and stability.
[0065] Perform the filling operation: If the last data block is smaller than the actual Max Packet Size, then according to the determined filling method, add filling bytes at the end of the data block to make its size equal to the actual Max Packet Size. In the above example, fill the last 116-byte data block with 12 bytes (128 - 116 = 12), and the size of the filled data packet is 128 bytes.
[0066] Add a packet header and a packet tail: For each divided and filled data packet, according to the USB2.0 protocol specification, add the corresponding packet header and packet tail information. The packet header usually contains a packet identifier (PID), address information, endpoint number, etc., which are used to identify the type of the data packet, the transmission direction, and the target device. The packet tail may contain check information, such as cyclic redundancy check (CRC), which is used to detect errors during data transmission. Combine the data content with the packet header and packet tail to generate a complete data packet that conforms to the USB2.0 protocol specification. These data packets are arranged in a certain order in the FIFO queue of the USB host's transmit buffer, waiting for subsequent transmission operations.
[0067] S203. Receive a data transmission request; the data transmission request is used to transmit a data packet of the actual Max Packet Size.
[0068] Among them, the USB host is in a continuous listening state, waiting to receive data transmission requests from USB devices or the application layer.
[0069] Parsing request: When receiving a data transfer request, the USB host parses the request content, takes out a data packet from the FIFO queue in S202, and determines that the request is for transferring a data packet of the actual Max Packet Size.
[0070] S204. Determine whether the remaining time interval of the current frame is sufficient to transfer the data packet.
[0071] Among them, the USB host obtains information such as the start time, end time, and used time of the current frame through the USB bus. Based on the start time and used time of the current frame, the remaining time of the current frame is calculated. According to the actual MaxPacket Size and the USB bus transfer rate (480 Mbps for high speed, 12 Mbps for full speed, 1.5 Mbps for low speed), the time required to transfer a data packet of the actual Max Packet Size is calculated. The remaining time of the current frame is compared with the time required to transfer the data packet to determine whether the remaining time is sufficient to transfer the data packet.
[0072] In some embodiments of the present application, determining whether the remaining time interval of the current frame is sufficient to transfer the data packet includes:
[0073] Calculate the transmission duration of the data packet according to the bus rate of the USB2.0 protocol type, the actual Max Packet Size, and the protocol overhead size; the transmission duration = ((MPS + P) * 8) / S, where MPS is the actual Max Packet Size, P is the protocol overhead size, and S represents the bus rate;
[0074] Compare the transmission duration of the data packet with the length of the remaining time interval of the current frame;
[0075] If the length of the remaining time interval of the current frame is greater than the transmission duration of the data packet, it is determined that it is sufficient to transfer the data packet;
[0076] Otherwise, it is not sufficient to transfer the data packet.
[0077] Among them, the transmission duration calculation formula is: transmission duration = ((MPS + P) * 8) / S.
[0078] Among them, MPS is the actual Max Packet Size (actual maximum data packet size), that is, the data packet size configured by the user according to system requirements. In this scenario, it is set to a specific value through user configuration for calculation. P is the protocol overhead size. The protocol overhead includes additional information such as the synchronization field, PID (packet identifier), and CRC for data content verification. These information will increase the total size of the data packet. Assume that the protocol overhead P in this scenario is 13 bytes (104 bits). S represents the bus rate. Under the USB2.0 Full speed protocol, the bus rate is 12Mbps (12000000 bits per second).
[0079] Taking the actual Max Packet Size of 128 bytes (1024 bits) as an example, substitute MPS = 128 bytes (1024 bits), P = 13 bytes (104 bits), and S = 12000000 bits per second into the formula. First, calculate the total size of MPS + P: 128 + 13 = 141 bytes, and convert it to bits as 141 * 8 = 1128 bits. Then calculate the transmission duration: 1128 / 12000000 = 0.000094 seconds, that is, 0.094 milliseconds. If calculated according to MPS = 512 bytes (4096 bits) in the example, (512 + 13) * 8 / 12000000 = 0.35 milliseconds. This example is used to show the calculation method under different MPSs.
[0080] The USB host obtains the start time, end time, and used time information of the current frame in real time through the internal clock and frame synchronization mechanism. Calculate the remaining time interval length of the current frame. For example, if the total duration of the current frame is 1 millisecond and 0.6 milliseconds have been used, then the remaining time interval length is 1 - 0.6 = 0.4 milliseconds. Compare the calculated data packet transmission duration with the remaining time interval length of the current frame. If the remaining time interval length of the current frame is greater than the data packet transmission duration, it is determined that the remaining time of the current frame is sufficient to transmit the data packet. For example, the data packet transmission duration is 0.094 milliseconds, and the remaining time interval length of the current frame is 0.4 milliseconds, 0.4 > 0.094, so it is determined that the remaining time of the current frame is sufficient to transmit the data packet. Conversely, if the remaining time interval length of the current frame is less than or equal to the data packet transmission duration, it is determined that the remaining time of the current frame is not sufficient to transmit the data packet.
[0081] S205. If it is yes, transmit the data packet in the current frame.
[0082] The USB host obtains the data packet to be transmitted from the cache.
[0083] Data encoding: According to the USB2.0 protocol specification, encode the data packet, including adding the synchronization field, PID (packet identifier), data content, CRC (cyclic redundancy check), etc.
[0084] Data transmission: The USB host sends the encoded data packet to the USB device via the USB bus. During the transmission, according to the timing requirements of the USB bus, the transmission rate and timing of the data are controlled. At the end of the current frame, the USB host sends a SOF packet.
[0085] S206. If the answer is no, continue to determine whether the current cross-frame cumulative quantity is equal to 0.
[0086] Among them, the USB host obtains the current cross-frame cumulative quantity from the internal register or cache, compares the current cross-frame cumulative quantity with 0, and determines whether it is equal to 0.
[0087] S207. If the answer is yes, do not respond to the data transmission request, reset the current cross-frame cumulative quantity to the maximum cross-frame quantity, and the USB host sends a SOF packet at the end of the remaining time interval of the current frame.
[0088] Among them, if the current cross-frame cumulative quantity is equal to 0, the USB host does not respond to this data transmission request, that is, does not transmit the data packet. Reset the current cross-frame cumulative quantity to the maximum cross-frame quantity configured in step S201. At the end of the remaining time interval of the current frame, the USB host sends a SOF (Start Of Frame) packet in accordance with the USB2.0 protocol specification to identify the start of a new frame.
[0089] S208. If the answer is no, transmit the data packet in a cross-frame manner in the remaining time interval of the current frame and the next frame, and subtract 1 from the current cross-frame cumulative quantity; among them, at the end of the current frame, the USB host does not send a SOF packet.
[0090] Among them, the USB host obtains the data packet to be transmitted from the cache. Encodes the data packet in accordance with the USB2.0 protocol specification. In the remaining time interval of the current frame, transmit as much data of the data packet as possible. If the remaining time of the current frame is not enough to transmit the entire data packet, leave the remaining data to be transmitted in the next frame. During the cross-frame transmission process, the USB host needs to precisely control the transmission timing of the data to ensure the correct connection of the data between different frames. At the end of the current frame, since the cross-frame method is used to transmit the data packet, the USB host does not send a SOF packet to avoid affecting the continuous transmission of the data. Subtract 1 from the current cross-frame cumulative quantity, indicating that a cross-frame transmission opportunity has been used.
[0091] For example: Refer to Figure 3 the shown timing diagram. The upper diagram is the timing diagram of the prior art for data transmission, and the lower diagram is the timing diagram of the present application for data transmission. It can be seen from Figure 3 that when the present application transmits the data packet, it spans two frames, and the USB host does not send a SOF packet at the end of the first frame.
[0092] The processes of S201 - S208 are illustrated by the following examples:
[0093] The USB host obtains the default Max Packet Size of 64 bytes according to the USB2.0 Full speed protocol specification. According to system requirements, the default Max Packet Size is multiplied by 2 to obtain the actual Max Packet Size of 128 bytes. Considering system performance and data transfer real-time performance, the maximum number of cross-frames is set to 3. The configuration of the actual Max Packet Size and the maximum number of cross-frames is completed to prepare for subsequent data transfer.
[0094] The USB host obtains 1500 bytes of data to be transmitted. The data is segmented with a size of 128 bytes. 1500 divided by 128 gives a quotient of 11 and a remainder of 92, that is, the size of the first 11 data packets is 128 bytes, and the size of the last data packet is 92 bytes. The last 92-byte data packet is filled. According to the all-0 filling rule, 36 bytes (128 - 92 = 36) of 0 are added to make its size become 128 bytes. 12 data packets with a size of 128 bytes are generated and stored in the send buffer.
[0095] The USB host is in a listening state, waiting to receive a data transfer request. When the application layer initiates a data transfer operation, the USB host receives a data transfer request for transmitting a 128-byte data packet. The USB host obtains the data transfer request and prepares for subsequent transfer judgment and operations.
[0096] The USB host obtains the start time, end time, and used time information of the current frame. The remaining time of the current frame is calculated. Assuming that the total duration of the current frame is 1 ms and 0.6 ms has been used, the remaining time is 0.4 ms. According to the transmission rate of USB2.0 Fullspeed of 12 Mbps (1.5 MB / s), the time required to transmit a 128-byte data packet is calculated. 128 bytes = 1024 bits, and the transmission time = 1024 bits / 12 Mbps ≈ 0.085 ms. Comparing the remaining time of 0.4 ms with the transmission time of 0.085 ms, it is concluded that the remaining time is sufficient to transmit the data packet. It is judged that the remaining time of the current frame is sufficient to transmit the data packet.
[0097] The USB host obtains a 128-byte data packet to be transmitted from the send buffer. According to the USB2.0 protocol specification, the data packet is encoded, adding a synchronization field, PID, data content, CRC, etc. The USB bus is controlled to send the encoded data packet to the USB device at a rate of 12 Mbps. A 128-byte data packet is successfully transmitted in the current frame.
[0098] Assume that during the previous data transmission, 2 cross-frame transmissions have been performed, and the current cross-frame cumulative count is 1. Compare the current cross-frame cumulative count 1 with 0. It is determined that the current cross-frame cumulative count is not equal to 0.
[0099] If the current cross-frame cumulative count is equal to 0, the USB host does not respond to this data transmission request. Reset the current cross-frame cumulative count to the maximum cross-frame count 3. At the end of the remaining time interval of the current frame, the USB host sends a SOF packet in accordance with the USB2.0 protocol specification to indicate the start of a new frame. Complete the operation of not responding to the request and parameter reset, and enter the new frame to wait for a new transmission opportunity.
[0100] Assume that the current data packet to be transmitted needs to be cross-frame transmitted due to insufficient remaining time in the current frame. Within the remaining 0.4 ms of the current frame, transmit as much data of the data packet as possible, for example, 80 bytes are transmitted (dynamically adjusted according to the actual bus rate and remaining time). The remaining 48 bytes of data are left to be transmitted in the next frame. During the cross-frame transmission, the USB host precisely controls the sending timing of the data to ensure the correct connection of the data between different frames. At the end of the current frame, the USB host does not send a SOF packet. Decrease the current cross-frame cumulative count by 1, changing from 1 to 0 (if continuing cross-frame, it will continue to decrease subsequently). Successfully transmit part of the data packet data in a cross-frame manner and update the cross-frame cumulative count. Transmit subsequent data packets (continue to complete the transmission of 1500 bytes of data).
[0101] Repeat the steps of S203 - S208 to sequentially transmit the remaining 11 128-byte data packets.
[0102] During the transmission, reasonably select to transmit in the current frame or use the cross-frame method according to the remaining time of the current frame and the situation of the cross-frame cumulative count. For example, when transmitting the second data packet, if the remaining time of the current frame is sufficient, transmit it in the current frame; if the remaining time is insufficient and the cross-frame cumulative count is not 0, use the cross-frame method to transmit. Successfully transmit 1500 bytes of data to the USB device through the USB2.0 Full speed bus according to the requirement that the actual Max Packet Size is 128 bytes, and follow the limit of the maximum cross-frame count of 3 during the transmission.
[0103] This technical solution proposes an optimization method based on the cross-frame transmission mechanism. By adjusting the maximum cross-frame count and increasing the Max Packet Size, it significantly reduces the occupation of bandwidth resources by protocol overhead and improves the actual data transmission rate.
[0104] The cross-frame transmission mechanism allows a single data packet to be dispersed and transmitted across multiple SOF frames, thereby making full use of frame resources and avoiding bandwidth waste caused by the limitation of the number of transmissions within a single SOF frame. In this technical solution, by setting the maximum number of cross frames, it is allowed for the data packet to be continuously transmitted across multiple SOF frames until the transmission is completed.
[0105] To further improve the transmission efficiency, this technical solution increases the Max Packet Size from 64 bytes to 512 bytes. This adjustment significantly reduces the proportion of protocol overhead in each data packet and increases the proportion of effective data transmission. At the same time, in combination with the cross-frame transmission mechanism, even if the number of transmissions within a single SOF frame decreases, the integrity of the data packet can be ensured through cross-frame transmission.
[0106] The maximum number of cross frames is set to 5: Under the condition that the physical layer rate is 7500 Byte / 5 frames (5 ms), that is, each SOF frame (actually the comprehensive calculation of multiple micro frames included within 5 ms, simplified as the SOF frame concept here for easy understanding) can be allocated an average transmission bandwidth of 1500 Byte. When the maximum number of cross frames is set to 5, it is allowed for the data packet to be continuously transmitted across 5 SOF frames. The maximum number of data transmissions within each SOF frame is 14 (limited by the total bandwidth and protocol overhead), and the total size of each data transmission is 512 + 13 = 525 Byte. However, considering the continuity of cross-frame transmission, the actual calculation is based on the effective data transmission volume within each SOF frame, that is, 512 * 14 = 7168 Byte (here is a simplified calculation, not strictly split into 14 times per frame, but calculated by dividing the total effective data volume by 5 frames to obtain the average effective data volume per frame and then multiplying by the theoretical upper limit of 14 times of transmission. In actual implementation, it needs to be allocated according to the specific scheduling algorithm), and the total effective data transmission volume within 5 SOF frames is 7168 * 5 / 5 (dividing by 5 and then multiplying by 5 here is only to illustrate that the total amount remains unchanged after equal division by frames. In fact, it is directly 7168 * "equivalent full-frame transmission times" (after considering cross frames) corresponding to the total amount of 5 frames logically, that is, 512 * 14 = 7168 Byte / frame (equivalent) * 5 frame logical transmission units (cross-frame integration) simplified as 512 * 14 / 5 * 5 (actually 512 * 14 directly corresponding to the total amount of 5-frame cross-frame transmission) = 1433600 Byte / 5 ms (converted to seconds) = 1433600 Byte / s (about 1.37 MB / s)). Compared with the 1216000 Byte / s of the existing technical solution, the actual application data rate has increased by approximately 17%.
[0107] When the maximum number of cross - frames is set to 3, the maximum amount of data that can be transmitted within each SOF frame is relatively reduced, but the cross - frame transmission mechanism can still ensure the complete transmission of data packets. At this time, the effective data transmission amount within each SOF frame is calculated in a similar way (considering cross - frames and bandwidth allocation). The total effective data transmission amount within 3 SOF frames is 512 * 14 * 3 / 5 (the concept of equal division of logical frames, actually the equivalent transmission amount of 3 frames after cross - frame integration) (simplified to directly calculate according to the transmission logic) ≈ 1365300 Byte / s (about 1.30MB / s, this is an approximate value, and the actual calculation needs to consider specific scheduling and bandwidth allocation). Compared with the existing technical solution, the actual application data rate is increased by about 12%.
[0108] Through the cross - frame transmission mechanism and the optimization method of increasing the Max Packet Size, this technical solution significantly improves the data transmission efficiency of the USB Full Speed mode. Compared with the existing technical solution, the actual application data rate is increased by 17% and 12% respectively, effectively reducing bandwidth waste and improving the overall performance of the system.
[0109] 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 the details not disclosed in the device embodiment of the present application, please refer to the method embodiment of the present application.
[0110] Please refer to Figure 4 , which shows a schematic structural diagram of a data transmission device based on the USB2.0 protocol provided by an exemplary embodiment of the present application, hereinafter referred to as device 4. The device 4 can be implemented as all or part of a USB host through software, hardware, or a combination of both. The device 4 includes: a configuration unit 401, a segmentation unit 402, a receiving unit 403, a judgment unit 404, a transmission unit 405, a statistical unit 406, and a reset unit 407.
[0111] The configuration unit 401 is used to configure the actual Max Packet Size according to the default Max Packet Size corresponding to the USB2.0 protocol type, and configure the maximum number of cross - frames; wherein, the actual Max Packet Size is greater than the default Max Packet Size;
[0112] The segmentation unit 402 is used to generate one or more data packets with the size of the actual Max Packet Size according to the data to be transmitted;
[0113] The receiving unit 403 is used to receive a data transmission request; the data transmission request is used to transmit a data packet with the size of the actual Max Packet Size;
[0114] A judging unit 404, configured to judge whether the remaining time interval of the current frame is sufficient to transmit the data packet;
[0115] A transmitting unit 405, configured to, if the judgment result of the judging unit is yes, transmit the data packet in the current frame;
[0116] A counting unit 406, configured to, if the judgment result of the judging unit is no, continue to judge whether the current cross-frame cumulative quantity is equal to 0;
[0117] A resetting unit 407, configured to, if the judgment result of the counting unit is yes, not respond to the data transmission request, reset the current cross-frame cumulative quantity to the maximum cross-frame quantity, and at the end of the remaining time interval of the current frame, the USB host sends a SOF packet;
[0118] The transmitting unit 405 is further configured to, if the judgment result of the counting unit is no, transmit the data packet in a cross-frame manner in the remaining time interval of the current frame and the next frame, and subtract 1 from the current cross-frame cumulative quantity; wherein, at the end of the current frame, the USB host does not send a SOF packet.
[0119] In one or more possible embodiments, the configuring the actual Max Packet Size according to the default Max PacketSize corresponding to the USB2.0 protocol type, and configuring the maximum cross-frame quantity includes:
[0120] Displaying a configuration interface on the USB host;
[0121] Configuring the actual Max Packet Size and the maximum cross-frame quantity based on a configuration instruction of a user on the configuration interface.
[0122] In one or more possible embodiments, the generating one or more data packets of the actual MaxPacket Size according to the data to be transmitted includes:
[0123] If the size of the data to be transmitted is greater than the actual Max Packet Size, splitting the data to be transmitted into multiple data packets of the actual Max Packet Size; wherein, the last packet divided is filled with 0.
[0124] In one or more possible embodiments, when the USB2.0 protocol type is USB2.0 Full speed, the configured actual Max Packet Size is 512 bytes.
[0125] In one or more possible embodiments, the judging whether the remaining time interval of the current frame is sufficient to transmit the data packet includes:
[0126] Calculate the transmission duration of the data packet based on the bus rate, actual Max Packet Size, and protocol overhead size of the USB2.0 protocol type; the transmission duration = ((MPS + P) * 8) / S, where MPS is the actual Max Packet Size, P is the protocol overhead size, and S represents the bus rate;
[0127] Compare the transmission duration of the data packet with the length of the remaining time interval of the current frame;
[0128] If the length of the remaining time interval of the current frame is greater than the transmission duration of the data packet, determine that it is sufficient to transmit the data packet;
[0129] Otherwise, it is not sufficient to transmit the data packet.
[0130] In one or more possible embodiments, perform an integrity check on the data packet, and after the integrity check passes, transmit the data packet.
[0131] In one or more possible embodiments, write one or more data packets of the actual Max Packet Size generated in sequence into the buffer.
[0132] It should be noted that when the device 4 provided in the above embodiments executes the data transmission method based on the USB2.0 protocol, only the above division of each functional module is used as an example. In actual applications, the above functions can be allocated to different functional modules as needed, 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 data transmission device based on the USB2.0 protocol provided in the above embodiments and the embodiments of the data transmission method based on the USB2.0 protocol belong to the same concept. The implementation process is detailed in the method embodiments and will not be repeated here.
[0133] The serial numbers of the above embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments.
[0134] The embodiments of the present application also provide a computer storage medium, which can store multiple instructions, and the instructions are suitable for being loaded and executed by a processor to perform the method steps of the above Figure 2 as shown in the embodiments, and the specific execution process can refer to Figure 2 the specific description of the embodiments shown, and will not be repeated here.
[0135] The present application also provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the data transmission method based on the USB2.0 protocol as described in the above various embodiments.
[0136] Please refer to Figure 5, This embodiment of the present application provides a schematic structural diagram of a USB host. As Figure 5 shown, the USB host 500 may include: at least one processor 501, at least one network interface 504, a user interface 503, a memory 505, and at least one communication bus 502.
[0137] Among them, the communication bus 502 is used to realize the connection and communication between these components.
[0138] Among them, the user interface 503 may include a display screen and a camera. Optionally, the user interface 503 may further include a standard wired interface and a wireless interface.
[0139] Among them, the network interface 504 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).
[0140] Among them, the processor 501 may include one or more processing cores. The processor 501 uses various interfaces and lines to connect various parts within the entire USB host 500, and by running or executing instructions, programs, code sets, or instruction sets stored in the memory 505, and by calling data stored in the memory 505, it executes various functions of the USB host 500 and processes data. Optionally, the processor 501 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 501 may integrate a combination of one or several of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes the operating system, the user interface, and 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 501 and may be implemented separately by a single chip.
[0141] Among them, the memory 505 may include a Random Access Memory (RAM), or may also include a Read-Only Memory. Optionally, the memory 505 includes a non-transitory computer-readable storage medium. The memory 505 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 505 may include a program storage area and a data storage area. Among them, the program storage area can 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 method embodiments, etc.; the data storage area can store the data involved in the above method embodiments. Optionally, the memory 505 may also be at least one storage device located far from the aforementioned processor 501. As Figure 5 shown, the memory 505 as a computer storage medium may include an operating system, a network communication module, a user interface module, and application programs.
[0142] In Figure 5 the USB host 500 shown, the user interface 503 is mainly used to provide an interface for the user to input and obtain the data input by the user; and the processor 501 can be used to call the application program stored in the memory 505 and specifically execute the method as Figure 2 shown. The specific process can be referred to Figure 2 shown, and will not be elaborated here.
[0143] Those of ordinary skill in the art can understand that all or part of the processes of implementing the above method 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 above method embodiments. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory or a random access memory, etc.
[0144] The foregoing disclosure is only for 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 data transmission method based on the USB2.0 protocol, characterized in that, Including: Configuring the actual Max Packet Size according to the default Max Packet Size corresponding to the USB2.0 protocol type, and configuring the maximum number of cross frames; wherein, the actual Max Packet Size is greater than the default Max Packet Size; Generating one or more data packets of the actual Max Packet Size according to the data to be transmitted; Receiving a data transmission request; the data transmission request is used to transmit a data packet of the actual Max Packet Size; Judging whether the remaining time interval of the current frame is sufficient to transmit the data packet; If so, transmitting the data packet in the current frame; If not, continuing to judge whether the current cumulative cross frame number is equal to 0; If so, not responding to the data transmission request, resetting the current cumulative cross frame number to the maximum number of cross frames, and the USB host sending a SOF packet at the end of the remaining time interval of the current frame; If not, transmitting the data packet in a cross frame manner in the remaining time interval of the current frame and the next frame, and subtracting 1 from the current cumulative cross frame number; wherein, at the end of the current frame, the USB host does not send a SOF packet.
2. The method according to claim 1, wherein The configuring the actual Max Packet Size according to the default Max Packet Size corresponding to the USB2.0 protocol type, and configuring the maximum number of cross frames includes: Displaying a configuration interface on the USB host; Configuring the actual Max Packet Size and the maximum number of cross frames based on the configuration instructions of the user on the configuration interface.
3. The method according to claim 1 or 2, characterized in that, The generating one or more data packets of the actual Max Packet Size according to the data to be transmitted includes: If the size of the data to be transmitted is greater than the actual Max Packet Size, splitting the data to be transmitted into multiple data packets of the actual Max Packet Size; wherein, the last packet divided is filled with 0.
4. The method according to claim 3, wherein When the USB2.0 protocol type is USB2.0 Full speed, the configured actual Max Packet Size is 512 bytes.
5. The method according to claim 1 or 2 or 4, characterized in that The judging whether the remaining time interval of the current frame is sufficient to transmit the data packet includes: Calculating the transmission duration of the data packet according to the bus rate, the actual Max Packet Size and the protocol overhead size of the USB2.0 protocol type; the transmission duration = ((MPS + P) * 8) / S, MPS is the actual Max Packet Size, P is the protocol overhead size, and S represents the bus rate; Comparing the transmission duration of the data packet with the length of the remaining time interval of the current frame; If the length of the remaining time interval of the current frame is greater than the transmission duration of the data packet, determining that it is sufficient to transmit the data packet; Otherwise, it is not sufficient to transmit the data packet.
6. The method according to claim 5, characterized in that, Performing integrity verification on the data packet, and transmitting the data packet after the integrity verification passes.
7. The method according to claim 1 or 2 or 4 or 6, characterized in that, Writing the generated one or more data packets of the actual Max Packet Size into the buffer in sequence.
8. A data transmission device based on the USB2.0 protocol, characterized in that, Including: Configuration unit, configured to configure the actual Max Packet Size according to the default Max Packet Size corresponding to the USB2.0 protocol type, and configure the maximum number of cross frames; wherein, the actual Max Packet Size is greater than the default Max Packet Size; Segmentation unit, configured to generate one or more data packets of the actual Max Packet Size according to the data to be transmitted; Receiving unit, configured to receive a data transmission request; the data transmission request is used to transmit a data packet of the actual Max Packet Size; Judgment unit, configured to judge whether the remaining time interval of the current frame is sufficient to transmit the data packet; Transmission unit, configured to, if the judgment result of the judgment unit is yes, transmit the data packet in the current frame; Statistics unit, configured to, if the judgment result of the judgment unit is no, continue to judge whether the current cumulative cross-frame number is equal to 0; Reset unit, configured to, if the judgment result of the statistics unit is yes, not respond to the data transmission request, reset the current cumulative cross-frame number to the maximum number of cross frames, and send a SOF packet by the USB host at the end of the remaining time interval of the current frame; The transmission unit is further configured to, if the judgment result of the statistics unit is no, transmit the data packet in a cross-frame manner in the remaining time interval of the current frame and the next frame, and subtract 1 from the current cumulative cross-frame number; wherein, at the end of the current frame, the USB host does not send a SOF packet.
9. A computer storage medium, characterized in that, The computer storage medium stores multiple instructions, and the instructions are suitable for being loaded and executed by a processor to perform the method steps of any one of claims 1 to 7.
10. A USB host, characterized in that, Comprising: A processor and a memory; wherein, the memory stores a computer program, and the computer program is suitable for being loaded and executed by the processor to perform the method steps of any one of claims 1 to 7.
Citation Information
Patent Citations
USB (universal serial bus) host controller and data transfer method thereof
CN102306133A
Optimizing response interframe space in communication systems
US20150138999A1
System and method for data compression based on data position in frames structure
US20220046114A1
System and method for USB controllers
US7035948B1