Hardware Reference
In-Depth Information
Step 2
Write the interrupt service routine . An interrupt service routine should be as short as
possible. For some interrupts, the service routine may only output a message to indicate
that something unusual has occurred. A service routine is similar to a subroutine—the only
difference is the last instruction. An interrupt service routine uses the return-from-interrupt
(or return-from-exception ) instruction instead of return-from-subroutine instruction to
return to the interrupted program. The following instruction sequence is an example of an
interrupt service routine (in HCS12 instructions):
irq_isr
ldx
#msg
jsr
puts
; call puts to output a string pointed by X
rti
; return from interrupt
msg fcc “This is an error”
The service routine may or may not return to the interrupted program, depending on
the cause of the interrupt. It makes no sense to return to the interrupted program if the
interrupt is caused by a software error such as divide by zero or overflow, because the
program is unlikely to generate correct results under these circumstances. In such
situations, the service routine would return to the monitor program or the operating
system instead. Returning to a program other than the interrupted program can be achieved
by changing the saved program counter (in the stack) to the desired value. Execution of the
return-from-interrupt instruction will then return CPU control to the new address.
Step 3
Enable the interrupts to be serviced. An interrupt can be enabled by clearing the global
interrupt mask and setting the local interrupt enable bit in the I/O control register. It is a
common mistake to forget enabling interrupts when writing interrupt-driven application
programs.
6.2.8 Overhead of Interrupts
Although the interrupt mechanism provides many advantages, it also involves some over-
head. The overhead of the HCS12 interrupt includes
1. Saving the CPU registers, including accumulators (A:B), index registers X and Y, and
the condition code register (CCR), and fetching the interrupt vector. This takes at
least 9 E-clock cycles.
2. The execution time of the RTI instruction. This instruction restores all the CPU
registers that have been stored in the stack by the CPU during the interrupt and takes
from 8 to 11 E-clock cycles to complete for the HCS12.
3. Execution time of instructions of the interrupt service routine. This depends on the
type and the number of instructions in the service routine.
The total overhead is thus at least 17 to 20 E-clock cycles, which amounts to almost 1
s for a
24-MHz E-clock. We need to be aware of the overhead involved in interrupt processing when
deciding whether to use the interrupt mechanism.
μ
6.3 Resets
The initial values of some CPU registers, flip-flops, and the control registers in I/O inter-
face chips must be established before the computer can operate properly. Computers provide a
reset mechanism to establish initial conditions.
 
Search WWH ::




Custom Search