From 2288c9e2ff93cc7e04856a01013ce231105c9133 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Fri, 24 Apr 2009 15:42:15 -0400 Subject: [PATCH 1/2] better way to do irqs --- Makefile | 2 +- boot.lds | 8 ++++---- src/isr.c | 5 +++-- src/start.S | 19 ++++++------------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 4803b5e1b..6ddfe5c22 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,7 @@ src/isr.o: src/isr.c %.dis: %.obj $(OBJDUMP) -SD $< > $@ -%.obj: $(LDSCRIPT) %.o #src/interrupt-utils.o +%.obj: $(LDSCRIPT) %.o src/isr.o $(LD) $(LDFLAGS) $(AOBJS) \ --start-group $(PLATFORM_LIBS) --end-group \ -Map $*.map $^ -o $@ diff --git a/boot.lds b/boot.lds index 0d4bb767b..c71b37ede 100644 --- a/boot.lds +++ b/boot.lds @@ -28,13 +28,13 @@ ENTRY(_start) SECTIONS { . = 0x00400000; - + . = ALIGN(4); .text : { - src/start.o (.text) - src/isr.o (.text) - *(.text) + src/start.o (.text) + *(.irq) + *(.text) } . = ALIGN(4); diff --git a/src/isr.c b/src/isr.c index 913374208..00d7c3207 100644 --- a/src/isr.c +++ b/src/isr.c @@ -4,8 +4,9 @@ #define reg32(x) (*(volatile uint32_t *)(x)) -//__attribute__ ((interrupt("IRQ"))) -void isr(void) +__attribute__ ((section (".irq"))) +__attribute__ ((interrupt("IRQ"))) +void irq(void) { // ISR_ENTRY(); /* check for TMR0 interrupt */ diff --git a/src/start.S b/src/start.S index bc991ad7d..ff6f06fcd 100644 --- a/src/start.S +++ b/src/start.S @@ -212,19 +212,12 @@ not_used: .align 5 -irq: - push {lr} - movs lr,pc - b isr - pop {lr} - subs pc,r14,#4 // suggested irq return cmd -// STMFD sp!, {r0-r12,lr} -// MOVNE lr,pc -// ldr r0, =isr -// BX r0 -// LDMFD r13!, {r0-r12,r14} -// MOVS PC, R14 -// subs pc, r14, #4 +//irq: +// push {lr} +// movs lr,pc +// b isr +// pop {lr} +// subs pc,r14,#4 // suggested irq return cmd fiq: .align 5 From d869766664cc75386c4bcc4e5ff4e28a684bbfe3 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Fri, 24 Apr 2009 16:04:04 -0400 Subject: [PATCH 2/2] using weak links for individual isrs --- include/isr.h | 6 +----- src/isr.c | 4 +++- tests/blink-blue.c | 2 -- tests/blink-green.c | 2 -- tests/blink-red.c | 2 -- tests/blink-white.c | 2 -- tests/nvm-read.c | 2 -- tests/rftest-rx.c | 4 +--- tests/rftest-tx.c | 4 +--- tests/romimg.c | 1 - tests/tmr.c | 2 -- tests/uart1-loopback.c | 2 -- 12 files changed, 6 insertions(+), 27 deletions(-) diff --git a/include/isr.h b/include/isr.h index 0583ffc7e..22e1772be 100644 --- a/include/isr.h +++ b/include/isr.h @@ -10,13 +10,9 @@ #define INTENNUM INTBASE + INTENNUM_OFF #define INTSRC INTBASE + INTSRC_OFF - -#define no_isrs() no_tmr_isr(); - #define enable_tmr_irq() *(volatile uint32_t *)(INTENNUM) = 5; -#define no_tmr_isr() void tmr_isr(void) { return; } -extern void tmr_isr(void); +extern void tmr_isr(void) __attribute__((weak)); #endif diff --git a/src/isr.c b/src/isr.c index 00d7c3207..323fd971f 100644 --- a/src/isr.c +++ b/src/isr.c @@ -10,7 +10,9 @@ void irq(void) { // ISR_ENTRY(); /* check for TMR0 interrupt */ - tmr_isr(); // led turns off if I have this, indicating that the isr does jump to tmr_isr + if(tmr_isr != NULL) { + tmr_isr(); // led turns off if I have this, indicating that the isr does jump to tmr_isr + } // if(reg32(INTSRC) & (1<<5)) { tmr_isr(); } // asm("SUBS PC,R14_IRQ,#4") // enableIRQ(); // I think this is necessary, but the LED never turns off when I have this diff --git a/tests/blink-blue.c b/tests/blink-blue.c index a0d59dee7..c732d9193 100644 --- a/tests/blink-blue.c +++ b/tests/blink-blue.c @@ -7,8 +7,6 @@ #include "embedded_types.h" #include "isr.h" -no_isrs(); - __attribute__ ((section ("startup"))) void main(void) { diff --git a/tests/blink-green.c b/tests/blink-green.c index c7bed04eb..3531ea4f5 100644 --- a/tests/blink-green.c +++ b/tests/blink-green.c @@ -7,8 +7,6 @@ #include "embedded_types.h" #include "isr.h" -no_isrs(); - __attribute__ ((section ("startup"))) void main(void) { diff --git a/tests/blink-red.c b/tests/blink-red.c index f1da55417..bdb9d44bf 100644 --- a/tests/blink-red.c +++ b/tests/blink-red.c @@ -7,8 +7,6 @@ #include "embedded_types.h" #include "isr.h" -no_isrs(); - __attribute__ ((section ("startup"))) void main(void) { *(volatile uint32_t *)GPIO_PAD_DIR0 = 0x00000100; diff --git a/tests/blink-white.c b/tests/blink-white.c index 18ba37308..87d456d12 100644 --- a/tests/blink-white.c +++ b/tests/blink-white.c @@ -7,8 +7,6 @@ #include "embedded_types.h" #include "isr.h" -no_isrs(); - __attribute__ ((section ("startup"))) void main(void) { diff --git a/tests/nvm-read.c b/tests/nvm-read.c index 12c2e44cc..54a912904 100644 --- a/tests/nvm-read.c +++ b/tests/nvm-read.c @@ -31,8 +31,6 @@ const uint8_t hex[16]={'0','1','2','3','4','5','6','7', #include "isr.h" -no_isrs(); - #define NBYTES 1024 __attribute__ ((section ("startup"))) void main(void) { diff --git a/tests/rftest-rx.c b/tests/rftest-rx.c index fb91e349e..e2c2a1491 100644 --- a/tests/rftest-rx.c +++ b/tests/rftest-rx.c @@ -14,6 +14,7 @@ #include "maca.h" #include "embedded_types.h" +#include "isr.h" #define reg(x) (*(volatile uint32_t *)(x)) @@ -77,9 +78,6 @@ void toggle_led(void) { } } -#include "isr.h" -no_isrs(); - __attribute__ ((section ("startup"))) void main(void) { uint8_t c; diff --git a/tests/rftest-tx.c b/tests/rftest-tx.c index b6f607934..485baaa5a 100644 --- a/tests/rftest-tx.c +++ b/tests/rftest-tx.c @@ -14,6 +14,7 @@ #include "maca.h" #include "embedded_types.h" +#include "isr.h" #define reg(x) (*(volatile uint32_t *)(x)) @@ -112,9 +113,6 @@ void fill_data(void) { } } -#include "isr.h" -no_isrs(); - __attribute__ ((section ("startup"))) void main(void) { uint8_t c; diff --git a/tests/romimg.c b/tests/romimg.c index 5b2d346eb..e29330e13 100644 --- a/tests/romimg.c +++ b/tests/romimg.c @@ -29,7 +29,6 @@ const uint8_t hex[16]={'0','1','2','3','4','5','6','7', //#define DUMP_LEN 16 #include "isr.h" -no_isrs(); __attribute__ ((section ("startup"))) void main(void) { diff --git a/tests/tmr.c b/tests/tmr.c index f83107acb..8e28ede74 100644 --- a/tests/tmr.c +++ b/tests/tmr.c @@ -47,9 +47,7 @@ #define reg16(x) (*(volatile uint16_t *)(x)) #include "embedded_types.h" - #include "isr.h" -no_isrs(); __attribute__ ((section ("startup"))) void main(void) { diff --git a/tests/uart1-loopback.c b/tests/uart1-loopback.c index b3eec3940..21a3bbcb5 100644 --- a/tests/uart1-loopback.c +++ b/tests/uart1-loopback.c @@ -10,9 +10,7 @@ #define UART1_BR 0x80005018 #include "embedded_types.h" - #include "isr.h" -no_isrs(); __attribute__ ((section ("startup"))) void main(void) {