Table Of ContentDesigning Embedded Internet Devices
[This is a blank page.]
[This page intentionally left blank.]
Designing Embedded Internet Devices
by Dan Eisenreich
Brian DeMuth
An imprint of Elsevier Science
Amsterdam Boston London New York Oxford Paris
San Diego San Francisco Singapore Sydney Tokyo
Newnes is an imprint of Elsevier Science.
Copyright © 2003, Elsevier Science (USA). All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, electronic, mechanical, photocopying,
recording, or otherwise, without the prior written permission of the publisher.
Recognizing the importance of preserving what has been written, Elsevier
Science prints its books on acid-free paper whenever possible.
Library of Congress Cataloging-in-Publication Data
ISBN: 1-878707-98-1
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library.
The publisher offers special discounts on bulk orders of this book.
For information, please contact:
Manager of Special Sales
Elsevier Science
200 Wheeler Road
Burlington, MA 01803
Tel: 781-313-4700
Fax: 781-313-4882
For information on all Newnes publications available, contact our World Wide
Web home page at: http://www.newnespress.com
10 9 8 7 6 5 4 3 2 1
Printed in the United States of America
iv
Acknowledgments
We would like to gratefully acknowledge
… the fine folks at Dallas Semiconductor for squeezing such a
capable JVM on an 8-bit microcontroller.
… all of the hard work proofreading and organizing the draft for
the book by the folks at Newnes (Kelly, Carol, Harry).
Dedication
Dan
To Keisha and Emily
Brian
To Linda, whose love and support made this possible.
....................................A...c..k..n..o..w...l.e..d..g.ments
...............................................................D...e..d..ication
W.h..a..t.(cid:144)s.. .o...n.. .t.h..e.. .C...D..-..R..O...M...?..........
1 Introduction................................................................ 1
Why should you read this book?............................................... 1
What this book will do for you ................................................... 2
How this book is laid out ........................................................... 2
How to get the most out of this book......................................... 3
What you should already know ................................................. 4
2 Computer Networks................................................... 5
A really simple network............................................................. 6
A small office and home network .............................................. 7
Connecting a LAN to the Internet (or a LAN, MAN, WAN)........ 8
Broadband connection............................................................................. 8
Alternate broadband connection.............................................................. 9
Dial up connection................................................................................... 9
The 10/100 Base- T cable......................................................... 11
Ethernet address....................................................................... 13
Internet addresses .................................................................... 14
Domain names.......................................................................... 14
Network classes........................................................................ 14
Subnetworks ............................................................................. 16
DHCP........................................................................................ 17
Protocols ................................................................................... 18
Client/server.............................................................................. 20
3 Java Essentials for Embedded Networked
Devices .......................................................................... 25
For Windows............................................................................. 26
Windows 95/98........................................................................................ 26
Windows 2000, Windows NT, Windows XP............................................. 26
For Linux ................................................................................... 28
For Windows............................................................................. 31
Windows 95/98........................................................................................ 32
Windows 2000, Windows NT, Windows XP............................................. 32
For Linux ................................................................................... 34
Classes, objects, methods, constructors................................... 37
OOP diagrams .......................................................................... 39
Inheritance ................................................................................ 41
Errors, exceptions, and exception handling .............................. 51
Network Programming .............................................................. 59
Reading and writing to a socket (a simple client)..................................... 60
Reading and writing to a socket (a simple server)................................... 63
Reading and writing to a socket (a slightly less simple server)................ 67
Programming with URLs.......................................................................... 73
Threads..................................................................................... 74
Implementing threads by extending the thread class............................... 75
Implementing threads by implementing the runnable interface............... 82
Serial ports................................................................................ 85
4 Overview of Embedded Networked Devices ........... 93
5 Getting Started with TINI........................................... 101
The TINI SIMM.......................................................................... 102
The socket board ...................................................................... 103
Get your TINI running................................................................ 105
For Windows............................................................................. 107
Windows 95/98.......................................................................... 107
Windows 2000, Windows NT, Windows XP.............................. 108
Linux.......................................................................................... 108
Running JavaKit........................................................................ 109
Your first TINI program.............................................................. 114
Windows.................................................................................... 117
Windows 95/98........................................................................................ 118
Windows 2000, Windows NT, Windows XP............................................. 118
Linux.......................................................................................... 119
Hardware................................................................................... 119
First 1-Wire program ................................................................. 120
Compile from Windows, run from Windows .............................. 122
Compile from Windows, run from TINI...................................... 122
Compile from Linux, run from Linux.......................................... 124
Compile from Linux, run from TINI............................................ 124
6 The TINI Hardware ..................................................... 127
Versions .................................................................................... 128
A high-level look at TINI............................................................ 129
What(cid:144)s in a TINI stick? ............................................................................. 129
A quick look at how it works..................................................................... 130
The SIMM (Single Inline Memory Module) edge connector...... 130
The processor and oscillator module........................................ 133
Programming example: the watchdog timer............................................ 137
A few words about the TINI address space............................................. 139
The TINI memory map............................................................................. 140
Flash ROM............................................................................................... 141
Static RAM............................................................................................... 143
The RAM nonvolatizer............................................................... 144
The CPU Reset circuitry............................................................ 146
The internal 1-Wire net.............................................................. 147
The external 1-Wire I/O, or iButton interface............................. 149
The RS232 interface ................................................................. 150
The real-time clock.................................................................... 151
Programming example: using the real-time clock..................... 153
The Ethernet controller.............................................................. 155
The I2C interface....................................................................... 157
The CAN interface..................................................................... 158
What(cid:144)s in an E20 socket board? ............................................... 158
The E20 in greater detail........................................................... 160
The serial interface and DTR reset enable.............................................. 160
The external 1-Wire interface................................................................... 162
The Ethernet interface............................................................................. 162
The CAN interface................................................................................... 163
The regulated power supply..................................................................... 164
Additional FLASH..................................................................................... 164
Support for Serial2 and Serial3................................................................ 167
External interrupt selection circuitry......................................................... 168
Internal 1-Wire interface........................................................................... 169
The parallel IO section............................................................................. 169
The LCD interface from earlier versions.................................................. 172
Vinculum Technologies Group.................................................. 173
Systronix ................................................................................... 174
Additional products and vendors............................................... 174
Making a custom TINI socket.................................................... 175
7 The TINI Software....................................................... 177
Terminal .................................................................................... 180
Starting slush ............................................................................ 191
Slush commands....................................................................... 193
Managing programs and files................................................................... 194
Managing users....................................................................................... 196
Managing connectivity............................................................................. 196
Miscellaneous slush commands.............................................................. 198
Optional slush commands........................................................................ 198
Slush files and environment...................................................... 199
passwd..................................................................................................... 199
startup file................................................................................................ 200
tininet file.................................................................................................. 201
User Home............................................................................................... 201
login file.................................................................................................... 202
Servers in slush....................................................................................... 202
Tips for your programs.............................................................. 205
Threads.................................................................................................... 205
Memory.................................................................................................... 205
Networking............................................................................................... 206
Good ideas............................................................................................... 206
Java classes/methods (API 1.02d).......................................................... 206
File system............................................................................................... 207
TINIConvertor............................................................................ 208
BuildDependency...................................................................... 209
A TINI example ......................................................................... 211
Modifying slush ......................................................................... 219
Recompiling Slush................................................................................... 219
Modifying the slush command set............................................................ 224
Adding optional commands to slush........................................................ 226
Adding new commands to slush.............................................................. 227
Utilities....................................................................................... 232
Using DOS batch files.............................................................................. 232
Using FTP................................................................................................ 235
Using the DOS command window........................................................... 236
GNUmake ................................................................................. 237
Linux.......................................................................................... 237
Windows.................................................................................... 237
JEdit.......................................................................................... 240
TiniHttpServer........................................................................... 242
TiniInstaller................................................................................ 242
TINIAnt...................................................................................... 242
8 Enhancing TINI........................................................... 245
Adding data bus buffer.............................................................. 256
The address decoder ................................................................ 256
Adding an LCD display.............................................................. 260
Adding buttons.......................................................................... 273
Adding a keypad ....................................................................... 280
Add an LED display................................................................... 286
9 TINI Serial and Parallel I/O ........................................ 295
A few serial port details............................................................. 296
The UART................................................................................................ 296
Flow control, parity, stop bits, data format............................................... 296
Serial line voltages................................................................................... 298
Cables and connectors............................................................................ 300
TINI serial ports......................................................................... 305
Serial0...................................................................................................... 307
Serial1...................................................................................................... 309
Serial2, 3.................................................................................................. 310
Serial communication software (API)........................................ 311
A serial example........................................................................ 313
Serial0...................................................................................................... 313
Serial1...................................................................................................... 321
Serial2 and serial3................................................................................... 328
A parting word on serial ports ................................................... 330
TINI parallel ports...................................................................... 332
Port control............................................................................................... 332
Parallel I/O buffers/drivers....................................................................... 332
Parallel communication software (API)..................................... 334
A simple parallel device example.............................................. 337
Another example....................................................................... 341
Other ways of handling parallel I/O........................................... 344
10 Wire Basics for TINI................................................. 345
Wire Reset Details .................................................................... 350
Wire Data Communication Details............................................ 350
The Read ROM command........................................................ 354
The Search ROM command ..................................................... 356
Match ROM............................................................................... 358
Skip ROM.................................................................................. 358
Memory commands................................................................... 359
DS2405 Addressable Switch ROM commands......................... 363
The DS2405 Match ROM command......................................... 364
The DS2405 Search ROM command ....................................... 364
The Active Only Search ROM command................................................. 364
DS1920 ROM commands......................................................... 367
The DS1920 Alarm Search command ...................................... 367
Communication ports on the PC ............................................... 371
The RS232 or serial (COM) ports............................................................ 372
The parallel or printer port........................................................................ 375
PC universal serial bus, or USB............................................................... 377
Cables and connectors............................................................................ 378
The 1-Wire Java API, TMEX drivers, and these mysterious
things called port adapters........................................................ 380
Example: finding all 1-Wire devices on a specific port.............. 382
The DSPortAdapter class........................................................................ 383
The OneWireAccessProvider class......................................................... 384
The Enumeration class............................................................................ 385
The OneWireContainer class................................................................... 385
Example: Finding devices by family on a specific port.............. 394
Example: Identifying all software port adapters present ........... 396
Example: Finding the default adapter ....................................... 398
Example: Finding all 1-Wire devices on any port...................... 400
Example: Controlling the DS2405 addressable switch ............. 401
The OneWireContainer05 class............................................................... 402
Example: Measuring temperature with a DS1920
temperature iButton................................................................... 411
The OneWireContainer10 class............................................................... 411
The TINI external 1-Wire bus.................................................... 419
The TINI internal 1-Wire bus..................................................... 420
TINI port adapter objects........................................................... 420
The TINI API ............................................................................. 421
Example: A Java program for TINI that identifies port adapters.............. 421
Example: Determining the default port on TINI........................................ 421
Example: Determining the ROM ID for all 1-Wire devices attached to
TINI.......................................................................................................... 422
Example: Another way of determining the ROM ID for all 1-
Wire devices attached to TINI................................................... 425
Example: Yet another way of determining the ROM ID for
all 1- Wire devices attached to TINI.......................................... 428
Example: Controlling a DS2405 addressable switch from
TINI ........................................................................................... 430
Example: Using a temperature iButton with TINI...................... 430
11 The I2C Bus.............................................................. 433
The master/slave concept in I2C............................................... 434
The I2C data format .................................................................. 435