1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id: timer.h 13806 2007-07-06 21:36:32Z jethead71 $
10 * Copyright (C) 2005 Kévin Ferrare
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 #include <SDL_timer.h>
23 static int timer_prio
= -1;
24 void (*global_timer_callback
)(void);
27 Uint32
SDL_timer_callback(Uint32 interval
, void *param
){
29 global_timer_callback();
33 #define cycles_to_miliseconds(cycles) \
34 ((int)((1000*cycles)/TIMER_FREQ))
36 bool timer_register(int reg_prio
, void (*unregister_callback
)(void),
37 long cycles
, int int_prio
, void (*timer_callback
)(void))
39 (void)int_prio
;/* interrupt priority not used */
40 (void)unregister_callback
;
41 if (reg_prio
<= timer_prio
|| cycles
== 0)
44 global_timer_callback
=timer_callback
;
45 timerId
=SDL_AddTimer(cycles_to_miliseconds(cycles
), SDL_timer_callback
, 0);
49 bool timer_set_period(long cycles
)
51 SDL_RemoveTimer (timerId
);
52 timerId
=SDL_AddTimer(cycles_to_miliseconds(cycles
), SDL_timer_callback
, 0);
56 void timer_unregister(void)
58 SDL_RemoveTimer (timerId
);