CN116601618A - USB-based communication method and device - Google Patents

USB-based communication method and device Download PDF

Info

Publication number
CN116601618A
CN116601618A CN202180079881.9A CN202180079881A CN116601618A CN 116601618 A CN116601618 A CN 116601618A CN 202180079881 A CN202180079881 A CN 202180079881A CN 116601618 A CN116601618 A CN 116601618A
Authority
CN
China
Prior art keywords
packet
data
usb
control transmission
transmitted
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202180079881.9A
Other languages
Chinese (zh)
Inventor
吴凯杰
伍东兴
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Publication of CN116601618A publication Critical patent/CN116601618A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Systems (AREA)

Abstract

The application discloses a communication method and device based on USB (universal serial bus), which are used for improving the reliability of USB control transmission. The USB peripheral device can respectively receive the establishment packets from the USB host at different times; the USB peripheral generates a unique number for each received establishment packet, associates each establishment packet with the corresponding number, and associates the corresponding number of each establishment packet with a data packet to be transmitted in control transmission initiated by each establishment packet; after the data transmission stage of any one control transmission starts, the USB peripheral device transmits the data packet to be transmitted in any one control transmission with the USB host after determining that the number corresponding to the data packet to be transmitted in any one control transmission is consistent with the number corresponding to the establishment packet latest received by the USB peripheral device. Therefore, the USB peripheral can ensure the corresponding relation between the data packet and the establishment packet, avoid the occurrence of the phenomenon of packet error transmission, and further improve the reliability of USB control transmission.

Description

