Implementation of ARM-based embedded TCP/IP protocol

Source: Internet
Author: User

Source: Electronic Technology Application Author: Hu Youshui, School of automation, Wuhan University of Technology, Li hanqiang

Abstract:This paper introduces a simplified implementation scheme of embedded TCP/IP protocol in low-speed processors, and is successfully applied to a distributed monitoring system.

Keywords:Today, TCP/IP protocol embedded ARM is becoming increasingly popular in network applications, and more embedded devices are networked over the Internet. TCP/IP is a widely used network protocol. The core technology of the embedded Internet is to partially or completely implement the TCP/IP protocol in the embedded system. Due to the complexity of TCP/IP protocols, a large number of low-speed processors are currently used in embedded systems. Due to memory and speed constraints, it is necessary to simplify TCP/IP protocols.

Figure 1 protocol processing

1. Implementation of TCP/IP protocolEmbedded TCP/IP protocols are generally implemented: ARP/RARP, IP, ICMP, TCP, UDP, HTTP, SMTP, FTP, telnet, and other protocols. The main process of protocol processing is 1. 1.1 The Implementation of the TCP protocol in the industrial control domain transport layer uses the TCP protocol and does not use the UDP protocol. It is considered that the real-time monitoring system does not have a large amount of transmission, but the reliability requirements are high. TCP is a reliable connection-oriented and end-to-end communication protocol. It uses many mechanisms to ensure reliable transmission. It is too complicated to apply to embedded systems. TCP data transmission can be divided into three phases: establishing a connection, transmitting data, and disconnecting. Its implementation process can be described by the state machine. There are two methods to establish a connection: active and passive. The server is a type of passive open, which keeps listening for connection requests, while the client is an active open, which sends connection requests to establish a connection. The study found that if the upper layer of the TCP layer implements the application of the server, the state machine part of the client connection can be simplified during the establishment of the standard TCP state machine. Similarly, if the application is client-based, the state machine that establishes a connection on the server can be simplified. There are two ways to disconnect: one is to actively disconnect the connection, and the other is to passively disconnect the connection. The process of passive disconnection is relatively simple, but the active disconnection state machine of the standard TCP protocol is too complicated. The experiment found that when you need to actively disconnect the connection, send a fin datagram. After receiving the confirmation of the fin datagram, send a reset datagram to successfully complete an active disconnection. The standard TCP protocol uses a slow-start sliding window mechanism. A sliding window is a solution that compromises the traffic control and network transmission efficiency. It allows the sender to send multiple windows before waiting for a confirmation, and its confirmation is a batch confirmation. Studying the Sliding Window Protocol, it is found that a limit condition of a sliding window is that only one window is used, and it becomes a simple and confirmed processing method. After this method is used, all processing operations only send and confirm a single datagram, saving system resources and making maintenance more convenient. For protocol compatibility, the other party that needs to communicate also uses a simple validation method. If the other party uses a large window, the processor may be drowned. This problem can be solved by setting the Windows Field Size of the TCP Header of the datagram to be sent. On the basis of the above, the flow chart 2 for simplified TCP protocol implementation is shown. "Corresponding processing in different states" indicates preparing the datagram to be sent based on the received TCP packet and sending it to the Ethernet. According to the different status of TCP, the processing is different. 1.2 The IP protocol is the basis of TCP/IP and provides the connectionless service for the Operation Sequence of data packets sent between hosts in different networks. Add an IP protocol header before a datagram to enable addressing for each datagram. The embedded system only uses IP addresses as transmission tools to simplify the process. After the IP packet is obtained, check whether the version, destination address, and checksum of the IP header are correct or not, parse the protocol type field, and then hand it over to the corresponding high-level protocol for processing. When sending an IP packet, swap the source address in the buffer zone with the destination address, set the checksum, and hand it over to the lower-layer protocol for processing. If the package does not meet the requirements, the package will be discarded. The maximum size of an IP packet is 65kb, which can be transmitted in segments. However, an embedded system cannot accommodate such large data packets. Therefore, segment transmission is generally not supported. Therefore, the MCU is limited to send and receive data packets to avoid segment transmission and reduce program complexity.

