Issue
146 September 2002
Build
Your Own 8051 Web Server
by
Jim Brady
Building your own web
server can be a difficult task, especially if you
proceed without proper direction and the right parts
for the job. Fortunately, Jim has finished an 8051
server and he’s eager to walk you through his project.
With this tutorial, you can avoid common difficulties.
Start
Benchmarking Can't
Be Done? Run-Time Profiling
Memory
Usage
Sources
& PDF
This
article grew out of an experiment to see how hard it
would be to build an 8051 web server and write a minimal
TCP/IP stack. It seems like everything is serving web
pages these days, so why not an 8051? It was not easy,
but it was a fun project. After a few months of studying
ARP and TCP, I had something up and running.
In
this article, I’ll explain how I built an 8051 web server
and describe what I learned along the way. I’ll also
discuss timing and performance. If you want to follow
along, download the source code from the Circuit Cellar
ftp site.
COMPONENTs
I
wanted an 8051 with enough RAM to hold a full-sized
Ethernet frame of 1.5 KB, and with analog inputs so
it could do something useful. The Cygnal parts were
my first choice. The C8051F005 is fast, and it has a
12-bit A/D converter and 2.4 KB of RAM. The C8051F005’s
32-KB flash memory is large enough for a reasonably
sized program plus a few web pages. At first I thought
its lack of a conventional bus would be a problem, but
it turned out to be no problem at all.
The
Cygnal 8051 makes up for being just 8 bits with its
speedy 25-MIPS peak performance. The Ethernet controller’s
RAM adds additional buffering capability for incoming
frames, which is key for allowing the CPU time to process
a frame while more are received. Browsers running on
fast machines can easily fire out two or three Ethernet
frames within a millisecond!
For
the Ethernet controller, I looked at the Realtek RTL8019AS
and the Cirrus Logic CS8900A. The former is inexpensive
and NE2000-compatible, but I’ve used many Cirrus parts
over the years, so I went with the CS8900A.
The
CS8900A’s 4 KB of RAM is enough to hold a number of
incoming frames. As with any Ethernet controller, the
datasheet for it is long and there are many registers
to set up. So, I sat down and read through the data-sheet
to figure out how to talk to it. By looking at a sample
driver, which I downloaded from the Cirrus web site,
I was able to create an interface in C, compile it to
assembly, and then hand-optimize the assembly code.
So
that’s it, almost everything in two chips. I added an
RS-232 port that runs at 115.2 KB for debugging, even
though I found Cygnal’s full-speed emulator to be more
than adequate.