WO2023142301A1 - Usb虚拟串口实时上传数据的方法及系统、usb主机 - Google Patents

Usb虚拟串口实时上传数据的方法及系统、usb主机 Download PDF

Info

Publication number
WO2023142301A1
WO2023142301A1 PCT/CN2022/092048 CN2022092048W WO2023142301A1 WO 2023142301 A1 WO2023142301 A1 WO 2023142301A1 CN 2022092048 W CN2022092048 W CN 2022092048W WO 2023142301 A1 WO2023142301 A1 WO 2023142301A1
Authority
WO
WIPO (PCT)
Prior art keywords
usb
data
serial port
transaction
virtual serial
Prior art date
Application number
PCT/CN2022/092048
Other languages
English (en)
French (fr)
Inventor
王春华
Original Assignee
南京沁恒微电子股份有限公司
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 南京沁恒微电子股份有限公司 filed Critical 南京沁恒微电子股份有限公司
Priority to GB2312141.1A priority Critical patent/GB2618707B/en
Publication of WO2023142301A1 publication Critical patent/WO2023142301A1/zh

Links

Images

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
    • G06F13/40Bus structure
    • G06F13/4063Device-to-bus coupling
    • G06F13/4068Electrical coupling
    • 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
    • G06F13/40Bus structure
    • G06F13/4063Device-to-bus coupling
    • G06F13/4068Electrical coupling
    • G06F13/4072Drivers or receivers
    • 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/10Program control for peripheral devices
    • G06F13/105Program control for peripheral devices where the programme performs an input/output emulation function
    • 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
    • G06F13/382Information transfer, e.g. on bus using universal interface adapter
    • G06F13/385Information transfer, e.g. on bus using universal interface adapter for adaptation of a particular data processing system to different peripheral devices
    • 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
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2213/00Indexing scheme relating to interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F2213/0042Universal serial bus [USB]

