Book Reviews


µC/OS, The Real-Time Kernel

Reviewed by Mark Gingrich


Mark Gingrich spurned a rewarding career in computer maintenance for a monastic, bit-twiddling existence in the medical device industry. Now, after nine years, he's gone back to school to learn how things should have been done. He can be reached at 355 Estabrook Street, Apt. 403, San Leandro, CA 94577.

Operating systems rank among the heftiest computer programs around. To illustrate, IBM expended 5,000 not-so-mythical programmer years to design, code, and debug their venerated, 1960s-vintage OS/360. You may find these statistics intimidating if you are new to programming or operating systems. How would you begin to learn about operating systems today? What OS would you study?

Why not start small — perhaps with something more bitesized? From the menu of operating system sandwiches, many piled high with features and supplemental utilities, programmers need only select the basic ingredients. A "poor boy" OS — a so-called "kernel" — will do just fine, thank you...and hold the mayo.

Jean Labrosse, a practicing software engineer and real-time operating systems expert, has prepared just such a kernel. In the tradition of Richard Stallman and his GNU C compiler effort, Labrosse has published the code and documentation for a generic pocket-sized real-time kernel. Dubbed µC/OS (Please, it's pronounced "micro-C O S," not "mucous."), this kernel is a simple — but by no means wimpy — preemptive and deterministic task switcher, with message queues, mailboxes, semaphores, and a priority scheduling scheme. All in all, I consider this a remarkable bargain: full source code and documentation — in book form — for less than a thirtieth of a kilobuck.

So what's the catch? I looked really hard, but I couldn't find one.

Certainly µC/OS's publishers have not shackled it with unreasonable usage restrictions. Here, quoted in full, are the restrictions:

The code in this book is protected by copyright. You may either transcribe the code to machine readable form or purchase the companion disk for your own personal use. You do not need a license to use this code in your application, if your application is distributed in object format. You should, however, indicate in your product literature that you are using µC/OS, The Real-Time Kernel. If you distribute µC/OS in source code, you must obtain a license.

Notice there's no mention of per-unit royalties, first-born children, etc. What could be more civilized?

µC/OS (the book) ably describes µC/OS (the program) — a just-the-facts-ma'am kind of a read. The book begins with a brief overview of terminology and the raison d'etre for Real-Time Operating Systems. In successive chapters, the book delves into specifics: these chapters cover µC/OS's kernel structure, how µC/OS processes interrupts, how it coordinates and synchronizes tasks, and how it performs initialization. Each section is replete with source code clippings, so you can follow along.

The chapters I just described make up the first third of the book; the next third is primarily a user's reference. The reference features every µC/OS function call on its own page, in fine UNIX-manual style, with — most important — usage examples, plus a listing of maximal 80186 execution and interrupt lock-out times. Finally, this section describes and lists two refreshingly simple, PC-runnable programs, which invoke several of the same kernel functions.

The final third of the book is a collage of appendices. These appendices present the unabridged source code. In addition, in this section Labrosse presents the rationale for his coding style, and unexpectedly tenders two handy utilities: one for printing listings, and one for speeding access to project directories.

If µC/OS whets your appetite for something more ambitious, you will particularly welcome the appendix that serves as a shopper's guide to RTOS vendors. However, I'm afraid this item will become rapidly dated. The rough-and-tumble RTOS market is causing many changes in product offerings, and this will affect kernel supplier survival rates. (In fact, I noted that the address of one vendor, Wind River Systems, had already changed from that shown.)

Code as a Learning Tool

A RTOS coded for maximum efficiency is often hard to read (typically, it's in assembly language); fortunately for us OS neophytes, LaBrosse has written about 90 percent of the µC/OS source in ANSI C; the few lines of assembly in µC/OS perform those operations specific to the type of microprocessor installed (mostly stack and register loads during a context switch). Yet, the resultant performance isn't bad (interrupt response is less than 750 80186 clock cycles under the small memory model).

Of course, developers of time-critical applications should probably consult a commercial vendor (who can also provide project-saving phone support); but for applications that can miss a task deadline without catastrophic consequences (as in a "soft" real-time system) µC/OS may fill the bill nicely.

Minor Caveats

While indeed a bargain, this book is not unique. Douglas Comer's Operating System Design: The XINU Approach and Andrew Tanenbaum's Operating Systems: Design and Implementation are two other books of a similar flavor. And like Labrosse, these authors walk you through the basic OS operations, speaking fluently in the C dialect. Each of the latter strives to recreate a low-budget version of UNIX, complete with file system and internetworking capabilities. Labrosse instead sticks to a plain-vanilla kernel, with emphasis on real-time response.

As often happens, a few typos, none particularly egregious, made it through to the final printing. However, a couple of goofs (much bigger than mere typos) might confuse some readers: The listing on p. 131 shows function OSTimeDly returning a value — it's actually a void function; and the text references to Figures 3.1 and 3.2 are swapped.

Potential Readers

Instructors who teach operating systems classes might consider µC/OS, The Real-Time Kernel as a supplemental resource. This book would add value to one of those pedantically broad, touch-on-every-OS-concept-ever-imagined textbooks, which never seem to supply adequate detail to build anything practical. In particular, µC/OS would inject concreteness into the study of an OS kernel. Students could make good use of µC/OS in projects, especially when they don't have time to reinvent a complete kernel within one busy semester.

The wonderful world of OS may appear a mysterious and alien land to the uninitiated. µC/OS offers a marvelous way to begin the tour. After reading this book, those OS buzzwords will seem much less foreign. "Kernel" will immediately bring to mind preemption, critical sections, mutual exclusion, semaphores — not a bewhiskered chicken fryer from Kentucky.

Conclusion

In the software development business, perhaps we programmers don't soil our fingernails often enough. Here's a justifiable excuse to roll up the sleeves and poke around a program's innards to comprehend the ghost in the machine. Jean Labrosse has provided a clean, well-documented, no-nonsense, and inexpensive real-time OS for us to dissect and re-assemble — an OS Heathkit of sorts. Whether you are just curious about OS, or want to jump right in and build your own, µC/OS, The Real-Time Kernel merits a healthy time slice of your reading task.

Title: µC/OS, The Real-Time Kernel
Author: Jean J. Labrosse
Publisher: R & D Publications, Inc. 1-913-841-1631
Price: $29.95 (Companion disk an additional $24.95)
ISBN: 0-13-031352-1