Runtime
Environment
-
Interrupt
Handling
5.5
Interrupt
Handling
5-16
C code can
be
interrupted and returned
to
without
disrupting the C environ-
ment,
as
long
as
you
follow
the guidelines in this section. When the C envi-
ronment is
initialized, the startup routine does
not
enable
or
disable interrupts.
(If
the system
is
initialized via a hardware reset, interrupts
are
disabled.)
If
your system uses interrupts,
it
is
your responsibility
to
handle any required
enabling or masking
of
interrupts. Such operations have no effect on the C
environment, and can
be
easily incorporated
with
asm statements.
The
C compiler uses a special naming convention
for
interrupt functions; such
functions have names
with
the
following
format:
c-intnn
where
nn
is
a
two-digit
number between
00
and
99
(for
example,
c-intOl).
Following this convention assures that the compiler treats the function
as
an
interrupt function. The name
c-intOO
is
reserved for the system reset inter-
rupt. This
special interrupt routine initializes the system and calls the function
main;
c_intOO
does
not
save any registers since
it
has
no
caller.
Interrupt
routines for any interrupt except
c-intOO
must save any register
used
(with
the exception
of
SP
and STK), including
AB.
In a normal function,
it
is
not
necessary
to
save
AB;
however, in the case
of
an
interrupt,
AB
must
be
saved.
The compiler uses the
RETI
instruction
to
return from
an
interrupt;
RETI
restores the
ST
register
of
an
interrupted function.
A
C interrupt routine
is
like any other C function -
it
can have local variables
and register variables,
it
can access global variables, and
it
can call other
functions. However,
an
interrupt routine should be declared
without
any ar-
guments and
it
should
not
be
called directly.
Any
interrupt function can
be
used
to
handle any interrupt or multiple inter-
rupts. The
compiler does
not
generate any code specific
to
the particular
in-
terrupt,
with
the exception of the system reset interrupt (e-intOO),
which
must
be used
as
system reset and cannot have any local variables (since
it
is as-
sumed that at system reset the stack has
not
yet been allocated).
To associate
an
interrupt function
with
an
interrupt, the address
of
the inter-
rupt must
be
placed in the proper interrupt vector. You can accomplish this
by
using the assembler and the linker
to
create a simple table
of
addresses at
the proper
location.