You are on page 1of 4

2010 International Conference on Networking and Information Technology

The Design and Implementation of Network Data Link Layer Based on Embedded
TCP/IP Protocol Stack

YanHongwei PanHongxia
College of Mechanical Engineering & Automatization, College of Mechanical Engineering & Automatization,
North University of China North University of China
Taiyuan, China Taiyuan, China
e-mail: yaweigeh@sohu.com e-mail: panhxlOI5@163.com

Abstract-With the development of computer technology, TCP/IP protocol used for embedded system networking is
embedded TCPIIP protocol stack has become an important called embedded TCPIIP protocol. Embedded TCP/IP
part of the network information intelligence. Considering the protocol is different from the conventional TCPIIP, it has
structure features of the embedded TCPIIP protocol stack, this portability, configurable and can be cut, the main
paper discusses the specific implementation procedure of the characteristic is a real-time, simplicity and flexibility.
protocol stack network interface layer. The datagram module
The link layer of the TCPIIP protocol stack, Network
of RTL8019AS controller and the Ethernet data sending
Interface Layer, is refered to the Ethernet physics interface
module are designed to achieve the network communication. It
and the Ethernet interface. The link layer is to drive the
is shown that the system design was accomplished and it can be
Ethernet interface circuit, programming network card driver
introduced to the practical usage in the real life.
and Ethernet interface according to interface circuit, so as to
realize the system connectes network[4][9][10][1l][16].
Keywords-TCPIIP Protocol Stack; Embedded Systems;
Ethernet; Network Interface Layer; ARP What network interface layer realizes is system and ethernet
network, structure of system network interface layer is
shown in figure 1
I. INTRODUCTION
CB
TCPIIP is a set of protocol used for computer EMBEDDED
communication, usually called TCPIIP protocol family, it is RAM
PROCESSOR
network architecture and the protocol standard developed by
United States Department of Defense for the Arpanet wan in
mid 1970s, Internet based on it is the largest international
computer network currently. Because of the extensive use of
the Internet, TCPIIP became the defacto standard. It RTL8019AS
represents a protocol stack,which is composed of a series of
small and special protocol, including IP, TCP and UDP,
ICMP(lnternet control message protocol), FTP(file transfer
protocol), SMTP (simple mail transfer protocol), an ARP
(Address Resoloution Protocol) and many other protocol,
referred to as the TCPIIP protocol. From the ayering model
of protocols, TCP/IP composed by four levels, the four
layers is the network interface layer, network layer, the
transport layer and network. The OSI reference model, Open Figure 1. Schematic Diagram of the Network Interface Layer
Systems Interconnection is the network architecture open
system interconnection reference model presented by ISO in
1981. The OSI network is divided into seven levels, namely: II. REALIZE NETWORK CONTROLLER DRIVER BASED ON

the physical layer, data link layer and network layer, the THE BOTTOM LAYER DRIVING

transport layer, session layer, presentation layer, application To realize the network interface layer, at first to realize
layer[I][2]. network controller RTL8019AS bottom driving, then prepare
In order to adapt to the application of the embedded the driver. As the physical foundation of achieving TCPIIP
system online demand, embedded system facing the 21st protocol stack, RTL8019AS driver mainly completed work
century requires to allocate standard one or more network includes: Nic initialization, sending and receiving data
communication interface[3].Embedded equipment for upper message.
network protocol stack usually choose to use the TCPIIP
protocol, through the TCP/IP protocol it can make internal A. RTL8019AS Initialization Program Design
network or networks communicate and exchange of In RTL8019AS initialization procedures, completing the
information with the Internet and worldwide networking,the resetting of network card , setting all the internal register of

978-1-4244-7578-0/$26.00 2010 IEEE 227


2010 International Conference on Networking and Information Technology

