summaryrefslogtreecommitdiff
path: root/apps/plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugin.c')
-rw-r--r--apps/plugin.c108
1 files changed, 21 insertions, 87 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 7bfa0e2a0f..6c018067ea 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -45,6 +45,7 @@
45#include "mp3data.h" 45#include "mp3data.h"
46#include "powermgmt.h" 46#include "powermgmt.h"
47#include "system.h" 47#include "system.h"
48#include "timer.h"
48#include "sound.h" 49#include "sound.h"
49#include "database.h" 50#include "database.h"
50#if (CONFIG_HWCODEC == MASNONE) 51#if (CONFIG_HWCODEC == MASNONE)
@@ -74,9 +75,6 @@ extern unsigned char pluginbuf[];
74/* for actual plugins only, not for codecs */ 75/* for actual plugins only, not for codecs */
75static bool plugin_loaded = false; 76static bool plugin_loaded = false;
76static int plugin_size = 0; 77static int plugin_size = 0;
77#ifndef SIMULATOR
78static void (*pfn_timer)(void) = NULL; /* user timer handler */
79#endif
80static void (*pfn_tsr_exit)(void) = NULL; /* TSR exit callback */ 78static void (*pfn_tsr_exit)(void) = NULL; /* TSR exit callback */
81 79
82static int plugin_test(int api_version, int model, int memsize); 80static int plugin_test(int api_version, int model, int memsize);
@@ -116,6 +114,14 @@ static const struct plugin_api rockbox_api = {
116 lcd_fillrect, 114 lcd_fillrect,
117 lcd_mono_bitmap_part, 115 lcd_mono_bitmap_part,
118 lcd_mono_bitmap, 116 lcd_mono_bitmap,
117#if LCD_DEPTH > 1
118 lcd_set_foreground,
119 lcd_get_foreground,
120 lcd_set_background,
121 lcd_get_background,
122 lcd_bitmap_part,
123 lcd_bitmap,
124#endif
119 lcd_putsxy, 125 lcd_putsxy,
120 lcd_puts_style, 126 lcd_puts_style,
121 lcd_puts_scroll_style, 127 lcd_puts_scroll_style,
@@ -126,6 +132,7 @@ static const struct plugin_api rockbox_api = {
126 scrollbar, 132 scrollbar,
127 checkbox, 133 checkbox,
128 font_get, 134 font_get,
135 font_getstringsize,
129#endif 136#endif
130 backlight_on, 137 backlight_on,
131 backlight_off, 138 backlight_off,
@@ -211,6 +218,9 @@ static const struct plugin_api rockbox_api = {
211#ifdef HAVE_ADJUSTABLE_CPU_FREQ 218#ifdef HAVE_ADJUSTABLE_CPU_FREQ
212 cpu_boost, 219 cpu_boost,
213#endif 220#endif
221 timer_register,
222 timer_unregister,
223 timer_set_period,
214#endif 224#endif
215 225
216 /* strings and memory */ 226 /* strings and memory */
@@ -220,6 +230,7 @@ static const struct plugin_api rockbox_api = {
220 strlen, 230 strlen,
221 strrchr, 231 strrchr,
222 strcmp, 232 strcmp,
233 strncmp,
223 strcasecmp, 234 strcasecmp,
224 strncasecmp, 235 strncasecmp,
225 memset, 236 memset,
@@ -289,6 +300,10 @@ static const struct plugin_api rockbox_api = {
289 &tagdb_fd, 300 &tagdb_fd,
290 &tagdb_initialized, 301 &tagdb_initialized,
291 tagdb_init, 302 tagdb_init,
303 /* runtime database */
304 &rundbheader,
305 &rundb_fd,
306 &rundb_initialized,
292 307
293 /* misc */ 308 /* misc */
294 srand, 309 srand,
@@ -299,14 +314,13 @@ static const struct plugin_api rockbox_api = {
299 set_time, 314 set_time,
300 plugin_get_buffer, 315 plugin_get_buffer,
301 plugin_get_audio_buffer, 316 plugin_get_audio_buffer,
302#ifndef SIMULATOR
303 plugin_register_timer,
304 plugin_unregister_timer,
305#endif
306 plugin_tsr, 317 plugin_tsr,
307#if defined(DEBUG) || defined(SIMULATOR) 318#if defined(DEBUG) || defined(SIMULATOR)
308 debugf, 319 debugf,
309#endif 320#endif
321#ifdef ROCKBOX_HAS_LOGF
322 logf,
323#endif
310 &global_settings, 324 &global_settings,
311 mp3info, 325 mp3info,
312 count_mp3_frames, 326 count_mp3_frames,
@@ -326,24 +340,6 @@ static const struct plugin_api rockbox_api = {
326 /* new stuff at the end, sort into place next time 340 /* new stuff at the end, sort into place next time
327 the API gets incompatible */ 341 the API gets incompatible */
328 342
329#ifdef ROCKBOX_HAS_LOGF
330 logf,
331#endif
332 &rundbheader,
333 &rundb_fd,
334 &rundb_initialized,
335 strncmp,
336#if LCD_DEPTH > 1
337 lcd_set_foreground,
338 lcd_get_foreground,
339 lcd_set_background,
340 lcd_get_background,
341 lcd_bitmap_part,
342 lcd_bitmap,
343#endif
344#ifdef HAVE_LCD_BITMAP
345 font_getstringsize,
346#endif
347}; 343};
348 344
349int plugin_load(const char* plugin, void* parameter) 345int plugin_load(const char* plugin, void* parameter)
@@ -486,68 +482,6 @@ void* plugin_get_audio_buffer(int* buffer_size)
486 return audiobuf; 482 return audiobuf;
487} 483}
488 484
489#ifndef SIMULATOR
490/* Register a periodic time callback, called every "cycles" CPU clocks.
491 Note that this function will be called in interrupt context! */
492int plugin_register_timer(int cycles, int prio, void (*timer_callback)(void))
493{
494 int phi = 0; /* bits for the prescaler */
495 int prescale = 1;
496
497 while (cycles > 0x10000)
498 { /* work out the smallest prescaler that makes it fit */
499 phi++;
500 prescale *= 2;
501 cycles /= 2;
502 }
503
504 if (prescale > 8 || cycles == 0 || prio < 1 || prio > 15)
505 return 0; /* error, we can't do such period, bad argument */
506
507 backlight_allow_timer(false); /* stop backlight from messing with the timer */
508#if CONFIG_CPU == SH7034
509 and_b(~0x10, &TSTR); /* Stop the timer 4 */
510 and_b(~0x10, &TSNC); /* No synchronization */
511 and_b(~0x10, &TMDR); /* Operate normally */
512
513 pfn_timer = timer_callback; /* install 2nd level ISR */
514
515 and_b(~0x01, &TSR4);
516 TIER4 = 0xF9; /* Enable GRA match interrupt */
517
518 GRA4 = (unsigned short)(cycles - 1);
519 TCR4 = 0x20 | phi; /* clear at GRA match, set prescaler */
520 IPRD = (IPRD & 0xFF0F) | prio << 4; /* interrupt priority */
521 or_b(0x10, &TSTR); /* start timer 4 */
522#else
523 pfn_timer = timer_callback;
524#endif
525 return cycles * prescale; /* return the actual period, in CPU clocks */
526}
527
528/* disable the user timer */
529void plugin_unregister_timer(void)
530{
531#if CONFIG_CPU == SH7034
532 and_b(~0x10, &TSTR); /* stop the timer 4 */
533 IPRD = (IPRD & 0xFF0F); /* disable interrupt */
534 pfn_timer = NULL;
535#endif
536 backlight_allow_timer(true);
537}
538
539#if CONFIG_CPU == SH7034
540/* interrupt handler for user timer */
541#pragma interrupt
542void IMIA4(void)
543{
544 if (pfn_timer != NULL)
545 pfn_timer(); /* call the user timer function */
546 and_b(~0x01, &TSR4); /* clear the interrupt */
547}
548#endif /* CONFIG_CPU == SH7034 */
549#endif /* #ifndef SIMULATOR */
550
551/* The plugin wants to stay resident after leaving its main function, e.g. 485/* The plugin wants to stay resident after leaving its main function, e.g.
552 runs from timer or own thread. The callback is registered to later 486 runs from timer or own thread. The callback is registered to later
553 instruct it to free its resources before a new plugin gets loaded. */ 487 instruct it to free its resources before a new plugin gets loaded. */