From 7b596416bf2cf533a514b4d1f7b95c6de6efa7d5 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 29 Dec 2011 12:02:49 +0000 Subject: Gigabeat S: Update RDS processing to use asynchronous I2C rather than thread. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31462 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/rds.c | 39 +++++++++++++++++++++++++++++++++++++-- firmware/drivers/tuner/si4700.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) (limited to 'firmware/drivers') diff --git a/firmware/drivers/rds.c b/firmware/drivers/rds.c index 09bc33807c..828c28b672 100644 --- a/firmware/drivers/rds.c +++ b/firmware/drivers/rds.c @@ -36,14 +36,46 @@ static char rt_copy[65]; static int rt_segment; static int rt_abflag; +#ifdef SI4700_RDS_ASYNC +/* Functions are called in ISR context */ +#define rds_disable_irq_save() disable_irq_save() +#define rds_restore_irq(old) restore_irq(old) +/* Need triple buffer so string isn't clobbered while caller is using it */ +static inline char * get_ps(void) +{ + static char ps_out[9]; + int oldlevel = rds_disable_irq_save(); + strcpy(ps_out, ps_copy); + rds_restore_irq(oldlevel); + return ps_out; +} +static inline char * get_rt(void) +{ + static char rt_out[65]; + int oldlevel = rds_disable_irq_save(); + strcpy(rt_out, rt_copy); + rds_restore_irq(oldlevel); + return rt_out; +} +#else /* ndef SI4700_RDS_ASYNC */ +#define rds_disable_irq_save() 0 +#define rds_restore_irq(old) ((void)(old)) +static inline char * get_ps(void) { return ps_copy; } +static inline char * get_rt(void) { return rt_copy; } +#endif /* SI4700_RDS_ASYNC */ + /* resets the rds parser */ void rds_reset(void) { + int oldlevel = rds_disable_irq_save(); + ps_copy[0] = '\0'; ps_segment = 0; rt_copy[0] = '\0'; rt_segment = 0; pi = 0; + + rds_restore_irq(oldlevel); } /* initialises the rds parser */ @@ -172,6 +204,9 @@ bool rds_process(uint16_t data[4]) return false; } +/* TODO: The caller really should provide the buffer in order to regulate + access */ + /* returns the programme identification code */ uint16_t rds_get_pi(void) { @@ -181,12 +216,12 @@ uint16_t rds_get_pi(void) /* returns the most recent valid programme service name */ char* rds_get_ps(void) { - return ps_copy; + return get_ps(); } /* returns the most recent valid RadioText message */ char* rds_get_rt(void) { - return rt_copy; + return get_rt(); } diff --git a/firmware/drivers/tuner/si4700.c b/firmware/drivers/tuner/si4700.c index bebbd0c881..0684d2042f 100644 --- a/firmware/drivers/tuner/si4700.c +++ b/firmware/drivers/tuner/si4700.c @@ -556,6 +556,34 @@ void si4700_dbg_info(struct si4700_dbg_info *nfo) } #ifdef HAVE_RDS_CAP + +#ifdef SI4700_RDS_ASYNC +/* Read raw RDS info for processing - asynchronously */ + +/* Assumes regbuf is 32 bytes */ +void si4700_rds_read_raw_async(void) +{ + si4700_read_raw_async((RDSD - STATUSRSSI + 1) * 2); +} + +void si4700_rds_read_raw_async_complete(unsigned char *regbuf, + uint16_t data[4]) +{ + const int index = (RDSA - STATUSRSSI) * 2; + + for (int i = 0; i < 4; i++) { + data[i] = regbuf[index] << 8 | regbuf[index + 1]; + regbuf += 2; + } +} + +/* Set the event flag */ +void si4700_rds_set_event(void) +{ + rds_event = 1; +} + +#else /* Read raw RDS info for processing */ bool si4700_rds_read_raw(uint16_t data[4]) { @@ -582,6 +610,7 @@ void si4700_rds_set_event(void) rds_event = 1; mutex_unlock(&fmr_mutex); } +#endif /* SI4700_RDS_ASYNC */ char * si4700_get_rds_info(int setting) { -- cgit v1.2.3