Design of network monitoring system under real-time kernel uC/OS-II

Abstract: This paper introduces the design process of a Web server embedded in a single-chip microcomputer. It gives the design of the hardware platform RTL8019AS hardware platform under the control of the single-chip microcomputer, and the application scheme of the simplified TCP/IP protocol stack accessing the Internet through the LAN. At the same time, the real-time kernel uC/OS-II management scheme for the whole system is briefly introduced, and the monitoring of the existing devices connected to the system I/O bus is completed.

Keywords: Web server, single-chip microcomputer, uC/OS-II, TCP/IP protocol stack, dynamic IP configuration

With the advent of the information age, especially the rapid spread of the Internet, people are beginning to get more and more exposed to a new concept - embedded products. Connect the embedded system to the Internet. Not only the remote control, maintenance and upgrade of the device, but also resource sharing can be realized. An external interface is indispensable for monitoring devices through the network. The use of a Web browser allows users to manage and update remote systems over the network, greatly simplifying the design of the human-machine interface. If the real-time operating system is embedded in the system, the system will be highly portable, and the addition and cutting of hardware devices will be extremely flexible. The DHCP protocol is used to dynamically obtain IP-related information, so that the TCP/IP software no longer depends on the fixed IP address stored in the chip, which will provide convenient conditions for the installation of large systems.

The key to this design is how to use the real-time kernel uC/OS-II to turn the information into IP packets that can be transmitted over the Internet on a single-chip system with limited memory resources, so as to monitor the state of the remote device through the IE browser.



Click here to view the picture in a new window

1 Network Monitoring System Overview

This design uses the Internet to monitor remote devices, and the entire system is equivalent to a network server. The client accesses the server through the IE browser, and obtains the state information of the device in real time to control and maintain the device. In this way, the server is required to provide the , that is, implement the HTTP protocol. It should be supported by all browsers to ensure that users anywhere can use the browser to issue commands. On the network interface, the system selects the network environment in which Ethernet operates. Figure 1 shows the HTTP design model. First, the client's browser and the web server use one or more TCP connections to communicate through port 80. The browser browses the control webpage stored in the EEROM in advance through the HTTP protocol, and passes the control command to the web server through the webpage, and then The server parses the command and calls the corresponding function to control the external I/O device.

The entire equipment monitoring system consists of hardware and software. The TCP/IP protocol stack is embedded in the hardware part. Due to the limited system resources, the content of the agreement should be reduced as much as possible while maintaining the layered architecture of the protocol. According to the principle of the network monitoring system, the system implements the following protocols: DHCP, HTTP, TCP, IP, ICMP, ARP.


Click here to view the picture in a new window

2 hardware platform design

This design uses Ethernet as the operating environment of the network, and requires a network control chip on the hardware. There are many Ethernet control chips on the market, but most of them are high in power consumption and complex in function, and are not suitable for use in low-cost embedded systems. The RTL8019AS is chosen here, which has the advantages of NE2000 compatibility, good software portability, simple interface, and no need to convert chips such as PCI-ISA bridge. The single-chip selects 89C55, it has 20K ROM, the internal structure is simple, as long as the code can be transplanted to it, it can be easily transplanted to Other architecture CPUs, such as ARM. Figure 2 is a block diagram of the hardware. 24C64 is used to store physical addresses and related information of devices; external RAM provides buffering for data processing. The system provides an RS232 interface for testing and an RJ45 interface for connection to Ethernet.
3 operating system choice

According to the characteristics of the monitoring system, the system must meet the requirements of real-time and concurrency in order to better support the scheduling of TCP/IP runtime, so the application software should be based on the embedded real-time operating system. It is suitable for on-chip real-time operating systems, but the code is open and suitable for porting 51 series MCUs, mainly uC/OS-II, RTX51, Small RTOS51, etc. The real-time kernel uC/OS-II is designed specifically for microcontroller embedded applications. Figure 3 shows the internal structure of the embedded real-time operating system. It is written primarily in the standard ANSI C language, and the hardware-related parts are written in assembly language to make it easy to port the operating system to other processors. It can be seen that when using the embedded operating system, the application software is only related to the upper layer code and has nothing to do with the processor. Only the hardware-related underlying functions need to be modified during software migration, so such application software has good portability. And stable reliability. Writing TCP/IP protocol under uC/OS-II is much more convenient than traditional front-end and back-end systems. It can be used to analyze memory buffer area, use before application, and release after use, which can effectively utilize system resources. The TCP/IP stack is tasked during programming, and the user program runs in another task. In this way, the MCU can realize network communication under the premise of completing the function of the original control system. In terms of code length, the TCP/IP protocol stack that implements basic functions is more advantageous than other operating systems such as Linux.

