mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-22 21:09:22 +08:00
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
|
* File : board.c
|
||||||
* This file is part of RT-Thread RTOS
|
* 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
|
* The license and distribution terms for this file may be
|
||||||
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
||||||
@ -31,7 +31,6 @@ extern const uint32_t SystemFrequency;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the timer interrupt service routine.
|
* This is the timer interrupt service routine.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
void SysTick_Handler(void)
|
void SysTick_Handler(void)
|
||||||
{
|
{
|
||||||
@ -55,7 +54,7 @@ void rt_hw_board_init(void)
|
|||||||
/* initialize UART device */
|
/* initialize UART device */
|
||||||
rt_hw_serial_init();
|
rt_hw_serial_init();
|
||||||
/* set console as UART device */
|
/* set console as UART device */
|
||||||
rt_console_set_device("uart2");
|
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||||
|
|
||||||
/* initialize nand flash device */
|
/* initialize nand flash device */
|
||||||
rt_hw_nand_init();
|
rt_hw_nand_init();
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#define RT_CONSOLE_FOREPIXEL (0x001f)
|
#define RT_CONSOLE_FOREPIXEL (0x001f)
|
||||||
|
|
||||||
extern struct serial_device uart2;
|
extern struct serial_device uart0;
|
||||||
|
|
||||||
struct rt_console
|
struct rt_console
|
||||||
{
|
{
|
||||||
@ -78,6 +78,7 @@ void rt_hw_console_putc(char c)
|
|||||||
console.current_col = 0;
|
console.current_col = 0;
|
||||||
|
|
||||||
rt_hw_console_putc(c);
|
rt_hw_console_putc(c);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +121,7 @@ void rt_hw_console_putc(char c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rt_hw_console_newline()
|
void rt_hw_console_newline(void)
|
||||||
{
|
{
|
||||||
console.current_row ++;
|
console.current_row ++;
|
||||||
if (console.current_row >= RT_CONSOLE_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_col = 0;
|
||||||
console.current_row = 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 be polite with serial console add a line feed
|
||||||
to the carriage return character
|
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));
|
while (!(uart0.uart_device->SSR & SSR_TDRE))
|
||||||
uart2.uart_device->TDR = (c & 0x1FF);
|
;
|
||||||
|
uart0.uart_device->TDR = (c & 0x1FF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
CODE (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000
|
CODE (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000
|
||||||
DATA (rw) : ORIGIN = 0x1FFFC000, LENGTH = 0x00010000
|
DATA (rw) : ORIGIN = 0x1FFF8000, LENGTH = 0x00010000
|
||||||
}
|
}
|
||||||
ENTRY(Reset_Handler)
|
ENTRY(Reset_Handler)
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
/* Using Device System */
|
/* Using Device System */
|
||||||
#define RT_USING_DEVICE
|
#define RT_USING_DEVICE
|
||||||
/* RT_USING_UART */
|
/* RT_USING_UART */
|
||||||
#define RT_USING_UART2
|
#define RT_USING_UART0
|
||||||
#define RT_UART_RX_BUFFER_SIZE 64
|
#define RT_UART_RX_BUFFER_SIZE 64
|
||||||
|
|
||||||
/* SECTION: Console options */
|
/* SECTION: Console options */
|
||||||
@ -60,6 +60,8 @@
|
|||||||
#define RT_USING_CONSOLE
|
#define RT_USING_CONSOLE
|
||||||
/* the buffer size of 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 */
|
/* SECTION: finsh, a C-Express shell */
|
||||||
/* Using FinSH as Shell*/
|
/* Using FinSH as Shell*/
|
||||||
@ -68,6 +70,7 @@
|
|||||||
#define FINSH_USING_SYMTAB
|
#define FINSH_USING_SYMTAB
|
||||||
#define FINSH_USING_DESCRIPTION
|
#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 */
|
/* SECTION: Device filesystem support */
|
||||||
/* using DFS support */
|
/* using DFS support */
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
/**
|
/**
|
||||||
* @addtogroup FM3 MB9B500
|
* @addtogroup FM3 MB9B500
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*@{*/
|
/*@{*/
|
||||||
|
|
||||||
/* RT-Thread Device Interface */
|
/* RT-Thread Device Interface */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function initializes serial
|
* This function initializes serial
|
||||||
*/
|
*/
|
||||||
@ -165,6 +167,7 @@ static rt_size_t rt_serial_read (rt_device_t dev, rt_off_t pos, void* buffer,
|
|||||||
|
|
||||||
/* set error code */
|
/* set error code */
|
||||||
rt_set_errno(err_code);
|
rt_set_errno(err_code);
|
||||||
|
|
||||||
return (rt_uint32_t)ptr - (rt_uint32_t)buffer;
|
return (rt_uint32_t)ptr - (rt_uint32_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));
|
while (!(uart->uart_device->SSR & SSR_TDRE));
|
||||||
uart->uart_device->TDR = (*ptr & 0x1FF);
|
uart->uart_device->TDR = (*ptr & 0x1FF);
|
||||||
|
|
||||||
++ptr; --size;
|
++ptr;
|
||||||
|
--size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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
|
#ifdef RT_USING_UART2
|
||||||
/* UART2 device driver structure */
|
/* UART2 device driver structure */
|
||||||
#define UART2 FM3_MFS2_UART
|
#define UART2 FM3_MFS2_UART
|
||||||
@ -326,6 +354,24 @@ void MFS2RX_IRQHandler(void)
|
|||||||
|
|
||||||
void rt_hw_serial_init(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
|
#ifdef RT_USING_UART2
|
||||||
/* initialize UART2 */
|
/* initialize UART2 */
|
||||||
/* Set Uart Ch2 Port, SIN2_1, SOT2_1 */
|
/* Set Uart Ch2 Port, SIN2_1, SOT2_1 */
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* File : startup.c
|
* File : startup.c
|
||||||
* This file is part of RT-Thread RTOS
|
* 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
|
* The license and distribution terms for this file may be
|
||||||
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
||||||
@ -88,7 +88,7 @@ void rtthread_startup(void)
|
|||||||
/* init finsh */
|
/* init finsh */
|
||||||
finsh_system_init();
|
finsh_system_init();
|
||||||
#ifdef RT_USING_DEVICE
|
#ifdef RT_USING_DEVICE
|
||||||
finsh_set_device("uart2");
|
finsh_set_device(FINSH_DEVICE_NAME);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user