From 4dd1acf294498c44c0ee8673c03519999809a0ec Mon Sep 17 00:00:00 2001 From: "dzzxzz@gmail.com" Date: Tue, 19 Jun 2012 00:43:54 +0000 Subject: [PATCH] update ls1bdev git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2176 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- bsp/ls1bdev/SConscript | 19 +- bsp/ls1bdev/applications/SConscript | 9 + bsp/ls1bdev/applications/application.c | 66 +++++ bsp/ls1bdev/applications/startup.c | 88 +++++++ bsp/ls1bdev/drivers/SConscript | 14 ++ bsp/ls1bdev/drivers/board.c | 105 ++++++++ bsp/ls1bdev/drivers/board.h | 25 ++ bsp/ls1bdev/drivers/display_controller.c | 234 ++++++++++++++++++ bsp/ls1bdev/drivers/display_controller.h | 58 +++++ bsp/ls1bdev/drivers/uart.c | 277 +++++++++++++++++++++ bsp/ls1bdev/drivers/uart.h | 97 ++++++++ bsp/ls1bdev/rtconfig.h | 295 ++++++++++++++--------- 12 files changed, 1158 insertions(+), 129 deletions(-) create mode 100644 bsp/ls1bdev/applications/SConscript create mode 100644 bsp/ls1bdev/applications/application.c create mode 100644 bsp/ls1bdev/applications/startup.c create mode 100644 bsp/ls1bdev/drivers/SConscript create mode 100644 bsp/ls1bdev/drivers/board.c create mode 100644 bsp/ls1bdev/drivers/board.h create mode 100644 bsp/ls1bdev/drivers/display_controller.c create mode 100644 bsp/ls1bdev/drivers/display_controller.h create mode 100644 bsp/ls1bdev/drivers/uart.c create mode 100644 bsp/ls1bdev/drivers/uart.h diff --git a/bsp/ls1bdev/SConscript b/bsp/ls1bdev/SConscript index dc4ae18a10..d9c64eb9f9 100644 --- a/bsp/ls1bdev/SConscript +++ b/bsp/ls1bdev/SConscript @@ -1,15 +1,12 @@ -Import('RTT_ROOT') from building import * -src_bsp = ['application.c', 'startup.c', 'board.c'] +cwd = GetCurrentDir() +objs = [] +list = os.listdir(cwd) -src_drv = ['uart.c'] - -if GetDepend('RT_USING_RTGUI'): - src_drv += ['display_controller.c'] - -src = File(src_bsp + src_drv) -CPPPATH = [GetCurrentDir()] -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/ls1bdev/applications/SConscript b/bsp/ls1bdev/applications/SConscript new file mode 100644 index 0000000000..4fe38ed0cf --- /dev/null +++ b/bsp/ls1bdev/applications/SConscript @@ -0,0 +1,9 @@ +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') +CPPPATH = [cwd, str(Dir('#'))] + +group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH) + +Return('group') diff --git a/bsp/ls1bdev/applications/application.c b/bsp/ls1bdev/applications/application.c new file mode 100644 index 0000000000..282620fff2 --- /dev/null +++ b/bsp/ls1bdev/applications/application.c @@ -0,0 +1,66 @@ +/* + * File : application.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2012, 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 + * 2010-06-25 Bernard first version + * 2011-08-08 lgnq modified for Loongson LS1B + */ + +#include +#include + +#ifdef RT_USING_COMPONENTS_INIT +#include +#endif + +#ifdef RT_USING_RTGUI +#include +extern void rt_hw_dc_init(void); +#endif + +void rt_init_thread_entry(void *parameter) +{ +#ifdef RT_USING_RTGUI + { + rt_device_t dc; + + /* init Display Controller */ + rt_hw_dc_init(); + + /* re-init device driver */ + rt_device_init_all(); + + /* find Display Controller device */ + dc = rt_device_find("dc"); + + /* set Display Controller device as rtgui graphic driver */ + rtgui_graphic_set_device(dc); + } +#endif + +#ifdef RT_USING_COMPONENTS_INIT + /* initialization RT-Thread Components */ + rt_components_init(); +#endif +} + +int rt_application_init(void) +{ + rt_thread_t tid; + + /* create initialization thread */ + tid = rt_thread_create("init", + rt_init_thread_entry, RT_NULL, + 4096, 8, 20); + if (tid != RT_NULL) + rt_thread_startup(tid); + + return 0; +} diff --git a/bsp/ls1bdev/applications/startup.c b/bsp/ls1bdev/applications/startup.c new file mode 100644 index 0000000000..2fdfa700ba --- /dev/null +++ b/bsp/ls1bdev/applications/startup.c @@ -0,0 +1,88 @@ +/* + * File : startup.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2012, 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 + * 2010-06-25 Bernard first version + * 2011-08-08 lgnq modified for Loongson LS1B + */ + +#include +#include + +#include "board.h" +#define A_K0BASE 0x80000000 + +/** + * @addtogroup Loongson LS1B + */ + +/*@{*/ + +extern unsigned char __bss_end; + +extern int rt_application_init(void); + +extern void tlb_refill_exception(void); +extern void general_exception(void); +extern void irq_exception(void); + +/** + * This function will startup RT-Thread RTOS. + */ +void rtthread_startup(void) +{ + /* disable interrupt first */ + rt_hw_interrupt_disable(); + + /* init cache */ + rt_hw_cache_init(); + /* init hardware interrupt */ + rt_hw_interrupt_init(); + + /* copy vector */ + memcpy((void *)A_K0BASE, tlb_refill_exception, 0x20); + memcpy((void *)(A_K0BASE + 0x180), general_exception, 0x20); + memcpy((void *)(A_K0BASE + 0x200), irq_exception, 0x20); + + /* init board */ + rt_hw_board_init(); + + /* show version */ + rt_show_version(); + +#ifdef RT_USING_HEAP + rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END); +#endif + + /* init scheduler system */ + rt_system_scheduler_init(); + +#ifdef RT_USING_DEVICE + /* init all device */ + rt_device_init_all(); +#endif + + /* init application */ + rt_application_init(); + + /* initialize timer thread */ + rt_system_timer_thread_init(); + + /* init idle thread */ + rt_thread_idle_init(); + + /* start scheduler */ + rt_system_scheduler_start(); + + /* never reach here */ + return ; +} + +/*@}*/ diff --git a/bsp/ls1bdev/drivers/SConscript b/bsp/ls1bdev/drivers/SConscript new file mode 100644 index 0000000000..9e7b13fc2c --- /dev/null +++ b/bsp/ls1bdev/drivers/SConscript @@ -0,0 +1,14 @@ +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') + +# remove no need file. +if GetDepend('RT_USING_RTGUI') == False: + SrcRemove(src, 'display_controller.c') + +CPPPATH = [cwd] + +group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) + +Return('group') diff --git a/bsp/ls1bdev/drivers/board.c b/bsp/ls1bdev/drivers/board.c new file mode 100644 index 0000000000..cea1fb5b56 --- /dev/null +++ b/bsp/ls1bdev/drivers/board.c @@ -0,0 +1,105 @@ +/* + * File : board.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2011, 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 + * 2010-06-25 Bernard first version + * 2011-08-08 lgnq modified for Loongson LS1B + */ + +#include +#include + +#include "board.h" +#include "uart.h" +#include "ls1b.h" + +/** + * @addtogroup Loongson LS1B + */ + +/*@{*/ + +/** + * This is the timer interrupt service routine. + */ +void rt_hw_timer_handler(void) +{ + unsigned int count; + + count = read_c0_compare(); + write_c0_compare(count); + write_c0_count(0); + + /* increase a OS tick */ + rt_tick_increase(); +} + +/** + * This function will initial OS timer + */ +void rt_hw_timer_init(void) +{ + write_c0_compare(CPU_HZ/2/RT_TICK_PER_SECOND); + write_c0_count(0); +} + +/** + * This function will initial sam7s64 board. + */ +void rt_hw_board_init(void) +{ +#ifdef RT_USING_UART + /* init hardware UART device */ + rt_hw_uart_init(); +#endif + +#ifdef RT_USING_CONSOLE + /* set console device */ + rt_console_set_device("uart0"); +#endif + + /* init operating system timer */ + rt_hw_timer_init(); + + rt_kprintf("current sr: 0x%08x\n", read_c0_status()); +} + +/* UART line status register value */ +#define UARTLSR_ERROR (1 << 7) +#define UARTLSR_TE (1 << 6) +#define UARTLSR_TFE (1 << 5) +#define UARTLSR_BI (1 << 4) +#define UARTLSR_FE (1 << 3) +#define UARTLSR_PE (1 << 2) +#define UARTLSR_OE (1 << 1) +#define UARTLSR_DR (1 << 0) +void rt_hw_console_output(const char* ptr) +{ + /* stream mode */ + while (*ptr) + { + if (*ptr == '\n') + { + /* FIFO status, contain valid data */ + while (!(UART_LSR(UART0_BASE) & (UARTLSR_TE | UARTLSR_TFE))); + /* write data */ + UART_DAT(UART0_BASE) = '\r'; + } + + /* FIFO status, contain valid data */ + while (!(UART_LSR(UART0_BASE) & (UARTLSR_TE | UARTLSR_TFE))); + /* write data */ + UART_DAT(UART0_BASE) = *ptr; + + ptr ++; + } +} + +/*@}*/ diff --git a/bsp/ls1bdev/drivers/board.h b/bsp/ls1bdev/drivers/board.h new file mode 100644 index 0000000000..62481a2a45 --- /dev/null +++ b/bsp/ls1bdev/drivers/board.h @@ -0,0 +1,25 @@ +/* + * File : board.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2011, 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 + * 2010-06-25 Bernard first version + * 2011-08-08 lgnq modified for Loongson LS1B + */ + +#ifndef __BOARD_H__ +#define __BOARD_H__ + +void rt_hw_board_init(void); + +/* 64M SDRAM */ +#define RT_HW_HEAP_END (0x80000000 + 64 * 1024 * 1024) +#define CPU_HZ (125 * 1000000) + +#endif diff --git a/bsp/ls1bdev/drivers/display_controller.c b/bsp/ls1bdev/drivers/display_controller.c new file mode 100644 index 0000000000..511f2dbe0d --- /dev/null +++ b/bsp/ls1bdev/drivers/display_controller.c @@ -0,0 +1,234 @@ +/* + * File : display_controller.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2011, 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 + * 2011-08-09 lgnq first version for LS1B DC + */ + +#include +#include "display_controller.h" + +struct vga_struct vga_mode[] = +{ + {/*"640x480_70.00"*/ 28560, 640, 664, 728, 816, 480, 481, 484, 500, }, + {/*"640x640_60.00"*/ 33100, 640, 672, 736, 832, 640, 641, 644, 663, }, + {/*"640x768_60.00"*/ 39690, 640, 672, 736, 832, 768, 769, 772, 795, }, + {/*"640x800_60.00"*/ 42130, 640, 680, 744, 848, 800, 801, 804, 828, }, + {/*"800x480_70.00"*/ 35840, 800, 832, 912, 1024, 480, 481, 484, 500, }, + {/*"800x600_60.00"*/ 38220, 800, 832, 912, 1024, 600, 601, 604, 622, }, + {/*"800x640_60.00"*/ 40730, 800, 832, 912, 1024, 640, 641, 644, 663, }, + {/*"832x600_60.00"*/ 40010, 832, 864, 952, 1072, 600, 601, 604, 622, }, + {/*"832x608_60.00"*/ 40520, 832, 864, 952, 1072, 608, 609, 612, 630, }, + {/*"1024x480_60.00"*/ 38170, 1024, 1048, 1152, 1280, 480, 481, 484, 497, }, + {/*"1024x600_60.00"*/ 48960, 1024, 1064, 1168, 1312, 600, 601, 604, 622, }, + {/*"1024x640_60.00"*/ 52830, 1024, 1072, 1176, 1328, 640, 641, 644, 663, }, + {/*"1024x768_60.00"*/ 64110, 1024, 1080, 1184, 1344, 768, 769, 772, 795, }, + {/*"1152x764_60.00"*/ 71380, 1152, 1208, 1328, 1504, 764, 765, 768, 791, }, + {/*"1280x800_60.00"*/ 83460, 1280, 1344, 1480, 1680, 800, 801, 804, 828, }, + {/*"1280x1024_55.00"*/ 98600, 1280, 1352, 1488, 1696, 1024, 1025, 1028, 1057, }, + {/*"1440x800_60.00"*/ 93800, 1440, 1512, 1664, 1888, 800, 801, 804, 828, }, + {/*"1440x900_67.00"*/ 120280, 1440, 1528, 1680, 1920, 900, 901, 904, 935, }, +}; + +ALIGN(16) +volatile rt_uint16_t _rt_framebuffer[FB_YSIZE][FB_XSIZE]; +static struct rt_device_graphic_info _dc_info; + +#define abs(x) ((x<0)?(-x):x) +#define min(a,b) ((atype = RT_Device_Class_Graphic; + dc->init = rt_dc_init; + dc->open = RT_NULL; + dc->close = RT_NULL; + dc->control = rt_dc_control; + dc->user_data = (void*)&_dc_info; + + /* register Display Controller device to RT-Thread */ + rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR); +} diff --git a/bsp/ls1bdev/drivers/display_controller.h b/bsp/ls1bdev/drivers/display_controller.h new file mode 100644 index 0000000000..85086daf31 --- /dev/null +++ b/bsp/ls1bdev/drivers/display_controller.h @@ -0,0 +1,58 @@ +/* + * File : display_controller.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2011, 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 + * 2011-08-08 lgnq first version for LS1B + */ + +#ifndef __DISPLAY_CONTROLLER_H__ +#define __DISPLAY_CONTROLLER_H__ + +#include +#include "ls1b.h" + +#define DC_BASE 0xBC301240 //Display Controller + +/* Frame Buffer registers */ +#define DC_FB_CONFIG __REG32(DC_BASE + 0x000) +#define DC_FB_BUFFER_ADDR0 __REG32(DC_BASE + 0x020) +#define DC_FB_BUFFER_STRIDE __REG32(DC_BASE + 0x040) +#define DC_FB_BUFFER_ORIGIN __REG32(DC_BASE + 0x060) +#define DC_DITHER_CONFIG __REG32(DC_BASE + 0x120) +#define DC_DITHER_TABLE_LOW __REG32(DC_BASE + 0x140) +#define DC_DITHER_TABLE_HIGH __REG32(DC_BASE + 0x160) +#define DC_PANEL_CONFIG __REG32(DC_BASE + 0x180) +#define DC_PANEL_TIMING __REG32(DC_BASE + 0x1A0) +#define DC_HDISPLAY __REG32(DC_BASE + 0x1C0) +#define DC_HSYNC __REG32(DC_BASE + 0x1E0) +#define DC_VDISPLAY __REG32(DC_BASE + 0x240) +#define DC_VSYNC __REG32(DC_BASE + 0x260) +#define DC_FB_BUFFER_ADDR1 __REG32(DC_BASE + 0x340) + +/* Display Controller driver for 1024x768 16bit */ +#define FB_XSIZE 1024 +#define FB_YSIZE 768 +#define CONFIG_VIDEO_16BPP + +#define APB_CLK 33333333 + +#define K1BASE 0xA0000000 +#define KSEG1(addr) ((void *)(K1BASE | (rt_uint32_t)(addr))) +#define HW_FB_ADDR KSEG1(_rt_framebuffer) +#define HW_FB_PIXEL(x, y) *(volatile rt_uint16_t*)((rt_uint8_t*)HW_FB_ADDR + (y * FB_XSIZE * 2) + x * 2) + +struct vga_struct +{ + long pclk; + int hr,hss,hse,hfl; + int vr,vss,vse,vfl; +}; + +#endif diff --git a/bsp/ls1bdev/drivers/uart.c b/bsp/ls1bdev/drivers/uart.c new file mode 100644 index 0000000000..71273fd595 --- /dev/null +++ b/bsp/ls1bdev/drivers/uart.c @@ -0,0 +1,277 @@ +/* + * File : board.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2012, 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 + * 2011-08-08 lgnq first version + */ + +#include +#include + +#include "uart.h" + +/** + * @addtogroup Loongson LS1B + */ + +/*@{*/ + +#if defined(RT_USING_UART) && defined(RT_USING_DEVICE) + +struct rt_uart_ls1b +{ + struct rt_device parent; + + rt_uint32_t hw_base; + rt_uint32_t irq; + + /* buffer for reception */ + rt_uint8_t read_index, save_index; + rt_uint8_t rx_buffer[RT_UART_RX_BUFFER_SIZE]; +}uart_device; + +static void rt_uart_irqhandler(int irqno) +{ + rt_ubase_t level; + rt_uint8_t isr; + struct rt_uart_ls1b* uart = &uart_device; + + /* read interrupt status and clear it */ + isr = UART_IIR(uart->hw_base); + isr = (isr >> 1) & 0x3; + + /* receive data available */ + if (isr & 0x02) + { + /* Receive Data Available */ + while (UART_LSR(uart->hw_base) & UARTLSR_DR) + { + uart->rx_buffer[uart->save_index] = UART_DAT(uart->hw_base); + + level = rt_hw_interrupt_disable(); + uart->save_index ++; + if (uart->save_index >= RT_UART_RX_BUFFER_SIZE) + uart->save_index = 0; + rt_hw_interrupt_enable(level); + } + + /* invoke callback */ + if (uart->parent.rx_indicate != RT_NULL) + { + rt_size_t length; + if (uart->read_index > uart->save_index) + length = RT_UART_RX_BUFFER_SIZE - uart->read_index + uart->save_index; + else + length = uart->save_index - uart->read_index; + + uart->parent.rx_indicate(&uart->parent, length); + } + } + + return; +} + +static rt_err_t rt_uart_init(rt_device_t dev) +{ + rt_uint32_t baud_div; + struct rt_uart_ls1b *uart = (struct rt_uart_ls1b *)dev; + + RT_ASSERT(uart != RT_NULL); + +#if 0 + /* init UART Hardware */ + UART_IER(uart->hw_base) = 0; /* clear interrupt */ + UART_FCR(uart->hw_base) = 0x60; /* reset UART Rx/Tx */ + + /* enable UART clock */ + /* set databits, stopbits and parity. (8-bit data, 1 stopbit, no parity) */ + UART_LCR(uart->hw_base) = 0x3; + + /* set baudrate */ + baud_div = DEV_CLK / 16 / UART_BAUDRATE; + UART_LCR(uart->hw_base) |= UARTLCR_DLAB; + + UART_MSB(uart->hw_base) = (baud_div >> 8) & 0xff; + UART_LSB(uart->hw_base) = baud_div & 0xff; + + UART_LCR(uart->hw_base) &= ~UARTLCR_DLAB; + + /* Enable UART unit, enable and clear FIFO */ + UART_FCR(uart->hw_base) = UARTFCR_UUE | UARTFCR_FE | UARTFCR_TFLS | UARTFCR_RFLS; +#endif + + return RT_EOK; +} + +static rt_err_t rt_uart_open(rt_device_t dev, rt_uint16_t oflag) +{ + struct rt_uart_ls1b *uart = (struct rt_uart_ls1b *)dev; + + RT_ASSERT(uart != RT_NULL); + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* Enable the UART Interrupt */ + UART_IER(uart->hw_base) |= UARTIER_IRXE; + + /* install interrupt */ + rt_hw_interrupt_install(uart->irq, rt_uart_irqhandler, RT_NULL); + rt_hw_interrupt_umask(uart->irq); + } + return RT_EOK; +} + +static rt_err_t rt_uart_close(rt_device_t dev) +{ + struct rt_uart_ls1b *uart = (struct rt_uart_ls1b *)dev; + + RT_ASSERT(uart != RT_NULL); + if (dev->flag & RT_DEVICE_FLAG_INT_RX) + { + /* Disable the UART Interrupt */ + UART_IER(uart->hw_base) &= ~(UARTIER_IRXE); + } + + return RT_EOK; +} + +static rt_size_t rt_uart_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size) +{ + rt_uint8_t *ptr; + struct rt_uart_ls1b *uart = (struct rt_uart_ls1b *)dev; + + RT_ASSERT(uart != 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 (uart->read_index != uart->save_index) + { + *ptr = uart->rx_buffer[uart->read_index]; + + uart->read_index ++; + if (uart->read_index >= RT_UART_RX_BUFFER_SIZE) + uart->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; + } + + return 0; +} + +static rt_size_t rt_uart_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size) +{ + char *ptr; + struct rt_uart_ls1b *uart = (struct rt_uart_ls1b *)dev; + + RT_ASSERT(uart != RT_NULL); + + ptr = (char *)buffer; + + if (dev->flag & RT_DEVICE_FLAG_STREAM) + { + /* stream mode */ + while (size) + { + if (*ptr == '\n') + { + /* FIFO status, contain valid data */ + while (!(UART_LSR(uart->hw_base) & (UARTLSR_TE | UARTLSR_TFE))); + /* write data */ + UART_DAT(uart->hw_base) = '\r'; + } + + /* FIFO status, contain valid data */ + while (!(UART_LSR(uart->hw_base) & (UARTLSR_TE | UARTLSR_TFE))); + /* write data */ + UART_DAT(uart->hw_base) = *ptr; + + ptr ++; + size --; + } + } + else + { + while (size != 0) + { + /* FIFO status, contain valid data */ + while (!(UART_LSR(uart->hw_base) & (UARTLSR_TE | UARTLSR_TFE))); + + /* write data */ + UART_DAT(uart->hw_base) = *ptr; + + ptr++; + size--; + } + } + + return (rt_size_t)ptr - (rt_size_t)buffer; +} + +void rt_hw_uart_init(void) +{ + struct rt_uart_ls1b *uart; + + /* get uart device */ + uart = &uart_device; + + /* device initialization */ + uart->parent.type = RT_Device_Class_Char; + rt_memset(uart->rx_buffer, 0, sizeof(uart->rx_buffer)); + uart->read_index = uart->save_index = 0; + +#if defined(RT_USING_UART0) + uart->hw_base = UART0_BASE; + uart->irq = LS1B_UART0_IRQ; +#elif defined(RT_USING_UART1) + uart->hw_base = UART1_BASE; + uart->irq = LS1B_UART1_IRQ; +#endif + + /* device interface */ + uart->parent.init = rt_uart_init; + uart->parent.open = rt_uart_open; + uart->parent.close = rt_uart_close; + uart->parent.read = rt_uart_read; + uart->parent.write = rt_uart_write; + uart->parent.control = RT_NULL; + uart->parent.user_data = RT_NULL; + + rt_device_register(&uart->parent, "uart0", + RT_DEVICE_FLAG_RDWR | + RT_DEVICE_FLAG_STREAM | + RT_DEVICE_FLAG_INT_RX); +} +#endif /* end of UART */ + +/*@}*/ diff --git a/bsp/ls1bdev/drivers/uart.h b/bsp/ls1bdev/drivers/uart.h new file mode 100644 index 0000000000..763ba514bd --- /dev/null +++ b/bsp/ls1bdev/drivers/uart.h @@ -0,0 +1,97 @@ +/* + * File : uart.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2011, 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 + * 2011-08-08 lgnq first version for LS1B + */ +#ifndef __UART_H__ +#define __UART_H__ + +#include "ls1b.h" + +#define UART0_BASE 0xBFE40000 +#define UART0_1_BASE 0xBFE41000 +#define UART0_2_BASE 0xBFE42000 +#define UART0_3_BASE 0xBFE43000 +#define UART1_BASE 0xBFE44000 +#define UART1_1_BASE 0xBFE45000 +#define UART1_2_BASE 0xBFE46000 +#define UART1_3_BASE 0xBFE47000 +#define UART2_BASE 0xBFE48000 +#define UART3_BASE 0xBFE4C000 +#define UART4_BASE 0xBFE6C000 +#define UART5_BASE 0xBFE7C000 + +/* UART registers */ +#define UART_DAT(base) __REG8(base + 0x00) +#define UART_IER(base) __REG8(base + 0x01) +#define UART_IIR(base) __REG8(base + 0x02) +#define UART_FCR(base) __REG8(base + 0x02) +#define UART_LCR(base) __REG8(base + 0x03) +#define UART_MCR(base) __REG8(base + 0x04) +#define UART_LSR(base) __REG8(base + 0x05) +#define UART_MSR(base) __REG8(base + 0x06) + +#define UART_LSB(base) __REG8(base + 0x00) +#define UART_MSB(base) __REG8(base + 0x01) + +/* UART0 registers */ +#define UART0_DAT __REG8(UART0_BASE + 0x00) +#define UART0_IER __REG8(UART0_BASE + 0x01) +#define UART0_IIR __REG8(UART0_BASE + 0x02) +#define UART0_FCR __REG8(UART0_BASE + 0x02) +#define UART0_LCR __REG8(UART0_BASE + 0x03) +#define UART0_MCR __REG8(UART0_BASE + 0x04) +#define UART0_LSR __REG8(UART0_BASE + 0x05) +#define UART0_MSR __REG8(UART0_BASE + 0x06) + +#define UART0_LSB __REG8(UART0_BASE + 0x00) +#define UART0_MSB __REG8(UART0_BASE + 0x01) + +/* UART1 registers */ +#define UART1_DAT __REG8(UART1_BASE + 0x00) +#define UART1_IER __REG8(UART1_BASE + 0x01) +#define UART1_IIR __REG8(UART1_BASE + 0x02) +#define UART1_FCR __REG8(UART1_BASE + 0x02) +#define UART1_LCR __REG8(UART1_BASE + 0x03) +#define UART1_MCR __REG8(UART1_BASE + 0x04) +#define UART1_LSR __REG8(UART1_BASE + 0x05) +#define UART1_MSR __REG8(UART1_BASE + 0x06) + +#define UART1_LSB __REG8(UART1_BASE + 0x00) +#define UART1_MSB __REG8(UART1_BASE + 0x01) + +/* UART interrupt enable register value */ +#define UARTIER_IME (1 << 3) +#define UARTIER_ILE (1 << 2) +#define UARTIER_ITXE (1 << 1) +#define UARTIER_IRXE (1 << 0) + +/* UART line control register value */ +#define UARTLCR_DLAB (1 << 7) +#define UARTLCR_BCB (1 << 6) +#define UARTLCR_SPB (1 << 5) +#define UARTLCR_EPS (1 << 4) +#define UARTLCR_PE (1 << 3) +#define UARTLCR_SB (1 << 2) + +/* UART line status register value */ +#define UARTLSR_ERROR (1 << 7) +#define UARTLSR_TE (1 << 6) +#define UARTLSR_TFE (1 << 5) +#define UARTLSR_BI (1 << 4) +#define UARTLSR_FE (1 << 3) +#define UARTLSR_PE (1 << 2) +#define UARTLSR_OE (1 << 1) +#define UARTLSR_DR (1 << 0) + +void rt_hw_uart_init(void); + +#endif diff --git a/bsp/ls1bdev/rtconfig.h b/bsp/ls1bdev/rtconfig.h index 337edd5402..8a2ad89a44 100644 --- a/bsp/ls1bdev/rtconfig.h +++ b/bsp/ls1bdev/rtconfig.h @@ -1,164 +1,223 @@ -/* RT-Thread config file */ #ifndef __RTTHREAD_CFG_H__ #define __RTTHREAD_CFG_H__ -/* RT_NAME_MAX*/ -#define RT_NAME_MAX 10 +// -/* RT_ALIGN_SIZE*/ +// +#define RT_NAME_MAX 10 +// #define RT_ALIGN_SIZE 4 - -/* PRIORITY_MAX */ -#define RT_THREAD_PRIORITY_MAX 256 - -/* Tick per Second */ +// +// 8 +// 32 +// 256 +// +#define RT_THREAD_PRIORITY_MAX 32 +// #define RT_TICK_PER_SECOND 100 - -/* SECTION: RT_DEBUG */ -/* Thread Debug */ +//
#define RT_DEBUG +// +// #define RT_THREAD_DEBUG +// #define RT_USING_OVERFLOW_CHECK +//
-/* Using Hook */ +// #define RT_USING_HOOK - -/* Using Software Timer */ -/* #define RT_USING_TIMER_SOFT */ -#define RT_TIMER_THREAD_PRIO 4 +//
+// #define RT_USING_TIMER_SOFT +// +#define RT_TIMER_THREAD_PRIO 4 +// #define RT_TIMER_THREAD_STACK_SIZE 512 +// #define RT_TIMER_TICK_PER_SECOND 10 +//
-/* SECTION: IPC */ -/* Using Semaphore */ +//
+// #define RT_USING_SEMAPHORE - -/* Using Mutex */ +// #define RT_USING_MUTEX - -/* Using Event */ +// #define RT_USING_EVENT - -/* Using MailBox */ +// #define RT_USING_MAILBOX - -/* Using Message Queue */ +// #define RT_USING_MESSAGEQUEUE +//
-/* SECTION: Memory Management */ -/* Using Memory Pool Management*/ +//
+// #define RT_USING_MEMPOOL - -/* Using Dynamic Heap Management */ +// +#define RT_USING_MEMHEAP +// #define RT_USING_HEAP +// +#define RT_USING_SMALL_MEM +// +// #define RT_USING_SLAB +//
-/* Using SLAB MM */ -#define RT_USING_SLAB -/* #define RT_USING_SMALL_MEM */ - -/* SECTION: Device System */ -/* Using Device System */ +//
#define RT_USING_DEVICE +// #define RT_USING_UART +// #define RT_USING_UART0 +// #define RT_UART_RX_BUFFER_SIZE 64 +//
-/* SECTION: Console options */ -/* the buffer size of console */ +//
#define RT_USING_CONSOLE +// #define RT_CONSOLEBUF_SIZE 128 +// +#define RT_CONSOLE_DEVICE_NAME "uart0" +//
-/* SECTION: the runtime libc library */ -/* the runtime libc library */ -/* #define RT_USING_NEWLIB */ -/* #define RT_USING_PTHREADS */ - -/* SECTION: finsh, a C-Express shell */ -/* Using FinSH as Shell*/ +// +#define RT_USING_COMPONENTS_INIT +//
#define RT_USING_FINSH -/* Using symbol table */ +// #define FINSH_USING_SYMTAB +// #define FINSH_USING_DESCRIPTION -#define FINSH_DEVICE_NAME "uart0" - -/* SECTION: device filesystem support */ -/* #define RT_USING_DFS */ -/* #define RT_USING_DFS_ELMFAT */ -#define RT_USING_DFS_ROMFS -/* #define RT_USING_DFS_DEVFS */ - -/* the max number of mounted filesystem */ -#define DFS_FILESYSTEMS_MAX 2 -/* the max number of opened files */ -#define DFS_FD_MAX 4 -/* the max number of cached sector */ -#define DFS_CACHE_MAX_NUM 4 -/* Using working directory */ -#define DFS_USING_WORKDIR - -/* SECTION: lwip, a lighwight TCP/IP protocol stack */ -/* #define RT_USING_LWIP */ -#define RT_LWIP_USING_RT_MEM - -/* Enable ICMP protocol*/ +// +#define FINSH_THREAD_STACK_SIZE 4096 +//
+ +//
+// +// #define RT_USING_NEWLIB +// +// #define RT_USING_PTHREADS +//
+ +//
+// #define RT_USING_DFS +// +// #define DFS_USING_WORKDIR +// +#define DFS_FILESYSTEMS_MAX 2 +// +#define DFS_FD_MAX 4 +// +#define RT_USING_DFS_ELMFAT +// +// 1 +// 2 +// +#define RT_DFS_ELM_USE_LFN 1 +// +#define RT_DFS_ELM_MAX_LFN 64 +// +// #define RT_USING_DFS_YAFFS2 +// +// #define RT_USING_DFS_UFFS +// +// #define RT_USING_DFS_DEVFS +// +// #define RT_USING_DFS_NFS +// +#define RT_NFS_HOST_EXPORT "192.168.1.5:/" +//
+ +//
+// #define RT_USING_LWIP +// #define RT_LWIP_ICMP -/* Enable UDP protocol*/ +// +// #define RT_LWIP_IGMP +// #define RT_LWIP_UDP -/* Enable TCP protocol*/ +// #define RT_LWIP_TCP -/* Enable DNS */ +// #define RT_LWIP_DNS - -/* the number of simulatenously active TCP connections*/ -#define RT_LWIP_TCP_PCB_NUM 5 - -/* ip address of target*/ -#define RT_LWIP_IPADDR0 192 -#define RT_LWIP_IPADDR1 168 -#define RT_LWIP_IPADDR2 1 -#define RT_LWIP_IPADDR3 30 - -/* gateway address of target*/ -#define RT_LWIP_GWADDR0 192 -#define RT_LWIP_GWADDR1 168 -#define RT_LWIP_GWADDR2 1 -#define RT_LWIP_GWADDR3 1 - -/* mask address of target*/ -#define RT_LWIP_MSKADDR0 255 -#define RT_LWIP_MSKADDR1 255 -#define RT_LWIP_MSKADDR2 255 -#define RT_LWIP_MSKADDR3 0 - -/* tcp thread options */ -#define RT_LWIP_TCPTHREAD_PRIORITY 12 -#define RT_LWIP_TCPTHREAD_MBOX_SIZE 4 -#define RT_LWIP_TCPTHREAD_STACKSIZE 1024 - -/* ethernet if thread options */ -#define RT_LWIP_ETHTHREAD_PRIORITY 15 -#define RT_LWIP_ETHTHREAD_MBOX_SIZE 4 -#define RT_LWIP_ETHTHREAD_STACKSIZE 512 - -/* SECTION: RT-Thread/GUI */ +// +#define RT_LWIP_PBUF_NUM 4 +// +#define RT_LWIP_TCP_PCB_NUM 3 +// +#define RT_LWIP_TCP_SND_BUF 2048 +// +#define RT_LWIP_TCP_WND 2048 +// +// #define RT_LWIP_SNMP +// +// #define RT_LWIP_DHCP +// +#define RT_LWIP_TCP_SEG_NUM 4 +// +#define RT_LWIP_TCPTHREAD_PRIORITY 12 +// +#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 +// +#define RT_LWIP_TCPTHREAD_STACKSIZE 4096 +// +#define RT_LWIP_ETHTHREAD_PRIORITY 14 +// +#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 +// +#define RT_LWIP_ETHTHREAD_STACKSIZE 512 +// +#define RT_LWIP_IPADDR0 192 +#define RT_LWIP_IPADDR1 168 +#define RT_LWIP_IPADDR2 1 +#define RT_LWIP_IPADDR3 30 +// +#define RT_LWIP_GWADDR0 192 +#define RT_LWIP_GWADDR1 168 +#define RT_LWIP_GWADDR2 1 +#define RT_LWIP_GWADDR3 1 +// +#define RT_LWIP_MSKADDR0 255 +#define RT_LWIP_MSKADDR1 255 +#define RT_LWIP_MSKADDR2 255 +#define RT_LWIP_MSKADDR3 0 +//
+ +//
+// #define RT_USING_MODULE +// +// #define RT_USING_LIBDL +//
+ +//
#define RT_USING_RTGUI - -/* name length of RTGUI object */ -#define RTGUI_NAME_MAX 12 -/* support 16 weight font */ +// +#define RTGUI_NAME_MAX 16 +// #define RTGUI_USING_FONT16 -/* support 12 weight font */ +// #define RTGUI_USING_FONT12 -/* support Chinese font */ +// #define RTGUI_USING_FONTHZ -/* use DFS as file interface */ +// #define RTGUI_USING_DFS_FILERW -/* use bmp font as Chinese font */ +// +// #define RTGUI_USING_HZ_FILE +// #define RTGUI_USING_HZ_BMP -/* use small size in RTGUI */ +// #define RTGUI_USING_SMALL_SIZE -/* use mouse cursor */ -/* #define RTGUI_USING_MOUSE_CURSOR */ -/* default font size in RTGUI */ -#define RTGUI_DEFAULT_FONT_SIZE 16 +// +// #define RTGUI_USING_MOUSE_CURSOR +// +#define RTGUI_IMAGE_XPM +// +// #define RTGUI_IMAGE_JPEG +// +// #define RTGUI_IMAGE_PNG +// +#define RTGUI_IMAGE_BMP +//
+ +//
#endif -- GitLab