Page 95 - The Art of Designing Embedded Systems
P. 95

82  THE ART OF  DESIGNING EMBEDDED SYSTEMS























        FIGURE 4-10  An idle loop quickly toggles the debug bit. . . until there’s
       something to do!


       ready to ship. Wrong. Hardware engineers stress their creations by run-
        ning them over a temperature range. We should do the same, instrument-
        ing our code or otherwise using performance-measuring tools, to be quite
        sure the system has sufficient margins. It’s trivial to take quite accurate
        performance data.


            The RTOS
            Whenever  an application manages multiple processes  and devices,
        whenever one handles a variety of activities, an RTOS is a logical tool that
       lets us simplify the code and help it run better.
            Consider the difficulty of building, say, a printer. Without an RTOS,
       one monolithic hunk of code would have to manage the door switches and
       paper feeding and communications and the print engine-all  at the same
       time. Add an RTOS, and individual tasks each manage one of these activ-
       ities; except for some status information, no task needs  to know  much
       about what any other one is doing. In this case the RTOS allows us to par-
       tition our code in the time domain (each of these activities is running con-
       currently) and procedurally (each task handles one thing).
            An important truism of software engineering is that code complex-
       ity-and   thus development time-grows  much faster than program size.
       Any  mechanism that  segments the  code  into  many  small independent
       pieces reduces the complexity; after all, this is why we write with lots of
       functions and not one huge main() program. Clever partitioning yields bet-
   90   91   92   93   94   95   96   97   98   99   100