diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-05-15 21:02:47 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-05-15 21:02:47 +0000 |
commit | 3d0cee8abbaf764958743e8a7851eee94e60a913 (patch) | |
tree | a96b1ec825003a71643a7da4707c300f64824f82 /uisimulator/sdl/kernel-sdl.c | |
parent | dcf442e61f21fb2aef5ce7de0547f733557b156e (diff) | |
download | rockbox-3d0cee8abbaf764958743e8a7851eee94e60a913.tar.gz rockbox-3d0cee8abbaf764958743e8a7851eee94e60a913.zip |
- Move uisimulator/sdl/*.[ch] into the target tree, under firmware/target/hosted/sdl, uisdl.c is split up across button-sdl.c and system-sdl.c.
- Refactor the program startup. main() is now in main.c like on target, and the implicit application thread will now act as our main thread (previously a separate one was created for this in thread initialization).
This is part of Rockbox as an application and is the first step to make an application port from the uisimulator. In a further step the sim bits from the sdl build will be separated out.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26065 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/sdl/kernel-sdl.c')
-rw-r--r-- | uisimulator/sdl/kernel-sdl.c | 155 |
1 files changed, 0 insertions, 155 deletions
diff --git a/uisimulator/sdl/kernel-sdl.c b/uisimulator/sdl/kernel-sdl.c deleted file mode 100644 index 3288a6f97a..0000000000 --- a/uisimulator/sdl/kernel-sdl.c +++ /dev/null | |||
@@ -1,155 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Felix Arends | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdlib.h> | ||
23 | #include <SDL.h> | ||
24 | #include <SDL_thread.h> | ||
25 | #include "memory.h" | ||
26 | #include "system-sdl.h" | ||
27 | #include "uisdl.h" | ||
28 | #include "kernel.h" | ||
29 | #include "thread-sdl.h" | ||
30 | #include "thread.h" | ||
31 | #include "debug.h" | ||
32 | |||
33 | static SDL_TimerID tick_timer_id; | ||
34 | long start_tick; | ||
35 | |||
36 | /* Condition to signal that "interrupts" may proceed */ | ||
37 | static SDL_cond *sim_thread_cond; | ||
38 | /* Mutex to serialize changing levels and exclude other threads while | ||
39 | * inside a handler */ | ||
40 | static SDL_mutex *sim_irq_mtx; | ||
41 | static int interrupt_level = HIGHEST_IRQ_LEVEL; | ||
42 | static int handlers_pending = 0; | ||
43 | static int status_reg = 0; | ||
44 | |||
45 | /* Nescessary logic: | ||
46 | * 1) All threads must pass unblocked | ||
47 | * 2) Current handler must always pass unblocked | ||
48 | * 3) Threads must be excluded when irq routine is running | ||
49 | * 4) No more than one handler routine should execute at a time | ||
50 | */ | ||
51 | int set_irq_level(int level) | ||
52 | { | ||
53 | SDL_LockMutex(sim_irq_mtx); | ||
54 | |||
55 | int oldlevel = interrupt_level; | ||
56 | |||
57 | if (status_reg == 0 && level == 0 && oldlevel != 0) | ||
58 | { | ||
59 | /* Not in a handler and "interrupts" are being reenabled */ | ||
60 | if (handlers_pending > 0) | ||
61 | SDL_CondSignal(sim_thread_cond); | ||
62 | } | ||
63 | |||
64 | interrupt_level = level; /* save new level */ | ||
65 | |||
66 | SDL_UnlockMutex(sim_irq_mtx); | ||
67 | return oldlevel; | ||
68 | } | ||
69 | |||
70 | void sim_enter_irq_handler(void) | ||
71 | { | ||
72 | SDL_LockMutex(sim_irq_mtx); | ||
73 | handlers_pending++; | ||
74 | |||
75 | if(interrupt_level != 0) | ||
76 | { | ||
77 | /* "Interrupts" are disabled. Wait for reenable */ | ||
78 | SDL_CondWait(sim_thread_cond, sim_irq_mtx); | ||
79 | } | ||
80 | |||
81 | status_reg = 1; | ||
82 | } | ||
83 | |||
84 | void sim_exit_irq_handler(void) | ||
85 | { | ||
86 | if (--handlers_pending > 0) | ||
87 | SDL_CondSignal(sim_thread_cond); | ||
88 | |||
89 | status_reg = 0; | ||
90 | SDL_UnlockMutex(sim_irq_mtx); | ||
91 | } | ||
92 | |||
93 | bool sim_kernel_init(void) | ||
94 | { | ||
95 | sim_irq_mtx = SDL_CreateMutex(); | ||
96 | if (sim_irq_mtx == NULL) | ||
97 | { | ||
98 | fprintf(stderr, "Cannot create sim_handler_mtx\n"); | ||
99 | return false; | ||
100 | } | ||
101 | |||
102 | sim_thread_cond = SDL_CreateCond(); | ||
103 | if (sim_thread_cond == NULL) | ||
104 | { | ||
105 | fprintf(stderr, "Cannot create sim_thread_cond\n"); | ||
106 | return false; | ||
107 | } | ||
108 | |||
109 | return true; | ||
110 | } | ||
111 | |||
112 | void sim_kernel_shutdown(void) | ||
113 | { | ||
114 | SDL_RemoveTimer(tick_timer_id); | ||
115 | SDL_DestroyMutex(sim_irq_mtx); | ||
116 | SDL_DestroyCond(sim_thread_cond); | ||
117 | } | ||
118 | |||
119 | Uint32 tick_timer(Uint32 interval, void *param) | ||
120 | { | ||
121 | long new_tick; | ||
122 | |||
123 | (void) interval; | ||
124 | (void) param; | ||
125 | |||
126 | new_tick = (SDL_GetTicks() - start_tick) / (1000/HZ); | ||
127 | |||
128 | while(new_tick != current_tick) | ||
129 | { | ||
130 | sim_enter_irq_handler(); | ||
131 | |||
132 | /* Run through the list of tick tasks - increments tick | ||
133 | * on each iteration. */ | ||
134 | call_tick_tasks(); | ||
135 | |||
136 | sim_exit_irq_handler(); | ||
137 | } | ||
138 | |||
139 | return 1; | ||
140 | } | ||
141 | |||
142 | void tick_start(unsigned int interval_in_ms) | ||
143 | { | ||
144 | if (tick_timer_id != NULL) | ||
145 | { | ||
146 | SDL_RemoveTimer(tick_timer_id); | ||
147 | tick_timer_id = NULL; | ||
148 | } | ||
149 | else | ||
150 | { | ||
151 | start_tick = SDL_GetTicks(); | ||
152 | } | ||
153 | |||
154 | tick_timer_id = SDL_AddTimer(interval_in_ms, tick_timer, NULL); | ||
155 | } | ||