add simulator bsp for win32, which can be compiled by visual studio (2005 or newer version)

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2357 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
goprife@gmail.com 2012-10-21 04:33:52 +00:00
parent d9b0bec989
commit c3b741d010
20 changed files with 2552 additions and 0 deletions

33
bsp/simulator/SConscript Normal file
View File

@ -0,0 +1,33 @@
import rtconfig
Import('RTT_ROOT')
from building import *
src_bsp = ['application.c', 'startup.c', 'board.c', 'platform.c']
src_drv = ['serial.c', 'usart_sim.c']
if GetDepend('RT_USING_DFS'):
src_drv += ['sd_sim.c']
if GetDepend('RT_USING_MTD_NAND'):
src_drv += ['nand_sim.c']
if GetDepend('RT_USING_MTD_NOR'):
src_drv += ['sst25vfxx_mtd_sim.c']
if GetDepend('RT_USING_RTGUI'):
src_drv += ['touch.c', 'calibration.c']
if GetDepend('RT_USING_RTGUI'):
if rtconfig.RT_USING_LCD_TYPE == 'FMT0371':
src_drv += ['lcd_a70.c']
elif rtconfig.RT_USING_LCD_TYPE == 'ILI932X':
src_drv += ['ili_lcd_general.c']
elif rtconfig.RT_USING_LCD_TYPE == 'SSD1289':
src_drv += ['ssd1289.c']
src = src_bsp + src_drv
CPPPATH = [ GetCurrentDir() ]
CPPDEFINES = []
group = DefineGroup('Startup', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
Return('group')

55
bsp/simulator/SConstruct Normal file
View File

@ -0,0 +1,55 @@
import os
import sys
import rtconfig
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *
TARGET = 'rtthread-win32.' + rtconfig.TARGET_EXT
env = Environment()
Export('RTT_ROOT')
Export('rtconfig')
# prepare building environment
libs = Split('''
kernel32
msvcrt
winmm
user32
gdi32
winspool
comdlg32
advapi32
shell32
ole32
oleaut32
uuid
odbc32
odbccp32
''')
env.Append(CCFLAGS=rtconfig.CFLAGS)
env.Append(LINKFLAGS=rtconfig.LFLAGS)
env['LIBS']=libs
objs = PrepareBuilding(env, RTT_ROOT)
# firemare library building script
# objs = objs + SConscript( GetCurrentDir() + '/Libraries/SConscript', variant_dir='build/bsp/Libraries', duplicate=0)
if GetDepend('RT_USING_RTGUI'):
objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0)
# build program
env.Program(TARGET, objs)
# end building
EndBuilding(TARGET)

118
bsp/simulator/application.c Normal file
View File

@ -0,0 +1,118 @@
/*
* File : application.c
* 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
* 2009-01-05 Bernard the first version
*/
#include <rtthread.h>
#include <stdio.h>
#include <board.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)
{
#ifdef RT_USING_COMPONENTS_INIT
/* initialization RT-Thread Components */
rt_components_init();
#endif
rt_platform_init();
/* Filesystem Initialization */
#ifdef RT_USING_DFS
{
#ifdef RT_USING_DFS_ELMFAT
/* mount sd card fat partition 1 as root directory */
if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
{
rt_kprintf("fatfs initialized!\n");
}
else
rt_kprintf("fatfs initialzation failed!\n");
#endif
#ifdef RT_USING_DFS_ELMFAT
/* mount sd card fat partition 1 as root directory */
if (dfs_mount("nand0", "/nand", "uffs", 0, 0) == 0)
{
rt_kprintf("uffs initialized!\n");
}
else
rt_kprintf("uffs initialzation failed!\n");
#endif
#ifdef RT_USING_DFS_JFFS2
/* mount sd card fat partition 1 as root directory */
if (dfs_mount("nor", "/nor", "jffs2", 0, 0) == 0)
{
rt_kprintf("jffs2 initialized!\n");
}
else
rt_kprintf("jffs2 initialzation failed!\n");
#endif
}
#endif
}
void rt_test_thread_entry(void* parameter)
{
int i;
for(i=0; i<10; i++)
{
rt_kprintf("hello, world\n");
rt_thread_delay(100);
}
}
#include <finsh.h>
int rt_application_init()
{
rt_thread_t thread;
#if (RT_THREAD_PRIORITY_MAX == 32)
thread = rt_thread_create("init",
rt_init_thread_entry, RT_NULL,
2048, 8, 20);
#else
thread = rt_thread_create("init",
rt_init_thread_entry, RT_NULL,
2048, 80, 20);
#endif
if (thread != RT_NULL)
rt_thread_startup(thread);
thread = rt_thread_create("test",
rt_test_thread_entry, RT_NULL,
2048, 9, 20);
if (thread != RT_NULL)
rt_thread_startup(thread);
return 0;
}
extern int rt_application_init(void);
#if 1
FINSH_FUNCTION_EXPORT(rt_application_init, app init)
void testfun()
{}
FINSH_FUNCTION_EXPORT(testfun, test fun)
#endif
/*@}*/

45
bsp/simulator/board.c Normal file
View File

@ -0,0 +1,45 @@
/*
* File : board.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2009 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
* 2009-01-05 Bernard first implementation
*/
#include <rthw.h>
#include <rtthread.h>
#include "board.h"
/**
* @addtogroup STM32
*/
/**
* This function will initial STM32 board.
*/
void rt_hw_board_init()
{
#if 0
/* NVIC Configuration */
NVIC_Configuration();
/* Configure the SysTick */
SysTick_Config( SystemCoreClock / RT_TICK_PER_SECOND );
#endif
#if defined(RT_USING_CONSOLE)
rt_hw_usart_init();
rt_hw_serial_init();
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
}
/*@}*/

32
bsp/simulator/board.h Normal file
View File

@ -0,0 +1,32 @@
/*
* File : board.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2009, 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
* 2009-09-22 Bernard add board.h to this bsp
*/
#ifndef __BOARD_H__
#define __BOARD_H__
void rt_hw_board_led_on(int n);
void rt_hw_board_led_off(int n);
void rt_hw_board_init(void);
void rt_hw_serial_init(void);
/* SD Card init function */
void rt_hw_sdcard_init(void);
int rt_hw_mtd_nand_init(void);
int sst25vfxx_mtd_init(const char * nor_name, unsigned int block_start, unsigned int block_end);
void rt_platform_init(void);
#endif

