From b6896cf22f14c3a49fc749361e93dabc2d96a1d3 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Tue, 10 Apr 2012 16:18:56 +0200 Subject: [PATCH] SDL timer support This patch adds a Genode-specific SDL timer backend. Fixes #211. --- libports/lib/mk/sdl.mk | 14 ++-- libports/src/lib/sdl/timer/SDL_systimer.cc | 97 ++++++++++++++++++++++ 2 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 libports/src/lib/sdl/timer/SDL_systimer.cc diff --git a/libports/lib/mk/sdl.mk b/libports/lib/mk/sdl.mk index a7f57eca0..3feadfdc7 100644 --- a/libports/lib/mk/sdl.mk +++ b/libports/lib/mk/sdl.mk @@ -18,7 +18,9 @@ SHARED_LIB = yes # backends SRC_CC = SDL_genode_fb_video.cc \ - SDL_genode_fb_events.cc + SDL_genode_fb_events.cc \ + SDL_genodeaudio.cc \ + SDL_systimer.cc INC_DIR += $(REP_DIR)/include/SDL \ $(REP_DIR)/src/lib/sdl \ @@ -53,8 +55,8 @@ INC_DIR += $(SDL_DIR)/src/thread SRC_C += SDL_cpuinfo.c # timer subsystem -SRC_C += SDL_systimer.c \ - SDL_timer.c +SRC_C += SDL_timer.c +INC_DIR += $(SDL_DIR)/src/timer # video subsystem SRC_C += SDL_blit_0.c \ @@ -92,8 +94,8 @@ SRC_C += SDL_audio.c \ SDL_mixer_m68k.c \ SDL_mixer_MMX.c \ SDL_mixer_MMX_VC.c \ - SDL_wave.c \ - SDL_genodeaudio.c + SDL_wave.c + INC_DIR += $(SDL_DIR)/src/audio # file I/O subsystem @@ -116,6 +118,7 @@ CC_OPT_SDL_wave += -Wno-unused-but-set-variable # backend pathes vpath % $(REP_DIR)/src/lib/sdl vpath % $(REP_DIR)/src/lib/sdl/audio +vpath % $(REP_DIR)/src/lib/sdl/timer vpath % $(REP_DIR)/src/lib/sdl/video # contribution pathes @@ -130,7 +133,6 @@ vpath %.c $(SDL_DIR)/src/audio vpath %.c $(SDL_DIR)/src/thread vpath %.c $(SDL_DIR)/src/thread/pthread vpath %.c $(SDL_DIR)/src/timer -vpath %.c $(SDL_DIR)/src/timer/dummy vpath %.c $(SDL_DIR)/src/events vpath %.c $(SDL_DIR)/src/cpuinfo vpath %.c $(SDL_DIR)/src/file diff --git a/libports/src/lib/sdl/timer/SDL_systimer.cc b/libports/src/lib/sdl/timer/SDL_systimer.cc new file mode 100644 index 000000000..b022251a4 --- /dev/null +++ b/libports/src/lib/sdl/timer/SDL_systimer.cc @@ -0,0 +1,97 @@ +/* + * \brief Genode-specific timer backend + * \author Christian Prochaska + * \date 2012-03-13 + * + * based on the dummy SDL timer + */ + +/* + * Copyright (C) 2012 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +extern "C" { + +#include + +#include "SDL_config.h" + +#include "SDL_timer.h" +#include "SDL_timer_c.h" + + +void SDL_StartTicks(void) +{ +} + + +Uint32 SDL_GetTicks (void) +{ + printf("SDL_GetTicks() called - not implemented yet\n"); + return 0; +} + + +void SDL_Delay (Uint32 ms) +{ + usleep(ms*1000); +} + + +#include "SDL_thread.h" + + +/* Data to handle a single periodic alarm */ +static int timer_alive = 0; +static SDL_Thread *timer = NULL; + + +static int RunTimer(void *unused) +{ + while ( timer_alive ) { + if ( SDL_timer_running ) { + SDL_ThreadedTimerCheck(); + } + SDL_Delay(1); + } + return(0); +} + + +/* This is only called if the event thread is not running */ +int SDL_SYS_TimerInit(void) +{ + timer_alive = 1; + timer = SDL_CreateThread(RunTimer, NULL); + if ( timer == NULL ) + return(-1); + return(SDL_SetTimerThreaded(1)); +} + + +void SDL_SYS_TimerQuit(void) +{ + timer_alive = 0; + if ( timer ) { + SDL_WaitThread(timer, NULL); + timer = NULL; + } +} + + +int SDL_SYS_StartTimer(void) +{ + SDL_SetError("Internal logic error: threaded timer in use"); + return(-1); +} + + +void SDL_SYS_StopTimer(void) +{ + return; +} + +}