1.1 History of this Book and What You’ll Get From Reading It
Over the course of roughly a year, after completing my first book, I resurrected an old pet project of building an autonomous submarine (referred to as the E-2 project) with certain fairly challenging functionality requirements. In the course of developing this idea, I spent many hours on the Internet and elsewhere, researching techniques for rapid development of various electromechanical control systems and platforms to run fairly complex signal-processing algorithms. Although there are, of course, thousands of useful projects and snippets of information to be obtained from the Internet and books on hobbyist robotics, I found that nobody else seemed to have my exact priorities. In particular, there is apparently no single reference that gathers together at least introductory solutions to all the embedded design issues that affected my project: a need to use low-cost (open-source) tools and operating systems, a requirement for several features with fairly hard real-time requirements, and a desire to use cheap, off-the-shelf consumer grade components wherever possible. Available resources on many topics concentrate either on very expensive off-the-shelf industrial components, or on tightly constrained systems built around a single microcontroller, with delicately optimized, nonportable code to control peripherals—and a very limited range of peripheral support, at that. These latter system design restrictions are unavoidable when you’re working to tight power requirements, space constraints, or a rock-bottom bill of material (BOM) cost, but it’s an inordinate amount of effort to build and tune such systems for a one-off project or a prototype. Furthermore, learning all the details required to assemble such a system is an enormous task; it’s easy to get lost in fine-tuning details without ever managing to field a complete, working system. Irritatingly, many of the tweaks and most of the careful planning you do to get that system operational will have to be thrown away if you move into actual production, or if you need to build some more units with slightly different components.
What I was searching for while developing the E-2 project was a way to build various hard real-time modules (sensors and actuators) that could easily and cheaply be interfaced to a general-purpose computer running Linux. The Linux box served as a testbed for algorithms which would later be ported down into a smaller, cooler, more power-efficient processing module of some kind. I needed a solid basis of known-good code and techniques so that I could strike out from that point and build my own customized system. I also wanted a simple up-and-running guide to building embedded Linux distributions. For the initial, nonfieldable prototype of my submarine, I didn’t have an exact idea of how much CPU horsepower I would need in the final version—so I didn’t want to get tied to a specific microcontroller architecture, nor did I want to get bogged down in trying to tweak and tune many real-time tasks on a single microcontroller. I also wanted to use a few peripherals—such as cameras—which are easiest interfaced through a general-purpose operating system.
These requirements may sound a chord with your own working life. Chances are you’ve encountered situations where it would be useful to automate some long-term data-gathering experiment or create a simple automated controller for a programming, manufacturing or other task. In this vein, three other instances where I have applied the techniques in this book are:
The development of a range of successful (commercially-fielded) networked multimedia appliances, designed for unattended advertising and art-gallery applications.
The development of specialized, almost wholly automatic mechanical failure testing apparatus for certain consumer electronics articles.
Construction of an automatic high-speed datalogger that monitors a radio link and extracts DTMF messages targeted at specific receivers.
The second item above is of particular interest, because it demonstrates nicely how this book can be of practical value in process control and testing applications. During 2002, I briefly worked for a small division of a multinational company whose major focus was household and office plasticware. It was most instructive to examine their automated test fixtures—proprietary systems—and compare the cost and setup complexity of these fixtures with the relatively low cost and setup time of a simple Linux-based SBC controlling the same pneumatic actuators and sensors. Clearly, there is an under-exploited market for low-cost test systems of this type. The proprietary systems in use at this particular facility cost almost $20,000 for a half-dozen actuators and the associated PLCs, plus uncounted hours of setup time1. The control software for these devices was specialized and not well-understood; in fact, most of this equipment was standing idle because the people who originally configured it had left the company. By way of contrast, the same tasks could easily be accomplished with a regular PC costing a mere few hundred dollars, plus perhaps $200 per actuator for the associated pneumatics. More importantly, the control software for such a system is a simple C program easily understood and adaptable by any competent computer science or electronic engineering major; there were several candidates readily available in the company lab.
Due to the nature of the research which led to this book’s inception, I have included a sprinkling of naval details within the text, not all of which are directly relevant to the embedded engineer. If this material is not of interest, you can safely ignore it without compromising your understanding of the remaining text in any way. The reason this information is included alongside the “pure” embedded development discussion is principally to illustrate the real-world requirements and thinking that led to various design decisions in the E-2 project. Engineering is not theoretical science; it is an applied discipline, and it is with this in mind that I use specific examples to illustrate theoretical points.
You should also note that some of the opinions expressed in this book, if not exactly controversial (except by Usenet standards—everything on Usenet is controversial!), are at least arguable; for example, the choice of AVR as my real-time control platform. For this reason, I have provided additional justification for the decisions I have made in this text. This additional explanation should demonstrate the reasons I had for choosing specific paths, but it’s expressly not designed to proselytize the AVR to people who have experience with, and prefer, another architecture. Again, this “bonus material” is not critical to your understanding of the basic concepts presented here, and you can safely skip it if you wish.
Also keep in mind that this book is intentionally not a “bible.” It is not an exhaustive coverage of every single nuance of the topics covered; such a work would span several shelves. The primary goal of this book is to describe and illustrate a simple, modular, inexpensive methodology for implementing complex embedded systems, and to present some ready-to-use modules for the reader to adapt to his or her own projects. The particular emphasis is on realizing end-to-end solutions using low-cost development hardware and free software tools. By the time you reach the last few pages, hopefully you should have the following:
A functional understanding of the critical “under-the-hood” details required to bootstrap Linux on x86 plat...