From 09b15558a15a4c440b82cdd1070e8d54c8ef64f8 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Mon, 20 Apr 2009 18:31:13 -0400 Subject: [PATCH] preliminary interrupts. looks like it is entering the isr but isn't leaving correctly. --- Makefile | 19 +++++++++++---- boot.lds | 1 + include/sys-interrupt.h | 10 ++++---- src/start.S | 2 +- tests/blink-blue.c | 3 +++ tests/blink-green.c | 3 +++ tests/blink-red.c | 3 +++ tests/blink-white.c | 3 +++ tests/nvm-read.c | 4 ++++ tests/rftest-rx.c | 3 +++ tests/rftest-tx.c | 3 +++ tests/romimg.c | 3 +++ tests/tmr-ints.c | 52 +++++++++++++++++++++++++++++------------ tests/tmr.c | 3 +++ tests/uart1-loopback.c | 3 +++ 15 files changed, 89 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 563cd2a01..dc29499dc 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ include $(TOPDIR)/config.mk ######################################################################### # blink objects....order is important (i.e. start must be first) -AOBJS = +AOBJS = COBJS = $(patsubst %.c,%.o,$(wildcard src/*.c)) TESTS = $(wildcard tests/*.c) TARGETS = $(patsubst %.c,%.o,$(TESTS)) @@ -58,12 +58,23 @@ ALL = $(TESTS:.c=.srec) $(TESTS:.c=.bin) $(TESTS:.c=.dis) .PRECIOUS: $(COBJS) $(TARGETS) $(TESTS:.c=.obj) -all: src/start.o $(ALL) +all: src/start.o src/isr.o $(ALL) tests/nvm-read.obj: src/maca.o src/nvm.o tests/rftest-rx.obj: src/maca.o src/nvm.o tests/rftest-tx.obj: src/maca.o src/nvm.o -tests/tmr-ints.c: src/interrupt-utils.o src/sys-interrupt.o +tests/tmr-ints.obj: src/interrupt-utils.o src/sys-interrupt.o src/isr.o + +NOTHUMB_CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \ + -D__KERNEL__ -DTEXT_BASE=$(TEXT_BASE) \ + -I$(TOPDIR)/include \ + -fno-builtin -ffreestanding -nostdinc -isystem \ + $(gccincdir) -pipe +NOTHUMB_CPPFLAGS_EXTRA = -march=armv4t -mlong-calls -mthumb-interwork -mtune=arm7tdmi-s -DCONFIG_ARM -D__ARM__ + + +src/isr.o: src/isr.c + $(CC) $(NOTHUMB_CPPFLAGS) $(NOTHUMB_CPPFLAGS_EXTRA) -c -o $@ $< %.srec: %.obj $(OBJCOPY) ${OBJCFLAGS} -O srec $< $@ @@ -77,7 +88,7 @@ tests/tmr-ints.c: src/interrupt-utils.o src/sys-interrupt.o %.dis: %.obj $(OBJDUMP) -SD $< > $@ -%.obj: $(LDSCRIPT) %.o +%.obj: $(LDSCRIPT) %.o src/interrupt-utils.o $(LD) $(LDFLAGS) $(AOBJS) \ --start-group $(PLATFORM_LIBS) --end-group \ -Map $*.map $^ -o $@ diff --git a/boot.lds b/boot.lds index 5b6ae7aef..0d4bb767b 100644 --- a/boot.lds +++ b/boot.lds @@ -33,6 +33,7 @@ SECTIONS .text : { src/start.o (.text) + src/isr.o (.text) *(.text) } diff --git a/include/sys-interrupt.h b/include/sys-interrupt.h index 433db4a0f..cdaf8d2c3 100644 --- a/include/sys-interrupt.h +++ b/include/sys-interrupt.h @@ -1,8 +1,7 @@ -#ifndef __SYS_INTERRUPT_H__QIHZ66NP8K__ -#define __SYS_INTERRUPT_H__QIHZ66NP8K__ +#ifndef __SYS_INTERRUPT_H +#define __SYS_INTERRUPT_H - -/* Returns true if it handled an activbe interrupt */ +/* Returns true if it handled an active interrupt */ typedef int (*SystemInterruptFunc)(); typedef struct _SystemInterruptHandler SystemInterruptHandler; @@ -12,7 +11,6 @@ struct _SystemInterruptHandler SystemInterruptFunc handler; }; - void sys_interrupt_enable(); @@ -28,4 +26,4 @@ sys_interrupt_prepend_handler(SystemInterruptHandler *handler); void sys_interrupt_remove_handler(SystemInterruptHandler *handler); -#endif /* __SYS_INTERRUPT_H__QIHZ66NP8K__ */ +#endif /* __SYS_INTERRUPT_H */ diff --git a/src/start.S b/src/start.S index ec6f93444..2e17e424e 100644 --- a/src/start.S +++ b/src/start.S @@ -197,7 +197,7 @@ not_used: .align 5 irq: - + b isr .align 5 fiq: diff --git a/tests/blink-blue.c b/tests/blink-blue.c index dda1750bf..a0d59dee7 100644 --- a/tests/blink-blue.c +++ b/tests/blink-blue.c @@ -5,6 +5,9 @@ #define DELAY 400000 #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 2a7aa7add..c7bed04eb 100644 --- a/tests/blink-green.c +++ b/tests/blink-green.c @@ -5,6 +5,9 @@ #define DELAY 400000 #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 0780033e0..f1da55417 100644 --- a/tests/blink-red.c +++ b/tests/blink-red.c @@ -5,6 +5,9 @@ #define DELAY 400000 #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 87a7f6720..18ba37308 100644 --- a/tests/blink-white.c +++ b/tests/blink-white.c @@ -5,6 +5,9 @@ #define DELAY 400000 #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 efbd22f64..12c2e44cc 100644 --- a/tests/nvm-read.c +++ b/tests/nvm-read.c @@ -29,6 +29,10 @@ void put_hex32(uint32_t x); const uint8_t hex[16]={'0','1','2','3','4','5','6','7', '8','9','a','b','c','d','e','f'}; +#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 aeecbb35e..fb91e349e 100644 --- a/tests/rftest-rx.c +++ b/tests/rftest-rx.c @@ -77,6 +77,9 @@ 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 de688bdef..b6f607934 100644 --- a/tests/rftest-tx.c +++ b/tests/rftest-tx.c @@ -112,6 +112,9 @@ 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 51ba68d8b..5b2d346eb 100644 --- a/tests/romimg.c +++ b/tests/romimg.c @@ -28,6 +28,9 @@ const uint8_t hex[16]={'0','1','2','3','4','5','6','7', #define DUMP_LEN 0x00014000 //#define DUMP_LEN 16 +#include "isr.h" +no_isrs(); + __attribute__ ((section ("startup"))) void main(void) { volatile uint32_t i; diff --git a/tests/tmr-ints.c b/tests/tmr-ints.c index 22c12a75d..acb324c64 100644 --- a/tests/tmr-ints.c +++ b/tests/tmr-ints.c @@ -47,12 +47,40 @@ #define reg16(x) (*(volatile uint16_t *)(x)) #include "embedded_types.h" +#include "sys-interrupt.h" + +#include "isr.h" + +volatile uint8_t led; + +#define LED_VAL 0x00000300 +#define led_init() do { reg32(GPIO_PAD_DIR0) = LED_VAL; } while(0); +#define led_on() do { led = 1; reg32(GPIO_DATA0) = LED_VAL; } while(0); +#define led_off() do { led = 0; reg32(GPIO_DATA0) = 0x00000000; } while(0); + +void toggle_led(void) { + if(0 == led) { + led_on(); + led = 1; + + } else { + led_off(); + } +} + +void tmr_isr(void) { + + toggle_led(); + reg16(TMR0_SCTRL) = 0; + reg16(TMR0_CSCTRL) = 0x0040; /* clear compare flag */ + +} __attribute__ ((section ("startup"))) void main(void) { /* pin direction */ - reg32(GPIO_PAD_DIR0) = 0x00000400; + led_init(); /* timer setup */ /* CTRL */ @@ -66,7 +94,8 @@ void main(void) { #define OUT_MODE 0 /* OFLAG is asserted while counter is active */ reg16(TMR_ENBL) = 0; /* tmrs reset to enabled */ - reg16(TMR0_SCTRL) = 0; + reg16(TMR0_SCTRL) = 0; + reg16(TMR0_CSCTRL) =0x0040; reg16(TMR0_LOAD) = 0; /* reload to zero */ reg16(TMR0_COMP_UP) = 18750; /* trigger a reload at the end */ reg16(TMR0_CMPLD1) = 18750; /* compare 1 triggered reload level, 10HZ maybe? */ @@ -74,19 +103,12 @@ void main(void) { reg16(TMR0_CTRL) = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (SEC_SRC<<7) | (ONCE<<6) | (LEN<<5) | (DIR<<4) | (CO_INIT<<3) | (OUT_MODE); reg16(TMR_ENBL) = 0xf; /* enable all the timers --- why not? */ + led_on(); + + enable_tmr_irq(); + enableIRQ(); + while(1) { - - /* blink on */ - reg32(GPIO_DATA0) = 0x00000400; - - while((reg16(TMR0_SCTRL)>>15) == 0) { continue; } - reg16(TMR0_SCTRL) = 0; /*clear bit 15, and all the others --- should be ok, but clearly not "the right thing to do" */ - - /* blink off */ - reg32(GPIO_DATA0) = 0x00000000; - - while((reg16(TMR0_SCTRL)>>15) == 0) { continue; } - reg16(TMR0_SCTRL) = 0; /*clear bit 15, and all the others --- should be ok, but clearly not "the right thing to do" */ - + /* sit here and let the interrupts do the work */ }; } diff --git a/tests/tmr.c b/tests/tmr.c index 22c12a75d..d09912e63 100644 --- a/tests/tmr.c +++ b/tests/tmr.c @@ -48,6 +48,9 @@ #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 ce516d7ad..b3eec3940 100644 --- a/tests/uart1-loopback.c +++ b/tests/uart1-loopback.c @@ -11,6 +11,9 @@ #include "embedded_types.h" +#include "isr.h" +no_isrs(); + __attribute__ ((section ("startup"))) void main(void) { /* Restore UART regs. to default */