Information appliance network server based on streamlined TCP/IP protocol stack

introduction

The S1C33209 is a 32-bit high-performance CMOS microprocessor from RISC. It features high speed, low power consumption, low voltage operation, and reduced instruction set. It provides multiply and accumulate functions for office equipment and is also suitable for use. For portable devices that require advanced data processing, high-speed computing, flexible I/O port control, and efficient data manipulation are possible. The S1C33209 has 8KB of internal RAM with an operating rate of up to 60MHz, plus an optimized instruction set for most single clock cycles, which greatly increases the throughput of the S1C33209. The S1C33209 has faster computing speeds, reliable performance, and reprogrammable architecture than conventional MCUs, enabling streamlined TCP/IP to operate reliably.

1 hardware platform structure and design

When the information appliance is remotely accessed, the amount of communication data is not large, and the communication rate of 10M Ethernet can meet the requirements; secondly, the information appliance has low requirements on real-time performance and can be positioned in the second level.

In this case, the home appliance network hardware platform server S1C-WebServer is constructed, and its structure is as shown in FIG. 1. S1C33-WebServer is mainly composed of three parts, namely S1C33209 microprocessor, RTL8019AS full-duplex Ethernet controller (RealTek, 100-pin TQFP package, maximum speed 10Mbps, 16KB SRAM, working in Ethernet II and IEEE802). .3, 10Base5, 10Base2, 10BasetT, full duplex, support 8-bit and 16-bit data bus, compatible with NE2000), rewritable Flash (using Intel's E28F320, capacity 4MB). Considering that Flash erasing is not convenient in program debugging, it expands 512KB of SDRAM for the S1C33209 peripheral. In S1C33209, run the user program and S1C33-Stack. In the Flash, the various Web resource information of the S1C-WebServer is stored, and the Web page, the image file, and the like can be processed, and the hard disk in the WebServer on the PC can store a large number of different pages. The size of Flash determines the size of the WebServer resource file. The RTL9019AS is an Ethernet controller responsible for data transfer between the S1C33209 and Ethernet. The home automation bus HAB (Home AutomaTIon Bus) is used as the S1C33-WebServer and the home network protocol SHNP (Simple Home Networks Protocol) under the condition that the information appliance has the RS232 or the related standard interface. The home appliance is connected to the S1C33-WebServer through the RS232 interface and connected to the Internet via the EEthernet.

After analysis, the S1C33209 is compatible with the RTL8019AS read and write timing, and the read and write latency of the MCU is much smaller than the RTL8019AS. The connection between the MCU and the RTL8019AS is shown in Figure 2. The operating voltage of the RTL8019AS is 5V, while the operating voltage of the S1C33209 is 3.3V, so the data line output of the RTL8019AS requires level conversion. The 8-channel (using a 16-bit data bus) 74HC245 with bidirectional data transfer is used. Since the output level of the S1C33209 meets the input level requirements of the RTL8019AS, the address lines can be directly connected without level shifting. The RTL8019AD interrupt signal (INT0) is active high. It is connected to the K60 port of the S1C33209 with port interrupt input. Since the interrupt valid mode (high, low or pulse) of the S1C33209 can be adjusted according to the setting of the register, there is no need to reverse or level shift the INT0.

2 Streamlined implementation of TCP/IP protocol stack

The built S1C33-Stack runs on a hardware platform based on the S1C33209 embedded CPU and is a set of configurable Internet protocols. These protocols are organized in a layered protocol stack, including HTTP, DHCP, SMTP at the application layer, TCP, UDP at the transport layer, IP/ICMP, ARP at the network layer, and data through the link layer and the physical layer (such as Ethernet). Interaction. The structural model of the S1C33-Stack is shown in Figure 3. The S1C33-Stack utilizes the high-speed processing power of the S1C33 to process TCP/IP packets, avoiding the need to buffer large amounts of data in a limited amount of RAM, allowing the controller to process more packets than the internal RAM bus. With the embedded S1C33-Stack, Webserver can communicate with any browser through Hypertext Transfer Protocol (HTTP), providing various types of resources, such as HTML, image files, and so on. These resources can be stored in a 4MB Flash using a special file system URI. This file system can contain as many directories as there are no restrictions on the length of the URL.

Considering the limited resources available for embedded systems, the reduced TCP/IP protocol stack, uIP, is used here. The uIP protocol mainly includes four basic protocols in the TCP/IP protocol suite: ARP, IP, ICMP, and TCP. The link layer protocol, such as PPP, is implemented as a device driver under the uIP. Application layer protocols, such as HTTP, FTP, and SMTP, are implemented as applications on top of uIP.

(1) Address Resolution Protocol ARP

The protocol maps IP addresses to Ethernet MAC addresses. In uIP, ARP execution relies on maintaining a table to map the IP address and MAC address. When there is an IP packet to be sent to the Ethernet, the corresponding MAC address is queried from the ARP table. If the IP address is not found in the ARP table, the corresponding ARP request is sent. After receiving the ARP Request packet, the destination host sends an ARP REPLY packet to send the requested MAC address. The ARP table is updated when ARP REPLY is received. Every 10 seconds, the ARP table is newly updated, and the old ARP entries are deleted. The lifetime of each ARP entry is 20 minutes.

(2) Internet Protocol IP

In uIP, the IP layer code has two functions: verifying the correctness of incoming IP packet headers, and offloading TCP and ICMP packets. Because IP fragmentation and reassembly are not considered, the IP layer code in uIP is very streamlined.

(3) Inter-network message control protocol ICMP

In uIP, only one type of ICMP information is implemented: ICMP ECHO is mainly used for application ping, checking whether the network is connected. In uIP, ICMP ECHO is usually handled in a very simple way; the ICMP type is changed from "ECHO" to "REPLY", and the ICMP check is adjusted to exchange the IP addresses of the sender and receiver.

(4) Transmission Control Protocol TCP

In order to reduce the use of memory, in uIP, TCP does not use a sliding window to receive and send data, and the arriving TCP message is not buffered but is immediately handed over to the application for processing. However, the application itself can buffer the data to be sent by the program itself to be sent, because there are usually several TCP messages to be sent in each connection. The structure of the uIP network communication module is shown in Figure 4.

Network communication requires the support of the underlying RTL8019AS driver. Refer to the RTL8019AS and S1C33209 data documentation to write the RTL8019AS driver for this system.

uIP does not cache incoming packets. When a packet on the network (specially indicating too frame) arrives at the network card, the NIC driver temporarily stores the packets in the NIC cache, one at a time, in DMA format to the target board. On the RAM. At this time, there will be a piece of code to copy the data packet arriving in the target board RAM to the global array uip_buf[], and the uIP protocol stack program then operates on the data in uip_buf[].

When the upper application or protocol stack program generates a packet sent to the network, it also puts the packet into uip_buf[]. Then call the network card driver, read the data in uip_buf[] into the cache of the network card, and then send it to the network.

Here is a description of the synchronization mechanism between the protocol stack and the network card driver and application. At the time of system initialization, three tasks are created by the system call vcre_tsk() provided by the operating system: task one (task1), uIP protocol stack, task two (task2), appliance monitoring program, task three (idle_task), idle task. The NIC driver is used as a hardware interrupt and is triggered by the "Detected network upload packet" event.

The flow chart of the entire protocol stack is shown in Figure 5.

Task 1 has the highest priority, task twice, and task 3 has the lowest priority. When the system starts running, the task first enters the RUN state, and the system call wai_flg() is added to the task 1. Since there is no network request, the task 1 subsequently enters the WAIT state. At this point, task two enters the RUN state. When a packet arrives on the network, the NIC driver begins execution as a hardware interrupt. Before exiting the interrupt, the task is set to the desired flag by the system call set_flg(). After the interrupt returns, since the waiting condition of task one has been satisfied, the priority of task one is higher than that of task two, so the task enters the RUN state, that is, the uIP protocol starts processing data. If there are always packets arriving on the network, task one and interrupt routines are constantly switching. When the network task is completed, return to the breakpoint of task two and continue to execute downward.

Since uIP does not cache network data, all interrupts are closed during the execution of task 1, ie when uip_buf[] is being operated. This can avoid the packet being destroyed. The disadvantage is that the real-time performance is worse, but it satisfies the requirements of this system.

3 operating system

The operating system used in this system is ROS33V31 provided by EPSON. ROS33 is an embedded real-time operating system for the S1C33 series MCUs that meets the uITRON 3.0 standard. Use ROS33 to quickly and efficiently develop embedded applications for printers, PDAs, and various control devices.

ROS33 has the following characteristics:

* Supports the uITRON 3.0 standard - S-class * compliant with this standard * The maximum number of tasks is 255, using a priority scheduling mechanism, supporting 9 different priorities, providing various communication mechanisms such as signal lights, mailboxes, and message buffers:

* Kernel is prioritized and compact - a minimum of 1.7K;

* Fast response - the fastest scheduling response time is 7.8μS (CPU frequency is 33MHz, the same below), the maximum interrupt masking time is 4.3μs;

* High-level language support - In addition to assembly language, it also supports C language programming based on ANSI standards.

Note: μITRON divides system functions into four levels. The R level (required level) only provides the basic system calls required for real-time, multitasking OS; the S level (standard level) provides all standard system calls; the E level (extension level) includes additional and extended system functions; The level (CPU dependent level) system functionality depends on the specific CPU and system implementation.

The basic kernel of ROS33 is divided into 6 parts by function:

*Task management - responsible for the change of task status in the system;

* Task-related synchronization management - through the sleep / wake, suspend / unhook operations, etc., to handle the synchronization relationship between related tasks and tasks;

* Synchronization and communication - Synchronization and communication between independent tasks through communication mechanisms such as signal lights, events, and mailboxes;

* System Management - Management of the system environment;

*Clock management - management of calendar clocks, timers, timing tasks, etc.;

* Interrupt management - On/Off interrupt.

Figure 6 shows the conceptual model of the ROS33 core.

4 Web server and upper application framework

The way the WEB server is used is called uip_connect, which is more suitable for embedded systems than the Sockets that are usually used in the design. It is the general framework of the WEB server.

#include

Void http_listen_init(void){

Uip_listen(80);

} //http listen initialization

Void listen_init(void){

Http_listen_init();

}

Void applicaTIon(void){

If(uip_connected()) //If the current connection state is connected

Switch (uip_conn->lport){

Case htons(80):

Httpd; / / If 80 PORT has data arrived, call HTTP to process the transmission of the HTML file

}

}

First, the server establishes a connection with the client, and then listens to the port 80 to determine whether a client request arrives. If so, the application httpd is called to perform corresponding processing; otherwise, the listener continues. Httpd is an application for handling HTTP requests, and the specific design is described in the protocol stack uIP. Uip.h is a header file for the protocol uIP.

The simple WEB server function is implemented on the application software, which is mainly composed of two modules: one is a user login module; the other is a home appliance monitoring module. The user login module needs to solve the user's legality check, that is, receive the user name and password input by the user, and perform verification. If it is legal, it will enter the homepage monitoring page, and if it is illegal, it will issue a warning page. The home appliance monitoring module collects the status code of the information appliance for each hardware condition of the home appliance, and displays it by webpage.

In the two modules, there is a part of similar processing, that is, the input data is parsed. Now define the array htmlinputs to store the parsed information. After parsing the data entered by the form, store its name and value in htmlinput_struct.name and htmlinput_struct.value for later processing. The variable htmlinputcount stores the number of input variables in the form. The definition is as follows:

Struct htmlinput_struct htmlinputs[100];

Int htmlinputcount=0;

In addition, the functions get_inputs() and translate() are defined to process the input data.

Int get_inputs();//Load the data entered from the form into the corresponding name/value data team

Void translate(char*sourcestr);//Interpret the encoded URL character

The specific program code will not be described here.

The flow chart of the entire upper application is shown in Figure 7.

5 Summary

As an interface, Ethernet uses the S1C33 series microprocessor as the hardware platform, and can realize HTTP service by using software-based streamlined embedded TCP/IP. Of course, in the mature system, you can also consider replacing the Ethernet interface with a wireless network interface. This article provides a solution for the information appliance network to access the Internet without the need for additional PC or gateway devices. This low-cost, high-performance solution is reliable and flexible, and is suitable for home automation equipment that has a low communication rate and allows a delay of more than 1 s and requires Internet connection. In addition, users can construct their own network servers according to this method according to their needs. They can give Internet access to common electrical equipment or systems such as public service equipment, home healthcare equipment, and industrial automation systems.