Definitions

  • the invention belongs to the technical field of data communication, and in particular relates to a method and system for uploading data through a USB virtual serial port in real time, and a USB host.
  • USB virtual serial port Due to the hot-swappable characteristics of USB and the advantages of the number of USB ports, the USB virtual serial port has become the main way to expand the serial port. The difference is at least a thousand times, and many applications still retain this requirement for the serial port data interval, which brings challenges to the compatibility of the USB virtual serial port.
  • the low-speed characteristics of the serial port will cause the transmission time of each byte to be longer. For example, 115200bps is commonly used, and 1ms is about 11 bytes. For example, it takes about 6ms to receive 64 bytes; if it is 9600bps, 1ms is about 1 byte. It takes 64ms to receive 64 bytes.
  • the USB communication mechanism is all initiated by the USB host, and the USB slave cannot actively initiate communication, and the high-speed communication is guaranteed by timing frames plus various transmission types and block transmission (BULK) plus limited bandwidth.
  • BULK block transmission
  • Such as USB full speed the bandwidth of batch endpoints per 1ms will be limited to 1023 bytes.
  • the transmission speed is guaranteed in blocks, and the basic unit of each block transmission is the endpoint size of Bulk.
  • the endpoint size is set to 32 bytes.
  • the USB host initiates a 320-byte request, and the USB transmission will be divided into multiple packets for processing. 32-byte endpoint size packet, after the USB transaction has filled the 320-byte data, it will reply the request to the USB host.
  • serial port transmits in byte stream, and the USB full speed transmits USB requests and data at the fastest interval of 1ms;
  • USB virtual serial port driver In order to improve the timeliness of serial port data reaching the upper layer, the USB virtual serial port driver is required to frequently initiate USB BLUK IN transactions at the fastest speed to improve the real-time performance of serial port data to the upper layer. .
  • USB bulk endpoint transmission cannot be fully guaranteed, because the bandwidth of USB bulk transmission is managed by the USB host as a whole and is not controlled. If there is a device performing high-speed communication at this time, the USB BULK IN transaction cannot be initiated within a certain period of time. And the driver cannot interfere with the co-ordination.
  • the present invention provides a method for real-time uploading data of USB virtual serial port And system, USB host.
  • the virtual serial port driver creates a receiving thread, and the receiving thread presets a plurality of USB transactions, and the USB transaction is a USB batch upload request packet, and the length of the USB batch upload request packet request upload is the batch endpoint size, and multiple USB transactions Submit to the USB host driver, execute the caching and application steps in a loop;
  • Described buffering and application step include: when receiving thread receives the returned data packet, pass the returned data packet to the serial port application layer cache, and immediately apply for a new USB transaction, and submit to the USB host driver;
  • the USB host driver puts the USB transaction into the USB transaction queue, and immediately returns the waiting status to the virtual serial port driver; the USB host driver executes the USB transaction ranked first in the USB transaction queue, and other USB transactions wait, and the loop operation returns and executes the steps ;
  • the step of returning and executing includes: after receiving the data sent by the USB device, when the data meets the bulk endpoint size, end the USB transaction and execute the data packet to the receiving thread, and immediately execute the next USB transaction in the USB transaction queue.
  • the data satisfying the batch endpoint size means that the length of the data reaches the batch endpoint size, or is smaller than the batch endpoint size.
  • the USB transaction queue includes one executing USB transaction and M ⁇ 1 waiting USB transactions.
  • the virtual serial port driver submits multiple USB transactions to the USB host driver in an asynchronous manner.
  • the step of returning and executing further includes: if the USB host driver does not receive the data packet sent by the USB device, the USB host driver will repeatedly execute the USB transaction.
  • the application program takes out the return data packet from the application layer cache.
  • the data sent by the USB device is the data uploaded by the USB device to the USB host
  • the data uploaded by the USB device to the USB host specifically includes:
  • bit timer is set to the corresponding duration of the fixed number of bytes; the serial port is decoded according to the serial port frame format and stored in the first-in-first-out queue of the serial port receiving data; according to the end time of the bit timer, the serial port The data in the first-in-first-out queue for receiving data is moved to the batch upload endpoint of the uploader, waiting for the USB batch upload request packet executed by the USB host to take the data away; after the data is taken away, the bit timer is cleared and restarted to continuously upload .
  • timing duration of the bit timer is set to be 1.1 bytes to 1.9 bytes in length, and the length of 1.1 bytes to 1.9 bytes is calculated from the serial port communication baud rate.
  • a USB host computer includes a processor, a memory, and a software program stored in the memory and executable by the processor.
  • the processor executes the software program, the above-mentioned method for uploading data through a USB virtual serial port can be realized in real time.
  • a system for uploading data through a USB virtual serial port in real time comprising the above-mentioned USB host and USB device, the USB host and the USB device are connected through the USB virtual serial port.
  • the present invention provides a method and system for real-time uploading of data by a USB virtual serial port, and a USB host. Compared with the prior art, there are the following beneficial effects:
  • USB batch transfer is the fastest transfer. It can transfer a large amount of data without blocking the bus.
  • the maximum length of the data packet for batch transfer is the size of the batch endpoint.
  • Each transmission transaction ends a bulk transmission transaction on the condition that the requested length is reached or the length is less than the endpoint size, and the data packet is returned in time to ensure maximum real-time performance.
  • the virtual serial port driver and the host driver each perform their own tasks without interfering with each other, and do not need to wait for each other.
  • USB batch upload request packets to form a USB transaction queue, which can improve the upload efficiency of USB devices, reduce the waiting interval for hardware data upload, improve the real-time performance of upload, and save the RAM required for hardware cache data .
  • the length of the USB batch upload request packet requests the upload data packet to be the size of the endpoint, which improves the return efficiency of USB transactions, reduces the bandwidth occupancy rate, and weakens the serial port transmission rate which is much lower than USB, serial port data fragmentation and USB block transmission The negative impact caused by the conflict between them improves the compatibility of the USB virtual serial port.
  • the endpoint packet size is used as the upload unit, which saves hardware processing time and avoids the need for the hardware to upload a zero-length packet to notify the end of the main USB transaction when uploading the entire packet.
  • the USB device cooperates closely with the USB host, and the USB host ends a batch transfer transaction on the condition of reaching the requested length or the length less than the endpoint size each time, and returns the data packet in time.
  • the USB device uploads data to the endpoint when the time reaches the fixed byte length according to the timing of the bit timer and calculation according to the baud rate.
  • the host and the device cooperate with each other to further maximize the real-time data transmission of the system.
  • Fig. 1 is the process schematic diagram of the USB virtual serial port transmission data that existing endpoint size is 64 bytes;
  • Fig. 2 is the process schematic diagram of the USB virtual serial port transmission data that existing endpoint size is 32 bytes;
  • Fig. 3 is the process schematic diagram of real-time uploading data of USB virtual serial port of the present invention.
  • Fig. 4 is the system architecture diagram of embodiment one USB virtual serial port uploading data in real time
  • Fig. 5 is the process schematic diagram of embodiment one USB virtual serial port uploading data in real time
  • Fig. 6 is the system architecture diagram of embodiment two USB virtual serial ports uploading data in real time
  • Fig. 7 is a schematic diagram of the process of uploading data in real time through the USB virtual serial port in Embodiment 3.
  • a system for uploading data in real time through a USB virtual serial port comprising a USB host and a USB device, the USB host and the USB device are connected through the USB virtual serial port.
  • the USB host can be a computer or a single-chip microcomputer, and the form is not limited.
  • USB virtual serial port uploading data method involves the content of parts such as integrated USB controller, serial port controller and PHY microcontroller (hereinafter referred to as hardware) and computer system USB port class manufacturer's equipment virtual serial port driver, as shown in Figure 4 As shown, it includes serial port application program, USB virtual serial port driver, USB host driver, USB device hardware, serial port peripherals, etc.
  • the hardware is connected to the computer through USB, and the hardware initializes the UART, USB controller and other units;
  • the system After the system recognizes the hardware device, it loads the virtual serial port driver and initializes the Bulk In and Bulk Out pipelines;
  • the virtual serial port driver After software such as the application layer opens the serial port, the virtual serial port driver sends parameters such as the serial port baud rate to the hardware for setting through the control request;
  • the virtual serial port driver creates a receiving thread and a sending thread for sending and receiving USB data of TX and RX.
  • M USB transactions are preset in the receiving thread.
  • the USB transactions are USB bulk upload request packets. Endpoints should be ⁇ 64 bytes, Hi-Speed USB bulk endpoints should be ⁇ 512 bytes. Therefore, N in FIG. 3 is ⁇ 64 bytes (under full speed environment), or ⁇ 512 bytes (under high speed environment).
  • N 1 , N 2 , N 3 . . . N m are all ⁇ N.
  • USB batch upload request packets there are 10 USB batch upload request packets preset in this embodiment, and the batch endpoint size of this embodiment is 64 bytes.
  • 10 USB batch upload request packets are submitted to the USB host driver in an asynchronous manner. This method occupies a small amount of bandwidth and can basically guarantee that a frame will be executed every millisecond.
  • USB host driver Every time the USB host driver completes a USB transaction, it puts the next USB transaction into the USB transaction queue, and immediately returns the waiting completion status (STATUS_PENDING) to the virtual serial port driver.
  • STATUS_PENDING the waiting completion status
  • USB transactions are arranged in the USB transaction queue, and the USB host driver starts to execute from the first USB transaction in the USB transaction queue, and other USB transactions wait;
  • USB transaction If after executing the USB transaction, the data sent by the USB device is received, and the data length reaches the endpoint size or is smaller than the endpoint size, the USB transaction is immediately ended and the data packet is returned to the receiving thread, and the next USB transaction in the USB transaction queue is executed immediately .
  • Such loop execution, return, execution, return ... always keep one USB transaction being executed and 9 USB transactions waiting in the USB transaction queue.
  • USB host driver will repeatedly execute the USB transaction.
  • the virtual serial port driver After the virtual serial port driver submits the USB bulk upload request packet to the USB host driver, when the receiving thread receives the returned data packet, it transfers the returned data packet to the serial port application layer cache, and immediately applies for a new endpoint-sized USB Upload request packets in batches and submit them to the USB host driver as a new USB transaction, such as circular cache, application, cache, application... .
  • the application program fetches data from the buffer area of the serial port application layer.
  • each transmission ends USB transaction with the data length satisfying an endpoint size, that is, reaching the endpoint size or less than the endpoint size (when the returned data is not satisfied with the endpoint size , will also return) as a condition to end a USB transaction, return the data packet immediately after the end of a USB transaction, do not need to wait for the larger data packet to return before uploading (the serial port transmission time is too long when the data packet is large, wasting the waiting Time, the application program does not obtain data in time), so that the application program can receive data in a timely manner, which improves the real-time performance of data transmission by the virtual serial port, and greatly weakens the transmission rate of the serial port. Side effects caused by collisions between block transfers.
  • the virtual serial port driver and the USB host driver each perform their own tasks without interfering with each other.
  • the virtual serial port driver does not need to submit a USB transaction request after the USB host driver returns the data packet.
  • the USB host driver can also execute it immediately after returning the data packet.
  • the waiting USB transaction request in the queue does not need to wait for the serial port driver USB application, bandwidth allocation and queuing time, which improves the efficiency of virtual serial port data transmission.
  • the second embodiment adds the setting of the USB device end on the basis of the first embodiment.
  • a bit timer is added on the USB device side, and the USB device side can continuously upload data to the BULK IN endpoint of the uploading end according to the time corresponding to the fixed number of bits, instead of a fixed delay, to cooperate with the host every time
  • the USB transaction performed at a time is a solution of batch endpoint size, thereby further reducing waiting time and further improving the real-time performance of the system.
  • the specific method of uploading data in real time on the USB device side is as follows:
  • the bit timer is set to the duration corresponding to the fixed number of bytes; after the UART RX receives the start frame of the first serial port signal, the bit timer starts, and the serial port signal is decoded according to the serial port frame format After that, store it in the RX FIFO (the first-in-first-out queue for receiving data at the serial port), and wait for uploading;
  • the setting of the bit timer is calculated according to the pre-set baud rate, and can be set to a length of 1.1 bytes to 1.9 bytes. In this embodiment, the default time is 1.5 bytes.
  • the bit timer reaches the time corresponding to 1.5 bytes, check whether there is data in the RX FIFO. If there is, move the data in the RX FIFO to the BULK IN endpoint of the upload end, and wait for the IN transaction packet executed by the host driver to take the data. ;
  • bit timer is cleared, wait for the serial port start frame to arrive, and restart timing.
  • the USB device regularly uploads data to the batch transmission endpoint of the upload end according to the time corresponding to the fixed number of bits. For the case of different baud rates, the same byte interval can be achieved, which improves the comparison with the native serial port. Compatibility and user convenience further improve the real-time performance of data transmission in the system, making the USB virtual serial port real-time upload system as real-time as possible.
  • the USB bulk endpoint size is 32 bytes.
  • 10 USB batch upload request packets are preset, and the 10 USB batch upload request packets are submitted to the USB host driver in an asynchronous manner.
  • This method occupies a small amount of bandwidth and can basically guarantee that frames will be executed every millisecond.

