From 87cd9c7a36920c5511c0fa52194d5936afc6abb9 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Fri, 26 Feb 2010 14:04:10 -0500 Subject: [PATCH] update build system for board specific code that's 'local' to the program you are building. update tests to consolidate common code. --- Makefile.include | 14 +++++--- board/Makefile.board | 2 +- libmc1322x/include/mc1322x.h | 4 +++ libmc1322x/include/utils.h | 2 -- tests/Makefile | 6 ++++ tests/nvm-read.c | 62 +++--------------------------------- tests/nvm-write.c | 57 +++------------------------------ tests/put.c | 36 +++++++++++++++++++++ tests/put.h | 10 ++++++ tests/romimg.c | 42 +++++------------------- tests/tests.c | 32 +++++++++++++++++++ tests/tests.h | 9 ++++++ tests/uart1-loopback.c | 16 ++-------- 13 files changed, 126 insertions(+), 166 deletions(-) create mode 100644 tests/put.c create mode 100644 tests/put.h create mode 100644 tests/tests.c create mode 100644 tests/tests.h diff --git a/Makefile.include b/Makefile.include index 223372291..5e931066b 100644 --- a/Makefile.include +++ b/Makefile.include @@ -11,9 +11,10 @@ include $(MC1322X)/board/Makefile.board include $(MC1322X)/libmc1322x/Makefile.lib -# default start and isr -CFLAGS += -I$(MC1322X)/src +CFLAGS += -I$(MC1322X)/src -I. + +# default start and isr ifndef START START = $(MC1322X)/src/start.o endif @@ -21,6 +22,7 @@ ifndef ISR ISR = $(MC1322X)/src/isr.o endif SRCOBJS += $(MC1322X)/src/default_lowlevel.o +BOARDOBJS := $(addprefix $(OBJDIR)/,$(COBJS)) ARCH = arm CPU = arm7tdmi-s @@ -28,16 +30,20 @@ export ARCH CPU VENDOR .SECONDARY: +#.depend: Makefile $(AOBJS:.o=.S) $(COBJS:.o=.c) +# $(CC) -M $(CFLAGS) $(AOBJS:.o=.S) $(COBJS:.o=.c) > $@ +#sinclude .depend + $(START): $(START:.o=.s) $(CC) $(AFLAGS) -c -o $@ $< $(ISR): $(ISR:.o=.c) $(CC) $(CFLAGS) $(ARM_FLAGS) $< -c -o $@ -%_$(BOARD).elf: %.elf +%_$(BOARD).elf: %.elf $(BOARDOBJS) mv $< $@ -%.elf: $(START) $(ISR) $(SRCOBJS) $(OBJDIR)/%.o $(LINKERSCRIPT) $(LIBMC1322X)/libmc1322x.a +%.elf: $(START) $(ISR) $(SRCOBJS) $(OBJDIR)/%.o $(BOARDOBJS) $(LINKERSCRIPT) $(LIBMC1322X)/libmc1322x.a $(CC) $(LDFLAGS) $(AOBJS) \ $(filter %.o %.a,$+) -o $@ diff --git a/board/Makefile.board b/board/Makefile.board index b187f2545..949231d05 100644 --- a/board/Makefile.board +++ b/board/Makefile.board @@ -4,7 +4,7 @@ BOARDS := redbee-dev redbee-r1 OBJDIR := obj_$(BOARD)_board -CFLAGS += -I$(OBJDIR) -I$(MC1322X)/board +CFLAGS += -I$(OBJDIR) -I$(MC1322X)/board -DBOARD=$(BOARD) $(OBJDIR): ifndef BOARD diff --git a/libmc1322x/include/mc1322x.h b/libmc1322x/include/mc1322x.h index fe7653e73..74041e3c9 100644 --- a/libmc1322x/include/mc1322x.h +++ b/libmc1322x/include/mc1322x.h @@ -4,5 +4,9 @@ #include "types.h" #include "isr.h" #include "gpio.h" +#include "crm.h" +#include "nvm.h" +#include "uart1.h" +#include "utils.h" #endif diff --git a/libmc1322x/include/utils.h b/libmc1322x/include/utils.h index 9b47defc3..215d3e3f9 100644 --- a/libmc1322x/include/utils.h +++ b/libmc1322x/include/utils.h @@ -1,8 +1,6 @@ #ifndef UTILS_H #define UTILS_H -#include - #define CAT2(x, y, z) x##y##z #define bit(bit) (1 << bit) diff --git a/tests/Makefile b/tests/Makefile index f1f05af76..0cb5f1daf 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,5 +1,11 @@ MC1322X := .. +# all off the common objects for each target +# a COBJ is made for EACH board and goes the obj_$(BOARD)_board directory +# board specific code is OK in these files +COBJS := tests.o put.o + +# all of the target programs to build TARGETS := blink-red blink-green blink-blue blink-white blink-allio uart1-loopback nvm-read nvm-write include $(MC1322X)/Makefile.include diff --git a/tests/nvm-read.c b/tests/nvm-read.c index 9f81bd50f..53d8ac02b 100644 --- a/tests/nvm-read.c +++ b/tests/nvm-read.c @@ -1,7 +1,7 @@ #include #include -#include -#include + +#include "tests.h" /* INC = 767; MOD = 9999 works: 115200 @ 24 MHz 16 bit sample */ #define INC 767 @@ -10,39 +10,15 @@ #define READ_ADDR 0x1F000 #define NBYTES 1024 -void putc(char c); -void puts(char *s); -void put_hex(uint8_t x); -void put_hex16(uint16_t x); -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'}; - - - void main(void) { nvmType_t type=0; nvmErr_t err; uint32_t buf[NBYTES/4]; uint32_t i; - /* Restore UART regs. to default */ - /* in case there is still bootloader state leftover */ + uart_init(INC, MOD); - *UART1_CON = 0x0000c800; /* mask interrupts, 16 bit sample --- helps explain the baud rate */ - - /* INC = 767; MOD = 9999 works: 115200 @ 24 MHz 16 bit sample */ - #define INC 767 - #define MOD 9999 - *UART1_BR = INC<<16 | MOD; - - /* see Section 11.5.1.2 Alternate Modes */ - /* you must enable the peripheral first BEFORE setting the function in GPIO_FUNC_SEL */ - /* From the datasheet: "The peripheral function will control operation of the pad IF */ - /* THE PERIPHERAL IS ENABLED. */ - *UART1_CON = 0x00000003; /* enable receive and transmit */ - *GPIO_FUNC_SEL0 = ( (0x01 << (14*2)) | (0x01 << (15*2)) ); /* set GPIO15-14 to UART (UART1 TX and RX)*/ + print_welcome("nvm-read"); vreg_init(); @@ -73,33 +49,3 @@ void main(void) { while(1) {continue;}; } -void putc(char c) { - while(*UT1CON == 31); /* wait for there to be room in the buffer */ - *UART1_DATA = c; -} - -void puts(char *s) { - while(s && *s!=0) { - putc(*s++); - } -} - -void put_hex(uint8_t x) -{ - putc(hex[x >> 4]); - putc(hex[x & 15]); -} - -void put_hex16(uint16_t x) -{ - put_hex((x >> 8) & 0xFF); - put_hex((x) & 0xFF); -} - -void put_hex32(uint32_t x) -{ - put_hex((x >> 24) & 0xFF); - put_hex((x >> 16) & 0xFF); - put_hex((x >> 8) & 0xFF); - put_hex((x) & 0xFF); -} diff --git a/tests/nvm-write.c b/tests/nvm-write.c index e52f83fe4..838bc51e0 100644 --- a/tests/nvm-write.c +++ b/tests/nvm-write.c @@ -1,7 +1,7 @@ #include #include -#include -#include + +#include "tests.h" /* INC = 767; MOD = 9999 works: 115200 @ 24 MHz 16 bit sample */ #define INC 767 @@ -12,34 +12,15 @@ #define WRITEVAL0 0xdeadbeef #define WRITEVAL1 0xdeadbeef -void putc(char c); -void puts(char *s); -void put_hex(uint8_t x); -void put_hex16(uint16_t x); -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'}; - void main(void) { nvmType_t type=0; nvmErr_t err; uint32_t buf[NBYTES/4]; uint32_t i; - *UART1_CON = 0x0000c800; /* mask interrupts, 16 bit sample --- helps explain the baud rate */ + uart_init(INC, MOD); - /* INC = 767; MOD = 9999 works: 115200 @ 24 MHz 16 bit sample */ - #define INC 767 - #define MOD 9999 - *UART1_BR = INC<<16 | MOD; - - /* see Section 11.5.1.2 Alternate Modes */ - /* you must enable the peripheral first BEFORE setting the function in GPIO_FUNC_SEL */ - /* From the datasheet: "The peripheral function will control operation of the pad IF */ - /* THE PERIPHERAL IS ENABLED. */ - *UART1_CON = 0x00000003; /* enable receive and transmit */ - *GPIO_FUNC_SEL0 = ( (0x01 << (14*2)) | (0x01 << (15*2)) ); /* set GPIO15-14 to UART (UART1 TX and RX)*/ + print_welcome("nvm-write"); vreg_init(); @@ -89,33 +70,3 @@ void main(void) { while(1) {continue;}; } -void putc(char c) { - while(*UT1CON == 31); /* wait for there to be room in the buffer */ - *UART1_DATA = c; -} - -void puts(char *s) { - while(s && *s!=0) { - putc(*s++); - } -} - -void put_hex(uint8_t x) -{ - putc(hex[x >> 4]); - putc(hex[x & 15]); -} - -void put_hex16(uint16_t x) -{ - put_hex((x >> 8) & 0xFF); - put_hex((x) & 0xFF); -} - -void put_hex32(uint32_t x) -{ - put_hex((x >> 24) & 0xFF); - put_hex((x >> 16) & 0xFF); - put_hex((x >> 8) & 0xFF); - put_hex((x) & 0xFF); -} diff --git a/tests/put.c b/tests/put.c new file mode 100644 index 000000000..34e336586 --- /dev/null +++ b/tests/put.c @@ -0,0 +1,36 @@ +#include +#include + +const uint8_t hex[16]={'0','1','2','3','4','5','6','7', + '8','9','a','b','c','d','e','f'}; + +void putc(char c) { + while(*UT1CON == 31); /* wait for there to be room in the buffer */ + *UART1_DATA = c; +} + +void puts(char *s) { + while(s && *s!=0) { + putc(*s++); + } +} + +void put_hex(uint8_t x) +{ + putc(hex[x >> 4]); + putc(hex[x & 15]); +} + +void put_hex16(uint16_t x) +{ + put_hex((x >> 8) & 0xFF); + put_hex((x) & 0xFF); +} + +void put_hex32(uint32_t x) +{ + put_hex((x >> 24) & 0xFF); + put_hex((x >> 16) & 0xFF); + put_hex((x >> 8) & 0xFF); + put_hex((x) & 0xFF); +} diff --git a/tests/put.h b/tests/put.h new file mode 100644 index 000000000..034b636ca --- /dev/null +++ b/tests/put.h @@ -0,0 +1,10 @@ +#ifndef PUT_H +#define PUT_H + +void putc(char c); +void puts(char *s); +void put_hex(uint8_t x); +void put_hex16(uint16_t x); +void put_hex32(uint32_t x); + +#endif diff --git a/tests/romimg.c b/tests/romimg.c index e29330e13..eb5af28af 100644 --- a/tests/romimg.c +++ b/tests/romimg.c @@ -1,19 +1,12 @@ -#define GPIO_FUNC_SEL0 0x80000018 /* GPIO 15 - 0; 2 bit blocks */ +#include +#include -#define BASE_UART1 0x80005000 -#define UART1_CON 0x80005000 -#define UART1_STAT 0x80005004 -#define UART1_DATA 0x80005008 -#define UR1CON 0x8000500c -#define UT1CON 0x80005010 -#define UART1_CTS 0x80005014 -#define UART1_BR 0x80005018 +#include "tests.h" +#include "put.h" -#include "embedded_types.h" - -#define reg(x) (*(volatile uint32_t *)(x)) - -#define DELAY 400000 +/* INC = 767; MOD = 9999 works: 115200 @ 24 MHz 16 bit sample */ +#define INC 767 +#define MOD 9999 void putc(uint8_t c); void puts(uint8_t *s); @@ -28,30 +21,11 @@ const uint8_t hex[16]={'0','1','2','3','4','5','6','7', #define DUMP_LEN 0x00014000 //#define DUMP_LEN 16 -#include "isr.h" - -__attribute__ ((section ("startup"))) void main(void) { volatile uint32_t i; -// volatile uint8_t *data; volatile uint8_t *data; - /* Restore UART regs. to default */ - /* in case there is still bootloader state leftover */ - - reg(UART1_CON) = 0x0000c800; /* mask interrupts, 16 bit sample --- helps explain the baud rate */ - - /* INC = 767; MOD = 9999 works: 115200 @ 24 MHz 16 bit sample */ - #define INC 767 - #define MOD 9999 - reg(UART1_BR) = INC<<16 | MOD; - - /* see Section 11.5.1.2 Alternate Modes */ - /* you must enable the peripheral first BEFORE setting the function in GPIO_FUNC_SEL */ - /* From the datasheet: "The peripheral function will control operation of the pad IF */ - /* THE PERIPHERAL IS ENABLED. */ - reg(UART1_CON) = 0x00000003; /* enable receive and transmit */ - reg(GPIO_FUNC_SEL0) = ( (0x01 << (14*2)) | (0x01 << (15*2)) ); /* set GPIO15-14 to UART (UART1 TX and RX)*/ + uart_init(inc, mod); for(data=DUMP_BASE; data<(DUMP_BASE+DUMP_LEN); data++) { putc(*data); diff --git a/tests/tests.c b/tests/tests.c new file mode 100644 index 000000000..2be580783 --- /dev/null +++ b/tests/tests.c @@ -0,0 +1,32 @@ +#include +#include "put.h" + +void uart_init(uint16_t inc, uint16_t mod) { + /* Restore UART regs. to default */ + /* in case there is still bootloader state leftover */ + + *UART1_CON = 0x0000c800; /* mask interrupts, 16 bit sample --- helps explain the baud rate */ + + /* INC = 767; MOD = 9999 works: 115200 @ 24 MHz 16 bit sample */ + *UART1_BR = (inc << 16) | mod; + + /* see Section 11.5.1.2 Alternate Modes */ + /* you must enable the peripheral first BEFORE setting the function in GPIO_FUNC_SEL */ + /* From the datasheet: "The peripheral function will control operation of the pad IF */ + /* THE PERIPHERAL IS ENABLED. */ + *UART1_CON = 0x00000003; /* enable receive and transmit */ + *GPIO_FUNC_SEL0 = ( (0x01 << (14*2)) | (0x01 << (15*2)) ); /* set GPIO15-14 to UART (UART1 TX and RX)*/ + +} + +void print_welcome(char* testname) { + puts("mc1322x-test: "); + puts(testname); + puts("\n\r"); + puts("board: "); +#if (BOARD == redbee-dev) + puts("redbee-dev"); +#elif (BOARD == redbee-r1) + puts("redbee-dev"); +#endif +} diff --git a/tests/tests.h b/tests/tests.h new file mode 100644 index 000000000..d3970d28a --- /dev/null +++ b/tests/tests.h @@ -0,0 +1,9 @@ +#ifndef TESTS_H +#define TESTS_H + +#include "put.h" + +void uart_init(uint16_t inc, uint16_t mod); +void print_welcome(char* testname); + +#endif diff --git a/tests/uart1-loopback.c b/tests/uart1-loopback.c index 487c31af6..1a12d2639 100644 --- a/tests/uart1-loopback.c +++ b/tests/uart1-loopback.c @@ -1,25 +1,13 @@ #include #include -#include + +#include "tests.h" /* INC = 767; MOD = 9999 works: 115200 @ 24 MHz 16 bit sample */ #define INC 767 #define MOD 9999 void main(void) { - - /* mask interrupts, 16 bit sample --- helps explain the baud rate */ - *UART1_CON = 0x0000c800; - - - *UART1_BR = INC<<16 | MOD; - - /* see Section 11.5.1.2 Alternate Modes */ - /* you must enable the peripheral first BEFORE setting the function in GPIO_FUNC_SEL */ - /* From the datasheet: "The peripheral function will control operation of the pad IF */ - /* THE PERIPHERAL IS ENABLED. */ - *UART1_CON = 0x00000003; /* enable receive and transmit */ - *GPIO_FUNC_SEL0 = ( (0x01 << (14*2)) | (0x01 << (15*2)) ); /* set GPIO15-14 to UART (UART1 TX and RX)*/ uint8_t c; while(1) {