Crossware

Table of Contents        Previous topic       Next topic       

C COMPILER->Interrupt Functions->Automatic Coding of Interrupt Vector

An alternative way of declaring an interrupt function is to use the _interrupt n qualifier.  The compiler generates exactly the same code for the function as it does when the _interrupt qualifier is used but in addition it also creates the code to set up the interrupt vector itself.  There is therefore no need to modify your startup code.  

The interrupt vector used corresponds to the value of n and is calculated as follows:

Vector address = n*4

File os.h contains a set of defines for the standard 680X0 vector numbers which you can use and so you might define func() as follows:

#include <os.h>

void _interrupt IVN_TRAP0 func()
{
    /* Your interrupt code goes here */
}

(IVN_TRAP0 is defined as 32 in os.h)

If you are setting the Vector Base Register to a non-zero value to relocate the exception vector table (CPU32 or 68020) or if you are using a jump table to relocate your vectors (68000), then you should use the /VO compiler option.  This tells the compiler to add the specified offset to the calculated vector address.  For example if you are setting VBR to $40000000, the /VO:40000000 compiler option should be used.  The vector address used will then be for the CPU32 or 68020:

Vector address = n*4+$40000000

or for the 68000:

Vector address = n*6+$40000000.

(The vector number is multiplied by 6 instead of 4 for the 68000 due to the additional 2 bytes required for the JMP instruction.

If you are working from within the Embedded Development Studio, you can specify the vector offset in the Compiler Settings tab (Build->Settings->Compiler).