234
bsp/simulator/nand_sim.c Normal file
View File

@ -0,0 +1,234 @@
#include <rtdevice.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dfs_def.h>
// #define NAND_TRACE rt_kprintf
#define NAND_TRACE(...)
#define NAND_SIM "nand.bin"
struct nand_device
{
struct rt_mtd_nand_device parent;
FILE * file;
};
static struct nand_device _nand;
#define NAND_DEVICE(device) (( struct nand_device*)(device))
#define PAGE_DATA_SIZE 2048 /* page data size in bytes */
#define PAGE_SPARE_SIZE 64 /* oob size in bytes */
#define BLOCK_PAGES 64 /* the number of pages in a block */
#define BLOCK_SIZE ((PAGE_DATA_SIZE + PAGE_SPARE_SIZE) * BLOCK_PAGES)
#define BLOCK_COUNT 128 /* 128 blocks == 16M */
#define BLOCK_MARK_SPARE_OFFSET 4
static rt_mutex_t lock;
/* RT-Thread device interface */
static rt_err_t k9f1g08_mtd_check_block(
struct rt_mtd_nand_device* device,
rt_uint32_t block)
{
rt_uint8_t block_status;
int result;
struct nand_device * nand;
nand = NAND_DEVICE(device);
fseek(nand->file, block * device->pages_per_block *
(device->page_size + device->oob_size) +
device->page_size + BLOCK_MARK_SPARE_OFFSET,
SEEK_SET);
result = fread(&block_status, 1, 1, nand->file);
if (result < 0)
{
NAND_TRACE("nand fread error\n");
return -RT_ERROR;
}
return block_status == 0xFF ? RT_EOK : -RT_ERROR;
}
static rt_err_t k9f1g08_mtd_mark_bad_block(
struct rt_mtd_nand_device* device,
rt_uint32_t block)
{
rt_uint8_t block_status;
int result;
struct nand_device * nand;
nand = NAND_DEVICE(device);
fseek(nand->file, block * device->pages_per_block *
(device->page_size + device->oob_size) +
device->page_size + BLOCK_MARK_SPARE_OFFSET,
SEEK_SET);
block_status = 0x00;
result = fwrite(&block_status, 1, 1, nand->file);
if (result < 0)
{
NAND_TRACE("nand fwrite error\n");
return -RT_ERROR;
}
return RT_EOK;
}
static char block_buffer[BLOCK_SIZE];
static rt_err_t k9f1g08_mtd_erase_block(
struct rt_mtd_nand_device* device,
rt_uint32_t block)
{
int result;
struct nand_device * nand;
nand = NAND_DEVICE(device);
fseek(nand->file, block * device->pages_per_block *
(device->page_size + device->oob_size),
SEEK_SET);
memset(block_buffer, 0xFF, sizeof(BLOCK_SIZE));
result = fwrite(block_buffer, BLOCK_SIZE, 1, nand->file);
if (result < 0)
{
NAND_TRACE("nand fwrite error\n");
return -RT_ERROR;
}
return RT_EOK;
}
/* return 0, ecc ok, 1, can be fixed , -1 can not be fixed */
static rt_err_t k9f1g08_mtd_read(
struct rt_mtd_nand_device * device,
rt_off_t page,
rt_uint8_t * data, rt_uint32_t data_len, //may not always be 2048
rt_uint8_t * spare, rt_uint32_t spare_len)
{
int result;
int ecc_status = 0;
struct nand_device * nand;
nand = NAND_DEVICE(device);
if (data != RT_NULL && data_len != 0)
{
fseek(nand->file, page * (device->page_size + device->oob_size),
SEEK_SET);
result = fread(data, data_len, 1, nand->file);
if (result < 0)
ecc_status = -1;
}
if (spare != RT_NULL && spare_len != 0)
{
fseek(nand->file, page * (device->page_size + device->oob_size)
+device->page_size,
SEEK_SET);
result = fread(spare, spare_len, 1, nand->file);
if (result < 0)
ecc_status = -1;
}
return ecc_status;
}
static rt_err_t k9f1g08_mtd_write (
struct rt_mtd_nand_device * device,
rt_off_t page,
const rt_uint8_t * data, rt_uint32_t data_len,//will be 2048 always!
const rt_uint8_t * spare, rt_uint32_t spare_len)
{
int result;
int ecc_status = 0;
struct nand_device * nand;
nand = NAND_DEVICE(device);
if (data != RT_NULL && data_len != 0)
{
fseek(nand->file, page * (device->page_size + device->oob_size),
SEEK_SET);
result = fwrite(data, data_len, 1, nand->file);
if (result < 0)
ecc_status = -1;
}
if (spare != RT_NULL && spare_len != 0)
{
fseek(nand->file, page * (device->page_size + device->oob_size)
+device->page_size,
SEEK_SET);
result = fwrite(spare, spare_len, 1, nand->file);
if (result < 0)
ecc_status = -1;
}
return ecc_status;
}
const static struct rt_mtd_nand_driver_ops k9f1g08_mtd_ops =
{
RT_NULL,
k9f1g08_mtd_read,
k9f1g08_mtd_write,
k9f1g08_mtd_erase_block,
k9f1g08_mtd_check_block,
k9f1g08_mtd_mark_bad_block,
};
/* interface of nand and rt-thread device */
static struct rt_mtd_nand_device nand_part[2];
int rt_hw_mtd_nand_init(void)
{
int size;
rt_uint32_t id, total_block;
struct nand_device * nand;
struct rt_mtd_nand_device * nand_part;
nand = &_nand;
nand_part = &(nand->parent);
lock = rt_mutex_create("nand", RT_IPC_FLAG_FIFO);
/* open sd card file, if not exist, then create it */
nand->file = fopen(NAND_SIM, "rb+");
if (nand->file == NULL)
{
int i;
/* create a file to simulate sd card */
nand->file = fopen(NAND_SIM, "wb+");
memset(block_buffer, 0xFF, sizeof(block_buffer));
for(i=0; i<BLOCK_COUNT; i++)
{
fseek(nand->file, i * BLOCK_SIZE, SEEK_SET);
fwrite(block_buffer, BLOCK_SIZE, 1, nand->file);
}
}
fseek(nand->file, 0, SEEK_SET);
/* the first partition of nand */
nand_part->page_size = PAGE_DATA_SIZE;
nand_part->pages_per_block = BLOCK_PAGES;//don't caculate oob size
nand_part->block_start = 0;
nand_part->block_end = BLOCK_COUNT -1;
nand_part->oob_size = PAGE_SPARE_SIZE;
nand_part->ops = &k9f1g08_mtd_ops;
rt_mtd_nand_register_device("nand0", nand_part);
return RT_EOK;
}
#ifdef RT_USING_FINSH
#include <finsh.h>
#endif

