Improve radio RDS driver and framework
* Remove unused bits like the radio event and simplify basic radio interface. It can be more self-contained with rds.h only required by radio and tuner code. * Add post-processing to text a-la Silicon Labs AN243. The chip's error correction can only do so much; additional checks are highly recommended. Simply testing for two identical messages in a row is extremely effective and I've never seen corrupted text since doing that, even with mediocre reception. Groups segments must arrive in order, not randomly; logic change only accepts them in order, starting at 0. Time readout was made a bit better but really we'd need to use verbose mode and ensure that no errors were seen during receiving of time and more checks would be need to have a stable PI. The text is the important bit anyway. * Time out of stale text. * Text is no longer updated until a complete group has been received, as is specified in the standard. Perhaps go back to scrolling text lines in the radio screen? * Add proper character conversion to UTF-8. Only the default G0 table for the moment. The other two could be added in. * Add variants "RDS_CFG_PROCESS" and "RDS_CFG_PUSH" to allow the option for processed RDS data to be pushed to the driver and still do proper post-processing (only text conversion for now for the latter). Change-Id: I4d83f8b2e89a209a5096d15ec266477318c66925
This commit is contained in:
parent
6436c6e749
commit
fc9695eb47
25 changed files with 514 additions and 343 deletions
|
@ -127,10 +127,6 @@
|
|||
#include "iap.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RDS_CAP
|
||||
#include "rds.h"
|
||||
#endif
|
||||
|
||||
#include "talk.h"
|
||||
|
||||
static const char* threads_getname(int selected_item, void *data,
|
||||
|
@ -2166,17 +2162,25 @@ static int radio_callback(int btn, struct gui_synclist *lists)
|
|||
#endif /* TEA5760 */
|
||||
|
||||
#ifdef HAVE_RDS_CAP
|
||||
simplelist_addline("PI:%04X PS:'%8s'",
|
||||
rds_get_pi(), rds_get_ps());
|
||||
simplelist_addline("RT:%s",
|
||||
rds_get_rt());
|
||||
time_t seconds = rds_get_ct();
|
||||
{
|
||||
char buf[65*4];
|
||||
uint16_t pi;
|
||||
time_t seconds;
|
||||
|
||||
tuner_get_rds_info(RADIO_RDS_NAME, buf, sizeof (buf));
|
||||
tuner_get_rds_info(RADIO_RDS_PROGRAM_INFO, &pi, sizeof (pi));
|
||||
simplelist_addline("PI:%04X PS:'%8s'", pi, buf);
|
||||
tuner_get_rds_info(RADIO_RDS_TEXT, buf, sizeof (buf));
|
||||
simplelist_addline("RT:%s", buf);
|
||||
tuner_get_rds_info(RADIO_RDS_CURRENT_TIME, &seconds, sizeof (seconds));
|
||||
|
||||
struct tm* time = gmtime(&seconds);
|
||||
simplelist_addline(
|
||||
"CT:%4d-%02d-%02d %02d:%02d",
|
||||
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
|
||||
time->tm_hour, time->tm_min, time->tm_sec);
|
||||
#endif
|
||||
}
|
||||
#endif /* HAVE_RDS_CAP */
|
||||
return ACTION_REDRAW;
|
||||
}
|
||||
static bool dbg_fm_radio(void)
|
||||
|
|
|
@ -540,9 +540,11 @@ const char *get_radio_token(struct wps_token *token, int preset_offset,
|
|||
#ifdef HAVE_RDS_CAP
|
||||
return "rds";
|
||||
case SKIN_TOKEN_RDS_NAME:
|
||||
return tuner_get_rds_info(RADIO_RDS_NAME);
|
||||
tuner_get_rds_info(RADIO_RDS_NAME, buf, buf_size);
|
||||
return buf;
|
||||
case SKIN_TOKEN_RDS_TEXT:
|
||||
return tuner_get_rds_info(RADIO_RDS_TEXT);
|
||||
tuner_get_rds_info(RADIO_RDS_TEXT, buf, buf_size);
|
||||
return buf;
|
||||
#else
|
||||
return NULL; /* end of the SKIN_TOKEN_HAVE_RDS case */
|
||||
#endif /* HAVE_RDS_CAP */
|
||||
|
|
|
@ -696,10 +696,6 @@ void radio_screen(void)
|
|||
|
||||
default:
|
||||
default_event_handler(button);
|
||||
#ifdef HAVE_RDS_CAP
|
||||
if (tuner_get(RADIO_EVENT))
|
||||
update_type = SKIN_REFRESH_ALL;
|
||||
#endif
|
||||
if (!tuner_get(RADIO_PRESENT))
|
||||
{
|
||||
#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
|
||||
|
|
|
@ -21,73 +21,195 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strlcpy.h>
|
||||
#include <system.h>
|
||||
#include <kernel.h>
|
||||
#include "rds.h"
|
||||
#include "time.h"
|
||||
#include "string-extra.h"
|
||||
|
||||
// timeout before segment obsolescence
|
||||
#define PS_SEGMENT_TIMEOUT (HZ / 2)
|
||||
#define RT_SEGMENT_TIMEOUT (10 * HZ)
|
||||
#define TIMED_OUT(tick) \
|
||||
TIME_AFTER(current_tick, (tick))
|
||||
#define SET_TIMEOUT(tick, duration) \
|
||||
({ (tick) = current_tick + (duration); })
|
||||
|
||||
/* Driver keeps strings in native character format, translating on demand */
|
||||
static char ps_copy[9]; /* copy of final message */
|
||||
static long ps_copy_tmo; /* timeout to discard programme service name */
|
||||
static char rt_copy[65]; /* copy of final message */
|
||||
static long rt_copy_tmo; /* time to discard radio text */
|
||||
static uint16_t pi_code; /* current programme identifier code */
|
||||
static time_t ct_data; /* date/time (not robust; not essential) */
|
||||
|
||||
/* timeout before text times out */
|
||||
#define TEXT_TIMEOUT (30 * HZ)
|
||||
|
||||
/* timeout before RDS is considered idle and is reset */
|
||||
#define RDS_TIMEOUT (10 * HZ)
|
||||
static long rds_timeout; /* timeout until rds is thought idle */
|
||||
static bool rds_active; /* if active, timeouts are monitored */
|
||||
|
||||
#if (CONFIG_RDS & RDS_CFG_PROCESS)
|
||||
/* timeout before group segment obsolescence */
|
||||
#define GROUP0_TIMEOUT (2 * HZ)
|
||||
#define GROUP2_TIMEOUT (10 * HZ)
|
||||
|
||||
/* programme identification (not robust; not really used anyway) */
|
||||
static uint16_t pi_last; /* previously read code */
|
||||
|
||||
/* programme service name */
|
||||
static char ps_data[2][9]; /* round-robin driver work queue */
|
||||
static int ps_segment; /* next expected segment */
|
||||
static long ps_timeout; /* timeout to receive full group */
|
||||
static int ps_data_idx; /* ps_data[0 or 1] */
|
||||
#define PS_DATA_INC(x) ps_data[ps_data_idx ^= (x)]
|
||||
|
||||
/* programme identification */
|
||||
static uint16_t pi_code;
|
||||
static uint16_t pi_last;
|
||||
/* program service name */
|
||||
static char ps_data[9];
|
||||
static char ps_copy[9];
|
||||
static long ps_segment_timeout[4];
|
||||
static int ps_segment;// bitmap of received segments
|
||||
/* radio text */
|
||||
static char rt_data[65];
|
||||
static char rt_copy[65];
|
||||
static long rt_segment_timeout[16];
|
||||
static int rt_segment;// bitmap of received segments
|
||||
static int rt_abflag;
|
||||
/* date/time */
|
||||
static time_t ct_data;
|
||||
static char rt_data[2][65]; /* round-robin driver work queue */
|
||||
static int rt_segment; /* next expected segment */
|
||||
static long rt_timeout; /* timeout to receive full group */
|
||||
static int rt_abflag; /* message change flag */
|
||||
static int rt_data_idx; /* rt_data[0 or 1] */
|
||||
#define RT_DATA_INC(x) rt_data[rt_data_idx ^= (x)]
|
||||
#endif /* (CONFIG_RDS & RDS_CFG_PROCESS) */
|
||||
|
||||
#ifdef RDS_ISR_PROCESSING
|
||||
#if (CONFIG_RDS & RDS_CFG_ISR)
|
||||
/* 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 RDS_ISR_PROCESSING */
|
||||
#else /* !(CONFIG_RDS & RDS_CFG_ISR) */
|
||||
#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 /* RDS_ISR_PROCESSING */
|
||||
#endif /* (CONFIG_RDS & RDS_CFG_ISR) */
|
||||
|
||||
/* RDS code table G0 to UTF-8 translation */
|
||||
static const uint16_t rds_tbl_g0[0x100-0x20] =
|
||||
{
|
||||
/* codes 0x00 .. 0x1F are omitted because they are identities and not
|
||||
* actually spec'ed as part of the character maps anyway */
|
||||
/* 0 1 2 3 4 5 6 7 */
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x00A4, 0x0025, 0x0026, 0x0027, /* 20 */
|
||||
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, /* 28 */
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, /* 30 */
|
||||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, /* 38 */
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, /* 40 */
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, /* 48 */
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, /* 50 */
|
||||
0x0058, 0x0059, 0x005A, 0x005B, 0x005B, 0x005D, 0x2015, 0x005F, /* 58 */
|
||||
0x2016, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, /* 60 */
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, /* 68 */
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, /* 70 */
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x203E, 0x0020, /* 78 */
|
||||
0x00E1, 0x00E0, 0x00E9, 0x00E8, 0x00ED, 0x00EC, 0x00F3, 0x00F2, /* 80 */
|
||||
0x00FA, 0x00F9, 0x00D1, 0x00C7, 0x015E, 0x00DF, 0x00A1, 0x0132, /* 88 */
|
||||
0x00E2, 0x00E4, 0x00EA, 0x00EB, 0x00EE, 0x00EF, 0x00F4, 0x00F6, /* 90 */
|
||||
0x00FB, 0x00FC, 0x00F1, 0x00E7, 0x015F, 0x01E7, 0x0131, 0x0133, /* 98 */
|
||||
0x00AA, 0x03B1, 0x00A9, 0x2030, 0x01E6, 0x011B, 0x0148, 0x0151, /* A0 */
|
||||
0x03C0, 0x20A0, 0x00A3, 0x0024, 0x2190, 0x2191, 0x2192, 0x2193, /* A8 */
|
||||
0x00BA, 0x00B9, 0x00B2, 0x00B3, 0x00B1, 0x0130, 0x0144, 0x0171, /* B0 */
|
||||
0x00B5, 0x00BF, 0x00F7, 0x00B0, 0x00BC, 0x00BD, 0x00BE, 0x00A7, /* B8 */
|
||||
0x00C1, 0x00C0, 0x00C9, 0x00C8, 0x00CD, 0x00CC, 0x00D3, 0x00D2, /* C0 */
|
||||
0x00DA, 0x00D9, 0x0158, 0x010C, 0x0160, 0x017D, 0x0110, 0x013F, /* C8 */
|
||||
0x00C2, 0x00C4, 0x00CA, 0x00CB, 0x00CE, 0x00CF, 0x00D4, 0x00D6, /* D0 */
|
||||
0x00DB, 0x00DC, 0x0159, 0x010D, 0x0161, 0x017E, 0x0111, 0x0140, /* D8 */
|
||||
0x00C3, 0x00C5, 0x00C6, 0x0152, 0x0177, 0x00DD, 0x00D5, 0x00D8, /* E0 */
|
||||
0x00DE, 0x014A, 0x0158, 0x0106, 0x015A, 0x0179, 0x0166, 0x00F0, /* E8 */
|
||||
0x00E3, 0x00E5, 0x00E6, 0x0153, 0x0175, 0x00FD, 0x00F5, 0x00F8, /* F0 */
|
||||
0x00FE, 0x014B, 0x0159, 0x0107, 0x015B, 0x017A, 0x0167, 0x0020, /* F8 */
|
||||
};
|
||||
|
||||
/* could add tables G1 and G2 without much trouble */
|
||||
|
||||
/* write one UTF-8 character; returns original 'dst' if insufficient space */
|
||||
static char * convert_rds_char(char *dst, unsigned int c, size_t dstsize)
|
||||
{
|
||||
unsigned int u = c >= 0x20 ? (rds_tbl_g0 - 0x20)[c] : c;
|
||||
|
||||
if (LIKELY(u <= 0x7F)) {
|
||||
/* U+0000 .. U+007F -> 0xxx xxxx */
|
||||
if (dstsize > 1) {
|
||||
*dst++ = u;
|
||||
}
|
||||
}
|
||||
else if (u <= 0x7FF) {
|
||||
/* U+0080 .. U+07FF -> 110x xxxx 10 xx xxxx */
|
||||
if (dstsize > 2) {
|
||||
*dst++ = 0xC0 | (u >> 6);
|
||||
*dst++ = 0x80 | (u & 0x3F);
|
||||
}
|
||||
}
|
||||
else /* if (u <= 0xFFFF) */ {
|
||||
/* U+0800 .. U+FFFF -> 1110 xxxx 10xx xxxx 10xx xxxx */
|
||||
if (dstsize > 3) {
|
||||
*dst++ = 0xE0 | (u >> 12);
|
||||
*dst++ = 0x80 | ((u >> 6) & 0x3F);
|
||||
*dst++ = 0x80 | (u & 0x3F);
|
||||
}
|
||||
}
|
||||
#if 0 /* No four-byte characters are used right now */
|
||||
else {
|
||||
/* U+10000 .. U+10FFFF -> 11110xxx 10xx xxxx 10xx xxxx 10xx xxxx */
|
||||
if (dstsize > 4) {
|
||||
*dst++ = 0xF0 | (c >> 18);
|
||||
*dst++ = 0x80 | ((c >> 12) & 0x3F);
|
||||
*dst++ = 0x80 | ((c >> 6) & 0x3F);
|
||||
*dst++ = 0x80 | (c & 0x3F);
|
||||
}
|
||||
}
|
||||
#endif /* 0 */
|
||||
return dst;
|
||||
}
|
||||
|
||||
/* Copy RDS character string with conversion to UTF-8
|
||||
* Acts like strlcpy but won't split multibyte characters */
|
||||
static size_t copy_rds_string(char *dst, const char *src, size_t dstsize)
|
||||
{
|
||||
char *p = dst;
|
||||
unsigned int c;
|
||||
|
||||
while ((c = (unsigned char)*src++)) {
|
||||
char *q = p;
|
||||
|
||||
p = convert_rds_char(q, c, dstsize);
|
||||
if (p == q) {
|
||||
dst -= dstsize;
|
||||
break;
|
||||
}
|
||||
|
||||
dstsize -= p - q;
|
||||
}
|
||||
|
||||
if (dstsize > 0) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
return p - dst;
|
||||
}
|
||||
|
||||
/* indicate recent processing activity */
|
||||
static void register_activity(void)
|
||||
{
|
||||
SET_TIMEOUT(rds_timeout, RDS_TIMEOUT);
|
||||
rds_active = true;
|
||||
}
|
||||
|
||||
/* resets the rds parser */
|
||||
void rds_reset(void)
|
||||
{
|
||||
int oldlevel = rds_disable_irq_save();
|
||||
|
||||
pi_code = 0;
|
||||
pi_last = 0;
|
||||
/* reset general info */
|
||||
pi_code = 0;
|
||||
ct_data = 0;
|
||||
ps_copy[0] = '\0';
|
||||
ps_segment = 0;
|
||||
rt_copy[0] = '\0';
|
||||
rds_active = false;
|
||||
|
||||
#if (CONFIG_RDS & RDS_CFG_PROCESS)
|
||||
/* reset driver info */
|
||||
pi_last = 0;
|
||||
ps_segment = 0;
|
||||
rt_segment = 0;
|
||||
ct_data = 0;
|
||||
#endif /* (CONFIG_RDS & RDS_CFG_PROCESS) */
|
||||
|
||||
rds_restore_irq(oldlevel);
|
||||
}
|
||||
|
@ -98,105 +220,141 @@ void rds_init(void)
|
|||
rds_reset();
|
||||
}
|
||||
|
||||
/* sync RDS state */
|
||||
void rds_sync(void)
|
||||
{
|
||||
int oldlevel = rds_disable_irq_save();
|
||||
|
||||
if (rds_active) {
|
||||
if (TIMED_OUT(rds_timeout)) {
|
||||
rds_reset();
|
||||
}
|
||||
else {
|
||||
if (TIMED_OUT(ps_copy_tmo)) {
|
||||
ps_copy[0] = '\0';
|
||||
}
|
||||
if (TIMED_OUT(rt_copy_tmo)) {
|
||||
rt_copy[0] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rds_restore_irq(oldlevel);
|
||||
}
|
||||
|
||||
#if (CONFIG_RDS & RDS_CFG_PROCESS)
|
||||
/* handles a group 0 packet, returns true if a new message was received */
|
||||
static bool handle_group0(uint16_t data[4])
|
||||
static void handle_group0(const uint16_t data[4])
|
||||
{
|
||||
int segment, pos;
|
||||
|
||||
/* remove obsolete segments */
|
||||
for(int i = 0; i < 4; i++)
|
||||
if(TIME_AFTER(current_tick, ps_segment_timeout[i]))
|
||||
ps_segment &= ~(1 << i);
|
||||
char *ps;
|
||||
|
||||
segment = data[1] & 3;
|
||||
|
||||
if (segment == 0) {
|
||||
ps_segment = 0;
|
||||
}
|
||||
else if (segment != ps_segment || TIMED_OUT(ps_timeout)) {
|
||||
ps_segment = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* store data */
|
||||
pos = segment * 2;
|
||||
ps_data[pos++] = (data[3] >> 8) & 0xFF;
|
||||
ps_data[pos++] = (data[3] >> 0) & 0xFF;
|
||||
ps_segment |= 1 << segment;
|
||||
ps_segment_timeout[segment] = current_tick + PS_SEGMENT_TIMEOUT;
|
||||
if (ps_segment == 0xf) {
|
||||
ps_data[8] = '\0';
|
||||
if (strcmp(ps_copy, ps_data) != 0) {
|
||||
/* we got an updated message */
|
||||
strcpy(ps_copy, ps_data);
|
||||
return true;
|
||||
}
|
||||
ps = PS_DATA_INC(0);
|
||||
ps[pos + 0] = (data[3] >> 8) & 0xFF;
|
||||
ps[pos + 1] = (data[3] >> 0) & 0xFF;
|
||||
|
||||
if (++ps_segment < 4) {
|
||||
/* don't have all segments yet */
|
||||
SET_TIMEOUT(ps_timeout, GROUP0_TIMEOUT);
|
||||
return;
|
||||
}
|
||||
|
||||
ps[8] = '\0';
|
||||
|
||||
/* two messages in a row must be the same */
|
||||
if (memcmp(ps, PS_DATA_INC(1), 8) == 0) {
|
||||
memcpy(ps_copy, ps, 9);
|
||||
SET_TIMEOUT(ps_copy_tmo, TEXT_TIMEOUT);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* handles a radio text characters, returns true if end-of-line found */
|
||||
static bool handle_rt(int pos, char c)
|
||||
static bool handle_rt(int *pos_p, char c)
|
||||
{
|
||||
char *rt = RT_DATA_INC(0);
|
||||
|
||||
switch (c) {
|
||||
case 0x0A:
|
||||
/* line break hint */
|
||||
rt_data[pos] = ' ';
|
||||
return false;
|
||||
case 0x0D:
|
||||
/* end of line */
|
||||
rt_data[pos] = '\0';
|
||||
case 0x0D: /* end of line */
|
||||
return true;
|
||||
default:
|
||||
rt_data[pos] = c;
|
||||
case 0x0A: /* optional line break */
|
||||
case 0x0B: /* end of headline */
|
||||
c = ' ';
|
||||
default: /* regular character */
|
||||
rt[(*pos_p)++] = c;
|
||||
case 0x00 ... 0x09: /* unprintable */
|
||||
case 0x0C:
|
||||
case 0x0E ... 0x1E:
|
||||
case 0x1F: /* soft hyphen */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* handles a group 2 packet, returns true if a new message was received */
|
||||
static bool handle_group2(uint16_t data[4])
|
||||
static void handle_group2(const uint16_t data[4])
|
||||
{
|
||||
int abflag, segment, version, pos;
|
||||
char *rt;
|
||||
bool done = false;
|
||||
|
||||
/* remove obsolete segments */
|
||||
for(int i = 0; i < 16; i++)
|
||||
if(TIME_AFTER(current_tick, rt_segment_timeout[i]))
|
||||
rt_segment &= ~(1 << i);
|
||||
|
||||
/* reset parsing if the message type changed */
|
||||
abflag = (data[1] >> 4) & 1;
|
||||
segment = data[1] & 0xF;
|
||||
if (abflag != rt_abflag) {
|
||||
version = (data[1] >> 11) & 1;
|
||||
|
||||
if (abflag != rt_abflag || segment == 0) {
|
||||
rt_abflag = abflag;
|
||||
rt_segment = 0;
|
||||
}
|
||||
|
||||
rt_segment |= 1 << segment;
|
||||
rt_segment_timeout[segment] = current_tick + RT_SEGMENT_TIMEOUT;
|
||||
else if (segment != rt_segment || TIMED_OUT(rt_timeout)) {
|
||||
rt_segment = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* store data */
|
||||
version = (data[1] >> 11) & 1;
|
||||
if (version == 0) {
|
||||
pos = segment * 4;
|
||||
done = done || handle_rt(pos++, (data[2] >> 8) & 0xFF);
|
||||
done = done || handle_rt(pos++, (data[2] >> 0) & 0xFF);
|
||||
done = done || handle_rt(pos++, (data[3] >> 8) & 0xFF);
|
||||
done = done || handle_rt(pos++, (data[3] >> 0) & 0xFF);
|
||||
done = done || handle_rt(&pos, (data[2] >> 8) & 0xFF);
|
||||
done = done || handle_rt(&pos, (data[2] >> 0) & 0xFF);
|
||||
done = done || handle_rt(&pos, (data[3] >> 8) & 0xFF);
|
||||
done = done || handle_rt(&pos, (data[3] >> 0) & 0xFF);
|
||||
} else {
|
||||
pos = segment * 2;
|
||||
done = done || handle_rt(pos++, (data[3] >> 8) & 0xFF);
|
||||
done = done || handle_rt(pos++, (data[3] >> 0) & 0xFF);
|
||||
}
|
||||
/* there are two cases for completion:
|
||||
* - we got all 16 segments
|
||||
* - we found a end of line AND we got all segments before it */
|
||||
if (rt_segment == 0xffff || (done && rt_segment == (1 << segment) - 1)) {
|
||||
rt_data[pos] = '\0';
|
||||
if (strcmp(rt_copy, rt_data) != 0) {
|
||||
/* we got an updated message */
|
||||
strcpy(rt_copy, rt_data);
|
||||
return true;
|
||||
}
|
||||
done = done || handle_rt(&pos, (data[3] >> 8) & 0xFF);
|
||||
done = done || handle_rt(&pos, (data[3] >> 0) & 0xFF);
|
||||
}
|
||||
|
||||
return false;
|
||||
/* there are two cases for completion:
|
||||
* - we got all 16 segments
|
||||
* - we found an end of line */
|
||||
if (++rt_segment < 16 && !done) {
|
||||
SET_TIMEOUT(rt_timeout, GROUP2_TIMEOUT);
|
||||
return;
|
||||
}
|
||||
|
||||
rt = RT_DATA_INC(0);
|
||||
rt[pos++] = '\0';
|
||||
|
||||
/* two messages in a row must be the same */
|
||||
if (memcmp(rt, RT_DATA_INC(1), pos) == 0) {
|
||||
memcpy(rt_copy, rt, pos);
|
||||
SET_TIMEOUT(rt_copy_tmo, TEXT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
/* handles a group 4a packet (clock-time) */
|
||||
static bool handle_group4a(uint16_t data[4])
|
||||
static void handle_group4a(const uint16_t data[4])
|
||||
{
|
||||
int daycode = ((data[1] << 15) & 0x18000) |
|
||||
((data[2] >> 1) & 0x07FFF);
|
||||
|
@ -208,29 +366,30 @@ static bool handle_group4a(uint16_t data[4])
|
|||
|
||||
if (daycode < 55927) {
|
||||
/* invalid date, before 2012-01-01 */
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if ((hour >= 24) || (minute >= 60)) {
|
||||
/* invalid time */
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (offset_abs > 24) {
|
||||
/* invalid local time offset */
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
/* convert modified julian day + time to UTC */
|
||||
time_t seconds = (daycode - 40587) * 86400;
|
||||
seconds += hour * 3600;
|
||||
seconds += minute * 60;
|
||||
seconds += ((offset_sig == 0) ? offset_abs : -offset_abs) * 1800;
|
||||
ct_data = seconds;
|
||||
|
||||
return true;
|
||||
time_t seconds = daycode - 40587;
|
||||
if (seconds < 24854) {
|
||||
seconds *= 86400;
|
||||
seconds += hour * 3600;
|
||||
seconds += minute * 60;
|
||||
seconds += ((offset_sig == 0) ? offset_abs : -offset_abs) * 1800;
|
||||
ct_data = seconds;
|
||||
}
|
||||
}
|
||||
|
||||
/* processes one rds packet, returns true if a new message was received */
|
||||
bool rds_process(uint16_t data[4])
|
||||
/* processes one rds packet */
|
||||
void rds_process(const uint16_t data[4])
|
||||
{
|
||||
int group;
|
||||
|
||||
|
@ -240,53 +399,98 @@ bool rds_process(uint16_t data[4])
|
|||
pi_code = pi;
|
||||
}
|
||||
pi_last = pi;
|
||||
|
||||
|
||||
/* handle rds data based on group */
|
||||
group = (data[1] >> 11) & 0x1F;
|
||||
switch (group) {
|
||||
|
||||
|
||||
case 0: /* group 0A: basic info */
|
||||
case 1: /* group 0B: basic info */
|
||||
return handle_group0(data);
|
||||
|
||||
handle_group0(data);
|
||||
break;
|
||||
|
||||
case 4: /* group 2A: radio text */
|
||||
case 5: /* group 2B: radio text */
|
||||
return handle_group2(data);
|
||||
handle_group2(data);
|
||||
break;
|
||||
|
||||
case 8: /* group 4A: clock-time */
|
||||
return handle_group4a(data);
|
||||
|
||||
default:
|
||||
handle_group4a(data);
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
register_activity();
|
||||
}
|
||||
#endif /* (CONFIG_RDS & RDS_CFG_PROCESS) */
|
||||
|
||||
/* TODO: The caller really should provide the buffer in order to regulate
|
||||
access */
|
||||
|
||||
/* returns the programme identification code */
|
||||
uint16_t rds_get_pi(void)
|
||||
#if (CONFIG_RDS & RDS_CFG_PUSH)
|
||||
/* pushes preprocesed RDS information */
|
||||
void rds_push_info(enum rds_info_id info_id, uintptr_t data, size_t size)
|
||||
{
|
||||
return pi_code;
|
||||
}
|
||||
switch (info_id) {
|
||||
#if 0
|
||||
case RDS_INFO_CODETABLE:
|
||||
/* nothing doing for now */
|
||||
break;
|
||||
#endif
|
||||
case RDS_INFO_PI:
|
||||
pi_code = (uint16_t)data;
|
||||
break;
|
||||
case RDS_INFO_PS:
|
||||
strmemcpy(ps_copy, (const char *)data, MIN(size, sizeof (ps_copy)-1));
|
||||
SET_TIMEOUT(ps_copy_tmo, TEXT_TIMEOUT);
|
||||
break;
|
||||
case RDS_INFO_RT:
|
||||
strmemcpy(rt_copy, (const char *)data, MIN(size, sizeof (rt_copy)-1));
|
||||
SET_TIMEOUT(rt_copy_tmo, TEXT_TIMEOUT);
|
||||
break;
|
||||
case RDS_INFO_CT:
|
||||
ct_data = (time_t)data;
|
||||
break;
|
||||
|
||||
/* returns the most recent valid programme service name */
|
||||
char* rds_get_ps(void)
|
||||
default:;
|
||||
}
|
||||
|
||||
register_activity();
|
||||
}
|
||||
#endif /* (CONFIG_RDS & RDS_CFG_PUSH) */
|
||||
|
||||
/* read fully-processed RDS data */
|
||||
size_t rds_pull_info(enum rds_info_id info_id, uintptr_t data, size_t size)
|
||||
{
|
||||
return get_ps();
|
||||
}
|
||||
int oldlevel = rds_disable_irq_save();
|
||||
|
||||
/* returns the most recent valid RadioText message */
|
||||
char* rds_get_rt(void)
|
||||
{
|
||||
return get_rt();
|
||||
}
|
||||
rds_sync();
|
||||
|
||||
/* returns the most recent valid clock-time value (or 0 if invalid) */
|
||||
time_t rds_get_ct(void)
|
||||
{
|
||||
return ct_data;
|
||||
}
|
||||
switch (info_id) {
|
||||
#if 0
|
||||
case RDS_INFO_CODETABLE:
|
||||
/* nothing doing for now */
|
||||
break;
|
||||
#endif
|
||||
case RDS_INFO_PI:
|
||||
if (size >= sizeof (uint16_t)) {
|
||||
*(uint16_t *)data = pi_code;
|
||||
}
|
||||
size = sizeof (uint16_t);
|
||||
break;
|
||||
case RDS_INFO_PS:
|
||||
size = copy_rds_string((char *)data, ps_copy, size);
|
||||
break;
|
||||
case RDS_INFO_RT:
|
||||
size = copy_rds_string((char *)data, rt_copy, size);
|
||||
break;
|
||||
case RDS_INFO_CT:
|
||||
if (size >= sizeof (time_t)) {
|
||||
*(time_t *)data = ct_data;
|
||||
}
|
||||
size = sizeof (time_t);
|
||||
break;
|
||||
|
||||
default:
|
||||
size = 0;
|
||||
}
|
||||
|
||||
rds_restore_irq(oldlevel);
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "adc.h"
|
||||
#include "settings.h"
|
||||
#include "power.h"
|
||||
#include "rds.h"
|
||||
|
||||
static unsigned char tuner_param = 0x00, old_tuner_param = 0xFF;
|
||||
/* temp var for tests to avoid looping execution in submenus settings*/
|
||||
|
@ -40,7 +41,6 @@ int radio_present = 0;
|
|||
static int tuner_frequency = 0;
|
||||
static int tuner_signal_power = 0;
|
||||
static bool radio_tuned = false;
|
||||
static bool rds_event = false;
|
||||
|
||||
static char rds_radioname[9];
|
||||
static char rds_radioinfo[65];
|
||||
|
@ -90,6 +90,7 @@ static void rmt_tuner_sleep(int state)
|
|||
{
|
||||
if (state == 0)
|
||||
{
|
||||
rds_init();
|
||||
tuner_param = 0x00;
|
||||
old_tuner_param = 0xFF;
|
||||
mono_mode = -1;
|
||||
|
@ -273,13 +274,12 @@ void rmt_tuner_rds_data(unsigned int len, const unsigned char *buf)
|
|||
{
|
||||
if (buf[2] == 0x1E)
|
||||
{
|
||||
strlcpy(rds_radioname,buf+4,8);
|
||||
rds_push_info(RDS_INFO_PS, (uintptr_t)(buf+4), 8);
|
||||
}
|
||||
else if(buf[2] == 0x04)
|
||||
{
|
||||
strlcpy(rds_radioinfo,buf+4,len-4);
|
||||
rds_push_info(RDS_INFO_RT, (uintptr_t)(buf+4), len-4);
|
||||
}
|
||||
rds_event = true;
|
||||
}
|
||||
|
||||
/* tuner abstraction layer: set something to the tuner */
|
||||
|
@ -421,31 +421,6 @@ int ipod_rmt_tuner_get(int setting)
|
|||
case RADIO_STEREO:
|
||||
val = true;
|
||||
break;
|
||||
|
||||
case RADIO_EVENT:
|
||||
if (rds_event)
|
||||
{
|
||||
val = 1;
|
||||
rds_event = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
char* ipod_get_rds_info(int setting)
|
||||
{
|
||||
char *text = NULL;
|
||||
|
||||
switch(setting)
|
||||
{
|
||||
case RADIO_RDS_NAME:
|
||||
text = rds_radioname;
|
||||
break;
|
||||
|
||||
case RADIO_RDS_TEXT:
|
||||
text = rds_radioinfo;
|
||||
break;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -213,9 +213,6 @@
|
|||
static bool tuner_present = false;
|
||||
static uint16_t cache[16];
|
||||
static struct mutex fmr_mutex SHAREDBSS_ATTR;
|
||||
#ifdef HAVE_RDS_CAP
|
||||
static int rds_event = 0;
|
||||
#endif
|
||||
|
||||
/* reads <len> registers from radio at offset 0x0A into cache */
|
||||
static void si4700_read(int len)
|
||||
|
@ -373,6 +370,7 @@ void si4700_init(void)
|
|||
si4700_sleep(1);
|
||||
|
||||
#ifdef HAVE_RDS_CAP
|
||||
rds_init();
|
||||
si4700_rds_init();
|
||||
#endif
|
||||
}
|
||||
|
@ -528,21 +526,6 @@ int si4700_get(int setting)
|
|||
case RADIO_RSSI_MAX:
|
||||
val = RSSI_MAX;
|
||||
break;
|
||||
|
||||
#ifdef HAVE_RDS_CAP
|
||||
case RADIO_EVENT:
|
||||
{
|
||||
#ifdef RDS_ISR_PROCESSING
|
||||
int oldlevel = disable_irq_save();
|
||||
#endif
|
||||
val = rds_event;
|
||||
rds_event = 0;
|
||||
#ifdef RDS_ISR_PROCESSING
|
||||
restore_irq(oldlevel);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
mutex_unlock(&fmr_mutex);
|
||||
|
@ -567,77 +550,45 @@ void si4700_dbg_info(struct si4700_dbg_info *nfo)
|
|||
|
||||
#ifdef HAVE_RDS_CAP
|
||||
|
||||
#ifdef RDS_ISR_PROCESSING
|
||||
/* Read raw RDS info for processing - in ISR */
|
||||
#if (CONFIG_RDS & RDS_CFG_ISR)
|
||||
static unsigned char isr_regbuf[(RDSD - STATUSRSSI + 1) * 2];
|
||||
|
||||
/* Assumes regbuf is 32 bytes */
|
||||
void si4700_rds_read_raw_async(void)
|
||||
/* Called by RDS interrupt on target */
|
||||
void si4700_rds_interrupt(void)
|
||||
{
|
||||
si4700_read_raw_async((RDSD - STATUSRSSI + 1) * 2);
|
||||
si4700_rds_read_raw_async(isr_regbuf, sizeof (isr_regbuf));
|
||||
}
|
||||
|
||||
void si4700_rds_read_raw_async_complete(unsigned char *regbuf,
|
||||
uint16_t data[4])
|
||||
/* Handle RDS event from ISR */
|
||||
void si4700_rds_process(void)
|
||||
{
|
||||
const int index = (RDSA - STATUSRSSI) * 2;
|
||||
uint16_t rds_data[4];
|
||||
int index = (RDSA - STATUSRSSI) * 2;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
data[i] = regbuf[index] << 8 | regbuf[index + 1];
|
||||
regbuf += 2;
|
||||
rds_data[i] = isr_regbuf[index] << 8 | isr_regbuf[index + 1];
|
||||
index += 2;
|
||||
}
|
||||
|
||||
rds_process(rds_data);
|
||||
}
|
||||
|
||||
/* Set the event flag */
|
||||
void si4700_rds_set_event(void)
|
||||
{
|
||||
rds_event = 1;
|
||||
}
|
||||
#else /* !(CONFIG_RDS & RDS_CFG_ISR) */
|
||||
|
||||
#else /* ndef RDS_ISR_PROCESSING */
|
||||
/* Read raw RDS info for processing */
|
||||
bool si4700_rds_read_raw(uint16_t data[4])
|
||||
/* Handle RDS event from thread */
|
||||
void si4700_rds_process(void)
|
||||
{
|
||||
bool retval = false;
|
||||
|
||||
mutex_lock(&fmr_mutex);
|
||||
|
||||
if (tuner_powered())
|
||||
{
|
||||
si4700_read_reg(RDSD);
|
||||
memcpy(data, &cache[RDSA], 4 * sizeof (uint16_t));
|
||||
retval = true;
|
||||
rds_process(&cache[RDSA]);
|
||||
}
|
||||
|
||||
mutex_unlock(&fmr_mutex);
|
||||
|
||||
return retval;
|
||||
}
|
||||
#endif /* (CONFIG_RDS & RDS_CFG_ISR) */
|
||||
|
||||
/* Set the event flag */
|
||||
void si4700_rds_set_event(void)
|
||||
{
|
||||
mutex_lock(&fmr_mutex);
|
||||
rds_event = 1;
|
||||
mutex_unlock(&fmr_mutex);
|
||||
}
|
||||
#endif /* RDS_ISR_PROCESSING */
|
||||
|
||||
char * si4700_get_rds_info(int setting)
|
||||
{
|
||||
char *text = NULL;
|
||||
|
||||
switch(setting)
|
||||
{
|
||||
case RADIO_RDS_NAME:
|
||||
text = rds_get_ps();
|
||||
break;
|
||||
|
||||
case RADIO_RDS_TEXT:
|
||||
text = rds_get_rt();
|
||||
break;
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
#endif /* HAVE_RDS_CAP */
|
||||
|
||||
|
|
|
@ -712,6 +712,16 @@ Lyre prototype 1 */
|
|||
#define BATTERY_CAPACITY_INC 0
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RDS_CAP
|
||||
/* combinable bitflags */
|
||||
#define RDS_CFG_ISR 0x1 /* uses ISR to process packets */
|
||||
#define RDS_CFG_PROCESS 0x2 /* uses raw packet processing */
|
||||
#define RDS_CFG_PUSH 0x4 /* pushes processed information */
|
||||
#ifndef CONFIG_RDS
|
||||
#define CONFIG_RDS RDS_CFG_PROCESS /* thread processing+raw processing */
|
||||
#endif /* CONFIG_RDS */
|
||||
#endif /* HAVE_RDS_CAP */
|
||||
|
||||
#ifndef CONFIG_ORIENTATION
|
||||
#if LCD_HEIGHT > LCD_WIDTH
|
||||
#define CONFIG_ORIENTATION SCREEN_PORTRAIT
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
/* Define this if you have a SI4700 fm radio tuner */
|
||||
#define CONFIG_TUNER SI4700
|
||||
#define HAVE_RDS_CAP
|
||||
#define RDS_ISR_PROCESSING
|
||||
#define CONFIG_RDS (RDS_CFG_ISR | RDS_CFG_PROCESS)
|
||||
|
||||
/* define this if you can flip your LCD */
|
||||
#define HAVE_LCD_FLIP
|
||||
|
|
|
@ -164,6 +164,7 @@
|
|||
/* Define Apple remote tuner */
|
||||
#define CONFIG_TUNER IPOD_REMOTE_TUNER
|
||||
#define HAVE_RDS_CAP
|
||||
#define CONFIG_RDS RDS_CFG_PUSH
|
||||
|
||||
/* Define this if you have a PortalPlayer PP5020 */
|
||||
#define CONFIG_CPU PP5020
|
||||
|
|
|
@ -167,6 +167,7 @@
|
|||
/* Define Apple remote tuner */
|
||||
//#define CONFIG_TUNER IPOD_REMOTE_TUNER
|
||||
//#define HAVE_RDS_CAP
|
||||
//#define CONFIG_RDS RDS_CFG_PUSH
|
||||
|
||||
/* The exact type of CPU */
|
||||
#define CONFIG_CPU S5L8702
|
||||
|
|
|
@ -151,6 +151,7 @@
|
|||
/* Define Apple remote tuner */
|
||||
#define CONFIG_TUNER IPOD_REMOTE_TUNER
|
||||
#define HAVE_RDS_CAP
|
||||
#define CONFIG_RDS RDS_CFG_PUSH
|
||||
|
||||
/* Define this if you have a PortalPlayer PP5020 */
|
||||
#define CONFIG_CPU PP5020
|
||||
|
|
|
@ -163,6 +163,7 @@
|
|||
/* Define Apple remote tuner */
|
||||
#define CONFIG_TUNER IPOD_REMOTE_TUNER
|
||||
#define HAVE_RDS_CAP
|
||||
#define CONFIG_RDS RDS_CFG_PUSH
|
||||
|
||||
/* Define this if you have a PortalPlayer PP5020 */
|
||||
#define CONFIG_CPU PP5020
|
||||
|
|
|
@ -164,6 +164,7 @@
|
|||
/* Define Apple remote tuner */
|
||||
#define CONFIG_TUNER IPOD_REMOTE_TUNER
|
||||
#define HAVE_RDS_CAP
|
||||
#define CONFIG_RDS RDS_CFG_PUSH
|
||||
|
||||
/* Define this if you have a PortalPlayer PP5022 */
|
||||
#define CONFIG_CPU PP5022
|
||||
|
|
|
@ -154,6 +154,7 @@
|
|||
/* Define Apple remote tuner */
|
||||
#define CONFIG_TUNER IPOD_REMOTE_TUNER
|
||||
#define HAVE_RDS_CAP
|
||||
#define CONFIG_RDS RDS_CFG_PUSH
|
||||
|
||||
/* Define this if you have a PortalPlayer PP5022 */
|
||||
#define CONFIG_CPU PP5022
|
||||
|
|
|
@ -164,6 +164,7 @@
|
|||
/* Define Apple remote tuner */
|
||||
//#define CONFIG_TUNER IPOD_REMOTE_TUNER
|
||||
//#define HAVE_RDS_CAP
|
||||
//#define CONFIG_RDS RDS_CFG_PUSH
|
||||
|
||||
/* The exact type of CPU */
|
||||
#define CONFIG_CPU S5L8701
|
||||
|
|
|
@ -170,6 +170,7 @@
|
|||
/* Define Apple remote tuner */
|
||||
#define CONFIG_TUNER IPOD_REMOTE_TUNER
|
||||
#define HAVE_RDS_CAP
|
||||
#define CONFIG_RDS RDS_CFG_PUSH
|
||||
|
||||
/* Define this if you have a PortalPlayer PP5022 */
|
||||
#define CONFIG_CPU PP5022
|
||||
|
|
|
@ -33,13 +33,10 @@ extern void rmt_tuner_rds_data(unsigned int len, const unsigned char *buf);
|
|||
|
||||
int ipod_rmt_tuner_set(int setting, int value);
|
||||
int ipod_rmt_tuner_get(int setting);
|
||||
char* ipod_get_rds_info(int setting);
|
||||
|
||||
|
||||
#ifndef CONFIG_TUNER_MULTI
|
||||
#define tuner_set ipod_rmt_tuner_set
|
||||
#define tuner_get ipod_rmt_tuner_get
|
||||
#define tuner_get_rds_info ipod_get_rds_info
|
||||
#endif
|
||||
|
||||
#endif /* _IPOD_REMOTE_TUNER_H_ */
|
||||
|
|
|
@ -18,18 +18,45 @@
|
|||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef RDS_H
|
||||
#define RDS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "time.h"
|
||||
|
||||
void rds_init(void);
|
||||
|
||||
void rds_reset(void);
|
||||
bool rds_process(uint16_t data[4]);
|
||||
void rds_sync(void);
|
||||
|
||||
uint16_t rds_get_pi(void);
|
||||
char* rds_get_ps(void);
|
||||
char* rds_get_rt(void);
|
||||
time_t rds_get_ct(void);
|
||||
#if (CONFIG_RDS & RDS_CFG_PROCESS)
|
||||
/* RDS raw data processing */
|
||||
void rds_process(const uint16_t data[4]);
|
||||
#endif /* (CONFIG_RDS & RDS_CFG_PROCESS) */
|
||||
|
||||
enum rds_info_id
|
||||
{
|
||||
RDS_INFO_NULL = 0,
|
||||
RDS_INFO_CODEABLE, /* code table, right now only G0 */
|
||||
RDS_INFO_PI, /* programme identifier */
|
||||
RDS_INFO_PS, /* programme service name */
|
||||
RDS_INFO_RT, /* radio text */
|
||||
RDS_INFO_CT, /* clock time */
|
||||
};
|
||||
|
||||
enum rds_code_table
|
||||
{
|
||||
RDS_CT_G0, /* default code table G0 */
|
||||
RDS_CT_G1, /* alternate code table G1 */
|
||||
RDS_CT_G2, /* alternate code table G2 */
|
||||
};
|
||||
|
||||
#if (CONFIG_RDS & RDS_CFG_PUSH)
|
||||
/* pushes preprocesed RDS information */
|
||||
void rds_push_info(enum rds_info_id info_id, uintptr_t data, size_t size);
|
||||
#endif /* (CONFIG_RDS & RDS_CFG_PUSH) */
|
||||
|
||||
/* read fully-processed RDS data */
|
||||
size_t rds_pull_info(enum rds_info_id info_id, uintptr_t data, size_t size);
|
||||
|
||||
#endif /* RDS_H */
|
||||
|
|
|
@ -35,36 +35,34 @@ struct si4700_dbg_info
|
|||
};
|
||||
|
||||
bool si4700_detect(void);
|
||||
void si4700_init(void);
|
||||
void si4700_init(void) INIT_ATTR;
|
||||
int si4700_set(int setting, int value);
|
||||
int si4700_get(int setting);
|
||||
void si4700_dbg_info(struct si4700_dbg_info *nfo);
|
||||
/* For interrupt-based mono/stereo indicator */
|
||||
bool si4700_st(void);
|
||||
|
||||
#ifdef HAVE_RDS_CAP
|
||||
/** RDS support **/
|
||||
void si4700_rds_init(void);
|
||||
|
||||
void si4700_rds_init(void) INIT_ATTR;
|
||||
/* Radio is fully powered up or about to be powered down */
|
||||
void si4700_rds_powerup(bool on);
|
||||
#ifdef RDS_ISR_PROCESSING
|
||||
|
||||
#if (CONFIG_RDS & RDS_CFG_ISR)
|
||||
/* Read raw RDS info for processing - asynchronously */
|
||||
void si4700_read_raw_async(int count); /* implemented by target */
|
||||
void si4700_rds_read_raw_async(void);
|
||||
void si4700_rds_read_raw_async_complete(unsigned char *regbuf,
|
||||
uint16_t data[4]);
|
||||
#else /* ndef RDS_ISR_PROCESSING */
|
||||
void si4700_rds_read_raw_async(unsigned char *buf, int count); /* implemented by target */
|
||||
void si4700_rds_interrupt(void);
|
||||
#endif /* (CONFIG_RDS & RDS_CFG_ISR) */
|
||||
|
||||
/* Read raw RDS info for processing */
|
||||
bool si4700_rds_read_raw(uint16_t data[4]);
|
||||
#endif /* RDS_ISR_PROCESSING */
|
||||
/* Obtain specified string */
|
||||
char* si4700_get_rds_info(int setting);
|
||||
/* Set the event flag */
|
||||
void si4700_rds_set_event(void);
|
||||
void si4700_rds_process(void);
|
||||
|
||||
#endif /* HAVE_RDS_CAP */
|
||||
|
||||
#ifndef CONFIG_TUNER_MULTI
|
||||
#define tuner_set si4700_set
|
||||
#define tuner_get si4700_get
|
||||
#define tuner_get_rds_info si4700_get_rds_info
|
||||
#endif
|
||||
|
||||
#endif /* _SI4700_H_ */
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
#include "config.h"
|
||||
#include "hwcompat.h"
|
||||
|
||||
#ifdef HAVE_RDS_CAP
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/** Settings to the tuner layer **/
|
||||
enum
|
||||
{
|
||||
|
@ -45,8 +49,6 @@ enum
|
|||
RADIO_PRESENT = 0,
|
||||
RADIO_TUNED,
|
||||
RADIO_STEREO,
|
||||
/* RADIO_EVENT is an event that requests a screen update */
|
||||
RADIO_EVENT,
|
||||
RADIO_RSSI,
|
||||
RADIO_RSSI_MIN,
|
||||
RADIO_RSSI_MAX,
|
||||
|
@ -57,15 +59,20 @@ enum
|
|||
|
||||
#ifdef HAVE_RDS_CAP
|
||||
/** Readback from the tuner RDS layer **/
|
||||
enum
|
||||
/* returns needed size if buffer size is inadequate */
|
||||
size_t tuner_get_rds_info(int setting, void *dst, size_t dstsize);
|
||||
|
||||
enum RADIO_RDS_INFO
|
||||
{
|
||||
RADIO_RDS_NAME,
|
||||
RADIO_RDS_TEXT,
|
||||
RADIO_RDS_NAME, /* dst: array of char, dstsize: buffer size */
|
||||
RADIO_RDS_TEXT, /* dst: array of char, dstsize: buffer size */
|
||||
RADIO_RDS_PROGRAM_INFO, /* dst: uint16_t *, dstsize: >= sizeof(uint16_t) */
|
||||
RADIO_RDS_CURRENT_TIME, /* dst: time_t *, dstsize: >= sizeof(time_t) */
|
||||
|
||||
/* Put new general-purpose readback values above this line */
|
||||
__RADIO_GET_RDS_INFO_STANDARD_LAST
|
||||
};
|
||||
#endif
|
||||
#endif /* HAVE_RDS_CAP */
|
||||
|
||||
/** Tuner regions **/
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "generic_i2c.h"
|
||||
#include "fmradio_i2c.h"
|
||||
#include "thread.h"
|
||||
#include "rds.h"
|
||||
|
||||
#if defined(SANSA_CLIP) || defined(SANSA_C200V2)
|
||||
#define I2C_SCL_GPIO(x) GPIOB_PIN(x)
|
||||
|
@ -203,13 +202,9 @@ void tuner_isr(void)
|
|||
/* Captures RDS data and processes it */
|
||||
static void NORETURN_ATTR rds_thread(void)
|
||||
{
|
||||
uint16_t rds_data[4];
|
||||
|
||||
while (true) {
|
||||
semaphore_wait(&rds_sema, TIMEOUT_BLOCK);
|
||||
if (si4700_rds_read_raw(rds_data) && rds_process(rds_data)) {
|
||||
si4700_rds_set_event();
|
||||
}
|
||||
si4700_rds_process();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,7 +228,6 @@ void si4700_rds_powerup(bool on)
|
|||
void si4700_rds_init(void)
|
||||
{
|
||||
semaphore_init(&rds_sema, 1, 0);
|
||||
rds_init();
|
||||
create_thread(rds_thread, rds_stack, sizeof(rds_stack), 0, "rds"
|
||||
IF_PRIO(, PRIORITY_REALTIME) IF_COP(, CPU));
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "system.h"
|
||||
#include "kernel.h"
|
||||
#include "pinctrl-imx233.h"
|
||||
#include "rds.h"
|
||||
#include "si4700.h"
|
||||
|
||||
/**
|
||||
|
@ -52,13 +51,11 @@ static void stc_rds_callback(int bank, int pin, intptr_t user)
|
|||
/* Captures RDS data and processes it */
|
||||
static void NORETURN_ATTR rds_thread(void)
|
||||
{
|
||||
uint16_t rds_data[4];
|
||||
|
||||
while(true)
|
||||
{
|
||||
semaphore_wait(&rds_sema, TIMEOUT_BLOCK);
|
||||
if(si4700_rds_read_raw(rds_data) && rds_process(rds_data))
|
||||
si4700_rds_set_event();
|
||||
si4700_rds_process();
|
||||
|
||||
/* renable callback */
|
||||
imx233_pinctrl_setup_irq(2, 27, true, true, false, &stc_rds_callback, 0);
|
||||
}
|
||||
|
@ -86,7 +83,6 @@ void si4700_rds_powerup(bool on)
|
|||
void si4700_rds_init(void)
|
||||
{
|
||||
semaphore_init(&rds_sema, 1, 0);
|
||||
rds_init();
|
||||
create_thread(rds_thread, rds_stack, sizeof(rds_stack), 0, "rds"
|
||||
IF_PRIO(, PRIORITY_REALTIME) IF_COP(, CPU));
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "gpio-target.h"
|
||||
#include "i2c-imx31.h"
|
||||
#include "fmradio_i2c.h"
|
||||
#include "rds.h"
|
||||
#include "tuner.h"
|
||||
|
||||
static struct i2c_node si4700_i2c_node =
|
||||
|
@ -128,60 +127,44 @@ bool si4700_st(void)
|
|||
|
||||
|
||||
/* Low-level RDS Support */
|
||||
|
||||
/* Transfer descriptor for RDS async operations */
|
||||
static struct si4700_i2c_transfer_desc
|
||||
{
|
||||
struct i2c_transfer_desc xfer;
|
||||
unsigned char regbuf[32];
|
||||
} si4700_xfer =
|
||||
{
|
||||
.xfer = { .node = &si4700_i2c_node }
|
||||
};
|
||||
|
||||
static bool int_restore;
|
||||
|
||||
static void si4700_rds_read_raw_callback(struct i2c_transfer_desc *xfer)
|
||||
/* Called after I2C read cycle completes */
|
||||
static void si4700_rds_read_raw_async_callback(struct i2c_transfer_desc *xfer)
|
||||
{
|
||||
struct si4700_i2c_transfer_desc *xf =
|
||||
(struct si4700_i2c_transfer_desc *)xfer;
|
||||
|
||||
if (xfer->rxcount == 0)
|
||||
{
|
||||
uint16_t rds_data[4];
|
||||
si4700_rds_read_raw_async_complete(xf->regbuf, rds_data);
|
||||
|
||||
if (rds_process(rds_data))
|
||||
si4700_rds_set_event();
|
||||
}
|
||||
si4700_rds_process();
|
||||
/* else read didn't finish */
|
||||
|
||||
if (int_restore)
|
||||
gpio_int_enable(SI4700_EVENT_ID);
|
||||
}
|
||||
|
||||
/* Callback from si4700_rds_read_raw to execute the read */
|
||||
void si4700_read_raw_async(int count)
|
||||
/* Called to read registers from ISR context */
|
||||
void si4700_rds_read_raw_async(unsigned char *buf, int count)
|
||||
{
|
||||
si4700_xfer.xfer.txdata = NULL;
|
||||
si4700_xfer.xfer.txcount = 0;
|
||||
si4700_xfer.xfer.rxdata = si4700_xfer.regbuf;
|
||||
si4700_xfer.xfer.rxcount = count;
|
||||
si4700_xfer.xfer.callback = si4700_rds_read_raw_callback;
|
||||
si4700_xfer.xfer.next = NULL;
|
||||
/* transfer descriptor for RDS async operations */
|
||||
static struct i2c_transfer_desc xfer = { .node = &si4700_i2c_node };
|
||||
|
||||
i2c_transfer(&si4700_xfer.xfer);
|
||||
xfer.txdata = NULL;
|
||||
xfer.txcount = 0;
|
||||
xfer.rxdata = buf;
|
||||
xfer.rxcount = count;
|
||||
xfer.callback = si4700_rds_read_raw_async_callback;
|
||||
xfer.next = NULL;
|
||||
|
||||
i2c_transfer(&xfer);
|
||||
}
|
||||
|
||||
/* RDS GPIO interrupt handler - start RDS data read */
|
||||
void INT_SI4700_RDS(void)
|
||||
{
|
||||
/* mask and clear the interrupt */
|
||||
/* mask and clear the interrupt until we're done */
|
||||
gpio_int_disable(SI4700_EVENT_ID);
|
||||
gpio_int_clear(SI4700_EVENT_ID);
|
||||
|
||||
/* read the RDS data */
|
||||
si4700_rds_read_raw_async();
|
||||
/* tell radio driver about it */
|
||||
si4700_rds_interrupt();
|
||||
}
|
||||
|
||||
/* Called with on=true after full radio power up, and with on=false before
|
||||
|
@ -197,5 +180,5 @@ void si4700_rds_powerup(bool on)
|
|||
/* One-time RDS init at startup */
|
||||
void si4700_rds_init(void)
|
||||
{
|
||||
rds_init();
|
||||
/* nothing to do */
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "kernel.h"
|
||||
|
||||
#include "radio-ypr.h"
|
||||
#include "rds.h"
|
||||
#include "si4700.h"
|
||||
#include "power.h"
|
||||
|
||||
|
@ -79,7 +78,6 @@ int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count)
|
|||
/* Low-level RDS Support */
|
||||
static struct event_queue rds_queue;
|
||||
static uint32_t rds_stack[DEFAULT_STACK_SIZE / sizeof(uint32_t)];
|
||||
static uint16_t rds_data[4];
|
||||
|
||||
enum {
|
||||
Q_POWERUP,
|
||||
|
@ -101,8 +99,7 @@ static void NORETURN_ATTR rds_thread(void)
|
|||
case SYS_TIMEOUT:
|
||||
/* Captures RDS data and processes it */
|
||||
if ((si4709_read_reg(STATUSRSSI) & STATUSRSSI_RDSR) >> 8) {
|
||||
if (si4700_rds_read_raw(rds_data) && rds_process(rds_data))
|
||||
si4700_rds_set_event();
|
||||
si4700_rds_process();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -121,6 +118,5 @@ void si4700_rds_init(void)
|
|||
queue_init(&rds_queue, false);
|
||||
create_thread(rds_thread, rds_stack, sizeof(rds_stack), 0, "rds"
|
||||
IF_PRIO(, PRIORITY_PLAYBACK) IF_COP(, CPU));
|
||||
rds_init();
|
||||
}
|
||||
#endif /* HAVE_RDS_CAP */
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include "kernel.h"
|
||||
#include "tuner.h"
|
||||
#include "fmradio.h"
|
||||
#ifdef HAVE_RDS_CAP
|
||||
#include "rds.h"
|
||||
#endif /* HAVE_RDS_CAP */
|
||||
|
||||
/* General region information */
|
||||
const struct fm_region_data fm_region_data[TUNER_NUM_REGIONS] =
|
||||
|
@ -102,4 +105,24 @@ void tuner_init(void)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_RDS_CAP
|
||||
size_t tuner_get_rds_info(int setting, void *dst, size_t dstsize)
|
||||
{
|
||||
/* TODO: integrate this into tuner_get/set */
|
||||
static const unsigned char info_id_tbl[] =
|
||||
{
|
||||
[RADIO_RDS_NAME] = RDS_INFO_PS,
|
||||
[RADIO_RDS_TEXT] = RDS_INFO_RT,
|
||||
[RADIO_RDS_PROGRAM_INFO] = RDS_INFO_PI,
|
||||
[RADIO_RDS_CURRENT_TIME] = RDS_INFO_CT,
|
||||
};
|
||||
|
||||
if ((unsigned int)setting >= ARRAYLEN(info_id_tbl))
|
||||
return 0;
|
||||
|
||||
return rds_pull_info(info_id_tbl[setting], (uintptr_t)dst, dstsize);
|
||||
}
|
||||
#endif /* HAVE_RDS_CAP */
|
||||
|
||||
#endif /* SIMULATOR */
|
||||
|
|
Loading…
Reference in a new issue