summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2013-08-31 17:14:21 -0700
committerBernard Xiong <[email protected]>2013-08-31 17:14:21 -0700
commite2a0b1930bb2e2af3069fcb0c35874b6634cfc8c (patch)
treec44c371b5d84a95491250befdadc22461462cbc2
parentf7f14cf566e5c3dbf92a0b7a52667ac702792282 (diff)
parent6563ae6cab1615df3e1abbccf8df1498934983f9 (diff)
Merge pull request #150 from grissiom/simulator-linux
Simulator linux
-rwxr-xr-xbsp/simulator/applications/application.c6
-rw-r--r--bsp/simulator/applications/platform.c5
-rwxr-xr-xbsp/simulator/drivers/sdl_fb.c18
3 files changed, 24 insertions, 5 deletions
diff --git a/bsp/simulator/applications/application.c b/bsp/simulator/applications/application.c
index 4abecb872e..ea07f01c5f 100755
--- a/bsp/simulator/applications/application.c
+++ b/bsp/simulator/applications/application.c
@@ -30,6 +30,12 @@ void rt_init_thread_entry(void *parameter)
/* initialization RT-Thread Components */
rt_components_init();
+#ifdef RT_USING_RTGUI
+ /* start sdl thread to simulate an LCD. SDL may depend on DFS and should be
+ * called after rt_components_init. */
+ rt_hw_sdl_start();
+#endif /* RT_USING_RTGUI */
+
#if defined(RT_USING_COMPONENTS_INIT) && defined(__GNUC__) && defined(RT_USING_FINSH)
finsh_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
diff --git a/bsp/simulator/applications/platform.c b/bsp/simulator/applications/platform.c
index 3c7ffdb541..fbc1003d2a 100644
--- a/bsp/simulator/applications/platform.c
+++ b/bsp/simulator/applications/platform.c
@@ -17,11 +17,6 @@ void rt_platform_init(void)
#endif /* RT_USING_DFS */
-#ifdef RT_USING_RTGUI
- /* start sdl thread to simulate an LCD */
- rt_hw_sdl_start();
-#endif /* RT_USING_RTGUI */
-
#ifdef _WIN32
rt_thread_idle_sethook(rt_hw_win32_low_cpu);
#endif
diff --git a/bsp/simulator/drivers/sdl_fb.c b/bsp/simulator/drivers/sdl_fb.c
index d7ebbc8245..78bca6f07f 100755
--- a/bsp/simulator/drivers/sdl_fb.c
+++ b/bsp/simulator/drivers/sdl_fb.c
@@ -152,8 +152,12 @@ static void sdlfb_hw_init(void)
#ifdef _WIN32
static HANDLE sdl_ok_event = NULL;
+
static DWORD WINAPI sdl_loop(LPVOID lpParam)
#else
+static pthread_mutex_t sdl_ok_mutex;
+static pthread_cond_t sdl_ok_event;
+
static void *sdl_loop(void *lpParam)
#endif
{
@@ -167,14 +171,19 @@ static void *sdl_loop(void *lpParam)
/* set the getchar without buffer */
sigfillset(&sigmask);
pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask);
+ pthread_mutex_lock(&sdl_ok_mutex);
#endif
sdlfb_hw_init();
device = rt_device_find("sdl");
+ RT_ASSERT(device);
rtgui_graphic_set_device(device);
#ifdef _WIN32
SetEvent(sdl_ok_event);
+#else
+ pthread_cond_signal(&sdl_ok_event);
+ pthread_mutex_unlock(&sdl_ok_mutex);
#endif
/* handle SDL event */
while (!quit)
@@ -338,11 +347,20 @@ void rt_hw_sdl_start(void)
/* Linux */
pthread_t pid;
int res;
+
+ pthread_mutex_init(&sdl_ok_mutex, NULL);
+ pthread_cond_init(&sdl_ok_event, NULL);
+
res = pthread_create(&pid, NULL, &sdl_loop, NULL);
if (res)
{
printf("pthread create sdl thread faild, <%d>\n", res);
exit(EXIT_FAILURE);
}
+ pthread_mutex_lock(&sdl_ok_mutex);
+ pthread_cond_wait(&sdl_ok_event, &sdl_ok_mutex);
+
+ pthread_mutex_destroy(&sdl_ok_mutex);
+ pthread_cond_destroy(&sdl_ok_event);
#endif
}