Landscapes

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

Abstract

本发明公开了一种USB虚拟串口实时上传数据的方法及系统、USB主机,虚拟串口驱动创建接收线程,预置多个USB事务,USB事务为USB批量上传请求包,USB批量上传请求包请求上传的长度为批量端点大小,将多个USB事务提交至USB主机驱动,当接收线程接收到返回的数据包时,将返回的数据包传至串口应用层缓存,并立即申请新的USB事务,提交至USB主机驱动;USB主机驱动执行USB事务队列中排列第一的USB事务,当接收到USB设备发出的数据后,数据满足批量端点大小时,结束该USB事务并返回数据包至接收线程,立即执行USB事务队列中下一个USB事务。本发明提高了USB虚拟串口传输数据的实时性及传输效率。

Description

USB虚拟串口实时上传数据的方法及系统、USB主机 技术领域
本发明属于数据通信技术领域,尤其涉及一种USB虚拟串口实时上传数据的方法及系统、USB主机。
背景技术
随着科技的不断进步,电脑上的接口越来越高速和小型化,对于电子产品中仍在广泛使用的UART串口,因串口插座体积和通讯速度等原因,已基本不集成。目前主要是通过现有广泛流行的PC总线接口USB/PCI/E进行扩展。而USB因热插拔特性和USB口数量的优势,USB虚拟串口已成为扩展串口的主要方式,但USB全速(12M)和高速(480M)通讯速率与串口的波特率(9600/115200)已相差至少上千倍,有很多应用对串口数据间隔时间依然保留这个要求,这给USB虚拟串口的兼容性带来挑战。
串口的低速特性会导致每个字节传输时间会较长,如常用115200bps,1ms约11个字节,如接收到64个字节需要约6ms;如果是9600bps,则1ms约1个字节,如接收64个字节则需要64ms。
USB通讯机制,全部由USB主机发起,USB从机无法主动发起通讯,且以定时帧加各传输类型以块传输形式(BULK)加限定带宽的方式来保证高速通讯。如USB全速,每1ms批量端点的带宽会限制在1023字节,对于USB传输而言,以块的方式来保证传输速度,每次块传输的事以Bulk的端点大小为基本单位。如图1所示,USB主机发起640字节的请求,USB传输将拆分多包处理执行,640字节=10*64,因此会拆出10个64字节端点大小的包,待USB事务将640字节的数据收满后,回复请求给USB主机。如图2所示,是端点大小设为32字节的场景,USB主机发起320字节的请求,USB传输将拆分多包处理执行,320字节=10*32,因此会拆出10个32字节端点大小的包,待USB事务将320字节的数据收满后,回复请求给USB主机。
实现USB虚拟串口功能,存在以下几个困难:
1、串口和USB速度有较大差异,串口以字节流方式传输,USB全速以最快1ms的间隔时间传输USB请求和数据;
2、串口数据碎片化和USB块传输有冲突,为提高串口数据到达上层的及时性,就需要USB虚拟串口驱动以最快的速度频繁发起USB BLUK IN事务,以提高串口数据到上层的实时性。
3、USB批量端点传输的实时性又无法充分保障,因为USB批量传输的带宽为USB主机统筹管理,不受控制。如果此时有设备进行高速通讯,就会造成 一定时间内USB BULK IN事务无法发起。且驱动程序无法干预统筹。
发明内容
发明目的:为了解决现有技术中串口和USB传输速度差异大、串口数据碎片化与USB块传输冲突导致的虚拟串口传输数据及时性差的问题,本发明提供一种USB虚拟串口实时上传数据的方法及系统、USB主机。
技术方案:一种USB虚拟串口实时上传数据的方法,包括以下步骤:
虚拟串口驱动创建接收线程,所述接收线程预置多个USB事务,所述USB事务为USB批量上传请求包,所述USB批量上传请求包请求上传的长度为批量端点大小,将多个USB事务提交至USB主机驱动,循环执行缓存并申请步骤;
所述缓存并申请步骤包括:当接收线程接收到返回的数据包时,将返回的数据包传至串口应用层缓存,并立即申请新的USB事务,提交至USB主机驱动;
USB主机驱动将USB事务放入USB事务队列中,并立刻向虚拟串口驱动返回等待完成状态;USB主机驱动执行USB事务队列中排列第一的USB事务,其他USB事务等待,循环操作返回并执行步骤;
所述返回并执行步骤包括:当接收到USB设备发出的数据后,数据满足批量端点大小时,结束该USB事务并执行数据包至接收线程,并立即执行USB事务队列中下一个USB事务。
进一步地,所述返回并执行步骤中,数据满足批量端点大小,指数据的长度达到批量端点大小,或者小于批量端点大小。
进一步地,设接收线程预置的USB事务的个数为M个,USB事务队列包含一个正在执行的USB事务及M-1个正在等待的USB事务。
进一步地,所述虚拟串口驱动将多个USB事务提交至USB主机驱动采用异步方式进行。
进一步地,所述返回并执行步骤还包括:若USB主机驱动没有接收到USB设备发出的数据包,USB主机驱动会重复执行该USB事务。
进一步地,所述缓存并申请步骤中,返回数据包传至串口应用层缓存后,应用程序从应用层缓存中取出返回数据包。
进一步地,所述USB设备发出的数据为USB设备上传给USB主机的数据,USB设备上传给USB主机数据具体包括:
定义位计时器,所述位计时器设置为固定字节数所对应的时长;串口按照串口帧格式解码后存入串口接收数据的先进先出队列内;根据位定时器的结束时间,将串口接收数据的先进先出队列内的数据移至上传端批量上传端点内,等待USB主机执行的USB批量上传请求包取走数据;数据取走后,位计时器清零并重新计时,不断循环上传。
进一步地,所述位计时器设置定时时长为1.1个字节~1.9个字节长度,1.1个字节~1.9个字节长度由串口通讯波特率计算得到。
一种USB主机,包括处理器、存储器及存储在存储器中并可被处理器执行的软件程序,处理器执行该软件程序时能够实现上述USB虚拟串口实时上传数据的方法。
一种USB虚拟串口实时上传数据的系统,包括上述USB主机及USB设备,USB主机与USB设备之间通过USB虚拟串口连接。
本发明提供一种USB虚拟串口实时上传数据的方法及系统、USB主机,相比较现有技术,存在以下有益效果:
1.充分发挥USB批量传输的优点,批量传输是最快的传输,可以传输大量的数据而不会阻塞总线,批量传输的数据包最大长度为批量端点大小。每次传输事务以达到请求长度或小于端点大小的长度为条件结束一个批量传输事务,及时返回数据包,保证最大化的实时性。虚拟串口驱动与主机驱动各自执行自身的任务,互不干扰互不影响,也不需要互相等待。
2.采用预置USB批量上传请求包,形成USB事务队列,可提高USB设备的上传效率,减少硬件数据的上传等待间隔,提高了上传的实时性,同时也节约了硬件缓存数据所需的RAM。
3.USB批量上传请求包请求上传数据包的长度为端点大小,提高了USB事务的返回效率,减少带宽的占用率,减弱了串口传输速率比USB低太多、串口数据碎片化和USB块传输间的冲突所造成的负面影响,提高了USB虚拟串口的兼容性。同时以端点包大小为上传单位,节约了硬件的处理时间,也避免了硬件在上传整包时需要上传零长度包来通知主要USB事务的结束。
4.USB设备与USB主机密切配合,USB主机每次以达到请求长度或小于端点大小的长度为条件结束一个批量传输事务,及时返回数据包。USB设备按照位计时器的定时,根据波特率计算,当时间达到固定字节长度时便上传数据至端点。主机与设备两者相互配合,进一步实现系统的数据传输实时性的最大化。
附图说明
图1为现有的端点大小为64字节的USB虚拟串口传输数据的过程示意图;
图2为现有的端点大小为32字节的USB虚拟串口传输数据的过程示意图;
图3为本发明USB虚拟串口实时上传数据的过程示意图;
图4为实施例一USB虚拟串口实时上传数据的系统架构图;
图5为实施例一USB虚拟串口实时上传数据的过程示意图;
图6为实施例二USB虚拟串口实时上传数据的系统架构图;
图7为实施例三USB虚拟串口实时上传数据的过程示意图。
具体实施方式
下面结合附图和具体实施例对本发明做进一步解释说明。
实施例一:
一种USB虚拟串口实时上传数据的系统,包括USB主机及USB设备,USB主机与USB设备之间通过USB虚拟串口连接。该USB主机可以是计算机,也可以是单片机,形式不限。
一种USB虚拟串口实时上传数据方法的实现,涉及集成USB控制器、串口控制器及PHY微控制器(以下简称硬件)和计算机系统USB端口类厂商设备虚拟串口驱动等部分的内容,如图4所示,包括串口应用程序、USB虚拟串口驱动、USB主机驱动、USB设备硬件、串口外设等。
首先硬件通过USB接入电脑,硬件初始化UART、USB控制器等单元;
系统识别到该硬件设备后加载虚拟串口驱动,并初始化好Bulk In和Bulk Out管道;
应用层等软件打开串口后,虚拟串口驱动通过控制请求,发送串口波特率等参数至硬件进行设置;
虚拟串口驱动创建接收线程和发送线程,用于进行TX、RX的USB数据收发。如图3所示,在接收线程内预置M个USB事务,所述USB事务为USB批量上传请求包,所述USB批量上传请求包请求上传的长度为批量端点大小N,协议规定全速USB批量端点应≤64字节,高速USB批量端点应≤512字节。因此图3中的N≤64字节(全速环境下),或≤512(高速环境下)。USB传输包一旦达到N或小于N就会结束当前事务,如图3中N 1、N 2、N 3……N m均≤N。
比如本实施例预置的USB批量上传请求包有10个,本实施例批量端点大小为64字节,如图5所示,以异步方式提交10个USB批量上传请求包至USB主机驱动。该方式占用带宽小,基本能保证每毫秒帧都会被执行,对于端点大小64字节,N=10的情况,最大仅占用50%的USB带宽,不影响USB设备的其他传输。如满载时每毫秒最多可传640字节,理论可满足6M波特率的连续传输。之所以将USB批量上传请求包请求上传的长度设为批量端点大小,是为了使主机驱动接收到数据后,一旦达到端点长度或小于端点大小就结束当前事务,并返回至虚拟串口驱动,尽可能提高数据上传的及时性,其过程如图5所示,为满载的情况。
USB主机驱动每完成一个USB事务,便将下一个USB事务放入USB事务队列,并立刻向虚拟串口驱动返回等待完成状态(STATUS_PENDING)。这些USB事务在USB事务队列中排列,USB主机驱动从USB事务队列中排第一的USB事务开始执行,其他USB事务等待;
如果在执行USB事务后,接收到了USB设备发出的数据,数据长度达到端点大小或小于端点大小,就立即结束该USB事务并返回数据包至接收线程,并立即执行USB事务队列中下一个USB事务。如此循环执行、返回、执行、返回……,始终保持USB事务队列中有一个正在执行的USB事务和9个正在等待的USB事务。
如果在执行USB事务后,硬件没有USB数据上传,未接收到上传需要的数据,USB主机驱动会重复执行该USB事务。
虚拟串口驱动在将USB批量上传请求包提交至USB主机驱动后,当接收线程接收到返回的数据包时,将返回的数据包传至串口应用层缓存,并立即申请一个新的端点大小的USB批量上传请求包,作为新USB事务提交至USB主机驱动,如此循环缓存、申请、缓存、申请……。应用程序从串口应用层的缓存区取走数据。在该USB虚拟串口实时上传数据的方法中,采用USB批量传输,每次传输以数据长度满足一个端点大小就结束USB事务,即达到端点大小或小于端点大小(当返回的数据不满一个端点大小了,也会返回)为条件结束一个USB事务,结束一个USB事务后立即返回数据包,不需要等到较大的数据包返回之后再上传(数据包较大时串口传输的时间太久,浪费了等待时间,应用程序获取数据不及时),使应用程序能够较为及时地接收到数据,提高了虚拟串口传输数据的实时性,极大削弱了串口传输速率比USB低太多、串口数据碎片化和USB块传输间的冲突所造成的负面影响。
此外,虚拟串口驱动和USB主机驱动各自执行自身的任务,互不干扰互不影响,虚拟串口驱动无需USB主机驱动返回数据包后提交USB事务请求,USB主机驱动也可以在返回数据包后立即执行队列内的在等待的USB事务请求,无需等待串口驱动USB申请及带宽分配和排队的时间,提高了虚拟串口传输数据的效率。
实施例二:
为了配合USB主机端的驱动,进一步提高数据上传的实时性,实施例二在实施例一的基础上,增加了USB设备端的设置。如图6所示,在USB设备端增加了位计时器,USB设备端可采用按照固定位数所对应的时长不断上传数据至上传端BULK IN端点内,而不是固定延时,以配合主机每次执行的USB事务为批量端点大小的方案,从而进一步减少等待时间,进一步提高系统的实时性。
USB设备端的实时上传数据的具体方法为:
1、定义位计时器,所述位计时器设置为固定字节数所对应的时长;UART RX收到第一个串口信号的开始帧后,位计时器开始启动,串口信号按照串口帧格式解码后,存入RX FIFO(串口接收数据的先进先出队列)内,等待上传;
2、位计时器的设定,根据事先设定的波特率进行计算,可设定为1.1个字节~1.9个字节长度,本实施例默认设为1.5字节的时间。当位计时器计时达到1.5字节对应的时间后,查询RX FIFO内是否有数据,如果有,将RX FIFO内数据移至上传端BULK IN端点内,等待主机驱动执行的IN事务包取走数据;
3、数据取走后,位计时器清空,等待串口开始帧到达后,重新开始计时。
USB设备为了配合USB主机驱动的方案,按照固定位数所对应的时间定时上传数据至上传端的批量传输端点,对于不同波特率的情况,能够实现同样的字节间隔,提高了与原生串口的兼容性和用户使用的方便性,进一步提高系统传输数据的实时性,使USB虚拟串口实时上传系统具有尽可能高的实时性。
实施例三:
实施例三与实施例一或实施例二的区别在于,如图7所示,USB批量端点大小为32字节。本实施例预置的USB批量上传请求包有10个,以异步方式提交10个USB批量上传请求包至USB主机驱动。该方式占用带宽小,基本能保证每毫秒帧都会被执行,对于端点大小32字节,N=10的情况,最大仅占用30%的USB带宽,不影响USB设备的其他传输。如图7满载时每毫秒最多可传320字节,理论可满足3M波特率的连续传输。

