Kaynağa Gözat

merge bsp/simlinux into bsp/simulator

prife 12 yıl önce
ebeveyn
işleme
fbbc4c8d18

+ 2 - 2
bsp/simlinux/drivers/board.c

@@ -71,8 +71,8 @@ void rt_hw_exit(void)
     /* *
      * 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 
+     * 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);

+ 2 - 2
bsp/simlinux/drivers/usart_sim.c

@@ -123,7 +123,7 @@ static int savekey(unsigned char key)
 
         serial_device.rx_indicate(&serial_device, rx_length);
     }
-    return 0; 
+    return 0;
 }
 #ifdef _WIN32
 static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam)
@@ -131,7 +131,7 @@ static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam)
 
 static struct termios oldt, newt;
 /*simulate windows' getch(), it works!!*/
-void set_stty(void) 
+void set_stty(void)
 {
 	/* get terminal input's attribute */
     tcgetattr(STDIN_FILENO, &oldt);

+ 31 - 25
bsp/simulator/SConstruct

@@ -18,38 +18,44 @@ else:
 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')
 
-libs = Split('''
-winmm
-gdi32
-winspool
-comdlg32
-advapi32
-shell32
-ole32
-oleaut32
-uuid
-odbc32
-odbccp32
-''')
-definitions = Split('''
-WIN32
-_DEBUG
-_CONSOLE
-MSVC
-_TIME_T_DEFINED
-''')
+if rtconfig.PLATFORM == 'cl':
+    TARGET = 'rtthread-win32.' + rtconfig.TARGET_EXT
+
+    libs = Split('''
+    winmm
+    gdi32
+    winspool
+    comdlg32
+    advapi32
+    shell32
+    ole32
+    oleaut32
+    uuid
+    odbc32
+    odbccp32
+    ''')
+    definitions = Split('''
+    WIN32
+    _DEBUG
+    _CONSOLE
+    MSVC
+    _TIME_T_DEFINED
+    ''')
+    env.Append(CCFLAGS=rtconfig.CFLAGS)
+    env.Append(LINKFLAGS=rtconfig.LFLAGS)
+    env['LIBS']=libs
+    env['CPPDEFINES']=definitions
+else:
+    TARGET = 'rtthread'
+    env.Append(CCFLAGS=rtconfig.CFLAGS)
+    env.Append(LINKFLAGS=rtconfig.LFLAGS)
 
-env.Append(CCFLAGS=rtconfig.CFLAGS)
-env.Append(LINKFLAGS=rtconfig.LFLAGS)
-env['LIBS']=libs
-env['CPPDEFINES']=definitions
 
 # prepare building environment
 

+ 5 - 1
bsp/simulator/applications/SConscript

@@ -1,7 +1,11 @@
 from building import *
 
-cwd     = GetCurrentDir()
+cwd = GetCurrentDir()
 src	= Glob('*.c')
+
+# remove no need file.
+if GetDepend('RT_USING_DFS_WINSHAREDIR') == False:
+    SrcRemove(src, 'dfs_win32.c')
 CPPPATH = [cwd, str(Dir('#'))]
 
 group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)

+ 8 - 14
bsp/simulator/applications/application.c

@@ -18,6 +18,7 @@
 
 #include <components.h>
 
+
 void rt_init_thread_entry(void *parameter)
 {
 #ifdef RT_USING_LWIP
@@ -49,7 +50,8 @@ void rt_init_thread_entry(void *parameter)
 
 #ifdef RT_USING_DFS_ELMFAT
         /* mount sd card fatfs as root directory */
-        if (dfs_mount("sd0", "/disk/sd", "elm", 0, 0) == 0)
+        //if (dfs_mount("sd0", "/disk/sd", "elm", 0, 0) == 0)
+        if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
             rt_kprintf("fatfs initialized!\n");
         else
             rt_kprintf("fatfs initialization failed!\n");
@@ -74,30 +76,23 @@ void rt_init_thread_entry(void *parameter)
     }
 #endif
 
-#if 0
-    {
-        extern void application_init(void);
-        rt_thread_delay(RT_TICK_PER_SECOND);
-        application_init();
-    }
-#endif
-
 #if defined(RT_USING_RTGUI)
-    rt_thread_delay(3000);
-    snake_main();
+    //rt_thread_delay(RT_TICK_PER_SECOND);
+    //snake_main();
 #endif
 }
 
 static void rt_test_thread_entry(void *parameter)
 {
     int i;
-    for (i = 0; i < 10; i++)
+    for (i = 0; i < 5; i++)
     {
         rt_kprintf("hello, world\n");
-        rt_thread_delay(100);
+        rt_thread_delay(RT_TICK_PER_SECOND);
     }
 }
 
