Solve communication problems of UDP protocol based on ARM9 and DM9000 chips

Publisher:sclibinLatest update time:2023-02-01 Source: elecfansKeywords:ARM9 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

With the rapid development of embedded technology and network technology, Ethernet interfaces are increasingly used in embedded systems. Ethernet communication is fast. Universal, can be directly connected to the Internet, providing a wider range of remote access. Currently, in the field of embedded industrial control, network communication usually uses UDP and TCP protocols. Compared with TCP, UDP uses non-connection. Unreliable communication method, so the network transmission speed is fast and the real-time performance is relatively good. In this article, a practical S3C2440 Ethernet controller DM9000 and a self-tailored TCP/IP protocol stack are designed to form the Ethernet interface of the embedded system and realize UDP communication.


1 System hardware introduction

The system uses YLP2440 of Youlong Technology Company as the developed hardware system. YLP2440 uses Samsung S3C2440A as the CPU, with a maximum frequency of 400MHz, an external memory of 64MB SDRAM and 64MB NAND Flash, and two five-wire asynchronous serial ports with a baud rate Up to 115200bps, a 10M/100M DM900AEP network interface card with connection and transmission indicators. DM9000A is a fully integrated. Powerful. A cost-effective Fast Ethernet MAC controller with a universal processing interface, EEPROM interface, 10/100MPHY and SRAM, powered by a single power supply, compatible with 3.3V.5V IO interface levels. DM9000A also supports MII ( Media IndependentInterface (Media Independent Interface), which contains a series of status registers that can be accessed and controlled. These registers are byte aligned and are set to initialization when hardware or software is reset.

The hardware block diagram is shown in Figure 1.

Solve communication problems of UDP protocol based on ARM9 and DM9000 chips

2 Design of Ethernet software

2. 1 Initialization of Ethernet card controller

First, DM9000A self-tests, reads the manufacturer ID and device ID of DM9000 and compares them with the already set ID to determine whether the DM9000 network card exists, and initializes DM9000A. The process is to properly configure the DM9000A register. The specific process is divided into Here are a few steps:

(1) Start DM9000A, set CPCR[REG_1E] = 0×1, make DM9000’s GPIO3 output, GPR[REG_1F] =0×0, make DM9000’s GPIO3 output low to activate the internal PHY. Delay more than 2ms to wait. PHY powers up.

(2) Perform two soft resets and set DM9000 to normal working mode. According to the chip design requirements, if you want the chip to work normally after power-on, you must perform two soft resets. Set 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 receiving and transmitting control registers, and set the FIFO size, 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 flag bits and interrupt flag bits again, NSR[REG_01] =0x2c, ISR[REG_FE] =0x3f.

(7) Set the interrupt mask register, turn on the receive interrupt, IMR[REG_FF] =0×81.


After completing the above steps, the DM9000A chip will be in normal working condition. During the subsequent communication process, if an exception occurs and the chip is restarted, the same settings must be made again.


2. 2 Sending and receiving Ethernet card data

DM9000A uses the loop query mode to send data, and the interrupt mode to receive data. There is a 0x3FF size SRAM inside DM9000 for receiving and sending data buffer. Before sending or receiving a data packet, data is temporarily stored in this SRAM. When data needs to be sent or received continuously, the DM9000 register MWCMD or MRCMD needs to be assigned to the data port respectively, thus specifying an address in the SRAM, and after transmitting one data, the pointer will point to the next address in the SRAM. This achieves the purpose of continuous access to data. But when the data pointer pointing to SRAM does not need to change after sending or receiving a data, MWCMDX or MRCMDX must be assigned to the data port.


Sending data is relatively simple, but 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 receivable data packet. 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 information of the data packet. The format of its high byte is completely the same as the DM9000 register RSR. consistent. The third and fourth bytes are the length of the data packet. The following data is the data that is actually to be received.


2. 2. 1 Tailored implementation of UDP protocol stack

UDP communication is mainly used in the system, and only the ARP protocol and IP protocol need to be implemented, and the TCP/IP protocol is partially implemented. UDP protocol communication (i.e. User Datagram Protocol), like TCP, is a transport layer protocol and is located in IP ( The top layer of the Internet Protocol) protocol. UDP is a simple protocol compared to TCP. It provides the minimum services, requires a small amount of code, requires less program and memory space, and runs fast. ARP corresponds to the IP address. Dynamic mapping is provided between hardware addresses. When the sending terminal sends an Ethernet data frame to another host on the same LAN, the destination interface is determined based on the 48-bit Ethernet address. The device driver never checks the destination IP address in the IP datagram. The IP protocol is the most core protocol in the TCP/IP protocol, and it provides unreliability. Connectionless datagram delivery service.


2. 2. 2 Data sending 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 final communication between the two terminals is by looking for the other party's MAC address, so it must first Through the ARP protocol, the other party's IP address is converted into a MAC address, and communication can only be achieved after obtaining the physical address. If the physical address cannot be obtained for a long time, it can only mean that the request failed and the ARP request needs to be resent. The ARP encapsulation process is shown in Figure 3(b).

Solve communication problems of UDP protocol based on ARM9 and DM9000 chips

Solve communication problems of UDP protocol based on ARM9 and DM9000 chips

2. 2. 3 Data packet encapsulation process

The encapsulation of UDP protocol data packets is performed at the transport layer. The packaged UDP data will be sent to the network layer for IP protocol packaging. UDP needs to complete process-to-process communication and deliver the message to the correct process. When the process has a message to be sent through UDP, it passes the message along 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). Then UDP adds its own header to the user data packet together with IP, and uses the value 17 in the protocol field to indicate that the data comes from the UDP protocol. This process is the encapsulation process of the IP data packet as shown in Figure 3(a). This IP packet is then passed to the data link layer. After receiving the IP data packet, the data link layer adds its own header (and possibly a tail), and then passes it to the physical layer. The physical layer encodes these bits into an electrical or optical signal and sends it to the remote machine.


