Serial port converter device and method based on ebi bus

文档序号:68086 发布日期:2021-10-01 浏览:61次 中文

阅读说明:本技术 基于ebi总线的串口转udp的装置及方法 (Serial port converter device and method based on ebi bus ) 是由 郑俊强 胡锦丽 王伟生 陈懋 周素青 王洪 张晓敏 陈岩峰 黄政钦 陈友武 李自 于 2021-07-01 设计创作,主要内容包括:本发明提出一种基于ebi总线的串口转udp的装置及方法,其采用epoll模型,监听所有文件描述符以及socket描述符。Epoll是基于事件驱动的模型,因此在进程中,不需要阻塞进程来接受和发送数据,因此可以同时监听多个udp端口。采用基于ebi的总线来驱动串口数据,从而不需要模拟出ttyUSB端口,当需要对具体的串口进行数据收发时,只需配置寄存器,即可对应适配到具体的串口。采用Ebi总线驱动和串口之间的通信,不使用read和write操作,使用内存映射,当需要发送数据的对应的串口的时,只需通过对映射之后的内存进行赋值即可,当需要从串口读取数据时,也只需要读取映射之后的内存。避免频繁的read/write操作,导致系统性能急剧下降,导致数据丢包。(The invention provides a serial port converter device and a serial port converter method based on ebi bus, which monitor all file descriptors and socket descriptors by adopting an epoll model. Epoll is based on an event-driven model, so in progress, there is no need to block the process to accept and send data, so multiple udp ports can be listened to simultaneously. The bus based on ebi is adopted to drive serial port data, so that a ttyUSB port does not need to be simulated, and when data are required to be transmitted and received to a specific serial port, only a register needs to be configured, and the serial port can be correspondingly adapted to the specific serial port. The method adopts the communication between the Ebi bus driver and the serial port, does not use read and write operations, uses memory mapping, and only needs to assign values to the mapped memory when the corresponding serial port of data needs to be sent, and only needs to read the mapped memory when the data needs to be read from the serial port. Frequent read/write operations are avoided, so that the system performance is sharply reduced, and data packet loss is caused.)

1. The utility model provides a serial ports turn over device of udp based on ebi bus which characterized in that: monitoring all file descriptors and socket descriptors by adopting an epoll model; driving serial port data by adopting a bus based on ebi; the communication between the Ebi bus driver and the serial port uses memory mapping.

2. The serial port relay device based on ebi bus according to claim 1, wherein: 3 EBI is converted into RS232, and a chip is selected by a chip selection signal of the chip; each EBI-RS 232 chip supports serial ports of 8 channels, and data sending and receiving are set and inquired through registers.

3. The serial port relay device based on ebi bus of claim 2, wherein: when data of a serial port is to be sent to a CPU, a GPIO interrupt is generated, after the CPU receives the interrupt, the CPU learns which serial port the data is through a query register, and then the data is read through memory mapping; and each EBI serial port chip sends the GPIO interruption information.

4. The operating method of the serial port relay over ebi bus as claimed in claim 3, wherein the initialization process comprises the following steps:

step S1: creating 24 udp server side sockets, monitoring client side connection information by using epoll, and creating a socket of a second point after receiving the connection request information; the socket of the first point is used for monitoring the connection information and does not accept data; the socket of the second point is a socket special for receiving data, and an epoll model is used;

step S2: after the client is successfully connected, a socket is created again, and the socket is used for monitoring data streams;

step S3: initializing ebi driving, and creating ebi memory mapping space; and initializing ebi to RS232 chip, configuring serial port attribute information, configuring fifo of the chip, triggering GPIO interrupt when fifo exceeds a certain byte number, and informing CPU to fetch serial port data.

5. The operating method of the serial port relay over ebi bus-based device according to claim 4, wherein: in step S2, a plurality of such sockets may be created, and a single-threaded, single-process creation of a plurality of sockets can be implemented.

