diff options
Diffstat (limited to 'bsp')
| -rw-r--r-- | bsp/lpc2478/board.c | 202 | ||||
| -rw-r--r-- | bsp/lpc2478/startup.c | 53 |
2 files changed, 79 insertions, 176 deletions
diff --git a/bsp/lpc2478/board.c b/bsp/lpc2478/board.c index 26059b5072..d08e1aa763 100644 --- a/bsp/lpc2478/board.c +++ b/bsp/lpc2478/board.c @@ -18,7 +18,7 @@ #include <LPC24xx.h> #include "board.h" -/* #define BOARD_DEBUG */ +/* #define RT_BOARD_DEBUG */ #define DATA_COUNT 14400000/RT_TICK_PER_SECOND /* T0MR0 = delayInMs * (Fpclk / 1000); */ @@ -36,17 +36,63 @@ void rt_timer_handler(int vector) T0IR |= 0x01; /* clear interrupt flag */ rt_tick_increase(); VICVectAddr = 0; /* Acknowledge Interrupt */ -} +}
+
+ +/**
+ * This function is used to display a string on console, normally, it's
+ * invoked by rt_kprintf
+ *
+ * @param str the displayed string
+ */
+void rt_hw_console_output(const char* str)
+{
+ while (*str)
+ {
+ if (*str=='\n')
+ {
+ while (!(U0LSR & 0x20));
+ U0THR = '\r';
+ }
+
+ while (!(U0LSR & 0x20));
+ U0THR = *str;
+
+ str ++;
+ }
+}
+
+#define BAUD_RATE 115200
+#define U0PINS 0x50
+void rt_hw_console_init()
+{
+ rt_uint32_t fdiv;
+
+ /* Enable RxD and TxD pins */
+ PINSEL0 = U0PINS;
+
+ /* 8 bits, no Parity, 1 Stop bit */
+ U0LCR = 0x83;
+
+ /* Setup Baudrate */
+ fdiv = ( PCLK / 16 ) / BAUD_RATE ; /*baud rate */
+ U0DLM = fdiv / 256;
+ U0DLL = fdiv % 256;
+ U0FCR = 0x00; /* Enable and reset TX and RX FIFO. */
+ U0LCR = 0x03; /* DLAB = 0 */
+
+ /* DLAB = 0 */
+ U0LCR = 0x03;
+}
/** * This function will init LPC2478 board */ void rt_hw_board_init() {
- extern void rt_serial_init(void); - /* init hardware serial */ - rt_serial_init();
- + /* init console for rt_kprintf function */ + rt_hw_console_init();
+ T0IR = 0xff; T0TC = 0; T0MCR = 0x03; @@ -58,148 +104,4 @@ void rt_hw_board_init() T0TCR = 0x01; //enable timer0 counter } -/****************************************************************************** -** Function name: TargetInit -** -** Descriptions: Initialize the target board; it is called in a necessary -** place, change it as needed -** -** parameters: None -** Returned value: None -** -******************************************************************************/ -void TargetInit(void) -{ - /* Add your codes here */ - return; -} - -/****************************************************************************** -** Function name: GPIOResetInit -** -** Descriptions: Initialize the target board before running the main() -** function; User may change it as needed, but may not -** deleted it. -** -** parameters: None -** Returned value: None -** -******************************************************************************/ -void GPIOResetInit( void ) -{ - return; -} - -/****************************************************************************** -** Function name: ConfigurePLL -** -** Descriptions: Configure PLL switching to main OSC instead of IRC -** at power up and wake up from power down. -** This routine is used in TargetResetInit() and those -** examples using power down and wake up such as -** USB suspend to resume, ethernet WOL, and power management -** example -** parameters: None -** Returned value: None -** -******************************************************************************/ -void ConfigurePLL ( void ) -{ - unsigned long MValue, NValue; - - if ( PLLSTAT & (1 << 25) ) - { - PLLCON = 1; /* Enable PLL, disconnected */ - PLLFEED = 0xaa; - PLLFEED = 0x55; - } - - PLLCON = 0; /* Disable PLL, disconnected */ - PLLFEED = 0xaa; - PLLFEED = 0x55; - - SCS |= 0x20; /* Enable main OSC */ - while( !(SCS & 0x40) ); /* Wait until main OSC is usable */ - - CLKSRCSEL = 0x1; /* select main OSC, 12MHz, as the PLL clock source */ - - PLLCFG = PLL_MValue | (PLL_NValue << 16); - PLLFEED = 0xaa; - PLLFEED = 0x55; - - PLLCON = 1; /* Enable PLL, disconnected */ - PLLFEED = 0xaa; - PLLFEED = 0x55; - - CCLKCFG = CCLKDivValue; /* Set clock divider */ -#if USE_USB - USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ -#endif - - while ( ((PLLSTAT & (1 << 26)) == 0) ); /* Check lock bit status */ - - MValue = PLLSTAT & 0x00007FFF; - NValue = (PLLSTAT & 0x00FF0000) >> 16; - while ((MValue != PLL_MValue) && ( NValue != PLL_NValue) ); - - PLLCON = 3; /* enable and connect */ - PLLFEED = 0xaa; - PLLFEED = 0x55; - while ( ((PLLSTAT & (1 << 25)) == 0) ); /* Check connect bit status */ - return; -} - -/****************************************************************************** -** Function name: TargetResetInit -** -** Descriptions: Initialize the target board before running the main() -** function; User may change it as needed, but may not -** deleted it. -** -** parameters: None -** Returned value: None -** -******************************************************************************/ -void TargetResetInit(void) -{
- MEMMAP = 0x1; /* remap to internal flash */ - -#if USE_USB - PCONP |= 0x80000000; /* Turn On USB PCLK */ -#endif - /* Configure PLL, switch from IRC to Main OSC */ - ConfigurePLL(); - - /* Set system timers for each component */ -#if (Fpclk / (Fcclk / 4)) == 1 - PCLKSEL0 = 0x00000000; /* PCLK is 1/4 CCLK */ - PCLKSEL1 = 0x00000000; -#endif -#if (Fpclk / (Fcclk / 4)) == 2 - PCLKSEL0 = 0xAAAAAAAA; /* PCLK is 1/2 CCLK */ - PCLKSEL1 = 0xAAAAAAAA; -#endif -#if (Fpclk / (Fcclk / 4)) == 4 - PCLKSEL0 = 0x55555555; /* PCLK is the same as CCLK */ - PCLKSEL1 = 0x55555555; -#endif - - /* Set memory accelerater module*/ - MAMCR = 0; -#if Fcclk < 20000000 - MAMTIM = 1; -#else -#if Fcclk < 40000000 - MAMTIM = 2; -#else - MAMTIM = 3; -#endif -#endif - MAMCR = 2; - - GPIOResetInit(); - - return; -} - /*@}*/ diff --git a/bsp/lpc2478/startup.c b/bsp/lpc2478/startup.c index 289d97b7b9..2ea112c8e0 100644 --- a/bsp/lpc2478/startup.c +++ b/bsp/lpc2478/startup.c @@ -5,15 +5,20 @@ * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at - * http://openlab.rt-thread.com/license/LICENSE + * http://www.rt-thread.org/license/LICENSE * * Change Logs: * Date Author Notes * 2008-12-11 xuxinming first version */ -#include <rtthread.h> #include <rthw.h> +#include <rtthread.h>
+ +#ifdef RT_USING_FINSH
+#include <finsh.h>
+extern void finsh_system_init(void); +#endif
#include <LPC24xx.h> #include <board.h> @@ -23,46 +28,36 @@ */ /*@{*/ -#ifdef __CC_ARM -extern int Image$$RW_IRAM1$$ZI$$Limit;
-#else -extern char __rodata_start[]; -extern char __rodata_end[]; -extern char __data_start[]; -extern char __bss_start[]; -extern char __data_end[]; -extern char __bss_end[]; -extern char __Heap_start[]; -extern char __Heap_end[]; +extern int rt_application_init(void); +#ifdef RT_USING_DEVICE
+extern rt_err_t rt_hw_serial_init(void);
#endif -#ifdef RT_USING_FINSH -extern void finsh_system_init(void); -#endif -extern int rt_application_init(void); +#ifdef __CC_ARM +extern int Image$$RW_IRAM1$$ZI$$Limit;
+#else
+extern int __bss_end;
+#endif
/** * This function will startup RT-Thread RTOS. */ void rtthread_startup(void) { - /* init hardware Target */ - // TargetResetInit(); -
/* init hardware interrupt */ rt_hw_interrupt_init(); /* init board */ rt_hw_board_init(); - rt_show_version(); -
/* init tick */ rt_system_tick_init(); /* init kernel object */ rt_system_object_init(); + rt_show_version(); + /* init timer system */ rt_system_timer_init(); @@ -71,22 +66,27 @@ void rtthread_startup(void) #ifdef __CC_ARM rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x40010000); #else - rt_system_heap_init((void*)__Heap_start, 0x40010000); + rt_system_heap_init((void*)&__bss_end, (void*)0x40010000);
#endif #endif /* init scheduler system */ rt_system_scheduler_init(); +#ifdef RT_USING_DEVICE
+ /* init hardware serial device */
+ rt_hw_serial_init();
+
+ /*init all registed devices*/
+ rt_device_init_all();
+#endif
/* init application */ rt_application_init(); #ifdef RT_USING_FINSH - /* init the finsh input */ - rt_hw_finsh_init(); - /* init finsh */ finsh_system_init(); + finsh_set_device("uart1"); #endif /* init idle thread */ @@ -102,6 +102,7 @@ void rtthread_startup(void) #ifdef __CC_ARM int main(void)
{
+ /* invoke rtthread_startup */
rtthread_startup();
return 0;
|
