diff options
Diffstat (limited to '')
-rw-r--r-- | c/src/lib/libbsp/arm/lpc24xx/startup/bspstart.c | 138 |
1 files changed, 84 insertions, 54 deletions
diff --git a/c/src/lib/libbsp/arm/lpc24xx/startup/bspstart.c b/c/src/lib/libbsp/arm/lpc24xx/startup/bspstart.c index 50483d49d9..20f3f17fbe 100644 --- a/c/src/lib/libbsp/arm/lpc24xx/startup/bspstart.c +++ b/c/src/lib/libbsp/arm/lpc24xx/startup/bspstart.c @@ -23,9 +23,12 @@ #include <bsp.h> #include <bsp/bootcard.h> #include <bsp/dma.h> +#include <bsp/io.h> +#include <bsp/irq-generic.h> #include <bsp/irq.h> #include <bsp/linker-symbols.h> #include <bsp/lpc24xx.h> +#include <bsp/stackalloc.h> #include <bsp/start.h> #include <bsp/system-clocks.h> @@ -38,15 +41,17 @@ static void lpc24xx_fatal_error( void) static void lpc24xx_ram_test_32( void) { - volatile unsigned *out = (volatile unsigned *) bsp_ram_ext_start; + const unsigned *end = (const unsigned *) bsp_region_data_end; + unsigned *begin = (unsigned *) bsp_region_data_begin; + unsigned *out = begin; - while (out < (volatile unsigned *) bsp_ram_ext_end) { + while (out != end) { *out = (unsigned) out; ++out; } - out = (volatile unsigned *) bsp_ram_ext_start; - while (out < (volatile unsigned *) bsp_ram_ext_end) { + out = begin; + while (out != end) { if (*out != (unsigned) out) { lpc24xx_fatal_error(); } @@ -65,14 +70,11 @@ static void lpc24xx_init_emc( void) int i = 0; uint32_t mode = 0; - /* Enable power */ - PCONP = SET_FLAGS( PCONP, 0x0800); + /* Enable module power */ + lpc24xx_module_enable( LPC24XX_MODULE_EMC, 0, LPC24XX_MODULE_PCLK_DEFAULT); - /* Set PIN selects */ - PINSEL5 = SET_FLAGS( PINSEL5, 0x05050555); - PINSEL6 = SET_FLAGS( PINSEL6, 0x55555555); - PINSEL8 = SET_FLAGS( PINSEL8, 0x55555555); - PINSEL9 = SET_FLAGS( PINSEL9, 0x50555555); + /* IO configuration */ + lpc24xx_io_config( LPC24XX_MODULE_EMC, 0, 0); /* Enable module, normal memory map and normal power mode */ EMC_CTRL = 1; @@ -166,14 +168,8 @@ static void lpc24xx_init_emc( void) /* Enable buffer */ EMC_DYN_CFG0 |= 0x00080000; - /* Static Memory 0 settings */ - EMC_STA_WAITWEN0 = 0x02; - EMC_STA_WAITOEN0 = 0x02; - EMC_STA_WAITRD0 = 0x1f; - EMC_STA_WAITPAGE0 = 0x1f; - EMC_STA_WAITWR0 = 0x1f; - EMC_STA_WAITTURN0 = 0x0f; - EMC_STA_CFG0 = 0x81; + /* Extended wait register */ + EMC_STA_EXT_WAIT = 0; /* Static Memory 1 settings */ EMC_STA_WAITWEN1 = 0x02; @@ -182,25 +178,25 @@ static void lpc24xx_init_emc( void) EMC_STA_WAITPAGE1 = 0x1f; EMC_STA_WAITWR1 = 0x08; EMC_STA_WAITTURN1 = 0x0f; - EMC_STA_CFG1 = 0x80; + EMC_STA_CFG1 = 0x81; /* RAM test */ lpc24xx_ram_test_32(); - #endif /* LPC24XX_EMC_MICRON */ + #endif } static void lpc24xx_init_pll( void) { #ifndef LPC24XX_HAS_UBOOT /* Enable main oscillator */ - SCS = SET_FLAGS( SCS, 0x20); + SCS = SET_FLAG( SCS, 0x20); while (IS_FLAG_CLEARED( SCS, 0x40)) { /* Wait */ } /* Set PLL */ lpc24xx_set_pll( 1, 0, 11, 3); - #endif /* LPC24XX_HAS_UBOOT */ + #endif } void /* __attribute__ ((section (".entry"))) */ bsp_start_hook_0( void) @@ -221,6 +217,19 @@ void /* __attribute__ ((section (".entry"))) */ bsp_start_hook_0( void) PINSEL8 = 0; PINSEL9 = 0; PINSEL10 = 0; + PINSEL11 = 0; + + /* Set pin modes */ + PINMODE0 = 0; + PINMODE1 = 0; + PINMODE2 = 0; + PINMODE3 = 0; + PINMODE4 = 0; + PINMODE5 = 0; + PINMODE6 = 0; + PINMODE7 = 0; + PINMODE8 = 0; + PINMODE9 = 0; /* Set periperal clocks */ PCLKSEL0 = 0; @@ -233,11 +242,8 @@ void /* __attribute__ ((section (".entry"))) */ bsp_start_hook_0( void) MAMCR = 0; MAMTIM = 4; - /* Set general purpose IO */ - IODIR0 = 0; - IODIR1 = 0; - IOSET0 = 0xffffffff; - IOSET1 = 0xffffffff; + /* Enable fast IO for ports 0 and 1 */ + SCS = SET_FLAG( SCS, 0x1); /* Set fast IO */ FIO0DIR = 0; @@ -245,51 +251,53 @@ void /* __attribute__ ((section (".entry"))) */ bsp_start_hook_0( void) FIO2DIR = 0; FIO3DIR = 0; FIO4DIR = 0; - FIO0SET = 0xffffffff; - FIO1SET = 0xffffffff; - FIO2SET = 0xffffffff; - FIO3SET = 0xffffffff; - FIO4SET = 0xffffffff; - - /* Initialize UART 0 */ - PCONP = SET_FLAGS( PCONP, 0x08); - PCLKSEL0 = SET_FLAGS( PCLKSEL0, 0x40); - PINSEL0 = SET_FLAGS( PINSEL0, 0x50); - U0LCR = 0; - U0IER = 0; - U0LCR = 0x80; - U0DLL = lpc24xx_cclk() / 16 / LPC24XX_UART_BAUD; - U0DLM = 0; - U0LCR = 0x03; - U0FCR = 0x07; + FIO0CLR = 0xffffffff; + FIO1CLR = 0xffffffff; + FIO2CLR = 0xffffffff; + FIO3CLR = 0xffffffff; + FIO4CLR = 0xffffffff; + + /* Initialize console */ + #ifdef LPC24XX_CONFIG_CONSOLE + lpc24xx_module_enable( LPC24XX_MODULE_UART, 0, LPC24XX_MODULE_CCLK); + lpc24xx_io_config( LPC24XX_MODULE_UART, 0, LPC24XX_CONFIG_CONSOLE); + U0LCR = 0; + U0IER = 0; + U0LCR = 0x80; + U0DLL = lpc24xx_cclk() / 16 / LPC24XX_UART_BAUD; + U0DLM = 0; + U0LCR = 0x03; + U0FCR = 0x07; + #endif /* Initialize Timer 1 */ - PCONP = SET_FLAGS( PCONP, 0x04); - PCLKSEL0 = SET_FLAGS( PCLKSEL0, 0x10); - #endif /* LPC24XX_HAS_UBOOT */ + lpc24xx_module_enable( LPC24XX_MODULE_TIMER, 1, LPC24XX_MODULE_CCLK); + #endif } static void lpc24xx_copy_data( void) { #ifndef LPC24XX_HAS_UBOOT - unsigned *in = bsp_section_text_end; - unsigned *out = bsp_section_data_start; + const unsigned *end = (const unsigned *) bsp_section_data_end; + unsigned *in = (unsigned *) bsp_section_data_load_begin; + unsigned *out = (unsigned *) bsp_section_data_begin; /* Copy data */ - while (out < bsp_section_data_end) { + while (out != end) { *out = *in; ++out; ++in; } - #endif /* LPC24XX_HAS_UBOOT */ + #endif } static void lpc24xx_clear_bss( void) { - unsigned *out = bsp_section_bss_start; + const unsigned *end = (const unsigned *) bsp_section_bss_end; + unsigned *out = (unsigned *) bsp_section_bss_begin; /* Clear BSS */ - while (out < bsp_section_bss_end) { + while (out != end) { *out = 0; ++out; } @@ -315,7 +323,9 @@ void bsp_start( void) printk( "CPU clock (CCLK): %u\n", lpc24xx_cclk()); /* Exceptions */ + /* FIXME rtems_exception_init_mngt(); + */ /* Interrupts */ if (bsp_interrupt_initialize() != RTEMS_SUCCESSFUL) { @@ -326,6 +336,26 @@ void bsp_start( void) /* DMA */ lpc24xx_dma_initialize(); + + /* Task stacks */ + bsp_stack_initialize( + bsp_section_stack_begin, + (intptr_t) bsp_section_stack_size + ); + + /* UART configurations */ + #ifdef LPC24XX_CONFIG_UART_1 + lpc24xx_module_enable( LPC24XX_MODULE_UART, 1, LPC24XX_MODULE_CCLK); + lpc24xx_io_config( LPC24XX_MODULE_UART, 1, LPC24XX_CONFIG_UART_1); + #endif + #ifdef LPC24XX_CONFIG_UART_2 + lpc24xx_module_enable( LPC24XX_MODULE_UART, 2, LPC24XX_MODULE_CCLK); + lpc24xx_io_config( LPC24XX_MODULE_UART, 2, LPC24XX_CONFIG_UART_2); + #endif + #ifdef LPC24XX_CONFIG_UART_3 + lpc24xx_module_enable( LPC24XX_MODULE_UART, 3, LPC24XX_MODULE_CCLK); + lpc24xx_io_config( LPC24XX_MODULE_UART, 3, LPC24XX_CONFIG_UART_3); + #endif } #define ULSR_THRE 0x00000020U |