Today, more and more embedded devices are increasingly universal today. TCP / IP protocol is a network protocol currently widely used. The technical core of embedded Internet is partially or completely implemented in the embedded system. Since the TCP / IP protocol is more complicated, a large number of low-speed processors in the current embedded system are limited by memory and speed, it is necessary to simplify the TCP / IP protocol.
Figure 1 Agreement
1 TCP / IP protocol implementation
Embedded TCP / IP protocols are generally implemented: ARP / RARP, IP, ICMP, TCP, UDP, HTTP, SMTP, FTP, Telnet and other protocols, the primary flow of protocol processing is shown in Figure 1.
1.1 Implementation of TCP Protocol
Industrial Control Field Transportation Layer uses TCP protocols, without UDP protocol, considering that the amount of transmission in real-time monitoring systems is not large, and reliability requires high. The TCP protocol is a reliable communication protocol for connection, end-to-end. It uses many mechanisms to ensure reliable transmission, which is applied to embedded systems.
TCP protocol data transmission can be divided into three phases: establish a connection, transfer data, and disconnect. Its implementation process can be described in a state machine. There are two ways to establish a connection, that is, actively open and passively open. The server side is a passive opening, which has been listening to the connection request; and the client is an active opening, which sends a connection request to establish a connection. The study found that if the upper layer of the TCP layer implements the server-side application, the Standard TCP state machine can be simplified during the connection process. Similarly, if the application is based on the client, the status machine portion that can be connected to the server side can be simplified. There are two ways to disconnect: First, the active disconnection is disconnected; the other is the passive disconnection. The passive disconnecting process is relatively simple, but the state machine portion of the active disconnection of the standard TCP protocol is too complicated. After experimentation, when it is necessary to actively disconnect the connection, a FIN datagram is sent; after receiving an acknowledgment of the FIN datagram, a reset datagram is sent, which can successfully complete the active disconnection connection. Standard TCP protocol uses a slow-start sliding window mechanism. The sliding window is a scheme that is folded between flow control and network transmission efficiency. It allows the sender to send multiple windows before waiting for a confirmation, confirming is a batch confirmation. The research sliding window protocol discovers that a limit of the sliding window is only a single window, which has become a simple confirmation process. After using this method, all processing is just the transmission and confirmation of a single datagram, saving the resources of the system, making it easier to maintain. For the compatibility of the protocol, the other party that needs to communicate also uses a simple confirmation method. Because if the other party uses a larger window, it may cause the processor being submerged. This problem can be solved by setting the size of the Windows field of the TCP header to be sent.
Based on the above, a flow chart that implements the TCP protocol is simplified as shown in Figure 2. Where "different status of different states" refers to the receipt of TCP packets to be sent and sent to Ethernet. This part is different from the different states in TCP, which is different.
1.2 IP protocol
The IP protocol is the foundation of TCP / IP, providing connectionless services for the operation sequence of the transmitting datagram between the hosts of different networks. Each datagram has an addressing capability by adding an IP protocol header before the datagram. The embedded system simplifies only the IP as a transmission tool to complete the main operation. After obtaining the IP package, verify the version of the IP header, destination address, check, and correct, parse the protocol type field, thus handed over to the corresponding high-level protocol processing. When sending an IP packet, convert the source address in the buffer with the destination address, set the check, and then hand it over to the next protocol. This package is discarded without meeting the requirements. The IP package can be 65KB, which can be segmented, and such a large packet is not allowed in the embedded system, so it is generally not supported. Therefore, the MCU is restricted to send and receive data packets to avoid segmentation transmission, thereby reducing program complexity. 1.3 other protocols
A dynamic mapping is provided between 32-bit IP addresses to the corresponding 48-bit Ethernet address. In response to the ARP request in the embedded system, send an ARP answer package. The requester broadcasts the Ethernet frame containing the ARP request, the destination Ethernet address is a broadcast address of all 1. After receiving the unit, the destination IP address found that he is a destination host, send an ARP answer. ICMP transmits its packets via IP protocol. The IP protocol is not connected. It cannot transmit messages and error messages to the initial host, and ICMP sends status information and error messages to the host.
2 system design of front-end equipment
The TCP / IP protocol extends to the industrial control level, applies the internal computer network to the publishing and display of real-time information in industrial field, and dynamically monitors on-site industrial information over the Internet browser. Below is an application example in a distributed monitoring system in a company. The Software Structure Software Structure Based on the TCP / IP protocol is shown in Figure 3. The front end embedded device processor is S3C4510B (ARM core) of Samsung. The chip is used in a high-cost, high-performance 16/32-bit RISC microcontroller based on the Ethernet system. The communication portion uses a BNC interface mode, and the signal output is coupled to the hub by the RJ45 connector by the RJ45 connector, in addition, the liquid crystal display and keyboard input function are also designed. Use multiple times and resend mechanisms in the TCP / IP protocol. This mechanism is very effective for ensuring that two or more independent communication nodes are automatically recovered from communication errors or fault states to normal state, but also increases the complexity of the software structure. Because the overtime processing is usually independent of the normal program process, it is also asynchronous with the normal program process. There is a timer to be used in the TCP / IP protocol software to be implemented: the first is in the maintenance of the ARP cache, the entries in the ARP cache are set to be invalid after a period of time; When the response is returned to the emitted ARP request, the returned response may not be received within the specified timeout; the third is that when the IP assembly is received, the partial fragment is not received for a certain period of time. The entire IP package is discarded; the fourth is to wait for the recipient to confirm the data segment on the TCP. If you have not received a confirmation of a data segment in the specified time, you need to resend. As can be seen from the above, the timer to be implemented has the following features:
· The accuracy requirements for timing are not very high, basically all the accuracy of the second level. In this way, it is completely slightly slightly slightly to process the timer timeout, and the timeout process is not placed in the clock interrupt handler.
• The same class timeout can be done by the same processing program, but it is only the parameters in the corresponding handler. For example, an entry in an ARP cache timeouts, you need to set it to invalid, you can unify one handler, and put the corresponding entry address in the parameter.
First, define the data structure of a timer, as shown in Figure 4. Each type of timeout is managed by a timeout control block and a chain list consisting of timeout event items. The entire linked list will be arranged in the timeout of the timeout event, and the first timeout event is arranged before. The head_ptr in the timeout control block is used to point to the first time of a timeout event neutral list; Timeout_Process is the entry address of the handler when the timeout event occurs. In each timeout event entry, Next_ptr point to the next item in the list; Relative_Time is the timeout event of this item's timeout event occurs relative to the timeout event of the previous entry. So a table item indicated timeout event is current time is the RELATIVE_TIME in which it has previously all entries (including itself). The basic unit of the Relative_Time is Granularity.
Timer tasks use a semaphore synchronization. There are two variables: count and waiting_task. Count the event count when Count is greater than 0, indicates that there is a count event, and wait for processing; when Count is less than 0, it means there is a task to wait for the wait event. At this time, WaitInt_task saves the address of the corresponding task control block. The amount of semapses have two operations: SEM_UP and SEM_DOWN. SEM_UP first makes COUNT 1, then see if count is 0, if 0 means a task is waiting, the address of the task control block recorded in waiting_task is set to be ready, otherwise it returns. SEM_DOWN first reduces the count and then see if count is less than 0, if less than 0 will make the current task be a wait state and trigger the schedule of the task to the task, otherwise it returns. Whenever the clock interrupt server counts to the Granular clock interrupt, the signal light used for the timer task is used as SEM_UP operation. When the timer task is scheduled, it traverses each timeout control block, and for each timeout control block, as shown in FIG. 5, finally call SEM_DOWN.