diff options
| author | prife <[email protected]> | 2013-01-22 16:57:47 +0800 |
|---|---|---|
| committer | prife <[email protected]> | 2013-01-22 16:57:47 +0800 |
| commit | fbbc4c8d183cbe12b649eb2dc750708f534da9bc (patch) | |
| tree | 3aae6de3ceabff01b0c29fb5925472bb15d15ff8 /bsp/simulator/drivers | |
| parent | 29d63fe2bcd04008322a0ca2259a56a6ed51ee89 (diff) | |
merge bsp/simlinux into bsp/simulator
Diffstat (limited to 'bsp/simulator/drivers')
| -rwxr-xr-x[-rw-r--r--] | bsp/simulator/drivers/board.c | 37 | ||||
| -rwxr-xr-x[-rw-r--r--] | bsp/simulator/drivers/sd_sim.c | 4 | ||||
| -rwxr-xr-x[-rw-r--r--] | bsp/simulator/drivers/sdl_fb.c | 28 | ||||
| -rwxr-xr-x[-rw-r--r--] | bsp/simulator/drivers/serial.c | 9 | ||||
| -rwxr-xr-x[-rw-r--r--] | bsp/simulator/drivers/usart_sim.c | 70 |
5 files changed, 133 insertions, 15 deletions
diff --git a/bsp/simulator/drivers/board.c b/bsp/simulator/drivers/board.c index c6320d27b5..dc24d39e20 100644..100755 --- a/bsp/simulator/drivers/board.c +++ b/bsp/simulator/drivers/board.c @@ -16,7 +16,6 @@ #include <rtthread.h> #include "board.h" #include <stdlib.h> -#include <windows.h> /** * @addtogroup simulator on win32 @@ -30,29 +29,56 @@ rt_uint8_t *rt_hw_sram_init(void) if (heap == RT_NULL) { rt_kprintf("there is no memory in pc."); +#ifdef _WIN32 _exit(1); +#else + exit(1); +#endif } return heap; } +#ifdef _WIN32 +#include <windows.h> +#endif + void rt_hw_win32_low_cpu(void) { +#ifdef _WIN32 + /* in windows */ Sleep(1000); +#else + /* in linux */ + sleep(1); +#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 <finsh.h> void rt_hw_exit(void) { rt_kprintf("RT-Thread, bye\n"); +#if !defined(_WIN32) && defined(__GNUC__) + /* * + * getchar reads key from buffer, while finsh need an non-buffer getchar + * in windows, getch is such an function, in linux, we had to change + * the behaviour of terminal to get an non-buffer getchar. + * in usart_sim.c, set_stty is called to do this work + * */ + { + extern void restore_stty(void); + restore_stty(); + } +#endif exit(0); } FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt - thread); @@ -66,8 +92,11 @@ void rt_hw_board_init() /* init system memory */ heap = rt_hw_sram_init(); -#if defined(RT_USING_CONSOLE) +//#if defined(RT_USING_USART) rt_hw_usart_init(); +//#endif + +#if defined(RT_USING_CONSOLE) rt_hw_serial_init(); rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif diff --git a/bsp/simulator/drivers/sd_sim.c b/bsp/simulator/drivers/sd_sim.c index 7c9844bae3..1f39843d3e 100644..100755 --- a/bsp/simulator/drivers/sd_sim.c +++ b/bsp/simulator/drivers/sd_sim.c @@ -1,7 +1,7 @@ #include <rtthread.h> #include <stdio.h> -#include <stdlib.h> -#include <string.h> +//#include <stdlib.h> +//#include <string.h> #include <dfs_def.h> // #define SD_TRACE rt_kprintf diff --git a/bsp/simulator/drivers/sdl_fb.c b/bsp/simulator/drivers/sdl_fb.c index 790797f2af..752a6fb93c 100644..100755 --- a/bsp/simulator/drivers/sdl_fb.c +++ b/bsp/simulator/drivers/sdl_fb.c @@ -1,6 +1,10 @@ #include <rtthread.h> +#ifdef _WIN32 #include <sdl.h> +#else +#include <SDL/SDL.h> +#endif #include <rtdevice.h> #include <rtgui/driver.h> @@ -104,7 +108,7 @@ static void sdlfb_hw_init(void) //_putenv("SDL_VIDEODRIVER=windib"); //if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0) - if (SDL_Init(SDL_INIT_EVERYTHING) < 0) + if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); @@ -132,16 +136,24 @@ static void sdlfb_hw_init(void) sdllock = rt_mutex_create("fb", RT_IPC_FLAG_FIFO); } +#ifdef _WIN32 #include <windows.h> #include <mmsystem.h> +#else +#include <pthread.h> +#endif + #include <stdio.h> -#include <sdl.h> #include <rtgui/event.h> #include <rtgui/kbddef.h> #include <rtgui/rtgui_server.h> #include <rtgui/rtgui_system.h> +#ifdef _WIN32 static DWORD WINAPI sdl_loop(LPVOID lpParam) +#else +static void *sdl_loop(void *lpParam) +#endif { int quit = 0; SDL_Event event; @@ -284,6 +296,7 @@ static DWORD WINAPI sdl_loop(LPVOID lpParam) /* start sdl thread */ void rt_hw_sdl_start(void) { +#ifdef _WIN32 HANDLE thread; DWORD thread_id; @@ -301,4 +314,15 @@ void rt_hw_sdl_start(void) return; } ResumeThread(thread); +#else + /* Linux */ + pthread_t pid; + int res; + res = pthread_create(&pid, NULL, &sdl_loop, NULL); + if (res) + { + printf("pthread create sdl thread faild, <%d>\n", res); + exit(EXIT_FAILURE); + } +#endif } diff --git a/bsp/simulator/drivers/serial.c b/bsp/simulator/drivers/serial.c index 5a18d98bde..87de4d0498 100644..100755 --- a/bsp/simulator/drivers/serial.c +++ b/bsp/simulator/drivers/serial.c @@ -13,8 +13,12 @@ #include "serial.h" #include <stdio.h> struct rt_device serial_device; -extern struct serial_int_rx serial_rx; +//extern struct serial_int_rx serial_rx; +struct serial_int_rx serial_rx; + +#if 0 static FILE *fp = RT_NULL; +#endif /*@{*/ @@ -109,13 +113,16 @@ static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void *buff #if _DEBUG_SERIAL==1 printf("in rt_serial_write()\n"); #endif +#if 0 if (fp == NULL) fp = fopen("log.txt", "wb+"); if (fp != NULL) fwrite(buffer, size, 1, fp); +#endif printf("%s", (char *)buffer); + fflush(stdout); return size; } diff --git a/bsp/simulator/drivers/usart_sim.c b/bsp/simulator/drivers/usart_sim.c index efc04614cb..2cbb1ed345 100644..100755 --- a/bsp/simulator/drivers/usart_sim.c +++ b/bsp/simulator/drivers/usart_sim.c @@ -1,15 +1,19 @@ #include <rthw.h> #include <rtthread.h> + +#ifdef _WIN32 #include <windows.h> #include <mmsystem.h> -#include <stdio.h> #include <conio.h> +#endif +#include <stdio.h> #include "serial.h" struct serial_int_rx serial_rx; extern struct rt_device serial_device; +#ifdef _WIN32 /* * Handler for OSKey Thread */ @@ -19,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 */ @@ -46,9 +49,31 @@ void rt_hw_usart_init(void) * Start OS get key Thread */ ResumeThread(OSKey_Thread); - } +#else /* POSIX version */ + +#include <pthread.h> +#include <semaphore.h> +#include <stdlib.h> +#include <signal.h> +#include <termios.h> /* for tcxxxattr, ECHO, etc */ +#include <unistd.h> /* for STDIN_FILENO */ + + +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 @@ -100,15 +125,48 @@ static int savekey(unsigned char key) } return 0; } +#ifdef _WIN32 static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam) +#else + +static struct termios oldt, newt; +/*simulate windows' getch(), it works!!*/ +void set_stty(void) +{ + /* 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); +} + +void restore_stty(void) +{ + /* recover terminal's attribute */ + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); +} + +#define getch getchar + +static void * ThreadforKeyGet(void * lpParam) +#endif /* not _WIN32*/ { unsigned char key; +#ifndef _WIN32 + sigset_t sigmask, oldmask; + /* set the getchar without buffer */ + sigfillset(&sigmask); + pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask); + set_stty(); +#endif (void)lpParam; //prevent compiler warnings - for (;;) { key = getch(); +#ifdef _WIN32 if (key == 0xE0) { key = getch(); @@ -128,7 +186,7 @@ static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam) continue; } - +#endif savekey(key); } -} /*** ThreadforKeyGet ***/
\ No newline at end of file +} /*** ThreadforKeyGet ***/ |
