introduction
S1C33209 is a 32-bit high-performance CMOS microprocessor with RISC structure introduced by EPSON. It has the characteristics of high speed, low power consumption, low voltage operation, and reduced instruction set. It provides multiply and accumulate functions. For portable devices that require advanced data processing, high-speed operations, flexible I / O port control, and efficient data operations can be performed. S1C33209 has 8KB of internal RAM, and its operation rate can reach 60MHz. In addition, the optimized instruction set, which is mostly a single clock cycle, greatly improves the throughput of S1C33209. S1C33209 has faster calculation speed, reliable performance and reprogrammable structure than conventional MCU, which makes the streamlined TCP / IP reliable in it.
1 Hardware platform structure and design
When remotely accessing information appliances, the amount of communication data is not large, and the communication rate of 10M Ethernet can meet the requirements. Secondly, the real-time requirements of information appliances are not high and can be located at the second level.
In this case, the home appliance network hardware platform server S1C-WebServer is constructed, and its structure is shown in FIG. 1. S1C33-WebServer is mainly composed of three parts, namely S1C33209 microprocessor, RTL8019AS full-duplex Ethernet controller (produced by RealTek, 100-pin TQFP package, maximum rate of 10Mbps, with 16KB of SRAM, working on Ethernet II and IEEE802 .3, 10Base5, 10Base2, 10BasetT, full-duplex, support 8-bit and 16-bit data bus, compatible with NE2000), erasable flash (using Intel's E28F320, capacity 4MB). Considering that Flash's erasure is not very convenient in program debugging, it expands 512KB SDRAM for S1C33209 peripheral. In S1C33209, run the user program and S1C33-Stack. In Flash, store various web resource information of S1C-WebServer, comprehensively process web pages, image files, etc., and the hard disk in WebServer on PC can store a large number of different pages. The capacity of Flash determines the size of WebServer's resource files. RTL9019AS is an Ethernet controller, responsible for data transfer between S1C33209 and Ethernet. Under the condition that the information appliances have RS232 or related standard interfaces, the Home Automation Bus (HAB) is used as the S1C33-WebServer and the Simple Home Networks Protocol (SHNP). The home appliances are connected to the S1C33-WebServer through the RS232 interface and connected to the Internet via EEthernet.
After analysis, S1C33209 is compatible with RTL8019AS read and write timing, and the MCU read and write delay is much smaller than RTL8019AS. The connection between MCU and RTL8019AS is shown in Figure 2. The working voltage of RTL8019AS is 5V, and the working voltage of S1C33209 is 3.3V, so the data line output of RTL8019AS needs level conversion. Choose two 8-bit (using 16-bit data bus) 74HC245 with bidirectional data transmission function to complete, because the output level of S1C33209 meets the requirements of RTL8019AS input level, so the address line can be directly connected without level conversion , RTL8019AD interrupt signal (INT0) is high level effective, select the K60 port of the port interrupt input in S1C33209 to connect to it. Since the interrupt effective mode (high, low or pulse) of S1C33209 can be adjusted according to the setting of the register), there is no need to reverse or level convert INT0.
2 Streamline the implementation of TCP / IP protocol stack
The constructed S1C33-Stack runs on a hardware platform based on the S1C33209 embedded CPU and is composed of a set of configurable multiple Internet protocols. These protocols are organized in a layered protocol stack, including application layer HTTP, DHCP, SMTP, transport layer TCP, UDP, network layer IP / ICMP, ARP, data through the link layer and physical layer (such as Ethernet) Interaction. The structural model of S1C33-Stack is shown in Figure 3. S1C33-Stack uses the high-speed processing capability of S1C33 to process TCP / IP data packets, avoiding the large amount of data cached in the limited-capacity RAM, so that the controller can process more data packets than the internal RAM bus. Using the embedded S1C33-Stack, Webserver can communicate with any browser through Hypertext Transfer Protocol (HTTP), and can provide various types of resources, such as HTML and image files. These resources can be stored in 4MB Flash using a special file system URI. This file system can contain any number of directories, and there is no limit to the length of the URL.
Considering that the available resources of the embedded system are limited, the reduced TCP / IP protocol stack—uIP is adopted here. The uIP protocol mainly includes the four basic protocols in the TCP / IP protocol group: ARP, IP, ICMP, TCP. Link layer protocols, such as PPP, are implemented as device drivers at the bottom of uIP. Application layer protocols, such as HTTP, FTP, and SMTP, are implemented on the upper layer of uIP as application programs.
(1) Address Resolution Protocol ARP
The protocol maps IP addresses to Ethernet MAC addresses. In uIP, the implementation of ARP depends on maintaining a table to complete the mapping of IP addresses and MAC addresses. When there is an IP data packet to be sent to the Ethernet, query the corresponding MAC address from the ARP table. If the IP address is not found in the ARP table, the corresponding ARP request is sent. When the destination host receives the ARP request message, it sends an ARP REPLY message to send out the requested MAC address. When ARP REPLY is received, the ARP table is updated. Every 10s, the ARP table is updated and the old ARP entries will be deleted. The life cycle of each ARP entry is 20 minutes.
(2) Internet Protocol IP
In uIP, the code of the IP layer has two functions: verify the correctness of the incoming IP packet header, and implement offloading of TCP and ICMP packets. Because IP fragmentation and reorganization are not considered, the code of the IP layer in uIP is very streamlined.
(3) Internet Message Control Protocol ICMP
In uIP, only one type of ICMP information is implemented: ICMP ECHO is mainly used for application ping to check whether the network is connected. In uIP, ICMP ECHO is usually handled in a very simple way; ICMP type is changed from "ECHO" to "REPLY", and ICMP check is adjusted at the same time, and the IP addresses of the sender and receiver are exchanged.
(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. The arriving TCP packets are not buffered but immediately handed over to the application for processing. But the application itself can buffer the data to be sent by the program to be sent, because there are usually several TCP packets to be sent in each connection. The structure of 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 description documents to write an RTL8019AS driver for this system.
uIP does not cache the arriving data packets. When a data packet arrives on the network card (here, it specifically points to a frame), the network card driver will temporarily store the data packets in the network card cache, and transfer them one by one to the target board in the form of DMA. On the RAM. At this time, there will be a piece of code to copy the data packet arriving in the RAM of the target board to the global array uip_buf [], and the uIP protocol stack program will then operate on the data in uip_buf [].
When the upper-layer application program or protocol stack program generates a data packet sent to the network, the data packet is also put into uip_buf []. Then call the network card driver, read the data in uip_buf [] into the network card's cache, and then send it to the network.
Here we should explain the problem of the synchronization mechanism between the protocol stack and the network card driver and application program. During 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), home appliance monitoring program; task three (idle_task), idle task. The NIC driver acts as a hardware interrupt and is triggered by the "detected data packet uploaded from the network" event.
The flow chart of the entire protocol stack program is shown in Figure 5.
Task one has the highest priority, task two has the highest priority, and task three has the lowest priority. When the system starts running, task one first enters the RUN state, and the system call wai_flg () is added to task one. Since there is no network request, task one then enters the WAIT state. At this time, task two enters the RUN state. When a data packet arrives on the network, the network card driver starts executing as a hardware interrupt. Before exiting the interrupt, set the desired flag of task 1 through the system call set_flg (). When the interrupt returns, because the waiting condition of task one has been met, the priority of task one is higher than that of task two, so task one enters the RUN state, that is, the uIP protocol starts to process data. If there are always data packets arriving on the network, task one and interrupt program are switched continuously. When the network task is completed, return to the breakpoint of task two and continue down.
Since uIP does not cache network data, all interrupts will be turned off during the execution of task one, that is, when uip_buf [] is being operated on. This can prevent the data packet from being destroyed. The disadvantage is that the real-time performance is worse, but it meets the requirements of the system.
3 Operating system
The operating system used in this system is ROS33V31 provided by EPSON. ROS33 is an embedded real-time operating system provided for S1C33 series MCU, which complies with uITRON 3.0 standard. Using ROS33 can quickly and effectively develop embedded applications for printers, PDAs, and various control devices.
ROS33 has the following characteristics:
* Support uITRON 3.0 standard-S-level conforming to the standard * The maximum number of tasks is 255, adopt priority scheduling mechanism, support 9 different priorities, provide multiple communication mechanisms such as semaphore, mailbox, message buffer, etc .:
* The core is prioritized and compact-the smallest can be 1.7K;
* Fast response-the fastest scheduling response time is 7.8μS (CPU frequency is 33MHz, the same below), and the maximum interrupt mask time is 4.3μs;
* Advanced language support-In addition to assembly language, C language programming based on ANSI standards is also supported.
Note: μITRON divides the system functions into four levels. Level R (necessary level) only provides basic system calls including real-time, multitasking OS; level S (standard level) provides all standard system calls; level E (extended level) includes additional and extended system functions; The level (CPU dependent level) system functions depend on the specific CPU and system implementation.
The basic core 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 operations of sleep / wake, suspend / unhang, etc., handle related tasks and the synchronization relationship between tasks;
* Synchronization and communication-through signal lights, events, mailboxes and other communication mechanisms to achieve synchronization and communication between independent tasks;
* System management-management of the system environment;
* Clock management-management of calendar clock, timers, timing tasks, etc .;
* Interrupt management-on / off interrupt.
Figure 6 shows the conceptual model of the ROS33 kernel.
4 Web server and upper application framework
The method adopted by the WEB server is called uip_connect, which is more suitable for the embedded system than the Socket used in the design, which 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 status is connected
switch (uip_conn-> lport) {
case htons (80):
httpd; // If data arrives at 80 PORT, call HTTP to process the transmission of HTML file
}
}
First, the server establishes a connection with the client, and then listens on port 80 to determine whether a client request arrives. If so, it will call the application httpd for corresponding processing, otherwise, continue to listen. Httpd is an application program for processing HTTP requests, and its specific design is described in the protocol stack uIP. uip.h is a header file of protocol uIP.
The simple WEB server function is implemented on the application software, which is mainly composed of two modules: one is the user login module; the other is the home appliance monitoring module. The user login module needs to solve the user's legality check, that is, receive the user name and password entered by the user to verify, if it is legal, it will enter the home page monitoring page, and if it is illegal, a warning page will be issued. The home appliance monitoring module collects information on the status of home appliances according to the hardware status of each home appliance and displays it through the web page.
In the two modules, there is a part of similar processing, which is to parse the input data. Now define the array htmlinputs to store the parsed information. After parsing the data entered in the form, the name value and value value are stored in htmlinput_struct.name and htmlinput_struct.value, respectively, for future 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, define functions get_inputs () and translate () to process the input data.
Int get_inputs (); // The data input from the form are loaded into the corresponding name / value data team
Void translate (char * sourcestr); // Interpret encoded URL characters
The specific program code will not be described here.
The flow chart of the entire upper-layer application is shown in Figure 7.
5 Summary
Ethernet is used as the interface, and the S1C33 series microprocessors are used as the hardware platform. Using software-based streamlined embedded TCP / IP, HTTP services can be realized. Of course, when the system is mature, 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 additional PC or gateway equipment. This low-cost, high-performance solution has the characteristics of reliability and flexibility, and is suitable for home automation equipment that has a low communication rate, allows a delay of more than 1s, and needs to be connected to the Internet. In addition, users can also construct their own network servers according to this method according to their needs, which can give ordinary electrical equipment or systems such as public service equipment, home medical care equipment, industrial automation systems, etc., to give Internet access.
Liquid Crystal Display For Vehicle Use
Dongguan Yijia Optoelectronics Co., Ltd. , https://www.everbestlcdlcm.com