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. Theabove 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.
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
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Knowledge popularization! "Common algorithms in embedded system software design"
- Today at 10:00 AM, live broadcast with awards: [How to use Microchip security solutions to protect IoT devices]
- [Raspberry Pi Pico Review] Raspberry Pi "chip" unboxing
- Problems with frequency modulation using MAX2607
- Recruiting BLE software development engineers (with favorable treatment)
- Eliminating Software Failures with MSP432
- Op amp adder and subtractor
- Award-winning lecture: Nexperia Micro Classroom - Explanation of parameters in the power GaN device data sheet
- [Environmental Expert's Smart Watch] Part 12: Configuration of watch name and time
- [TI recommended course] #Boost and buck-boost DCDC converters help wireless charging design#