Defining Interrupt Functions <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
This manual entry discusses some important topics related to the handling of interrupt functions:
· Definition of an interrupt function
· Initialization of the vector table
· Placing interrupt function in special sections
Defining an Interrupt Function
The compiler provides two ways to define an interrupt function:
· Using pragma TRAP_PROC.
· Using the keyword interrupt.
The pragma TRAP_PROC indicates to the compiler that the following function is an interrupt function. In that case, the compiler should terminate the function by a special interrupt return sequence (for many processors a RTI instead of a RTS).
void INCcount(void) {
tcount++;
The keyword `interrupt" is not ANSI C standard and as thus is not supported by all ANSI C compiler vendor. In the same way, the syntax for the usage of this keyword may change between different compiler. The keyword interrupt indicates to the compiler that the following function is an interrupt function.
interrupt void INCcount(void) {
tcount++;
Once the code for an interrupt function has been written, you have to associate this function with an interrupt vector. This is done through initialization of the vector table. The vector table can be initialized in following ways:
· Using the command VECTOR or VECTOR ADDRESS in the PRM file
· Using the keyword "interrupt".
The Linker provides two commands to initialize the vector table: VECTOR or VECTOR ADDRESS. The command VECTOR ADDRESS is used to write the address of a function at a specific address in the vector table.
In order to enter the address of the function INCcount at address 0x<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />8A, insert following command in the application PRM file:
The command VECTOR is used to associate a function with a specific vector, identified with its number. The mapping from the vector number is target specific.
In order to associate the address of the function INCcount with the vector number 69, insert following command in the application PRM file:
When you are using the keyword "interrupt", you may directly associate your interrupt function with a vector number in the ANSI C source file. In that purpose just specify the vector number next to the keyword interrupt.
In order to associate the address of the function INCcount with the vector number 69, define your function as follows:
interrupt 69 void INCcount(void) {
int card1;
tcount++;
Placing Interrupt Function in Special Sections
For all targets supporting paging, the interrupt function must be allocated in an area which is accessible all the time. This can be obtained by putting the interrupt function into a specific segment.
Defining Functions in a Specific Segment.
In order to define a function in a specific segment, you can use the pragma CODE_SEG.
/* These functions are defined in segment `int_Function'*/
#pragma CODE_SEG Int_Function
void INCcount(void) {
tcount++;
#pragma CODE_SEG DEFAULT /*Return to default code segment.*/
In the PRM file, you can define where you want to allocate each segments you have defined in your source code. In order to place a segment in a specific memory area; just add the segment name in the PLACEMENT block of your PRM file. Be careful, the linker is case sensitive. Take special attention to the upper and lower cases in your segment name.
LINK test.abs
NAMES test.o ... END
SECTIONS
INTERRUPT_ROM = READ_ONLY 0x4000 TO 0x5FFF;
MY_RAM = READ_WRITE ....
PLACEMENT
Int_Function INTO INTERRUPT_ROM;
DEFAULT_RAM INTO MY_RAM;
....
文章评论(0条评论)
登录后参与讨论