update FM3 MB9BF506R serial driver
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1997 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
8a960a86f5
commit
3b06be1cde
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* File : board.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2009 - 2011 RT-Thread Develop Team
|
||||
* COPYRIGHT (C) 2009 - 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
|
||||
|
@ -31,7 +31,6 @@ extern const uint32_t SystemFrequency;
|
|||
|
||||
/**
|
||||
* This is the timer interrupt service routine.
|
||||
*
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
|
@ -45,7 +44,7 @@ void SysTick_Handler(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* This function will initial FM3 Easy Kit board.
|
||||
* This function will initial FM3 Easy Kit board.
|
||||
*/
|
||||
void rt_hw_board_init(void)
|
||||
{
|
||||
|
@ -55,7 +54,7 @@ void rt_hw_board_init(void)
|
|||
/* initialize UART device */
|
||||
rt_hw_serial_init();
|
||||
/* set console as UART device */
|
||||
rt_console_set_device("uart2");
|
||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||
|
||||
/* initialize nand flash device */
|
||||
rt_hw_nand_init();
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
|
||||
#define RT_CONSOLE_FOREPIXEL (0x001f)
|
||||
|
||||
extern struct serial_device uart2;
|
||||
extern struct serial_device uart0;
|
||||
|
||||
struct rt_console
|
||||
{
|
||||
rt_uint8_t* video_ptr;
|
||||
rt_uint8_t* font_ptr;
|
||||
rt_uint8_t *video_ptr;
|
||||
rt_uint8_t *font_ptr;
|
||||
|
||||
/* bpp and pixel of width */
|
||||
rt_uint8_t bpp;
|
||||
|
@ -32,12 +32,12 @@ struct rt_console
|
|||
};
|
||||
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_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)
|
||||
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));
|
||||
|
||||
|
@ -53,74 +53,75 @@ 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 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;
|
||||
case 9:
|
||||
console.current_col += RT_CONSOLE_TAB;
|
||||
break;
|
||||
|
||||
default:
|
||||
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_uint8_t* font_ptr;
|
||||
register rt_uint32_t cursor;
|
||||
register rt_uint32_t i, j;
|
||||
rt_hw_console_newline();
|
||||
console.current_col = 0;
|
||||
|
||||
if (console.current_col == RT_CONSOLE_COL)
|
||||
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 ++)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
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;
|
||||
|
||||
console.current_col ++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void rt_hw_console_newline()
|
||||
void rt_hw_console_newline(void)
|
||||
{
|
||||
console.current_row ++;
|
||||
if (console.current_row >= RT_CONSOLE_ROW)
|
||||
|
@ -144,7 +145,7 @@ void rt_hw_console_newline()
|
|||
}
|
||||
}
|
||||
|
||||
void rt_hw_console_clear()
|
||||
void rt_hw_console_clear(void)
|
||||
{
|
||||
console.current_col = 0;
|
||||
console.current_row = 0;
|
||||
|
@ -159,10 +160,12 @@ 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');
|
||||
if (c=='\n')
|
||||
rt_hw_serial_putc('\r');
|
||||
|
||||
while (!(uart2.uart_device->SSR & SSR_TDRE));
|
||||
uart2.uart_device->TDR = (c & 0x1FF);
|
||||
while (!(uart0.uart_device->SSR & SSR_TDRE))
|
||||
;
|
||||
uart0.uart_device->TDR = (c & 0x1FF);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,7 +173,7 @@ void rt_hw_serial_putc(const char c)
|
|||
*
|
||||
* @param str the displayed string
|
||||
*/
|
||||
void rt_hw_console_output(const char* str)
|
||||
void rt_hw_console_output(const char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
MEMORY
|
||||
{
|
||||
CODE (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000
|
||||
DATA (rw) : ORIGIN = 0x1FFFC000, LENGTH = 0x00010000
|
||||
DATA (rw) : ORIGIN = 0x1FFF8000, LENGTH = 0x00010000
|
||||
}
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
#ifndef __RTTHREAD_CFG_H__
|
||||
#define __RTTHREAD_CFG_H__
|
||||
|
||||
/* RT_NAME_MAX*/
|
||||
#define RT_NAME_MAX 8
|
||||
/* RT_NAME_MAX */
|
||||
#define RT_NAME_MAX 8
|
||||
|
||||
/* RT_ALIGN_SIZE*/
|
||||
#define RT_ALIGN_SIZE 8
|
||||
/* RT_ALIGN_SIZE */
|
||||
#define RT_ALIGN_SIZE 8
|
||||
|
||||
/* PRIORITY_MAX */
|
||||
#define RT_THREAD_PRIORITY_MAX 32
|
||||
|
||||
/* Tick per Second */
|
||||
#define RT_TICK_PER_SECOND 100
|
||||
#define RT_TICK_PER_SECOND 100
|
||||
|
||||
/* SECTION: RT_DEBUG */
|
||||
/* Thread Debug */
|
||||
|
@ -52,14 +52,16 @@
|
|||
/* Using Device System */
|
||||
#define RT_USING_DEVICE
|
||||
/* RT_USING_UART */
|
||||
#define RT_USING_UART2
|
||||
#define RT_USING_UART0
|
||||
#define RT_UART_RX_BUFFER_SIZE 64
|
||||
|
||||
/* SECTION: Console options */
|
||||
/* #define RT_TINY_SIZE */
|
||||
#define RT_USING_CONSOLE
|
||||
/* the buffer size of console */
|
||||
#define RT_CONSOLEBUF_SIZE 128
|
||||
#define RT_CONSOLEBUF_SIZE 128
|
||||
/* the device used by console */
|
||||
#define RT_CONSOLE_DEVICE_NAME "uart0"
|
||||
|
||||
/* SECTION: finsh, a C-Express shell */
|
||||
/* Using FinSH as Shell*/
|
||||
|
@ -67,23 +69,24 @@
|
|||
/* Using symbol table */
|
||||
#define FINSH_USING_SYMTAB
|
||||
#define FINSH_USING_DESCRIPTION
|
||||
#define FINSH_THREAD_STACK_SIZE 1024
|
||||
#define FINSH_THREAD_STACK_SIZE 1024
|
||||
#define FINSH_DEVICE_NAME RT_CONSOLE_DEVICE_NAME
|
||||
|
||||
/* SECTION: Device filesystem support */
|
||||
/* using DFS support */
|
||||
#define RT_USING_DFS
|
||||
#define RT_USING_DFS_ELMFAT
|
||||
/* use long file name feature */
|
||||
/* use long file name feature */
|
||||
/* #define RT_DFS_ELM_USE_LFN */
|
||||
/* the max number of file length */
|
||||
#define RT_DFS_ELM_MAX_LFN 32
|
||||
/* the max number of file length */
|
||||
#define RT_DFS_ELM_MAX_LFN 32
|
||||
/* #define RT_USING_DFS_UFFS */
|
||||
/* #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 8
|
||||
#define DFS_FILESYSTEMS_MAX 2
|
||||
/* the max number of opened files */
|
||||
#define DFS_FD_MAX 8
|
||||
/* using working directory */
|
||||
#define DFS_USING_WORKDIR
|
||||
|
||||
|
|
|
@ -20,15 +20,17 @@
|
|||
/**
|
||||
* @addtogroup FM3 MB9B500
|
||||
*/
|
||||
|
||||
/*@{*/
|
||||
|
||||
/* RT-Thread Device Interface */
|
||||
|
||||
/**
|
||||
* This function initializes serial
|
||||
*/
|
||||
static rt_err_t rt_serial_init (rt_device_t dev)
|
||||
static rt_err_t rt_serial_init(rt_device_t dev)
|
||||
{
|
||||
struct serial_device* uart = (struct serial_device*) dev->user_data;
|
||||
struct serial_device *uart = (struct serial_device*)dev->user_data;
|
||||
|
||||
if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
|
||||
{
|
||||
|
@ -53,7 +55,7 @@ static rt_err_t rt_serial_init (rt_device_t dev)
|
|||
}
|
||||
|
||||
/* save a char to serial buffer */
|
||||
static void rt_serial_savechar(struct serial_device* uart, char ch)
|
||||
static void rt_serial_savechar(struct serial_device *uart, char ch)
|
||||
{
|
||||
rt_base_t level;
|
||||
|
||||
|
@ -79,10 +81,10 @@ static void rt_serial_savechar(struct serial_device* uart, char ch)
|
|||
|
||||
static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag)
|
||||
{
|
||||
struct serial_device* uart;
|
||||
struct serial_device *uart;
|
||||
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
uart = (struct serial_device*) dev->user_data;
|
||||
uart = (struct serial_device*)dev->user_data;
|
||||
|
||||
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
|
||||
{
|
||||
|
@ -95,10 +97,10 @@ static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag)
|
|||
|
||||
static rt_err_t rt_serial_close(rt_device_t dev)
|
||||
{
|
||||
struct serial_device* uart;
|
||||
struct serial_device *uart;
|
||||
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
uart = (struct serial_device*) dev->user_data;
|
||||
uart = (struct serial_device*)dev->user_data;
|
||||
|
||||
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
|
||||
{
|
||||
|
@ -109,12 +111,12 @@ static rt_err_t rt_serial_close(rt_device_t dev)
|
|||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_size_t rt_serial_read (rt_device_t dev, rt_off_t pos, void* buffer,
|
||||
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;
|
||||
rt_uint8_t *ptr;
|
||||
rt_err_t err_code;
|
||||
struct serial_device* uart;
|
||||
struct serial_device *uart;
|
||||
|
||||
ptr = buffer;
|
||||
err_code = RT_EOK;
|
||||
|
@ -165,15 +167,16 @@ static rt_size_t rt_serial_read (rt_device_t dev, rt_off_t pos, void* buffer,
|
|||
|
||||
/* set error code */
|
||||
rt_set_errno(err_code);
|
||||
|
||||
return (rt_uint32_t)ptr - (rt_uint32_t)buffer;
|
||||
}
|
||||
|
||||
static rt_size_t rt_serial_write (rt_device_t dev, rt_off_t pos,
|
||||
const void* buffer, rt_size_t size)
|
||||
static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos,
|
||||
const void *buffer, rt_size_t size)
|
||||
{
|
||||
rt_uint8_t* ptr;
|
||||
rt_uint8_t *ptr;
|
||||
rt_err_t err_code;
|
||||
struct serial_device* uart;
|
||||
struct serial_device *uart;
|
||||
|
||||
err_code = RT_EOK;
|
||||
ptr = (rt_uint8_t*)buffer;
|
||||
|
@ -219,7 +222,8 @@ static rt_size_t rt_serial_write (rt_device_t dev, rt_off_t pos,
|
|||
while (!(uart->uart_device->SSR & SSR_TDRE));
|
||||
uart->uart_device->TDR = (*ptr & 0x1FF);
|
||||
|
||||
++ptr; --size;
|
||||
++ptr;
|
||||
--size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,7 +233,7 @@ static rt_size_t rt_serial_write (rt_device_t dev, rt_off_t pos,
|
|||
return (rt_uint32_t)ptr - (rt_uint32_t)buffer;
|
||||
}
|
||||
|
||||
static rt_err_t rt_serial_control (rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t rt_serial_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
{
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
|
@ -252,7 +256,7 @@ static rt_err_t rt_serial_control (rt_device_t dev, rt_uint8_t cmd, void *args)
|
|||
/*
|
||||
* serial register
|
||||
*/
|
||||
rt_err_t rt_hw_serial_register(rt_device_t device, const char* name,
|
||||
rt_err_t rt_hw_serial_register(rt_device_t device, const char *name,
|
||||
rt_uint32_t flag, struct serial_device *serial)
|
||||
{
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
|
@ -275,7 +279,7 @@ rt_err_t rt_hw_serial_register(rt_device_t device, const char* name,
|
|||
/* ISR for serial interrupt */
|
||||
void rt_hw_serial_isr(rt_device_t device)
|
||||
{
|
||||
struct serial_device* uart = (struct serial_device*) device->user_data;
|
||||
struct serial_device *uart = (struct serial_device*)device->user_data;
|
||||
|
||||
/* interrupt mode receive */
|
||||
RT_ASSERT(device->flag & RT_DEVICE_FLAG_INT_RX);
|
||||
|
@ -300,6 +304,30 @@ void rt_hw_serial_isr(rt_device_t device)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef RT_USING_UART0
|
||||
/* UART0 device driver structure */
|
||||
#define UART0 FM3_MFS0_UART
|
||||
struct serial_int_rx uart0_int_rx;
|
||||
struct serial_device uart0 =
|
||||
{
|
||||
UART0,
|
||||
MFS0RX_IRQn,
|
||||
MFS0TX_IRQn,
|
||||
&uart0_int_rx,
|
||||
RT_NULL
|
||||
};
|
||||
struct rt_device uart0_device;
|
||||
|
||||
void MFS0RX_IRQHandler(void)
|
||||
{
|
||||
/* enter interrupt */
|
||||
rt_interrupt_enter();
|
||||
rt_hw_serial_isr(&uart0_device);
|
||||
/* leave interrupt */
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_UART2
|
||||
/* UART2 device driver structure */
|
||||
#define UART2 FM3_MFS2_UART
|
||||
|
@ -326,6 +354,24 @@ void MFS2RX_IRQHandler(void)
|
|||
|
||||
void rt_hw_serial_init(void)
|
||||
{
|
||||
#ifdef RT_USING_UART0
|
||||
/* initialize UART0 */
|
||||
/* Set Uart Ch0 Port, SIN0_0, SOT0_0 */
|
||||
FM3_GPIO->PFR2 = FM3_GPIO->PFR2 | 0x0006;
|
||||
FM3_GPIO->EPFR07 = FM3_GPIO->EPFR07 | 0x00000040;
|
||||
|
||||
uart0.uart_device->SMR = SMR_MD_UART | SMR_SOE;;
|
||||
uart0.uart_device->BGR = (40000000UL + (BPS/2))/BPS - 1;
|
||||
uart0.uart_device->ESCR = ESCR_DATABITS_8;
|
||||
uart0.uart_device->SCR = SCR_RXE | SCR_TXE | SCR_RIE;
|
||||
|
||||
/* register UART2 device */
|
||||
rt_hw_serial_register(&uart0_device,
|
||||
"uart0",
|
||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
|
||||
&uart0);
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_UART2
|
||||
/* initialize UART2 */
|
||||
/* Set Uart Ch2 Port, SIN2_1, SOT2_1 */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* File : startup.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2009 - 2011, RT-Thread Development Team
|
||||
* COPYRIGHT (C) 2009 - 2012, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
|
@ -88,7 +88,7 @@ void rtthread_startup(void)
|
|||
/* init finsh */
|
||||
finsh_system_init();
|
||||
#ifdef RT_USING_DEVICE
|
||||
finsh_set_device("uart2");
|
||||
finsh_set_device(FINSH_DEVICE_NAME);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue