Design and implementation of embedded TCP/IP protocol suite based on SF0020 chip

Publisher:创意驿站Latest update time:2011-09-22 Keywords:SF0020 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Introduction
TCP/IP originated from a packet switching network research project funded by the US government in the late 1960s. Today, it has developed into the most commonly used networking form between computers. Although the standard TCP/IP protocol family does a good job in data transmission reliability and data flow control, the implementation of the standard TCP/IP protocol family occupies a large amount of system resources due to the performance limitations of 8-bit microcontrollers, which is not allowed in practical applications. Therefore, it is necessary to tailor the TCP/IP protocol family without changing its standards to improve its real-time performance while ensuring reliability to meet the requirements of embedded systems.
SF0020 is an 8-bit microcontroller chip compatible with 80C51 launched by NEC. According to the needs of the system in the control terminal application of the network monitoring system, a 25MHz crystal is connected externally and the internal frequency is multiplied to 50MHz. The chip has an embedded 10M/100Mbps MAC module and provides an MII interface, which can be easily connected to an external Ethernet PHY chip. The chip has a 256-byte internal data memory, which can be expanded to 512K bytes externally. The DMA channel has realized the function of fast data transmission in RAM and between MAC and RAM; it supports the checksum module, which can save the controller computing overhead when implementing TCP/IP. The instruction cycle is 4 clock cycles (the standard 80C51 is 12 clock cycles/instruction cycle). Its performance meets the basic requirements for implementing the embedded TCP/IP protocol family.
2. Overall framework design and tailoring strategy of the protocol family
In order to realize the application requirements of controlling front-end monitoring equipment (hard disk recorders, encoders, decoders, video servers, etc.) as a client in a local area network environment, the reliability and real-time performance of data transmission must be guaranteed under the condition of limited hardware resources. Therefore, the data link layer adopts the most widely used Ethernet protocol at present; the upper layer uses TCP/IP to directly adopt the reliable TCP protocol in the transport layer, and then tailor it appropriately. This is because considering the versatility, compatibility and reliability of communication, the solution of adding control strategies in the application layer and using simple UDP protocol in the transport layer is not used. The flow of local data must provide reliable data to the application and interact with the underlying Ethernet driver for datagram functions.
The structure framework of the protocol family system is shown in Figure 1 below, where the dotted part is what this article needs to complete, including the socket sublayer, the TCP protocol of the transport layer, the IP and ICMP protocols of the network layer, the ARP protocol and the Ethernet sublayer.



Figure 1 Protocol family system framework
2.1 Interface sublayer implementation
The Ethernet sublayer provides an interface with the Ethernet driver, which implements the function of data transfer between the driver storage space and the protocol space; as well as the branching of datagram inflow and the encapsulation of outflow.
The Socket sublayer provides the upper layer with the functions of creating a socket descriptor, binding the local IP address and port number to a socket, establishing and disconnecting TCP connections, and receiving and sending data.
2.2 Network layer implementation
The network layer implementation includes the IP protocol (Internet Protocol) and the ICMP protocol (Internet Control Messages Protocol) based on the IP protocol. The ARP (Address Resolution Protocol) at the bottom of this layer in Figure 1 provides dynamic address resolution services for IP. IP
is the core protocol in the TCP/IP protocol family. All network layer and transport layer data are transmitted in IP datagram format. In order to reduce the burden of the TCP/IP protocol family, the correctness of the datagram must be checked first when receiving it, and the messages whose destination address is not the local machine must be filtered; in addition, if a datagram fragmented by IP is received, it must be discarded immediately. Finally, the protocol is determined to be handled by TCP or ICMP protocol. Because prohibiting IP layer fragmentation can improve the efficiency and reliability of communication, according to the Ethernet maximum transmission unit (MTU) limit, the socket sublayer controls the maximum number of bytes of each packet transmitted by the user. Similarly, the server also limits IP fragmentation so that IP does not need to consume limited system resources on IP message reassembly, which is the reason why fragmented IP datagrams are discarded.
ICMP provides services for hosts or routers to report errors or provide query information. ICMP messages can be divided into two categories: errors and queries. Query messages are defined by a pair of requests and replies. ICMP error messages usually contain the IP header (and options) of the first fragment of the IP datagram that caused the error, plus the first 8 bytes of the data part of the fragment. Since the transport layer only uses the TCP protocol, ICMP is also trimmed. The protocol supports the ping command to request an echo reply, which is used to check the operation status of the protocol family; all error control is handled by the transport layer TCP protocol. [page]

The ARP protocol provides mapping between IP addresses and hardware addresses. ARP messages are divided into two types: request and reply messages, and the ARP cache is updated through these two messages. The ARP cache is very critical in its operation. Due to the hardware resource limitation of the microcontroller, the ARP cache only defines 8 groups, so the linear search method has no effect on the final performance. The cache only contains the following 4 items to implement the ARP protocol and save hardware resources: IP address, MAC address, write time, and flag.
2.3 Transport layer implementation
The transport layer only implements TCP (Transfer Control Protocol). This protocol provides full-duplex high-reliability communication, so the application layer and network layer can ignore the relevant details. TCP is a connection-oriented transport layer protocol in the TCP/IP system. Its work includes handing over the data packets handed over to it by the application to the network layer below, confirming the received packets, setting the timeout clock for sending the last confirmed packet, etc.
Whenever a connection establishment request is issued locally, a corresponding transmission control module TCB (Transmission Control Block) is created. It stores important information in the connection. Like the ARP cache, its data is stored in the on-chip data storage area to improve the operation efficiency of the protocol. The implementation of TCB in this article only includes the following contents: IP address, port numbers of both parties, sequence numbers of both parties, response sequence number of the other party, current connection status, timer, pointer to the next valid data area, and window size. In addition, by configuring the option field of the TCP header, it is ensured that the IP layer will not be fragmented when transmitting within the LAN, so that the MMS (Maximum Segment Size) is as large as possible, which can improve the TCP transmission efficiency. At the same time, considering that it is a client application, the two states of LISTEN (listening) and SYN_RCVED (receiving SYN state 0) on the server are removed in the TCP finite state machine implementation without affecting normal operation, as shown in Figure 2 below.



Figure 2 TCP finite state machine

Since data transmission in the network will inevitably result in data loss, TCP error retransmission and data reassembly are particularly important. Error retransmission is to set a retransmission timer after sending a segment that requires confirmation from the other end. If ACK is not received within the time limit of the timer, the segment will be retransmitted. Therefore, after the data is sent, it must wait for the ACK confirmation message to be discarded. Data reassembly is based on byte-oriented sequence numbers to achieve the discard of duplicate data and the reassembly of out-of-order messages.

3. Key technologies for protocol family implementation
3.1 Implementation of protocol family timers
ARP implementation requires two timers. Retransmission requires a timer. If there is no response within 1 second after the ARP message is sent, it will be sent again. This article implements that ARP will give up after 4 consecutive retransmissions; ARP cache data storage time requires a timer, and the cache content is kept for 20 minutes. At the same time, administrators are allowed to create permanent nodes as proxy nodes.
TCP implementation establishes the following six timers for the current connection: connection establishment timer, retransmission timer, delayed ACK timer, persistence timer, FIN_WAIT_2 timer, TIME_WAIT timer; the keep-alive timer is removed because this timer is only an optional configuration for TCP connections, and the application needs to implement more stringent connection maintenance timing in monitoring. This paper modifies the timeout defined by the standard protocol family according to the actual monitoring network situation to improve the real-time performance.
3.2 Memory management strategy of the protocol family
The incoming packets are stored in the memory and passed to the appropriate protocol for further processing. At the same time, the data generated by the application must also be stored in the memory in the form of packets, and finally handed over to the network hardware device for transmission. Therefore, the efficiency of the protocol depends on how to manage the storage space for storing these packets. This paper uses the following two methods for memory management to quickly allocate storage space and avoid data duplication when packets move between protocols at different layers.

[page]

When sending datagrams, a large buffer solution is used: that is, the buffer is divided into a large enough size (1514 bytes), and the size of the protocol header bytes is reserved in advance to store the longest packet. When receiving datagrams, a linked list solution is used: in order to avoid memory fragmentation, the buffer uses a fixed size. The characteristic of the linked list is that it allows fast encapsulation without data duplication, that is, when a submitted datagram is received, a new buffer is allocated, and after filling in the content, the new buffer is inserted into the linked list that stores this information. In this way, additional bytes can be easily inserted in front of a certain information without moving the existing data. This method can optimize the reorganization of TCP datagrams. The
above two methods can maximize the data sharing within the TCP/IP protocol family without the need for additional data movement.
3.3 Protocol family data flow
As shown in Figure 3 below, the data to be sent by the user first enters the TCP/IP protocol family through the socket interface program, and the TCP and IP data are encapsulated respectively, and then the ARP cache is queried. If there is a mapping between the current destination IP and the hardware address, the Ethernet frame header information is filled and copied to the Ethernet driver space for immediate transmission. Otherwise, an ARP query message is sent, and the current user data is copied to the send waiting buffer, and the receiving state is entered to wait for the response of the ARP query message.

Since the input operation occurs during the interrupt, the device driver cannot call any process to process the packet at this time, that is, the interrupt service program does not directly call IP, but uses the message passing method. When an IP packet arrives, the main loop is notified with a message, and the main loop calls the protocol family for data processing. As shown in Figure 4 below, the frame is first routed through the Ethernet sublayer. If it is an ARP message, the ARP buffer is checked and updated. If the ARP request is received, it is immediately responded. If it is a response message, the local sending waiting queue is checked and data is sent immediately. If it is an IP message, its protocol type is first determined. If the ping command request echo in the ICMP message is immediately responded, the source station suppression message is handed over to TCP for processing. If it is a TCP protocol, the finite state machine is entered for parsing and finally the valid data is submitted to the upper layer through the socket interface.


Figure 3 Protocol family data transmission processing block diagram Figure 4 Protocol family data reception processing block diagram

4. Conclusion
The tailored embedded TCP/IP protocol family has a simple structure and strong real-time performance. It can run stably on the SF0020 chip. The network monitoring system control terminal based on this protocol family has passed the special test and met the expected requirements.

Keywords:SF0020 Reference address:Design and implementation of embedded TCP/IP protocol suite based on SF0020 chip

Previous article:Processing of multi-bank partition jump problem in C8051 F12X
Next article:Design of PZT driving circuit based on C8051F005 single chip microcomputer

Recommended ReadingLatest update time:2024-11-17 01:47

Transplantation and implementation of LwIP TCP/IP protocol stack on embedded real-time operating system uC/0SII
    Abstract: Combined with the specific implementation on ez80 and ARM7 systems, this paper explains how to port the TCP/IP protocol stack LwIP to the embedded real-time operating system uC/0SII, making uC/0S II a network-supported RTOS.     1 Introduction     With the increasing integration of embedded systems and n
[Microcontroller]
Multi-serial port server based on μC/OS-II and TCP/IP protocol
Abstract: Aiming at the problem that many devices do not have network interfaces, an embedded system is built with ARM7Cortex-M3 processor LM8962 as the core, and 8 serial ports are expanded using SC28L198 chip to complete the design of multi-serial port server based on μC/OS-II operating system and TCP/IP protocol.
[Industrial Control]
Multi-serial port server based on μC/OS-II and TCP/IP protocol
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号