Implementation of lwlp based on ARM microprocessor TCP/IP protocol stack

Source: Internet
Author: User
Tags types of functions
0

With embeddedSystemAndNetworkMore and more embeddedDeviceTo achieve Internet network and support the access of embedded devices to the network, it has become an important part of the embedded field.ResearchDirection. A large number of Embedded SystemsApplicationLow SpeedProcessor, Restricted by memory and speed,Complete TCP/IPProtocolLWIP is widely used as a mature embedded TCP/IP protocol stack..

1HardwarePlatform

The hardware platform of the communication system consists of the following parts:Composition:S3C2410The master CPU chip controls the storage, communication, protection, debugging, and display operations of embedded peripheral devices;DSP and FPGACollects and processes signal data;Cs8900aResponsible for sending and receiving network data; other components include serial RS232 communication, LCD data display, data storage flash and SDRAM, and other hardware control. The hardware communication platformPrincipleFigure 1 shows.

EmbeddedOperating SystemSelectμCOS ⅱ,As the smallest embedded operating system in the market, μCOS ⅱ has been widely used to provideInter-taskThe semaphores, mailboxes, and message queues used for communication and synchronization are well cropped.

2 TCP/IP protocol stack LWIPPort

LWIP consists of several modules,In addition to the TCP/IP implementation modules (IP, ICMP, UDP, and TCP), there are also many supported modules.. These support modules include:Operating System Simulation layer, buffer and memoryManagementSubsystems, NetworksInterfaceFunctions and a set of Internet checksum and calculation functions. The LWIP of most modules, such as the buffer and memory management subsystem, has been released independently. During the porting process, no changes are required. We only need to implement the Operating System Simulation layer and underlying hardware.DriverYou can work normally.

The operating system simulation layer is designed to facilitate LWIP migration. It provides an interface between the underlying operating system μCOS ⅱ and LWIP. In this way, we only need to modify this interface when porting LWIP to a new target system. The OS simulation layer must implement three types of functions: semaphore operation function, mailbox operation function, and thread operation function.

To support the Operating System Simulation layer, you also need to define the CPU or compiler, such as the data type, data length, and the order of characters, these should be consistent with the implementation of μC/OS-ⅱ. Note that a network may be different fromArchitectureIn two ways: Little-Endian order and big-Endian order. Note the matching of the byte order.

3. Implementation of underlying network drivers

The underlying network-driven framework LWIP has already implemented a vast majority for US (as shown in Figure 2 ).DesignComplete the components related to the underlying hardware in the framework. That is, we only need to implement the hardware-related Nic initialization function network packet sending function and network packet receiving function.

Cs8900a, the underlying network chip used in this article, is a 16-bit Ethernet controller with low power consumption and superior performance produced by C irru slo g ic. It has powerful functions. It features flexible usage, physical layer interfaces, and dataTransmissionBoth the internal and work modes can be dynamically adjusted as needed.RegisterTo adapt to different applications.Environment. It complies with the IEEE 802.3 Ethernet standard and has 4 K bytes of RAM in the chip to store the sent and received data; the data communication modes between hosts include I/O mode, memory mode, and DMA mode, which can be flexibly selected according to the specific circumstances during circuit design; 10base2t connection port with transmit and receive low-pass filtering; Supports the au I interfaces of 10base2, 10base5, and 10base2f; automatically generates headers, performs CRC checks, and resends after a conflict; full and half duplex modes.

The main content of cs8900a Initialization is as follows:

    • SoftwareReset and check whether the reset mark is set;
    • Set the memory working mode to map the 4 K memory address to the host memory;
    • Set the physical ethernet address for temporary use. apply to the Authority for the actual address;
    • Set the type of the received frame, at least to be able to receive the broadcast;
    • Determine the data transmission direction, generally set to full duplex mode;
    • Enable interrupt;
    • Enable receiving interruption;
    • Determine the interrupt PIN number of cs8900a Based on the usage of the hardware line;
    • Receive and send enable.

It must be noted that due to the frequent TCP/IP communicationArmThe interrupted mode occupies too many resources.Query MethodTo ensure basic data communication.

Basic data transmission for cs8900aProcessListen to the network line after receiving the datagram from the host. If the line is busy, it waits until the line is idle. Otherwise, the data frame is sent immediately. During sending, it first adds the Ethernet frame header (including the pilot field and the frame start flag), generates the CRC check code, and finally sends the data frame to the Ethernet. Data transmission flowchart 3.

When the data is received, it sends the data frame received from the EthernetDecodingRemove the frame header and address check steps and then cache them in the slice. After the CRC check is passed, it notifies the host cs8900a of receiving the data frame based on the Initialization Configuration and then transmits it to the host's storage area. Figure 4 shows the data receiving flowchart.

4 upper layer socket basic communication implementation

LWIP has implemented most Socket network connection functions. to implement basic socket communication, you only needBasicBy calling its Socket network connection function to implement a simple client/server mode. The instrument acts as the server and the host acts as the client for connection. As shown in result 5, send the program-controlled command freq 300 and return freq 300.000000mhzok, indicating that the setting is successful.

5 conclusion

The system has been used in the field force meter av3942 and can remotely control it through the network. Practice has proved that the system is simple and practical, and can achieve convenient and flexible interconnection of various communication systems.

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.