6. The operating method of the serial port relay over ebi bus-based device according to claim 4, wherein: in step S3, the serial port attribute information includes: baud rate of the serial port.

7. The operating method of the serial port relay over ebi bus-based device according to claim 4, wherein: the process of receiving serial port data is as follows: when fifo meets the condition, after triggering the interrupt, cpu directly reads the value of a certain memory area through memory mapping control until the data is empty; and when receiving the serial port event, generating an interrupt notice.

8. The operating method of the serial port relay over ebi bus-based device according to claim 4, wherein: the process of sending data to the serial port is as follows: when data needs to be sent to the serial port, 128 bytes are sent at most once, then the chip waits for being forwarded to the corresponding serial port, the CPU is informed through interruption, and when the ebi RS232 transferring sending buffer area is empty, the data can be sent continuously, and the above processes are circulated until the data is sent completely.

Technical Field

The invention relates to the technical field of data transmission and data conversion, in particular to a serial port converter device and a serial port converter method based on ebi buses.

Background

The hardware design of the USB-to-serial port scheme in the prior art is shown in the attached figure 1 of the specification, the hardware serial port uses a USB-to-serial port chip, the software design is shown in the attached figure 2 of the specification, and the USB-to-serial port scheme has the following characteristics:

1. a process is needed for forwarding data of each serial port and udp;

2. each serial port corresponds to a ttyUSB on the equipment file;

3. each data interaction requires one read and write operation.

The disadvantages of the above prior art include:

1. the data forwarding of each serial port and udp requires a process:

a. the expansion performance is insufficient, when more than 20 serial ports are needed, the system needs more than 20 processes, and the system resources are strained

b. Each process uses a series of resources of the system, so that the method wastes system resources greatly

2. Each serial port corresponds to a ttyUSB on the device file:

the corresponding relation between the ttyUSB port and the serial port cannot be determined, when the system has a plurality of serial ports, the ttyUSB has a chaotic condition, and the system cannot ensure that the ttyUSB devices are enumerated according to a certain sequence when enumerating the ttyUSB devices, so that the ttyUSB and the serial ports cannot be in one-to-one correspondence, and data forwarding is disordered.

3. Each data interaction requires one read and write operation:

when the system needs to read serial port data, a read operation is carried out, the read operation can be embedded into a system kernel to be executed, and when the system is embedded into the kernel to be executed, stack information can be saved, so that time waste and performance reduction are caused.

Disclosure of Invention

In order to solve the problems of defects and shortcomings in the prior art, the invention provides a serial port converter device and a serial port converter method based on ebi bus. Aiming at each main problem existing in the prior art, the invention respectively adopts the following solutions:

1. the data forwarding of each serial port and udp requires a process:

and monitoring all file descriptors and socket descriptors by adopting an epoll model. Epoll is based on an event-driven model, so in progress, there is no need to block the process to accept and send data, so multiple udp ports can be listened to simultaneously.

2. Each serial port corresponds to a ttyUSB on the device file:

the bus based on ebi is adopted to drive serial port data, so that a ttyUSB port does not need to be simulated, and when data are required to be transmitted and received to a specific serial port, only a register needs to be configured, and the serial port can be correspondingly adapted to the specific serial port.

3. Each data interaction requires one read and write operation:

the Ebi bus driver and the serial port are communicated, read and write operations are not used, memory mapping is used, when the corresponding serial port of data needs to be sent, only the memory after mapping needs to be assigned, and when the data needs to be read from the serial port, only the memory after mapping needs to be read. The memory mapping technology solves the performance problem of data interaction between a linux application layer and a drive layer, and avoids the rapid reduction of system performance and data packet loss caused by frequent read/write operations.

The invention specifically comprises the following contents:

the utility model provides a serial ports turn over device of udp based on ebi bus which characterized in that: monitoring all file descriptors and socket descriptors by adopting an epoll model; driving serial port data by adopting a bus based on ebi; the communication between the Ebi bus driver and the serial port uses memory mapping.

