Port UIP 51

Source: Internet
Author: User

 

UIPFeatures

UIP was developed by Adam dunkels of the Swedish Institute of Computer Science (network embedded systems team. The source code is written in C language and fully disclosed. All codes and related instructions can be downloaded at http://dunkels.com/adam/uip. The latest version is uip1.0. This version is the one for porting and using this book.

The uIP protocol stack removes the incomplete functions that are not commonly used in TCP/IP and simplifies the communication process, but retains the protocols required for network communication, the design focuses on the IP/tcp/ICMP/udp/arp networks and transport layer protocols to ensure the versatility of the Code and the stability of the structure.

Because the uIP protocol stack is designed for embedded systems, it also has the following advantages:

(1) The number of codes is very small, and the protocol stack code is less than 6 kb, which makes it easy to read and transplant.

(2) The memory usage is very small, and the RAM usage is only several hundred bytes.

(3) The hardware processing layer, protocol stack layer, and application layer share a global cache zone, and there is no copy of data, and both sending and receiving depend on this cache zone, greatly saves space and time.

(4) supports multiple active connections and passive connection concurrency.

(5) The source code provides a set of instance programs: Web servers, web clients, E-mail sending programs (SMTP clients), Telnet servers, DNS host name resolution programs, and so on. It is highly versatile and can be migrated without modification.

(6) data processing adopts a round robin mechanism and does not require the support of the operating system.

Most 8-bit controllers use the uIP protocol stack, and many well-known embedded products and projects (such as satellites, Cisco routers, the uIP protocol stack is used in wireless sensor networks.

.2 UIPArchitecture

 

UIP is equivalent to a code base. It communicates with underlying hardware and high-level applications through a series of functions. For the entire system, its internal protocol groups are transparent, which increases the universality of the Protocol. The relationship between the uIP protocol stack and the underlying and high-level applications of the system is 2-1.

 

Figure 2-1 location of a UIP IN THE SYSTEM

It can be seen that the uIP protocol stack mainly provides three functions for the system to call at the underlying layer. Uip_init (), uip_input (), and uip_periodic (). Its main interface with the application is uip_appcall ().

Uip_init () is called during system initialization. It mainly initializes the listening port of the protocol stack and closes all connections by default.

When the NIC driver receives an input packet, it is placed in the global buffer uip_buf. The package size is subject to the global variable uip_len. At the same time, the uip_input () function will be called. This function will process the package and call the application as needed based on the protocol of the package header. When uip_input () is returned, an output package is also placed in the global buffer uip_buf, And the size is assigned to uip_len. If uip_len is 0, no package is sent. Otherwise, call the package sending function of the underlying system to send the package to the network.

The UIP cycle time is used to drive all UIP internal clock events. When cyclic timing is triggered, each TCP connection calls the UIP function uip_periodic (). Similar to the uip_input () function. When the uip_periodic () function returns, the output IP package should be placed in uip_buf for the underlying system to query the size of uip_len.

Because TCP/IP is used in many scenarios, applications are implemented by users as separate modules. The uIP protocol stack provides a series of interface functions for user programs to call. Most of the functions are implemented as macro commands of C, mainly for speed, code size, efficiency, and stack usage. You need to provide the application-layer Entry Program as an interface to the uIP protocol stack and define this function as macro uip_appcall (). In this way, UIP calls uip_appcall () where it needs to be sent to the upper-layer application for processing after receiving data packets from the bottom layer (). You can adapt to different applications without modifying the protocol stack.

2.3 UIPInMCS-51Transplantation on Single Chip Microcomputer

1.Create a Keil C Project for this project and create the src directory to store the source files.

2.Read the uip-1.0/Unix/Main. C, understand the UIP's main loop code architecture, and put main. c uip_arch.h under the src directory.

3.Follow the uip-1.0/Unix/tapdev. C to write the NIC driver, and the specific hardware. This step is a little time-consuming, but fortunately most of the NIC chip drivers have code for reference or transplantation. The driver must provide three functions. The rtl9019as driver is used as an example.

Tapdev_init (): Nic initialization function, which initializes the NIC working mode.

Tapdev_read_read (void): Read Package function. Put the data received by the network adapter into the uip_buf in the global cache, and assign the length of the returned package to uip_len.

Tapdev_send (void): the packet sending function. Send the data (length in uip_buf) in the global cache area to uip_len.

Therefore, uip_buf and uip_len are mainly used to collect and send packets. For detailed driver analysis, see Chapter 3 network chip driver.

4.The uIP protocol stack uses a clock to serve the timer of TCP and ARP. Therefore, the single-chip microcomputer timer 0 is used as the clock, so that every 20 ms to count tick_cnt plus 1, so that 25 count (0.5 s) is full, you can call the TCP timed processing program. You can call the ARP aging program after 10 s. Copy timer. c/Timer. H, which is used to manage the clock and put them under SRC.

5.UIP protocol stack in the uip-1.0/UIP. c/UIP. H, put the SRC. If ARP is required, put uip_arp.c and uip_arp.h under SRC.

6.Uipopt. h/uip-conf.h is the configuration file

(6) The macro definition needs to be modified because the single-chip microcomputer is a large-end structure.

# Define uip_conf_byte_order uip_big_endian

 

(8) define data structure types

Typedef unsigned char u8_t;

Typedef unsigned int u16_t;

Typedef unsigned long u32_t;

7.If you use the small mode of Keil C for compilation, you need to add xdata before most Ram variables.

8.Data is the keyword of Keil C. In the code, all data (mainly parameters, local variables, and struct members) is changed to pucdata or ucdata.

9.Solve compilation errors. Solve Some header files. The uIP protocol stack is written in C language, which has fewer problems during compilation and is easy to solve.

10. Comment on debug. It is not supported in Kei C.

 

Add "# define uip_conf_ipv6 0" to disable so many warnings during arm compilation.
Add "# include" netapp. H "". This is the header file of your network application, which should be defined:
# Define uip_appcall
# Define uip_tcp_appstate_t and # define uip_udp_appstate_t
# Define uip_appstate_size
Uipopt. h:
You can directly use some advanced configurations of the protocol stack without modifying them.

 

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.