
137
Chapter 2 Applications Programming
add
add
add
add
add
add
add
add
const
consth
load
cpeq
const
consth
jmpfi
nop
iret
gr102,gr71,0
gr101,gr70,0
gr100,gr69,0
gr99,gr68,0
gr98,gr67,0
gr97,gr66,0
gr96,gr65,0
lr0,gr64,0
gr64,_sig_sig
gr64,_sig_sig
0,0,gr64,gr64
gr65,gr64,0
gr66,_signal_associate_code + 4 ;no relative
gr66,_signal_associate_code + 4 ; addressing
gr65,gr66
;jump if sig_sig != 0
;restore lr0
;the following eight
; instructions deal with
; sig_sig testing
;test for zero
_interrupt_cache_end:
The context cache code is a little different from the code shown in section 2.5.1.
Eight extra instruction have been added to support a memory variable called
sig_sig
.
It supports a very useful technique of two–level interrupt processing. Predominantly
a Freeze mode interrupt handler is used alone. However, when the
sig_sig
variable is
set to a signal number before the Freeze mode handler completes, a signal is
generated causing a second signal handler routine to execute after the Freeze mode
handler returns.
Examine the example handler routines. When interrupt INTR1 (vector 17)
occurs, the Freeze mode handler,
f_handler()
, normally accesses the interrupting
UART and receives a character; it then increments the
count
value and returns. The
processes of accessing the UART causes the interrupt request to be deasserted. This
results in a very fast interrupt handler written in C. However, when the received
character is a ‘\n’ (carriage return),
sig_sig
is set to the signal number allocated to the
INTR0 signal handler. This causes the
s_handler()
to be executed in response to the
signal. The occurrence of interrupt INTR0 (vector 16) also causes
s_handler()
to
execute as a signal handler associated with trap 16. The example
interrupt()
service
automatically allocates signal numbers, starting with SIGUSR1, to handler routines
which are to be processed via signal trampoline code. The
interrupt()
procedure
returns the selected signal number; zero is returned if a Freeze mode handler is
selected. An interrupt handler can be restricted to fast Freeze mode processing and
when more extensive processing is required the
sig_sig
variable can be set and a
second level
handler invoked. (Note, the
s_handler()
routine calls the
printf()
library routine. This is not permitted with the High C 29K library routines as the
printf()
routine is not reentrant. However, the use of
printf()
helps illustrate the
two–stage principle.)
To perform signal processing, the trampoline code shown below is placed in
heap memory. It is similar to the code of section 2.5.3. Interrupts are disabled before