Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CHAPTER 1: INTRODUCTION
1
CHAPTER 4: APPLICATION LAYER PROTOCOLS
CONCLUSION------------------------------------------------------------82
BIBILOGRAPHY- -------------------------------------------------------83
2
1. INTRODUCTION
1.1 Introduction:
The Internet has revolutionized many aspects of our daily lives. It has affected
the way we do business as well as the way we spend our leisure time. Count the ways
you have used the Internet recently. Perhaps you have sent email to a friend, paid a
utility bill, read a news paper from a distant city, or looked up a local movie schedule
– all by using the Internet. Or, may be you researched a medical topic, booked a hotel
reservation, and chatted with a fellow trekkie. The Internet is a communication system
that has brought a wealth of information to our fingertips and organized it for our use.
These days it seems, everybody and their brother is talking about the need of
becoming “Internet aware” - a new catch phrase sounding eerily similar to something
said in Eden some time ago. The explosive growth and appeal of the Internet has
everyone scrambling to get onboard, or be thought of as somehow “20th century”.
Today, Internet accessibility in one form or another, if not an a priori requirement, is
at least a highly desirable option in many embedded applications. Previously the sole
domain of mainframes, PCs, and workstations, TCP/IP stacks and other networking
applications are now being written by the dozens for embedded microprocessors and
microcontrollers, providing them the smarts to hook into the “matrix”. We’ll also seek
to resonate some understanding of the basic issues one needs to consider when
deciding on which approach is best suited for their embedded Internet application.
3
Communications is fast becoming a general requirement for Embedded
Systems that include no form of external communication. This requirement is nothing
to fear as networking technologies can meet the challenge of the embedded domain
and make developing these systems much simpler.
Note that from this definition, a desktop personal computer does not
qualify. Nor do any other general-purpose devices such as Personal Digital
Assistants (PDA). The embedded computer in the microwave fits this def -
inition, as does the computer within our car's radio. Even cellular phones still fit
this definition, although that definition is changing with the higher integration
possible today (cell phone/PDA integration).
4
It's important to note that an embedded system in no way implies a real-
time system. A real-time system responds to unpredictable external stimuli in a
timely and predictable way. All of the protocols discussed in this text have very
soft requirements with respect to timing and therefore embedded aspects will be
the secondary focus.
ABSTRACT
1.3 Embedded Web Server:
5
In this project we are developing “Embedded Web Server For Temperature
Monitor and Controller” Based on 8 bit - Rabbit Microprocessor. This device can be
used in any LAN / WAN / and Internet. Using this application we can get an idea of
how to control more complex equipments in a large network from a centralized
station.
Rabbit
Microprocessor T
C REMOTE - PC
Ether [TCP / IP
P INTERN
Net ENABLED
/ ET /
Port CLEINT]
I LAN /
AD P WAN
C
Temperatur
e Sensor
6
Embedded solutions:
Among the myriad of embedded Internet solutions being touted today, all fall neatly
into one of five fundamental groups:
1. Embedding a fully functional (or nearly so), third party TCP/IP stack into your
application, enabling direct Internet access…
7
Suppose the embedded web server is embedded in several units in a
house. Every server is connected to the network. A computer located at home
as on Figure 2 controls all devices and can receive requests from other
computers on the Internet. The web server is identified by its unique IP
address and can be controlled remotely from anywhere in the world as long
as the authorization is in order.
8
1.5 Characteristics of Embedded Systems
Let's now look at some of the characteristics of embedded systems regard ing
their capability of connecting to the Internet.
For example, the TCPIIP stack must have a relatively accu rate time
source for timer management (to handle the various timeouts and timing
activities that take place in the stack). The stack must also have a resource
management system for packets. This could be a standard dy namic memory
management system (Malloc/Free) or a custom system that pre-allocates packet
buffers for speed.
9
It is possible to use a TC P /IPstack with no kernel as long as you pro vide
the services that it needs (timer, memory manager, etc.). In systems with minimal
requirements, this can yield a very small and fast imple mentation. When
possible, the best arrangement is an OS that is pre-configured with a network
stack. For example, all embedded Linux distributions au tomatically include a
standard TC P /IPstack. Commercial RTOS vendors such as QNX Software and
Wind River Systems optionally include net- working stacks. Other than
simplicity for development (you concentrate on your application instead of the
as/stack), there are other benefits to this model. The largest benefit is that of
available software.
10
tailored for the embedded environment saving time and effort .
The standard socket layer defines blocking semantics such that a call to
read from a socket with no data available will cause the call to block until data is
available. The write call behaves in a similar mam1er. If the number of octets
being written is greater than the available space in the buffer, the write call
blocks until sufficient space in the write buffer is available. If an as is not
available, these blocking semantics are also not available. The socket layer can
work in a non-blocking manner, though in many cases this can be inefficient.
Some commercial stacks provide a callback mecha nism such that when some
type of event occurs for a given socket, a user- "---- defined application is called.
This type of architecture can be extremely efficient.
With an RTOS, the stack may be defined as a single task or be split among the
protocol layers. In most cases, this distinction exists between the stack and the
data link layer. The Media Access Control (MAC) or serial port (for PPP/SLIP)
is commonly split from the TCPIIP stack software due to their asynchronous
nature. Recall from Chapter I that this split is due to the asynchrony of the layer's
processing requirements.
Embedded systems are commonly designed for minimal cost. With cost re -
11
duction comes reduction in the available resources such as Flash/non volatile
memory and RAM. Having a minimal amount of RAM means that extreme care
must be taken regarding the method that the TCPIIP stack uses for the allocation
of packets.
12
2.THE OSI REFERENCE MODEL:
The OSI reference model specifies standards for describing "Open Systems
Interconnection" with the term 'open' chosen to emphasize the fact that by using these
international standards, a system may be defined which is open to all other systems
obeying the same standards throughout the world. The definition of a common
technical language has been a major catalyst to the standardization of communications
protocols and the functions of a protocol layer.
13
The seven layers of the OSI reference model showing a connection between
two end systems communicating using one intermediate system.
The structure of the OSI architecture is given in the figure above, which
indicates the protocols used to exchange data between two users A and B. The figure
shows bidirectional (duplex) information flow; information in either direction passes
through all seven layers at the end points. When the communication is via a network
of intermediate systems, only the lower three layers of the OSI protocols are used in
the intermediate systems.
Data link layer: Provides functional and procedural means to transfer data between
network entities and (possibly) correct transmission errors; provides for activation,
maintenance, and deactivation of data link connections, grouping of bits into
characters and message frames, character and frame synchronisation, error control,
media access control, and flow control (examples include HDLC and Ethernet)
Network layer: Provides independence from data transfer technology and relaying
and routing considerations; masks peculiarities of data transfer medium from higher
layers and provides switching and routing functions to establish, maintain, and
terminate network layer connections and transfer data between users.
14
provides end-to-end control and information interchange with quality of service
needed by the application program; first true end-to-end layer.
The two lowest layers operate between adjacent systems connected via the
physical link and are said to work "hop by hop". The protocol control information is
15
removed after each "hop" across a link (i.e. by each System) and a suitable new
header added each time the information is sent on a subsequent hop.
The layers above layer 3 operate "end to end" and are only used in the End
Systems (ES) which are communicating. The Layer 4 - 7 protocol control information
is therefore unchanged by the IS in the network and is delivered to the corresponding
ES in its original form. Layers 4-7 (if present) in Intermediate Systems (IS) play no
part in the end-to-end communication.
2.2 Encapsulation:
When an application sends data using TCP, the data is sent down the
protocol stack, through each layer, until it is sent as a stream of bits across
the network. Each layer adds information to the data by prepending headers
and adding trailers to the data it receives. Figure 5 shows this process.
16
2.3 Some abbreviations:
17
value in its header called the protocol field. Similarly, many different
applications can be using TCP or UDP at any time. The Transport Layer
protocol stores an identifier in the header they generate to identify the
application. Both TCP and UDP use 16-bit port numbers to identify
applications. The TCP and UDP store the source port number and the
destination port number in their respective headers. The network interface
sends and receives frames on behalf of IP, ARP, RARP. There must be some
form of identification in the Ethernet header indicating which network layer
protocol generates the data. To handle this, there is a 16- bit frame type field
in the Ethernet header.
18
Client / Server interaction across a packet data network
Detailed Description
The diagram above provides only a very simplified view of what happens. In
fact, a number of primitives are required to perform even such simple communication.
The text belows performs a detailed analysis of the primitives and PDUs which are
exchanged.
The user executes the client program and attempts to send one piece of data to
the server (for example,. a request to lookup the address corresponding to a name).
The actual data need not be of concern here. Before the client may send the data, it
must first establish a connection to the application layer (i.e. communications
software library) on the local computer.
19
The client program uses an A-Associate request function call to start the
communication session. Once the application layer has initialized, it contacts the
presentation layer, sending a P-Connect request primitive (see below). This
establishes the format of the data to be used and the data formats which are to be
supported by the system A on the network. This information is sent to the session
layer as an SDU with an S-Connect request primitive. The session layer allocates a
session identifier, and selects appropriate protocol options to support the services
requested by the application layer. The session layer also identifies the intended
recipient of the communication (i.e. the remote computer).
At this stage the transport layer requests the network layer to establish a
connection to the remote system. The network layer service will normally have
established a link layer connection (and a physical layer connection) to the nearest
intermediate system. In this case however, we assume that all the layers must be
connected.
20
Finally, the network layer connect packet is sent using the link layer service to
the remote system. The system responds by invoking the requested transport layer,
and establishing a transport layer connection. If the remote system is able, it will then
confirm the establishment of the transport connection, and pass the confirmation back
to the local client computer. At this time the two systems have a communications path
using the transport layer service.
The transport layer may then use this service to request a connection to the
server process on the remote computer . It does this by forwarding the original session
layer SDU (which it had previously stored in the session layer of the local computer)
as a transport layer packet. This passes across the network layer service, and at the
remote system is passed to the session layer protocol.
21
The received SDU identifies the session ID and the application process with
which the client wishes to communicate. The presentation layer is sent an S-Connect
indication, containing the presentation options requested by the client and the A-
Associate request sent by the client. The application layer now attempts to connect to
the server process. (In some cases, a new server program will be activated to handle
this new request).
Once this has succeeded a response is generated, carrying the final details of
the connection. This information is passed as an A-Associate response primitive to the
application layer. At each layer additional PCI is added by the remote system, and
finally an N-Data primitive is sent across the network layer service. At the receiver
each layer verifies the information it receives, and confirms the successful connection.
The application layer send an A-Associate confirm message to the client process
which is then ready to transmit data.
22
Data Indication primitives, with reduced data units, cascade up the layers until the
application data reaches server application. Client application only learns of
successful receipt if the server application returns an Acknowledgment (in this case,
possibly with the requested data). The Acknowledgment returns across the network.
The "association" has now been made and data may be sent across the network
between the client and server.
After data transfer is complete, a disconnect phase similar to the connect phase will
occur
23
.
Figure 1-1 shows the TCP/IP protocol suite in relationship to the OSI
reference model.[1] The network interface layer, which corresponds to the OSI
physical and data link layers, is not actually part of the specification. However, it has
become a de facto layer either as shown in Figure 1-1 or as separate physical and data
link layers. It is described in this section in terms of the OSI physical and data link
layers.
The OSI protocol suite itself has become, with some rare exceptions, a relic of
early Internet history. Its current contribution to networking technology seems to be
24
mainly limited to the usefulness of its reference model in illustrating modular protocol
suites to networking students and, of course, the IS-IS routing protocol still widely
used in large service provider and carrier networks.
The physical layer contains the protocols relating to the physical medium on
which TCP/IP will be communicating. Officially, the protocols of this layer fall
within four categories that together describe all aspects of physical media:
25
Procedural protocols describe how something is done. For example, a binary 1
is represented on an EIA-232-D lead as a voltage more negative than 3 volts.
The data link layer contains the protocols that control the physical layer: how
the medium is accessed and shared, how devices on the medium are identified, and
how data is framed before being transmitted on the medium. Examples of data-link
protocols are IEEE 802.3/Ethernet, Frame Relay, ATM, and SONET.
The host-to-host layer, corresponding to the OSI transport layer, specifies the
protocols that control the internet layer, much as the data link layer controls the
physical layer. Both the host-to-host and data link layers can define such mechanisms
as flow and error control. The difference is that while data-link protocols control
traffic on the data link the physical medium connecting two devices the transport
layer controls traffic on the logical link the end-to-end connection of two devices
whose logical connection traverses a series of data links.
26
The application layer corresponds to the OSI session, presentation, and
application layers. Although some routing protocols such as Border Gateway Protocol
(BGP) and routing Information Protocol (RIP) reside at this layer,[2] the most
common services of the application layer provide the interfaces by which user
applications access the network.
A function common to the protocol suite of Figure 1-1 and any other protocol
suite is multiplexing between layers. Many applications might use a service at the
host-to-host layer, and many services at the host-to-host layer might use the internet
layer. Multiple protocol suites (IP, IPX, and AppleTalk, for example) can share a
physical link via common data-link protocols.
27
3. TCP/IP SUITE
TCP manages the transfer of data between peers by encapsulating the data into
segments, which are then carried in IP datagrams through the Internet. TCP attaches a
header as shown in Figure 1 to each segment, carrying parameters necessary for
addressing, flow-control, and other important functions.
28
Figure 1. TCP Header Format
Reliability:
TCP includes mechanisms to recover data that has been damaged, lost, duplicated,
or received out of order. These mechanisms include:
1. Assigning a number to each byte transmitted (the sequence number), and requiring
an acknowledgement (or, “ACK”) from the receiving TCP for all bytes sent. If such
an acknowledgment is not received within a predefined timeout interval, the data is
retransmitted. At the receiver, these sequence numbers are used to reconstruct the
original data. It is possible for segments to be received out of order, should they be
routed through paths having unequal transit times. In addition, consequent to the
varying and potentially unequal delays incurred by different segments, a transmitting
TCP may not receive a timely acknowledgement should a segment be unduly delayed.
In that case, the transmitter would resend this segment - incorrectly inferring that it
had been either lost or damaged, resulting in the reception of duplicated segments by
the receiving TCP. In both of these cases, the segments’ sequence numbers help
ensure that the data reconstructed by the receiving TCP exactly matches that
originally sent. Segments received out of order are correctly reordered, and duplicate
segments are discarded.
29
2. Including a checksum for each segment transmitted. This checksum must be
confirmed
by the receiving TCP. Should a segment’s checksum fail, it is not acknowledged. In
this
case, the sending TCP will eventually resend this segment.
Flow Control:
TCP utilizes a method of flow control called a window. The window is a 16-
bit value transmitted in every segment header indicating the maximum number of
bytes that the sender may transmit before receiving further permission. More on this
later…
Multiplexing:
In a typical host (all systems using TCP/IP attached to the Internet - except
routers), multiple resident applications (e.g. a Web browser, and an e-mail client) may
simultaneously utilize TCP’s services. Within each host, each application is assigned
a port number, thereafter used by TCP as a “handle” to identify the application. Using
this port number, TCP is able to determine which segment goes to which application.
Connections:
30
Precedence and Security:
31
one frame at a time. This is desirable in that it reduces the number of ACK packets the
receiver must send, again improving network efficiency. In this case, the sender may
send several segments without waiting for a confirmatory “ACK” after each segment.
Since the delays encountered by datagrams traversing the internet are highly variable,
requiring a transmitter to wait for the peer to ACK every segment before sending
another would result in a great deal of wasted time. The judicious use of the Window
helps minimize such waste by allowing the transmitter to send as much data as the
peer is capable of accepting, without having to wait for an ACK of the individual
segments. Certainly, the receiver must still “ACK” every segment, but this can be
done in an aggregate manner instead of one at a time.
32
3.3 IP Backgrounder:
3.4 IP addressing
The answer is straightforward. Remember that the Internet is not simply one
big LAN; rather the Internet is defined as a network of networks, or perhaps better
stated, a network of LANs.
If everybody were a node on one great big homogenous network, all running
the same Link layer protocol (Ethernet, for example), there would be no need for a
separate addressing scheme. The fact is however, that many disparate networks exist,
all operating incompatible Link layer protocols. Every host on a LAN is uniquely
identified at the Data Link layer by its Link layer, or MAC address (Media Access
Control). Neighboring nodes on any given LAN communicate with each other based
on this physical address. However, a node on an Ethernet cannot directly
33
communicate with a node on a Token Ring network – and vice versa. Likewise, nodes
speaking ATM, FDDI, etc. are all unintelligible to an Ethernet node. The purpose and
design of the Internet Protocol is to allow nodes sitting on these dissimilar LANs to
internet work. It does so by abstracting their conflicting Link layer protocols,
providing a uniform communication interface for all hosts. This permits hosts residing
on disparate networks to communicate, even
though they may speak a different L3 (Link layer language).
This is where the IP address comes in. Whereas every node on a LAN is
uniquely identified at the Data Link layer by its MAC address, each host on the
Internet is uniquely identified by its IP address. IP addresses (i.e. Ipv4) are 32-bit
numbers, comprising two subfields: a network identifier and a host identifier (also
referred to as the netid and hostid). Figure 3 illustrates this hierarchical addressing
scheme. The netid field of the address uniquely identifies a specific LAN, WAN, or
other group of linked computers, such as one of the networks shown in Figure 2. The
hostid field of the address uniquely identifies a host on the addressed network.
(Actually, the hostid specifies a unique NIC, or Network Interface Card. An
individual computer usually - but not necessarily, has only one such NIC.)
Version 4 of the Internet Protocol (IPv4) has been in use since 1981 and is
slowly being supplanted by IPv6. Version 6 improves upon IPv4 in several areas, not
the least of which is the extension of IP addresses to 128 bits.
34
Figure 3 – Ipv4 Hierarchical Addressing scheme
The IP Address:
The Internet Protocol moves data between hosts in the form of datagrams.
Each datagram is delivered to the address contained in the Destination Address (word
5) of the datagram's header. The Destination Address is a standard 32-bit IP address
that contains sufficient information to uniquely identify a network and a specific host
on that network.
An IP address contains a network part and a host part, but the format of these
parts is not the same in every IP address. The number of address bits used to identify
the network, and the number used to identify the host, vary according to the prefix
length of the address. There are two ways the prefix length is determined: by address
class or by a CIDR address mask. We begin with a discussion of traditional IP address
classes.
35
Address Classes
Originally, the IP address space was divided into a few fixed-length structures
called address classes. The three main address classes are class A, class B, and class
C. By examining the first few bits of an address, IP software can quickly determine
the class, and therefore the structure, of an address. IP follows these rules to
determine the address class:
If the first 2 bits of the address are 1 0, it is a class B network address. The
first 2 bits identify class; the next 14 bits identify the network, and the last 16 bits
identify the host. There are thousands of class B network numbers and each class B
network can contain thousands of hosts.
36
If the first four bits of the address are 1 1 1 1, it is a special reserved address.
These addresses are sometimes called class E addresses, but they don't really refer to
specific networks. No numbers are currently assigned in this range.
[1] Addresses are occasionally written in other formats, e.g., as hexadecimal numbers.
However, the "dot" notation form is the most widely used. Whatever the notation, the
structure of the address is the same.
Less than 128, the address is class A; the first byte is the network number, and the
next three bytes are the host address.
From 128 to 191, the address is class B; the first two bytes identify the network, and
the last two bytes identify the host.
37
From 192 to 223, the address is class C; the first three bytes are the network address,
and the last byte is the host number.
From 224 to 239, the address is multicast. There is no network part. The entire
address identifies a specific multicast group.
Greater than 239, the address is reserved. We can ignore reserved addresses.
The IP address, which provides universal addressing across all of the networks
of the Internet, is one of the great strengths of the TCP/IP protocol suite. However, the
original class structure of the IP address has weaknesses. The TCP/IP designers did
not envision the enormous scale of today's network. When TCP/IP was being
designed, networking was limited to large organizations that could afford substantial
computer systems. The idea of a powerful UNIX system on every desktop did not
exist. At that time, a 32-bit address seemed so large that it was divided into classes to
reduce the processing load on routers, even though dividing the address into classes
sharply reduced the number of host addresses actually available for use. For example,
assigning a large network a single class B address, instead of six class C addresses,
reduced the load on the router because the router needed to keep only one route for
that entire organization. However, an organization that was given the class B address
probably did not have 64,000 computers, so most of the host addresses available to
the organization were never assigned.
38
The class-structured address design was critically strained by the rapid growth
of the Internet. At one point it appeared that all class B addresses might be rapidly
exhausted. [2] To prevent this, a new way of looking at IP addresses without a class
structure was developed.
The source for this prediction is the draft of Super netting: an Address
Assignment and Aggregation Strategy, by V. Fuller, T. Li, J. Yu, and K. Varadhan,
March 1992.
Classless IP Addresses
The rapid depletion of the class B addresses showed that three primary address
classes were not enough: class A was much too large and class C was much too small.
Even a class B address was too large for many networks but was used because it was
better than the alternatives.
The obvious solution to the class B address crisis was to force organizations to
use multiple class C addresses. There were millions of these addresses available and
they were in no immediate danger of depletion. As is often the case, the obvious
solution is not as simple as it may seem. Each class C address requires its own entry
within the routing table. Assigning thousands or millions of class C addresses would
cause the routing table to grow so rapidly that the routers would soon be
overwhelmed. The solution required a new way of assigning addresses and a new way
of looking at addresses.
39
Originally network addresses were assigned in more or less sequential order as
they were requested. This worked fine when the network was small and centralized.
However, it did not take network topology into account. Thus only random chance
would determine if the same intermediate routers would be used to reach network
195.4.12.0 and network 195.4.13.0, which makes it difficult to reduce the size of the
routing table. Addresses can only be aggregated if they are contiguous numbers and
are reachable through the same route. For example, if addresses are contiguous for
one service provider, a single route can be created for that aggregation because that
service provide will have a limited number of routes to the Internet. But if one
network address is in France and the next contiguous address is in Australia, creating
a consolidated route for these addresses does not work.
Evaluating addresses according to the class rules discussed above limits the
length of network numbers to 8, 16, or 24 bits - 1, 2, or 3 bytes. The IP address,
however, is not really byte-oriented. It is 32 contiguous bits. A more flexible way to
interpret the network and host portions of an address is with a bit mask. An address
bit mask works in this way: if a bit is on in the mask, that equivalent bit in the address
is interpreted as a network bit; if a bit in the mask is off, the bit belongs to the host
part of the address. For example, if address 195.4.12.0 is interpreted as a class C
40
address, the first 24 bits are the network number and the last 8 bits are the host
address. The network mask that represents this is 255.255.255.0, 24 bits on and 8 bits
off. The bit mask that is derived from the traditional class structure is called the
default mask or the natural mask. However, with bit masks we are no longer limited
by the address class structure. A mask of 255.255.0.0 can be applied to network
address 195.4.0.0. This mask includes all addresses from 195.4.0.0 to 195.4.255.255
in a single network number. In effect, it creates a network number as large as a class
B network in the class C address space. Using bit masks to create networks larger than
the natural mask is called supernetting, and the use of a mask instead of the address
class to determine the destination network is called Classless Inter-Domain Routing
(CIDR). [3]
3.5 IP fragmentation
41
3.6 Ethernet/TCP/IP Applications
Every receive event is triggered by an interrupt from the Ethernet controller.
This interrupt has the highest priority, so all other activities are stopped immediately.
Responses to the packet received are sent within this interrupt.
Data sent from the Transmission Control Protocol are sent periodically with a
timer interrupt. Every time the timer interrupt occurs, a counter is incremented. This
counter controls when a packet has to be retransmitted. Applications are running all
the time when there is no transmission of packets. This means that when there are
several applications, each application has to be activated in a round robin manner.
Time and memory sharing has to be taken care of by the programmer.
Limitations
Since the software for this web server has been optimized with regard to both
size and speed, there are some limitations to the web server. In the lower layer
protocols (Ethernet - IP), only the functionality required to keep the protocols able to
respond to normal headers is implemented. TCP is simplified, but almost fully
implemented. data, respectively.
• The application data is broken into what TCP considers the best sized chunks to
send. This is totally different from UDP, where each write by the application
generate a UDP datagram of that size. When TCP sends a segment it maintains a
timer, waiting for the other end to acknowledge reception of the segment.
When TCP receives data from the other end of the connection, it sends an
acknowledgment. TCP maintains a checksum on its data header page. This is an end-
to-end checksum whose purpose is to detect any modifications of the data in transit. If
a segment arrives with an invalid checksum, TCP discards it and does not
acknowledge receiving it.TCP also provides flow control. Each end of a TCP
connection has a finite amount of buffer space.
42
TCP/IP Capabilities
43
4.APPLICATION LAYER PROTOCOLS
4.1 Introduction:
44
FIGURE Application using application layer protocols.
While the TCP/IP suite provides the capability to move data between hosts
on the Internet, the application layer protocols provide services that are
meaningful to higher level applications (transporting e-mail, finding resources on
a network, synchronizing time, etc.).
45
A final example is Service Location Protocol (SLP). In this protocol. a
User Agent may request a particular service but instead of communicating
directly to a server, the agent multicasts its request on the network to any one who
is listening. If a Service Agent hears the request and provides the service being
requested, a reply is generated directly to the User Agent. This is a peer-to-peer
architecture in which no central control exists; con trol is instead distributed
throughout the network.
Standard Client/Server
The client/server architecture is by far the most common as the pattern fits
the requirements of most application layer protocols. In this model, a server
exists which serves as the repository for some type of data. Clients connect to the
server to request and then receive data for processing or presentation. From our
prior example of HTTP and SNMP, the topologies differ but the same
relationships exist (see Figure).
46
In the H1TP example, there exists a one-to-many relationship to the
server. In contrast. in the SNMP example there is a one-to-many relation ship to
the client. Each example represents the standard client/server model but serves a
different purpose .•
47
Client Server
Client Server
Another model exists which is used primarily on local area networks and
makes use of broadcast or multicast communication. The Service Lo cation
Protocol can operate with a Directory Agent which will provide the Meta data as
described before (who is in the group). In the absence of a Di rectory Agent, the
clients and servers can use multicast communication to target a specific group of
hosts. Another example is the Dynamic Host Configuration protocol. DHCP uses
broadcast communication to identify the host on the local network that can
provide configuration data.
48
4.5 Application Layer:
At the top of the TCP/IP protocol architecture is the Application Layer. This
layer includes all processes that use the Transport Layer protocols to deliver data.
There are many applications protocols. Most provide user services, and new services
are always being added to this layer.
While HTTP, FTP, SMTP, and telnet are the most widely implemented
TCP/IP applications, you will work with many others as both a user and a system
administrator. Some other commonly used TCP/IP applications are: Domain Name
Service (DNS)
Also called name service, this application maps IP addresses to the names
assigned to network devices. DNS is discussed in detail in this book. Open Shortest
Path First (OSPF)
Routing is central to the way TCP/IP works. OSPF is used by network devices
to exchange routing information. Routing is also a major topic of this book.
Network Filesystem (NFS) This protocol allows files to be shared by various hosts
on the network.
Some protocols, such as telnet and FTP, can only be used if the user has some
knowledge of the network. Other protocols, like OSPF, run without the user even
knowing that they exist. As system administrator, you are aware of all these
applications and all the protocols in the other TCP/IP layers. And you're responsible
for configuring them!
49
4.6 Embedded HTTP server
The use of Web browsers has become the standard method for communi cating
with Managing remote embedded devices. The Web browser is a common
appliance on networked desktops and provides a rich set of functionality for
communication and presentation of data from remote devices.
These days it's commonplace to find HTTP servers on a variety of small embedded
devices. Like e-mail, the Web client is a ubiquitous tool and is used by all Internet users. The
HTTP server provides the means to export information from the device for remote monitoring
as well as permit modification of device parameters via Common Gateway Interface (CGI)
forms. With a little work, the HTTP server can provide the means to display dynamic data
(more on this topic later in this chapter).
The greatest attribute of the HTTP server is its peer, the HTTP client. Using a very
simple tag language called HTML (Hypertext Markup Language), a rich presentation can be
realized. The simplicity of serving simple files to the client results in simple presentation of
possibly complex data.
The HTTP server is a perfect vehicle for the presentation of data from an embedded
system. The HTTP server can be built simply and can reside in very small code space. HTTP
is very simple and therefore supports the simplicity of implementation. Since the Web
browser (HTTP client) pro· vides the rendering of the HTML page to the usee the server need
only serve content through a simple socket server to provide the HTTP server functionality.
50
4.7 Protocol discussion:
General Header
Request line
Request Header
operational headers
CRLF Entity Header
Massage body
Request
Response
51
The HTIP request message is made up of a number of fields. The
request. One setting the stage for the activities that follows. The first element is
'''e method token (in this case, GET)which indicates the method to be performed
on the resource. The resource follows ) , for the G E Trequest
( l i n d e x . h t m lwhid.
indicates the file to be returned. Finally, the HTTP ver sion string is provided to
indicate which version of HTTP the request, understands.
Connection: Keep-Alive
52
The U s e r - A g e nrequest
t header field contains intonation about the User
Agent originating the request. Its most common use is in statistical: collection of
data to identify most common browsers, which present pro tocol violations, etc.
Unfortunately, the field is also used by malicious com panies to mangle or refuse
to serve content to client browsers that come from different developers.
Host: 192.168.1.1:80
The Host request header is the host URL as sped lied by the original re -
quest. Combining this with our resource results in 192.168.1.1: 801 index.html.
Which is (minus the HTTP://protocolheader)theoriginaIURL of the request.
The host can be used by hosts that can be referenced by more than one
fully qualified domain name (such as www.a.com. www.b.com). By looking at
the Host header, the server can identify which host was originally requested and
serve content appropriately.
A c ce p t : i m ag e / gi f , im a ge / x - x b i tm a p , i m ag e / jp e g , i m a g e / pj p e g,
i m ag e / pn g
The Accept request header specifies which media types are acceptable
within the response. In this case, the client browser informs, among other things.
that it can render images of type gif.
Accept-Encoding: gzip
53
The Accept-Encoding request header indicates which encoding methods
are acceptable. In this case, the client indicates that gzip is the only accept able
encoding. If the Accept-Encoding request header were followed by an empty
field, this would indicate that no encoding method was acceptable.
Accept·Language: en
A c c e p t - C h a r s eits:o - 8 8 59 - 1 ,· , u tf · a
The response headers then follow and provide some generic and so~
detailed information about the response. The Date: and Server: headers a:~ self-
explanatory.
54
The ETag: header is an entity tag that can be used (as one service . identify
whether a cached version of a page on a client is the same as 1hz on the server. If
the Tags match, the page is deemed unchanged and is. cached version is used.
The Content Length: header simply represents the number of octets, the
message body. This is useful in systems in which memory is dynamic: . Call
allocated for the body of the message.
The Connection: close header indicates that the server, upon eminent: the
response to the client, will close this socket and that no further requests can be
made through it. Recall the discussion of Keep-Alive in the re quest section.
The final header Content - Type: indicates the type of data that follows . -
the message body. The text/html type identifies our response as text with an
HTML encoding. Finally, the message body is emitted with a single blank line
separation it from the response headers.
We've covered only a few of the many possible headers and variation that can
occur in HTTP, but this sampling should indicate the complex rand flexibility of
HTTP. Using a simple text-based structure for both ~ quests and responses, data
transfer is accommodated as well as feature negotiation.
55
Advanced Uses
While the use of HTTP for retrieval of multimedia files from Web servers the
most common application, HTTP is finding new uses in modern appli cation-layer
protocols. HTTP has evolved into an application transport layer protocol for other
application-layer protocols, such as SOAP (Simple Object Access Protocol) and XML-
RPC (Extensible Markup Language-Re mote Procedure Call). In these applications, the
request includes the object: of interest along with any parameters and the response is the
object or re sult of computation from that remote object. As an extensible transport
protocol, HTTP is finding new uses outside of the hypertext and content distribution
domain.
The Hypertext Transfer Protocol was derived from an earlier idea by T e '_ Nelson
in his book, Literary Machilles
(in which the term "hypertext· " coined). A hypertext link
provided the ability to tie together ideas or relate>: pieces of knowledge. Therefore, ideas
could be linked, allowing a user' identify relations and connections to other pieces of
information. Nelson enveloped this idea in a project called "Xanadu" through the 1960s
and ear 1970s, but due to a lack of product release, his project was finally droppeG..
Using the ideas of Nelson, Tim Berners-Lee of the European Organiza tion for Nuclear
Research (CERN) conceived of hypertext links that spanned the network allowing
computers to be linked not only by net works but also by information. In 1989, Berners-
Lee submitted a proposal that would allow researchers at CERN to gain access to large
amounts of stored information.
This information included reports, documentation, online databases, and other
information that was useful to a geographically dispersed group that desired to
collaborate on a particular subject.
Although useful, the early browsers were limited. In 1994, Marc An dreeson built the first
widely used browser called Mosaic at the National Center for Supercomputing
Applications (at the University of Illinois). This work led to the first browser company-
Netscape.
Since that time, many other browsers have been introduced including Internet
Explorer from Microsoft, Communicator from Netscape, Opera from Opera Software,
and the open source Galeon (available at source forge.net).
56
5. HARDWARE DEVELOPMENT
57
In addition, a variant of the RCM2200 is available. The RCM2300 omits the
Ethernet connectivity but offers a much smaller footprint, one-half the size of the
RCM2200. Another Rabbit Core module can be used to reprogram an RCM2200.
This reprogramming (and debugging) can be done via the Internet using Z-World’s
Rabbit Link network programming gateway or with Ethernet-equipped Rabbit Core
RCM2100 and RCM2200 models using Dynamic C’s Device Mate features. The
RCM2200 is particularly suitable for use as an inexpensive hardware platform for
Dynamic C’s Device Mate features.
58
time clock and the static RAM. Two 26-pin headers bring out the
Rabbit 2000 I/O bus lines, address lines, data lines, parallel ports,
and serial ports.
59
5.2.1 RCM2200 Features
60
5.2.2 Advantages of the RCM2200
61
5.3. HARDWARE SETUP
NOTE: This chapter (and this manual) assume that you have the RCM2200
Development Kit. If you purchased an RCM2200 module by itself, you will have to
adapt the information in this chapter and elsewhere to your test and development
setup.
62
5.3.1 Development Kit Contents
• RCM2200 module with Ethernet port, 256K flash memory, and 128K SRAM.
• RCM2200 Prototyping Board.
• Wall transformer power supply, 12 V DC, 500 mA. (Included only with
Development Kits sold for the North American market. Overseas users will have to
substitute a power supply compatible with local mains power.)
• 10-pin header to DE9 programming cable with integrated level-matching circuitry.
• Dynamic C CD-ROM, with complete product documentation on disk.
• This Getting Started manual.
• Rabbit 2000 Processor Easy Reference poster.
• Registration card.
63
The Prototyping Board is shown below in Figure 2, with its main features
identified.
64
• Regulated Power Supply—The raw DC voltage provided at the POWER IN
jack is routed to a 5 V linear voltage regulator, which provides stable power to the
RCM2200 module and the Prototyping Board. A Shottky diode protects the power
supply against damage from reversed raw power connections.
• Power LED—The power LED lights whenever power is connected to the
Prototyping Board.
65
• Prototyping Area—A generous prototyping area has been provided for the
installation of through-hole components. Vcc (5 V DC) and Ground buses run around
the edge of this area. An area for surface-mount devices is provided to the right of the
through-hole area. (Note that there are SMT device pads on both top and bottom of
the Prototyping Board.) Each SMT pad is connected to a hole designed to accept a 30
AWG solid wire.
The Prototyping Board comes with several unpopulated areas, which may be
filled with components to suit the user’s development needs. After you have
experimented with the sample programs in Section 3.4, you may wish to expand the
board’s capabilities for further experimentation and development. Refer to the
Prototyping Board schematic (090– 0122) for details as necessary.
• Module Extension Headers—The complete pin sets of both the Master and
Slave RabbitCore modules are duplicated at these two sets of headers. Developers can
solder wires directly into the appropriate holes, or, for more flexible development, 26-
pin header strips can be soldered into place. See Figure 1 for the header pinouts.
66
• RS-232—Two 2-wire or one 4-wire RS-232 serial port can be added to the
Prototyping Board by installing a driver IC and four capacitors. The Maxim
MAX232CPE driver chip or a similar device is recommended for the U2. Refer to the
Prototyping Board schematic for additional details.
A 10-pin 0.1-inch spacing header strip can be installed at J6 to permit
connection of a ribbon cable leading to a standard DE-9 serial connector.
All RS-232 port components mount to the underside of the Prototyping Board,
between the Master module connectors.
NOTE: The RS-232 chip, capacitors and header strip are available from electronics
distributors such as Digi-Key.
• Prototyping Board Component Header—Four I/O pins from the module are
hardwired to the Prototyping Board LEDs and switches.
67
5.4.1 Attach Module to Prototyping Board:
Turn the RCM2200 module so that the Ethernet connector end of the module
extends off the Prototyping Board, as shown in Figure 4 below. Align the module
headers J4 ad J5 into sockets J1 and J2 on the Prototyping Board.
68
Connect Ethernet Network Cable
Programming and development can be done with the RCM2200 without
connecting the Ethernet port to a network. However, if you will be running the sample
programs that use the Ethernet capability or will be doing Ethernet-enabled
development, you should connect the RCM2200 module’s Ethernet port at this time.
There are four options for connecting the RCM2200 to a network for development
and runtime purposes. The first two options permit total freedom of action in selecting
network addresses and use of the “network,” as no action can interfere with other
users. We recommend one of these options for initial development.
69
• No LAN — The simplest alternative for desktop development. Connect the
RCM2200’s Ethernet port directly to the PC’s network interface card using an RJ-45
crossover cable. A crossover cable is a special cable that flips some connections
between the two connectors and permits direct connection of two client systems. A
standard RJ-45 network cable will not work for this purpose.
• LAN — Connect the RCM2200’s Ethernet port to an existing LAN, preferably one
to which the development PC is already connected. You will need to obtain IP
addressing information from your network administrator.
• WAN — The RCM2200 is capable of direct connection to the Internet and other
Wide Area Networks, but exceptional care should be used with IP address settings
and all network-related programming and development. We recommend that
development and debugging be done on a local network before connecting a
RabbitCore system to the Internet.
70
5.4.2 Connect Power
When all other connections have been made, you can connect
power to the RCM2200 Prototyping Board.
71
5.5 ADC DESCRIPTION
General Description
72
Key Specifications:
1. Resolution 8 bits
2.Total error ±1⁄4 LSB, ±1⁄2 LSB and ±1 LSB
3.Conversion time 100 µs
This fig. shows the pin diagram of 80x family. It is a dual in line
package and it has 20 pins. the data pins of this IC are connected to the data
pins of the rabbit micro processor.and the fourth pin of the PORT D of the
processor is connected to the RD pin f the ADC. the fifth pin of the PORT D of
the processor is connected to the WR pin f the ADC.the sixth pin of the PORT
D of the processor is connected to the INT pin f the ADC.
Read operation:
Write operation:
74
5.6 Temparature sensor:
LM35
Low cost is assured by trimming and calibration at his wafer level. The
LM35’s low output impedance, linear output, and precise inherent calibration make
interfacing to readout or control circuitry especially easy. It can be used with single
power supplies, or with plus and minus supplies. As it draws only 60 µA from its
supply, it has very low self-heating, less than 0.1°C in still air. The LM35 is rated to
operate over a −55° to +150°C temperature range, while the LM35C is rated for a
−40° to +110°C range (−10° with improved accuracy). The LM35 series is available
packaged in hermetic TO-46 transistor packages, while the LM35C, LM35CA, and
LM35D are also available in the plastic TO-92 transistor package. The LM35D is also
available in an 8-lead surface mount small outline package and a plastic TO-220
package.
75
5.6.2 Features:
76
77
6. SOFTWARE IMPLEMENTATION
/
*********************************************************************
**********
post.c
Z-World, 2000
#class auto
/***********************************
* Configuration *
* ------------- *
* All fields in this section must *
* be altered to match your local *
* network settings. *
***********************************/
/*
#define TCPCONFIG 1
/*
* Web server configuration
*/
/*
* Only one server is needed for a reserved port
*/
#define HTTP_MAXSERVERS 1
#define MAX_TCP_SOCKET_BUFFERS 1
78
/*
* Our web server as seen from the clients.
* This should be the address that the clients (netscape/IE)
* use to access your server. Usually, this is your IP address.
* If you are behind a firewall, though, it might be a port on
* the proxy, that will be forwarded to the Rabbit board. The
* commented out line is an example of such a situation.
*/
#define REDIRECTHOST _PRIMARY_STATIC_IP
//#define REDIRECTHOST "proxy.domain.com:1212"
/********************************
* End of configuration section *
********************************/
/*
#memmap xmem
#use "dcrtcp.lib"
#use "http.lib"
//Hardware connections
//Port A -> ADC DATA
//Port D.3 ->ADC RD
//Port D.4 ->ADC WR
//Port D.5 ->ADC INT
//
#define INT 0
#define RD 1
#define WR 4
#define SET 1
#define CLR 0
79
/* the default for / must be first */
const HttpType http_types[] =
{
{ ".shtml", "text/html", shtml_handler}, // ssi
{ ".html", "text/html", NULL}, // html
{ ".cgi", "", NULL}, // cgi
{ ".gif", "image/gif", NULL}
};
#define MAX_FORMSIZE 64
typedef struct {
char *name;
char value[MAX_FORMSIZE];
} FORMType;
FORMType FORMSpec[1];
int setpoint,ctmp;
char lrtime[40],strsetpoint[10],strctmp[10];
unsigned int d;
void getTemp(void);
/*
* parse the url-encoded POST data into the FORMSpec struct
* (ie: parse 'foo=bar&baz=qux' into the struct
*/
80
if (retval < 0) {
// Error--just bail out
return 1;
}
/*
* Sample submit.cgi function
*/
if(state->length)
{
/* buffer to write out */
if(state->offset < state->length)
{
state->offset += sock_fastwrite(&state->s,
state->buffer + (int)state->offset,
(int)state->length - (int)state->offset);
}
else
{
state->offset = 0;
state->length = 0;
}
}
81
else
{
switch(state->substate)
{
case 0:
strcpy(state->buffer, "HTTP/1.0 200 OK\r\n\r\n");
state->length = strlen(state->buffer);
state->offset = 0;
state->substate++;
break;
case 1:
strcpy(state->buffer,
"<html><head><title>Results</title></head><body>\r\n");
state->length = strlen(state->buffer);
state->substate++;
break;
case 2:
/* init the FORMSpec data */
FORMSpec[0].value[0] = '\0';
state->p = state->buffer;
state->substate++;
break;
case 3:
/* parse the POST information */
if(parse_post(state))
{
sprintf(state->buffer, "<p>SetPoint:
%s<p>\r\n",
FORMSpec[0].value);
// ### Add
strcpy(strsetpoint,FORMSpec[0].value);
setpoint= atoi(strsetpoint);
// ### Add End
state->length = strlen(state->buffer);
state->substate++;
}
else{ }
break;
82
case 4:
strcpy(state->buffer, "<p>Go <a
href=\"/\">home</a></body></html>\r\n");
state->length = strlen(state->buffer);
state->substate++;
break;
default:
state->substate = 0;
return 1;
}
}
return 0;
}
void main()
{
/* 1. Convert the I/O ports. Disable slave port which makes
* Port A an output, and PORT E not have SCS signal.
*/
WrPortI(PDFR,&PDFRShadow,0X0);
WrPortI(PDDDR,& PDDDRShadow,0X18);
83
/* init FORM searchable names - must init ALL FORMSpec structs! */
FORMSpec[0].name = "setpoint";
ctmp=0;
setpoint =0;
sock_init();
http_init();
tcp_reserveport(80);
while (1){
http_handler();
getTemp();
// for(d=5000;d>0;d--);
}
}
void getTemp()
{
struct tm rtc; // time struct
// ADC Read
int val;
BitWrPortI(PDDR,&PDDRShadow,SET,WR);
BitWrPortI(PDDR,&PDDRShadow,CLR,WR);
for(d=5000;d>0;d--); //delay
BitWrPortI(PDDR,&PDDRShadow,SET,WR);
while( BitRdPortI(PDDR,INT) );
BitWrPortI(PDDR,&PDDRShadow,CLR,RD);
//for(d=65000;d>0;d--);//delay
BitWrPortI(PDDR,&PDDRShadow,CLR,RD);
BitWrPortI(PDDR,&PDDRShadow,SET,RD);
ctmp = RdPortI(PADR);
sprintf(strctmp,"%d",ctmp);
84
85