Crossware

Table of Contents        Previous topic       Next topic       

C/C++ COMPILER->Interrupt Functions->Manual Coding of Interrupt Vector

The _interrupt qualifier is used to define a function as an interrupt function.  It is placed before the function name as in the following example:

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

The routine that the compiler then generates includes additional code to save and restore any internal variables that must not be overwritten and returns with the RTE rather than the RTS instruction. The resulting function should only be entered in response to an interrupt.

No special code is generated to perform the actual call to this function in response to an interrupt and so you need to manually edit your startup code to set the appropriate interrupt vector to jump to it.  Since the compiler adds an underscore to all function names, you should add this underscore to the function name when you add the assembler code jump instruction to your startup code.  So if the above interrupt function is to be called when a TRAP0  interrupt occurs, you might add the following lines of assembler to your startup code:

    xref _func
    org $80
    DC.L _func

If you intend to set the VBR to relocate the exception vector table, then you should take this into account when specifying the origin.  For instance:

VBR_Location equ $40000000

    '85
    move.l    #VBR_Location,D0
    movec    D0,VBR
    '85
    '85
    
    xref _func
    org VBR_Location+$80
    dc.l _func