36
bsp/simulator/platform.c Normal file
View File

@ -0,0 +1,36 @@
#include <rtthread.h>
#include "board.h"
void rt_platform_init(void)
{
#ifdef RT_USING_DFS
/* initilize sd card */
#ifdef RT_USING_DFS_ELMFAT
rt_hw_sdcard_init();
#endif
#ifdef RT_USING_MTD_NAND
rt_hw_mtd_nand_init();
#endif
#ifdef RT_USING_MTD_NOR
sst25vfxx_mtd_init("nor", 0, RT_UINT32_MAX);
#endif
#endif /* RT_USING_DFS */
#ifdef RT_USING_RTGUI
/* initilize touch panel */
rtgui_touch_hw_init("spi21");
/* initilize ra8875 lcd controller */
ra8875_init();
/* initilize key module */
rt_hw_key_init();
#endif /* RT_USING_RTGUI */
rt_thread_delay(50);
rt_device_init_all();
}

188
bsp/simulator/rtconfig.h Normal file
View File

@ -0,0 +1,188 @@
/* RT-Thread config file */
#ifndef __RTTHREAD_CFG_H__
#define __RTTHREAD_CFG_H__
#ifdef _MSC_VER
#undef RT_USING_NEWLIB
#undef RT_USING_MINILIBC
#define NORESOURCE //RT_VESRION in winuser.h
#define _CRT_ERRNO_DEFINED //errno macro redefinition
#endif
#define RT_USING_COMPONENTS_INIT
#define RT_USING_MTD_NAND
#define RT_USING_MTD_NOR
#define RT_USING_DFS_UFFS
#define RT_USING_DFS_JFFS2
/* RT_NAME_MAX*/
#define RT_NAME_MAX 8
/* RT_ALIGN_SIZE*/
#define RT_ALIGN_SIZE 4
/* PRIORITY_MAX */
#define RT_THREAD_PRIORITY_MAX 32
/* Tick per Second */
#define RT_TICK_PER_SECOND 1000
/* 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_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_HEAP
/* Using Small MM */
#define RT_USING_SMALL_MEM
//#define RT_TINY_SIZE
/* SECTION: Device System */
/* Using Device System */
#define RT_USING_DEVICE
#define RT_USING_SERIAL
//#define RT_USING_UART1
/* SECTION: Console options */
#define RT_USING_CONSOLE
/* the buffer size of console*/
#define RT_CONSOLEBUF_SIZE 128
#define RT_CONSOLE_DEVICE_NAME "sci0"
/* SECTION: finsh, a C-Express shell */
#define RT_USING_FINSH
/* Using symbol table */
#define FINSH_USING_SYMTAB
#define FINSH_USING_DESCRIPTION
/* SECTION: device filesystem */
#define RT_USING_DFS
#define RT_USING_DFS_ELMFAT
#define RT_DFS_ELM_WORD_ACCESS
/* Reentrancy (thread safe) of the FatFs module. */
#define RT_DFS_ELM_REENTRANT
/* Number of volumes (logical drives) to be used. */
#define RT_DFS_ELM_DRIVES 2
/* #define RT_DFS_ELM_USE_LFN 1 */
#define RT_DFS_ELM_MAX_LFN 255
/* Maximum sector size to be handled. */
#define RT_DFS_ELM_MAX_SECTOR_SIZE 512
/* the max number of mounted filesystem */
#define DFS_FILESYSTEMS_MAX 4
/* the max number of opened files */
#define DFS_FD_MAX 4
/* SECTION: lwip, a lighwight TCP/IP protocol stack */
/* #define RT_USING_LWIP */
/* LwIP uses RT-Thread Memory Management */
#define RT_LWIP_USING_RT_MEM
/* Enable ICMP protocol*/
#define RT_LWIP_ICMP
/* Enable UDP protocol*/
#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
/* Using DHCP */
/* #define RT_LWIP_DHCP */
/* 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 10
#define RT_LWIP_TCPTHREAD_STACKSIZE 1024
/* ethernet if thread options */
#define RT_LWIP_ETHTHREAD_PRIORITY 15
#define RT_LWIP_ETHTHREAD_MBOX_SIZE 10
#define RT_LWIP_ETHTHREAD_STACKSIZE 512
/* TCP sender buffer space */
#define RT_LWIP_TCP_SND_BUF 8192
/* TCP receive window. */
#define RT_LWIP_TCP_WND 8192
/* SECTION: RT-Thread/GUI */
/* #define RT_USING_RTGUI */
/* name length of RTGUI object */
#define RTGUI_NAME_MAX 12
/* support 16 weight font */
#define RTGUI_USING_FONT16
/* 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 */
/* default font size in RTGUI */
#define RTGUI_DEFAULT_FONT_SIZE 16
/* image support */
/* #define RTGUI_IMAGE_XPM */
/* #define RTGUI_IMAGE_BMP */
#endif

80
bsp/simulator/rtconfig.py Normal file
View File

