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.

Compiler/TM4C1294NCPDT: interrupt keyword and its usage

Part Number: TM4C1294NCPDT

Tool/software: TI C/C++ Compiler

Hi Folks,

I have been studying the TI C++ compiler, when I found the keyword "interrupt" and the fact that it should be used to declare interrupt service routines.

My applications have been developed under C++ and most of the time, I'm using static class member functions to grab interrupts (they are placed into the interrupt vector table), and it seems everything is OK. Can anybody explain me, what it the pros / cons of using this keyword? Why does my code works without it, etc...

Regards,

Norbert

  • In summary, you are getting lucky.  You really need to use the interrupt keyword.

    The main difference is the register convention.  Normal functions do not preserve every register that is modified.  The register conventions only require certain registers be preserved.  Other registers can be modified and not preserved because, per the convention, the point where the function is called expects those registers to change.  Interrupt functions, on other hand, are required to preserve every register that is modified.  I'm not sure how you avoid problems here.  Luck must be a part of it.  I'm not an expert on the ARM architecture.  Perhaps certain registers are automatically preserved when an interrupt occurs, and your interrupt functions only use those registers.

    Thanks and regards,

    -George

  • Hi,

    I can accept your answer, but in this case, there are several thing, what I don't understand.

    1. I use FreeRTOS provided by the TivaWare. It requires these 3 handlers below. To do its work. The first two is written in ASM, but I don't see any 'r' register saving statement, the third one is written in C without "interrupt" keyword.
      1. vPortSVCHandler();
      2. xPortPendSVHandler();
      3. xPortSysTickHandler()
    2. I use LwIP stack too, it is also coming from the TivaWare, and its interrupt handler also stays without "interrupt" modifier.

    Can you help / explain me to understand these observations? I would like to learn the manner of this keyword or the missing of it.

    Regards,

    Norbert

  • The interrupt keyword is appropriate for interrupt routines directly vectored to by the CPU, without any interaction with an OS or RTOS like FreeRTOS.  If you use FreeRTOS, then you need to follow their documentation regarding interrupt routines.  It is likely you should not use the interrupt keyword.  I know that is the case with interrupts invoked by SYS/BIOS.

    Thanks and regards,

    -George

  • Norbert Toth said:
    Why does my code works without it, etc...

    The Exception entry and return section in the Cortex-M4 Devices Generic User Guide shows that integer registers xPSR, PC, LR, R12, R3, R2, R1 and R0 are pushed onto the stack by the processor upon exception entry (interrupt handler). When using floating-point routines the Cortex-M4 processor automatically stacks the architected floating-point state on exception entry. 

    The Register Conventions section of the TI ARM Optimizing C/C++ Compiler User's Guide shows that registers R0, R1, R2, R3 and R12 are preserved by the calling function, while the other registers are preserved by the child function.

    Since on exception entry the Cortex-M4 processor automatically pushes the registers which the C compiler required to be preserved by the calling function, that explains why on the Cortex-M4 that the "interrupt" keyword is not required on interrupt service routines.