I have this more or less theoretical question while all my IDEs are reinstalling...

So I work with MSP430s mostly, and I'm curious about what happens if I create multiple ISRs for a single interrupt vector.

Let's say I'm watching Port2 (pin inputs) for a button press.

#pragma vector = PORT2_VECTOR
__interrupt void Port2_ISR_1 (void)
{
    if (BUTTON1_DOWN)
    {
       g_temp = 1234;
    }
}

Now what if I add another one somewhere that corresponds to the same PORT2_VECTOR?

#pragma vector = PORT2_VECTOR
__interrupt void Port2_ISR_2 (void)
{
    if (BUTTON2_DOWN)
    {
       g_temp = 2345;
    }
}

They correspond to different buttons being pressed, but for the same interrupt vector. When the compiler compiles, does it put the service routines together if they belong to the same vector? Does the microcontroller execute both sequentially whenever PORT2 interrupt goes off?

有帮助吗?

解决方案

As said above, this is implementation dependent; however, so far I've never met a microcontroller which supports multiple interrupt service routines.

The standard behaviour implemented by most common microcontroller families is: one vector = one service routine.

Moreover, as other users pointed out in the comments, your code would trigger a duplicate symbol error while linking.

其他提示

You can write as many ISR's as you have space for. However, the interrupt vector table (IVT) is a on-to-one correspondence between interrupts and ISR addresses. So when your program loads, only one address can be written into an IVT entry for any particular interrupt. No processor or interrupt controller allows more than one ISR address per interrupt.

The processor interrupt vector table is initialized by the C runtime program ("crt0") that you link with your program. Here is an example crt0 for an AVR microprocessor. As you can see, this crt0 implementation uses global symbols to assign values to the interrupt vector table entries. This means that the linker should detect the multiple ISR symbols.

Some crt0 implementations, including some for the MSP430, copy the IVT from the location of a symbol into the hardware location of the IVT, 0xFFE0 to 0xFFFE. For this type of crt0, the compiler needs to detect the multiple ISR's, because it builds the IVT and set the symbol for crt0.

Which crt0 you are using depends on the compiler configuration, unless you specifically override it, for example, in GCC by specifying a custom directory name in the GCC_EXEC_PREFIX environment variable.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top