This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

#pragma vector

Hi,

I dont understand how the interrupt prototype works in msp430?

I was going through the resource example and i didnt understand the following thing.

#pragma vector=USI_VECTOR
__interrupt void universal_serial_interface(void)

{  

//some code.

}

What does #pragma do? and how does it works as ISR?

  • Pragma’s are not directly part of the code but are special instructions to the compiler, in this case to create (into the code) an interrupt vector, in this case for the USI, to the place just following with the label of your choice.

    More her over you can read in the ‘ MSP430 Optimizing C/C++ Compiler’.

  • If you write an ISR, it is just a function. A function with specific entry/exit code, but a function nonetheless. Worse, it is a function that is never called by anyone in the source code. So it is a candidate for being discarded at link time.

    The "#pragma vector" generates a reference to the following function and locates it at the USI_VECTOR position in the interrupt vector table. So the ISR gets referenced (and the linker won’t discard it) and the CPU knows where to jump in case of an USI interrupt.

     In general, #pragma, while being a preprocessor directive like #ifdef, is not handled by the preprocessor. Instead it is forwarded to the compiler as a compiler control instruction. Depending on its content, It may switch optimization on or of at a specific point of the code, may allow or restrict the use of certain instructions, define segments in which to place the following code, disable specific compiler warnings (like ‘unused argument’, when this is intentional) etc.
    The supported pragmas depend on the compiler, sometimes even on compiler version, and are usually not portable.

**Attention** This is a public forum