Further, 3 EBI is converted into RS232, and which chip is used is selected through a chip selection signal of the chip; each EBI-RS 232 chip supports serial ports of 8 channels, and data sending and receiving are set and inquired through registers.

Further, when data in the serial port is to be sent to the CPU, a GPIO interrupt is generated, after the CPU receives the interrupt, the CPU obtains which serial port data is through the query register, and then reads the data through memory mapping; and each EBI serial port chip sends the GPIO interruption information.

The working method of the serial port converter device based on the ebi bus is characterized in that the initialization process comprises the following steps:

step S1: creating 24 udp server side sockets, monitoring client side connection information by using epoll, and creating a socket of a second point after receiving the connection request information; the socket of the first point is used for monitoring the connection information and does not accept data; the socket of the second point is a socket special for receiving data, and an epoll model is used;

step S2: after the client is successfully connected, a socket is created again, and the socket is used for monitoring data streams;

step S3: initializing ebi driving, and creating ebi memory mapping space; and initializing ebi to RS232 chip, configuring serial port attribute information, configuring fifo of the chip, triggering GPIO interrupt when fifo exceeds a certain byte number, and informing CPU to fetch serial port data.

Further, in step S2, a plurality of such sockets may be created, and a single-threaded, single-process creation of a plurality of sockets can be implemented.

Further, in step S3, the serial port attribute information includes: baud rate of the serial port.

Further, the process of receiving serial port data is as follows: when fifo meets the condition, after triggering the interrupt, cpu directly reads the value of a certain memory area through memory mapping control until the data is empty; when receiving the serial port event, generating an interrupt notice;

further, the process of sending data to the serial port is as follows: when data needs to be sent to the serial port, 128 bytes are sent at most once, then the chip waits for being forwarded to the corresponding serial port, the CPU is informed through interruption, and when the ebi RS232 transferring sending buffer area is empty, the data can be sent continuously, and the above processes are circulated until the data is sent completely.

Compared with the prior art, the invention and the optimized scheme thereof realize the high-speed forwarding of the data through the memory mapping, improve the system performance and reduce the hardware cost; by epoll communication, single-process and single-thread monitoring of all data forwarding ports is realized, single-process and single-thread monitoring of all ports is realized, and system expansibility is improved.

Drawings

The invention is described in further detail below with reference to the following figures and detailed description:

FIG. 1 is a schematic diagram of a hardware design of a USB-to-serial scheme in the prior art;

FIG. 2 is a diagram of an example of a software design for a USB-to-serial scheme in the prior art;

fig. 3 is a schematic diagram of a hardware structure of a serial port converter based on ebi bus according to an embodiment of the present invention;

fig. 4 is a diagram illustrating a software flow of a serial port translator based on ebi bus according to an embodiment of the present invention.

Detailed Description

In order to make the features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in detail as follows:

the hardware design of the USB to serial port scheme in the prior art is shown in fig. 1, the hardware serial port uses a USB to serial port chip, and the software design is shown in fig. 2, and the scheme has the following characteristics:

1. a process is needed for forwarding data of each serial port and udp;

2. each serial port corresponds to a ttyUSB on the equipment file;

3. each data interaction requires one read and write operation.

The disadvantages of the above prior art include:

1. the data forwarding of each serial port and udp requires a process:

a. the expansion performance is insufficient, when more than 20 serial ports are needed, the system needs more than 20 processes, and the system resources are strained

b. Each process uses a series of resources of the system, so that the method wastes system resources greatly

2. Each serial port corresponds to a ttyUSB on the device file:

the corresponding relation between the ttyUSB port and the serial port cannot be determined, when the system has a plurality of serial ports, the ttyUSB has a chaotic condition, and the system cannot ensure that the ttyUSB devices are enumerated according to a certain sequence when enumerating the ttyUSB devices, so that the ttyUSB and the serial ports cannot be in one-to-one correspondence, and data forwarding is disordered.