+
 int rt_application_init()
 {
     rt_thread_t tid;
@@ -118,5 +113,4 @@ int rt_application_init()
     return 0;
 }
 
-
 /*@}*/

+ 33 - 4
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

+ 2 - 2
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

+ 26 - 2
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
 }

+ 8 - 1
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;
 }
 

+ 64 - 6
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 ***/
+} /*** ThreadforKeyGet ***/

+ 10 - 6
bsp/simulator/rtconfig.h

@@ -2,15 +2,15 @@
 #ifndef __RTTHREAD_CFG_H__
 #define __RTTHREAD_CFG_H__
 
+#define RT_HEAP_SIZE   (1024*1024*2)
+
+#if  defined(_MSC_VER)
 /* SECTION: port for visual studio */
-#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
 
-#define RT_HEAP_SIZE   (1024*1024*2)
-
 /* disable some warning in MSC */
 #pragma warning(disable:4273)	/* to ignore: warning C4273: inconsistent dll linkage */
 #pragma warning(disable:4312)   /* to ignore: warning C4312: 'type cast' : conversion from 'rt_uint32_t' to 'rt_uint32_t *' */
@@ -18,6 +18,9 @@
 #pragma warning(disable:4996)   /* to ignore: warning C4996: The POSIX name for this item is deprecated. */
 #pragma warning(disable:4267)   /* to ignore: warning C4267: conversion from 'size_t' to 'rt_size_t', possible loss of data */
 #pragma warning(disable:4244)   /* to ignore: warning C4244: '=' : conversion from '__w64 int' to 'rt_size_t', possible loss of data */
+
+#elif defined(__GNUC__)
+#define RT_USING_NOLIBC
 #endif
 
 /* SECTION: basic kernel options */
@@ -31,11 +34,12 @@
 #define RT_THREAD_PRIORITY_MAX  32	
 
 /* Tick per Second */
-#define RT_TICK_PER_SECOND	1000
+#define RT_TICK_PER_SECOND	100
 
 /* SECTION: RT_DEBUG */
 /* Thread Debug */
 #define RT_DEBUG
+//#define RT_DEBUG_SCHEDULER   1
 #define RT_THREAD_DEBUG
 
 #define RT_USING_OVERFLOW_CHECK
@@ -129,11 +133,11 @@
 /* #define RT_UFFS_USE_CHECK_MARK_FUNCITON */
 
 /* DFS: JFFS2 nor flash file system options */
-#define RT_USING_DFS_JFFS2
+//#define RT_USING_DFS_JFFS2
 
 /* DFS: windows share directory mounted to rt-thread/dfs  */
 /* only used in bsp/simulator */
-#define RT_USING_DFS_WINSHAREDIR
+//#define RT_USING_DFS_WINSHAREDIR
 
 /* the max number of mounted file system */
 #define DFS_FILESYSTEMS_MAX			4

+ 10 - 5
bsp/simulator/rtconfig.py

@@ -1,7 +1,9 @@
 # toolchains options
 ARCH='sim'
-CPU='win32' #CPU='posix'
-CROSS_TOOL='msvc' #win32
+#CPU='win32'
+#CPU='posix'
+CPU='posix'
+CROSS_TOOL='gcc' #msvc # gcc
 
 # lcd panel options
 # 'FMT0371','ILI932X', 'SSD1289'
@@ -33,16 +35,19 @@ if PLATFORM == 'gcc':
     OBJCPY = PREFIX + 'objcopy'
 
     DEVICE = ' -ffunction-sections -fdata-sections'
-    CFLAGS = DEVICE
+    DEVICE = '  '
+    CFLAGS = DEVICE + ' -I/usr/include -w -D_REENTRANT'
     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'
+    #LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-linux.map -lpthread'
+    #LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-linux.map -pthread'
+    LFLAGS = DEVICE + ' -Wl,-Map=rtthread-linux.map -pthread -T gcc.ld'
 
     CPATH = ''
     LPATH = ''
 
     if BUILD == 'debug':
-        CFLAGS += ' -O0 -gdwarf-2'
+        CFLAGS += ' -g -O0 -gdwarf-2'
         AFLAGS += ' -gdwarf-2'
     else:
         CFLAGS += ' -O2'