From dd47ccd6ca397e0d50d38eaaad6fa3509d424c3b Mon Sep 17 00:00:00 2001 From: wuyangyong Date: Tue, 20 Dec 2011 09:11:13 +0000 Subject: update bsp lpc2478. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1853 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- bsp/lpc2478/SConscript | 17 +- bsp/lpc2478/SConstruct | 4 +- bsp/lpc2478/application.c | 26 --- bsp/lpc2478/applications/SConscript | 11 + bsp/lpc2478/applications/application.c | 26 +++ bsp/lpc2478/applications/startup.c | 112 ++++++++++ bsp/lpc2478/board.c | 58 ----- bsp/lpc2478/board.h | 119 ---------- bsp/lpc2478/drivers/SConscript | 22 ++ bsp/lpc2478/drivers/board.c | 58 +++++ bsp/lpc2478/drivers/board.h | 123 +++++++++++ bsp/lpc2478/drivers/serial.c | 389 +++++++++++++++++++++++++++++++++ bsp/lpc2478/project.Uv2 | 88 ++++---- bsp/lpc2478/rtconfig.h | 2 - bsp/lpc2478/rtconfig.py | 11 +- bsp/lpc2478/startup.c | 112 ---------- 16 files changed, 804 insertions(+), 374 deletions(-) delete mode 100644 bsp/lpc2478/application.c create mode 100644 bsp/lpc2478/applications/SConscript create mode 100644 bsp/lpc2478/applications/application.c create mode 100644 bsp/lpc2478/applications/startup.c delete mode 100644 bsp/lpc2478/board.c delete mode 100644 bsp/lpc2478/board.h create mode 100644 bsp/lpc2478/drivers/SConscript create mode 100644 bsp/lpc2478/drivers/board.c create mode 100644 bsp/lpc2478/drivers/board.h create mode 100644 bsp/lpc2478/drivers/serial.c delete mode 100644 bsp/lpc2478/startup.c (limited to 'bsp') diff --git a/bsp/lpc2478/SConscript b/bsp/lpc2478/SConscript index 291cde94ea..a425264923 100644 --- a/bsp/lpc2478/SConscript +++ b/bsp/lpc2478/SConscript @@ -1,11 +1,14 @@ -import rtconfig +# for module compiling +import os Import('RTT_ROOT') -from building import * -src_bsp = ['application.c', 'startup.c', 'board.c'] +cwd = str(Dir('#')) +objs = [] +list = os.listdir(cwd) -src = File(src_bsp) -CPPPATH = [RTT_ROOT + '/bsp/lpc2478'] -group = DefineGroup('Startup', src, depend = [''], CPPPATH = CPPPATH) +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) -Return('group') +Return('objs') diff --git a/bsp/lpc2478/SConstruct b/bsp/lpc2478/SConstruct index 15a893bcdf..4eade96f4b 100644 --- a/bsp/lpc2478/SConstruct +++ b/bsp/lpc2478/SConstruct @@ -6,7 +6,7 @@ RTT_ROOT = os.path.normpath(os.getcwd() + '/../..') sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] from building import * -TARGET = 'rtthread-lpc.' + rtconfig.TARGET_EXT +TARGET = 'rtthread-lpc24xx.' + rtconfig.TARGET_EXT env = Environment(tools = ['mingw'], AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, @@ -19,7 +19,7 @@ Export('RTT_ROOT') Export('rtconfig') # prepare building environment -objs = PrepareBuilding(env, RTT_ROOT) +objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False) # build program env.Program(TARGET, objs) diff --git a/bsp/lpc2478/application.c b/bsp/lpc2478/application.c deleted file mode 100644 index 1f92fc7b8c..0000000000 --- a/bsp/lpc2478/application.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * File : app.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, RT-Thread Development Team - * - * 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 - * - * Change Logs: - * Date Author Notes - * 2008-12-11 xuxinming the first version - */ - -#include - -/** - * @addtogroup LPC2478 - */ -/*@{*/ -int rt_application_init() -{ - return 0; -} - -/*@}*/ diff --git a/bsp/lpc2478/applications/SConscript b/bsp/lpc2478/applications/SConscript new file mode 100644 index 0000000000..591734409c --- /dev/null +++ b/bsp/lpc2478/applications/SConscript @@ -0,0 +1,11 @@ +Import('RTT_ROOT') +Import('rtconfig') +from building import * + +cwd = os.path.join(str(Dir('#')), 'applications') +src = Glob('*.c') +CPPPATH = [cwd, str(Dir('#'))] + +group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH) + +Return('group') diff --git a/bsp/lpc2478/applications/application.c b/bsp/lpc2478/applications/application.c new file mode 100644 index 0000000000..1f92fc7b8c --- /dev/null +++ b/bsp/lpc2478/applications/application.c @@ -0,0 +1,26 @@ +/* + * File : app.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Development Team + * + * 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 + * + * Change Logs: + * Date Author Notes + * 2008-12-11 xuxinming the first version + */ + +#include + +/** + * @addtogroup LPC2478 + */ +/*@{*/ +int rt_application_init() +{ + return 0; +} + +/*@}*/ diff --git a/bsp/lpc2478/applications/startup.c b/bsp/lpc2478/applications/startup.c new file mode 100644 index 0000000000..642d90f66a --- /dev/null +++ b/bsp/lpc2478/applications/startup.c @@ -0,0 +1,112 @@ +/* + * File : startup.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2008-12-11 xuxinming first version + * 2010-4-3 LiJin add init soft timer thread + */ + +#include +#include + +#ifdef RT_USING_FINSH +#include +extern void finsh_system_init(void); +#endif + +#include +#include + +/** + * @addtogroup LPC2478 + */ +/*@{*/ + +extern int rt_application_init(void); +#ifdef RT_USING_DEVICE +extern rt_err_t rt_hw_serial_init(void); +#endif + +#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 interrupt */ + rt_hw_interrupt_init(); + + /* init board */ + rt_hw_board_init(); + + /* init tick */ + rt_system_tick_init(); + + /* init kernel object */ + rt_system_object_init(); + + rt_show_version(); + + /* init timer system */ + rt_system_timer_init(); + + /* init memory system */ +#ifdef RT_USING_HEAP +#ifdef __CC_ARM + rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x40010000); +#else + rt_system_heap_init((void*)&__bss_end, (void*)0x40010000); +#endif +#endif + + /* init scheduler system */ + rt_system_scheduler_init(); + + /* init application */ + rt_application_init(); + +#ifdef RT_USING_FINSH + /* init finsh */ + finsh_system_init(); + finsh_set_device("uart1"); +#endif + + /* init soft timer thread */ + rt_system_timer_thread_init(); + + /* init idle thread */ + rt_thread_idle_init(); + + /* start scheduler */ + rt_system_scheduler_start(); + + /* never reach here */ + return ; +} + +#ifdef __CC_ARM +int main(void) +{ + /* disable interrupt first */ + rt_hw_interrupt_disable(); + + /* invoke rtthread_startup */ + rtthread_startup(); + + return 0; +} +#endif + +/*@}*/ diff --git a/bsp/lpc2478/board.c b/bsp/lpc2478/board.c deleted file mode 100644 index 9ed24d28bd..0000000000 --- a/bsp/lpc2478/board.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * File : board.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, RT-Thread Develop Team - * - * 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 - * - * Change Logs: - * Date Author Notes - * 2008-12-11 xuxinming first version - */ - -#include -#include - -#include -#include "board.h" - -#define DATA_COUNT 14400000/RT_TICK_PER_SECOND /* T0MR0 = delayInMs * (Fpclk / 1000); */ - -extern void rt_hw_serial_init(void); - -/** - * @addtogroup LPC2478 - */ -/*@{*/ - -void rt_timer_handler(int vector) -{ - T0IR |= 0x01; /* clear interrupt flag */ - rt_tick_increase(); - VICVectAddr = 0; /* Acknowledge Interrupt */ -} - -/** - * This function will init LPC2478 board - */ -void rt_hw_board_init() -{ -#if defined(RT_USING_DEVICE) && defined(RT_USING_UART1) - rt_hw_serial_init(); - rt_console_set_device("uart1"); -#endif - - T0IR = 0xff; - T0TC = 0; - T0MCR = 0x03; - T0MR0 = (DATA_COUNT); - - rt_hw_interrupt_install(TIMER0_INT, rt_timer_handler, RT_NULL); - rt_hw_interrupt_umask(TIMER0_INT); - - T0TCR = 0x01; //enable timer0 counter -} - -/*@}*/ diff --git a/bsp/lpc2478/board.h b/bsp/lpc2478/board.h deleted file mode 100644 index 0ab153ab50..0000000000 --- a/bsp/lpc2478/board.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * File : board.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, RT-Thread Develop Team - * - * 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 - * - * Change Logs: - * Date Author Notes - * 2008-12-11 xuxinming first version - */ - -#ifndef __BOARD_H__ -#define __BOARD_H__ - -void rt_hw_board_init(void); -void rt_hw_led_set(rt_uint32_t led); -void rt_hw_led_flash(void); - -#ifdef RT_USING_FINSH -void rt_hw_finsh_init(void); -#endif - -#define USE_USB 0 - -#if USE_USB /* 1 is USB, 0 is non-USB related */ -#define PLL_MValue 11 -#define PLL_NValue 0 -#define CCLKDivValue 4 -#define USBCLKDivValue 5 - -#define Fosc 12000000 -#define Fcclk 57600000 -#define Fcco 288000000 -#else - -#define PLL_MValue 12 -#define PLL_NValue 1 -#define CCLKDivValue 5 - -#define Fosc 12000000 -#define Fcclk 72000000 -#define Fcco 360000000 - -#endif - -#if USE_USB -#define Fpclk (Fcclk / 2) -#else -#define Fpclk (Fcclk / 4) -#endif - -/* IRQ define */ -#define SYS32Mode 0x1F -#define IRQ32Mode 0x12 -#define FIQ32Mode 0x11 - -#define HIGHEST_PRIORITY 0x01 -#define LOWEST_PRIORITY 0x0F - -#define WDT_INT 0 -#define SWI_INT 1 -#define ARM_CORE0_INT 2 -#define ARM_CORE1_INT 3 -#define TIMER0_INT 4 -#define TIMER1_INT 5 -#define UART0_INT 6 -#define UART1_INT 7 -#define PWM0_1_INT 8 -#define I2C0_INT 9 -#define SPI0_INT 10 /* SPI and SSP0 share VIC slot */ -#define SSP0_INT 10 -#define SSP1_INT 11 -#define PLL_INT 12 -#define RTC_INT 13 -#define EINT0_INT 14 -#define EINT1_INT 15 -#define EINT2_INT 16 -#define EINT3_INT 17 -#define ADC0_INT 18 -#define I2C1_INT 19 -#define BOD_INT 20 -#define EMAC_INT 21 -#define USB_INT 22 -#define CAN_INT 23 -#define MCI_INT 24 -#define GPDMA_INT 25 -#define TIMER2_INT 26 -#define TIMER3_INT 27 -#define UART2_INT 28 -#define UART3_INT 29 -#define I2C2_INT 30 -#define I2S_INT 31 - -#define VIC_SIZE 32 - -#define VECT_ADDR_INDEX 0x100 -#define VECT_CNTL_INDEX 0x200 - -#define CCLK 60000000 /* Fosc = 12MHz, M = 5 */ -#define PCLK 15000000 /* CCLK/4, use default */ - -/****************************************************************************** -** Function name: TargetInit -** -** Descriptions: Initialize the target board; it is called in a -** necessary place, change it as needed -** -** parameters: None -** Returned value: None -** -******************************************************************************/ -extern void TargetInit(void); -extern void ConfigurePLL( void ); -extern void TargetResetInit(void); - -#endif diff --git a/bsp/lpc2478/drivers/SConscript b/bsp/lpc2478/drivers/SConscript new file mode 100644 index 0000000000..245bc46b05 --- /dev/null +++ b/bsp/lpc2478/drivers/SConscript @@ -0,0 +1,22 @@ +import copy +Import('RTT_ROOT') +Import('rtconfig') +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') + +# remove no need file. +if GetDepend('RT_USING_LWIP') == False: + src_need_remove = ['dm9000.c'] # need remove file list. + SrcRemove(src, src_need_remove) + +if GetDepend('RT_USING_DFS') == False: + src_need_remove = ['sd.c'] # need remove file list. + SrcRemove(src, src_need_remove) + +CPPPATH = [cwd] + +group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) + +Return('group') diff --git a/bsp/lpc2478/drivers/board.c b/bsp/lpc2478/drivers/board.c new file mode 100644 index 0000000000..9ed24d28bd --- /dev/null +++ b/bsp/lpc2478/drivers/board.c @@ -0,0 +1,58 @@ +/* + * File : board.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Develop Team + * + * 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 + * + * Change Logs: + * Date Author Notes + * 2008-12-11 xuxinming first version + */ + +#include +#include + +#include +#include "board.h" + +#define DATA_COUNT 14400000/RT_TICK_PER_SECOND /* T0MR0 = delayInMs * (Fpclk / 1000); */ + +extern void rt_hw_serial_init(void); + +/** + * @addtogroup LPC2478 + */ +/*@{*/ + +void rt_timer_handler(int vector) +{ + T0IR |= 0x01; /* clear interrupt flag */ + rt_tick_increase(); + VICVectAddr = 0; /* Acknowledge Interrupt */ +} + +/** + * This function will init LPC2478 board + */ +void rt_hw_board_init() +{ +#if defined(RT_USING_DEVICE) && defined(RT_USING_UART1) + rt_hw_serial_init(); + rt_console_set_device("uart1"); +#endif + + T0IR = 0xff; + T0TC = 0; + T0MCR = 0x03; + T0MR0 = (DATA_COUNT); + + rt_hw_interrupt_install(TIMER0_INT, rt_timer_handler, RT_NULL); + rt_hw_interrupt_umask(TIMER0_INT); + + T0TCR = 0x01; //enable timer0 counter +} + +/*@}*/ diff --git a/bsp/lpc2478/drivers/board.h b/bsp/lpc2478/drivers/board.h new file mode 100644 index 0000000000..6271d45140 --- /dev/null +++ b/bsp/lpc2478/drivers/board.h @@ -0,0 +1,123 @@ +/* + * File : board.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Develop Team + * + * 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 + * + * Change Logs: + * Date Author Notes + * 2008-12-11 xuxinming first version + */ + +#ifndef __BOARD_H__ +#define __BOARD_H__ + +/* RT_USING_UART */ +#define RT_USING_UART1 +#define RT_USING_UART2 +#define RT_UART_RX_BUFFER_SIZE 64 +void rt_hw_board_init(void); +void rt_hw_led_set(rt_uint32_t led); +void rt_hw_led_flash(void); + +#ifdef RT_USING_FINSH +void rt_hw_finsh_init(void); +#endif + +#define USE_USB 0 + +#if USE_USB /* 1 is USB, 0 is non-USB related */ +#define PLL_MValue 11 +#define PLL_NValue 0 +#define CCLKDivValue 4 +#define USBCLKDivValue 5 + +#define Fosc 12000000 +#define Fcclk 57600000 +#define Fcco 288000000 +#else + +#define PLL_MValue 12 +#define PLL_NValue 1 +#define CCLKDivValue 5 + +#define Fosc 12000000 +#define Fcclk 72000000 +#define Fcco 360000000 + +#endif + +#if USE_USB +#define Fpclk (Fcclk / 2) +#else +#define Fpclk (Fcclk / 4) +#endif + +/* IRQ define */ +#define SYS32Mode 0x1F +#define IRQ32Mode 0x12 +#define FIQ32Mode 0x11 + +#define HIGHEST_PRIORITY 0x01 +#define LOWEST_PRIORITY 0x0F + +#define WDT_INT 0 +#define SWI_INT 1 +#define ARM_CORE0_INT 2 +#define ARM_CORE1_INT 3 +#define TIMER0_INT 4 +#define TIMER1_INT 5 +#define UART0_INT 6 +#define UART1_INT 7 +#define PWM0_1_INT 8 +#define I2C0_INT 9 +#define SPI0_INT 10 /* SPI and SSP0 share VIC slot */ +#define SSP0_INT 10 +#define SSP1_INT 11 +#define PLL_INT 12 +#define RTC_INT 13 +#define EINT0_INT 14 +#define EINT1_INT 15 +#define EINT2_INT 16 +#define EINT3_INT 17 +#define ADC0_INT 18 +#define I2C1_INT 19 +#define BOD_INT 20 +#define EMAC_INT 21 +#define USB_INT 22 +#define CAN_INT 23 +#define MCI_INT 24 +#define GPDMA_INT 25 +#define TIMER2_INT 26 +#define TIMER3_INT 27 +#define UART2_INT 28 +#define UART3_INT 29 +#define I2C2_INT 30 +#define I2S_INT 31 + +#define VIC_SIZE 32 + +#define VECT_ADDR_INDEX 0x100 +#define VECT_CNTL_INDEX 0x200 + +#define CCLK 60000000 /* Fosc = 12MHz, M = 5 */ +#define PCLK 15000000 /* CCLK/4, use default */ + +/****************************************************************************** +** Function name: TargetInit +** +** Descriptions: Initialize the target board; it is called in a +** necessary place, change it as needed +** +** parameters: None +** Returned value: None +** +******************************************************************************/ +extern void TargetInit(void); +extern void ConfigurePLL( void ); +extern void TargetResetInit(void); + +#endif diff --git a/bsp/lpc2478/drivers/serial.c b/bsp/lpc2478/drivers/serial.c new file mode 100644 index 0000000000..0eeb94a61e --- /dev/null +++ b/bsp/lpc2478/drivers/serial.c @@ -0,0 +1,389 @@ +/* + * File : serial.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Development Team + * + * 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 + * + * Change Logs: + * Date Author Notes + * 2006-08-23 Bernard first version + */ + +#include +#include + +#include "LPC24xx.h" +#include "board.h" + +/* serial hardware register */ +#define REG8(d) (*((volatile unsigned char *)(d))) +#define REG32(d) (*((volatile unsigned long *)(d))) + +#define UART_RBR(base) REG8(base + 0x00) +#define UART_THR(base) REG8(base + 0x00) +#define UART_IER(base) REG32(base + 0x04) +#define UART_IIR(base) REG32(base + 0x08) +#define UART_FCR(base) REG8(base + 0x08) +#define UART_LCR(base) REG8(base + 0x0C) +#define UART_MCR(base) REG8(base + 0x10) +#define UART_LSR(base) REG8(base + 0x14) +#define UART_MSR(base) REG8(base + 0x18) +#define UART_SCR(base) REG8(base + 0x1C) +#define UART_DLL(base) REG8(base + 0x00) +#define UART_DLM(base) REG8(base + 0x04) +#define UART_ACR(base) REG32(base + 0x20) +#define UART_FDR(base) REG32(base + 0x28) +#define UART_TER(base) REG8(base + 0x30) + +/* LPC serial device */ +struct rt_lpcserial +{ + /* inherit from device */ + struct rt_device parent; + + rt_uint32_t hw_base; + rt_uint32_t irqno; + rt_uint32_t baudrate; + + /* reception field */ + rt_uint16_t save_index, read_index; + rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE]; +}; + +#ifdef RT_USING_UART1 +struct rt_lpcserial serial1; +#endif +#ifdef RT_USING_UART2 +struct rt_lpcserial serial2; +#endif + +void rt_hw_serial_init(void); + +#define U0PINS 0x00000005 + +void rt_hw_uart_isr(struct rt_lpcserial* lpc_serial) +{ + UNUSED rt_uint32_t iir; + + RT_ASSERT(lpc_serial != RT_NULL) + + if (UART_LSR(lpc_serial->hw_base) & 0x01) + { + rt_base_t level; + + while (UART_LSR(lpc_serial->hw_base) & 0x01) + { + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + + /* read character */ + lpc_serial->rx_buffer[lpc_serial->save_index] = + UART_RBR(lpc_serial->hw_base); + lpc_serial->save_index ++; + if (lpc_serial->save_index >= RT_UART_RX_BUFFER_SIZE) + lpc_serial->save_index = 0; + + /* if the next position is read index, discard this 'read char' */ + if (lpc_serial->save_index == lpc_serial->read_index) + { + lpc_serial->read_index ++; + if (lpc_serial->read_index >= RT_UART_RX_BUFFER_SIZE) + lpc_serial->read_index = 0; + } + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + } + + /* invoke callback */ + if(lpc_serial->parent.rx_indicate != RT_NULL) + { + lpc_serial->parent.rx_indicate(&lpc_serial->parent, 1); + } + } + + /* clear interrupt source */ + iir = UART_IIR(lpc_serial->hw_base); + + /* acknowledge Interrupt */ + VICVectAddr = 0; +} + +#ifdef RT_USING_UART1 +void rt_hw_uart_isr_1(int irqno) +{ + /* get lpc serial device */ + rt_hw_uart_isr(&serial1); +} +#endif + +#ifdef RT_USING_UART2 +void rt_hw_uart_isr_2(int irqno) +{ + /* get lpc serial device */ + rt_hw_uart_isr(&serial2); +} +#endif + +/** + * @addtogroup LPC214x + */ +/*@{*/ + +static rt_err_t rt_serial_init (rt_device_t dev) +{ + return RT_EOK; +} + +static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag) +{ + struct rt_lpcserial* lpc_serial; + lpc_serial = (struct rt_lpcserial*) dev; + + RT_ASSERT(lpc_serial != RT_NULL); + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* init UART rx interrupt */ + UART_IER(lpc_serial->hw_base) = 0x01; + + /* install ISR */ + if (lpc_serial->irqno == UART0_INT) + { +#ifdef RT_USING_UART1 + rt_hw_interrupt_install(lpc_serial->irqno, rt_hw_uart_isr_1, RT_NULL); +#endif + } + else + { +#ifdef RT_USING_UART2 + rt_hw_interrupt_install(lpc_serial->irqno, rt_hw_uart_isr_2, RT_NULL); +#endif + } + + rt_hw_interrupt_umask(lpc_serial->irqno); + } + + return RT_EOK; +} + +static rt_err_t rt_serial_close(rt_device_t dev) +{ + struct rt_lpcserial* lpc_serial; + lpc_serial = (struct rt_lpcserial*) dev; + + RT_ASSERT(lpc_serial != RT_NULL); + + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* disable UART rx interrupt */ + UART_IER(lpc_serial->hw_base) = 0x00; + } + + return RT_EOK; +} + +static rt_err_t rt_serial_control(rt_device_t dev, rt_uint8_t cmd, void *args) +{ + return RT_EOK; +} + +static rt_size_t rt_serial_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) +{ + rt_uint8_t* ptr; + struct rt_lpcserial *lpc_serial = (struct rt_lpcserial*)dev; + RT_ASSERT(lpc_serial != RT_NULL); + + /* point to buffer */ + ptr = (rt_uint8_t*) buffer; + + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + while (size) + { + /* interrupt receive */ + rt_base_t level; + + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + if (lpc_serial->read_index != lpc_serial->save_index) + { + *ptr = lpc_serial->rx_buffer[lpc_serial->read_index]; + + lpc_serial->read_index ++; + if (lpc_serial->read_index >= RT_UART_RX_BUFFER_SIZE) + lpc_serial->read_index = 0; + } + else + { + /* no data in rx buffer */ + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + break; + } + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + + ptr ++; size --; + } + + return (rt_uint32_t)ptr - (rt_uint32_t)buffer; + } + else if (dev->flag & RT_DEVICE_FLAG_DMA_RX) + { + /* not support right now */ + RT_ASSERT(0); + } + + /* polling mode */ + while (size && (UART_LSR(lpc_serial->hw_base) & 0x01)) + { + /* Read Character */ + *ptr = UART_RBR(lpc_serial->hw_base); + + ptr ++; + size --; + } + + return (rt_size_t)ptr - (rt_size_t)buffer; +} + +static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) +{ + struct rt_lpcserial* lpc_serial; + char *ptr; + + lpc_serial = (struct rt_lpcserial*) dev; + if (dev->flag & RT_DEVICE_FLAG_INT_TX) + { + /* not support */ + RT_ASSERT(0); + } + else if (dev->flag & RT_DEVICE_FLAG_DMA_TX) + { + /* not support */ + RT_ASSERT(0); + } + + /* polling write */ + ptr = (char *)buffer; + + if (dev->flag & RT_DEVICE_FLAG_STREAM) + { + /* stream mode */ + while (size) + { + if (*ptr == '\n') + { + while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); + UART_THR(lpc_serial->hw_base) = '\r'; + } + + while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); + UART_THR(lpc_serial->hw_base) = *ptr; + + ptr ++; + size --; + } + } + else + { + while (size) + { + while (!(UART_LSR(lpc_serial->hw_base) & 0x20)); + UART_THR(lpc_serial->hw_base) = *ptr; + + ptr ++; + size --; + } + } + + return (rt_size_t) ptr - (rt_size_t) buffer; +} + +void rt_hw_serial_init(void) +{ + struct rt_lpcserial* lpc_serial; + +#ifdef RT_USING_UART1 + lpc_serial = &serial1; + + lpc_serial->parent.type = RT_Device_Class_Char; + + lpc_serial->hw_base = 0xE000C000; + lpc_serial->baudrate = 115200; + lpc_serial->irqno = UART0_INT; + + rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); + lpc_serial->read_index = lpc_serial->save_index = 0; + + /* Enable UART0 RxD and TxD pins */ + PINSEL0 |= 0x50; + + /* 8 bits, no Parity, 1 Stop bit */ + UART_LCR(lpc_serial->hw_base) = 0x83; + + /* Setup Baudrate */ + UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; + UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; + + /* DLAB = 0 */ + UART_LCR(lpc_serial->hw_base) = 0x03; + + lpc_serial->parent.type = RT_Device_Class_Char; + lpc_serial->parent.init = rt_serial_init; + lpc_serial->parent.open = rt_serial_open; + lpc_serial->parent.close = rt_serial_close; + lpc_serial->parent.read = rt_serial_read; + lpc_serial->parent.write = rt_serial_write; + lpc_serial->parent.control = rt_serial_control; + lpc_serial->parent.user_data = RT_NULL; + + rt_device_register(&lpc_serial->parent, + "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM); +#endif + +#ifdef RT_USING_UART2 + lpc_serial = &serial2; + + lpc_serial->parent.type = RT_Device_Class_Char; + + lpc_serial->hw_base = 0xE0010000; + lpc_serial->baudrate = 115200; + lpc_serial->irqno = UART1_INT; + + rt_memset(lpc_serial->rx_buffer, 0, sizeof(lpc_serial->rx_buffer)); + lpc_serial->read_index = lpc_serial->save_index = 0; + + /* Enable UART1 RxD and TxD pins */ + PINSEL0 |= 0x05 << 16; + + /* 8 bits, no Parity, 1 Stop bit */ + UART_LCR(lpc_serial->hw_base) = 0x83; + + /* Setup Baudrate */ + UART_DLL(lpc_serial->hw_base) = (PCLK/16/lpc_serial->baudrate) & 0xFF; + UART_DLM(lpc_serial->hw_base) = ((PCLK/16/lpc_serial->baudrate) >> 8) & 0xFF; + + /* DLAB = 0 */ + UART_LCR(lpc_serial->hw_base) = 0x03; + + lpc_serial->parent.type = RT_Device_Class_Char; + lpc_serial->parent.init = rt_serial_init; + lpc_serial->parent.open = rt_serial_open; + lpc_serial->parent.close = rt_serial_close; + lpc_serial->parent.read = rt_serial_read; + lpc_serial->parent.write = rt_serial_write; + lpc_serial->parent.control = rt_serial_control; + lpc_serial->parent.user_data = RT_NULL; + + rt_device_register(&lpc_serial->parent, + "uart2", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX); +#endif +} + +/*@}*/ diff --git a/bsp/lpc2478/project.Uv2 b/bsp/lpc2478/project.Uv2 index 05ac110f5a..cd7dfbc16c 100644 --- a/bsp/lpc2478/project.Uv2 +++ b/bsp/lpc2478/project.Uv2 @@ -3,52 +3,50 @@ Target (RT-Thread LPC2478), 0x0004 // Tools: 'ARM-ADS' -Group (Startup) +Group (Applications) +Group (Drivers) Group (Kernel) Group (LPC24XX) Group (finsh) -File 1,1,<.\application.c> -File 1,1,<.\startup.c> -File 1,1,<.\board.c> -File 2,1,<..\..\src\clock.c> -File 2,1,<..\..\src\device.c> -File 2,1,<..\..\src\idle.c> -File 2,1,<..\..\src\ipc.c> -File 2,1,<..\..\src\irq.c> -File 2,1,<..\..\src\kservice.c> -File 2,1,<..\..\src\mem.c> -File 2,1,<..\..\src\mempool.c> -File 2,1,<..\..\src\module.c> -File 2,1,<..\..\src\object.c> -File 2,1,<..\..\src\rtm.c> -File 2,1,<..\..\src\scheduler.c> -File 2,1,<..\..\src\slab.c> -File 2,1,<..\..\src\thread.c> -File 2,1,<..\..\src\timer.c> -File 3,1,<..\..\libcpu\arm\lpc24xx\cpu.c> -File 3,1,<..\..\libcpu\arm\lpc24xx\interrupt.c> -File 3,1,<..\..\libcpu\arm\lpc24xx\serial.c> -File 3,1,<..\..\libcpu\arm\lpc24xx\stack.c> -File 3,1,<..\..\libcpu\arm\lpc24xx\trap.c> -File 3,2,<..\..\libcpu\arm\lpc24xx\context_rvds.S> -File 3,2,<..\..\libcpu\arm\lpc24xx\start_rvds.S> -File 3,1,<..\..\libcpu\arm\common\backtrace.c> -File 3,1,<..\..\libcpu\arm\common\div0.c> -File 3,1,<..\..\libcpu\arm\common\showmem.c> -File 4,1,<..\..\components\finsh\cmd.c> -File 4,1,<..\..\components\finsh\finsh_compiler.c> -File 4,1,<..\..\components\finsh\finsh_error.c> -File 4,1,<..\..\components\finsh\finsh_heap.c> -File 4,1,<..\..\components\finsh\finsh_init.c> -File 4,1,<..\..\components\finsh\finsh_node.c> -File 4,1,<..\..\components\finsh\finsh_ops.c> -File 4,1,<..\..\components\finsh\finsh_parser.c> -File 4,1,<..\..\components\finsh\finsh_token.c> -File 4,1,<..\..\components\finsh\finsh_var.c> -File 4,1,<..\..\components\finsh\finsh_vm.c> -File 4,1,<..\..\components\finsh\shell.c> -File 4,1,<..\..\components\finsh\symbol.c> +File 1,1, +File 1,1, +File 2,1, +File 2,1, +File 3,1,<..\..\src\device.c> +File 3,1,<..\..\src\thread.c> +File 3,1,<..\..\src\scheduler.c> +File 3,1,<..\..\src\timer.c> +File 3,1,<..\..\src\irq.c> +File 3,1,<..\..\src\kservice.c> +File 3,1,<..\..\src\clock.c> +File 3,1,<..\..\src\object.c> +File 3,1,<..\..\src\mempool.c> +File 3,1,<..\..\src\ipc.c> +File 3,1,<..\..\src\idle.c> +File 3,1,<..\..\src\mem.c> +File 4,1,<..\..\libcpu\arm\lpc24xx\cpu.c> +File 4,1,<..\..\libcpu\arm\lpc24xx\interrupt.c> +File 4,1,<..\..\libcpu\arm\lpc24xx\stack.c> +File 4,1,<..\..\libcpu\arm\lpc24xx\trap.c> +File 4,2,<..\..\libcpu\arm\lpc24xx\context_rvds.S> +File 4,2,<..\..\libcpu\arm\lpc24xx\start_rvds.S> +File 4,1,<..\..\libcpu\arm\common\backtrace.c> +File 4,1,<..\..\libcpu\arm\common\div0.c> +File 4,1,<..\..\libcpu\arm\common\showmem.c> +File 5,1,<..\..\components\finsh\cmd.c> +File 5,1,<..\..\components\finsh\finsh_compiler.c> +File 5,1,<..\..\components\finsh\finsh_error.c> +File 5,1,<..\..\components\finsh\finsh_heap.c> +File 5,1,<..\..\components\finsh\finsh_init.c> +File 5,1,<..\..\components\finsh\finsh_node.c> +File 5,1,<..\..\components\finsh\finsh_ops.c> +File 5,1,<..\..\components\finsh\finsh_parser.c> +File 5,1,<..\..\components\finsh\finsh_token.c> +File 5,1,<..\..\components\finsh\finsh_var.c> +File 5,1,<..\..\components\finsh\finsh_vm.c> +File 5,1,<..\..\components\finsh\shell.c> +File 5,1,<..\..\components\finsh\symbol.c> Options 1,0,0 // Target 'RT-Thread LPC2478' @@ -109,7 +107,7 @@ Options 1,0,0 // Target 'RT-Thread LPC2478' ADSCMISC () ADSCDEFN () ADSCUDEF () - ADSCINCD (..\..\include;..\..\libcpu\arm\common;..\..\components\finsh;..\..\libcpu\arm\lpc24xx;.) + ADSCINCD (..\..\include;drivers;.;applications;..\..\libcpu\arm\common;..\..\components\finsh;..\..\libcpu\arm\lpc24xx) ADSASFLG { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } ADSAMISC () ADSADEFN () @@ -130,11 +128,11 @@ Options 1,0,0 // Target 'RT-Thread LPC2478' ADSLDSC () ADSLDIB () ADSLDIC () - ADSLDMC ( --keep __fsym_* --keep __vsym_*) + ADSLDMC ( --keep __fsym_* --keep __vsym_* ) ADSLDIF () ADSLDDW () OPTDL (SARM.DLL)(-cLPC24xx)(DARMP.DLL)(-pLPC2478)(SARM.DLL)()(TARMP.DLL)(-pLPC2478) - OPTDBG 48125,7,()()()()()()()()()() (Segger\JL2CM3.dll)()()() + OPTDBG 48126,7,()()()()()()()()()() (Segger\JL2CM3.dll)()()() FLASH1 { 9,0,0,0,1,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0 } FLASH2 (BIN\UL2ARM.DLL) FLASH3 ("LPC210x_ISP.EXE" ("#H" ^X $D COM1: 38400 1)) diff --git a/bsp/lpc2478/rtconfig.h b/bsp/lpc2478/rtconfig.h index f4495c1b5d..d1a5d9d521 100644 --- a/bsp/lpc2478/rtconfig.h +++ b/bsp/lpc2478/rtconfig.h @@ -63,8 +63,6 @@ /* SECTION: Device System */ /* Using Device System*/ #define RT_USING_DEVICE -#define RT_USING_UART1 -#define RT_UART_RX_BUFFER_SIZE 64 /* SECTION: Console options */ #define RT_USING_CONSOLE diff --git a/bsp/lpc2478/rtconfig.py b/bsp/lpc2478/rtconfig.py index 7f7cf363e9..ee4345b76c 100644 --- a/bsp/lpc2478/rtconfig.py +++ b/bsp/lpc2478/rtconfig.py @@ -1,7 +1,7 @@ # toolchains options ARCH='arm' CPU='lpc24xx' -CROSS_TOOL='gcc' +CROSS_TOOL='keil' if CROSS_TOOL == 'gcc': PLATFORM = 'gcc' @@ -9,12 +9,16 @@ if CROSS_TOOL == 'gcc': elif CROSS_TOOL == 'keil': PLATFORM = 'armcc' EXEC_PATH = 'E:/Keil' +elif CROSS_TOOL == 'iar': + PLATFORM = 'iar' + EXEC_PATH = 'E:/Program Files/IAR Systems/Embedded Workbench 6.0/arm/bin' BUILD = 'debug' if PLATFORM == 'gcc': # toolchains PREFIX = 'arm-none-eabi-' CC = PREFIX + 'gcc' + CXX = PREFIX + 'g++' AS = PREFIX + 'gcc' AR = PREFIX + 'ar' LINK = PREFIX + 'gcc' @@ -23,8 +27,8 @@ if PLATFORM == 'gcc': OBJDUMP = PREFIX + 'objdump' OBJCPY = PREFIX + 'objcopy' - DEVICE = ' -mcpu=arm7tdmi' - CFLAGS = DEVICE + DEVICE = ' -mcpu=arm7tdmi-s' + CFLAGS = DEVICE + ' -DRT_USING_MINILIBC' AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp' LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-lpc2478.map,-cref,-u,Reset_Handler -T lpc2478_rom.lds' @@ -42,6 +46,7 @@ if PLATFORM == 'gcc': elif PLATFORM == 'armcc': # toolchains CC = 'armcc' + CXX = 'armcc' AS = 'armasm' AR = 'armar' LINK = 'armlink' diff --git a/bsp/lpc2478/startup.c b/bsp/lpc2478/startup.c deleted file mode 100644 index 642d90f66a..0000000000 --- a/bsp/lpc2478/startup.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * File : startup.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, RT-Thread Develop Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2008-12-11 xuxinming first version - * 2010-4-3 LiJin add init soft timer thread - */ - -#include -#include - -#ifdef RT_USING_FINSH -#include -extern void finsh_system_init(void); -#endif - -#include -#include - -/** - * @addtogroup LPC2478 - */ -/*@{*/ - -extern int rt_application_init(void); -#ifdef RT_USING_DEVICE -extern rt_err_t rt_hw_serial_init(void); -#endif - -#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 interrupt */ - rt_hw_interrupt_init(); - - /* init board */ - rt_hw_board_init(); - - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - - rt_show_version(); - - /* init timer system */ - rt_system_timer_init(); - - /* init memory system */ -#ifdef RT_USING_HEAP -#ifdef __CC_ARM - rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x40010000); -#else - rt_system_heap_init((void*)&__bss_end, (void*)0x40010000); -#endif -#endif - - /* init scheduler system */ - rt_system_scheduler_init(); - - /* init application */ - rt_application_init(); - -#ifdef RT_USING_FINSH - /* init finsh */ - finsh_system_init(); - finsh_set_device("uart1"); -#endif - - /* init soft timer thread */ - rt_system_timer_thread_init(); - - /* init idle thread */ - rt_thread_idle_init(); - - /* start scheduler */ - rt_system_scheduler_start(); - - /* never reach here */ - return ; -} - -#ifdef __CC_ARM -int main(void) -{ - /* disable interrupt first */ - rt_hw_interrupt_disable(); - - /* invoke rtthread_startup */ - rtthread_startup(); - - return 0; -} -#endif - -/*@}*/ -- cgit v1.3.1