1.3 Other protocols: the same handler can process the same type of timeout, but the parameters passed into the corresponding Handler are different. For example, if a table item in an ARP high-speed cache times out, it must be set to invalid. You can use a uniform processing program and add the corresponding table item address to the parameter. A timer task uses a semaphore for synchronization. Semaphores have two variables: Count and waiting_task. Count: Event count. When count is greater than 0, it indicates that count events occur and are waiting for processing. When count is less than 0, it indicates that a task is waiting for an event, at this time, waitint_task saves the address of the corresponding task control block. Semaphores have two operations: sem_up and sem_down. Sem_up first adds count to 1, and then checks whether count is 0. If it is 0, a task is waiting. The address of the task control block recorded in waiting_task sets the waiting task status to ready, otherwise, return. Sem_down first reduces count by 1 and then checks whether count is smaller than 0. If it is smaller than 0, the current task becomes a waiting state and the Task Manager schedules the task. Otherwise, the system returns. ARP provides dynamic ing between 32-bit IP addresses and 48-bit Ethernet IP addresses. In the embedded system, the system only responds to ARP requests and sends ARP response packets. The requester broadcasted the Ethernet frame containing the ARP request and the destination ethernet address is the broadcast address of all 1. After receiving the IP address, the local host finds itself as the target host and sends an ARP response. ICMP transmits its packets through the IP protocol. The IP protocol is connectionless. It cannot send messages and error messages to the original host. ICMP sends status information and error messages to the host sending messages.2 system design of front-end devicesThe TCP/IP protocol is extended to the industrial control level. The enterprise's internal computer network is applied to the release and display of real-time industrial information, and the on-site industrial information is dynamically monitored through the Internet browser. The following is an example of my application in a company's distributed monitoring system. Software Architecture of front-end Device System Based on TCP/IP protocol 3. The front-end embedded device processor is Samsung's arm core ). The chip is a cost-effective, high-performance 16/32-bit Proteus microcontroller based on Ethernet systems. The communication part adopts the BNC interface mode, and the signal output is coupled with the isolating transformer. The RJ45 connector is connected to the hub. In addition, the LCD display and keyboard input Local interface functions are designed. Timeout and retransmission mechanisms are used in multiple TCP/IP protocols. This mechanism is very effective for ensuring that two or more independent communication nodes are automatically restored from the communication error or fault status to the normal state, but it also increases the complexity of the software structure. The timeout processing is usually independent from the normal program process, that is, asynchronous with the normal program process. The TCP/IP software to be implemented involves the use of Timers: the first is the maintenance of ARP high-speed cache, the table items added to the ARP high-speed cache must be set to invalid after a period of time. The second is to wait for the response to the ARP request, the returned response may not be received within the specified timeout period. The third is to discard the entire IP packet because some parts are not received within a certain period of time when the IP is assembled and received; the fourth is when TCP waits for the receiver to confirm the data segment. If you have not received confirmation for a data segment within the specified time, You Need To resend it. From the above, we can see that the timer has the following features: · The timer precision requirements are not very high, basically in seconds. In this way, the timer timeout can be processed with a slight lag, and the timeout processing is not placed in the clock interrupt processing program.
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 linked list consisting of timeout events. The entire linked list is sorted by the time-out events that will occur, and the time-out events that occur first are listed first. The head_ptr In the timeout control block is used to point to the first item of a timeout event linked list. timeout_process is the entry address of the processing program when a timeout event occurs. In each time-out event item, next_ptr points to the next item in the linked list; relative_time is the relative time when the time-out event of the current table item occurs relative to the time-out event of the previous table item. Therefore, the time-out event represented by a table item is the sum of relative_time in all its previous table items (including its own) from the current time. The basic unit of relative_time is granularity.
Every time the clock interruption service program counts to granularity, it performs sem_up operations on the signal lights used by the timer task. When a timer task is scheduled to run, it traverses each time-out control block, processes each time-out control block as shown in step 5, and finally calls sem_down to the traffic signal.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.