Claims (10)

  1. 一种USB虚拟串口实时上传数据的方法,其特征在于,包括以下步骤:
    虚拟串口驱动创建接收线程和发送线程,所述接收线程预置多个USB事务,所述USB事务为USB批量上传请求包,所述USB批量上传请求包请求上传的长度为批量端点大小,将多个USB事务提交至USB主机驱动,循环执行缓存并申请步骤;
    所述缓存并申请步骤包括:当接收线程接收到返回的数据包时,将返回的数据包传至串口应用层缓存,并立即申请新的USB事务,提交至USB主机驱动;
    USB主机驱动将USB事务放入USB事务队列中,并立刻向虚拟串口驱动返回等待完成状态;USB主机驱动执行USB事务队列中排列第一的USB事务,其他USB事务等待,循环操作返回并执行步骤;
    所述返回并执行步骤包括:当接收到USB设备发出的数据后,数据满足批量端点大小时,结束该USB事务并返回数据包至接收线程,并立即执行USB事务队列中下一个USB事务。
  2. 根据权利要求1所述的USB虚拟串口实时上传数据的方法,其特征在于,所述返回并执行步骤中,数据满足批量端点大小,指数据的长度达到批量端点大小,或者小于批量端点大小。
  3. 根据权利要求1或2所述的USB虚拟串口实时上传数据的方法,其特征在于,设接收线程预置的USB事务的个数为M个,USB事务队列包含一个正在执行的USB事务及M-1个正在等待的USB事务。
  4. 根据权利要求1或2所述的USB虚拟串口实时上传数据的方法,其特征在于,所述虚拟串口驱动将多个USB事务提交至USB主机驱动采用异步方式进行。
  5. 根据权利要求1或2所述的USB虚拟串口实时上传数据的方法,其特征在于,所述返回并执行步骤还包括:若USB主机驱动没有接收到USB设备发出的数据包,USB主机驱动会重复执行该USB事务。
  6. 根据权利要求1或2所述的USB虚拟串口实时上传数据的方法,其特征在于,所述缓存并申请步骤中,返回数据包传至串口应用层缓存后,应用程序从应用层缓存中取出返回数据包。
  7. 根据权利要求1或2所述的USB虚拟串口实时上传数据的方法,其特征在于,所述USB设备发出的数据为USB设备上传给USB主机的数据,USB设备上传给USB主机数据的方法具体包括:
    定义位计时器,所述位计时器设置为固定字节数所对应的时长;串口按照串口帧格式解码后存入串口接收数据的先进先出队列内;根据位定时器的结束时间,将串口接收数据的先进先出队列内的数据移至上传端批量上传端点内,等待USB 主机执行的USB批量上传请求包取走数据;数据取走后,位计时器清零并重新计时,不断循环上传。
  8. 根据权利要求7所述的USB虚拟串口实时上传数据的方法,其特征在于,所述位计时器设置定时时长为1.1个字节~1.9个字节长度,1.1个字节~1.9个字节长度由串口通讯波特率计算得到。
  9. 一种USB主机,其特征在于,包括处理器、存储器及存储在存储器中并可被处理器执行的软件程序,处理器执行该软件程序时能够实现权利要求1-8任一USB虚拟串口实时上传数据的方法。
  10. 一种USB虚拟串口实时上传数据的系统,其特征在于,包括权利要求9所述的USB主机及USB设备,USB主机与USB设备之间通过USB虚拟串口连接。
