diff options
-rw-r--r-- | include/isr_vector.h | 19 | ||||
-rw-r--r-- | src/blinky.c | 11 | ||||
-rw-r--r-- | src/init.c | 1 | ||||
-rw-r--r-- | src/isr.s | 1 |
4 files changed, 28 insertions, 4 deletions
diff --git a/include/isr_vector.h b/include/isr_vector.h index bd5786a..65359a5 100644 --- a/include/isr_vector.h +++ b/include/isr_vector.h @@ -10,6 +10,7 @@ void default_irq_handler(void); /** Weakly defined interrput service routine vectors. These just alias to * default_irq_handler if not overridden. */ +void irq_on_reset(void); void irq_on_nmi(void); void irq_on_exc(void); void irq_on_systick(void); @@ -33,4 +34,20 @@ void irq_on_uart2(void); void irq_on_uart3(void); void irq_on_wdog_bat(void); -#define IRQ(name) void __attribute__((__section__(".isr_vector"))) name(void) +/* + * Macro to define an interrput service routine. + */ +#define IRQ(name) \ + /* Real interrupt service routine. This contains most of the code to handle \ + * the interrupt. */ \ + static void __attribute__((noinline)) _real__irq_on_##name(void); \ + /* The actual routine that's jumped to. It's soley responsible for jumping \ + * to the real handler (which requires multiple instructions because it's a \ + * long jump). This stub is compiled and linked promimal to the ISR vector. \ + */ \ + void __attribute__((interrupt)) \ + __attribute__((__section__(".isr_vector"))) irq_on_##name(void) \ + { \ + _real__irq_on_##name(); \ + } \ + static void __attribute__((noinline)) _real__irq_on_##name(void) diff --git a/src/blinky.c b/src/blinky.c index 9f89238..355b479 100644 --- a/src/blinky.c +++ b/src/blinky.c @@ -12,9 +12,6 @@ void delay(void); void main(void); -IRQ(irq_on_systick) { - main(); -} uint32_t collatz(uint32_t n) { @@ -78,3 +75,11 @@ void main(void) delay(); } } + +IRQ(systick) { + collatz(5); +} + +IRQ(exc) {} + +IRQ(nmi) {} @@ -16,6 +16,7 @@ default_irq_handler(void) weak, alias("default_irq_handler"), __section__(".isr_vector"))) \ irq(void) +WEAK_IRQ(irq_on_reset); WEAK_IRQ(irq_on_nmi); WEAK_IRQ(irq_on_exc); WEAK_IRQ(irq_on_systick); @@ -8,6 +8,7 @@ j on_reset /* first instruction. Should jump directly to on_reset */ isr_vector: .align 4 .word 0 + j irq_on_reset j irq_on_nmi j irq_on_exc |