diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
commit | 513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch) | |
tree | 10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/pdbox.c | |
parent | 95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff) | |
download | rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip |
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/pdbox.c')
-rw-r--r-- | apps/plugins/pdbox/pdbox.c | 314 |
1 files changed, 314 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/pdbox.c b/apps/plugins/pdbox/pdbox.c new file mode 100644 index 0000000000..9407849352 --- /dev/null +++ b/apps/plugins/pdbox/pdbox.c | |||
@@ -0,0 +1,314 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 Wincent Balin | ||
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 "plugin.h" | ||
23 | #include "pdbox.h" | ||
24 | |||
25 | /* Welcome to the PDBox plugin */ | ||
26 | PLUGIN_HEADER | ||
27 | PLUGIN_IRAM_DECLARE | ||
28 | |||
29 | /* Quit flag. */ | ||
30 | bool quit = false; | ||
31 | |||
32 | /* Thread IDs. */ | ||
33 | unsigned int core_thread_id; | ||
34 | unsigned int gui_thread_id; | ||
35 | |||
36 | /* Stacks for threads. */ | ||
37 | #define STACK_SIZE 16384 | ||
38 | uint32_t core_stack[STACK_SIZE / sizeof(uint32_t)]; | ||
39 | uint32_t gui_stack[STACK_SIZE / sizeof(uint32_t)]; | ||
40 | |||
41 | |||
42 | /* Core thread */ | ||
43 | void core_thread(void) | ||
44 | { | ||
45 | struct datagram ping; | ||
46 | |||
47 | /* Main loop */ | ||
48 | while(!quit) | ||
49 | { | ||
50 | /* Wait for request. */ | ||
51 | while(!RECEIVE_TO_CORE(&ping)) | ||
52 | rb->yield(); | ||
53 | |||
54 | if(memcmp("Ping!", ping.data, ping.size) == 0) | ||
55 | { | ||
56 | SEND_FROM_CORE("Pong!"); | ||
57 | break; | ||
58 | } | ||
59 | |||
60 | rb->yield(); | ||
61 | } | ||
62 | |||
63 | rb->thread_exit(); | ||
64 | } | ||
65 | |||
66 | /* GUI thread */ | ||
67 | void gui_thread(void) | ||
68 | { | ||
69 | struct datagram pong; | ||
70 | |||
71 | /* GUI loop */ | ||
72 | while(!quit) | ||
73 | { | ||
74 | /* Send ping to the core. */ | ||
75 | SEND_TO_CORE("Ping!"); | ||
76 | rb->splash(HZ, "Sent ping."); | ||
77 | |||
78 | /* Wait for answer. */ | ||
79 | while(!RECEIVE_FROM_CORE(&pong)) | ||
80 | rb->yield(); | ||
81 | |||
82 | /* If got a pong -- everything allright. */ | ||
83 | if(memcmp("Pong!", pong.data, pong.size) == 0) | ||
84 | { | ||
85 | rb->splash(HZ, "Got pong!"); | ||
86 | quit = true; | ||
87 | break; | ||
88 | } | ||
89 | |||
90 | rb->yield(); | ||
91 | } | ||
92 | |||
93 | rb->thread_exit(); | ||
94 | } | ||
95 | |||
96 | |||
97 | /* Plug-in entry point */ | ||
98 | enum plugin_status plugin_start(const void* parameter) | ||
99 | { | ||
100 | PLUGIN_IRAM_INIT(rb) | ||
101 | |||
102 | size_t mem_size; | ||
103 | void* mem_pool; | ||
104 | |||
105 | /* Get the file name. */ | ||
106 | const char* filename = (const char*) parameter; | ||
107 | |||
108 | #if 0 | ||
109 | /* Allocate memory; check it's size; add to the pool. */ | ||
110 | mem_pool = rb->plugin_get_audio_buffer(&mem_size); | ||
111 | if(mem_size < MIN_MEM_SIZE) | ||
112 | { | ||
113 | rb->splash(HZ, "Not enough memory!"); | ||
114 | return PLUGIN_ERROR; | ||
115 | } | ||
116 | add_pool(mem_pool, mem_size); | ||
117 | #endif | ||
118 | |||
119 | /* Initialze net. */ | ||
120 | net_init(); | ||
121 | |||
122 | /* Start threads. */ | ||
123 | core_thread_id = | ||
124 | rb->create_thread(&core_thread, | ||
125 | core_stack, | ||
126 | sizeof(core_stack), | ||
127 | 0, /* FIXME Which flags? */ | ||
128 | "PD core" | ||
129 | IF_PRIO(, MAX(PRIORITY_USER_INTERFACE / 2, | ||
130 | PRIORITY_REALTIME + 1)) | ||
131 | IF_COP(, COP)); | ||
132 | gui_thread_id = | ||
133 | rb->create_thread(&gui_thread, | ||
134 | gui_stack, | ||
135 | sizeof(gui_stack), | ||
136 | 0, /* FIXME Which flags? */ | ||
137 | "PD GUI" | ||
138 | IF_PRIO(, PRIORITY_USER_INTERFACE) | ||
139 | IF_COP(, CPU)); | ||
140 | |||
141 | /* If having an error creating threads, bail out. */ | ||
142 | if(core_thread_id == 0 || gui_thread_id == 0) | ||
143 | return PLUGIN_ERROR; | ||
144 | |||
145 | /* Wait for quit flag. */ | ||
146 | while(!quit) | ||
147 | rb->yield(); | ||
148 | |||
149 | /* Wait for threads to complete. */ | ||
150 | rb->thread_wait(gui_thread_id); | ||
151 | rb->thread_wait(core_thread_id); | ||
152 | |||
153 | /* Destroy net. */ | ||
154 | net_destroy(); | ||
155 | |||
156 | return PLUGIN_OK; | ||
157 | } | ||
158 | /*************************************************************************** | ||
159 | * __________ __ ___. | ||
160 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
161 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
162 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
163 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
164 | * \/ \/ \/ \/ \/ | ||
165 | * $Id$ | ||
166 | * | ||
167 | * Copyright (C) 2009 Wincent Balin | ||
168 | * | ||
169 | * This program is free software; you can redistribute it and/or | ||
170 | * modify it under the terms of the GNU General Public License | ||
171 | * as published by the Free Software Foundation; either version 2 | ||
172 | * of the License, or (at your option) any later version. | ||
173 | * | ||
174 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
175 | * KIND, either express or implied. | ||
176 | * | ||
177 | ****************************************************************************/ | ||
178 | |||
179 | #include "plugin.h" | ||
180 | #include "pdbox.h" | ||
181 | |||
182 | /* Welcome to the PDBox plugin */ | ||
183 | PLUGIN_HEADER | ||
184 | PLUGIN_IRAM_DECLARE | ||
185 | |||
186 | /* Quit flag. */ | ||
187 | bool quit = false; | ||
188 | |||
189 | /* Thread IDs. */ | ||
190 | unsigned int core_thread_id; | ||
191 | unsigned int gui_thread_id; | ||
192 | |||
193 | /* Stacks for threads. */ | ||
194 | #define STACK_SIZE 16384 | ||
195 | uint32_t core_stack[STACK_SIZE / sizeof(uint32_t)]; | ||
196 | uint32_t gui_stack[STACK_SIZE / sizeof(uint32_t)]; | ||
197 | |||
198 | |||
199 | /* Core thread */ | ||
200 | void core_thread(void) | ||
201 | { | ||
202 | struct datagram ping; | ||
203 | |||
204 | /* Main loop */ | ||
205 | while(!quit) | ||
206 | { | ||
207 | /* Wait for request. */ | ||
208 | while(!RECEIVE_TO_CORE(&ping)) | ||
209 | rb->yield(); | ||
210 | |||
211 | if(memcmp("Ping!", ping.data, ping.size) == 0) | ||
212 | { | ||
213 | SEND_FROM_CORE("Pong!"); | ||
214 | break; | ||
215 | } | ||
216 | |||
217 | rb->yield(); | ||
218 | } | ||
219 | |||
220 | rb->thread_exit(); | ||
221 | } | ||
222 | |||
223 | /* GUI thread */ | ||
224 | void gui_thread(void) | ||
225 | { | ||
226 | struct datagram pong; | ||
227 | |||
228 | /* GUI loop */ | ||
229 | while(!quit) | ||
230 | { | ||
231 | /* Send ping to the core. */ | ||
232 | SEND_TO_CORE("Ping!"); | ||
233 | rb->splash(HZ, "Sent ping."); | ||
234 | |||
235 | /* Wait for answer. */ | ||
236 | while(!RECEIVE_FROM_CORE(&pong)) | ||
237 | rb->yield(); | ||
238 | |||
239 | /* If got a pong -- everything allright. */ | ||
240 | if(memcmp("Pong!", pong.data, pong.size) == 0) | ||
241 | { | ||
242 | rb->splash(HZ, "Got pong!"); | ||
243 | quit = true; | ||
244 | break; | ||
245 | } | ||
246 | |||
247 | rb->yield(); | ||
248 | } | ||
249 | |||
250 | rb->thread_exit(); | ||
251 | } | ||
252 | |||
253 | |||
254 | /* Plug-in entry point */ | ||
255 | enum plugin_status plugin_start(const void* parameter) | ||
256 | { | ||
257 | PLUGIN_IRAM_INIT(rb) | ||
258 | |||
259 | size_t mem_size; | ||
260 | void* mem_pool; | ||
261 | |||
262 | /* Get the file name. */ | ||
263 | const char* filename = (const char*) parameter; | ||
264 | |||
265 | #if 0 | ||
266 | /* Allocate memory; check it's size; add to the pool. */ | ||
267 | mem_pool = rb->plugin_get_audio_buffer(&mem_size); | ||
268 | if(mem_size < MIN_MEM_SIZE) | ||
269 | { | ||
270 | rb->splash(HZ, "Not enough memory!"); | ||
271 | return PLUGIN_ERROR; | ||
272 | } | ||
273 | add_pool(mem_pool, mem_size); | ||
274 | #endif | ||
275 | |||
276 | /* Initialze net. */ | ||
277 | net_init(); | ||
278 | |||
279 | /* Start threads. */ | ||
280 | core_thread_id = | ||
281 | rb->create_thread(&core_thread, | ||
282 | core_stack, | ||
283 | sizeof(core_stack), | ||
284 | 0, /* FIXME Which flags? */ | ||
285 | "PD core" | ||
286 | IF_PRIO(, MAX(PRIORITY_USER_INTERFACE / 2, | ||
287 | PRIORITY_REALTIME + 1)) | ||
288 | IF_COP(, COP)); | ||
289 | gui_thread_id = | ||
290 | rb->create_thread(&gui_thread, | ||
291 | gui_stack, | ||
292 | sizeof(gui_stack), | ||
293 | 0, /* FIXME Which flags? */ | ||
294 | "PD GUI" | ||
295 | IF_PRIO(, PRIORITY_USER_INTERFACE) | ||
296 | IF_COP(, CPU)); | ||
297 | |||
298 | /* If having an error creating threads, bail out. */ | ||
299 | if(core_thread_id == 0 || gui_thread_id == 0) | ||
300 | return PLUGIN_ERROR; | ||
301 | |||
302 | /* Wait for quit flag. */ | ||
303 | while(!quit) | ||
304 | rb->yield(); | ||
305 | |||
306 | /* Wait for threads to complete. */ | ||
307 | rb->thread_wait(gui_thread_id); | ||
308 | rb->thread_wait(core_thread_id); | ||
309 | |||
310 | /* Destroy net. */ | ||
311 | net_destroy(); | ||
312 | |||
313 | return PLUGIN_OK; | ||
314 | } | ||