USB-based communication method and device Technical Field
The present application relates to the field of computer technologies, and in particular, to a communication method and apparatus based on a universal serial bus (Universal Serial Bus, USB).
Background
The USB communication protocol adopts a master-slave structure to realize the communication between the USB host and the USB peripheral (or called USB slave device, USB peripheral device, USB device, etc.). All transactions (data streaming) on the USB bus are actively initiated by the USB host, while the USB peripheral passively receives and then processes the various commands (requirements) issued by the USB host. The USB communication protocol has 4 modes of transmitting data: control transfers, bulk transfers, interrupt transfers, and isochronous transfers. Wherein the control transmission is used for transmitting control, state, configuration and other information between the USB host and the USB peripheral. A complete control transfer consists of 2 to 3 phases: a setup phase, a data phase, and a status phase, wherein the data phase is optional. The control transmission is initiated by the USB host through the setup packet, and after the USB peripheral receives the setup packet sent by the USB host, the USB peripheral considers that a new control transmission starts.
In the prior art, the USB host often initiates a new control transmission when the previous control transmission is not completed, and the USB peripheral cannot identify the correspondence between setup packets and data packets/status packets in different control transmissions, resulting in a packet error transmission phenomenon.
Disclosure of Invention
The embodiment of the application provides a communication method and a communication device based on USB, which are used for improving the reliability of USB control transmission.
In a first aspect, a USB-based communication method is provided, which may be applied to a USB peripheral, which is communicatively connected to a USB host via a USB bus. The method comprises the following steps: the USB peripheral device receives the establishment packets from the USB host at different times respectively, wherein any one establishment packet is used for initiating a corresponding control transmission; the USB peripheral generates a unique number for each received establishment packet, associates each establishment packet with the corresponding number, and associates the corresponding number of each establishment packet with a data packet to be transmitted in control transmission initiated by each establishment packet; after the data transmission stage of any one control transmission starts, the USB peripheral device transmits the data packet to be transmitted in any one control transmission with the USB host after determining that the number corresponding to the data packet to be transmitted in any one control transmission is consistent with the number corresponding to the establishment packet latest received by the USB peripheral device.
The USB peripheral device in the embodiment of the application generates a unique number for each received setup packet, when the transmission of the data packet is prepared, the data packet is attached with the number of the establishment packet corresponding to the current pen control transmission, and the number verification is carried out before the data packet is transmitted, and the USB peripheral device starts to transmit the data packet only after the number corresponding to the data packet is consistent with the number of the newly received establishment packet, so that the corresponding relation between the data packet and the establishment packet can be ensured, the occurrence of error packet transmission is avoided, and the reliability of USB control transmission is further improved.
In a possible implementation, the USB peripheral device further needs to allocate at least one event buffer space before associating each setup packet with its corresponding number. Correspondingly, the USB peripheral device associating each setup packet with its corresponding number includes: and storing each establishment packet and the corresponding number thereof into the same event cache space.
In this embodiment, the USB peripheral device stores the setup packet in the event buffer space, so that the buffer space storing the setup packet (i.e. the event buffer space) and the buffer space storing the data packet (i.e. the data buffer space) are independent of each other, and do not interfere with each other, so that the packet loss phenomenon can be improved, and the reliability of USB control transmission is further improved.
In one possible implementation manner, a plurality of event buffer spaces are allocated to the USB peripheral device; the USB peripheral device can sequentially store a plurality of establishment packets received at different times and corresponding numbers into a plurality of allocated event cache spaces according to the time sequence of receiving the establishment packets.
In the embodiment, the USB peripheral allocates a plurality of event cache spaces at one time, so that the frequency of allocating caches by the USB peripheral can be reduced, namely, the software and hardware interaction of the USB peripheral is reduced, and the efficiency of USB control transmission is improved.
In one possible implementation manner, the USB peripheral device stores each setup packet and its corresponding number into the same event cache space, and may include: if at least one event buffer space exists in the idle event buffer space, storing each set-up packet and the corresponding number thereof in the idle event buffer space; if at least one event buffer space does not exist, using N establishment packets received at different times and corresponding numbers thereof to replace the establishment packets and corresponding numbers in N event buffer spaces from old to new stored historical numbers in the at least one event buffer space respectively, wherein N is a positive integer.
In this embodiment, the event buffer space of the USB peripheral device provides a coverage function, and when there is no free event buffer space, the new setup packet can be used to replace the old setup packet, so that the USB peripheral device can be guaranteed to receive and store the new setup packet at any time, and the occurrence of the packet loss phenomenon is better avoided.
In a possible implementation manner, if the at least one event buffer space does not have an idle event buffer space, the specific manner in which the USB peripheral device stores each setup packet and the number corresponding to each setup packet in the same event buffer space includes the following two:
In the mode 1, when at least one event buffer space does not exist, the USB peripheral device empties all the event buffer spaces in the at least one event buffer space; according to the time sequence of receiving the establishment packets, the USB peripheral sequentially stores N establishment packets received at different times and corresponding numbers into N emptied event cache spaces; wherein N is a positive integer. That is, the USB peripheral device empties all the event cache spaces at once, and then uses the emptied event cache spaces as newly allocated event cache spaces.
In the mode 2, when at least one event buffer space does not exist, the USB peripheral device empties one event buffer space in the at least one event buffer space after receiving an ith setup packet in the N setup packets; storing the ith establishment packet and the corresponding number into the emptied event cache space, and i is a positive integer from 1 to N; wherein N is a positive integer. That is, the USB peripheral device clears a history setup packet after each new setup packet is received.
It should be appreciated that in mode 2, the one event cache space may be any one of the at least one event cache space. Optionally, the one event cache space stores, before being emptied: the method comprises the steps of receiving the setup packet with the earliest time in the received setup packets, or receiving the smallest number or the largest number in numbers corresponding to the received setup packets.
It should be understood that the above two approaches are examples only and are not limiting.
In a possible implementation manner, after associating each setup packet with its corresponding number and before associating the number corresponding to each setup packet with a data packet to be transmitted in each setup packet initiated control transmission, the USB peripheral device further parses the content of each setup packet to obtain the size of the data packet to be transmitted in each setup packet initiated control transmission (optionally, the content and the direction of the data packet to be transmitted in each setup packet initiated control transmission may also be obtained); and distributing a data buffer space for the data packets to be transmitted in the control transmission initiated by each set-up packet according to the size of the data packets to be transmitted.
It should be appreciated that if the data phase of the arbitrary control transmission is an IN transmission; the USB peripheral may further prepare, according to the content, the data packet to be transmitted in any control transmission after allocating a data buffer space for the data packet to be transmitted in each control transmission initiated by the set-up packet according to the size and before starting a data phase of any control transmission, and store the data packet to be transmitted in the data buffer space. In this way, the reliability of the USB control transfer can be improved.
In one possible implementation, the USB peripheral device associating the number corresponding to each set-up packet with a data packet to be transmitted in a control transmission initiated by each set-up packet includes: for any set-up packet, the number corresponding to the set-up packet and the data packet to be transmitted in the control transmission initiated by the set-up packet are stored in a data buffer space allocated for the data packet to be transmitted in the control transmission initiated by the set-up packet.
The following describes the specific implementation process of the data phase of the control transmission IN the two scenarios of OUT transmission and IN transmission, respectively.
In the first case, the data phase of any one control transmission is OUT transmission (i.e. the USB host sends a data packet to the USB peripheral).
The USB peripheral equipment receives a data packet from a USB host; after the USB peripheral determines that the number corresponding to the data packet to be transmitted in any one control transmission is consistent with the number corresponding to the establishment packet latest received by the USB peripheral, the received data packet is stored in a data cache space allocated for the data packet to be transmitted in any one control transmission.
IN the second case, the data phase of any one control transmission is IN transmission (namely, the USB peripheral device sends a data packet to the USB host);
after the data phase of any control transmission starts, the USB peripheral receives a data packet request from the USB host, wherein the data packet request is used for requesting the USB peripheral to send a data packet; after determining that the number corresponding to the data packet to be transmitted in any control transmission is consistent with the number corresponding to the establishment packet latest received by the USB peripheral, reading the data packet from the data buffer space allocated for the data packet to be transmitted in any control transmission according to the data packet request, and sending the data packet to the USB host.
In one possible implementation, after associating the number corresponding to each setup packet with the data packet to be transmitted in the control transmission initiated by each setup packet, the USB peripheral device may further associate the number corresponding to each setup packet with the status packet in the control transmission initiated by each setup packet. After the end of the data stage of any one control transmission, the USB peripheral device receives a status packet request from the USB host (the status packet request is used for requesting the USB peripheral device to send a status packet), and after determining that the number corresponding to the status packet in any one control transmission is consistent with the number corresponding to the newly received setup packet by the USB peripheral device, the USB peripheral device sends the status packet to be transmitted in any one control transmission to the USB host.
In this embodiment, the USB peripheral performs the number verification before transmitting the status packet, and the USB peripheral starts to transmit the status packet only after the number corresponding to the status packet is consistent with the number of the latest received setup packet, so that the correspondence between the status packet and the setup packet can be ensured, the occurrence of packet error transmission is avoided, and the reliability of USB control transmission is further improved.
In a second aspect, a USB-based communication device is provided, the device being applicable to a USB peripheral, the USB peripheral being communicatively coupled to a USB host via a USB bus; the apparatus comprises means for performing the method described in the first aspect or any of the possible embodiments of the first aspect.
Illustratively, the apparatus may include: the USB interface module is used for respectively receiving the establishment packets from the USB host at different times, wherein any one establishment packet is used for initiating a corresponding control transmission; the interface control module is used for generating a unique number for each received establishment packet and associating each establishment packet with the corresponding number; the main control module is used for associating the number corresponding to each set-up packet with a data packet to be transmitted in control transmission initiated by each set-up packet; the interface control module is further configured to, after determining that a number corresponding to a data packet to be transmitted in any one control transmission is consistent with a number corresponding to an establishment packet received by the USB peripheral device after starting a data transmission stage of any one control transmission, control the USB interface module and the USB host to transmit the data packet to be transmitted in any one control transmission.
In a third aspect, a computer readable storage medium is provided, storing computer program instructions that, when executed, cause a method as described in the first aspect or any one of the possible implementation manners of the first aspect to be implemented.
In a fourth aspect, a chip is provided, which may be coupled to a memory, the chip being adapted to read and execute program instructions stored in the memory, implementing a method as described in the first aspect or any of the possible implementation manners of the first aspect.
In a fifth aspect, there is provided a computer program product having instructions stored therein which, when run on a computer, cause the computer to perform the method as described in the first aspect or any of the possible implementation manners of the first aspect.
Technical effects that may be achieved by the possible designs of any one of the second aspect to the fifth aspect and any one of the second aspect are described with reference to the technical effects that may be achieved by the possible designs of the first aspect and the corresponding possible designs, and the detailed description is not repeated here.
Drawings
FIG. 1 is a schematic diagram of a USB communication scenario for which embodiments of the present application are applicable;
fig. 2A to fig. 2D are schematic structural diagrams of a USB peripheral device 4 to which the scheme provided by the embodiment of the present application may be applied;
FIG. 3 is a flowchart of a method for USB-based communication according to an embodiment of the present application;
FIG. 4 is a flowchart of another method for USB-based communication according to an embodiment of the present application;
FIG. 5 is a flowchart of another method for USB-based communication according to an embodiment of the present application;
fig. 6 is a flowchart of another method for USB-based communication according to an embodiment of the present application.
Detailed Description
USB technology is commonly used in data transmission of various electronic devices, for example, an electronic device may be charged by connecting a power supply through USB technology, and data transmission between one electronic device and another electronic device may also be performed through USB technology, for example, video or picture transmission sharing is performed.
The technical scheme provided by the embodiment of the application can be suitable for various USB communication scenes, and as shown in figure 1, a USB host and a USB peripheral can be connected through a USB bus to realize USB communication. In some possible embodiments, the USB host and the USB peripheral may be directly connected by a cable. In other possible embodiments, other devices may be provided between the USB host and the USB peripheral device, without limitation. For example, a USB hub may be provided, to which the USB host and the USB peripheral are connected by cables, respectively, the USB host, the USB peripheral and the USB hub being connected to the USB bus.
In general, the USB communication protocol supports 4 modes of data transfer between a USB host and a USB peripheral, respectively: control transfers, bulk transfers, interrupt transfers, and isochronous transfers. Wherein the control transmission is used for transmitting control, state, configuration and other information between the USB host and the USB peripheral. Typically a complete control transfer comprises 2 to 3 phases: a setup phase, a data phase, and a status phase. Wherein the data phase is optional. The control transmission is initiated by the USB host sending a setup packet to the USB peripheral, which, after receiving the setup packet sent by the USB host, considers a new control transmission to begin.
Further, the control transmission on the USB host and the USB peripheral device is divided according to the transmission direction of the data-stage data packet, and may include two kinds of control OUT transmission and control IN transmission. Wherein, the control of OUT transmission means that the USB host sends a data packet to the USB peripheral; the control of IN transmission means that the USB peripheral device sends a data packet to the USB host.
In the prior art, when control transmission is performed between a USB host and a USB peripheral, each control transmission needs to allocate a buffer space in advance for the USB peripheral to receive setup packets in the control transmission, which causes complex software and hardware interaction of the USB peripheral and low efficiency of the USB control transmission. In addition, since the storage positions of the setup packet and the data packet on the USB peripheral are in the data cache space, when the USB peripheral allocates the cache of the setup packet and the cache of the data packet, there is a competition relationship, and the USB peripheral cannot read/write the setup packet and the data packet at the same time, and these causes may lead to untimely allocation of the cache space, thereby leading to occurrence of the packet loss phenomenon. For example, after the USB host sends a setup packet to the USB peripheral device, if the USB peripheral device has not allocated a data buffer space for storing the setup packet, the setup packet cannot be stored, and then a phenomenon of discarding the setup packet occurs; in addition, as the USB peripheral device does not successfully store the setup packet, the USB peripheral device cannot allocate a data buffer space in advance for the data packet to be transmitted in the data phase, and after the data phase begins, the USB peripheral device cannot successfully transmit the data packet naturally, which eventually results in failure of the control transmission.
In another case, the USB host initiates a new control transmission before the previous control transmission is completed, in this case, setup packets, data or status packets in different control transmissions appear on the USB peripheral, but the USB peripheral cannot determine the correspondence between setup packets and data/status packets in different control transmissions, so that the previous data packet is wrongly returned to the USB host, resulting in a packet error phenomenon.
To address one or more of the problems described above, embodiments of the present application provide a USB-based communication scheme. In the embodiment of the application, after the USB peripheral device receives a setup packet, the USB peripheral device can generate a unique number for the setup packet (or control transmission initiated by the setup packet), and associate the number with the setup packet; when the USB peripheral prepares for transmission of the data packet/status packet, the serial number of the setup packet corresponding to the current pen control transmission (i.e. the serial number of the setup packet corresponding to the data packet/status packet) on the data packet/status packet is needed to be attached (or associated), and serial number verification is carried out before transmission; the USB peripheral device starts to transmit the data/status packet only after the number attached to the data packet/status packet is consistent with the number of the latest received status packet, so that the occurrence of error packet transmission can be avoided, and the reliability of USB control transmission is improved.
In the embodiment of the application, the USB peripheral can also store the setup packet into the event cache space and store the data packet into the data cache space, so that the cache spaces used by the setup packet and the data packet are mutually independent and do not interfere with each other, the packet loss phenomenon can be improved, and the reliability of USB control transmission is improved.
In the embodiment of the application, the USB peripheral can also allocate a plurality of buffer spaces for storing the setup packets in advance, and sequentially store the setup packets from the USB host according to the time sequence of receiving the setup packets, so that the frequency of allocating buffer by the USB peripheral can be reduced, namely, the software and hardware interaction of the USB peripheral is reduced, and the efficiency of USB control transmission is improved.
In the embodiment of the application, the USB peripheral device may further provide a buffer coverage function, when the USB peripheral device receives the setup packet, if the USB peripheral device has not allocated a buffer space for storing the setup packet, and the USB peripheral device has a buffer space storing a history setup packet ("history setup packet" refers to a previously received setup packet), the history setup packet may be replaced by the setup packet, so, even if there is no spare buffer space, the USB peripheral device may receive and store a new setup packet at any time, so as to avoid a packet loss phenomenon.
The technical scheme provided by the embodiment of the application will be described in detail below with reference to the accompanying drawings.
Referring to fig. 2A, a schematic structural diagram of a USB peripheral device 4 to which the scheme provided in the embodiment of the present application may be applied includes an interface control module 41, a main control module 42, a buffer module 43, and a USB interface module 44.
The USB interface module 44 is a physical interface (i.e., a USB socket) of the USB peripheral device 4, and can be plugged into a USB data line. The data from the USB host sequentially passes through the USB socket, the USB data line and the USB interface module 44 of the USB host to reach the USB peripheral device 4, and correspondingly, the data sent from the USB peripheral device 4 to the USB host sequentially finally passes through the USB interface module 44, the USB data line and the USB socket of the USB host to reach the USB host. The USB interface module 44 may be an interface conforming to USB standard specifications, specifically may be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface module 44 may be used to connect a charger to charge an electronic device, or may be used to transfer data between the electronic device and other peripheral devices (e.g., a USB host). And can also be used for connecting with a headset, and playing audio through the headset.
The interface control module 41 is connected with the USB interface module 44 and the USB main control module 42, and the interface control module 41 is responsible for data transmission control on the USB interface module 44. For example, a data packet to be transmitted to the USB host is read from the buffer module 43 and transmitted through the USB interface 44, and a data packet received from the USB host by the USB interface 44 is stored to the buffer module 43. In the embodiment of the present application, the USB interface control module 41 performs other functions, such as generating a corresponding number for each control transmission, reporting an event to the main control module 42, and performing a number check before transmitting a data packet and/or status packet, in addition to performing data reading and writing in the buffer module 43.
The buffer module 43 has a buffer space, which may be a computer readable and writable storage medium, for storing data received from the USB host by the USB peripheral device 4 and data to be transmitted. In the embodiment of the application, the buffer space is divided into an event buffer space and a data buffer space, wherein the event buffer space can be used for storing setup packets of an establishment stage, and the data buffer space can be used for storing data packets of a data stage.
The data buffer space is a buffer space for storing data, such as a data packet for storing a data phase, a status packet for a status phase, and the like. The event buffer space is a buffer space for storing events, such as an event for which a setup packet is received, an event for which data transmission is completed, and the like. It should be noted that, in the embodiment of the present application, the setup packet belonging to the data is stored in the event cache space, which is different from the prior art that the setup packet is stored in the data cache space, so that the interface control module 41 can access the data cache space and the event cache space at the same time, that is, the read-write of the setup packet and the read-write of the data packet are independent, and the allocation of the cache spaces of the two is also independent.
The main control module 42 is a main control center of the USB peripheral device 4, and the main control module 42 may perform one or more of the following functions: control data phase, start/end of state phase, allocate event buffer space, allocate data buffer space, etc. The main control module 42 may also be integrated in the interface control module 41, for example, the interface control module 41 is a USB controller, and the USB controller has a separate MCU or MPU, so that the main control module 41 may be implemented by the MCU or MPU in the USB controller.
The main control module 42 may integrate driving software supporting the USB protocol. Optionally, the host module 42 also has client software (or upper layer application) integrated thereon. The driver software is a special program that enables the computer and the hardware to communicate with each other, and corresponds to an interface of the hardware through which the client software controls the operation of the hardware. In other words, the client software is upper layer software of the driving software, the client software cannot interact with other hardware of the USB peripheral device 4 directly, the instruction needs to be transmitted to the driving software, then the driving software calls the hardware in the USB peripheral device 4 to execute the corresponding function, and correspondingly, the signal reported by the hardware in the USB peripheral device 4 needs to be firstly packaged to the driving software and then transmitted to the client software by the driving software. The various functions performed by the main control module 42 may be implemented by running driver software and client software.
The modules may be further subdivided according to the functions performed by the modules. For example, as shown in fig. 2B, the cache module 43 includes an event cache space 431, a data cache space 432, and the like; the interface control module 41 includes a number generation sub-module 411, an event reporting sub-module 412, a number checking sub-module 413, and the like, where the number generation sub-module 411 may be configured to generate a corresponding number for each control transmission, the event reporting sub-module 412 may be configured to report an event to the main control module 42 (e.g., notify the main control module 42 of an event that receives a setup packet and/or generates a number), and the number checking sub-module 413 may be configured to perform a number check in a data phase and a status phase. Of course, other division modes are also possible in practical application, and the application is not limited.
In a specific implementation, the master control module 42 may specifically be, but is not limited to: a central processing unit (Central Processing Unit, CPU), a microcontroller unit (Micro Controller Unit, MCU), a microprocessor unit (Micro Processor Unit, MPU), digital signal processing (Digital Signal Processing/Processor, DSP), a field programmable gate array device (Field Programmable Gate Array, FPGA), etc. The caching module 43 may be, but is not limited to: registers, first-in first-out (First Input First Output, FIFO) memory, static random access memory (Static Random Access Memory, SRAM), dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The interface control module 41 may specifically be, but is not limited to: logic circuits connected with the cache module 43 and the main control module 42.
It should be noted that, the interface control module 41, the main control module 42, and the buffer module 43 may be integrated in the same chip, or may be integrated in different chips, which is not limited by the present application. For example, as shown in fig. 2C, the interface control module 41 and the main control module 42 and the buffer module 43 are integrated in the USB controller, where the buffer module 43 may be a register or FIFO memory or SRAM integrated in the USB controller, etc. (the USB interface module 44 is not shown in fig. 2C). Alternatively, as shown in fig. 2D, for example, the interface control module 41 and the main control module 42 are integrated in the USB controller, and the buffer module 43 is SRAM or DRAM, which is a part of a data memory (the USB interface module 44 is not shown in fig. 2D) outside the USB controller. Of course, the interface control module 41 and the main control module 42 may be separately provided, for example, the interface control module 41 is integrated in a USB controller, and the main control module 42 is integrated in a CPU.
It should be noted that, in practical application, the USB peripheral device 4 may further include more modules than those shown in fig. 2A to 2D, for example, may further include one or more hubs, which are not shown in the present application.
In the embodiment of the present application, the USB peripheral device 4 may be, but not limited to, a USB disk, a sound device, a mouse, a keyboard, a computer, a mobile phone, an intelligent wearable device, a vehicle-mounted device, and the like.
Referring to fig. 3, a method for USB-based communication according to an embodiment of the present application is taken as an example of a method applied to the USB peripheral device in fig. 2A, and the method includes:
s600, the main control module 42 allocates at least two event cache spaces and notifies the first address of the allocated event cache space to the interface control module 41;
in fig. 3, two event buffer spaces are allocated as an example, and more events may be implemented in practical applications, for example, three, four, five, etc., which is not a limitation of the present application.
The interface control module 41 may store the setup packets later, in sequence, starting from the first address.
S601, the USB interface module 44 receives a first setup packet from the USB host, wherein the first setup packet is used for indicating the start of the first pen control transmission; the interface control module 41 stores the first setup packet into the first event cache space;
It should be noted that, for the sake of clarity of the drawing, the USB interface module 44 is not shown in fig. 3, but the USB interface module 44 is also provided between the actual interface control module 41 and the USB host, and the USB peripheral device finally transmits data to and receives data transmitted from an external device (such as the USB host) through the USB interface module 44.
S602, the interface control module 41 reports an event notification main control module 42;
specifically, the specific manner in which the interface control module 41 reports the event may be a manner in which a hardware interrupt is generated, for example, a setup interrupt signal is generated.
S603, after receiving the notification, the main control module 42 reads the content of the last (or latest) setup packet from the first event cache space, for example, reads and analyzes the content of the first setup packet, and knows the size, content and direction of the data packet to be transmitted;
s604, the main control module 42 allocates a first data buffer space according to the size of a data packet to be transmitted, and notifies the first address of the first data buffer space to the interface control module 41;
it should be appreciated that if the IN transmission is controlled, the main control module 42 also prepares the data packet to be transmitted according to the content of the data packet, and stores the data packet IN the first data buffer space. The storage mode may be storage from the first address to the next.
S605, data packet transmission;
if it is the control OUT transmission, the USB interface module 44 receives a data packet from the USB host; the interface control module 41 stores the data packet received by the USB interface module 44 into the first data cache space; if the control IN transmission is performed, the USB interface module 44 receives a data packet request from the USB host, and the interface control module 41 takes out the data packet from the first data buffer space and sends it to the USB host through the USB interface module 44.
S606, transmitting status packets;
the main control module 42 issues a status package to the interface control module 41; after the USB interface module 44 receives the status packet request from the USB host, the interface control module 41 returns the status packet to the USB host through the USB interface module 44.
The host module 42 may issue status packages to the interface control module 41, and the present application is not limited thereto. For example, directly passing status packets to interface control module 41; or, for example, store status packets in the first data cache space, and then the interface control module 41 reads status packets from the first data cache space; or, for example, store status packets in other data cache spaces, and then the interface control module 41 reads status packets from other data cache spaces.
To this end, the first pen control transmission is completed.
S601', the USB interface module 44 receives a second setup packet from the USB host, the second setup packet being used to instruct the start of a second pen control transfer; the interface control module 41 stores the second setup packet to the second event cache space;
s602', the interface control module 41 reports the event notification master control module 42;
s603', after the main control module 42 receives the notification, reading and analyzing the content of the last (or latest) setup packet from the second event cache space, for example, reading and analyzing the content of the second setup packet, and obtaining the size, the content and the direction of the data packet to be transmitted;
s604', the main control module 42 allocates a second data buffer space according to the size of the data packet to be transmitted, and notifies the first address of the second data buffer space to the interface control module 41;
similarly, if the IN transmission is controlled, the main control module 42 prepares the data packet according to the content of the data packet to be transmitted, and stores the data packet IN the second data buffer space.
S605', data packet transmission;
if the control is OUT transmission, the USB interface module 44 receives a data packet from the USB host, and the interface control module 41 stores the data packet received by the USB interface module 44 into the second data buffer space; if the control IN transmission is performed, the USB interface module 44 receives a data packet request from the USB host, and the interface control module 41 fetches the data packet from the second data buffer space and sends it to the USB host through the USB interface module 44.
S606', status packet transmission;
the main control module 42 issues a status package to the interface control module 41; after the USB interface module 44 receives the status packet request from the USB host, the USB interface control module 41 returns the status packet to the USB host through the USB interface control module 41.
To this end, the second pen control transmission is completed.
It should be understood that fig. 3 is an example of allocating two event buffer spaces in advance, so fig. 3 only shows the procedure of two control transmissions. In practical applications, the USB peripheral may allocate more event buffer space in advance, so after the second control transmission is completed, the process similar to the above-mentioned processes S601 to S606 or S601 'to S606' may be further executed, which is not shown here.
As can be seen from the above, the USB peripheral device in the embodiment of the present application can allocate a plurality of event buffer spaces at a time, and is used for storing setup packets for multiple control transmissions, so that the technical defect that each control transmission requires the USB peripheral device to allocate a buffer space in advance can be avoided, the software and hardware interactions of the USB peripheral device are reduced, and the efficiency of USB control transmission is improved. In addition, the USB peripheral uses the event buffer space to store Setup packets, uses the Data buffer space to store Data packets, and the event buffer space and the Data buffer space are mutually independent and are not interfered with each other, so that the packet loss phenomenon caused by untimely Data buffer space allocation can be improved, and the reliability of USB control transmission is further improved.
It should be understood that, in the embodiment shown in fig. 3, the buffer space for storing the setup packet is taken as an example of an event buffer space, and in a specific implementation, the buffer space may be replaced by a data buffer space, that is, a plurality of buffer spaces are allocated to the setup packet in the data buffer space, which also can reduce software and hardware interactions of the USB peripheral device and improve the efficiency of USB control transmission.
Referring to fig. 4, another method for USB-based communication according to an embodiment of the present application is taken as an example of a method applied to the USB peripheral device in fig. 2A, where the method includes:
s700, the main control module 42 allocates one or more event buffer spaces and notifies the head address of the one or more event buffer spaces to the interface control module 41;
s701, the USB interface module 44 receives a setup packet from the USB host, wherein the setup packet is used for indicating that one control transmission starts; the interface control module 41 determines whether an idle event buffer space exists in the event buffer space, and if so, stores the setup packet received by the USB interface module 44 in S701 in the idle event buffer space; otherwise, the setup packet (i.e., the history setup packet) in the non-idle event cache space is replaced with the setup packet received by the USB interface module 44 in S701.
It should be noted that, for the sake of clarity of the drawing, the USB interface module 44 is not shown in fig. 4, but the USB interface module is still located between the actual interface control module 41 and the USB host, and the USB peripheral device finally transmits data to and receives data from an external device (such as the USB host) through the USB interface module 44.
The following describes the method for storing setup packets by the USB interface module 44 for two cases of allocating an event buffer space and a plurality of event buffer spaces to the host module 42.
In the first case, the main control module 42 allocates only one event buffer space, and the interface control module 41 directly stores the received first setup packet into the event buffer space; starting from the second received setup packet, the newly received setup packet is used to replace the last setup packet in the event buffer space, so that the latest received setup packet is ensured not to be lost.
For example, after the first pen control transmission starts, the USB interface module 44 receives the first setup packet, and the interface control module 41 stores the first setup packet in the event buffer space; after the second control transmission starts, the USB interface module 44 receives the second setup packet, but since the event cache space already stores the first setup packet in the first control transmission, the interface control module 41 replaces the first setup packet with the second setup packet; after the third control transfer begins, the USB interface module 44 receives the third setup packet, but since the event cache space already stores the second setup packet in the second control transfer, the interface control module 41 replaces the second setup packet … … with the third setup packet
In the second case, the main control module 42 allocates a plurality of event buffer spaces, and when the interface control module 41 stores the setup packet, the setup packet is stored sequentially from the first event buffer space of the plurality of event buffer spaces.
Taking the example that the master control module 42 allocates three event buffer spaces (i.e., a first event buffer space, a second event buffer space, and a third event buffer space): after the first pen control transmission starts, the USB interface module 44 receives the first setup packet, and the interface control module 41 stores the first setup packet in the first event buffer space; after the second control transmission starts, the USB interface module 44 receives the second setup packet, and the interface control module 41 stores the second setup packet in the second event buffer space; after the third control transmission starts, the USB interface module 44 receives the third setup packet, and the interface control module 41 stores the third setup packet in the third event buffer space.
Further, when the last event buffer space of the plurality of event buffer spaces is exhausted, the old setup packet can be replaced by the new setup packet so as to ensure that the new setup packet does not lose packets.
For example, following the example of three event cache spaces described above, when the fourth control transmission begins, USB interface module 44 receives the fourth setup packet, and when all event cache spaces (i.e., the first event cache space, the second event cache space, and the third event cache space) already store setup packets, interface control module 41 may replace the old setup packet with the new setup packet (i.e., the fourth setup packet).
The application is not limited to the particular manner in which the interface control module 41 replaces the old setup packet with the new setup packet. Two of the possible ways are exemplified below:
mode 1, "instant change.
After receiving a new setup packet, the USB interface module 44, if the interface control module 41 finds that the event buffer space is exhausted, the interface control module 41 empties one of the event buffer spaces, and stores the new setup packet and the corresponding number into the emptied one of the event buffer spaces. Optionally, the one event cache space stores, before being emptied: the setup packet with the earliest or latest time is received in the received (or stored) setup packets, or the smallest or largest number among the numbers corresponding to the received (or stored) setup packets. It should be understood that the setup packet with the earliest reception time is the setup packet with the smallest number if numbered in order from small to large, whereas the setup packet with the earliest reception time is the setup packet with the largest number if numbered in order from large to small.
Taking the fourth setup packet as an example, and taking the case that the one event buffer space stores the setup packet having the earliest reception time among the received setup packets before being emptied as an example, the first setup packet stored before in the first event buffer space may be replaced with the fourth setup packet.
Mode 2, "disposable empty".
After receiving a new setup packet, the USB interface module 44, if the interface control module 41 finds that the event buffer space is exhausted, the interface control module 41 empties all the event buffer space at a time, and then starts a new poll, and stores the new setup packet and the corresponding number sequentially.
Taking the fourth setup packet as an example, the interface control module 41 empties all the event buffer spaces (i.e. the first event buffer space, the second event buffer space, and the third event buffer space), stores the fourth setup packet in the first event buffer space, and then sequentially stores the fourth setup packet in the second event buffer space if there is a new setup packet.
S702, the interface control module 41 reports an event notification main control module 42;
s703, after receiving the notification, the main control module 42 reads and analyzes the content of the last (or latest) setup packet, for example, the content of the first setup packet, from the event cache space, and obtains the size, content and direction of the data packet to be transmitted;
s704, the main control module 42 allocates a data cache space according to the size of a data packet to be transmitted, and informs the interface control module 41 of the head address of the data cache space;
s705, data packet transmission;
S706, status packet transmission.
The specific implementation process of S702 to S706 may refer to S602 to S606 or S602 'to S606' above, and will not be described here again.
As can be seen from the foregoing, in the embodiment of the present application, after the USB peripheral device receives the setup packet, if the USB peripheral device has not allocated the event buffer space for storing the setup packet, the event buffer space allocated in the previous control transmission process may be emptied to store a new setup packet later, so that even if there is no empty buffer space, the USB peripheral device may receive and store the new setup packet at any time, thereby avoiding the occurrence of the packet loss phenomenon. In addition, the USB peripheral uses an event buffer space to store Setup packets, uses a Data buffer space to store Data packets, and the event buffer space and the Data buffer space are mutually independent and are not interfered with each other, so that the phenomenon of packet loss caused by untimely Data buffer space allocation can be further improved, and the reliability of USB control transmission is further improved.
It should be understood that, in the embodiment shown in fig. 4, the buffer space for storing the setup packet is taken as an example of an event buffer space, and in a specific implementation, the buffer space may be replaced by a data buffer space, that is, when the data buffer space for storing the setup packet is used up, the old setup packet is replaced by the new setup packet in the data buffer space, and the effect that the USB peripheral receives and stores the new setup packet at any time, so as to avoid the packet loss phenomenon may be achieved.
Referring to fig. 5, another method for USB-based communication according to an embodiment of the present application is taken as an example of a method applied to the USB peripheral device in fig. 2A, where the method includes:
s801, the main control module 42 allocates at least one event buffer space;
as shown in fig. 5, each event cache space includes a first subspace S431A for storing setup packets and a second subspace S431B for storing the numbers of the setup packets. It should be appreciated that fig. 5 shows only one event cache space, and that in practice there may be more.
S802, the USB interface module 44 receives a first setup packet from the USB host, wherein the first setup packet is used for indicating the USB host and the USB peripheral to start a control transmission; the interface control module 41 generates a unique number, such as a first number, for the first setup packet and then associates the first number with the first setup packet.
It should be noted that, for the sake of clarity of the drawing, the USB interface module 44 is not shown in fig. 5, but the USB interface module is still located between the actual interface control module 41 and the USB host, and the USB peripheral device finally transmits data to and receives data from an external device (such as the USB host) through the USB interface module 44.
Specifically, the interface control module 41 associates the first number with the first setup packet, which may be that the interface control module 41 stores the first number and the first setup packet in the same event cache space. For example, a first setup packet is stored in a first subspace of a first event cache space, and a first number is stored in a second subspace of the first event cache space.
In one possible design, the master module 42 allocates only one event buffer space. In this case, the event cache space may provide an override function, i.e. a newly received setup packet and its number may override a historical setup packet (i.e. a previously received setup packet) and its number. The specific implementation may refer to the description related to the case one in S701, which is not repeated here.
In another possible design, the main control module 42 allocates a plurality of event buffer spaces, and the interface control module 41 may sequentially store a plurality of setup packets received in the plurality of control transmissions into the plurality of event buffer spaces according to a time sequence of receiving the setup packets. In this case, when the event buffer space allocated in advance is exhausted, i.e., there is no free event buffer space, the event buffer space may also provide an overlay function, i.e., the interface control module 41 may replace the historical setup packet (i.e., the setup packet received before the USB interface module 44) stored in the event buffer space and its number with the setup packet newly received by the USB interface module 44 and its number. The specific implementation may refer to the description related to the second case in S701, which is not repeated here.
S803, the interface control module 41 reports an event notification main control module 42, and triggers the main control module 42 to read the number and the setup packet;
specifically, the specific manner in which the interface control module 41 reports the event may be a manner in which a hardware interrupt is generated, for example, a setup interrupt signal is generated.
S804, after the main control module 42 receives the notification, reading a last (or latest) setup packet and its number from the event cache space, analyzing the read setup packet, and obtaining the size, content and direction of the data packet to be transmitted, wherein in FIG. 5, taking reading the first setup packet and the first number as an example;
s805, the main control module 42 allocates a data buffer space with a specified size according to the size of the first data packet, wherein the data buffer space is used for storing the first data packet to be transmitted; associating a first data packet to be transmitted with the first number;
the manner of associating the first data packet to be transmitted with the first number by the main control module 42 may be various, which is not limited by the present application. Several of these are exemplified here: in mode 1, the main control module 42 stores the first number in the data buffer space allocated for the first data packet, for example, as shown in fig. 5, the data buffer space includes a third subspace S432A for storing data packets and a fourth subspace S432B for storing numbers, and the main control module stores the first number in the fourth subspace S432B. Mode 2, the main control module 42 directly issues the first number to the interface control module 41, for indicating that the currently allocated data buffer space is allocated for the first data packet. Mode 3, the main control module 42 stores the first number in other data buffer spaces, and then associates the other data buffer spaces with the data buffer space for storing the first data packet to be transmitted.
It should be understood that, if the IN transmission is controlled, the main control module 42 also needs to prepare the data packet to be sent to the USB host and store the data packet IN the third subspace S432A of the data cache space.
It should be further noted that, after the USB interface module 44 receives the first setup packet and before the start of the data phase of the control transmission initiated by the first setup packet (i.e., after step S802 and before step S806), the USB interface module 44 may receive a new setup packet. Whether a new setup packet is received by USB interface module 44 during this period depends on whether the USB host is sending a new setup packet. If the USB interface module 44 receives a new setup packet again, the interface control module 41 also performs the flow of S802 described above for the new setup packet. For example, after step S802 and before step S806, the USB interface module 44 receives a second setup packet from the USB host, where the second setup packet is used to instruct the USB host and the USB peripheral to start another control transmission; the interface control module 41 generates a unique number, such as a second number, for the second setup packet, and stores the second number and the second setup packet in association in the event cache space allocated in S801; wherein the first number is different from the second number.
S806, data packet transmission;
when the data phase of the pen control transmission initiated by the first setup packet starts, the interface control module 41 determines that the serial number of the latest received setup packet by the USB interface module 44 is consistent with the serial number of the data packet to be transmitted, and then the data packet is transmitted with the USB host; if not, the data packet is not transmitted.
If the data phase of the pen control transmission is OUT transmission, the data transmission process may include: the USB interface module 44 receives data packets from the USB host; if the number stored latest in the event buffer space is consistent with the number in the data buffer space, the interface control module 41 stores the data packet received by the USB interface module 44 into the data buffer space, otherwise, discards the data packet.
If the data phase of the pen control transmission is IN transmission, the data transmission process may include: the USB interface module 44 receives a data packet request from the USB host; if the interface control module 41 determines that the number stored latest in the event cache space is consistent with the number in the data cache space, the interface control module 41 reads the data packet from the data cache space and controls the USB interface module 44 to send the data packet to the USB host; otherwise, not returning the data packet.
One specific example: the USB host sends a setup packet-1 to the USB peripheral device and then sends a setup packet-2 to the USB peripheral device, based on the method, the latest number in the event cache space is the number of the setup packet-2 (assumed to be the second number); at this time, if the master control module 42 prepares for the transmission of the data packet-1 (i.e. the number in the data buffer space is the number of the setup packet-1, such as the first number, and the data packet in the data buffer space is the data packet-1), after the USB host sends the request of the data packet-2, the interface control module 41 determines that the number in the data buffer space (i.e. the first number) is inconsistent with the latest number in the event buffer space (i.e. the second number), so that the USB interface module 44 is not controlled to send the data packet-1 to the USB host, so that the erroneous packet transmission of the data packet can be avoided.
S807, status packet transmission.
Specifically, the main control module 42 issues a status packet to the interface control module 41, and the interface control module 41 controls the USB interface module 44 to send the status packet to the USB host.
Optionally, a numbering check process may be added to the status packet transmission process, for example: before the main control module 42 issues the status packet to the interface control module 41, the main control module 42 may use the first number read in S804 as the number of the status packet, and then issue the number and the status packet to the interface control module 41; accordingly, after the USB interface module 44 receives the status packet request from the USB host, the interface control module 41 may check whether the number of the status packet is consistent with the number of the setup packet that is received by the USB interface module 44, and if so, the interface control module 41 controls the USB interface module 44 to send the status packet to the USB host, otherwise, the interface control module 41 does not control the USB interface module 44 to send the status packet, so that erroneous packet transmission of the status packet can be avoided.
So far, the control transmission is completed.
After receiving a new Setup packet at any time, the USB peripheral device only needs to repeatedly execute the steps S802-S806.
As can be seen from the above, the USB peripheral device in the embodiment of the present application generates a unique number for each setup packet, when preparing transmission of a data/status packet, attaches the data/status packet to the number of the setup packet corresponding to the current pen control transmission, and performs the number check before transmission, and only after the number corresponding to the data/status packet is consistent with the number of the latest received setup packet, the USB peripheral device starts to transmit the data/status packet, so that occurrence of erroneous packet transmission can be avoided, and further reliability of USB control transmission is improved; in addition, the event buffer space and the data buffer space are mutually independent and do not interfere with each other, so that the packet loss phenomenon caused by untimely allocation of the data buffer space can be improved, and the reliability of USB control transmission is further improved; furthermore, the buffer memory of the USB peripheral can provide a coverage function, so that the USB peripheral can be ensured to receive and store a new setup packet at any time, and further the occurrence of packet loss is avoided; in addition, the USB peripheral can allocate a plurality of event cache spaces at one time, so that the software and hardware interaction of the USB peripheral can be reduced, and the efficiency of USB control transmission is further improved.
It should be understood that, in the embodiment shown in fig. 5, the buffer space for storing the setup packet is taken as an example of an event buffer space, and in a specific implementation, the buffer space may be replaced by a data buffer space, that is, the setup packet and the data/status packet are stored in the data buffer space at the same time, and the setup packet and the data/status packet are numbered and checked before the data/status packet is transmitted, so that the occurrence of transmission of an erroneous packet can be avoided, and further, the reliability of USB control transmission is improved.
The above embodiments may be combined with each other to achieve different technical effects.
Referring to fig. 6, another method for USB-based communication according to an embodiment of the present application is taken as an example of a method applied to the USB peripheral device in fig. 2A, where the method includes:
s901, the USB peripheral device receives setup packets from the USB host at different times, wherein any one setup packet is used for initiating a corresponding control transmission;
s902, the USB peripheral generates a unique number for each received setup packet, and associates each setup packet with a corresponding number; and associating the number corresponding to each setup packet with a data packet to be transmitted in control transmission initiated by each setup packet;
S903, after the USB peripheral starts in the data transmission stage of any control transmission, determining that the number corresponding to the data packet to be transmitted in any control transmission is consistent with the number corresponding to the setup packet received by the USB peripheral last time, and transmitting the data packet to be transmitted in any control transmission with the USB host.
The specific implementation method of each step in S901 to S903 may refer to the related embodiments above, and will not be described herein.
Based on the same technical concept, the embodiments of the present application also provide a computer-readable storage medium storing computer program instructions that, when executed, cause the method as described above in fig. 3 to 6 to be implemented.
Based on the same technical concept, the embodiment of the application also provides a chip, which can be coupled with the memory, and is used for reading and executing the program instructions stored in the memory to realize the method in the above figures 3-6.
Based on the same technical idea, an embodiment of the present application also provides a computer program product, in which instructions are stored, which when run on a computer, cause the computer to perform the above-mentioned methods in fig. 3-6.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various modifications and variations can be made to the present application without departing from the scope of the application. Thus, it is intended that the present application also include such modifications and alterations insofar as they come within the scope of the appended claims or the equivalents thereof.