@ -0,0 +1,80 @@
# toolchains options
ARCH='x86'
#CPU='posix'
CPU='win32'
CROSS_TOOL='msvc' #win32
# lcd panel options
# 'FMT0371','ILI932X', 'SSD1289'
# RT_USING_LCD_TYPE = 'SSD1289'
# cross_tool provides the cross compiler
# EXEC_PATH is the compiler execute path, for example, CodeSourcery, Keil MDK, IAR
if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = '/usr/bin/gcc'
if CROSS_TOOL == '':
PLATFORM = 'gcc'
EXEC_PATH = '/usr/bin/gcc'
if CROSS_TOOL == 'msvc':
PLATFORM = 'cl'
EXEC_PATH = ''
BUILD = 'debug'
#BUILD = ''
if PLATFORM == 'gcc':
# toolchains
PREFIX = ''
CC = PREFIX + 'gcc'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
LINK = PREFIX + 'gcc'
TARGET_EXT = 'axf'
SIZE = PREFIX + 'size'
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
DEVICE = ' -ffunction-sections -fdata-sections'
CFLAGS = DEVICE
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
#LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-linux.map,-cref,-u,Reset_Handler -T stm32_rom.ld'
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-linux.map -lpthread'
CPATH = ''
LPATH = ''
if BUILD == 'debug':
CFLAGS += ' -O0 -gdwarf-2'
AFLAGS += ' -gdwarf-2'
else:
CFLAGS += ' -O2'
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'
elif PLATFORM == 'cl':
# toolchains
PREFIX = ''
TARGET_EXT = 'exe'
AS = PREFIX + 'cl'
CC = PREFIX + 'cl'
AR = PREFIX + 'cl'
LINK = PREFIX + 'cl'
AFLAGS = ''
CFLAGS = '/MT /ZI /Od /W 3 /WL /DMSVC /D_TIME_T_DEFINED'
#LFLAGS = '/SUBSYSTEM:WINDOWS /NODEFAULTLIB /MACHINE:X86 /DEBUG'
LFLAGS = '/SUBSYSTEM:CONSOLE /NODEFAULTLIB /MACHINE:X86 '
CPATH = ''
LPATH = ''
if BUILD == 'debug':
CFLAGS += ' /DEBUG'
else:
CFLAGS += ''
POST_ACTION = ''

193
bsp/simulator/sd_sim.c Normal file
View File

