原创 CodeWarrior中中断函数的集中表示方法

2008-6-7 14:56 3409 2 2 分类: MCU/ 嵌入式

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.


 

Using Pragma "TRAP_PROC"


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).


Example:


#pragma TRAP_PROC


void INCcount(void) {


   tcount++;


}


 

Using Keyword "interrupt"


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.


Example:


interrupt void INCcount(void) {


   tcount++;


}


Initializing the Vector Table


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".


Using the Linker Commands


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.


Example:


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:


VECTOR ADDRESS 0x8A INCcount


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.


Example:


In order to associate the address of the function INCcount with the vector number 69, insert following command in the application PRM file:


VECTOR ADDRESS 69 INCcount


 

Using the Keyword "interrupt"


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.


Example:


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.


Example:


/* These functions are defined in segment `int_Function'*/


#pragma CODE_SEG Int_Function


#pragma TRAP_PROC


void INCcount(void) {


   tcount++;


}


#pragma CODE_SEG DEFAULT /*Return to default code segment.*/


Placing a Specific 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.


Example:


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;


    ....


END





 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
2
关闭 站长推荐上一条 /3 下一条