Claims (24)

  1. The communication method based on the universal serial bus USB is characterized in that the method is applied to a USB peripheral, and the USB peripheral is in communication connection with a USB host through a USB bus;
    the method comprises the following steps:
    receiving establishment packets from the USB host at different times, wherein any one establishment packet is used for initiating a corresponding control transmission;
    generating a unique number for each received establishment packet, and associating each establishment packet with a corresponding number thereof; and associating the number corresponding to each set-up packet with the data packet to be transmitted in the control transmission initiated by each set-up packet;
    after the data transmission stage of any one control transmission starts, determining that the number corresponding to the data packet to be transmitted in any one control transmission is consistent with the number corresponding to the establishment packet latest received by the USB peripheral, and transmitting the data packet to be transmitted in any one control transmission with the USB host.
  2. The method of claim 1, wherein prior to associating each setup packet with its corresponding number, the method further comprises:
    allocating at least one event buffer space;
    Associating each set-up packet with its corresponding number, comprising:
    and storing each establishment packet and the corresponding number thereof into the same event cache space.
  3. The method of claim 2, wherein there are a plurality of allocated event cache spaces;
    storing each set-up packet and the corresponding number thereof into the same event cache space, including:
    and according to the time sequence of receiving the establishment packets, sequentially storing the establishment packets received at different times and corresponding numbers into the allocated event cache spaces.
  4. The method of claim 2, wherein storing each setup packet and its corresponding number in the same event cache space comprises:
    if the at least one event cache space has an idle event cache space, storing each set-up packet and a corresponding number thereof in the idle event cache space;
    if the at least one event buffer space does not have an idle event buffer space, respectively replacing the set-up packets and the corresponding numbers in the N event buffer spaces from old to new stored historical numbers in the at least one event buffer space by using the N set-up packets and the corresponding numbers received at different times, wherein N is a positive integer.
  5. The method of claim 2, wherein storing each setup packet and its corresponding number in the same event cache space if there is no free event cache space in the at least one event cache space, comprises:
    clearing all event cache spaces in the at least one event cache space; according to the time sequence of receiving the establishment packets, storing N establishment packets received at different times and corresponding numbers into N emptied event cache spaces in sequence; or,
    after receiving an ith establishment packet in the N establishment packets, emptying one event cache space in the at least one event cache space; storing the ith establishment packet and the corresponding number into the emptied event cache space, wherein i is a positive integer from 1 to N;
    wherein N is a positive integer.
  6. The method of claim 5, wherein the one event cache space stores, prior to flushing: the method comprises the steps of receiving the setup packet with the earliest time in the received setup packets, or receiving the smallest number or the largest number in numbers corresponding to the received setup packets.
  7. The method according to any of claims 1-6, wherein after associating each set-up packet with its corresponding number and before associating the number corresponding to each set-up packet with a data packet to be transmitted in the control transmission initiated by each set-up packet, the method further comprises:
    analyzing the content of each set-up packet to obtain the size of a data packet to be transmitted in control transmission initiated by each set-up packet;
    distributing a data buffer space for the data packets to be transmitted in the control transmission initiated by each set-up packet according to the size;
    and associating the number corresponding to each set-up packet with a data packet to be transmitted in control transmission initiated by each set-up packet, including:
    for any set-up packet, storing the number corresponding to the set-up packet and the data packet to be transmitted in the control transmission initiated by the set-up packet into a data buffer space allocated for the data packet to be transmitted in the control transmission initiated by the set-up packet.
  8. The method of claim 7, wherein the arbitrary one of the data phases of the control transmission is the USB host sending a data packet to the USB peripheral device;
    After the start of a data stage of any one control transmission, determining that a number corresponding to a data packet to be transmitted in any one control transmission is consistent with a number corresponding to an establishment packet latest received by the USB peripheral, and transmitting the data packet to be transmitted in any one control transmission with the USB host, wherein the method comprises the following steps:
    receiving a data packet from the USB host;
    after determining that the number corresponding to the data packet to be transmitted in any one control transmission is consistent with the number corresponding to the establishment packet latest received by the USB peripheral, storing the received data packet into the data buffer space allocated for the data packet to be transmitted in any one control transmission.
  9. The method of claim 7, wherein the data phase of any control transmission is the USB peripheral device sending a data packet to the USB host;
    after parsing the content of each setup package, the method further comprises:
    obtaining the content of the data packet to be transmitted in the control transmission initiated by each establishment packet;
    after allocating a data buffer space for the data packet to be transmitted in the control transmission initiated by each set-up packet according to the size, and before starting the data phase of any control transmission, the method further includes:
    Storing the data packets to be transmitted in the control transmission initiated by each set-up packet into a data buffer space allocated for the data packets to be transmitted in the control transmission initiated by each set-up packet according to the content;
    after the start of a data stage of any one control transmission, determining that a number corresponding to a data packet to be transmitted in any one control transmission is consistent with a number corresponding to an establishment packet latest received by the USB peripheral, and transmitting the data packet to be transmitted in any one control transmission with the USB host, wherein the method comprises the following steps:
    receiving a data packet request from the USB host, wherein the data packet request is used for requesting the USB peripheral to send a data packet;
    after determining that the number corresponding to the data packet to be transmitted in any one control transmission is consistent with the number corresponding to the establishment packet received by the USB peripheral device, reading the data packet from the data buffer space allocated for the data packet to be transmitted in any one control transmission according to the data packet request, and sending the data packet to the USB host.
  10. The method according to any of claims 1-9, wherein after associating the number corresponding to each set-up packet with the data packet to be transmitted in the control transmission initiated by each set-up packet, the method further comprises:
    Associating the number corresponding to each set-up packet with a state packet in control transmission initiated by each set-up packet;
    after the end of the data phase of the arbitrary pen control transmission, the method further comprises:
    receiving a status packet request from the USB host, wherein the status packet request is used for requesting the USB peripheral to send a status packet; after determining that the number corresponding to the status packet in any one control transmission is consistent with the number corresponding to the setup packet latest received by the USB peripheral, sending the status packet to be transmitted in any one control transmission to the USB host.
  11. A communication device based on USB, which is characterized in that the device is applied to a USB peripheral, and the USB peripheral is in communication connection with a USB host through a USB bus;
    the USB interface module is used for respectively receiving the establishment packets from the USB host at different times, wherein any one establishment packet is used for initiating a corresponding control transmission;
    the interface control module is used for generating a unique number for each received establishment packet and associating each establishment packet with the corresponding number;
    the main control module is used for associating the number corresponding to each set-up packet with the data packet to be transmitted in the control transmission initiated by each set-up packet;
    The interface control module is further configured to, after determining that a number corresponding to a data packet to be transmitted in any one control transmission is consistent with a number corresponding to an establishment packet received by the USB peripheral device after starting a data transmission stage of any one control transmission, control the USB interface module and the USB host to transmit the data packet to be transmitted in any one control transmission.
  12. The apparatus of claim 11, wherein the master control module is further to:
    before the interface control module associates each set-up packet with its corresponding number, at least one event cache space is allocated;
    the interface control module is specifically configured to, when associating each setup packet with its corresponding number:
    and storing each establishment packet and the corresponding number thereof into the same event cache space.
  13. The apparatus of claim 12, wherein the allocated event cache space is a plurality;
    the interface control module is specifically configured to, when storing each setup packet and the corresponding number thereof in the same event cache space:
    and according to the time sequence of receiving the establishment packets, sequentially storing the establishment packets received at different times and corresponding numbers into the allocated event cache spaces.
  14. The apparatus of claim 12, wherein the interface control module is configured to, when storing each setup packet and its corresponding number in the same event cache space:
    if the at least one event cache space has an idle event cache space, storing each set-up packet and a corresponding number thereof in the idle event cache space;
    if the at least one event buffer space does not have an idle event buffer space, respectively replacing the set-up packets and the corresponding numbers in the N event buffer spaces from old to new stored historical numbers in the at least one event buffer space by using the N set-up packets and the corresponding numbers received at different times, wherein N is a positive integer.
  15. The apparatus of claim 13, wherein if there is no free event cache space in the at least one event cache space, the interface control module is specifically configured to, when storing each setup packet and its corresponding number in the same event cache space:
    clearing all event cache spaces in the at least one event cache space; according to the time sequence of receiving the establishment packets, storing N establishment packets received at different times and corresponding numbers into N emptied event cache spaces in sequence; or,
    After the USB interface module receives the ith establishment packet in the N establishment packets, one event cache space in the at least one event cache space is emptied; storing the ith establishment packet and the corresponding number into the emptied event cache space, wherein i is a positive integer from 1 to N;
    wherein N is a positive integer.
  16. The apparatus of claim 15, wherein the one event cache space stores, prior to flushing: and receiving the setup packet with the earliest time in the setup packets received by the USB interface module, or the smallest number or the largest number in the numbers corresponding to the setup packets received by the USB interface module.
  17. The apparatus of any one of claims 11-16, wherein the master control module is further configured to:
    after the interface control module associates each set-up packet with its corresponding number, and before the main control module associates the number corresponding to each set-up packet with a data packet to be transmitted in control transmission initiated by each set-up packet, analyzing the content of each set-up packet to obtain the size of the data packet to be transmitted in control transmission initiated by each set-up packet; distributing a data buffer space for the data packets to be transmitted in the control transmission initiated by each set-up packet according to the size;
    The main control module is specifically configured to, when associating the number corresponding to each set-up packet with a data packet to be transmitted in control transmission initiated by each set-up packet:
    for any set-up packet, storing the number corresponding to the set-up packet and the data packet to be transmitted in the control transmission initiated by the set-up packet into a data buffer space allocated for the data packet to be transmitted in the control transmission initiated by the set-up packet.
  18. The apparatus of claim 17, wherein the data phase of any one control transmission is the USB host sending a data packet to the USB peripheral device;
    the USB interface module is also used for: after the data stage of any one control transmission starts, receiving a data packet from the USB host;
    the interface control module is specifically configured to, when controlling the USB interface module and the USB host to transmit a data packet to be transmitted in the arbitrary control transmission: after determining that the number corresponding to the data packet to be transmitted in any one control transmission is consistent with the number corresponding to the establishment packet latest received by the USB peripheral, storing the received data packet into the data buffer space allocated for the data packet to be transmitted in any one control transmission.
  19. The apparatus of claim 17, wherein the data phase of any one control transmission is the USB peripheral device sending a data packet to the USB host;
    the main control module is also used for: after analyzing the content of each set-up packet, obtaining the content of a data packet to be transmitted in control transmission initiated by each set-up packet; after allocating a data buffer space for the data packet to be transmitted in the control transmission initiated by each set-up packet according to the size and before starting the data phase of any control transmission, storing the data packet to be transmitted in the control transmission initiated by each set-up packet into the data buffer space allocated for the data packet to be transmitted in the control transmission initiated by each set-up packet according to the content;
    the USB interface module is also used for: after the data stage of any one control transmission starts, receiving a data packet request from the USB host, wherein the data packet request is used for requesting the USB peripheral to send a data packet;
    the interface control module is specifically configured to, when controlling the USB interface module and the USB host to transmit a data packet to be transmitted in the arbitrary control transmission: after determining that the number corresponding to the data packet to be transmitted in any one control transmission is consistent with the number corresponding to the establishment packet received by the USB peripheral device last time, reading the data packet from the data buffer space allocated for the data packet to be transmitted in any one control transmission according to the data packet request, and sending the read data packet to the USB host through the USB interface module.
  20. The apparatus of any one of claims 11-19, wherein the master control module is further configured to:
    after the number corresponding to each set-up packet is associated with a data packet to be transmitted in control transmission initiated by each set-up packet, associating the number corresponding to each set-up packet with a status packet in control transmission initiated by each set-up packet;
    the USB interface module is also used for: after the data stage of any one control transmission is finished, receiving a status packet request from the USB host, wherein the status packet request is used for requesting the USB peripheral to send a status packet;
    the interface control module is further configured to: after determining that the number corresponding to the status packet in any one control transmission is consistent with the number corresponding to the setup packet received by the USB peripheral device, controlling the USB interface module to send the status packet to be transmitted in any one control transmission to the USB host.
  21. The apparatus of claim 12, wherein the interface control module is further to: after each set-up packet and the corresponding number thereof are stored in the same event cache space, reporting an interrupt signal to the main control module, wherein the interrupt signal is used for indicating the main control module to read each set-up packet and the corresponding number thereof from the event cache space;
    The main control module is also used for: before associating the number corresponding to each set-up packet with a data packet to be transmitted in control transmission initiated by each set-up packet, receiving the interrupt signal from the interface control module; and reading the serial numbers of each establishment packet and the corresponding serial numbers of each establishment packet from the event cache space based on the interrupt signal.
  22. A computer readable storage medium containing computer program instructions which, when executed, cause the method of any of claims 1-10 to be implemented.
  23. A chip, characterized in that the chip is coupled to a memory for reading and executing program instructions stored in the memory, implementing the method according to any of claims 1-10.
  24. A computer program product having instructions stored therein, which when run on a computer, cause the computer to perform the method of any of claims 1-10.
