Table of Contents        Previous topic       Next topic       

C/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 ColdFire 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, 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 uesd will then be:

Vector address = n*4+$40000000

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