Book Reviews


The Art of Programming Embedded Systems

Reviewed by Mark Gingrich


Mark Gingrich has been employed in the medical device industry for the past nine years. Presently he serves as a software engineer for Baxter Healthcare Corporation's Novacor division. He can be reached at 355 Estabrook St., Apt. 403, San Leandro, CA 94577.

The series of books by Donald Knuth called The Art of Computer Programming may be the archetype of its genre. So I approach recent epics leading with "The Art of" title with elevated expectation. The Art of Programming Embedded Systems is among the latest (though unrelated to Knuth's trilogy). Its author, Jack Ganssle, checks in with good credentials: a contributing editor for Embedded Systems Programming magazine, a designer and purveyor of in-circuit emulators, and a veteran practitioner of said "art."

But why a book on coding embedded systems? Perhaps because the topic is so woefully treated in the engineering/computer science curricula. More often it's a trade learned on the job — the hard way — at no small expense to our employers. And many of us drift into this sea having cast off on the purely hardware or purely software oceans. The luckiest benefit from a mentor helping to steer around obstacles: how to coerce the compiler to accept writeable variables distinct from RAM; how to debug optimized code sans print statements; how to configure the emulator to trap bugs which occur only during neap tides on Groundhog Day; how to do this; how not to do that. Don't have a mentor as such? Well, then, this book may be a reasonable alternative.

Only don't expect a tutorial from square zero. Gannsle's approach is more casual — rather like talking shop with colleagues. He assumes that you've already served your software apprenticeship; now your goal is to fill those gaps of wisdom which have postponed your transition to true embedded systems programming enlightenment. The parallel path to this state of being entails time-consuming and costly mistakes (the euphemism is called "experience").

And experience is seldom acquired in each and every aspect of embedded design. For example, chief among my own gaps of wisdom is one in memory management techniques, having never employed bank switching on a project. Ganssle comes through in chapter six with a clear depiction of the camouflaged snake pits lurking in this area. Reading this chapter made it plainly apparent that I would have pathetically underestimated the time required to implement a bank-switching scheme.

Likewise, a good introduction to real-time operating systems is found in chapter nine. Although not the be-all, end-all word on the subject, it's an appropriate diving-in point for the novice before swimming through the voluminous sales literature and spec sheets from the umpteen RTOS-to-go vendors. Of particular value is the small — but functional — real-time executive supplied in source listing form.

Ever need a lone transcendental function in your system? Instead of calling the compiler's bloated, glacier-speed floating-point math library routine (which returns a result with three digits of precision more than you require), why not roll your own? Ganssle shows how — illustrated with C — in chapter seven.

In addition, there are chapters on interrupt management; on signal smoothing and curve fitting (especially intriguing is the Savitsky and Golay technique); on software design which allows for civilized debugging; on designing to permit simplified production test — always guaranteed to endear you with the harried, under-appreciated manufacturing folk.

And interspersed with the lucid, here's-the-way-it-is writing style are snippets of reality — flashbacks from Ganssle's eventful past:

"It always seems that just before a demo everything falls apart. After a late night of removing the final bugs from microcontroller-based design, I unplugged the emulator and installed the computer chip. On power up the unit did nothing — it was completely dead. Fortunately the code had a simple test routine that blinked an LED before any other initialization took place. Since the LED didn't blink, I knew immediately that the code was not starting and indeed found that a floating DMA request line was keeping the processor idle. The emulator's slightly different DC characteristics masked the problem during weeks of code development."

Such anecdotal digressions in the prose are welcome. They add realism. And they underscore that the proffered advice is not rarefied academic theory; these are eyewitness war stories from the front.

Occasionally, too, Ganssle opines on the softer issues of software development: programming style and professional improvement. And he confronts business issues so often avoided like the plague by the technical staff. This holistic approach is commendable. The still-too-pervasive image of "proglodytes" (wearing pocket protectors, of course) hacking away in the back room, oblivious to the rest of the world, has been a hindrance to our collective professional advancement. There is a bottom line, and Ganssle steps back to point out our role and responsibilities within the big picture.

Reading widely is among our responsibilities, we're admonished. So Gannsle supplies an eclectic bibliography: from techy Intel application notes to Alvin Toffler's Powershift. (Though I would have preferred a more exhaustive reference section — pointers to the richest embedded systems lore. Indigenous software types, for instance, may need to "speak" electronic more proficiently; another "art of" book, The Art of Electronics, by Horowitz and Hill, is an appropriate text. Those of the hardware stripe would benefit from, say, Kernighan and Plauger's The Elements of Programming Style.) An appendix with recommended periodicals for the cognizant embedded programmer is also offered. (The C Users Journal makes the list; but somehow Dr. Dobb's Journal is omitted, a conspicuous oversight considering it is cited elsewhere in the book.)

Be advised, however, that the "art" presented is not the state of the art. Embedded systems are described as they've existed over the past few years, with 4-, 8-, and 16-bit processors. There are no visits from the ghost of Embedded-Programming-Yet-To-Be. One must look elsewhere for coverage of fuzzy logic, neural nets, and DSP chips as embedded controllers.

Mind you, I heartily recommend this book, but there are a few too many warts, most of which should have been removed with scrupulous copy editing. On page 152 the definitions of accuracy and precision are confused, as is the described behavior of the sine function, and the constant pi/2 is termed a "round" number. (Ironically, these blunders occur on a page with the subhead "Errors.") Elsewhere, the repeated misspelling of "kernel," the missing arrowhead in the state diagram in Figure 3.2, and the interchanged x-y coordinates in Figure 7.4 are annoying flaws. The state diagram in Figure 9.1 is simple, but it could have been drawn without the confusion-adding crossed lines.

Then there are the source listings. Yes, there's enough source in this book (but, alas, no companion disk) to satisfy your minimum daily requirement of real code: much of it in C, a few in sundry assembly languages, and one listing in Basic. But the art of software book publishing demands faithful reproduction of listings. Just a cursory scan caught a missing right parenthesis in the for loop on page 31; the phex routine on page 95 lost a curly bracket somewhere; page 96 contains a commented-out source line, which is somewhat disconcerting. These typos along with the schizophrenic indentation style hint of manually-typeset code listings — a dangerous practice. My overall impression: Academic Press skimped on (or rushed) the proofreading and the illustrations.

These are nitpicking complaints. I'm being a bit harsh because such a valuable work deserves better handling. And pricey books with lofty titles justifiably receive more intense scrutiny. But I'll apply a more pragmatic rule of thumb: If a book's cost and the invested reading time is more than compensated by the added quality and productivity of my work, or to the improved quality of my company's product, it's an unequivocable bargain. Without question, The Art of Programming Embedded Systems hits this critical breakpoint.

Title: The Art of Programming Embedded Systems
Author: Jack G. Ganssle
Publisher: Academic Press
Price: $49.00
ISBN: 0-12-274880-8