2. 2. 4 Reception of data

The system uses interrupt mode to receive data. When the network card receives data, it triggers an interrupt and starts the interrupt service program. In the interrupt service program, first clear the interrupt flag bit to prevent another interrupt when receiving data, and then judge the value of the register MRMDX to determine whether the network card has received the data. If the data is received, the data must be processed, that is, the data Unblock the package and get the data sent by the application. If the data is not obtained, it means that the network card initialization failed and the network card needs to be re-initialized. The flow chart of the interrupt receiving program is shown in Figure 4.

Solve communication problems of UDP protocol based on ARM9 and DM9000 chips

When receiving an Ethernet data frame, first determine the data type field. If it is the ARP protocol, it will enter the ARP processing process. If it is the IP protocol, it will enter the IP protocol process. ARP protocol processing process:

First, determine whether the destination IP address of the ARP packet is consistent with the local IP address. If it is inconsistent, it will be discarded and not processed; if it is consistent, then determine the ARP type. When the operation type field is 1, it indicates an ARP request, and the ARP sending function is called to send the ARP response packet. When the operation type field is 2, record the MAC address of the other party, and future communications will transmit data based on this MAC.


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, it will be discarded and not processed. If it is consistent, then determine the protocol type and whether it is a UDP data packet. If so, enter the UDP processing process. Otherwise, just enter other protocol processing processes.


3 Experimental results and analysis

3. 1 ARP communication test

The ARP request and UDP communication were tested in the experiment. The IP address of the ARM development board was set to 219. 243. 50. 187, and the MAC address was 0×52, 0×54, 0x4c, 0×38, 0xf7, 0×42, PC The IP address of the machine 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 is opened and an ARP request is sent to the PC, the PC can The response packet is correctly responded to, and correct responses can be obtained for multiple requests, which proves that the ARP protocol can operate stably. The experimental results are shown in Figure 5.

[1] [2]
Keywords:ARM9 Reference address:Solve communication problems of UDP protocol based on ARM9 and DM9000 chips

Previous article:DM9000AE working principle Ethernet interface circuit design
Next article:Video data collection based on microprocessor S3C2440 and WinCE embedded real-time operating system

Latest Microcontroller Articles
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号