RTL8019AS and the physical address of Ethernet,Specific as Design program that make RTL8019AS sends data to the
follows: Ethernet, as Ethernet bottom driver, all the data sent should
Before the initialization function setting internal get through the program. First calculate total length of
register, first reset RTL8019AS, Reset pin RSTDRV packets sent, then send the data to send buffer, and set the
is high level effective. To make chips reset, length of starting address of the chip (i.e. starting address of send
time of high level should be more than 800ns, buffer). If data is less than 60 bytes, need to fill 60 bytes with
usually 100ms after RSTDRV from high level to low padding bit, then start sending. If failure to send, send
level,then read-write RTL8019AS, to ensure the again ,the number of times of sending defind for six times.
completely reset. The design code is in the critical areas of operating system
Setting all internal working registers of RTL8019AS. task , the process is shown in figure 2.
By the Ethernet interface circuit we can know
C. The Design Program Module of Receiving Datagram
ethercard map in the Bank3 of system, so the
addresses starte from Ox83400000 , the program are The function of received processing program is to
defined as follows: process packets received and is direct called by receive tasks.
#define RTL8019AS_Base Ox83400000 II Bank3 Before writing receiving and processing process ,defind the
Offset relatived to it being 00 is register CR, assign circular chain of receive buffer, and determine the length of
to CR to make RTL8019AS Stop mode, delay !Oms the chain according to the length of maximum frame of data
ensure chips get into stop mode. Select page 0,
clean RBCRO,RBCRI . Assign to registers RCR,
make Ethernet controller get into monitoring
mode,stop receive packets, Assign to registers TCR,
make Ethernet get ino loop back mode. Choose page
1, the current page registers CURR=Ox4D; Clear
Multicast addresses register MARO-MAR7. Write
Ox22 to registers CR, chip began to work. Then
obtain the physical address of the Ethernet, and
writte it to MAR registers[5][6].
Obtaining physical address of ethernet. Storage
physical address of network card in OxOOOO-Ox001F
RAM of RTL8019AS , program read the data to
MAR register. After obtaining n physical address of
network, setting chip into normal mode, connect
with external network. Write Ox22 to CR registers,
start chip began to work, ISR = OxFF, remove all
interrupt the flag. Ethernet controller RTL8019AS
initialization completes.

B. The Design Program Module of Sending Datagram

Figure 3. Receive datagram flow chart

In order to protect the hardware in the process of


operation, call two macros of the embedded real-time
operating system uCIOS-II: OS_ENTER_CRITICAL into
critical area, OS_EXIT_CRITICAL exit critical area; Almost
all of the code are belong to the critical area code. When the
program code comes into critical area, judg the state of
network chip. If RTL8019AS at reset condition, initialized
then the exit, If in normal working condition, then read the
read/write pointer, and operation. Read/write operation judge
the location of pointer, if not wrong, then execute pointer add
1, Otherwise, exit. Judge whether the pointer pointe to the
last page, decide whether to set back to the start page. Check
Figure 2. Send datagram flow chart

228
2010 International Conference on Networking and Information Technology

whether receiving data, if not, then exit, If the check to B. The Design Program Module ofSending Datagram
receive data, then check whether the it is correct data and the
According to data information and target address of
length is too long, etc. If all operations are correct, then read
pointing to a layer protocol,Ethernet layer sending module
and do the corresponding processing. After treatment, check
judge relationship betwing the destination address and local
again until the data report without receiving. If the check and
address, determine whether belong to the same subnet. If
length of data is error, empty receive buffer of network
not, set the target MAC addresses as the default gateway
interface chip RTL8019AS, then exit operation. Due to the
MAC address, Otherwise, in an ARP list inquires whether
use of Ethernet communication system, call Ethernet layer
receiving program in program, thus Ethernet obtaine data there is corresponding MAC address. If checked, writte the

[6][12][13][14][20].The program flow is shown in figure 3. target MAC address to ethernet layer send buffer zone, Then
according to the parameter of PROTOCOL set agreement
III. DESIGN ETHERNET INTERFACE LAYER PROGRAM fields of ethernet layer, finally called the send data program
The realization of the Ethernet interface is to write the of driver to sends data. If not, then send address, Otherwise,
Ethernet interface, through the Ethernet interface program, inquires in an ARP list whether there is corresponding MAC
network controller RTL8019AS can obtaine from the address. If there is, then sending an ARP request frame ,
network and transmit data. Therefore, the Ethernet interface request the IP address corresponding the MAC address,
program is the agreement of connection hardware and return to send failure marks[15][17][19][21]. Program
software. Program the ethernet interface include flowchart as shown in figure 5.
programming receiving of ethernet layer data and
programming sending of ethernet layer data [7][8][11].

A. The Design Program Module ofReceiving Datagram


Design ethernet layer receiving complete the function of
receiving data from the upper agreement. According to
starting address of Ethernet data frame and packet and the
network slogan, judge source type and address of data of
packets. The types of ARP packets can be divided into ARP
and IP. When the system is receiving data, first judge types
of data frames, if ARP packets, add the information to ARP
table, If IP packets, inquires ARP table whether there is
corresponding entries, if have, it refreshes the survival time,
Otherwise, add entries and then processing[12][18].
Therefore, before program must be defined ARP listed below:
struct ARP_t{Survival time; The IP address; The IP
address corresponding the MAC address;}
Programming flowchart as shown in figure 4.

NO

Figure 5. Ethernet sends process flow diagram

In the process, to judge the data sent or received and


