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

Real  Time Means Right Now!  59
                    to the data), consider using another task or ISR, one driven via a timer
                    that interrupts at the rate you consider “real time,” to process the queued
                    data.
                         An  analogous  rule to keeping  ISRs short is to keep them  simple.
                    Complex ISRs lead to debugging nightmares, especially when the tools
                    may  be  somewhat less  than  adequate.  Debugging  ISRs  with  a  simple
                    BDM-like debugger is going to hurt-bad.  Keep the code so trivial there’s
                    little chance of error.
                         An old rule of software design is to use one function (in this case the
                    serial ISR) to do one thing. A real-time analogy is to do things only when
                    they need to ger done, not at some arbitrary rate.
                         Reenable interrupts as soon as practical in the ISR. Do the hardware-
                    critical and non-reentrant things up front, then execute the interrupt enable
                    instruction. Give other ISRs a fighting chance to do their thing.
                         Fill all of your unused interrupt vectors with a pointer to a null rou-
                    tine (Figure 4-4). During debug, ulwwys set a breakpoint on this routine.
                    Any spurious interrupt, due to hardware problems or misprogrammed pe-
                    ripherals, will then stop the code cleanly and immediately, giving you a
                    prayer of finding the problem in minutes instead of weeks.


                         Hardwarre Issues

                         Lousy hardware design is just as deadly as crummy software. Mod-
                    ern high-integration CPUs such as the 68332,80186. and 2180 all include
                    a wealth of internal peripherals-serial  ports, timers, DMA controllers,
                    etc. Interrupts from these sources pose no hardware design issues, since the
                    chip vendors take care of this for you. All of these chips, though, do per-
                    mit the use of external interrupt sources. There’s trouble in them thar ex-
                    ternal interrupts!


                        Vect-table:
                                   dl    start-up           power  up  vector
                                   dl    nul  1-1 s r       unused  vector
                                   dl    nu 11-1 s r        unused  vector
                                   dl    timer-isr         main  tick  timer  ISR
                                   dl    se ri al-i n-i  s r   ; serial  receive  ISR
                                   dl    se rial-out-i  s r   ; serial transmit  ISR
                                   dl    null-isr           unused  vector
                                   dl    null-isr           unused  vector
                        null-isr  :                       ; spurious  intr  routine
                                   imp   null-isr         ; set  BP  here!

                    FIGURE 4-4  Fill unused vectors with a pointer to  null-isr,  and set a
                    breakpoint there while debugging.
   67   68   69   70   71   72   73   74   75   76   77