PCT/CN2022/092048 2022-01-29 2022-05-10 Usb虚拟串口实时上传数据的方法及系统、usb主机 WO2023142301A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
GB2312141.1A GB2618707B (en) 2022-01-29 2022-05-10 Method and system for real-time data uploading by USB virtual serial port and USB host

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210110028.5 2022-01-29
CN202210110028.5A CN114116577B (zh) 2022-01-29 2022-01-29 Usb虚拟串口实时上传数据的方法及系统、usb主机

Publications (1)

Publication Number Publication Date
WO2023142301A1 true WO2023142301A1 (zh) 2023-08-03

Family

ID=80361728

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/092048 WO2023142301A1 (zh) 2022-01-29 2022-05-10 Usb虚拟串口实时上传数据的方法及系统、usb主机

Country Status (3)

Country Link
CN (1) CN114116577B (zh)
GB (1) GB2618707B (zh)
WO (1) WO2023142301A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114116577B (zh) * 2022-01-29 2022-05-03 南京沁恒微电子股份有限公司 Usb虚拟串口实时上传数据的方法及系统、usb主机

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7035948B1 (en) * 2001-03-19 2006-04-25 Transdimension, Inc. System and method for USB controllers
US20090222841A1 (en) * 2008-03-03 2009-09-03 Moschip Semiconductor Technology Limited Acceleration of receive data throughput of a usb device
CN101815014A (zh) * 2010-02-09 2010-08-25 上海百络信息技术有限公司 基于连接的实时网络数据捕获方法
CN101894041A (zh) * 2010-07-15 2010-11-24 中兴通讯股份有限公司 多虚拟串口系统及其通信方法
CN106095716A (zh) * 2016-06-24 2016-11-09 武汉光迅科技股份有限公司 一种基于首尾循环队列的串口通信方法
CN107172181A (zh) * 2017-06-07 2017-09-15 河南辉煌城轨科技有限公司 一种基于双线程的文件传输方法
CN114116577A (zh) * 2022-01-29 2022-03-01 南京沁恒微电子股份有限公司 Usb虚拟串口实时上传数据的方法及系统、usb主机

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP3955512B2 (ja) * 2002-08-27 2007-08-08 富士通株式会社 データ処理装置及びパケット判別方法
CN113326093A (zh) * 2020-04-08 2021-08-31 阿里巴巴集团控股有限公司 数据处理方法、装置、电子设备及计算机可读介质

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7035948B1 (en) * 2001-03-19 2006-04-25 Transdimension, Inc. System and method for USB controllers
US20090222841A1 (en) * 2008-03-03 2009-09-03 Moschip Semiconductor Technology Limited Acceleration of receive data throughput of a usb device
CN101815014A (zh) * 2010-02-09 2010-08-25 上海百络信息技术有限公司 基于连接的实时网络数据捕获方法
CN101894041A (zh) * 2010-07-15 2010-11-24 中兴通讯股份有限公司 多虚拟串口系统及其通信方法
CN106095716A (zh) * 2016-06-24 2016-11-09 武汉光迅科技股份有限公司 一种基于首尾循环队列的串口通信方法
CN107172181A (zh) * 2017-06-07 2017-09-15 河南辉煌城轨科技有限公司 一种基于双线程的文件传输方法
CN114116577A (zh) * 2022-01-29 2022-03-01 南京沁恒微电子股份有限公司 Usb虚拟串口实时上传数据的方法及系统、usb主机