purpose network card, so before designing the program must
define frame header,body structure are as follows:
type struct{
Purpose card address;
Source network address;
The next layer protocol;
} IpEthernet
Definition of the hardware interface parameters structure
are as follows:
Figure 4. Ethernet receive program flow chart type struct {

229
2010 International Conference on Networking and Information Technology

Interface IP address; [S] YanHongwei and PanHongxia, "embedded network parameters


testing system research," Electronic engineer, Vo1.30, pp.72-
Interface gateway IP address;
74,Mar.2004.
Interface IP address masking;
[6] ZhuFengxin and YaoZhuting, "Based on AVR time trigger embedded
Interface MAC address; system,"Industrial control computer,July.2006, pp.34-37.
Gateway MAC address; [7] M.J. Willis, G.A. Montague, "Artifitial Neural Netwoks in Process
Survival time of the gateway IP address; Estimation and Control," Automatica, Vo1.2S, pp. IISO
Local interface corresponding ARP llS6,Jun.1992.

structure array tables; [S] Mcfadden, P.D, Toozhy M M, "Application of Synchronous


Averaging to Vibration monitoring of Rolling Element Bearing,"
}. Mechanical Systems and Signal Processing, Vo1.l4,pp. 34-46,
Jun.1992.
IV. CONCLUSION
[9] XuHaiyan, "technology and application of embedded system,"China
Embedded TCP / IP protocol stack is the underlying Machine Press, 2002, pp.2S-SS.
network data link layer protocol. This paper discussed the [10] TianZe, "the development and application of the embedded system,"
specific implementation procedure of the protocol stack Beijing university of aeronautics & astronautics press, 200S, pp.134-
26S.
network interface layer with the consideration of the
[11] WangChunming, "Embedded system and the Ethernet interface
structural characteristics of the embedded TCPIIP protocol
design and interconnection,"Nanjing university of science,Dec.2002,
stack. The datagram module of RTL8019AS controller and pp.I44-16S.
the Ethernet data sending module were reset, initialized, and [12] ZhouLigong, "ARM micro controller basis and actual combat,"
programmed to send and receive the network data and Beijing university of aeronautics &astronautics press,2003, pp.I-3S0.
achieve the low-level network interface and hardware [13] WangDongyun, "network access control, Internet solutions and
function drive. This study separated the physical interface in example,"Electrical Automation, 2003, pp.3-2S.

the network communication and the upper layer protocol. It [14] WuXiaorong, "Internet technology in embedded system," the
realization of computer engineering, 2004, pp.I-4.
also played a role on connecting the protocol stack layers.
The presented work provided a promising basis for further [IS] Thomas F, "An introduction to TCPIIP for Embedded Engineers,"
Embedded System Conference, San Francisco 2002, pp.126-370.
improving the efficiency and shortening the design cycles.
[16] GeYongming and LinJiBao; "Ethernet interface design of embedded
system,"Electronic technology applications, Mar.2002, pp.2S-27.
ACKNOWLEDGMENT
[17] Jean J.L abrosse, "Embedded real-time operating system of IlC/OS- II
The work described in this paper has been supported by maximum tire-road friction coefficient beibei model," Beijing
National Natural Science Foundation of China under the aviation aerospace big university press, 2003,pp.I-S.

grant No.50575214. The authors would like to express their [IS] LiZheYing, "ARM kernel embedded system developing platform,"

gratitude for the support of this study. semiconductor technology; ADS In Vo1.2, pp.12-14, Feb.2002.

[19] Jae-Ho Lee, "Implementing priorit inheritance semaphore on IlC/OS


REFERENCES real-time kernel Software Technologies for Future Embedded
Systems, 2003.IEEE Workshop on May 2003,pp.IS-16.
[I] Tim Paukeu, "Leading studios translate, TCPIIP technology, "China
[20] RenTaiMing, "TCPIIP protocol and network programming," xidian
Machine Press, 2000, pp.41-164.
university press, 2004, pp.24-30S.
[2] Osteuloh Heathen, ZhangJinXiang translate. "TCPIIP Puimeu Plus
(Chinese) ,"China Posts & Telecom Press, 200S, pp.S-23. [21] Tong Xiaoyang, "transformer fault that online and associated
embedded system based on TCPIIP and Pub/Sub new beaver
[3] RenTaiming, "TCPIIP protocol and network programming, " xidian
population,"Apr.2003,Electrical and Electronics Inc e, pp2S-2S.
university press, 2004, pp.64-SS.

[4] Jacek w.Szymanski. "Embedded Communication Systems," 2000


IEEE International Workshop on June 2000,pp.36- 42.

230

You might also like