IRQ Handling

IRQ handlers need two things. First, they are different from normal functions in that they must use the rti (return from interrupt) instruction in place of the standard rts (return from subroutine). Second, your handler must be in the list of pointers to IRQ handlers.

To achieve this behaviour, declare your interrupt handler with __attribute__((interrupt)). This will tell the compiler to generate the proper function prolog and epilog when compiling it. Your declaration should then look like:

void pulse_width_modulation() __attribute__((interrupt));
void pulse_width_modulation()
{
   [...]
}

In order to tell the linker that you want your interrupt handler associated with a particular interrupt, you declare an alias to the function with a special name. You may have an many aliases for the same handler as you like. The valid names are defined in miniboard.lds and listed in the table below. To tie the above function to the “timer input capture 4” use the following:

void irq_ti4o5() __attribute__((alias ("pulse_width_modulation")));
Symbol name Address Meaning
irq_reset 0xfffe POR (power-on) or external reset
irq_clock 0xfffc clock monitor failure
irq_cop 0xfffa watchdog timer timeout (computer operating properly)
irq_trap 0xfff8 illegal opcode trap
irq_swi 0xfff6 software interrupt
irq_xirq 0xfff4 XIRQ pin
irq_irq 0xfff2 IRQ pin
irq_rti 0xfff0 real-time interrupt
irq_tic1 0xffee timer input capture 1
irq_tic2 0xffec timer input capture 2
irq_tic3 0xffea timer input capture 3
irq_toc1 0xffe8 timer output compare 1
irq_toc2 0xffe6 timer output compare 2
irq_toc3 0xffe4 timer output compare 3
irq_toc4 0xffe2 timer output compare 4
irq_ti4o5 0xffe0 timer input capture 4/output compare 5
irq_tflow 0xffde timer overflow
irq_pflow 0xffdc pulse accumulator overflow
irq_pedge 0xffdc pulse accumulator input edge
irq_spitc 0xffda SPI serial transfer complete
irq_sci 0xffd8 SCI serial system multi-use interrupt

See the M68HC11 manual for details on each of these interrupts.

If not specified, irq_reset will default to the entry point of your program.


Nick Lewycky
Last modified: Tue Dec 21 00:33:44 EST 2004