4 software design

Software design is an important part of network monitoring system design, mainly to complete the RTL8019AS driver, uC/OS-II corresponding system management and TCP/IP protocol stack implementation.

4.1 Application of uC/OS-II operating system

uC/OS-II can be tailored to the 51 MCU as needed. It is used to manage the system, making the program easy to read and easy to port.è—½/OS-II is mainly responsible for managing NIC initialization, creating system resources, and creating tasks. In the creation of system resources, TxSem, RxSem semaphores and TxQFIFO queues are used. When the data needs to be sent or received, the RTL8019AS interrupt is triggered, and the CPU enters the interrupt vector into the interrupt service subroutine for event processing. The interrupt service subroutine determines the state of the system according to the value of the internal interrupt status register IMR of the RTL8019AS, and switches the system task through two semaphores TxSemPost and RxSemPost to make a task of the corresponding semaphore of the system enter the ready state. The process of sending data frames is performed by checking the semaphore TxSemPost. In order to ensure that the data arrives at the client correctly, a multiple transmission mechanism is used here. When the semaphore RxSemPost arrives, it starts receiving data. If the data frame is correct, apply the appropriate memory space according to the size of the data packet to store the data, and then decide whether to submit the frame to the upper layer application according to the correctness of the destination address of the received frame. If there is no error, parse the data header and handle it accordingly.


Click here to view the picture in a new window

4.2 RTL8019 driver

The RTL8019AS performs the conversion between the data packet and the electrical signal. The driver mainly includes three parts: chip initialization, receiving and sending. The transceiver operation on the physical channel uses the Ethernet protocol 802.3 frame format. The principle of sending and receiving data packets by the system is that the MCU first stores the data packet to be sent into the RTL8019 chip RAM, and gives the first address of the transmission buffer and the packet length (written to TPSR, TBCR0, 1), and then starts the sending command (CR=0x3E). ), the transmission function of RTL8019 can be realized. The RTL8019 automatically sends the transmission according to the Ethernet protocol and writes the result to the status register. The RTL8019 chip receive buffer forms a circular FIFO queue. The PSTART and PSTOP registers define the start and end pages of the cyclic queue. CURR is the write pointer, controlled by the chip, and BNRY is the read pointer, which is controlled by the host program. According to CURR==BNRY+1? It can be judged whether a new data packet is received, and the newly received data packet is stored in the RAM with the address indicated by CURR as the first address. When CURR==BNRY, the chip stops receiving packets.
4.3 Implementation of the network protocol stack

Based on the TCP/IP protocol, a variety of functions can be implemented. This article mainly discusses the HTTP protocol, which is the main composition protocol of the Web service at the application layer. Since the TCP/IP protocol stack itself is a layered structure, the modularization idea is adopted in the design of the protocol stack, which is implemented layer by layer, and then the complete protocol stack is realized by calling each layer interface function. The general flow of implementing the TCP/IP protocol stack is shown in Figure 4.

To connect the embedded system as a terminal and connect it over TCP/IP, you must set the IP address, gateway, and subnet mask. In order to enhance the flexibility of the system, an automatic configuration capability is required, that is, the system automatically obtains information such as an IP address from the central server. The standard way to do this is through the Host Dynamic Configuration Protocol (DHCP). DHCP is based on the application above the UDP layer. It uses port 68 and 67 to communicate in the form of broadcast. Its work mainly includes operations such as probing, giving, requesting, and confirming.

