Embedded serial port server design using RTL8019 and LPC2210 chips

Publisher:sjjawx831Latest update time:2023-04-07 Source: elecfansKeywords:RTL8019 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

With the widespread application of digital information technology and the Internet, embedded systems marked by operating systems and the Internet are the development trend of the post-PC era. The 232/485 communication interface widely used in industry is connected to the Internet, allowing a large amount of data from various sensors, controllers and other devices to be transmitted over the Internet.


The serial port server was born from this. By expanding multiple serial ports, various peripherals can be remotely monitored and managed on the PC side, or system upgrades can be performed on the peripherals. Usually the serial port server uses an ARM9 microprocessor and a paid operating system with a TCP/IP protocol stack. The serial port server proposed in this article is implemented by transplanting the LW IP protocol stack to the open source μC/OS-Ⅱ. This not only reduces the cost, but also reduces the cost. Moreover, the writing of code is more transparent and flexible.


1Design of hardware system

This serial server uses Philip's ARM7 series chip LPC2210, the network control chip uses RTL8019, and the serial port uses TL16C554 chip expansion. In order to obtain a wider range of applications, the serial port also expands the 485 interface, and selects the 232/485 mode through a jumper. The system structure block diagram is shown in Figure 1.

Embedded serial port server design using RTL8019 and LPC2210 chips

Figure 1 System structure block diagram

2 Implementation of software system

The serial server software system includes two parts: TCP/IP protocol stack transplantation and real-time multi-tasking application. The transplantation of μC/OS-Ⅱ into the LPC series ARM adopts Zhou Ligong's solution.


2.1Transplantation of TCP/IP protocol stack

LW IP is an open source streamlined TCP/IP protocol stack developed by Swiss Adma Dumkels and others. The purpose is to reduce the demand for system resources while ensuring the integrity of the TCP protocol, and is suitable for embedded system applications with fewer resources. There are two main parts of code for transplanting the LW IP protocol stack: (1) Writing code related to the operating system simulation layer; (2) Initial setting of the LW IP interface and network card driver.


2.1.1 Code related to operating system simulation layer

The main purpose of the operating system simulation layer is to provide a bridge between μC/OS-Ⅱ and LW IP, so that LW IP and μC/OS-Ⅱ can exist in a system with the same specifications and communicate with each other. LW IP has two process communication methods, semaphore and mailbox, and μC/OS-Ⅱ also provides these two process communication methods.


Semaphores are used to synchronize tasks. The operation functions include sys_new_sem (create and return a new semaphore), sys_ sem _ signal (specify the semaphore to be sent), sys_sem_free (specify the semaphore to be released), sys_arch_sem_wait (wait for the semaphore to be sent by the parameter sem) Specify the semaphore and block the thread), initialize the data structure in these function bodies and add the relevant functions in μC/OS-Ⅱ to complete.


The mailbox is used to deliver messages. LW IP allows the mailbox to be implemented as a queue, and multiple messages are delivered to this mailbox.

μC/OS-II provides a wealth of message queue functions, and the messages delivered to the mailbox by μC/OS-II and LW IP are all implemented using pointers. The system has established multiple mailboxes, and the mailboxes are connected through a one-way linked list. The maximum number of received messages is determined by the message array, and the structure diagram is shown in Figure 2.

Embedded serial port server design using RTL8019 and LPC2210 chips

Figure 2 Mailbox data structure diagram

After the mailbox is built, use the pointer P_Mbox to point to node 1. Apply for a new mailbox to disconnect node 1 and node 2. P_Mbox points to p stNext of node 1, and so on. The movement direction of P_Mbox during recycling is opposite to that during application. This will not waste memory and is more stable. Write mailbox-related functions based on the above structure and the functions provided by μC/OS-Ⅱ.


In addition, you also need to write the task creation function sys_thread_new and sys_arch_timeouts function. Since each task has a timeouts linked list, the sys_timeouts structure returned by the sys_arch _timeouts function saves the first address of the timeouts linked list.


2.1.2LW IP initialization settings and underlying driver

The initialization setting of LW IP is included in the entry function of the LW IP communication process. The basic structure of its entry function LwipEntry is as follows:

Void LwipEntry (void 3 pvArg)

