mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-22 03:09:16 +08:00
update Fujitsu MB9BF506R project
add nandflash device driver support RT-Thread DFS git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1515 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2011-02-24 Bernard the first version
|
* 2011-05-24 Bernard the first version
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,18 +21,49 @@
|
|||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
|
||||||
|
#ifdef RT_USING_DFS
|
||||||
|
/* dfs init */
|
||||||
|
#include <dfs_init.h>
|
||||||
|
/* dfs filesystem:ELM filesystem init */
|
||||||
|
#include <dfs_elm.h>
|
||||||
|
/* dfs Filesystem APIs */
|
||||||
|
#include <dfs_fs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void rt_init_thread_entry(void *parameter)
|
void rt_init_thread_entry(void *parameter)
|
||||||
{
|
{
|
||||||
|
/* Filesystem Initialization */
|
||||||
|
#ifdef RT_USING_DFS
|
||||||
|
{
|
||||||
|
/* init the device filesystem */
|
||||||
|
dfs_init();
|
||||||
|
|
||||||
|
#ifdef RT_USING_DFS_ELMFAT
|
||||||
|
/* init the elm chan FatFs filesystam*/
|
||||||
|
elm_init();
|
||||||
|
|
||||||
|
/* mount ELM FatFs on NAND flash as root directory */
|
||||||
|
if (dfs_mount("nand", "/", "elm", 0, 0) == 0)
|
||||||
|
{
|
||||||
|
rt_kprintf("File System initialized!\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
rt_kprintf("File System initialzation failed!\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* LED Initialization */
|
||||||
rt_hw_led_init();
|
rt_hw_led_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_application_init()
|
int rt_application_init()
|
||||||
{
|
{
|
||||||
rt_thread_t init_thread;
|
rt_thread_t tid;
|
||||||
|
|
||||||
init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 1024, 21, 20);
|
tid = rt_thread_create("init",
|
||||||
if(init_thread != RT_NULL)
|
rt_init_thread_entry, RT_NULL,
|
||||||
rt_thread_startup(init_thread);
|
2048, 8, 20);
|
||||||
|
if (tid != RT_NULL) rt_thread_startup(tid);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-57
@@ -17,30 +17,12 @@
|
|||||||
|
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "mb9bf506r.h"
|
#include "mb9bf506r.h"
|
||||||
#include "core_cm3.h"
|
|
||||||
|
#include "serial.h"
|
||||||
|
#include "nand.h"
|
||||||
|
|
||||||
extern const uint32_t SystemFrequency;
|
extern const uint32_t SystemFrequency;
|
||||||
|
|
||||||
#define UART0 FM3_MFS0_UART
|
|
||||||
struct serial_int_rx uart0_int_rx;
|
|
||||||
struct serial_device uart0 =
|
|
||||||
{
|
|
||||||
UART0,
|
|
||||||
&uart0_int_rx,
|
|
||||||
RT_NULL
|
|
||||||
};
|
|
||||||
struct rt_device uart0_device;
|
|
||||||
|
|
||||||
#define UART2 FM3_MFS2_UART
|
|
||||||
struct serial_int_rx uart2_int_rx;
|
|
||||||
struct serial_device uart2 =
|
|
||||||
{
|
|
||||||
UART2,
|
|
||||||
&uart2_int_rx,
|
|
||||||
RT_NULL
|
|
||||||
};
|
|
||||||
struct rt_device uart2_device;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup FM3
|
* @addtogroup FM3
|
||||||
*/
|
*/
|
||||||
@@ -62,48 +44,21 @@ void rt_hw_timer_handler(void)
|
|||||||
rt_interrupt_leave();
|
rt_interrupt_leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
void rt_hw_uart2_rx_handler(void)
|
|
||||||
{
|
|
||||||
#ifdef RT_USING_UART2
|
|
||||||
extern struct rt_device uart2_device;
|
|
||||||
extern void rt_hw_serial_isr(struct rt_device *device);
|
|
||||||
|
|
||||||
/* enter interrupt */
|
|
||||||
rt_interrupt_enter();
|
|
||||||
|
|
||||||
rt_hw_serial_isr(&uart2_device);
|
|
||||||
|
|
||||||
/* leave interrupt */
|
|
||||||
rt_interrupt_leave();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function will handle init uart
|
|
||||||
*/
|
|
||||||
static void rt_hw_uart_init(void)
|
|
||||||
{
|
|
||||||
/* Set Uart Ch2 Port, SIN2_1, SOT2_1 */
|
|
||||||
FM3_GPIO->PFR2 = FM3_GPIO->PFR2 | 0x0030;
|
|
||||||
FM3_GPIO->EPFR07 = FM3_GPIO->EPFR07 | 0x000a0000;
|
|
||||||
|
|
||||||
uart2.uart_device->SMR = SMR_MD_UART | SMR_SOE;;
|
|
||||||
uart2.uart_device->BGR = (40000000UL + (BPS/2))/BPS - 1;
|
|
||||||
uart2.uart_device->ESCR = ESCR_DATABITS_8;
|
|
||||||
uart2.uart_device->SCR = SCR_RXE | SCR_TXE | SCR_RIE;
|
|
||||||
|
|
||||||
UART_ENABLE_IRQ(MFS2RX_IRQn);
|
|
||||||
UART_ENABLE_IRQ(MFS2TX_IRQn);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function will initial FM3 Easy Kit board.
|
* This function will initial FM3 Easy Kit board.
|
||||||
*/
|
*/
|
||||||
void rt_hw_board_init()
|
void rt_hw_board_init()
|
||||||
{
|
{
|
||||||
/* init systick */
|
/* init systick */
|
||||||
SysTick_Config(SystemFrequency/RT_TICK_PER_SECOND - 1);
|
SysTick_Config(SystemFrequency/RT_TICK_PER_SECOND);
|
||||||
rt_hw_uart_init();
|
|
||||||
|
/* initialize UART device */
|
||||||
|
rt_hw_serial_init();
|
||||||
|
/* set console as UART device */
|
||||||
|
rt_console_set_device("uart2");
|
||||||
|
|
||||||
|
/* initialize nand flash device */
|
||||||
|
rt_hw_nand_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|||||||
+501
-317
File diff suppressed because it is too large
Load Diff
@@ -289,6 +289,8 @@
|
|||||||
<state>$PROJ_DIR$\..\CMSIS</state>
|
<state>$PROJ_DIR$\..\CMSIS</state>
|
||||||
<state>$PROJ_DIR$\..\..\..\include</state>
|
<state>$PROJ_DIR$\..\..\..\include</state>
|
||||||
<state>$PROJ_DIR$\..\..\..\components\finsh</state>
|
<state>$PROJ_DIR$\..\..\..\components\finsh</state>
|
||||||
|
<state>$PROJ_DIR$\..\..\..\components\dfs\include</state>
|
||||||
|
<state>$PROJ_DIR$\..\..\..\components\dfs\filesystems\elmfat</state>
|
||||||
</option>
|
</option>
|
||||||
<option>
|
<option>
|
||||||
<name>CCStdIncCheck</name>
|
<name>CCStdIncCheck</name>
|
||||||
@@ -1746,6 +1748,27 @@
|
|||||||
<name>$PROJ_DIR$\..\CMSIS\system_mb9bf50x.c</name>
|
<name>$PROJ_DIR$\..\CMSIS\system_mb9bf50x.c</name>
|
||||||
</file>
|
</file>
|
||||||
</group>
|
</group>
|
||||||
|
<group>
|
||||||
|
<name>Filesystem</name>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\..\..\..\components\dfs\src\dfs.c</name>
|
||||||
|
</file>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\..\..\..\components\dfs\filesystems\elmfat\dfs_elm.c</name>
|
||||||
|
</file>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\..\..\..\components\dfs\src\dfs_file.c</name>
|
||||||
|
</file>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\..\..\..\components\dfs\src\dfs_fs.c</name>
|
||||||
|
</file>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\..\..\..\components\dfs\src\dfs_posix.c</name>
|
||||||
|
</file>
|
||||||
|
<file>
|
||||||
|
<name>$PROJ_DIR$\..\..\..\components\dfs\filesystems\elmfat\ff.c</name>
|
||||||
|
</file>
|
||||||
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<name>Finsh</name>
|
<name>Finsh</name>
|
||||||
<file>
|
<file>
|
||||||
@@ -1860,10 +1883,10 @@
|
|||||||
<name>$PROJ_DIR$\board.c</name>
|
<name>$PROJ_DIR$\board.c</name>
|
||||||
</file>
|
</file>
|
||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\console.c</name>
|
<name>$PROJ_DIR$\led.c</name>
|
||||||
</file>
|
</file>
|
||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\led.c</name>
|
<name>$PROJ_DIR$\nand.c</name>
|
||||||
</file>
|
</file>
|
||||||
<file>
|
<file>
|
||||||
<name>$PROJ_DIR$\serial.c</name>
|
<name>$PROJ_DIR$\serial.c</name>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* File : nand.h
|
||||||
|
* 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://www.rt-thread.org/license/LICENSE
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2011-05-25 Bernard first version
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __NAND_H__
|
||||||
|
#define __NAND_H__
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
#define IO_NF_PFR FM3_GPIO->PFR3
|
||||||
|
#define IO_NF_DDR FM3_GPIO->DDR3
|
||||||
|
#define IO_NF_PDOR FM3_GPIO->PDOR3
|
||||||
|
|
||||||
|
#define NF_EN 0x0008
|
||||||
|
#define NF_DATA_DIR 0x0004
|
||||||
|
|
||||||
|
#define EXT_BUS_BASE_ADDR 0x60000000
|
||||||
|
#define EXT_CS7_OFFSET 0x0E000000
|
||||||
|
#define EXT_CS7_SIZE 0x02000000
|
||||||
|
|
||||||
|
#define NF_FLASH_BASE_ADDR (EXT_BUS_BASE_ADDR+EXT_CS7_OFFSET)
|
||||||
|
|
||||||
|
#define NF_ALE_OFFSET 0x00003000
|
||||||
|
#define NF_ADDR_OFFSET 0x00002000
|
||||||
|
#define NF_CMD_OFFSET 0x00001000
|
||||||
|
#define NF_DATA_OFFSET 0x00000000
|
||||||
|
|
||||||
|
/* NAND command */
|
||||||
|
#define NAND_CMD_READ0 0x00
|
||||||
|
#define NAND_CMD_READ1 0x01
|
||||||
|
#define NAND_CMD_PAGEPROG 0x10
|
||||||
|
#define NAND_CMD_READOOB 0x50
|
||||||
|
#define NAND_CMD_ERASE1 0x60
|
||||||
|
#define NAND_CMD_STATUS 0x70
|
||||||
|
#define NAND_CMD_SEQIN 0x80
|
||||||
|
#define NAND_CMD_READID 0x90
|
||||||
|
#define NAND_CMD_READID1 0x91
|
||||||
|
#define NAND_CMD_ERASE2 0xd0
|
||||||
|
#define NAND_CMD_RESET 0xff
|
||||||
|
|
||||||
|
#define FLASH_OK 0
|
||||||
|
#define FLASH_NG 1
|
||||||
|
|
||||||
|
/* nand flash device initialization */
|
||||||
|
void rt_hw_nand_init(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#define __RTTHREAD_CFG_H__
|
#define __RTTHREAD_CFG_H__
|
||||||
|
|
||||||
/* RT_NAME_MAX*/
|
/* RT_NAME_MAX*/
|
||||||
#define RT_NAME_MAX 8
|
#define RT_NAME_MAX 4
|
||||||
|
|
||||||
/* RT_ALIGN_SIZE*/
|
/* RT_ALIGN_SIZE*/
|
||||||
#define RT_ALIGN_SIZE 4
|
#define RT_ALIGN_SIZE 4
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
#define RT_UART_RX_BUFFER_SIZE 64
|
#define RT_UART_RX_BUFFER_SIZE 64
|
||||||
|
|
||||||
/* SECTION: Console options */
|
/* SECTION: Console options */
|
||||||
//#define RT_TINY_SIZE
|
/* #define RT_TINY_SIZE */
|
||||||
#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
|
||||||
@@ -67,54 +67,24 @@
|
|||||||
/* Using symbol table */
|
/* Using symbol table */
|
||||||
#define FINSH_USING_SYMTAB
|
#define FINSH_USING_SYMTAB
|
||||||
#define FINSH_USING_DESCRIPTION
|
#define FINSH_USING_DESCRIPTION
|
||||||
#define FINSH_THREAD_STACK_SIZE 4096
|
#define FINSH_THREAD_STACK_SIZE 1024
|
||||||
|
|
||||||
/* SECTION: Device filesystem support */
|
/* SECTION: Device filesystem support */
|
||||||
/* using DFS support */
|
/* using DFS support */
|
||||||
/* #define RT_USING_DFS */
|
#define RT_USING_DFS
|
||||||
/* #define RT_USING_DFS_ELMFAT */
|
#define RT_USING_DFS_ELMFAT
|
||||||
/* use long file name feature */
|
/* use long file name feature */
|
||||||
#define RT_DFS_ELM_USE_LFN 1
|
/* #define RT_DFS_ELM_USE_LFN */
|
||||||
/* the max number of file length */
|
/* the max number of file length */
|
||||||
#define RT_DFS_ELM_MAX_LFN 32
|
#define RT_DFS_ELM_MAX_LFN 32
|
||||||
/* #define RT_USING_DFS_YAFFS2 */
|
|
||||||
/* #define RT_USING_DFS_UFFS */
|
/* #define RT_USING_DFS_UFFS */
|
||||||
/* #define RT_USING_DFS_DEVFS */
|
/* #define RT_USING_DFS_DEVFS */
|
||||||
|
|
||||||
//#define RT_USING_DFS_NFS
|
/* the max number of mounted filesystem */
|
||||||
//#define RT_NFS_HOST_EXPORT "192.168.1.5:/"
|
#define DFS_FILESYSTEMS_MAX 2
|
||||||
|
/* the max number of opened files */
|
||||||
|
#define DFS_FD_MAX 8
|
||||||
|
/* using working directory */
|
||||||
#define DFS_USING_WORKDIR
|
#define DFS_USING_WORKDIR
|
||||||
|
|
||||||
/* the max number of mounted filesystem */
|
|
||||||
#define DFS_FILESYSTEMS_MAX 4
|
|
||||||
/* the max number of opened files */
|
|
||||||
#define DFS_FD_MAX 16
|
|
||||||
/* the max number of cached sector */
|
|
||||||
#define DFS_CACHE_MAX_NUM 4
|
|
||||||
|
|
||||||
/* SECTION: RTGUI support */
|
|
||||||
/* using RTGUI support */
|
|
||||||
//#define RT_USING_RTGUI
|
|
||||||
|
|
||||||
/* name length of RTGUI object */
|
|
||||||
#define RTGUI_NAME_MAX 16
|
|
||||||
/* support 16 weight font */
|
|
||||||
//#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 font file as Chinese font */
|
|
||||||
/* #define RTGUI_USING_HZ_FILE */
|
|
||||||
/* use Chinese bitmap font */
|
|
||||||
//#define RTGUI_USING_HZ_BMP
|
|
||||||
/* use small size in RTGUI */
|
|
||||||
//#define RTGUI_USING_SMALL_SIZE
|
|
||||||
/* use mouse cursor */
|
|
||||||
/* #define RTGUI_USING_MOUSE_CURSOR */
|
|
||||||
#define RTGUI_DEFAULT_FONT_SIZE 12
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+75
-10
@@ -5,12 +5,12 @@
|
|||||||
*
|
*
|
||||||
* 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
|
||||||
* http://openlab.rt-thread.com/license/LICENSE
|
* http://www.rt-thread.org/license/LICENSE
|
||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2006-03-13 Bernard first version
|
* 2006-03-13 Bernard first version
|
||||||
* 2009-04-20 yi.qiu modified according bernard's stm32 version
|
* 2011-05-15 lgnq modified according bernard's implementaion.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
@@ -32,7 +32,6 @@ static rt_err_t rt_serial_init (rt_device_t dev)
|
|||||||
|
|
||||||
if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
|
if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
|
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
|
||||||
{
|
{
|
||||||
rt_memset(uart->int_rx->rx_buffer, 0,
|
rt_memset(uart->int_rx->rx_buffer, 0,
|
||||||
@@ -79,20 +78,39 @@ 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)
|
static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag)
|
||||||
{
|
{
|
||||||
RT_ASSERT(dev != RT_NULL);
|
struct serial_device* uart;
|
||||||
|
|
||||||
|
RT_ASSERT(dev != RT_NULL);
|
||||||
|
uart = (struct serial_device*) dev->user_data;
|
||||||
|
|
||||||
|
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
|
||||||
|
{
|
||||||
|
/* enable interrupt */
|
||||||
|
UART_ENABLE_IRQ(uart->rx_irq);
|
||||||
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t rt_serial_close(rt_device_t dev)
|
static rt_err_t rt_serial_close(rt_device_t dev)
|
||||||
{
|
{
|
||||||
|
struct serial_device* uart;
|
||||||
|
|
||||||
RT_ASSERT(dev != RT_NULL);
|
RT_ASSERT(dev != RT_NULL);
|
||||||
|
uart = (struct serial_device*) dev->user_data;
|
||||||
|
|
||||||
|
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
|
||||||
|
{
|
||||||
|
/* disable interrupt */
|
||||||
|
UART_DISABLE_IRQ(uart->rx_irq);
|
||||||
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_size_t rt_serial_read (rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
|
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;
|
rt_err_t err_code;
|
||||||
@@ -150,7 +168,8 @@ static rt_size_t rt_serial_read (rt_device_t dev, rt_off_t pos, void* buffer, rt
|
|||||||
return (rt_uint32_t)ptr - (rt_uint32_t)buffer;
|
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;
|
rt_err_t err_code;
|
||||||
@@ -233,7 +252,8 @@ static rt_err_t rt_serial_control (rt_device_t dev, rt_uint8_t cmd, void *args)
|
|||||||
/*
|
/*
|
||||||
* serial register
|
* serial register
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct serial_device *serial)
|
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);
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
@@ -246,12 +266,12 @@ rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t
|
|||||||
device->read = rt_serial_read;
|
device->read = rt_serial_read;
|
||||||
device->write = rt_serial_write;
|
device->write = rt_serial_write;
|
||||||
device->control = rt_serial_control;
|
device->control = rt_serial_control;
|
||||||
device->user_data = serial;
|
device->user_data = serial;
|
||||||
|
|
||||||
/* register a character device */
|
/* register a character device */
|
||||||
return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | flag);
|
return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ISR for serial interrupt */
|
/* ISR for serial interrupt */
|
||||||
void rt_hw_serial_isr(rt_device_t device)
|
void rt_hw_serial_isr(rt_device_t device)
|
||||||
{
|
{
|
||||||
@@ -280,4 +300,49 @@ void rt_hw_serial_isr(rt_device_t device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RT_USING_UART2
|
||||||
|
/* UART2 device driver structure */
|
||||||
|
#define UART2 FM3_MFS2_UART
|
||||||
|
struct serial_int_rx uart2_int_rx;
|
||||||
|
struct serial_device uart2 =
|
||||||
|
{
|
||||||
|
UART2,
|
||||||
|
MFS2RX_IRQn,
|
||||||
|
MFS2TX_IRQn,
|
||||||
|
&uart2_int_rx,
|
||||||
|
RT_NULL
|
||||||
|
};
|
||||||
|
struct rt_device uart2_device;
|
||||||
|
|
||||||
|
void MFS2RX_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* enter interrupt */
|
||||||
|
rt_interrupt_enter();
|
||||||
|
rt_hw_serial_isr(&uart2_device);
|
||||||
|
/* leave interrupt */
|
||||||
|
rt_interrupt_leave();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void rt_hw_serial_init(void)
|
||||||
|
{
|
||||||
|
#ifdef RT_USING_UART2
|
||||||
|
/* initialize UART2 */
|
||||||
|
/* Set Uart Ch2 Port, SIN2_1, SOT2_1 */
|
||||||
|
FM3_GPIO->PFR2 = FM3_GPIO->PFR2 | 0x0030;
|
||||||
|
FM3_GPIO->EPFR07 = FM3_GPIO->EPFR07 | 0x000a0000;
|
||||||
|
|
||||||
|
uart2.uart_device->SMR = SMR_MD_UART | SMR_SOE;;
|
||||||
|
uart2.uart_device->BGR = (40000000UL + (BPS/2))/BPS - 1;
|
||||||
|
uart2.uart_device->ESCR = ESCR_DATABITS_8;
|
||||||
|
uart2.uart_device->SCR = SCR_RXE | SCR_TXE | SCR_RIE;
|
||||||
|
|
||||||
|
/* register UART2 device */
|
||||||
|
rt_hw_serial_register(&uart2_device,
|
||||||
|
"uart2",
|
||||||
|
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
|
||||||
|
&uart2);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|||||||
@@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* File : serial.h
|
||||||
|
* 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://www.rt-thread.org/license/LICENSE
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2006-03-13 Bernard first version
|
||||||
|
* 2011-05-15 lgnq modified according bernard's implementaion.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef __RT_HW_SERIAL_H__
|
#ifndef __RT_HW_SERIAL_H__
|
||||||
#define __RT_HW_SERIAL_H__
|
#define __RT_HW_SERIAL_H__
|
||||||
|
|
||||||
@@ -69,16 +84,16 @@ struct serial_int_tx
|
|||||||
struct serial_device
|
struct serial_device
|
||||||
{
|
{
|
||||||
FM3_MFS03_UART_TypeDef* uart_device;
|
FM3_MFS03_UART_TypeDef* uart_device;
|
||||||
|
/* irq number */
|
||||||
|
IRQn_Type rx_irq, tx_irq;
|
||||||
|
|
||||||
/* rx structure */
|
/* rx structure */
|
||||||
struct serial_int_rx* int_rx;
|
struct serial_int_rx* int_rx;
|
||||||
|
|
||||||
/* tx structure */
|
/* tx structure */
|
||||||
struct serial_int_tx* int_tx;
|
struct serial_int_tx* int_tx;
|
||||||
};
|
};
|
||||||
|
|
||||||
rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct serial_device *serial);
|
|
||||||
|
|
||||||
void rt_hw_serial_isr(rt_device_t device);
|
void rt_hw_serial_isr(rt_device_t device);
|
||||||
|
void rt_hw_serial_init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -58,10 +58,6 @@ void rtthread_startup(void)
|
|||||||
|
|
||||||
/* init tick */
|
/* init tick */
|
||||||
rt_system_tick_init();
|
rt_system_tick_init();
|
||||||
|
|
||||||
/* init kernel object */
|
|
||||||
rt_system_object_init();
|
|
||||||
|
|
||||||
/* init timer system */
|
/* init timer system */
|
||||||
rt_system_timer_init();
|
rt_system_timer_init();
|
||||||
|
|
||||||
@@ -79,27 +75,12 @@ void rtthread_startup(void)
|
|||||||
/* init scheduler system */
|
/* init scheduler system */
|
||||||
rt_system_scheduler_init();
|
rt_system_scheduler_init();
|
||||||
|
|
||||||
#ifdef RT_USING_DEVICE
|
|
||||||
/* register uart0 */
|
|
||||||
rt_hw_serial_register(&uart0_device, "uart0",
|
|
||||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
|
|
||||||
&uart0);
|
|
||||||
|
|
||||||
/* register uart2, used for RTI debug */
|
|
||||||
rt_hw_serial_register(&uart2_device, "uart2",
|
|
||||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
|
|
||||||
&uart2);
|
|
||||||
|
|
||||||
#ifdef RT_USING_DFS
|
#ifdef RT_USING_DFS
|
||||||
#ifdef RT_USING_DFS_UFFS
|
#ifdef RT_USING_DFS_UFFS
|
||||||
rt_hw_nand_init();
|
rt_hw_nand_init();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*init all registed devices */
|
|
||||||
rt_device_init_all();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* init application */
|
/* init application */
|
||||||
rt_application_init();
|
rt_application_init();
|
||||||
|
|
||||||
@@ -110,7 +91,7 @@ void rtthread_startup(void)
|
|||||||
finsh_set_device("uart2");
|
finsh_set_device("uart2");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* init timer thread */
|
/* init timer thread */
|
||||||
rt_system_timer_thread_init();
|
rt_system_timer_thread_init();
|
||||||
|
|
||||||
@@ -126,10 +107,8 @@ void rtthread_startup(void)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
rt_uint32_t UNUSED level;
|
|
||||||
|
|
||||||
/* disable interrupt first */
|
/* disable interrupt first */
|
||||||
level = rt_hw_interrupt_disable();
|
rt_hw_interrupt_disable();
|
||||||
|
|
||||||
/* init system setting */
|
/* init system setting */
|
||||||
SystemInit();
|
SystemInit();
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
IMPORT rt_hw_pend_sv
|
IMPORT rt_hw_pend_sv
|
||||||
IMPORT rt_hw_timer_handler
|
IMPORT rt_hw_timer_handler
|
||||||
#ifdef RT_USING_UART2
|
#ifdef RT_USING_UART2
|
||||||
IMPORT rt_hw_uart2_rx_handler
|
IMPORT MFS2RX_IRQHandler
|
||||||
#endif
|
#endif
|
||||||
PUBLIC __low_level_init
|
PUBLIC __low_level_init
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ __vector_table
|
|||||||
DCD EXTI3_IRQHandler ; EXTI Line 3
|
DCD EXTI3_IRQHandler ; EXTI Line 3
|
||||||
DCD EXTI4_IRQHandler ; EXTI Line 4
|
DCD EXTI4_IRQHandler ; EXTI Line 4
|
||||||
#ifdef RT_USING_UART2
|
#ifdef RT_USING_UART2
|
||||||
DCD rt_hw_uart2_rx_handler
|
DCD MFS2RX_IRQHandler
|
||||||
#else
|
#else
|
||||||
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
|
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user