Crossware

Table of Contents        Previous topic       Next topic       

C/C++ COMPILER->Interrupt Functions->Cortex->Automatic Coding of Interrupt Vector

For the Cortex cores, any function can be an interrupt function.  The compiler does not need to save any scratch registers or generate any special return statement.

Nevertheless, the _interrupt keyword can still be used to tell the compiler to automatically generate an interrupt vector for the function.

The _interrupt keyword is used with a numeric constant n which is the interrupt vector number. The interrupt vector used corresponds to the value of n and is calculated as follows:

Vector address = n*4

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

#include <oscm3.h>

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

(IVN_SV_CALL is defined as 11 in oscm3.h)

For this example the compiler will generate an absolute section for the interrupt vector as follows:

    ORG    0000002Ch
    DCDU    _func+1

Vector numbers specific to a particular microcontroller variant are provided in a file specific to that variant.

If you are using a Crossware Code Creation Wizard to generate the interrupt handler then it will automatically insert the correct symbol for the vector number.

If you are setting the Vector Table Offset 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 used 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).