Electronic – Interrupt question ARM

armcinterruptsmicrocontroller

I often see something like this void UART2_IRQHandler(void) __irq, and I wonder why __irq is used when declaring interrupt handler, is it required or handler can work without it?

Best Answer

Basically, an interrupt service routine written in C is simply a function that takes no arguments and doesn't return anything void someKindOfIsr(void).

__irq is a C language extension for your compiler that is used to generate special entry and/or exit assembly instructions for handling interrupts. For instance, the return instruction may be different if you are returning from an interrupt rather than a simple function to clear some type of interrupt status register.

Whether it is necessary or not depends on what ARM architecture you are working with. A quick way to find out if it is necessary for your platform is to examine the assembly produced both with and without the __irq keyword.

Even if the listing file is exactly the same both with and without the __irq keyword, you may want to consider leaving the __irq keyword in place for clarity and for portability to some future platform.