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

40  THE  ART OF  DESIGNING EMBEDDED SYSTEMS

                           Among the great money-makers for ICE vendors are complex hard-
                       ware breakpoints,  used  most often  for chasing  down errant  changes to
                       global variables. If you like globals, figure on anteing up plenty for tools.
                           There’s yet one more waffle on my anti-global crusade: device han-
                       dlers sometimes must share data stored in common buffers and the like.
                       We do not write a serial receive routine in isolation. It’s part of a fabric of
                       handlers that include input, output, initialization, and one or more interrupt
                       service routines (ISRs).
                           This implies something profound about module design. Write pro-
                       grams with lots and lots of modules! Don’t lump code into a handful of
                       5000-line files. Assign one module per logical function: for example, have
                       a single module (file) that includes all of the serial device handlers-nd
                       nothing else. Structurally it looks like:
                                             public      serial-in,  serial-out,
                           serial-init
                            serial-in:           code
                            serial-out:          code
                            serial-init:         code
                            serial-isr:          code
                                             private  data
                           buffer:       data
                            status  :    data
                           The data items are filescopics-global  to the module but private to
                       the rest of the system. I feel this tradeoff is needed in embedded systems
                       to reduce performance penalties of the noble but not-always-possible anti-
                       global tack.

                            Partit;on with CPUS

                           Given that firmware is the most expensive thing in the universe, given
                       that the code will always be the most expensive part of the development ef-
                       fort, given that we’re under fire to deliver more complex systems to market
                       faster than ever, it makes sense in all but the most cost-sensitive systems to
                       have the hardware design fall out of software considerations. That is, design
                       the hardware in a way to minimize the cost of software development.
                           It’s time  to reverse  the conventional  design  approach, and  let the
                       sofware drive the hardware design.
                           Consider the typical modern embedded system. A single CPU has the
                       metaphorical role of a mainframe computer: it handles all of the inputs and
                       outputs, runs  application  code, and  services  interrupts.  Like the  main-
   48   49   50   51   52   53   54   55   56   57   58