@ -0,0 +1,193 @@
#include <rtthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <dfs_def.h>
// #define SD_TRACE rt_kprintf
#define SD_TRACE(...)
//#define SDCARD_SIM "F:\\Project\\tools\\SDCARD"
#define SDCARD_SIM "sd.bin"
#define SDCARD_SIZE (16*1024*1024) //16M
struct sdcard_device
{
struct rt_device parent;
FILE* file;
};
static struct sdcard_device _sdcard;
#define SDCARD_DEVICE(device) (( struct sdcard_device*)(device))
static rt_mutex_t lock;
/* RT-Thread device interface */
static rt_err_t rt_sdcard_init(rt_device_t dev)
{
return RT_EOK;
}
static rt_err_t rt_sdcard_open(rt_device_t dev, rt_uint16_t oflag)
{
return RT_EOK;
}
static rt_err_t rt_sdcard_close(rt_device_t dev)
{
return RT_EOK;
}
/* position: block page address, not bytes address
* buffer:
* size : how many blocks
*/
static rt_size_t rt_sdcard_read(rt_device_t device, rt_off_t position, void* buffer, rt_size_t size)
{
struct sdcard_device * sd;
int result = 0;
SD_TRACE("sd read: pos %d, size %d\n", position, size);
rt_mutex_take(lock, RT_WAITING_FOREVER);
sd = SDCARD_DEVICE(device);
fseek(sd->file, position * SECTOR_SIZE, SEEK_SET);
result = fread(buffer, size * SECTOR_SIZE, 1, sd->file);
if (result < 0)
goto _err;
rt_mutex_release(lock);
return size;
_err:
SD_TRACE("sd read errors!\n");
rt_mutex_release(lock);
return 0;
}
/* position: block page address, not bytes address
* buffer:
* size : how many blocks
*/
static rt_size_t rt_sdcard_write(rt_device_t device, rt_off_t position, const void* buffer, rt_size_t size)
{
struct sdcard_device * sd;
int result = 0;
SD_TRACE("sst write: pos %d, size %d\n", position, size);
rt_mutex_take(lock, RT_WAITING_FOREVER);
sd = SDCARD_DEVICE(device);
fseek(sd->file, position * SECTOR_SIZE, SEEK_SET);
result = fwrite(buffer, size * SECTOR_SIZE, 1, sd->file);
if (result < 0)
goto _err;
rt_mutex_release(lock);
return size;
_err:
SD_TRACE("sd write errors!\n");
rt_mutex_release(lock);
return 0;
}
static rt_err_t rt_sdcard_control(rt_device_t dev, rt_uint8_t cmd, void *args)
{
struct sdcard_device * sd;
unsigned int size;
RT_ASSERT(dev != RT_NULL);
sd = SDCARD_DEVICE(dev);
if (cmd == RT_DEVICE_CTRL_BLK_GETGEOME)
{
struct rt_device_blk_geometry *geometry;
geometry = (struct rt_device_blk_geometry *)args;
if (geometry == RT_NULL) return -RT_ERROR;
geometry->bytes_per_sector = SECTOR_SIZE;
geometry->block_size = SECTOR_SIZE;
fseek(sd->file, 0, SEEK_END);
size = ftell(sd->file);
geometry->sector_count = size/SECTOR_SIZE;
}
return RT_EOK;
}
rt_err_t rt_hw_sdcard_init(const char * spi_device_name)
{
int size;
rt_uint32_t id, total_block;
struct sdcard_device * sd;
struct rt_device * device;
sd = &_sdcard;
device = &(sd->parent);
lock = rt_mutex_create("lock", RT_IPC_FLAG_FIFO);
/* open sd card file, if not exist, then create it */
sd->file = fopen(SDCARD_SIM, "rb+");
if (sd->file == NULL)
{
/* create a file to simulate sd card */
sd->file = fopen(SDCARD_SIM, "wb+");
fseek(sd->file, 0, SEEK_END);
size = ftell(sd->file);
fseek(sd->file, 0, SEEK_SET );
if (size < SDCARD_SIZE)
{
int i;
unsigned char* ptr;
ptr = (unsigned char*) malloc (1024 * 1024);
if (ptr == NULL)
{
SD_TRACE("malloc error, no memory!\n");
return RT_ERROR;
}
memset(ptr, 0x0, 1024 * 1024);
fseek(sd->file, 0, SEEK_SET);
for(i=0; i<(SDCARD_SIZE / (1024*1024)); i++)
fwrite(ptr, 1024 * 1024, 1, sd->file);
free(ptr);
}
}
fseek(sd->file, 0, SEEK_SET);
device->type = RT_Device_Class_Block;
device->init = rt_sdcard_init;
device->open = rt_sdcard_open;
device->close = rt_sdcard_close;
device->read = rt_sdcard_read;
device->write = rt_sdcard_write;
device->control = rt_sdcard_control;
device->user_data = NULL;
rt_device_register(device, "sd0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
return RT_EOK;
}
#ifdef RT_USING_FINSH
#include <finsh.h>
void eraseall(void)
{
printf("had not implemented yet!\n");
}
FINSH_FUNCTION_EXPORT(eraseall, erase all block in SPI flash);
#endif

164
bsp/simulator/serial.c Normal file
View File

@ -0,0 +1,164 @@
/*
******************************************************************************
* By : parai
* email:parai@foxmail.com
*
******************************************************************************
*/
#include "rtthread.h"
//#ifdef RT_USING_SERIAL
#define _DEBUG_SERIAL 0
#include "serial.h"
#include <stdio.h>
struct rt_device serial_device;
extern struct serial_int_rx serial_rx;
/*@{*/
/* RT-Thread Device Interface */
/**
* This function initializes serial
*/
static rt_err_t rt_serial_init (rt_device_t dev)
{
if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
{
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
{
rt_memset(serial_rx.rx_buffer, 0,
sizeof(serial_rx.rx_buffer));
serial_rx.read_index = 0;
serial_rx.save_index = 0;
}
dev->flag |= RT_DEVICE_FLAG_ACTIVATED;
}
return RT_EOK;
}
static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag){
#if _DEBUG_SERIAL==1
printf("in rt_serial_open()\n");
#endif
return RT_EOK;
}
static rt_err_t rt_serial_close(rt_device_t dev)
{
#if _DEBUG_SERIAL==1
printf("in rt_serial_close()\n");
#endif
return RT_EOK;
}
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_err_t err_code;
#if 1
ptr = buffer;
err_code = RT_EOK;
if (dev->flag & RT_DEVICE_FLAG_INT_RX)
{
/* interrupt mode Rx */
while (size)
{
rt_base_t level;
/* disable interrupt */
level = rt_hw_interrupt_disable();
if (serial_rx.read_index != serial_rx.save_index)
{
/* read a character */
*ptr++ = serial_rx.rx_buffer[serial_rx.read_index];
size--;
/* move to next position */
serial_rx.read_index ++;
if (serial_rx.read_index >= SERIAL_RX_BUFFER_SIZE)
serial_rx.read_index = 0;
}
else
{
/* set error code */
err_code = -RT_EEMPTY;
/* enable interrupt */
rt_hw_interrupt_enable(level);
break;
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
}
/* set error code */
rt_set_errno(err_code);
return (rt_uint32_t)ptr - (rt_uint32_t)buffer;
#endif
}
static rt_size_t rt_serial_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
{
#if _DEBUG_SERIAL==1
printf("in rt_serial_write()\n");
#endif
printf("%s",(char*)buffer);
return size;
}
static rt_err_t rt_serial_control (rt_device_t dev, rt_uint8_t cmd, void *args)
{
RT_ASSERT(dev != RT_NULL);
switch (cmd){
case RT_DEVICE_CTRL_SUSPEND:
/* suspend device */
dev->flag |= RT_DEVICE_FLAG_SUSPENDED;
break;
case RT_DEVICE_CTRL_RESUME:
/* resume device */
dev->flag &= ~RT_DEVICE_FLAG_SUSPENDED;
break;
}
return RT_EOK;
}
/*
* serial register
*/
static rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag)
{
RT_ASSERT(device != RT_NULL);
#if _DEBUG_SERIAL==1
printf("in rt_serial_register()\n");
#endif
device->type = RT_Device_Class_Char;
device->rx_indicate = RT_NULL;
device->tx_complete = RT_NULL;
device->init = rt_serial_init;
device->open = rt_serial_open;
device->close = rt_serial_close;
device->read = rt_serial_read;
device->write = rt_serial_write;
device->control = rt_serial_control;
device->user_data = RT_NULL;
/* register a character device */
return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | flag);
}
rt_err_t rt_hw_serial_init(void)
{
return rt_hw_serial_register(&serial_device,"sci0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM);
}
//#endif

22
bsp/simulator/serial.h Normal file
View File

@ -0,0 +1,22 @@
/*
*********************************************************************************************************
* MC9S12DP256/DG128 Specific code
* BANKED MEMORY MODEL
*
* File : rthw.c
* By : parai
* email:parai@foxmail.com
*******************************************************************************************************/
#ifndef __RT_HW_SERIAL_H__
#define __RT_HW_SERIAL_H__
#define SERIAL_RX_BUFFER_SIZE 80
struct serial_int_rx
{
rt_uint8_t rx_buffer[SERIAL_RX_BUFFER_SIZE];
rt_uint32_t read_index, save_index;
};
rt_err_t rt_hw_serial_init(void);
#endif

View File

@ -0,0 +1,24 @@
/*
* File : sst25vfxx_mtd.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, 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-12-16 aozima the first version
* 2012-02-01 mbbill MTD driver version
*/
#ifndef SST25VFXX_MTD_H
#define SST25VFXX_MTD_H
#include <rtthread.h>
#include <drivers/spi.h>
rt_err_t sst25vfxx_mtd_init(const char *spi_device_name, rt_uint32_t block_start, rt_uint32_t block_end);
#endif

View File

@ -0,0 +1,229 @@
/*
* File : rtdef.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, 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-12-16 aozima the first version
* 2012-02-01 mbbill MTD device version
*/
#include <rtdevice.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sst25vfxx_mtd.h"
#ifdef RT_USING_MTD_NOR
#define NOR_SIM "nor.bin"
/* JEDEC Manufacturer¡¯s ID */
#define MF_ID (0xBF)
/* JEDEC Device ID : Memory Type */
#define MT_ID (0x25)
/* JEDEC Device ID: Memory Capacity */
#define MC_ID_SST25VF016 (0x41)
#define MC_ID_SST25VF032 (0x4A)
#define MC_ID_SST25VF064 (0x4B)
#define BLOCK_SIZE (64*1024)
#define SST25_MTD(device) ((struct sst25_mtd*)(device))
struct sst25_mtd
{
struct rt_mtd_nor_device parent;
FILE * file;
};
static struct sst25_mtd _sst25_mtd;
static struct rt_mutex flash_lock;
/* RT-Thread MTD device interface */
static rt_uint32_t sst25vfxx_read_id(struct rt_mtd_nor_device* device)
{
rt_uint8_t id_recv[3] = {MF_ID, MT_ID, MC_ID_SST25VF016};
return (id_recv[0] << 16) | (id_recv[1] << 8) | id_recv[2];
}
static int sst25vfxx_read(struct rt_mtd_nor_device* device, rt_off_t position, rt_uint8_t *data, rt_size_t size)
{
struct sst25_mtd *sst25;
int result;
sst25 = SST25_MTD(device);
RT_ASSERT(sst25 != RT_NULL);
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
fseek(sst25->file, position, SEEK_SET);
result = fread(data, size, 1, sst25->file);
if (result < 0)
rt_kprintf("sst read error.\n");
rt_mutex_release(&flash_lock);
return size;
}
static int sst25vfxx_write(struct rt_mtd_nor_device* device, rt_off_t position,
const rt_uint8_t *data, rt_size_t size)
{
struct sst25_mtd *sst25;
int result;
sst25 = SST25_MTD(device);
RT_ASSERT(sst25 != RT_NULL);
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
fseek(sst25->file, position, SEEK_SET);
result = fwrite(data, size, 1, sst25->file);
if (result < 0)
rt_kprintf("sst write error.\n");
rt_mutex_release(&flash_lock);
return size;
}
static char block_buffer[BLOCK_SIZE];
static rt_err_t sst25vfxx_erase_block(struct rt_mtd_nor_device* device, rt_uint32_t block)
{
struct sst25_mtd *sst25;
int result;
sst25 = SST25_MTD(device);
RT_ASSERT(sst25 != RT_NULL);
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
memset(block_buffer, 0xFF, BLOCK_SIZE);
fseek(sst25->file, block, SEEK_SET);
result = fwrite(block_buffer, BLOCK_SIZE, 1, sst25->file);
if (result < 0)
rt_kprintf("sst write error.\n");
rt_mutex_release(&flash_lock);
return RT_EOK;
}
const static struct rt_mtd_nor_driver_ops sst25vfxx_mtd_ops =
{
sst25vfxx_read_id,
sst25vfxx_read,
sst25vfxx_write,
sst25vfxx_erase_block,
};
static rt_err_t sst25vfxx_hw_init(struct sst25_mtd *mtd)
{
mtd = mtd;
return RT_EOK;
}
/**
* SST25vfxx API
*/
rt_err_t sst25vfxx_mtd_init(const char * nor_name,
rt_uint32_t block_start,
rt_uint32_t block_end)
{
rt_uint32_t id, total_block;
struct sst25_mtd * sst25;
struct rt_mtd_nor_device *mtd;
sst25 = &_sst25_mtd;
mtd = &(sst25->parent);
/* set page size and block size */
mtd->block_size = 64 * 1024; /* 64kByte */
mtd->ops = &sst25vfxx_mtd_ops;
/* initialize mutex */
if (rt_mutex_init(&flash_lock, nor_name, RT_IPC_FLAG_FIFO) != RT_EOK)
{
rt_kprintf("init sd lock mutex failed\n");
}
/* initialize flash */
id = sst25vfxx_read_id(mtd);
switch (id & 0xff)
{
case MC_ID_SST25VF016:
total_block = (16 * 1024 * 1024 / 8) / mtd->block_size;
break;
case MC_ID_SST25VF032:
total_block = (32 * 1024 * 1024 / 8) / mtd->block_size;
break;
case MC_ID_SST25VF064:
total_block = (64 * 1024 * 1024 / 8) / mtd->block_size;
break;
default:
rt_kprintf("SST25 detection error, id: %x\n", id);
return -RT_ERROR;
}
if ((block_end == RT_UINT32_MAX) || (block_end == 0))
{
block_end = total_block;
}
else if (block_end > total_block)
{
rt_kprintf("SST25 total block: %d, out of block\n", total_block);
return -RT_ERROR;
}
mtd->block_start = block_start;
mtd->block_end = block_end;
/* open nor file, if not exist, then create it */
sst25->file = fopen(NOR_SIM, "rb+");
if (sst25->file == NULL)
{
int i;
/* create a file to simulate nor */
sst25->file = fopen(NOR_SIM, "wb+");
memset(block_buffer, 0xFF, sizeof(block_buffer));
for(i=0; i<total_block; i++)
{
fseek(sst25->file, i * BLOCK_SIZE, SEEK_SET);
fwrite(block_buffer, BLOCK_SIZE, 1, sst25->file);
}
}
fseek(sst25->file, 0, SEEK_SET);
/* initialize hardware */
sst25vfxx_hw_init(&_sst25_mtd);
/* register MTD device */
rt_mtd_nor_register_device("nor", mtd);
return RT_EOK;
}
#ifdef RT_USING_FINSH
#include <finsh.h>
void nor_erase(void)
{
rt_uint32_t index;
struct rt_mtd_nor_device *mtd;
mtd = SST25_MTD(&_sst25_mtd);
for (index = mtd->block_start; index < mtd->block_end; index ++)
{
sst25vfxx_erase_block(mtd, index * mtd->block_size);
}
}
FINSH_FUNCTION_EXPORT(nor_erase, erase all block in SPI flash);
#endif
#endif

102
bsp/simulator/startup.c Normal file
View File

@ -0,0 +1,102 @@
/*
* File : startup.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006, 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://openlab.rt-thread.com/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2012-09-03 prife first implementation
*/
#include <rthw.h>
#include <rtthread.h>
#include "board.h"
/**
* @addtogroup win32
*/
#define HEAP_SIZE (1024*1024*10)
static rt_uint8_t * heap;
void vs_heap_init(void)
{
heap = malloc(HEAP_SIZE);
if (heap == RT_NULL)
rt_kprintf("there is no memory in pc.");
}
/*@{*/
extern int rt_application_init(void);
#ifdef RT_USING_FINSH
extern void finsh_system_init(void);
extern void finsh_set_device(const char* device);
#endif
/**
* This function will startup RT-Thread RTOS.
*/
void rtthread_startup(void)
{
/* init board */
rt_hw_board_init();
/* show version */
rt_show_version();
/* init tick */
rt_system_tick_init();
/* init kernel object */
rt_system_object_init();
/* init timer system */
rt_system_timer_init();
#ifdef RT_USING_HEAP
/* init memory system */
#if (MSVC)
vs_heap_init();
#endif
rt_system_heap_init((void*)heap, (void*)&heap[HEAP_SIZE-1]);
#endif
/* init scheduler system */
rt_system_scheduler_init();
/* init all device */
#ifdef RT_USING_DEVICE
rt_device_init_all();
#endif
/* init application */
rt_application_init();
/* init timer thread */
rt_system_timer_thread_init();
/* init idle thread */
rt_thread_idle_init();
/* start scheduler */
rt_system_scheduler_start();
/* never reach here */
return ;
}
int main(void)
{
/* disable interrupt first */
rt_hw_interrupt_disable();
/* startup RT-Thread RTOS */
rtthread_startup();
return 0;
}
/*@}*/

107
bsp/simulator/testfs.c Normal file
View File

@ -0,0 +1,107 @@
/*
* File : application.c
* 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
* 2009-01-05 Bernard the first version
*/
#include <rtthread.h>
#include <stdio.h>
#include <board.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
#include <dfs_posix.h>
int testfat(void)
{
int Fd,i;
int res;
Fd = open("/nor/test.txt", O_WRONLY | O_CREAT | O_TRUNC, 0); //打开文件
if (Fd>=0)
{
rt_kprintf("begin\n");
for (i = 0; i < 94520 ; i++)
//for (i = 0; i < 512 ; i++)
{
res = write(Fd, &i, 1);
if (res < 0)
{
rt_kprintf("write %d bytes, then meet a error, break\n", i);
break;
}
}
close(Fd);
rt_kprintf("over\n");
}
else
{
rt_kprintf("failed\n");
}
return 0;
}
static char buf[94520];
int testfat2(void)
{
int Fd,i;
Fd = open("/nor/test2.txt", O_WRONLY | O_CREAT | O_TRUNC, 0); //打开文件
if (Fd>=0)
{
rt_kprintf("begin\n");
for (i = 0; i < 94520 ; i++)
{
write(Fd, buf, 1);
}
close(Fd);
rt_kprintf("over\n");
}
else
{
rt_kprintf("failed\n");
}
return 0;
}
int testfat3(void)
{
int Fd,i;
Fd = open("/nor/test3.txt", O_WRONLY | O_CREAT | O_TRUNC, 0); //打开文件
if (Fd>=0)
{
rt_kprintf("begin\n");
{
write(Fd, buf, 94520);
}
close(Fd);
rt_kprintf("over\n");
}
else
{
rt_kprintf("failed\n");
}
return 0;
}
#include <finsh.h>
FINSH_FUNCTION_EXPORT(testfat, test fs);
FINSH_FUNCTION_EXPORT(testfat2, test fs);
FINSH_FUNCTION_EXPORT(testfat3, test fs);

131
bsp/simulator/usart_sim.c Normal file
View File

@ -0,0 +1,131 @@
#include <rtthread.h>
#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>
#include "serial.h"
struct serial_int_rx serial_rx;
extern struct rt_device serial_device;
/*
* Handler for OSKey Thread
*/
static HANDLE OSKey_Thread;
static DWORD OSKey_ThreadID;
static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam);
void rt_hw_usart_init(void)
{
/*
* create serial thread that revice key input from keyboard
*/
OSKey_Thread = CreateThread(NULL,
0,
(LPTHREAD_START_ROUTINE)ThreadforKeyGet,
0,
CREATE_SUSPENDED,
&OSKey_ThreadID);
if(OSKey_Thread == NULL)
{
//Display Error Message
return;
}
SetThreadPriority(OSKey_Thread,
THREAD_PRIORITY_NORMAL);
SetThreadPriorityBoost(OSKey_Thread,
TRUE);
SetThreadAffinityMask(OSKey_Thread,
0x01);
/*
* Start OS get key Thread
*/
ResumeThread(OSKey_Thread);
}
/*
* () 0xe04b
* () 0xe048
* () 0xe04d
* () 0xe050
*/
static int savekey(unsigned char key)
{
/* save on rx buffer */
{
rt_base_t level;
/* disable interrupt */
//暂时关闭中断因为要操作uart数据结构
level = rt_hw_interrupt_disable();
/* save character */
serial_rx.rx_buffer[serial_rx.save_index] = key;
serial_rx.save_index ++;
//下面的代码检查save_index是否已经到到缓冲区尾部如果是则回转到头部称为一个环形缓冲区
if (serial_rx.save_index >= SERIAL_RX_BUFFER_SIZE)
serial_rx.save_index = 0;
//这种情况表示反转后的save_index追上了read_index则增大read_index丢弃一个旧的数据
/* if the next position is read index, discard this 'read char' */
if (serial_rx.save_index == serial_rx.read_index)
{
serial_rx.read_index ++;
if (serial_rx.read_index >= SERIAL_RX_BUFFER_SIZE)
serial_rx.read_index = 0;
}
/* enable interrupt */
//uart数据结构已经操作完成重新使能中断
rt_hw_interrupt_enable(level);
}
/* invoke callback */
if (serial_device.rx_indicate != RT_NULL)
{
rt_size_t rx_length;
/* get rx length */
rx_length = serial_rx.read_index > serial_rx.save_index ?
SERIAL_RX_BUFFER_SIZE - serial_rx.read_index + serial_rx.save_index :
serial_rx.save_index - serial_rx.read_index;
serial_device.rx_indicate(&serial_device, rx_length);
}
return 0;
}
static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam)
{
unsigned char key;
(void)lpParam; //prevent compiler warnings
for(;;)
{
key = _getch();//getchar();
if (key == 0xE0)
{
key = _getch();
if (key == 0x48) //up key , 0x1b 0x5b 0x41
{
savekey(0x1b);
savekey(0x5b);
savekey(0x41);
}
else if (key == 0x50)//0x1b 0x5b 0x42
{
savekey(0x1b);
savekey(0x5b);
savekey(0x42);
}
continue;
}
savekey(key);
}
} /*** ThreadforKeyGet ***/

