Page 187 - Embedded Microprocessor Systems Real World Design
P. 187
If transmit FIFO has data,
If TXRDY flag set,
Reset TXRDY flag
Transmit a word to other DSF!
End of polling loop.
Rx serial data ISR:
Set RXRDY
Return.
Transmit acknowledge ISR
Set TXRDY
Return
When to Use lnterrupts
This topic almost makes more sense at the beginning of the chapter, but I wanted
to talk about how interrupts work before discussing why they are not always a good
idea.
To begin with, sometimes there is no choice but to use interrupts. The previous
dual DSP, for example, had to use an interrupt for receiving because there is no
internal status bit that can be checked by the polling loop to determine whether
data are available.
Chapter 1 stated that designers sometimes overuse interrupts. Although it is
dangerous to lay down universal rules like this, in general, interrupts should be
used for three reasons:
1. To generate a regular, repeatable event. A timer interrupt on a regular basis for
timekeeping is a good example.
2. When a peripheral absolutely must be serviced immediately or something will
go wrong (for example, a UART receiving a continuous stream of data that
will overrun the receiver if each byte is not taken out before the next one is
received). Be careful, though, about assuming that cases like this require an
interrupt. The protocol converter described in Chapter 4 used no interrupts.
The program loop was short enough and fast enough, even with subroutine calls,
to guarantee that no received bytes were missed.
3. To save on hardware. For example, a processor might get an interrupt from the
shaft encoder of a motor. Each time the interrupt occurs, the processor incre-
ments a position count. This saves adding a hardware counter. The pool timer
uses an interrupt to multiplex the display, saving the cost of external display
registers and multiplexing logic.
Interrupts also are used as a means of scheduling tasks through a real-time
operating system, which we’ll cover in Chapter 9.
168 Embedded Microprocessor Systems