3. Each data interaction requires one read and write operation:

when the system needs to read serial port data, a read operation is carried out, the read operation can be embedded into a system kernel to be executed, and when the system is embedded into the kernel to be executed, stack information can be saved, so that time waste and performance reduction are caused.

In order to solve the above drawbacks and deficiencies, the present embodiment provides an apparatus and a method for serial port converter based on ebi bus. For each main problem existing in the prior art, the following solutions are respectively adopted in the present embodiment:

1. the data forwarding of each serial port and udp requires a process:

and monitoring all file descriptors and socket descriptors by adopting an epoll model. Epoll is based on an event-driven model, so in progress, there is no need to block the process to accept and send data, so multiple udp ports can be listened to simultaneously.

2. Each serial port corresponds to a ttyUSB on the device file:

the bus based on ebi is adopted to drive serial port data, so that a ttyUSB port does not need to be simulated, and when data are required to be transmitted and received to a specific serial port, only a register needs to be configured, and the serial port can be correspondingly adapted to the specific serial port.

3. Each data interaction requires one read and write operation:

the Ebi bus driver and the serial port are communicated, read and write operations are not used, memory mapping is used, when the corresponding serial port of data needs to be sent, only the memory after mapping needs to be assigned, and when the data needs to be read from the serial port, only the memory after mapping needs to be read. The memory mapping technology solves the performance problem of data interaction between a linux application layer and a drive layer, and avoids the rapid reduction of system performance and data packet loss caused by frequent read/write operations.

Specifically, as shown in fig. 3, the hardware design of the present embodiment is as follows:

1. 3 pieces of EBI to RS232 are used in total, and the chip selection signal of the chip is used to select which chip is used

2. Each EBI-RS 232 chip supports serial ports of 8 channels, and data sending and receiving are set and inquired through a register

3. When data of the serial port is to be sent to the CPU, one GPIO interrupt occurs, after the CPU receives the interrupt, the CPU obtains the data of which serial port through the query register, and then reads the data through memory mapping. Each EBI serial port chip sends out a GPIO interrupt notice.

The software design scheme is a flow framework as shown in FIG. 4:

1. and creating 24 udp server side sockets, monitoring the client side connection information by using epoll, and creating a socket of a second point after receiving the connection request information.

2. After the client is successfully connected, a socket is created again, the socket is used for monitoring data streams, the socket at the first point is only used for monitoring connection information and does not receive data, the socket at the second point is a socket specially used for receiving data, and process blocking is avoided by using an epoll model. Multiple such sockets can be created, and single-threaded, single-process creation of multiple sockets can be implemented.

3. The driver of ebi is initialized and ebi memory mapped space is created. And initializing ebi to RS232 chip, configuring serial port attribute information such as baud rate of serial port, configuring fifo of the chip, triggering GPIO interrupt when fifo exceeds a certain byte number, and informing CPU to fetch serial port data.

4. Receiving serial port data: when fifo meets the condition, after triggering the interrupt, cpu directly reads the value of a certain memory area through memory mapping control until the data is empty. The receiving serial port is an asynchronous event and therefore requires an interrupt notification.

5. Sending data to a serial port: when data needs to be sent to the serial port, considering that the rate of the ebi bus far exceeds the baud rate of the serial port, at most 128 bytes can be sent at one time, then the chip waits for being forwarded to the corresponding serial port, the CPU is informed through interruption, the sending buffer of ebi-to-RS 232 is empty, the data can be continuously sent, and the process is circulated until the data is sent completely.

The present invention is not limited to the above preferred embodiments, and other various forms of serial port converter based on ebi bus and method thereof can be obtained by anyone skilled in the art from the teaching of the present invention.

9页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:用于SSD的总线多路复用器网格的高级CE编码

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!