CN202180079881.9A 2021-02-27 2021-02-27 USB-based communication method and device Pending CN116601618A (en)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2021/078314 WO2022178882A1 (en) 2021-02-27 2021-02-27 Usb-based communication method and apparatus

Publications (1)

Publication Number Publication Date
CN116601618A true CN116601618A (en) 2023-08-15

Family

ID=83047653

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202180079881.9A Pending CN116601618A (en) 2021-02-27 2021-02-27 USB-based communication method and device

Country Status (2)

Country Link
CN (1) CN116601618A (en)
WO (1) WO2022178882A1 (en)

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA2345596C (en) * 2001-04-27 2007-12-04 Icron Systems Inc. Method and apparatus for extending the range of the universal serial bus protocol
CN100468353C (en) * 2006-08-09 2009-03-11 英业达股份有限公司 USB interface standard inspection system and its method
CN102043751B (en) * 2010-06-29 2012-12-12 飞天诚信科技股份有限公司 Method for identifying host operation system by using USB equipment
CN104123258A (en) * 2014-07-23 2014-10-29 龙迅半导体科技(合肥)有限公司 USB data transmission interface and system
US10733135B2 (en) * 2017-04-03 2020-08-04 Futurewei Technologies, Inc. Universal serial bus network switch
WO2019071529A1 (en) * 2017-10-12 2019-04-18 深圳传音通讯有限公司 Control method and control device for intelligent device signal switching