20
bsp/simulator/vc.sln Normal file
View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vs", "vs2005.vcproj", "{4A6BF1B1-C645-4BAD-A9B7-7B6E3DB67B2C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4A6BF1B1-C645-4BAD-A9B7-7B6E3DB67B2C}.Debug|Win32.ActiveCfg = Debug|Win32
{4A6BF1B1-C645-4BAD-A9B7-7B6E3DB67B2C}.Debug|Win32.Build.0 = Debug|Win32
{4A6BF1B1-C645-4BAD-A9B7-7B6E3DB67B2C}.Release|Win32.ActiveCfg = Release|Win32
{4A6BF1B1-C645-4BAD-A9B7-7B6E3DB67B2C}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

BIN
bsp/simulator/vc.suo Normal file

Binary file not shown.

739
bsp/simulator/vs2005.vcproj Normal file
View File

@ -0,0 +1,739 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="vs"
ProjectGUID="{4A6BF1B1-C645-4BAD-A9B7-7B6E3DB67B2C}"
RootNamespace="vs2008"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\;..\..\include;..\..\bsp\vs2008;..\..\components\finsh;..\..\components\dfs\include;..\..\components\dfs\filesystems\uffs\src\inc\;..\..\components\dfs\filesystems\uffs;..\..\components\drivers\include;..\..\components\dfs\filesystems\jffs2\src;..\..\components\dfs\filesystems\jffs2\kernel;..\..\components\dfs\filesystems\jffs2\include;..\..\components\dfs\filesystems\jffs2\;..\..\components\dfs\filesystems\jffs2\cyg\compress"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;MSVC;_TIME_T_DEFINED"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\porting.c"
>
</File>
<File
RelativePath=".\rtconfig.h"
>
</File>
<Filter
Name="kernel"
>
<File
RelativePath="..\..\src\clock.c"
>
</File>
<File
RelativePath="..\..\src\device.c"
>
</File>
<File
RelativePath="..\..\src\idle.c"
>
</File>
<File
RelativePath="..\..\src\ipc.c"
>
</File>
<File
RelativePath="..\..\src\irq.c"
>
</File>
<File
RelativePath="..\..\src\kservice.c"
>
</File>
<File
RelativePath="..\..\src\mem.c"
>
</File>
<File
RelativePath="..\..\src\memheap.c"
>
</File>
<File
RelativePath="..\..\src\mempool.c"
>
</File>
<File
RelativePath="..\..\src\object.c"
>
</File>
<File
RelativePath="..\..\src\scheduler.c"
>
</File>
<File
RelativePath="..\..\src\slab.c"
>
</File>
<File
RelativePath="..\..\src\thread.c"
>
</File>
<File
RelativePath="..\..\src\timer.c"
>
</File>
</Filter>
<Filter
Name="board"
>
<File
RelativePath=".\application.c"
>
</File>
<File
RelativePath=".\board.c"
>
</File>
<File
RelativePath=".\nand_sim.c"
>
</File>
<File
RelativePath=".\platform.c"
>
</File>
<File
RelativePath=".\sd_sim.c"
>
</File>
<File
RelativePath=".\serial.c"
>
</File>
<File
RelativePath=".\sst25vfxx_mtd_sim.c"
>
</File>
<File
RelativePath=".\startup.c"
>
</File>
<File
RelativePath=".\testfs.c"
>
</File>
<File
RelativePath=".\usart_sim.c"
>
</File>
</Filter>
<Filter
Name="libcpu"
>
<File
RelativePath="..\..\libcpu\x86\win32\cpu_port.c"
>
</File>
<File
RelativePath="..\..\libcpu\x86\win32\cpu_port.h"
>
</File>
</Filter>
<Filter
Name="finsh"
>
<File
RelativePath="..\..\components\finsh\cmd.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh.h"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_compiler.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_error.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_error.h"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_heap.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_heap.h"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_init.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_node.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_node.h"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_ops.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_ops.h"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_parser.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_parser.h"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_token.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_token.h"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_var.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_var.h"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_vm.c"
>
</File>
<File
RelativePath="..\..\components\finsh\finsh_vm.h"
>
</File>
<File
RelativePath="..\..\components\finsh\shell.c"
>
</File>
<File
RelativePath="..\..\components\finsh\shell.h"
>
</File>
<File
RelativePath="..\..\components\finsh\symbol.c"
>
</File>
</Filter>
<Filter
Name="DFS"
>
<File
RelativePath="..\..\components\dfs\src\dfs.c"
>
</File>
<File
RelativePath="..\..\components\dfs\src\dfs_file.c"
>
</File>
<File
RelativePath="..\..\components\dfs\src\dfs_fs.c"
>
</File>
<File
RelativePath="..\..\components\dfs\src\dfs_posix.c"
>
</File>
</Filter>
<Filter
Name="FATFS"
>
<File
RelativePath="..\..\components\dfs\filesystems\elmfat\dfs_elm.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\elmfat\diskio.h"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\elmfat\ff.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\elmfat\ff.h"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\elmfat\ffconf.h"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\elmfat\integer.h"
>
</File>
</Filter>
<Filter
Name="MTD"
>
<File
RelativePath="..\..\components\drivers\mtd\mtd_nand.c"
>
</File>
<File
RelativePath="..\..\components\drivers\mtd\mtd_nor.c"
>
</File>
<Filter
Name="uffs"
>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\dfs_uffs.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\dfs_uffs.h"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\uffs_config.h"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\uffs_nandif.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\uffs_rtthread.c"
>
</File>
<Filter
Name="src"
>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_badblock.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_blockinfo.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_buf.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_crc.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_debug.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_device.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_ecc.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_fd.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_find.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_flash.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_fs.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_init.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_mem.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_mtb.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_pool.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_public.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_tree.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_utils.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\uffs\src\uffs\uffs_version.c"
>
</File>
</Filter>
</Filter>
</Filter>
<Filter
Name="components"
>
<File
RelativePath="..\..\components\init\components.c"
>
</File>
</Filter>
<Filter
Name="jffs"
>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\dfs_jffs2.c"
>
</File>
<Filter
Name="cyg"
>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\compress\src\adler32.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\compress\src\compress.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\crc\crc16.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\crc\crc32.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\compress\src\deflate.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\compress\src\infback.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\compress\src\inffast.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\compress\src\inflate.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\compress\src\inftrees.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\crc\posix_crc.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\compress\src\trees.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\compress\src\uncompr.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\cyg\compress\src\zutil.c"
>
</File>
</Filter>
<Filter
Name="kernel"
>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\kernel\rbtree.c"
>
</File>
</Filter>
<Filter
Name="src"
>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\build.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\compr.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\compr_rtime.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\compr_rubin.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\compr_zlib.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\debug.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\dir-ecos.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\erase.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\flashio.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\fs-ecos.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\gc.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\gcthread.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\malloc-ecos.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\nodelist.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\nodemgmt.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\read.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\readinode.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\scan.c"
>
</File>
<File
RelativePath="..\..\components\dfs\filesystems\jffs2\src\write.c"
>
</File>
</Filter>
</Filter>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>