Also Published As

Publication number Publication date
GB202312141D0 (en) 2023-09-20
CN114116577B (zh) 2022-05-03
GB2618707A (en) 2023-11-15
CN114116577A (zh) 2022-03-01
GB2618707B (en) 2024-04-03

Similar Documents

Publication Publication Date Title
US11176068B2 (en) Methods and apparatus for synchronizing uplink and downlink transactions on an inter-device communication link
US6397316B2 (en) System for reducing bus overhead for communication with a network interface
US6393457B1 (en) Architecture and apparatus for implementing 100 Mbps and GBPS Ethernet adapters
KR100677538B1 (ko) 입출력 종료 보고서를 결합하는 호스트 어댑터와 그의사용방법
CN108763121B (zh) TTE端系统适配卡PCIe控制器的中断操作方法
CN101620551B (zh) 一种面向多虚拟机应用的网卡中断控制方法
WO2023142301A1 (zh) Usb虚拟串口实时上传数据的方法及系统、usb主机
US6735662B1 (en) Method and apparatus for improving bus efficiency given an array of frames to transmit
US8745296B2 (en) Serial storage protocol compatible frame conversion, at least in part being compatible with SATA and one packet being compatible with PCIe protocol
CN109992543A (zh) 一种基于zyzq-7000的pci-e数据高效传输方法
US20080147905A1 (en) Method and system for generating a DMA controller interrupt
CN116069711B (zh) 直接内存访问控制器、异构设备、内存访问方法及介质
CN108959136A (zh) 基于spi的数据传输加速装置、系统及数据传输方法
CN103885840A (zh) 一种基于AXI4总线的FCoE协议加速引擎IP核
CN101937413B (zh) 一种i2c总线的通信方法
EP4213030A1 (en) Method and device for data processing
CN110990309B (zh) Tte端系统适配卡pcie控制器的高效中断操作方法
US7080189B1 (en) USB device communication
CN115794721A (zh) 一种基于多核的PCIe网卡及其工作方法
CN108874685B (zh) 固态硬盘的数据处理方法以及固态硬盘
CN110727619B (zh) 基于sdio接口的通信系统及数据传输方法
CN114365104A (zh) 针对慢速设备和功率节省的sdio芯片间互连协议扩展
CN114900471B (zh) 一种高性能无阻塞数据传输方法
KR20070024600A (ko) 호스트 제어기 및 그 동작 방법
CN116627869B (zh) 应用于电子设备的数据传输方法及装置

Legal Events

Date Code Title Description
ENP Entry into the national phase

Ref document number: 202312141

Country of ref document: GB

Kind code of ref document: A

Free format text: PCT FILING DATE = 20220510

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22923116

Country of ref document: EP

Kind code of ref document: A1