From 9a8004c177af3acd7e78890c8439430905129f76 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Fri, 26 Feb 2010 12:37:13 -0500 Subject: [PATCH] working on nvm-read. fixed lib ordering on link command --- Makefile.include | 8 +- board/Makefile.board | 2 +- board/redbee-r1.h | 2 + board/std_conf.h | 4 +- config.mk | 4 +- libmc1322x/Makefile.lib | 2 +- libmc1322x/include/crm.h | 100 +++++++++++++++++++++ libmc1322x/nvm.c | 1 + board/lowlevel.c => src/default_lowlevel.c | 1 + board/lowlevel.h => src/default_lowlevel.h | 0 tests/nvm-read.c | 13 +-- 11 files changed, 122 insertions(+), 15 deletions(-) create mode 100644 libmc1322x/include/crm.h rename board/lowlevel.c => src/default_lowlevel.c (95%) rename board/lowlevel.h => src/default_lowlevel.h (100%) diff --git a/Makefile.include b/Makefile.include index 1631fa113..223372291 100644 --- a/Makefile.include +++ b/Makefile.include @@ -12,12 +12,15 @@ include $(MC1322X)/board/Makefile.board include $(MC1322X)/libmc1322x/Makefile.lib # default start and isr +CFLAGS += -I$(MC1322X)/src + ifndef START START = $(MC1322X)/src/start.o endif ifndef ISR ISR = $(MC1322X)/src/isr.o endif +SRCOBJS += $(MC1322X)/src/default_lowlevel.o ARCH = arm CPU = arm7tdmi-s @@ -34,9 +37,8 @@ $(ISR): $(ISR:.o=.c) %_$(BOARD).elf: %.elf mv $< $@ -%.elf: $(START) $(ISR) $(LIBMC1322X)/libmc1322x.a $(OBJDIR)/%.o $(LINKERSCRIPT) - $(LD) $(LDFLAGS) $(AOBJS) \ - --start-group $(PLATFORM_LIBS) --end-group \ +%.elf: $(START) $(ISR) $(SRCOBJS) $(OBJDIR)/%.o $(LINKERSCRIPT) $(LIBMC1322X)/libmc1322x.a + $(CC) $(LDFLAGS) $(AOBJS) \ $(filter %.o %.a,$+) -o $@ %.srec: %.elf diff --git a/board/Makefile.board b/board/Makefile.board index 92c63c15a..b187f2545 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) +CFLAGS += -I$(OBJDIR) -I$(MC1322X)/board $(OBJDIR): ifndef BOARD diff --git a/board/redbee-r1.h b/board/redbee-r1.h index e4a77f438..79bde2d4e 100644 --- a/board/redbee-r1.h +++ b/board/redbee-r1.h @@ -1,6 +1,8 @@ #ifndef BOARD_REDBEE_R1_H #define BOARD_REDBEE_R1_H +#include + #define LED_RED (1 << 8) #define LED_GREEN (1 << 9) #define LED_BLUE (1 << 10) diff --git a/board/std_conf.h b/board/std_conf.h index ee7954670..e6376a7f9 100644 --- a/board/std_conf.h +++ b/board/std_conf.h @@ -1,7 +1,9 @@ #ifndef STDCONF_H #define STDCONF_H -#ifndef vreg_init() +#include + +#ifndef vreg_init #define vreg_init() default_vreg_init() #endif diff --git a/config.mk b/config.mk index dd1c073c1..7740c06ec 100644 --- a/config.mk +++ b/config.mk @@ -27,8 +27,6 @@ OBJCFLAGS += --gap-fill=0xff gccincdir := $(shell $(CC) -print-file-name=include) -PLATFORM_LIBS += --no-warn-mismatch -L $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-name`) -lgcc - CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \ -D__KERNEL__ -DTEXT_BASE=$(TEXT_BASE) \ -fno-builtin -ffreestanding -nostdinc -isystem \ @@ -39,7 +37,7 @@ CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wcast-align -Wcast-align AFLAGS_DEBUG := -Wa,-gstabs AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) -LDFLAGS += -T $(LINKERSCRIPT) -nostartfiles -static -Map=$*.map -export-dynamic +LDFLAGS += -T $(LINKERSCRIPT) -nostartfiles -static -Wl,-Map=$*.map -export-dynamic ######################################################################### diff --git a/libmc1322x/Makefile.lib b/libmc1322x/Makefile.lib index 3a5a15c32..51ce030c0 100644 --- a/libmc1322x/Makefile.lib +++ b/libmc1322x/Makefile.lib @@ -5,4 +5,4 @@ CFLAGS += -I$(LIBMC1322X)/include LIBOBJS = $(patsubst %.c,%.o,$(wildcard $(LIBMC1322X)/*.c)) $(LIBMC1322X)/libmc1322x.a: $(LIBOBJS) - $(AR) r $(LIBMC1322X)/libmc1322x.a $(LIBOBJS) + $(AR) rcs $(LIBMC1322X)/libmc1322x.a $(LIBOBJS) diff --git a/libmc1322x/include/crm.h b/libmc1322x/include/crm.h new file mode 100644 index 000000000..068b335d2 --- /dev/null +++ b/libmc1322x/include/crm.h @@ -0,0 +1,100 @@ +#ifndef CRM_H +#define CRM_H + +#include + +#define CRM_BASE (0x80003000) +#define CRM_SYS_CNTL ((volatile uint32_t *) (CRM_BASE+0x00)) +#define CRM_WU_CNTL ((volatile uint32_t *) (CRM_BASE+0x04)) +#define CRM_SLEEP_CNTL ((volatile uint32_t *) (CRM_BASE+0x08)) +#define CRM_BS_CNTL ((volatile uint32_t *) (CRM_BASE+0x0c)) +#define CRM_COP_CNTL ((volatile uint32_t *) (CRM_BASE+0x10)) +#define CRM_COP_SERVICE ((volatile uint32_t *) (CRM_BASE+0x14)) +#define CRM_STATUS ((volatile uint32_t *) (CRM_BASE+0x18)) +#define CRM_MOD_STATUS ((volatile uint32_t *) (CRM_BASE+0x1c)) +#define CRM_WU_COUNT ((volatile uint32_t *) (CRM_BASE+0x20)) +#define CRM_WU_TIMEOUT ((volatile uint32_t *) (CRM_BASE+0x24)) +#define CRM_RTC_COUNT ((volatile uint32_t *) (CRM_BASE+0x28)) +#define CRM_RTC_TIMEOUT ((volatile uint32_t *) (CRM_BASE+0x2c)) +#define CRM_CAL_CNTL ((volatile uint32_t *) (CRM_BASE+0x34)) +#define CRM_CAL_COUNT ((volatile uint32_t *) (CRM_BASE+0x38)) +#define CRM_RINGOSC_CNTL ((volatile uint32_t *) (CRM_BASE+0x3c)) +#define CRM_XTAL_CNTL ((volatile uint32_t *) (CRM_BASE+0x40)) +#define CRM_XTAL32_CNTL ((volatile uint32_t *) (CRM_BASE+0x44)) +#define CRM_VREG_CNTL ((volatile uint32_t *) (CRM_BASE+0x48)) +#define CRM_SW_RST ((volatile uint32_t *) (CRM_BASE+0x50)) + +/* CRM_SYS_CNTL bit locations */ +#define XTAL32_EXISTS 5 + +/* CRM_WU_CNTL bit locations */ +#define EXT_WU_IEN 20 /* 4 bits */ +#define EXT_WU_EN 4 /* 4 bits */ +#define EXT_WU_EDGE 8 /* 4 bits */ +#define EXT_WU_POL 12 /* 4 bits */ +#define TIMER_WU_EN 0 +#define RTC_WU_EN 1 +#define TIMER_WU_IEN 16 +#define RTC_WU_IEN 17 + +/* CRM_STATUS bit locations */ +#define EXT_WU_EVT 4 /* 4 bits, rw1c */ +#define RTC_WU_EVT 3 /* rw1c */ + +/* RINGOSC_CNTL bit locations */ +#define ROSC_CTUNE 9 /* 4 bits */ +#define ROSC_FTUNE 4 /* 4 bits */ +#define ROSC_EN 0 + +#define ring_osc_on() (set_bit(reg32(CRM_RINGOSC_CNTL),ROSC_EN)) +#define ring_osc_off() (clear_bit(reg32(CRM_RINGOSC_CNTL),ROSC_EN)) + +#define REF_OSC 24000000ULL /* reference osc. frequency */ +#define NOMINAL_RING_OSC_SEC 2000 /* nominal ring osc. frequency */ +//extern uint32_t cal_rtc_secs; /* calibrated 2khz rtc seconds */ + +/* XTAL32_CNTL bit locations */ +#define XTAL32_GAIN 4 /* 2 bits */ +#define XTAL32_EN 0 + +#define xtal32_on() (set_bit(reg32(CRM_XTAL32_CNTL),XTAL32_EN)) +#define xtal32_off() (clear_bit(reg32(CRM_XTAL32_CNTL),XTAL32_EN)) +#define xtal32_exists() (set_bit(reg32(CRM_SYS_CNTL),XTAL32_EXISTS)) + +/* enable external wake-ups on kbi 4-7 */ +/* see kbi.h for other kbi specific macros */ +#define enable_ext_wu(kbi) (set_bit(reg32(CRM_WU_CNTL),(EXT_WU_EN+kbi-4))) +#define disable_ext_wu(kbi) (clear_bit(reg32(CRM_WU_CNTL),(EXT_WU_EN+kbi-4))) + +#define is_ext_wu_evt(kbi) (bit_is_set(reg32(CRM_STATUS),(EXT_WU_EVT+kbi-4))) +#define clear_ext_wu_evt(kbi) (set_bit(reg32(CRM_STATUS),(EXT_WU_EVT+kbi-4))) /* r1wc bit */ + +/* enable wake-up timer */ +#define enable_timer_wu_irq() ((set_bit(reg32(CRM_WU_CNTL),(TIMER_WU_IEN)))) +#define disable_timer_wu_irq() ((clear_bit(reg32(CRM_WU_CNTL),(TIMER_WU_IEN)))) + +#define enable_timer_wu() ((set_bit(reg32(CRM_WU_CNTL),(TIMER_WU_EN)))) +#define disable_timer_wu() ((clear_bit(reg32(CRM_WU_CNTL),(TIMER_WU_EN)))) + +/* enable wake-up from RTC compare */ +#define enable_rtc_wu_irq() (set_bit(reg32(CRM_WU_CNTL),RTC_WU_IEN)) +#define disable_rtc_wu_irq() (clear_bit(reg32(CRM_WU_CNTL),RTC_WU_IEN)) + +#define enable_rtc_wu() ((set_bit(reg32(CRM_WU_CNTL),(RTC_WU_EN)))) +#define disable_rtc_wu() ((clear_bit(reg32(CRM_WU_CNTL),(RTC_WU_EN)))) + +#define clear_rtc_wu_evt() (set_bit(reg32(CRM_STATUS),RTC_WU_EVT)) +#define rtc_wu_evt() (bit_is_set(reg32(CRM_STATUS),RTC_WU_EVT)) + +#define SLEEP_MODE_HIBERNATE bit(0) +#define SLEEP_MODE_DOZE bit(1) + +#define SLEEP_PAD_PWR bit(7) +#define SLEEP_RETAIN_MCU bit(6) +#define sleep_ram_retain(x) (x<<4) /* 0-3 */ +#define SLEEP_RAM_8K sleep_ram_retain(0) +#define SLEEP_RAM_32K sleep_ram_retain(1) +#define SLEEP_RAM_64K sleep_ram_retain(2) +#define SLEEP_RAM_96K sleep_ram_retain(3) + +#endif diff --git a/libmc1322x/nvm.c b/libmc1322x/nvm.c index 15f823dd9..5bd902084 100644 --- a/libmc1322x/nvm.c +++ b/libmc1322x/nvm.c @@ -19,3 +19,4 @@ volatile nvmErr_t (*nvm_erase) volatile void(*nvm_setsvar) (uint32_t zero_for_awesome) = (void *)0x00007085; + diff --git a/board/lowlevel.c b/src/default_lowlevel.c similarity index 95% rename from board/lowlevel.c rename to src/default_lowlevel.c index c12b96dbe..c1df5c9fe 100644 --- a/board/lowlevel.c +++ b/src/default_lowlevel.c @@ -1,3 +1,4 @@ +#include #include void default_vreg_init(void) { diff --git a/board/lowlevel.h b/src/default_lowlevel.h similarity index 100% rename from board/lowlevel.h rename to src/default_lowlevel.h diff --git a/tests/nvm-read.c b/tests/nvm-read.c index 2bfd28fc7..7cbbc2d4c 100644 --- a/tests/nvm-read.c +++ b/tests/nvm-read.c @@ -1,6 +1,7 @@ #include #include #include +#include /* INC = 767; MOD = 9999 works: 115200 @ 24 MHz 16 bit sample */ #define INC 767 @@ -29,19 +30,19 @@ void main(void) { /* 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 */ + *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; + *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)*/ + *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)*/ vreg_init(); @@ -77,8 +78,8 @@ void main(void) { } void putc(uint8_t c) { - while(reg(UT1CON)==31); /* wait for there to be room in the buffer */ - reg(UART1_DATA) = c; + while(*UT1CON == 31); /* wait for there to be room in the buffer */ + *UART1_DATA = c; } void puts(uint8_t *s) {