{

//Initialize LW IP, involving all aspects of the memory area, PCB (TCP/UDP) and OS simulation layer used by LW IP

__ilvInitLwip();

//Set LW IP, including adding and configuring network interfaces, establishing and accepting tasks, etc.

__ilvSetLwip();

//Create LW IP application here. The server supports TCP/UDP mode. Both methods are established.

}

The underlying driver must be called every time the server sends and receives data. This part of the code needs to have good robustness and stability. The entire implementation sequence is shown in Figure 3.

Embedded serial port server design using RTL8019 and LPC2210 chips

Figure 3 Underlying program framework diagram

The sending main line first starts with the Ethernet initialization function (1), calls the link layer sending function (2) and adds each layer protocol header, and then calls the RTL8019 sending function (9) to send data.


In addition to initializing the Ethernet, the receiving main line needs to call the link layer initialization function (3), and call (4) in (3) to initialize the RTL8019.


The received data first passes through function (8), and then is transmitted to function (6) through the semaphore. (6) calls (7) to get the number of data. Finally, (5) determines the number of data based on the upper layer protocol type carried by the Ethernet frame header. Determine whether to hand it over to the IP protocol or the ARP protocol.


After the transplantation is completed, the data sending and receiving experiment verification is carried out. Using the TCP transmission protocol, the network port virtual serial port software VSPM sends and receives data through the serial port debugging tool. Figure 4 is a screenshot of the data sent and received in the spontaneous self-receiving program at a sending speed of 10 ms.

Embedded serial port server design using RTL8019 and LPC2210 chips

Figure 4TCP protocol data transmission interface

Since COM1 and COM2 are occupied by the PC, the serial port virtualized by the network port is COM3. It can be seen from Figure 4 that under the connection-oriented TCP protocol, high-speed data sending and receiving will not lose packets.


2.2 Design of real-time multi-tasking solution

The 16 serial ports and network ports form 16 bidirectional channels. In order to make the code flexible and transparent, the program does not use the SOCKET API provided by LW IP. The application divides each two-way channel into three tasks: sending, receiving, and serial port. In addition, the LW IP itself takes up one task, and a total of 49 tasks need to be created. μC/OS-II can create up to 64 tasks, 8 of which are occupied by the operating system itself, and the remaining 56 can meet the requirements. The VSPM software simulates the network port into 16 serial ports, and the 16 ports listened by the serial server are 1000~1015, as shown in Figure 5.

Embedded serial port server design using RTL8019 and LPC2210 chips

Figure 5 Network port virtual expansion 16 serial port interface

Data reception on the network side and serial port side will trigger corresponding interrupts. The three tasks of each bidirectional channel perform their own duties. After the network port end receives data and is interrupted, the port number of the source is determined by the transport layer protocol and handed over to the corresponding receiving task. After processing, it is handed over to the serial port task to transfer the data from the corresponding serial port. Send; After the serial port receives the data, it determines the channel number of the source in the interrupt program, and hands the data to the serial port task. After processing, the sending task sends the data through the network port.


The server supports two transmission protocols, TCP/UDP. The TCP transmission flow chart of a channel is given below. The UDP part of the code only needs to call the UDP function provided by LW IP in the corresponding task. In TCP mode, the serial port server works in Server mode, and the PC works in Client mode. The flow chart is shown in Figure 6.

Embedded serial port server design using RTL8019 and LPC2210 chips

Figure 6 Serial server single channel program flow chart


3.Conclusion

This article designs a low-cost serial port server with a simple hardware framework and flexible software structure. Although this server uses ARM7 as the main control chip, which is not as good as ARM9 and cannot use Linux, two open source codes μC/OS-Ⅱ The effective combination of real-time operating system and LW IP protocol stack avoids high software costs and can meet communication requirements. Experiments have proven that the serial port server based on LW IP and μC/OS-Ⅱ can not only achieve two-way communication, but also transmit data in real time and accurately, meeting the requirements of industrial applications.


Keywords:RTL8019 Reference address:Embedded serial port server design using RTL8019 and LPC2210 chips

Previous article:Design of automatic switch life test system based on LPC2138CPU chip
Next article:Design of central air conditioning control system using μC/OS-II and LPC2210 processor

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号