From 859477d7ba9a9b052914430d443f3d422d0aa1aa Mon Sep 17 00:00:00 2001 From: "goprife@gmail.com" Date: Thu, 27 Dec 2012 06:58:58 +0000 Subject: [PATCH] clean code in bsp/simulator git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2531 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- bsp/simulator/applications/application.c | 122 +---------------------- bsp/simulator/applications/platform.c | 4 + bsp/simulator/drivers/board.c | 39 ++++++-- bsp/simulator/drivers/board.h | 2 + bsp/simulator/rtconfig.h | 60 ++++++----- 5 files changed, 73 insertions(+), 154 deletions(-) diff --git a/bsp/simulator/applications/application.c b/bsp/simulator/applications/application.c index 7d0109c0a..0ef8c5164 100644 --- a/bsp/simulator/applications/application.c +++ b/bsp/simulator/applications/application.c @@ -16,11 +16,7 @@ #include #include -/* fix the compile errors for redefiniton of lwip_htonl in win socket */ -#ifdef _WIN32 -#undef RT_USING_LWIP #include -#endif void rt_init_thread_entry(void *parameter) { @@ -82,13 +78,6 @@ void rt_init_thread_entry(void *parameter) rt_kprintf("jffs2 initialzation failed!\n"); #endif - - } -#endif -#ifdef WIN32 - { - extern void low_cpu(void); - rt_thread_idle_sethook(low_cpu); } #endif @@ -106,7 +95,7 @@ void rt_init_thread_entry(void *parameter) #endif } -void rt_test_thread_entry(void *parameter) +static void rt_test_thread_entry(void *parameter) { int i; for (i = 0; i < 10; i++) @@ -135,115 +124,6 @@ int rt_application_init() return 0; } -#ifdef WIN32 -#include -void low_cpu(void) -{ - Sleep(1000); -} -#ifndef _CRT_TERMINATE_DEFINED -#define _CRT_TERMINATE_DEFINED -_CRTIMP __declspec(noreturn) void __cdecl exit(__in int _Code); -_CRTIMP __declspec(noreturn) void __cdecl _exit(__in int _Code); -_CRTIMP void __cdecl abort(void); -#endif -void rt_hw_exit(void) -{ - rt_kprintf("RT-Thread, bye\n"); - exit(0); -} -FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt-thread); - -#endif - -#include -void test_fs(void) -{ - int fd; - DIR *dir; - struct dirent *dirp; - off_t off[6]; - int i; - mkdir("/testdir", 0777); - fd = open("/testdir/file1", O_CREAT | O_RDWR, 0777); - close(fd); - fd = open("/testdir/file2", O_CREAT | O_RDWR, 0777); - close(fd); - fd = open("/testdir/file3", O_CREAT | O_RDWR, 0777); - close(fd); - fd = open("/testdir/file4", O_CREAT | O_RDWR, 0777); - close(fd); - fd = open("/testdir/file5", O_CREAT | O_RDWR, 0777); - close(fd); - fd = open("/testdir/file6", O_CREAT | O_RDWR, 0777); - close(fd); - - dir = opendir("/testdir"); - for (i = 0; i < 6; i++) - { - off[i] = telldir(dir); - dirp = readdir(dir); - if (dirp) - rt_kprintf("#%d NAME:%s\n", i, dirp->d_name); - else break; - } - for (i = 0; i < 6; i++) - { - seekdir(dir, off[i]); - dirp = readdir(dir); - if (dirp) - rt_kprintf("#%d NAME:%s\n", i, dirp->d_name); - else break; - } - - rt_kprintf("unlink file2\n"); - unlink("/testdir/file2"); - rewinddir(dir); - for (i = 0; i < 6; i++) - { - off[i] = telldir(dir); - dirp = readdir(dir); - if (dirp) - rt_kprintf("#%d NAME:%s\n", i, dirp->d_name); - else break; - } - for (i = 0; i < 6; i++) - { - seekdir(dir, off[i]); - dirp = readdir(dir); - if (dirp) - rt_kprintf("#%d NAME:%s\n", i, dirp->d_name); - else break; - } - - rt_kprintf("unlink file4\n"); - unlink("/testdir/file4"); - rewinddir(dir); - for (i = 0; i < 6; i++) - { - off[i] = telldir(dir); - dirp = readdir(dir); - if (dirp) - rt_kprintf("#%d NAME:%s\n", i, dirp->d_name); - else break; - } - for (i = 0; i < 6; i++) - { - seekdir(dir, off[i]); - dirp = readdir(dir); - if (dirp) - rt_kprintf("#%d NAME:%s\n", i, dirp->d_name); - else break; - } - - unlink("/testdir/file1"); - unlink("/testdir/file3"); - unlink("/testdir/file5"); - unlink("/testdir/file6"); - - closedir(dir); -} -FINSH_FUNCTION_EXPORT(test_fs, test fs); /*@}*/ diff --git a/bsp/simulator/applications/platform.c b/bsp/simulator/applications/platform.c index d137be0bf..8d94fc501 100644 --- a/bsp/simulator/applications/platform.c +++ b/bsp/simulator/applications/platform.c @@ -22,6 +22,10 @@ void rt_platform_init(void) sdl_start(); #endif /* RT_USING_RTGUI */ +#ifdef WIN32 + + rt_thread_idle_sethook(rt_hw_win32_low_cpu); +#endif rt_thread_delay(50); rt_device_init_all(); } diff --git a/bsp/simulator/drivers/board.c b/bsp/simulator/drivers/board.c index 5d9cfcfd6..33b1300ba 100644 --- a/bsp/simulator/drivers/board.c +++ b/bsp/simulator/drivers/board.c @@ -22,24 +22,43 @@ */ /** - * This function will initial STM32 board. + * This function will initial win32 */ 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 - } +/* fix the compile errors for redefiniton of lwip_htonl in win socket */ +#ifdef WIN32 +#include +void rt_hw_win32_low_cpu(void) +{ + Sleep(1000); +} + +#if defined(RT_USING_FINSH) + +#ifndef _CRT_TERMINATE_DEFINED +#define _CRT_TERMINATE_DEFINED +_CRTIMP __declspec(noreturn) void __cdecl exit(__in int _Code); +_CRTIMP __declspec(noreturn) void __cdecl _exit(__in int _Code); +_CRTIMP void __cdecl abort(void); +#endif + +#include +void rt_hw_exit(void) +{ + rt_kprintf("RT-Thread, bye\n"); + exit(0); +} +FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt-thread); + +#endif /* RT_USING_FINSH */ + +#endif /* WIN32 */ /*@}*/ diff --git a/bsp/simulator/drivers/board.h b/bsp/simulator/drivers/board.h index cf7c375cc..8c943ef81 100644 --- a/bsp/simulator/drivers/board.h +++ b/bsp/simulator/drivers/board.h @@ -29,4 +29,6 @@ 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); + +void rt_hw_win32_low_cpu(void); #endif diff --git a/bsp/simulator/rtconfig.h b/bsp/simulator/rtconfig.h index 60a545b0b..623114abb 100644 --- a/bsp/simulator/rtconfig.h +++ b/bsp/simulator/rtconfig.h @@ -2,6 +2,7 @@ #ifndef __RTTHREAD_CFG_H__ #define __RTTHREAD_CFG_H__ +/* SECTION: port for visual stuido */ #ifdef _MSC_VER #undef RT_USING_NEWLIB #undef RT_USING_MINILIBC @@ -9,22 +10,7 @@ #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 -/* configration for uffs, more to see dfs_uffs.h and uffs_config.h */ -#define RT_USING_DFS_UFFS -/* use ecc soft, the uffs will do all the things about ecc */ -#define RT_CONFIG_UFFS_ECC_MODE UFFS_ECC_SOFT -/* enable this ,you need provide a mark_badblock/check_block funciton */ -#define RT_UFFS_USE_CHECK_MARK_FUNCITON - -#define RT_USING_DFS_JFFS2 -#define RT_USING_DFS_WINSHAREDIR - +/* SECTION: basic kernel options */ /* RT_NAME_MAX*/ #define RT_NAME_MAX 8 @@ -71,20 +57,20 @@ /* SECTION: Memory Management */ /* Using Memory Pool Management*/ -//#define RT_USING_MEMPOOL +/* #define RT_USING_MEMPOOL */ /* Using Dynamic Heap Management */ #define RT_USING_HEAP /* Using Small MM */ #define RT_USING_SMALL_MEM -//#define RT_TINY_SIZE +/* #define RT_TINY_SIZE */ /* SECTION: Device System */ /* Using Device System */ #define RT_USING_DEVICE -//#define RT_USING_SERIAL -//#define RT_USING_UART1 +/* #define RT_USING_SERIAL */ +/* #define RT_USING_UART1 */ /* SECTION: Console options */ #define RT_USING_CONSOLE @@ -92,6 +78,15 @@ #define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLE_DEVICE_NAME "sci0" +/* SECTION: commponent opitions */ +#define RT_USING_COMPONENTS_INIT + +/* SECTION: MTD interface opitons */ +/* using mtd nand flash */ +#define RT_USING_MTD_NAND +/* using mtd nor flash */ +#define RT_USING_MTD_NOR + /* SECTION: finsh, a C-Express shell */ #define RT_USING_FINSH /* Using symbol table */ @@ -101,6 +96,7 @@ /* SECTION: device filesystem */ #define RT_USING_DFS +/* DFS: ELM FATFS options */ #define RT_USING_DFS_ELMFAT #define RT_DFS_ELM_WORD_ACCESS /* Reentrancy (thread safe) of the FatFs module. */ @@ -112,13 +108,31 @@ /* Maximum sector size to be handled. */ #define RT_DFS_ELM_MAX_SECTOR_SIZE 512 +/* DFS: network filesystem options */ +#define RT_USING_DFS_NFS + +/* DFS: uffs nand filesystem options */ +/* #define RT_USING_DFS_UFFS */ +/* configration for uffs, more to see dfs_uffs.h and uffs_config.h */ +/* use ecc soft, the uffs will do all the things about ecc */ +#define RT_CONFIG_UFFS_ECC_MODE UFFS_ECC_SOFT +/* enable this ,you need provide a mark_badblock/check_block funciton */ +#define RT_UFFS_USE_CHECK_MARK_FUNCITON + +/* DFS: uffs nor flash filesystem options */ +#define RT_USING_DFS_JFFS2 + +/* DFS: windows share dictory mounted to rt-thread/dfs */ +/* only used in bsp/simulator */ +#define RT_USING_DFS_WINSHAREDIR + /* 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 +#define RT_USING_LWIP /* LwIP uses RT-Thread Memory Management */ #define RT_LWIP_USING_RT_MEM /* Enable ICMP protocol*/ @@ -139,13 +153,13 @@ /* ip address of target*/ #define RT_LWIP_IPADDR0 192 #define RT_LWIP_IPADDR1 168 -#define RT_LWIP_IPADDR2 1 +#define RT_LWIP_IPADDR2 126 #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_GWADDR2 126 #define RT_LWIP_GWADDR3 1 /* mask address of target*/