diff options
| author | Jonne <[email protected]> | 2020-04-10 21:40:33 +0800 |
|---|---|---|
| committer | Jonne <[email protected]> | 2020-04-10 23:28:36 +0800 |
| commit | b3c7bc964bdab9a4ff04f06e9cfb85bd2f9c6107 (patch) | |
| tree | d10cf89b31b4ffd6c773edec191c364cf9afdf3a /bsp/mini2440/drivers | |
| parent | 0f57faa591b4eb9cf8ec88bb092855369a71d19a (diff) | |
更新mini2440 bsp包:
1、加入Kconfig以支持图形化菜单配置
2、编译脚本中添加动态模块编译参数
3、开启自动初始化机制支持
4、重构串口驱动以解决开启posix支持后终端无响应问题
5、解决dm9000网卡驱动link up问题
6、添加mnt.c文件用来挂载文件系统
Diffstat (limited to 'bsp/mini2440/drivers')
| -rw-r--r-- | bsp/mini2440/drivers/SConscript | 4 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/board.c | 154 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/board.h | 1 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/console.c | 180 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/dm9000.c | 7 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/dm9000.h | 2 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/key.c | 2 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/sdcard.c | 9 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/touch.c | 2 | ||||
| -rw-r--r-- | bsp/mini2440/drivers/uart.c | 183 |
10 files changed, 245 insertions, 299 deletions
diff --git a/bsp/mini2440/drivers/SConscript b/bsp/mini2440/drivers/SConscript index 55c8b43cd5..8b36ce3aab 100644 --- a/bsp/mini2440/drivers/SConscript +++ b/bsp/mini2440/drivers/SConscript @@ -8,7 +8,7 @@ cwd = os.path.join(str(Dir('#')), 'drivers') src = Split(""" board.c led.c -console.c +uart.c """) if GetDepend('RT_USING_DFS'): @@ -18,7 +18,7 @@ if GetDepend('RT_USING_LWIP'): src += ['dm9000.c'] if GetDepend('RT_USING_RTGUI'): - src += ['touch.c', 'key.c', 'calibration.c'] + src += ['touch.c', 'key.c'] if GetDepend('RT_USING_FTK'): src += ['touch.c', 'key.c'] diff --git a/bsp/mini2440/drivers/board.c b/bsp/mini2440/drivers/board.c index fc623386b4..14e2e426df 100644 --- a/bsp/mini2440/drivers/board.c +++ b/bsp/mini2440/drivers/board.c @@ -26,6 +26,29 @@ */ /*@{*/ +#if defined(__CC_ARM) + extern int Image$$ER_ZI$$ZI$$Base; + extern int Image$$ER_ZI$$ZI$$Length; + extern int Image$$ER_ZI$$ZI$$Limit; +#elif (defined (__GNUC__)) + rt_uint8_t _irq_stack_start[1024]; + rt_uint8_t _fiq_stack_start[1024]; + rt_uint8_t _undefined_stack_start[512]; + rt_uint8_t _abort_stack_start[512]; + rt_uint8_t _svc_stack_start[4096] SECTION(".nobss"); +#endif + +#if defined(__CC_ARM) +extern int Image$$RW_IRAM1$$ZI$$Limit; +#define HEAP_BEGIN ((void*)&Image$$RW_IRAM1$$ZI$$Limit) +#elif defined(__GNUC__) +extern int __bss_end; +#define HEAP_BEGIN (((void*)&__bss_end) + 0x1000) +#endif + +#define HEAP_END (void*)(0x33F00000) + + extern rt_uint32_t PCLK, FCLK, HCLK, UCLK; extern void rt_hw_clock_init(void); @@ -35,26 +58,6 @@ extern void rt_hw_get_clock(void); extern void rt_hw_set_dividor(rt_uint8_t hdivn, rt_uint8_t pdivn); extern void rt_hw_set_clock(rt_uint8_t sdiv, rt_uint8_t pdiv, rt_uint8_t mdiv); -#define UART0 ((struct uartport *)&U0BASE) -struct serial_int_rx uart0_int_rx; -struct serial_device uart0 = -{ - UART0, - &uart0_int_rx, - RT_NULL -}; -struct rt_device uart0_device; - -#define UART2 ((struct uartport *)&U2BASE) -struct serial_int_rx uart2_int_rx; -struct serial_device uart2 = -{ - UART2, - &uart2_int_rx, - RT_NULL -}; -struct rt_device uart2_device; - /** * This function will handle rtos timer */ @@ -64,92 +67,6 @@ static void rt_timer_handler(int vector, void *param) } /** - * This function will handle serial - */ -static void rt_serial0_handler(int vector, void *param) -{ - INTSUBMSK |= (BIT_SUB_RXD0); - - rt_hw_serial_isr(&uart0_device); - - SUBSRCPND |= BIT_SUB_RXD0; - - /* Unmask sub interrupt (RXD0) */ - INTSUBMSK &=~(BIT_SUB_RXD0); -} - -/** - * This function will handle serial - */ -static void rt_serial2_handler(int vector, void *param) -{ - INTSUBMSK |= (BIT_SUB_RXD2); - - rt_hw_serial_isr(&uart2_device); - - SUBSRCPND |= BIT_SUB_RXD2; - - /* Unmask sub interrupt (RXD0) */ - INTSUBMSK &=~(BIT_SUB_RXD2); -} - -/** - * This function will handle init uart - */ -static void rt_hw_uart_init(void) -{ - int i; - /* UART0 port configure */ - GPHCON |= 0xAA; - /* PULLUP is disable */ - GPHUP |= 0xF; - - /* FIFO enable, Tx/Rx FIFO clear */ - uart0.uart_device->ufcon = 0x0; - /* disable the flow control */ - uart0.uart_device->umcon = 0x0; - /* Normal,No parity,1 stop,8 bit */ - uart0.uart_device->ulcon = 0x3; - /* - * tx=level,rx=edge,disable timeout int.,enable rx error int., - * normal,interrupt or polling - */ - uart0.uart_device->ucon = 0x245; - /* Set uart0 bps */ - uart0.uart_device->ubrd = (rt_int32_t)(PCLK / (BPS * 16)) - 1; - /* output PCLK to UART0/1, PWMTIMER */ - CLKCON |= 0x0D00; - - /* FIFO enable, Tx/Rx FIFO clear */ - uart2.uart_device->ufcon = 0x0; - /* disable the flow control */ - uart2.uart_device->umcon = 0x0; - /* Normal,No parity,1 stop,8 bit */ - uart2.uart_device->ulcon = 0x3; - /* - * tx=level,rx=edge,disable timeout int.,enable rx error int., - * normal,interrupt or polling - */ - uart2.uart_device->ucon = 0x245; - /* Set uart0 bps */ - uart2.uart_device->ubrd = (rt_int32_t)(PCLK / (BPS * 16)) - 1; - - for (i = 0; i < 100; i++); - - /* install uart0 isr */ - INTSUBMSK &= ~(BIT_SUB_RXD0); - - /* install uart2 isr */ - INTSUBMSK &= ~(BIT_SUB_RXD2); - - rt_hw_interrupt_install(INTUART0, rt_serial0_handler, RT_NULL, "UART0"); - rt_hw_interrupt_umask(INTUART0); - - rt_hw_interrupt_install(INTUART2, rt_serial2_handler, RT_NULL, "UART2"); - rt_hw_interrupt_umask(INTUART2); -} - -/** * This function will init timer4 for system ticks */ static void rt_hw_timer_init(void) @@ -177,6 +94,12 @@ static void rt_hw_timer_init(void) */ void rt_hw_board_init(void) { + rt_hw_cpu_icache_enable(); + rt_hw_cpu_dcache_enable(); + + /* init hardware interrupt */ + rt_hw_interrupt_init(); + /* initialize the system clock */ rt_hw_clock_init(); @@ -186,14 +109,27 @@ void rt_hw_board_init(void) /* initialize led port */ rt_hw_led_init(); - /* initialize uart */ - rt_hw_uart_init(); - /* initialize mmu */ rt_hw_mmu_init(); /* initialize timer4 */ rt_hw_timer_init(); + + /* initialize system heap */ + rt_system_heap_init(HEAP_BEGIN, HEAP_END); + + rt_components_board_init(); + +#ifdef RT_USING_CONSOLE + rt_console_set_device("uart0"); +#endif + } +#ifdef RT_USING_MODULE +int rt_system_module_init(void) +{ + return 0; +} +#endif /*@}*/ diff --git a/bsp/mini2440/drivers/board.h b/bsp/mini2440/drivers/board.h index 2635ab147a..434f725216 100644 --- a/bsp/mini2440/drivers/board.h +++ b/bsp/mini2440/drivers/board.h @@ -16,7 +16,6 @@ #define __BOARD_H__ #include <s3c24x0.h> -#include <serial.h> void rt_hw_board_init(void); void rt_hw_sdcard_init(void); diff --git a/bsp/mini2440/drivers/console.c b/bsp/mini2440/drivers/console.c deleted file mode 100644 index 70a57a7370..0000000000 --- a/bsp/mini2440/drivers/console.c +++ /dev/null @@ -1,180 +0,0 @@ -#include <rtthread.h> - -#include <serial.h> - -#define RT_CONSOLE_WIDTH 240 -#define RT_CONSOLE_HEIGHT 320 - -#define RT_CONSOLE_FONT_WIDTH 8 -#define RT_CONSOLE_FONT_HEIGHT 16 - -#define RT_CONSOLE_COL (RT_CONSOLE_WIDTH/RT_CONSOLE_FONT_WIDTH) -#define RT_CONSOLE_ROW (RT_CONSOLE_HEIGHT/RT_CONSOLE_FONT_HEIGHT) - -#define RT_CONSOLE_TAB 4 - -#define RT_CONSOLE_FOREPIXEL (0x001f) - -extern struct serial_device uart0; - -struct rt_console -{ - rt_uint8_t* video_ptr; - rt_uint8_t* font_ptr; - - /* bpp and pixel of width */ - rt_uint8_t bpp; - rt_uint32_t pitch; - - /* current cursor */ - rt_uint8_t current_col; - rt_uint8_t current_row; -}; -struct rt_console console; - -void rt_hw_console_init(rt_uint8_t* video_ptr, rt_uint8_t* font_ptr, rt_uint8_t bpp); -void rt_hw_console_newline(void); -void rt_hw_console_putc(char c); -void rt_hw_console_clear(void); - -void rt_hw_console_init(rt_uint8_t* video_ptr, rt_uint8_t* font_ptr, rt_uint8_t bpp) -{ - rt_memset(&console, 0, sizeof(struct rt_console)); - - console.video_ptr = video_ptr; - console.font_ptr = font_ptr; - console.bpp = bpp; - console.pitch = console.bpp * RT_CONSOLE_WIDTH; - - rt_hw_console_clear(); -} - -void rt_hw_console_putc(char c) -{ - switch (c) - { - case 10: - case 11: - case 12: - case 13: - /* to next line */ - rt_hw_console_newline(); - console.current_col = 0; - break; - - case 9: - console.current_col += RT_CONSOLE_TAB; - break; - - default: - { - rt_uint8_t* font_ptr; - register rt_uint32_t cursor; - register rt_uint32_t i, j; - - if (console.current_col == RT_CONSOLE_COL) - { - rt_hw_console_newline(); - console.current_col = 0; - - rt_hw_console_putc(c); - return; - } - - font_ptr = console.font_ptr + c * RT_CONSOLE_FONT_HEIGHT; - cursor = (console.current_row * RT_CONSOLE_FONT_HEIGHT) * console.pitch - + console.current_col * RT_CONSOLE_FONT_WIDTH * console.bpp; - - for (i = 0; i < RT_CONSOLE_FONT_HEIGHT; i ++ ) - { - for (j = 0; j < RT_CONSOLE_FONT_WIDTH; j ++) - { - if ( ((font_ptr[i] >> (7-j)) & 0x01) != 0 ) - { - /* draw a pixel */ - rt_uint8_t *ptr = &(console.video_ptr[cursor + i * console.pitch + j * console.bpp]); - switch(console.bpp) - { - case 1: - *ptr = RT_CONSOLE_FOREPIXEL; - break; - case 2: - *(rt_uint16_t*)ptr = RT_CONSOLE_FOREPIXEL; - break; - case 3: - ptr[0] = RT_CONSOLE_FOREPIXEL & 0xff; - ptr[1] = (RT_CONSOLE_FOREPIXEL >> 8) & 0xff; - ptr[2] = (RT_CONSOLE_FOREPIXEL >> 16) & 0xff; - break; - case 4: - *(rt_uint32_t*)ptr = RT_CONSOLE_FOREPIXEL; - break; - } - } - } - } - - console.current_col ++; - } - break; - } -} - -void rt_hw_console_newline() -{ - console.current_row ++; - if (console.current_row >= RT_CONSOLE_ROW) - { - rt_uint32_t i; - - /* scroll to next line */ - for (i = 0; i < RT_CONSOLE_ROW - 1; i ++) - { - rt_memcpy(console.video_ptr + i * RT_CONSOLE_FONT_HEIGHT * console.pitch, - console.video_ptr + (i + 1) * RT_CONSOLE_FONT_HEIGHT * console.pitch, - RT_CONSOLE_FONT_HEIGHT * console.pitch); - } - - /* clear last line */ - rt_memset(console.video_ptr + (RT_CONSOLE_ROW - 1) * RT_CONSOLE_FONT_HEIGHT * console.pitch, - 0, - RT_CONSOLE_FONT_HEIGHT * console.pitch); - - console.current_row = RT_CONSOLE_ROW - 1; - } -} - -void rt_hw_console_clear() -{ - console.current_col = 0; - console.current_row = 0; - - rt_memset(console.video_ptr, 0, RT_CONSOLE_HEIGHT * console.pitch); -} - -/* write one character to serial, must not trigger interrupt */ -void rt_hw_serial_putc(const char c) -{ - /* - to be polite with serial console add a line feed - to the carriage return character - */ - if (c=='\n')rt_hw_serial_putc('\r'); - - while (!(uart0.uart_device->ustat & USTAT_TXB_EMPTY)); - uart0.uart_device->utxh = (c & 0x1FF); -} - -/** - * This function is used by rt_kprintf to display a string on console. - * - * @param str the displayed string - */ -void rt_hw_console_output(const char* str) -{ - while (*str) - { - rt_hw_serial_putc(*str++); - } -} - diff --git a/bsp/mini2440/drivers/dm9000.c b/bsp/mini2440/drivers/dm9000.c index e3f1f0d634..22afb322c7 100644 --- a/bsp/mini2440/drivers/dm9000.c +++ b/bsp/mini2440/drivers/dm9000.c @@ -287,6 +287,9 @@ static rt_err_t rt_dm9000_init(rt_device_t dev) } } + /* send a notify */ + eth_device_linkchange(&dm9000_device.parent, RT_TRUE); + /* see what we've got */ lnk = phy_read(17) >> 12; rt_kprintf("operating at "); @@ -588,7 +591,7 @@ void INTEINT4_7_handler(int irqno, void *param) EINTPEND = eint_pend; } -void rt_hw_dm9000_init() +int rt_hw_dm9000_init() { /* Set GPF7 as EINT7 */ GPFCON = GPFCON & (~(3 << 14)) | (2 << 14); @@ -641,6 +644,8 @@ void rt_hw_dm9000_init() rt_hw_interrupt_umask(INTEINT4_7); } +INIT_DEVICE_EXPORT(rt_hw_dm9000_init); + void dm9000a(void) { rt_kprintf("\n"); diff --git a/bsp/mini2440/drivers/dm9000.h b/bsp/mini2440/drivers/dm9000.h index 1dda60bfd2..28499c22d8 100644 --- a/bsp/mini2440/drivers/dm9000.h +++ b/bsp/mini2440/drivers/dm9000.h @@ -143,6 +143,6 @@ #define GPCR_GEP_CNTL (1<<0) -void rt_hw_dm9000_init(void); +int rt_hw_dm9000_init(void); #endif diff --git a/bsp/mini2440/drivers/key.c b/bsp/mini2440/drivers/key.c index 3c73c7a788..d75ffd6d26 100644 --- a/bsp/mini2440/drivers/key.c +++ b/bsp/mini2440/drivers/key.c @@ -79,7 +79,7 @@ static void rt_hw_key_isr(void) /** * This function is only for QEMU emulation */ -static void rt_key_handler(int vector) +static void rt_key_handler(int vector, void *param) { INTSUBMSK |= (BIT_SUB_RXD1); diff --git a/bsp/mini2440/drivers/sdcard.c b/bsp/mini2440/drivers/sdcard.c index b2ab684e48..0f5b79bb25 100644 --- a/bsp/mini2440/drivers/sdcard.c +++ b/bsp/mini2440/drivers/sdcard.c @@ -550,7 +550,7 @@ static rt_size_t rt_sdcard_write(rt_device_t dev, return size; } -void rt_hw_sdcard_init(void) +int rt_hw_sdcard_init(void) { rt_uint8_t i, status; rt_uint8_t *sector; @@ -574,7 +574,7 @@ void rt_hw_sdcard_init(void) { rt_kprintf("allocate partition sector buffer failed\n"); - return; + return RT_ERROR; } status = sd_readblock(0, sector); if (status == RT_EOK) @@ -637,12 +637,15 @@ void rt_hw_sdcard_init(void) /* release sector buffer */ rt_free(sector); - return; + return RT_ERROR; } else { rt_kprintf("sdcard init failed\n"); } + + return RT_EOK; } +INIT_BOARD_EXPORT(rt_hw_sdcard_init); #endif diff --git a/bsp/mini2440/drivers/touch.c b/bsp/mini2440/drivers/touch.c index 08d41080be..e584c379e3 100644 --- a/bsp/mini2440/drivers/touch.c +++ b/bsp/mini2440/drivers/touch.c @@ -349,7 +349,7 @@ static void s3c2410_intc_stylus_updown(void) SUBSRCPND |= BIT_SUB_TC; } -static void rt_touch_handler(int irqno) +static void rt_touch_handler(int irqno, void *param) { if (SUBSRCPND & BIT_SUB_ADC) { diff --git a/bsp/mini2440/drivers/uart.c b/bsp/mini2440/drivers/uart.c new file mode 100644 index 0000000000..f7bf1d9461 --- /dev/null +++ b/bsp/mini2440/drivers/uart.c @@ -0,0 +1,183 @@ +/* + * File : uart.c + * Drivers for s3c2440 uarts. + * Change Logs: + * Date Author Notes + * 2020-04-09 Jonne Code refactoring for new bsp + */ + +#include <rthw.h> +#include <rtdevice.h> +#include <board.h> + +#define ULCON_OFS 0x00 +#define UCON_OFS 0x04 +#define UFCON_OFS 0x08 +#define UMCON_OFS 0x0c +#define UTRSTAT_OFS 0x10 +#define UERSTAT_OFS 0x14 +#define UFSTAT_OFS 0x18 +#define UMSTAT_OFS 0x1c +#define UTXH_OFS 0x20 +#define URXH_OFS 0x24 +#define UBRDIV_OFS 0x28 + +#define readl(addr) (*(volatile unsigned long *)(addr)) +#define writel(addr, value) (*(volatile unsigned long *)(addr) = value) + +#define PCLK_HZ 50000000 + +struct hw_uart_device +{ + rt_uint32_t hw_base; + rt_uint32_t irqno; +}; + +static rt_err_t s3c2440_serial_configure(struct rt_serial_device *serial, struct serial_configure *cfg) +{ + struct hw_uart_device* uart = serial->parent.user_data; + + writel(uart->hw_base + UBRDIV_OFS, PCLK_HZ / (cfg->baud_rate * 16)); + + writel(uart->hw_base + ULCON_OFS, 0x03);// 8bit data, 1bit stop, No parity + writel(uart->hw_base + UCON_OFS, 0x05); + writel(uart->hw_base + UFCON_OFS, 0x00); + writel(uart->hw_base + UMCON_OFS, 0x00); + + return RT_EOK; +} + +static rt_err_t s3c2440_serial_control(struct rt_serial_device *serial, int cmd, void *arg) +{ + struct hw_uart_device *uart; + + RT_ASSERT(serial != RT_NULL); + uart = (struct hw_uart_device *)serial->parent.user_data; + + switch (cmd) + { + case RT_DEVICE_CTRL_CLR_INT: + /* disable rx irq */ + INTSUBMSK |= BIT_SUB_RXD0; + + break; + + case RT_DEVICE_CTRL_SET_INT: + /* enable rx irq */ + INTSUBMSK &= ~(BIT_SUB_RXD0); + break; + } + + return RT_EOK; +} +static int s3c2440_putc(struct rt_serial_device *serial, char c) +{ + struct hw_uart_device* uart = serial->parent.user_data; + + while(!(readl(uart->hw_base + UTRSTAT_OFS) & (1<<2))) + { + } + + writel(uart->hw_base + UTXH_OFS, c); + + return 0; + + +} +static int s3c2440_getc(struct rt_serial_device *serial) +{ + struct hw_uart_device* uart = serial->parent.user_data; + int ch = -1; + + if(readl(uart->hw_base + UTRSTAT_OFS) & (1<<0)) + { + ch = readl(uart->hw_base + URXH_OFS) & 0x000000FF; + } + + return ch; +} + +static void rt_hw_uart_isr(int irqno, void *param) +{ + struct rt_serial_device *serial = (struct rt_serial_device *)param; + + rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND); + + /*clear SUBSRCPND*/ + if(irqno == INTUART0) + { + SUBSRCPND = BIT_SUB_RXD0; + } + else if(irqno == INTUART1) + { + SUBSRCPND = BIT_SUB_RXD1; + } + else + { + SUBSRCPND = BIT_SUB_RXD2; + } +} + +static struct rt_uart_ops s3c2440_uart_ops = { + .configure = s3c2440_serial_configure, + .control = s3c2440_serial_control, + .putc = s3c2440_putc, + .getc = s3c2440_getc +}; + + +static struct rt_serial_device _serial0 = { + .ops = &s3c2440_uart_ops, + .config = RT_SERIAL_CONFIG_DEFAULT, + .serial_rx = NULL, + .serial_tx = NULL +}; +static struct hw_uart_device _hwserial0 = { + .hw_base = 0x50000000, + .irqno = INTUART0 +}; + +static struct rt_serial_device _serial1 = { + .ops = &s3c2440_uart_ops, + .config = RT_SERIAL_CONFIG_DEFAULT, + .serial_rx = NULL, + .serial_tx = NULL +}; +static struct hw_uart_device _hwserial1 = { + .hw_base = 0x50004000, + .irqno = INTUART1 +}; + +static struct rt_serial_device _serial2 = { + .ops = &s3c2440_uart_ops, + .config = RT_SERIAL_CONFIG_DEFAULT, + .serial_rx = NULL, + .serial_tx = NULL +}; +static struct hw_uart_device _hwserial2 = { + .hw_base = 0x50008000, + .irqno = INTUART2 +}; + + +int rt_hw_uart_init(void) +{ + /* register UART0 device */ + rt_hw_serial_register(&_serial0, "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, &_hwserial0); + rt_hw_interrupt_install(_hwserial0.irqno, rt_hw_uart_isr, &_serial0, "uart0"); + rt_hw_interrupt_umask(INTUART0); + + /* register UART1 device */ + rt_hw_serial_register(&_serial1, "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, &_hwserial1); + rt_hw_interrupt_install(_hwserial1.irqno, rt_hw_uart_isr, &_serial1, "uart1"); + rt_hw_interrupt_umask(INTUART1); + + /* register UART2 device */ + rt_hw_serial_register(&_serial2, "uart2", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, &_hwserial2); + rt_hw_interrupt_install(_hwserial2.irqno, rt_hw_uart_isr, &_serial2, "uart2"); + rt_hw_interrupt_umask(INTUART2); + + return 0; +} + +INIT_BOARD_EXPORT(rt_hw_uart_init); |