Also Published As

Publication number Publication date
WO2022178882A1 (en) 2022-09-01

Similar Documents

Publication Publication Date Title
CN107209644B (en) Data processing method and NVMe memory
CN108647104B (en) Request processing method, server and computer readable storage medium
KR102245247B1 (en) GPU remote communication using triggered actions
JP2024099640A (en) Unified address space for multiple hardware accelerators with dedicated low latency links
JP5527512B2 (en) Bus protocol conversion device and bus protocol conversion method
CA2987807C (en) Computer device and method for reading/writing data by computer device
CN104216865A (en) System and method for accelerating mapreduce operation
CN112947857B (en) Data moving method, device, equipment and computer readable storage medium
CN114416630B (en) PCIE-based communication method, PCIE-based communication device, computer equipment and readable storage medium
US20060236001A1 (en) Direct memory access controller
CN113590512A (en) Self-starting DMA device capable of directly connecting peripheral equipment and application
CN117312201B (en) Data transmission method and device, accelerator equipment, host and storage medium
CN116594951B (en) FPGA-based data transmission system and method
CN115883022B (en) DMA transmission control method, apparatus, electronic device and readable storage medium
CN116601618A (en) USB-based communication method and device
US8041902B2 (en) Direct memory move of multiple buffers between logical partitions
CN111371799B (en) Method, device and equipment for controlling data receiving and transmitting of MCTP (Multi-channel media Port) controller
CN111026694B (en) Data receiving method, data receiving apparatus, image forming system, and electronic apparatus
CN109241362B (en) Block generation method, device, equipment and storage medium
US20160162199A1 (en) Multi-processor communication system sharing physical memory and communication method thereof
CN104850517A (en) Method and apparatus for transmitting packet data using DMA
KR20050063939A (en) Direct memory access controller for updating data transmission size automatically from peripheral, and control method thereof
CN115442239B (en) Bandwidth resource allocation method, PCIe channel switcher and electronic device
CN111200594B (en) Method and device for receiving data, data receiving equipment and storage medium
US20240069754A1 (en) Computing system and associated method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination