diff --git a/bsp/simlinux/drivers/SConscript b/bsp/simlinux/drivers/SConscript index 34b1a0bda7..079d329c0e 100755 --- a/bsp/simlinux/drivers/SConscript +++ b/bsp/simlinux/drivers/SConscript @@ -12,8 +12,8 @@ if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_MTD_NAND') == False SrcRemove(src, 'nanddrv_file.c') if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_MTD_NOR') == False: SrcRemove(src, 'sst25vfxx_mtd_sim.c') -if GetDepend('RT_USING_SERIAL') == False: - SrcRemove(src, 'usart_sim.c') +#if GetDepend('RT_USING_SERIAL') == False: +# SrcRemove(src, 'usart_sim.c') CPPPATH = [cwd] diff --git a/bsp/simlinux/drivers/board.c b/bsp/simlinux/drivers/board.c index 5506acb55d..1ece5c8831 100755 --- a/bsp/simlinux/drivers/board.c +++ b/bsp/simlinux/drivers/board.c @@ -53,15 +53,16 @@ void rt_hw_win32_low_cpu(void) #endif } -#if defined(RT_USING_FINSH) - +#ifdef _WIN32 #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 +#endif +#if defined(RT_USING_FINSH) #include void rt_hw_exit(void) { @@ -79,9 +80,9 @@ void rt_hw_board_init() /* init system memory */ heap = rt_hw_sram_init(); -#if defined(RT_USING_USART) +//#if defined(RT_USING_USART) rt_hw_usart_init(); -#endif +//#endif #if defined(RT_USING_CONSOLE) rt_hw_serial_init(); diff --git a/bsp/simlinux/drivers/usart_sim.c b/bsp/simlinux/drivers/usart_sim.c index 6a2564786a..5331f34679 100755 --- a/bsp/simlinux/drivers/usart_sim.c +++ b/bsp/simlinux/drivers/usart_sim.c @@ -4,16 +4,16 @@ #ifdef _WIN32 #include #include +#include #endif #include -#include - #include "serial.h" struct serial_int_rx serial_rx; extern struct rt_device serial_device; +#ifdef _WIN32 /* * Handler for OSKey Thread */ @@ -23,7 +23,6 @@ static DWORD OSKey_ThreadID; static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam); void rt_hw_usart_init(void) { - /* * create serial thread that receive key input from keyboard */ @@ -50,9 +49,52 @@ void rt_hw_usart_init(void) * Start OS get key Thread */ ResumeThread(OSKey_Thread); - } +#else /* POSIX version */ + +#include +#include +#include +#include /* for tcxxxattr, ECHO, etc */ +#include /* for STDIN_FILENO */ + +/*simulate windows' getch(), it works!!*/ +int getch(void) +{ + int ch; + struct termios oldt, newt; + + // get terminal input's attribute + tcgetattr(STDIN_FILENO, &oldt); + newt = oldt; + + //set termios' local mode + newt.c_lflag &= ~(ECHO|ICANON); + tcsetattr(STDIN_FILENO, TCSANOW, &newt); + + //read character from terminal input + ch = getchar(); + + //recover terminal's attribute + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + + return ch; +} + +static void * ThreadforKeyGet(void * lpParam); +static pthread_t OSKey_Thread; +void rt_hw_usart_init(void) +{ + int res; + res = pthread_create(&OSKey_Thread, NULL, &ThreadforKeyGet, NULL); + if (res) + { + printf("pthread create faild, <%d>\n", res); + exit(EXIT_FAILURE); + } +} +#endif /* * ·½Ïò¼ü(¡û)£º 0xe04b * ·½Ïò¼ü(¡ü)£º 0xe048 @@ -104,7 +146,11 @@ static int savekey(unsigned char key) } return 0; } +#ifdef _WIN32 static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam) +#else +static void * ThreadforKeyGet(void * lpParam) +#endif { unsigned char key; diff --git a/bsp/simlinux/rtconfig.h b/bsp/simlinux/rtconfig.h index ae213813ec..fcbda8a2a4 100755 --- a/bsp/simlinux/rtconfig.h +++ b/bsp/simlinux/rtconfig.h @@ -101,7 +101,7 @@ /* #define RT_USING_MTD_NOR */ /* SECTION: finsh, a C-Express shell */ -/* #define RT_USING_FINSH */ +#define RT_USING_FINSH /* Using symbol table */ #define FINSH_USING_SYMTAB #define FINSH_USING_DESCRIPTION diff --git a/libcpu/sim/posix/cpu_port.c b/libcpu/sim/posix/cpu_port.c index e3dea83eee..6d2b517cff 100644 --- a/libcpu/sim/posix/cpu_port.c +++ b/libcpu/sim/posix/cpu_port.c @@ -1,7 +1,7 @@ /* * author : prife (goprife@gmail.com) * date : 2013/01/14 01:18:50 - * version: v 0.1.0 + * version: v 0.2.0 */ #include #include