Include divide-by-zero handling within plugins and codecs for ARM processors.
[kugel-rb.git] / apps / plugin.c
blob1e86b4d07e8d9ee6fdbecd10af5f2376c6325d06
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "plugin.h"
22 #include <ctype.h>
23 #include <string.h>
24 #include <sprintf.h>
25 #include <stdlib.h>
26 #include "debug.h"
27 #include "i2c.h"
28 #include "lang.h"
29 #include "led.h"
30 #include "keyboard.h"
31 #include "buffer.h"
32 #include "backlight.h"
33 #include "sound_menu.h"
34 #include "mp3data.h"
35 #include "powermgmt.h"
36 #include "splash.h"
37 #include "logf.h"
38 #include "option_select.h"
39 #include "talk.h"
40 #include "version.h"
41 #include "storage.h"
43 #if CONFIG_CHARGING
44 #include "power.h"
45 #endif
47 #ifdef HAVE_LCD_BITMAP
48 #include "scrollbar.h"
49 #include "peakmeter.h"
50 #include "bmp.h"
51 #include "bidi.h"
52 #endif
54 #ifdef SIMULATOR
55 #define PREFIX(_x_) sim_ ## _x_
56 #else
57 #define PREFIX
58 #endif
60 #ifdef SIMULATOR
61 static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE];
62 void *sim_plugin_load(char *plugin, void **pd);
63 void sim_plugin_close(void *pd);
64 void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int));
65 void sim_lcd_ex_update_rect(int x, int y, int width, int height);
66 #else
67 #define sim_plugin_close(x)
68 extern unsigned char pluginbuf[];
69 #include "bitswap.h"
70 #endif
72 /* for actual plugins only, not for codecs */
73 static bool plugin_loaded = false;
74 static int plugin_size = 0;
75 static bool (*pfn_tsr_exit)(bool reenter) = NULL; /* TSR exit callback */
76 static char current_plugin[MAX_PATH];
78 char *plugin_get_current_filename(void);
80 static const struct plugin_api rockbox_api = {
82 /* lcd */
83 lcd_set_contrast,
84 lcd_update,
85 lcd_clear_display,
86 lcd_getstringsize,
87 lcd_putsxy,
88 lcd_puts,
89 lcd_puts_scroll,
90 lcd_stop_scroll,
91 #ifdef HAVE_LCD_CHARCELLS
92 lcd_define_pattern,
93 lcd_get_locked_pattern,
94 lcd_unlock_pattern,
95 lcd_putc,
96 lcd_put_cursor,
97 lcd_remove_cursor,
98 lcd_icon,
99 lcd_double_height,
100 #else
101 &lcd_framebuffer[0][0],
102 lcd_update_rect,
103 lcd_set_drawmode,
104 lcd_get_drawmode,
105 lcd_setfont,
106 lcd_drawpixel,
107 lcd_drawline,
108 lcd_hline,
109 lcd_vline,
110 lcd_drawrect,
111 lcd_fillrect,
112 lcd_mono_bitmap_part,
113 lcd_mono_bitmap,
114 #if LCD_DEPTH > 1
115 lcd_set_foreground,
116 lcd_get_foreground,
117 lcd_set_background,
118 lcd_get_background,
119 lcd_bitmap_part,
120 lcd_bitmap,
121 lcd_get_backdrop,
122 lcd_set_backdrop,
123 #endif
124 #if LCD_DEPTH == 16
125 lcd_bitmap_transparent_part,
126 lcd_bitmap_transparent,
127 lcd_blit_yuv,
128 #if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
129 || defined(IRIVER_H10) || defined(COWON_D2)
130 lcd_yuv_set_options,
131 #endif
132 #elif (LCD_DEPTH < 4) && !defined(SIMULATOR)
133 lcd_blit_mono,
134 lcd_blit_grey_phase,
135 #endif /* LCD_DEPTH */
136 lcd_puts_style,
137 lcd_puts_scroll_style,
138 #ifdef HAVE_LCD_INVERT
139 lcd_set_invert_display,
140 #endif /* HAVE_LCD_INVERT */
141 #if defined(HAVE_LCD_ENABLE) && defined(HAVE_LCD_COLOR)
142 lcd_set_enable_hook,
143 &button_queue,
144 #endif
145 bidi_l2v,
146 font_get_bits,
147 font_load,
148 font_get,
149 font_getstringsize,
150 font_get_width,
151 screen_clear_area,
152 gui_scrollbar_draw,
153 #endif /* HAVE_LCD_BITMAP */
154 get_codepage_name,
156 backlight_on,
157 backlight_off,
158 backlight_set_timeout,
159 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
160 backlight_set_brightness,
161 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
163 #if CONFIG_CHARGING
164 backlight_set_timeout_plugged,
165 #endif
166 is_backlight_on,
167 splash,
168 splashf,
170 #ifdef HAVE_REMOTE_LCD
171 /* remote lcd */
172 lcd_remote_set_contrast,
173 lcd_remote_clear_display,
174 lcd_remote_puts,
175 lcd_remote_puts_scroll,
176 lcd_remote_stop_scroll,
177 lcd_remote_set_drawmode,
178 lcd_remote_get_drawmode,
179 lcd_remote_setfont,
180 lcd_remote_getstringsize,
181 lcd_remote_drawpixel,
182 lcd_remote_drawline,
183 lcd_remote_hline,
184 lcd_remote_vline,
185 lcd_remote_drawrect,
186 lcd_remote_fillrect,
187 lcd_remote_mono_bitmap_part,
188 lcd_remote_mono_bitmap,
189 lcd_remote_putsxy,
190 lcd_remote_puts_style,
191 lcd_remote_puts_scroll_style,
192 &lcd_remote_framebuffer[0][0],
193 lcd_remote_update,
194 lcd_remote_update_rect,
196 remote_backlight_on,
197 remote_backlight_off,
198 remote_backlight_set_timeout,
199 #if CONFIG_CHARGING
200 remote_backlight_set_timeout_plugged,
201 #endif
202 #endif /* HAVE_REMOTE_LCD */
203 #if NB_SCREENS == 2
204 {&screens[SCREEN_MAIN], &screens[SCREEN_REMOTE]},
205 #else
206 {&screens[SCREEN_MAIN]},
207 #endif
208 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
209 lcd_remote_set_foreground,
210 lcd_remote_get_foreground,
211 lcd_remote_set_background,
212 lcd_remote_get_background,
213 lcd_remote_bitmap_part,
214 lcd_remote_bitmap,
215 #endif
216 viewport_set_defaults,
217 viewportmanager_set_statusbar,
219 /* list */
220 gui_synclist_init,
221 gui_synclist_set_nb_items,
222 gui_synclist_set_icon_callback,
223 gui_synclist_get_nb_items,
224 gui_synclist_get_sel_pos,
225 gui_synclist_draw,
226 gui_synclist_select_item,
227 gui_synclist_add_item,
228 gui_synclist_del_item,
229 gui_synclist_limit_scroll,
230 gui_synclist_do_button,
231 gui_synclist_set_title,
232 gui_syncyesno_run,
233 simplelist_info_init,
234 simplelist_show_list,
236 /* button */
237 button_get,
238 button_get_w_tmo,
239 button_status,
240 #ifdef HAVE_BUTTON_DATA
241 button_get_data,
242 #endif
243 button_clear_queue,
244 button_queue_count,
245 #ifdef HAS_BUTTON_HOLD
246 button_hold,
247 #endif
248 #ifdef HAVE_TOUCHSCREEN
249 touchscreen_set_mode,
250 #endif
252 #ifdef HAVE_BUTTON_LIGHT
253 buttonlight_set_timeout,
254 buttonlight_off,
255 buttonlight_on,
256 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
257 buttonlight_set_brightness,
258 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
259 #endif /* HAVE_BUTTON_LIGHT */
261 /* file */
262 (open_func)PREFIX(open),
263 PREFIX(close),
264 (read_func)PREFIX(read),
265 PREFIX(lseek),
266 (creat_func)PREFIX(creat),
267 (write_func)PREFIX(write),
268 PREFIX(remove),
269 PREFIX(rename),
270 PREFIX(ftruncate),
271 PREFIX(filesize),
272 fdprintf,
273 read_line,
274 settings_parseline,
275 storage_sleep,
276 storage_spin,
277 storage_spindown,
278 #if USING_STORAGE_CALLBACK
279 register_storage_idle_func,
280 unregister_storage_idle_func,
281 #endif /* USING_STORAGE_CALLBACK */
282 reload_directory,
283 create_numbered_filename,
284 file_exists,
286 /* dir */
287 opendir,
288 closedir,
289 readdir,
290 mkdir,
291 rmdir,
292 dir_exists,
294 /* kernel/ system */
295 PREFIX(sleep),
296 yield,
297 &current_tick,
298 default_event_handler,
299 default_event_handler_ex,
300 create_thread,
301 thread_exit,
302 thread_wait,
303 #if (CONFIG_CODEC == SWCODEC)
304 thread_thaw,
305 #ifdef HAVE_PRIORITY_SCHEDULING
306 thread_set_priority,
307 #endif
308 mutex_init,
309 mutex_lock,
310 mutex_unlock,
311 #endif
313 reset_poweroff_timer,
314 #ifndef SIMULATOR
315 system_memory_guard,
316 &cpu_frequency,
318 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
319 #ifdef CPU_BOOST_LOGGING
320 cpu_boost_,
321 #else
322 cpu_boost,
323 #endif
324 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
325 #endif /* !SIMULATOR */
326 #ifdef HAVE_SCHEDULER_BOOSTCTRL
327 trigger_cpu_boost,
328 cancel_cpu_boost,
329 #endif
330 #ifdef CACHE_FUNCTIONS_AS_CALL
331 flush_icache,
332 invalidate_icache,
333 #endif
334 timer_register,
335 timer_unregister,
336 timer_set_period,
338 queue_init,
339 queue_delete,
340 queue_post,
341 queue_wait_w_tmo,
342 #if CONFIG_CODEC == SWCODEC
343 queue_enable_queue_send,
344 queue_empty,
345 queue_wait,
346 queue_send,
347 queue_reply,
348 #endif
349 usb_acknowledge,
350 #ifdef RB_PROFILE
351 profile_thread,
352 profstop,
353 __cyg_profile_func_enter,
354 __cyg_profile_func_exit,
355 #endif
357 #ifdef SIMULATOR
358 /* special simulator hooks */
359 #if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
360 sim_lcd_ex_init,
361 sim_lcd_ex_update_rect,
362 #endif
363 #endif
365 /* strings and memory */
366 snprintf,
367 vsnprintf,
368 strcpy,
369 strncpy,
370 strlen,
371 strrchr,
372 strcmp,
373 strncmp,
374 strcasecmp,
375 strncasecmp,
376 memset,
377 memcpy,
378 memmove,
379 _ctype_,
380 atoi,
381 strchr,
382 strcat,
383 memchr,
384 memcmp,
385 strcasestr,
386 strtok_r,
387 /* unicode stuff */
388 utf8decode,
389 iso_decode,
390 utf16LEdecode,
391 utf16BEdecode,
392 utf8encode,
393 utf8length,
394 utf8seek,
396 /* sound */
397 sound_set,
398 sound_default,
399 sound_min,
400 sound_max,
401 sound_unit,
402 sound_val2phys,
403 #ifndef SIMULATOR
404 mp3_play_data,
405 mp3_play_pause,
406 mp3_play_stop,
407 mp3_is_playing,
408 #if CONFIG_CODEC != SWCODEC
409 bitswap,
410 #endif
411 #endif
412 #if CONFIG_CODEC == SWCODEC
413 &audio_master_sampr_list[0],
414 &hw_freq_sampr[0],
415 pcm_apply_settings,
416 pcm_play_data,
417 pcm_play_stop,
418 pcm_set_frequency,
419 pcm_is_playing,
420 pcm_is_paused,
421 pcm_play_pause,
422 pcm_get_bytes_waiting,
423 pcm_calculate_peaks,
424 pcm_play_lock,
425 pcm_play_unlock,
426 #ifdef HAVE_RECORDING
427 &rec_freq_sampr[0],
428 pcm_init_recording,
429 pcm_close_recording,
430 pcm_record_data,
431 pcm_record_more,
432 pcm_stop_recording,
433 pcm_calculate_rec_peaks,
434 audio_set_recording_gain,
435 #endif /* HAVE_RECORDING */
436 #if INPUT_SRC_CAPS != 0
437 audio_set_output_source,
438 audio_set_input_source,
439 #endif
440 dsp_set_crossfeed,
441 dsp_set_eq,
442 dsp_dither_enable,
443 dsp_configure,
444 dsp_process,
445 #endif /* CONFIG_CODEC == SWCODEC */
447 /* playback control */
448 playlist_amount,
449 playlist_resume,
450 playlist_start,
451 PREFIX(audio_play),
452 audio_stop,
453 audio_pause,
454 audio_resume,
455 audio_next,
456 audio_prev,
457 audio_ff_rewind,
458 audio_next_track,
459 audio_status,
460 audio_has_changed_track,
461 audio_current_track,
462 audio_flush_and_reload_tracks,
463 audio_get_file_pos,
464 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
465 mpeg_get_last_header,
466 #endif
467 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
468 (CONFIG_CODEC == SWCODEC)
469 sound_set_pitch,
470 #endif
472 #if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
473 /* MAS communication */
474 mas_readmem,
475 mas_writemem,
476 mas_readreg,
477 mas_writereg,
478 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
479 mas_codec_writereg,
480 mas_codec_readreg,
481 i2c_begin,
482 i2c_end,
483 i2c_write,
484 #endif
485 #endif /* !SIMULATOR && CONFIG_CODEC != SWCODEC */
487 /* menu */
488 do_menu,
489 /* statusbars */
490 &statusbars,
491 gui_syncstatusbar_draw,
492 /* options */
493 get_settings_list,
494 find_setting,
495 option_screen,
496 set_option,
497 set_bool_options,
498 set_int,
499 set_bool,
500 #ifdef HAVE_LCD_COLOR
501 set_color,
502 #endif
504 /* action handling */
505 get_custom_action,
506 get_action,
507 action_userabort,
509 /* power */
510 battery_level,
511 battery_level_safe,
512 battery_time,
513 #ifndef SIMULATOR
514 battery_voltage,
515 #endif
516 #if CONFIG_CHARGING
517 charger_inserted,
518 # if CONFIG_CHARGING == CHARGING_MONITOR
519 charging_state,
520 # endif
521 #endif
522 #ifdef HAVE_USB_POWER
523 usb_powered,
524 #endif
526 /* misc */
527 srand,
528 rand,
529 (qsort_func)qsort,
530 kbd_input,
531 get_time,
532 set_time,
533 #if CONFIG_RTC
534 mktime,
535 #endif
536 plugin_get_buffer,
537 plugin_get_audio_buffer,
538 plugin_tsr,
539 plugin_get_current_filename,
540 #ifdef PLUGIN_USE_IRAM
541 plugin_iram_init,
542 #endif
543 #if defined(DEBUG) || defined(SIMULATOR)
544 debugf,
545 #endif
546 #ifdef ROCKBOX_HAS_LOGF
547 _logf,
548 #endif
549 &global_settings,
550 &global_status,
551 talk_disable,
552 #if CONFIG_CODEC == SWCODEC
553 codec_thread_do_callback,
554 codec_load_file,
555 get_codec_filename,
556 get_metadata,
557 #endif
558 mp3info,
559 count_mp3_frames,
560 create_xing_header,
561 find_next_frame,
562 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
563 peak_meter_scale_value,
564 peak_meter_set_use_dbfs,
565 peak_meter_get_use_dbfs,
566 #endif
567 #ifdef HAVE_LCD_BITMAP
568 read_bmp_file,
569 screen_dump_set_hook,
570 #endif
571 show_logo,
572 tree_get_context,
573 set_current_file,
574 set_dirfilter,
576 #ifdef HAVE_WHEEL_POSITION
577 wheel_status,
578 wheel_send_events,
579 #endif
581 #ifdef IRIVER_H100_SERIES
582 /* Routines for the iriver_flash -plugin. */
583 detect_original_firmware,
584 detect_flashed_ramimage,
585 detect_flashed_romimage,
586 #endif
587 led,
588 #if (CONFIG_CODEC == SWCODEC)
589 bufopen,
590 bufalloc,
591 bufclose,
592 bufseek,
593 bufadvance,
594 bufread,
595 bufgetdata,
596 bufgettail,
597 bufcuttail,
599 buf_get_offset,
600 buf_handle_offset,
601 buf_request_buffer_handle,
602 buf_set_base_handle,
603 buf_used,
604 #endif
606 #ifdef HAVE_TAGCACHE
607 tagcache_search,
608 tagcache_search_set_uniqbuf,
609 tagcache_search_add_filter,
610 tagcache_get_next,
611 tagcache_retrieve,
612 tagcache_search_finish,
613 tagcache_get_numeric,
614 #endif
616 #ifdef HAVE_ALBUMART
617 find_albumart,
618 search_albumart_files,
619 #endif
621 #ifdef HAVE_SEMAPHORE_OBJECTS
622 semaphore_init,
623 semaphore_wait,
624 semaphore_release,
625 #endif
627 appsversion,
628 /* new stuff at the end, sort into place next time
629 the API gets incompatible */
630 #ifdef CPU_ARM
631 __div0,
632 #endif
635 int plugin_load(const char* plugin, const void* parameter)
637 int rc;
638 bool oldbars;
639 struct plugin_header *hdr;
640 #ifdef SIMULATOR
641 void *pd;
642 #else /* !SIMULATOR */
643 int fd;
644 ssize_t readsize;
645 #if NUM_CORES > 1
646 unsigned my_core;
647 #endif
648 #endif /* !SIMULATOR */
650 #if LCD_DEPTH > 1
651 fb_data* old_backdrop;
652 #endif
654 if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
656 if (pfn_tsr_exit(!strcmp(current_plugin, plugin)) == false )
658 /* not allowing another plugin to load */
659 return PLUGIN_OK;
661 pfn_tsr_exit = NULL;
662 plugin_loaded = false;
665 splash(0, ID2P(LANG_WAIT));
666 strcpy(current_plugin, plugin);
668 #ifdef SIMULATOR
669 hdr = sim_plugin_load((char *)plugin, &pd);
670 if (pd == NULL) {
671 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
672 return -1;
674 if (hdr == NULL
675 || hdr->magic != PLUGIN_MAGIC
676 || hdr->target_id != TARGET_ID) {
677 sim_plugin_close(pd);
678 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
679 return -1;
681 if (hdr->api_version > PLUGIN_API_VERSION
682 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
683 sim_plugin_close(pd);
684 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
685 return -1;
687 #else
688 fd = open(plugin, O_RDONLY);
689 if (fd < 0) {
690 splashf(HZ*2, str(LANG_PLUGIN_CANT_OPEN), plugin);
691 return fd;
693 #if NUM_CORES > 1
694 /* Make sure COP cache is flushed and invalidated before loading */
695 my_core = switch_core(CURRENT_CORE ^ 1);
696 invalidate_icache();
697 switch_core(my_core);
698 #endif
700 readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE);
701 close(fd);
703 if (readsize < 0) {
704 splashf(HZ*2, str(LANG_READ_FAILED), plugin);
705 return -1;
707 hdr = (struct plugin_header *)pluginbuf;
709 if ((unsigned)readsize <= sizeof(struct plugin_header)
710 || hdr->magic != PLUGIN_MAGIC
711 || hdr->target_id != TARGET_ID
712 || hdr->load_addr != pluginbuf
713 || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) {
714 splash(HZ*2, str(LANG_PLUGIN_WRONG_MODEL));
715 return -1;
717 if (hdr->api_version > PLUGIN_API_VERSION
718 || hdr->api_version < PLUGIN_MIN_API_VERSION) {
719 splash(HZ*2, str(LANG_PLUGIN_WRONG_VERSION));
720 return -1;
722 plugin_size = hdr->end_addr - pluginbuf;
724 /* zero out bss area only, above guards end of pluginbuf */
725 if (plugin_size > readsize)
726 memset(pluginbuf + readsize, 0, plugin_size - readsize);
727 #endif
729 *(hdr->api) = &rockbox_api;
730 plugin_loaded = true;
733 #if defined HAVE_LCD_BITMAP && LCD_DEPTH > 1
734 old_backdrop = lcd_get_backdrop();
735 #endif
736 lcd_clear_display();
737 lcd_update();
739 #ifdef HAVE_REMOTE_LCD
740 lcd_remote_clear_display();
741 lcd_remote_update();
742 #endif
744 invalidate_icache();
745 oldbars = viewportmanager_set_statusbar(false);
747 rc = hdr->entry_point(parameter);
749 viewportmanager_set_statusbar(true);
751 button_clear_queue();
753 #ifdef HAVE_LCD_BITMAP
754 #if LCD_DEPTH > 1
755 lcd_set_backdrop(old_backdrop);
756 #ifdef HAVE_LCD_COLOR
757 lcd_set_drawinfo(DRMODE_SOLID, global_settings.fg_color,
758 global_settings.bg_color);
759 #else
760 lcd_set_drawinfo(DRMODE_SOLID, LCD_DEFAULT_FG, LCD_DEFAULT_BG);
761 #endif
762 #else /* LCD_DEPTH == 1 */
763 lcd_set_drawmode(DRMODE_SOLID);
764 #endif /* LCD_DEPTH */
765 #endif /* HAVE_LCD_BITMAP */
767 lcd_clear_display();
768 lcd_update();
770 #ifdef HAVE_REMOTE_LCD
771 #if LCD_REMOTE_DEPTH > 1
772 lcd_remote_set_drawinfo(DRMODE_SOLID, LCD_REMOTE_DEFAULT_FG,
773 LCD_REMOTE_DEFAULT_BG);
774 #else
775 lcd_remote_set_drawmode(DRMODE_SOLID);
776 #endif
777 lcd_remote_clear_display();
780 lcd_remote_update();
783 #endif
784 viewportmanager_set_statusbar(oldbars);
785 if (pfn_tsr_exit == NULL)
786 plugin_loaded = false;
788 sim_plugin_close(pd);
790 switch (rc) {
791 case PLUGIN_OK:
792 break;
794 case PLUGIN_USB_CONNECTED:
795 return PLUGIN_USB_CONNECTED;
797 default:
798 splash(HZ*2, str(LANG_PLUGIN_ERROR));
799 break;
802 return PLUGIN_OK;
805 /* Returns a pointer to the portion of the plugin buffer that is not already
806 being used. If no plugin is loaded, returns the entire plugin buffer */
807 void* plugin_get_buffer(size_t *buffer_size)
809 int buffer_pos;
811 if (plugin_loaded)
813 if (plugin_size >= PLUGIN_BUFFER_SIZE)
814 return NULL;
816 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
817 buffer_pos = plugin_size;
819 else
821 *buffer_size = PLUGIN_BUFFER_SIZE;
822 buffer_pos = 0;
825 return &pluginbuf[buffer_pos];
828 /* Returns a pointer to the mp3 buffer.
829 Playback gets stopped, to avoid conflicts.
830 Talk buffer is stolen as well.
832 void* plugin_get_audio_buffer(size_t *buffer_size)
834 #if CONFIG_CODEC == SWCODEC
835 return audio_get_buffer(true, buffer_size);
836 #else
837 audio_stop();
838 talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
839 *buffer_size = audiobufend - audiobuf;
840 return audiobuf;
841 #endif
844 #ifdef PLUGIN_USE_IRAM
845 /* Initializes plugin IRAM */
846 void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
847 char *iedata, size_t iedata_size)
849 /* We need to stop audio playback in order to use codec IRAM */
850 audio_hard_stop();
851 memcpy(iramstart, iramcopy, iram_size);
852 memset(iedata, 0, iedata_size);
853 memset(iramcopy, 0, iram_size);
854 #if NUM_CORES > 1
855 /* writeback cleared iedata and iramcopy areas */
856 flush_icache();
857 #endif
859 #endif /* PLUGIN_USE_IRAM */
861 /* The plugin wants to stay resident after leaving its main function, e.g.
862 runs from timer or own thread. The callback is registered to later
863 instruct it to free its resources before a new plugin gets loaded. */
864 void plugin_tsr(bool (*exit_callback)(bool))
866 pfn_tsr_exit = exit_callback; /* remember the callback for later */
869 char *plugin_get_current_filename(void)
871 return current_plugin;