Add console implementation on LPC2478 porting.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@11 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2009-07-31 04:10:48 +00:00
parent 53919ba500
commit 1df36ebf2f
2 changed files with 79 additions and 176 deletions

View File

@ -18,7 +18,7 @@
#include <LPC24xx.h> #include <LPC24xx.h>
#include "board.h" #include "board.h"
/* #define BOARD_DEBUG */ /* #define RT_BOARD_DEBUG */
#define DATA_COUNT 14400000/RT_TICK_PER_SECOND /* T0MR0 = delayInMs * (Fpclk / 1000); */ #define DATA_COUNT 14400000/RT_TICK_PER_SECOND /* T0MR0 = delayInMs * (Fpclk / 1000); */
@ -38,14 +38,60 @@ void rt_timer_handler(int vector)
VICVectAddr = 0; /* Acknowledge Interrupt */ 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 * This function will init LPC2478 board
*/ */
void rt_hw_board_init() void rt_hw_board_init()
{ {
extern void rt_serial_init(void); /* init console for rt_kprintf function */
/* init hardware serial */ rt_hw_console_init();
rt_serial_init();
T0IR = 0xff; T0IR = 0xff;
T0TC = 0; T0TC = 0;
@ -58,148 +104,4 @@ void rt_hw_board_init()
T0TCR = 0x01; //enable timer0 counter 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;
}
/*@}*/ /*@}*/

View File

@ -5,15 +5,20 @@
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * 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: * Change Logs:
* Date Author Notes * Date Author Notes
* 2008-12-11 xuxinming first version * 2008-12-11 xuxinming first version
*/ */
#include <rtthread.h>
#include <rthw.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 <LPC24xx.h>
#include <board.h> #include <board.h>
@ -23,46 +28,36 @@
*/ */
/*@{*/ /*@{*/
extern int rt_application_init(void);
#ifdef RT_USING_DEVICE
extern rt_err_t rt_hw_serial_init(void);
#endif
#ifdef __CC_ARM #ifdef __CC_ARM
extern int Image$$RW_IRAM1$$ZI$$Limit; extern int Image$$RW_IRAM1$$ZI$$Limit;
#else #else
extern char __rodata_start[]; extern int __bss_end;
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[];
#endif #endif
#ifdef RT_USING_FINSH
extern void finsh_system_init(void);
#endif
extern int rt_application_init(void);
/** /**
* This function will startup RT-Thread RTOS. * This function will startup RT-Thread RTOS.
*/ */
void rtthread_startup(void) void rtthread_startup(void)
{ {
/* init hardware Target */
// TargetResetInit();
/* init hardware interrupt */ /* init hardware interrupt */
rt_hw_interrupt_init(); rt_hw_interrupt_init();
/* init board */ /* init board */
rt_hw_board_init(); rt_hw_board_init();
rt_show_version();
/* init tick */ /* init tick */
rt_system_tick_init(); rt_system_tick_init();
/* init kernel object */ /* init kernel object */
rt_system_object_init(); rt_system_object_init();
rt_show_version();
/* init timer system */ /* init timer system */
rt_system_timer_init(); rt_system_timer_init();
@ -71,22 +66,27 @@ void rtthread_startup(void)
#ifdef __CC_ARM #ifdef __CC_ARM
rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x40010000); rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x40010000);
#else #else
rt_system_heap_init((void*)__Heap_start, 0x40010000); rt_system_heap_init((void*)&__bss_end, (void*)0x40010000);
#endif #endif
#endif #endif
/* init scheduler system */ /* init scheduler system */
rt_system_scheduler_init(); 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 */ /* init application */
rt_application_init(); rt_application_init();
#ifdef RT_USING_FINSH #ifdef RT_USING_FINSH
/* init the finsh input */
rt_hw_finsh_init();
/* init finsh */ /* init finsh */
finsh_system_init(); finsh_system_init();
finsh_set_device("uart1");
#endif #endif
/* init idle thread */ /* init idle thread */
@ -102,6 +102,7 @@ void rtthread_startup(void)
#ifdef __CC_ARM #ifdef __CC_ARM
int main(void) int main(void)
{ {
/* invoke rtthread_startup */
rtthread_startup(); rtthread_startup();
return 0; return 0;