The HTTP protocol chooses to define a request-response mechanism to obtain files on the web server. When a user accesses a web page in a web server, an HTTP request is sent from the browser to the web server in the form of a multi-line string. The first line specifies a method GET followed by a string of parameters. The server responds to the client with an HTTP header. If the request is successful, it also includes the document itself. This information is sent along the TCP connection until the transfer is complete. A message header containing a small amount of information contains the success or failure status and the content type (text, HTML, GIF graphics, etc.) of the transmitted document. All connection related information such as IP address, guest port number, serial number, response number and TCP status are placed into a structure, and each element of the structure can be regarded as a connection state. The server process closes the connection to indicate the end of this response. The web page information is stored in the EEROM in HTML text format, and the web server creates a local change to match the special characters in the document. The information is sent to the browser along the TCP connection through the HTTP protocol, and the server encounters the appropriate character in the response document. Replace a variable value to implement a dynamic web page.

In order to pass HTTP request and response information between the server and the room side, a reliable communication channel is required, which is provided by the Transmission Control Protocol TCP. TCP provides a reliable connection-oriented data flow service whose main task is to create process-to-process communication. Data transmission takes place in three phases: establishing connections, transferring data, and disconnecting are relatively complex to implement. Since the embedded system is the server side, it always responds to the client's connection request and never initiates the connection request. Therefore, as long as the embedded system can correctly respond to the TCP packet, the TCP protocol can be made large. Simplified amplitude. The embedded system always responds to the client connection and always passively opens the connection, so it only needs to provide the LISTEN and SYN_RCVD states for the embedded system in the process of establishing the connection. Although the CLOSED and SYN_SENT states are missing from the standard state transition diagram, LISTEN and SYN_RCVD are sufficient to describe the state when the system establishes a connection. When the system is transmitting the last packet, set FIN to terminate the current connection. Both active and simultaneous shutdowns are possible, so you only need to provide the system with active shutdown and simultaneous shutdown.



Click here to view the picture in a new window

In order to pass TCP segments between hosts, an IP protocol needs to be implemented. The implementation of the IP protocol is more complicated, but from the specific requirements of implementing the Web server, it is necessary to grasp the following two design ideas: First, the received IP datagram is processed, and the upper layer protocol is submitted; second; It is responsible for encapsulating TCP packets and ICMP packets and submitting them to the data link layer for binding. In fact, this is the most basic function of the IP protocol, and it is also a necessary function of the Web server at the network layer. The ICMP protocol is responsible for transmitting error messages and other information that needs attention. Ping uses the reverberation function of the ICMP protocol to test whether the host/server responds. The implementation of Ping is mainly completed by three functions: ping request, ping response, and echo operation.

Design of network monitoring system under real-time kernel uC/OS-II



HC Network December 22, 2005 10:35 Information: Electronic Technology Applications

Because of the Ethernet access method, the system must implement the IEEE802.3 standard, which is mainly completed by the RTL8019AS. In order to ensure the communication of the system in the Ethernet, the ARP protocol needs to be implemented. The essence of the ARP protocol is to complete the mapping from the network address to the physical address, thus ensuring the correct transmission of the network. The entire ARP processing process is implemented by three functions: ARP request, ARP response, and ARP processing. The ARP processing function establishes an ARP cache table.

The embedded network monitoring system introduced in this paper uses IE browser as the client interface, supports RS232 and Ethernet connection, can access the Internet through Ethernet, and then realizes monitoring embedded devices from the Internet. In practical applications, if the I/O port is connected to other hardware devices, remote monitoring can be realized by simply changing the processing function of the variable. The system is embedded with the uC/OS-II operating system and is flexible enough to be programmed to add the required functions. The use of DHCP to dynamically obtain information such as IP addresses enhances system flexibility. The network monitoring system realized by the solution has the characteristics of low cost, visualization, and platform independence, and can be widely applied in the field of industrial control, and has high practical value.



:
0 times
Window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "2", "bdMiniList": false, "bdPic": "", "bdStyle": " 0", "bdSize": "24" }, "share": {}, "image": { "viewList": ["qzone", "tsina", "tqq", "renren", "weixin"], "viewText": "Share to:", "viewSize": "16" }, "selectShare": { "bdContainerClass": null, "bdSelectMiniList": ["qzone", "tsina", "tqq", "renren" , "weixin"] } }; with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share. Baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];

Barbed Wire

Shunxing Hardware Wire Mesh Co., Ltd. , http://www.rywiremesh.com