summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-07-26 20:01:11 +0000
committerJens Arnold <amiconn@rockbox.org>2005-07-26 20:01:11 +0000
commite44372ef18cbf30f0e174ed76be4ee4e6206f2cc (patch)
tree8860863bbfb7a6151173e7428900d9de2bdbba73 /apps
parentc20a00ef3e35b15acf422a2e7f6716abde840c24 (diff)
downloadrockbox-e44372ef18cbf30f0e174ed76be4ee4e6206f2cc.zip
rockbox-e44372ef18cbf30f0e174ed76be4ee4e6206f2cc.tar.gz
rockbox-e44372ef18cbf30f0e174ed76be4ee4e6206f2cc.tar.bz2
rockbox-e44372ef18cbf30f0e174ed76be4ee4e6206f2cc.tar.xz
Moved implementation of user timer to the firmware layer, implemented it for iriver, and made it shareable based on priorities. On iriver, the user timer is shared between the backlight fading and other use, so if a plugin registers the timer, the backlight will resort to simple on/off switching until the plugin releases the timer again. Sorted and bumped the plugin api.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7242 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugin.c108
-rw-r--r--apps/plugin.h71
-rw-r--r--apps/plugins/alpine_cdc.c8
-rw-r--r--apps/plugins/lib/gray_core.c4
-rw-r--r--apps/plugins/metronome.c4
-rw-r--r--apps/plugins/oscilloscope.c4
-rw-r--r--apps/plugins/video.c16
7 files changed, 74 insertions, 141 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 7bfa0e2..6c01806 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -45,6 +45,7 @@
#include "mp3data.h"
#include "powermgmt.h"
#include "system.h"
+#include "timer.h"
#include "sound.h"
#include "database.h"
#if (CONFIG_HWCODEC == MASNONE)
@@ -74,9 +75,6 @@ extern unsigned char pluginbuf[];
/* for actual plugins only, not for codecs */
static bool plugin_loaded = false;
static int plugin_size = 0;
-#ifndef SIMULATOR
-static void (*pfn_timer)(void) = NULL; /* user timer handler */
-#endif
static void (*pfn_tsr_exit)(void) = NULL; /* TSR exit callback */
static int plugin_test(int api_version, int model, int memsize);
@@ -116,6 +114,14 @@ static const struct plugin_api rockbox_api = {
lcd_fillrect,
lcd_mono_bitmap_part,
lcd_mono_bitmap,
+#if LCD_DEPTH > 1
+ lcd_set_foreground,
+ lcd_get_foreground,
+ lcd_set_background,
+ lcd_get_background,
+ lcd_bitmap_part,
+ lcd_bitmap,
+#endif
lcd_putsxy,
lcd_puts_style,
lcd_puts_scroll_style,
@@ -126,6 +132,7 @@ static const struct plugin_api rockbox_api = {
scrollbar,
checkbox,
font_get,
+ font_getstringsize,
#endif
backlight_on,
backlight_off,
@@ -211,6 +218,9 @@ static const struct plugin_api rockbox_api = {
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
cpu_boost,
#endif
+ timer_register,
+ timer_unregister,
+ timer_set_period,
#endif
/* strings and memory */
@@ -220,6 +230,7 @@ static const struct plugin_api rockbox_api = {
strlen,
strrchr,
strcmp,
+ strncmp,
strcasecmp,
strncasecmp,
memset,
@@ -289,6 +300,10 @@ static const struct plugin_api rockbox_api = {
&tagdb_fd,
&tagdb_initialized,
tagdb_init,
+ /* runtime database */
+ &rundbheader,
+ &rundb_fd,
+ &rundb_initialized,
/* misc */
srand,
@@ -299,14 +314,13 @@ static const struct plugin_api rockbox_api = {
set_time,
plugin_get_buffer,
plugin_get_audio_buffer,
-#ifndef SIMULATOR
- plugin_register_timer,
- plugin_unregister_timer,
-#endif
plugin_tsr,
#if defined(DEBUG) || defined(SIMULATOR)
debugf,
#endif
+#ifdef ROCKBOX_HAS_LOGF
+ logf,
+#endif
&global_settings,
mp3info,
count_mp3_frames,
@@ -326,24 +340,6 @@ static const struct plugin_api rockbox_api = {
/* new stuff at the end, sort into place next time
the API gets incompatible */
-#ifdef ROCKBOX_HAS_LOGF
- logf,
-#endif
- &rundbheader,
- &rundb_fd,
- &rundb_initialized,
- strncmp,
-#if LCD_DEPTH > 1
- lcd_set_foreground,
- lcd_get_foreground,
- lcd_set_background,
- lcd_get_background,
- lcd_bitmap_part,
- lcd_bitmap,
-#endif
-#ifdef HAVE_LCD_BITMAP
- font_getstringsize,
-#endif
};
int plugin_load(const char* plugin, void* parameter)
@@ -486,68 +482,6 @@ void* plugin_get_audio_buffer(int* buffer_size)
return audiobuf;
}
-#ifndef SIMULATOR
-/* Register a periodic time callback, called every "cycles" CPU clocks.
- Note that this function will be called in interrupt context! */
-int plugin_register_timer(int cycles, int prio, void (*timer_callback)(void))
-{
- int phi = 0; /* bits for the prescaler */
- int prescale = 1;
-
- while (cycles > 0x10000)
- { /* work out the smallest prescaler that makes it fit */
- phi++;
- prescale *= 2;
- cycles /= 2;
- }
-
- if (prescale > 8 || cycles == 0 || prio < 1 || prio > 15)
- return 0; /* error, we can't do such period, bad argument */
-
- backlight_allow_timer(false); /* stop backlight from messing with the timer */
-#if CONFIG_CPU == SH7034
- and_b(~0x10, &TSTR); /* Stop the timer 4 */
- and_b(~0x10, &TSNC); /* No synchronization */
- and_b(~0x10, &TMDR); /* Operate normally */
-
- pfn_timer = timer_callback; /* install 2nd level ISR */
-
- and_b(~0x01, &TSR4);
- TIER4 = 0xF9; /* Enable GRA match interrupt */
-
- GRA4 = (unsigned short)(cycles - 1);
- TCR4 = 0x20 | phi; /* clear at GRA match, set prescaler */
- IPRD = (IPRD & 0xFF0F) | prio << 4; /* interrupt priority */
- or_b(0x10, &TSTR); /* start timer 4 */
-#else
- pfn_timer = timer_callback;
-#endif
- return cycles * prescale; /* return the actual period, in CPU clocks */
-}
-
-/* disable the user timer */
-void plugin_unregister_timer(void)
-{
-#if CONFIG_CPU == SH7034
- and_b(~0x10, &TSTR); /* stop the timer 4 */
- IPRD = (IPRD & 0xFF0F); /* disable interrupt */
- pfn_timer = NULL;
-#endif
- backlight_allow_timer(true);
-}
-
-#if CONFIG_CPU == SH7034
-/* interrupt handler for user timer */
-#pragma interrupt
-void IMIA4(void)
-{
- if (pfn_timer != NULL)
- pfn_timer(); /* call the user timer function */
- and_b(~0x01, &TSR4); /* clear the interrupt */
-}
-#endif /* CONFIG_CPU == SH7034 */
-#endif /* #ifndef SIMULATOR */
-
/* The plugin wants to stay resident after leaving its main function, e.g.
runs from timer or own thread. The callback is registered to later
instruct it to free its resources before a new plugin gets loaded. */
diff --git a/apps/plugin.h b/apps/plugin.h
index f504bac..7cda354 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -48,6 +48,7 @@
#include "pcm_playback.h"
#endif
#include "settings.h"
+#include "timer.h"
#include "thread.h"
#include "playlist.h"
#ifdef HAVE_LCD_BITMAP
@@ -87,12 +88,12 @@
#endif
/* increase this every time the api struct changes */
-#define PLUGIN_API_VERSION 46
+#define PLUGIN_API_VERSION 47
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */
-#define PLUGIN_MIN_API_VERSION 42
+#define PLUGIN_MIN_API_VERSION 47
/* plugin return codes */
enum plugin_status {
@@ -168,6 +169,23 @@ struct plugin_api {
int stride, int x, int y, int width, int height);
void (*lcd_mono_bitmap)(const unsigned char *src, int x, int y,
int width, int height);
+#if LCD_DEPTH > 1
+#ifdef HAVE_LCD_COLOR
+ void (*lcd_set_foreground)(struct rgb color);
+ struct rgb (*lcd_get_foreground)(void);
+ void (*lcd_set_background)(struct rgb color);
+ struct rgb (*lcd_get_background)(void);
+#else
+ void (*lcd_set_foreground)(int brightness);
+ int (*lcd_get_foreground)(void);
+ void (*lcd_set_background)(int brightness);
+ int (*lcd_get_background)(void);
+#endif
+ void (*lcd_bitmap_part)(const unsigned char *src, int src_x, int src_y,
+ int stride, int x, int y, int width, int height);
+ void (*lcd_bitmap)(const unsigned char *src, int x, int y, int width,
+ int height);
+#endif
void (*lcd_putsxy)(int x, int y, const unsigned char *string);
void (*lcd_puts_style)(int x, int y, const unsigned char *str, int style);
void (*lcd_puts_scroll_style)(int x, int y, const unsigned char* string,
@@ -181,6 +199,8 @@ struct plugin_api {
int min_shown, int max_shown, int orientation);
void (*checkbox)(int x, int y, int width, int height, bool checked);
struct font* (*font_get)(int font);
+ int (*font_getstringsize)(const unsigned char *str, int *w, int *h,
+ int fontnumber);
#endif
void (*backlight_on)(void);
void (*backlight_off)(void);
@@ -272,6 +292,11 @@ struct plugin_api {
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
void (*cpu_boost)(bool on_off);
#endif
+ bool (*timer_register)(int reg_prio, void (*unregister_callback)(void),
+ long cycles, int int_prio,
+ void (*timer_callback)(void));
+ void (*timer_unregister)(void);
+ bool (*timer_set_period)(long count);
#endif
/* strings and memory */
@@ -281,6 +306,7 @@ struct plugin_api {
size_t (*strlen)(const char *str);
char * (*strrchr)(const char *s, int c);
int (*strcmp)(const char *, const char *);
+ int (*strncmp)(const char *, const char *, size_t);
int (*strcasecmp)(const char *, const char *);
int (*strncasecmp)(const char *s1, const char *s2, size_t n);
void* (*memset)(void *dst, int c, size_t length);
@@ -350,6 +376,10 @@ struct plugin_api {
int *tagdb_fd;
int *tagdb_initialized;
int (*tagdb_init) (void);
+ /* runtime database */
+ struct rundb_header *rundbheader;
+ int *rundb_fd;
+ int *rundb_initialized;
/* misc */
void (*srand)(unsigned int seed);
@@ -361,14 +391,13 @@ struct plugin_api {
int (*set_time)(const struct tm *tm);
void* (*plugin_get_buffer)(int* buffer_size);
void* (*plugin_get_audio_buffer)(int* buffer_size);
-#ifndef SIMULATOR
- int (*plugin_register_timer)(int cycles, int prio, void (*timer_callback)(void));
- void (*plugin_unregister_timer)(void);
-#endif
void (*plugin_tsr)(void (*exit_callback)(void));
#if defined(DEBUG) || defined(SIMULATOR)
void (*debugf)(const char *fmt, ...);
#endif
+#ifdef ROCKBOX_HAS_LOGF
+ void (*logf)(const char *fmt, ...);
+#endif
struct user_settings* global_settings;
bool (*mp3info)(struct mp3entry *entry, const char *filename, bool v1first);
int (*count_mp3_frames)(int fd, int startpos, int filesize,
@@ -395,41 +424,11 @@ struct plugin_api {
/* new stuff at the end, sort into place next time
the API gets incompatible */
-#ifdef ROCKBOX_HAS_LOGF
- void (*logf)(const char *fmt, ...);
-#endif
- struct rundb_header *rundbheader;
- int *rundb_fd;
- int *rundb_initialized;
- int (*strncmp)(const char *, const char *, size_t);
-#if LCD_DEPTH > 1
-#ifdef HAVE_LCD_COLOR
- void (*lcd_set_foreground)(struct rgb color);
- struct rgb (*lcd_get_foreground)(void);
- void (*lcd_set_background)(struct rgb color);
- struct rgb (*lcd_get_background)(void);
-#else
- void (*lcd_set_foreground)(int brightness);
- int (*lcd_get_foreground)(void);
- void (*lcd_set_background)(int brightness);
- int (*lcd_get_background)(void);
-#endif
- void (*lcd_bitmap_part)(const unsigned char *src, int src_x, int src_y,
- int stride, int x, int y, int width, int height);
- void (*lcd_bitmap)(const unsigned char *src, int x, int y, int width,
- int height);
-#endif
-#ifdef HAVE_LCD_BITMAP
- int (*font_getstringsize)(const unsigned char *str, int *w, int *h,
- int fontnumber);
-#endif
};
int plugin_load(const char* plugin, void* parameter);
void* plugin_get_buffer(int *buffer_size);
void* plugin_get_audio_buffer(int *buffer_size);
-int plugin_register_timer(int cycles, int prio, void (*timer_callback)(void));
-void plugin_unregister_timer(void);
void plugin_tsr(void (*exit_callback)(void));
/* defined by the plugin */
diff --git a/apps/plugins/alpine_cdc.c b/apps/plugins/alpine_cdc.c
index 7c014a2..5dd8b4a 100644
--- a/apps/plugins/alpine_cdc.c
+++ b/apps/plugins/alpine_cdc.c
@@ -230,15 +230,15 @@ void timer_set_mode(int mode)
if (mode == TM_RX_TIMEOUT)
{
- rb->plugin_register_timer(gTimer.timeout, 11, timer4_isr);
+ rb->timer_register(1, NULL, gTimer.timeout, 11, timer4_isr);
}
else if (mode == TM_TRANSMIT)
{
- rb->plugin_register_timer(gTimer.transmit, 14, timer4_isr);
+ rb->timer_register(1, NULL, gTimer.transmit, 14, timer4_isr);
}
else
{
- rb->plugin_unregister_timer();
+ rb->timer_unregister();
}
}
@@ -252,7 +252,7 @@ void timer4_isr(void) /* IMIA4 */
break;
case TM_RX_TIMEOUT:
receive_timeout_isr();
- rb->plugin_unregister_timer(); /* single shot */
+ rb->timer_unregister(); /* single shot */
break;
default:
timer_set_mode(TM_OFF); /* spurious interrupt */
diff --git a/apps/plugins/lib/gray_core.c b/apps/plugins/lib/gray_core.c
index 18b9c3c..361b392 100644
--- a/apps/plugins/lib/gray_core.c
+++ b/apps/plugins/lib/gray_core.c
@@ -257,11 +257,11 @@ void gray_show(bool enable)
if (enable)
{
_gray_info.flags |= _GRAY_RUNNING;
- _gray_rb->plugin_register_timer(FREQ / 67, 1, _timer_isr);
+ _gray_rb->timer_register(1, NULL, FREQ / 67, 1, _timer_isr);
}
else
{
- _gray_rb->plugin_unregister_timer();
+ _gray_rb->timer_unregister();
_gray_info.flags &= ~_GRAY_RUNNING;
_gray_rb->lcd_update(); /* restore whatever there was before */
}
diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c
index 3793fd9..fa5520b 100644
--- a/apps/plugins/metronome.c
+++ b/apps/plugins/metronome.c
@@ -235,7 +235,7 @@ void cleanup(void *parameter)
{
(void)parameter;
- rb->plugin_unregister_timer();
+ rb->timer_unregister();
rb->mp3_play_stop(); /* stop audio ISR */
led(0);
}
@@ -278,7 +278,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
rb->mp3_play_stop(); // stop audio ISR
calc_period();
- rb->plugin_register_timer(((*rb->cpu_frequency)/1024), 1, timer_callback);
+ rb->timer_register(1, NULL, (*rb->cpu_frequency)/1024, 1, timer_callback);
draw_display();
diff --git a/apps/plugins/oscilloscope.c b/apps/plugins/oscilloscope.c
index ae77f33..f5e5189 100644
--- a/apps/plugins/oscilloscope.c
+++ b/apps/plugins/oscilloscope.c
@@ -192,7 +192,7 @@ void cleanup(void *parameter)
{
(void)parameter;
- rb->plugin_unregister_timer();
+ rb->timer_unregister();
}
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
@@ -205,7 +205,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
(void)parameter;
rb = api;
- rb->plugin_register_timer(FREQ / 67, 1, timer_isr);
+ rb->timer_register(1, NULL, FREQ / 67, 1, timer_isr);
while (!exit)
{
diff --git a/apps/plugins/video.c b/apps/plugins/video.c
index b4b27e0..1a288ee 100644
--- a/apps/plugins/video.c
+++ b/apps/plugins/video.c
@@ -388,7 +388,7 @@ void timer4_isr(void)
else
{
gPlay.bVideoUnderrun = true;
- rb->plugin_unregister_timer(); // disable ourselves
+ rb->timer_unregister(); // disable ourselves
return; // no data available
}
}
@@ -490,7 +490,7 @@ int SeekTo(int fd, int nPos)
if (gPlay.bHasAudio)
rb->mp3_play_stop(); // stop audio ISR
if (gPlay.bHasVideo)
- rb->plugin_unregister_timer(); // stop the timer
+ rb->timer_unregister(); // stop the timer
rb->lseek(fd, nPos, SEEK_SET);
@@ -538,9 +538,9 @@ int SeekTo(int fd, int nPos)
gPlay.bVideoUnderrun = false;
// start display interrupt
#if FREQ == 12000000 /* Ondio speed kludge */
- rb->plugin_register_timer(gPlay.nFrameTimeAdjusted, 1, timer4_isr);
+ rb->timer_register(1, NULL, gPlay.nFrameTimeAdjusted, 1, timer4_isr);
#else
- rb->plugin_register_timer(gFileHdr.video_frametime, 1, timer4_isr);
+ rb->timer_register(1, NULL, gFileHdr.video_frametime, 1, timer4_isr);
#endif
}
@@ -553,7 +553,7 @@ void Cleanup(void *fd)
rb->close(*(int*)fd); // close the file
if (gPlay.bHasVideo)
- rb->plugin_unregister_timer(); // stop video ISR, now I can use the display again
+ rb->timer_unregister(); // stop video ISR, now I can use the display again
if (gPlay.bHasAudio)
rb->mp3_play_stop(); // stop audio ISR
@@ -705,7 +705,7 @@ int PlayTick(int fd)
if (gPlay.bHasAudio)
rb->mp3_play_pause(false); // pause audio
if (gPlay.bHasVideo)
- rb->plugin_unregister_timer(); // stop the timer
+ rb->timer_unregister(); // stop the timer
}
else if (gPlay.state == paused)
{
@@ -719,10 +719,10 @@ int PlayTick(int fd)
if (gPlay.bHasVideo)
{ // start the video
#if FREQ == 12000000 /* Ondio speed kludge */
- rb->plugin_register_timer(
+ rb->timer_register(1, NULL,
gPlay.nFrameTimeAdjusted, 1, timer4_isr);
#else
- rb->plugin_register_timer(
+ rb->timer_register(1, NULL,
gFileHdr.video_frametime, 1, timer4_isr);
#endif
}