In an experimental project using an AVR64EA MCU, I've wired two external interrupts to pins of the same port. The ISR looks like this:
ISR(PORTD_PORT_vect) {
if (PORTD_INTFLAGS & PORT_INT_2_bm) {
PORTD_INTFLAGS |= PORT_INT_2_bm;
// do something quick and lightweight
} else if (PORTD_INTFLAGS & PORT_INT_3_bm) {
PORTD_INTFLAGS |= PORT_INT_3_bm;
// do something else quick and lightweight
}
}
While this works fine, I am wondering how efficient (as in time efficiency/ISR run time) and elegant it is to check for up to 8 interrupts in the same ISR instead of having one ISR for each interrupt.
The datasheet explains about Compact Vector Table:
The Compact Vector Table (CVT) is a feature to allow the writing of compact code by having all level 0 interrupts share the same interrupt vector number. Thus, the interrupts share the same Interrupt Service Routine (ISR). This reduces the number of interrupt handlers and thereby frees up memory that can be used for the application code.
So, the above example is desirable (at least for memory usage) but I am still unsure about efficiency. Or is my if .. else if just too clumsy?