“In order to meet the needs of fast transmission of large amounts of data in the Ethernet communication process, some reliability can often be sacrificed in exchange for high-speed data transmission. According to the scheme, a set of UDP communication system based on YLP2440 is designed in this paper, which realizes a simple and practical UDP communication system. Communication protocol. Firstly, the overall hardware structure of the system is introduced, and then the software design of the Ethernet communication system is completed. Based on the DM9000A Ethernet card driver, the TCP/IP protocol stack is cut and transplanted to realize the reception and transmission of system data. UDP and ARP communication are tested, and the results show that the overall UDP communication system is stable and reliable, and the system overhead
Abstract: In order to meet the needs of fast transmission of large amounts of data in the Ethernet communication process, some reliability can often be sacrificed in exchange for high-speed data transmission. According to the scheme, a set of UDP communication system based on YLP2440 is designed in this paper, which realizes a simple and practical First, the overall hardware structure of the system is introduced, and then the software design of the Ethernet communication system is completed. Based on the DM9000A Ethernet card driver, the TCP/IP protocol stack is cut and transplanted to realize the receiving and sending of system data. The system UDP and ARP communication are tested, and the results show that the overall UDP communication system is stable and reliable, and the system overhead is small. The data transmission speed is fast, which can meet the needs of practical applications.
With the rapid development of embedded technology and network technology, the application of Ethernet interface in embedded systems is more and more extensive. Ethernet communication speed is fast. Universal, it can be directly connected to the Internet to provide a wider range of remote access. At present, in the field of industrial control embedded, network communication usually adopts UDP and TCP protocols. Compared with TCP, UDP uses non-connected and unreliable communication methods, so the network transmission speed is fast and the real-time performance is relatively good. The practical S3C2440 is designed in this paper. .Ethernet controller DM9000 and self-tailored TCP/IP protocol stack form the Ethernet interface of the embedded system to realize UDP communication.
1 Introduction to the hardware of the system
The system adopts YLP2440 of Youlong Technology Co., Ltd. as the developed hardware system. YLP2440 adopts Samsung S3C2440A as the CPU, the highest frequency is 400MHz, with 64MB SDRAM and 64MB NANDFlash external memory, there are two five-wire asynchronous serial ports, baud rate Up to 115200bps, a 10M / 100M DM900AEP network interface card with connection and transmission indicators. DM9000A is a fully integrated, powerful, cost-effective Fast Ethernet MAC controller with a general processing interface. EEPROM interface. 10/ 100MPHY and SRAM, powered by a single power supply, compatible with 3.3V.5V IO interface level. DM9000A also supports MII (Media Independent Interface, media independent interface), which includes a series of status registers that can be accessed and controlled. These Registers are byte-aligned and are set to initialize on hardware or software reset.
The hardware block diagram is shown in Figure 1.
2 Design of Ethernet software
2. 1 Initialization of the Ethernet card controller
First, DM9000A self-checks, reads the manufacturer ID and device ID of DM9000 and compares it with the ID that has been set to determine whether the DM9000 network card exists, and initializes DM9000A. Its process is the process of properly configuring the DM9000A registers. The specific process is divided into The following steps:
(1) Start DM9000A and set CPCR[REG_1E] = 0×1, make GPIO3 of DM9000 output, GPR[REG_1F] =0×0, make the GPIO3 output of DM9000 low to activate the internal PHY. Delay more than 2ms to wait for the PHY to power up.
(2) Perform two soft resets and set the DM9000 to the normal working mode. According to the chip design requirements, to make the chip work normally after power-on, it is necessary to perform two soft resets and set it to NCR[REG_00] =0×01,NCR[REG_00] =0×00, these two steps are performed twice.
(3) Clear various status flag bits and interrupt flag bits, NSR[REG_01] =0x2c,ISR[REG_FE] =0x3f.
(4) Set the receive and transmit control registers, and set the size of the FIFO, RCR[REG_05] =0×39.TCR[REG_02] =0×00.FCTR[REG_09] =0×38.
(5) Set the MAC address of the board itself.
(6) Clear various status flags and interrupt flags again, NSR[REG_01] =0x2c,ISR[REG_FE] =0x3f.
(7) Set the interrupt mask register, open the receive interrupt, IMR[REG_FF] =0×81.
After the settings of the above steps are performed, the DM9000A chip is in a normal working state. In the process of subsequent communication, if an abnormality occurs and the chip is restarted, the same settings are performed again.
2. 2 Ethernet card data transmission and reception
DM9000A uses circular query mode to send data, and interrupt mode to receive data. DM9000 has a SRAM of size 0x3FF for receiving and sending data buffer. Before sending or receiving data packets, the data is temporarily stored in this SRAM. When it is necessary to continuously send or receive data, it is necessary to assign the DM9000 register MWCMD or MRCMD to the data port respectively, so that an address in the SRAM is specified, and after a data is transmitted, the pointer will point to the next address in the SRAM, Thus, the purpose of continuous data access is completed. However, when the data pointer to SRAM does not need to be changed after sending or receiving a data, MWCMDX or MRCMDX should be assigned to the data port.
Sending data is relatively simple, and receiving data is slightly more complicated, because it has certain format requirements. If the first byte in a received packet of data is 0×01, it means that this is a receivable data packet; If it is 0×0, it means that there is no data packet that can be received. Therefore, when reading other bytes, you must first determine whether the first byte is 0×01. The second byte of the data packet is some of the data packet. Information, the format of its high byte is exactly the same as the register RSR of DM9000. The third and fourth bytes are the length of the data packet. The following data is the real data to be received.
2.2.1 Tailored implementation of UDP protocol stack
UDP communication is mainly used in the system, only the ARP protocol and IP protocol need to be implemented, and part of the TCP/IP protocol is implemented. The top layer of the Internet Protocol) protocol. Compared with TCP, UDP is a simple protocol, providing the least service, the amount of code written is also small, the required program and memory space is small, and the running speed is fast. ARP corresponds to IP address Dynamic mapping is provided between hardware addresses. When the sending terminal sends an Ethernet data frame to another host on the same local area network, the destination interface is determined based on the 48-bit Ethernet address. The device driver never checks the IP datagram The destination IP address in the .IP protocol is the most core protocol in the TCP/IP protocol, which provides unreliable and connectionless datagram transmission services.
2. 2. 2 Data transmission process
The data sending process is shown in Figure 2. When the sending terminal sends data for the first time, it needs to know the IP address and port number of the receiving end, as well as the physical MAC address of the other party, because the last communication between the two terminals is by looking for each other. Therefore, it is necessary to convert the IP address of the other party into a MAC address through the ARP protocol. After obtaining the physical address, the communication can be carried out. If the physical address cannot be obtained for a long time, it can only indicate that the request failed and needs to be resent. ARP request, the encapsulation process of ARP is shown in Figure 3(b).
2.2.3 Packet encapsulation process
UDP protocol data packets are encapsulated at the transport layer. The packaged UDP data will be sent to the network layer for IP protocol packaging. UDP should complete the process-to-process communication and deliver the message to the correct process. When the message is to be sent through UDP, it passes the message together with a pair of socket addresses and data length to UDP. After UDP receives the data, it adds the UDP header, which is the encapsulation of the UDP data packet as shown in Figure 3 (c ) shown. Then UDP adds the user data packet together with the IP to its own header, and uses the value 17 in the protocol field to indicate that the data is from the UDP protocol. This process is the encapsulation process of the IP data packet as shown in Figure 3 (a ) shown. This IP data packet is then passed to the data link layer. After the data link layer receives the IP data packet, it adds its own header (and possibly a tail), and then passes it to the physical layer. The physical layer puts these bits Encode it into an electrical or optical signal and send it to a remote machine.
2.2.4 Data reception
The system uses the interrupt mode to receive data. When the network card receives data, it triggers an interrupt and starts the interrupt service routine. In the interrupt service routine, first clear the interrupt flag bit to prevent an interrupt from being triggered again when receiving data, and then judge The value of the register MRMDX determines whether the network card has received data. If the data is received, data processing is performed, that is, the data packet is unpacked, and the data sent by the application program is obtained. If the data is not obtained, the network card initialization failed. Initialize the network card. The flowchart of the interrupt receiving program is shown in Figure 4.
In the received Ethernet data frame, first determine the data type field, if it is ARP protocol, enter the ARP processing flow, if it is IP protocol, enter the IP protocol flow. ARP protocol processing process:
First, determine whether the destination IP address of the ARP packet is the same as the local IP address. If it is inconsistent, discard it and not process it; if it is consistent, then determine the ARP type. When the operation type field is 1, it means an ARP request, and the ARP sending function is called to send an ARP response packet. Operation type When the field is 2, record the MAC address of the other party, and future communication is based on this MAC to transmit data.
The IP protocol processing process is as follows: First, determine whether the destination IP address of the IP packet is consistent with the local IP. If it is inconsistent, discard it and not process it. If it is consistent, then determine the protocol type, whether it is a UDP data packet, and then enter the UDP processing process. If not, it will enter other protocol processing process.
3 Experimental results and analysis
3.1 ARP communication test
ARP request and UDP communication are tested in the experiment, the IP address of the ARM development board is set to 219. 243. 50. 187, the MAC address is 0×52, 0×54, 0x4c, 0×38, 0xf7, 0×42, PC The IP address of the computer is 219. 243. 50. 188, and the MAC address is 0×00, 0×23, 0x5A, 0×15, 0×73, 0xF4. After testing, when the board sends an ARP request to the PC, the PC can The response packet is correctly answered, and the correct response can be obtained for multiple requests, which proves that the ARP protocol can run stably. The experimental results are shown in Figure 5.
When the development board gets the MAC address of the PC, it can communicate with it normally with UDP. In the interrupt program, determine the protocol type, whether the received data packet is ARP protocol or UDP protocol, when the received data packet is ARP protocol , the ARP protocol processing is performed, and the experimental results in Figure 5 are obtained. When the UDP protocol is obtained, the UDP protocol processing is performed, and the experimental results obtained are shown in Figure 6. After a long period of communication, it can be found that the transmitted data There is no code error, which means that this communication method is relatively stable and feasible.
3.2 UDP communication test
In the UDP communication experiment, set the IP addresses and communication ports of the two data terminals to 220.127.116.11:6000, 18.104.22.168:10005, respectively, and then send the data. The result of packet capture with the packet capture tool sniffer is shown in Figure 6. It can be seen from the results in the figure that the SrcIP is 22.214.171.124, the Src Port is 6000, the DestIP is 126.96.36.199, and the Dst Port is 10005, which are the same as the settings. The Protocol is 0×800, which is expressed as UDP protocol type, and can correctly receive the sent data, and after many experiments, the results are correct, which proves that the system communication is stable and reliable, and the transplanted protocol stack can work normally and achieve the expected goal.
In this paper, the UDP communication based on ARM9 and DM9000 chips is realized, and the TCP/IP protocol stack is successfully cut and transplanted to realize the communication of protocols such as UDP. Through the transmission experiment of a large amount of data, the stability of the performance of the communication system composed of ARM9 and DM9000 is proved. It can better solve the problem of communication of a large amount of data through the UDP protocol.