diff options
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/rds.c | 39 | ||||
-rw-r--r-- | firmware/drivers/tuner/si4700.c | 29 |
2 files changed, 66 insertions, 2 deletions
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]; | |||
36 | static int rt_segment; | 36 | static int rt_segment; |
37 | static int rt_abflag; | 37 | static int rt_abflag; |
38 | 38 | ||
39 | #ifdef SI4700_RDS_ASYNC | ||
40 | /* Functions are called in ISR context */ | ||
41 | #define rds_disable_irq_save() disable_irq_save() | ||
42 | #define rds_restore_irq(old) restore_irq(old) | ||
43 | /* Need triple buffer so string isn't clobbered while caller is using it */ | ||
44 | static inline char * get_ps(void) | ||
45 | { | ||
46 | static char ps_out[9]; | ||
47 | int oldlevel = rds_disable_irq_save(); | ||
48 | strcpy(ps_out, ps_copy); | ||
49 | rds_restore_irq(oldlevel); | ||
50 | return ps_out; | ||
51 | } | ||
52 | static inline char * get_rt(void) | ||
53 | { | ||
54 | static char rt_out[65]; | ||
55 | int oldlevel = rds_disable_irq_save(); | ||
56 | strcpy(rt_out, rt_copy); | ||
57 | rds_restore_irq(oldlevel); | ||
58 | return rt_out; | ||
59 | } | ||
60 | #else /* ndef SI4700_RDS_ASYNC */ | ||
61 | #define rds_disable_irq_save() 0 | ||
62 | #define rds_restore_irq(old) ((void)(old)) | ||
63 | static inline char * get_ps(void) { return ps_copy; } | ||
64 | static inline char * get_rt(void) { return rt_copy; } | ||
65 | #endif /* SI4700_RDS_ASYNC */ | ||
66 | |||
39 | /* resets the rds parser */ | 67 | /* resets the rds parser */ |
40 | void rds_reset(void) | 68 | void rds_reset(void) |
41 | { | 69 | { |
70 | int oldlevel = rds_disable_irq_save(); | ||
71 | |||
42 | ps_copy[0] = '\0'; | 72 | ps_copy[0] = '\0'; |
43 | ps_segment = 0; | 73 | ps_segment = 0; |
44 | rt_copy[0] = '\0'; | 74 | rt_copy[0] = '\0'; |
45 | rt_segment = 0; | 75 | rt_segment = 0; |
46 | pi = 0; | 76 | pi = 0; |
77 | |||
78 | rds_restore_irq(oldlevel); | ||
47 | } | 79 | } |
48 | 80 | ||
49 | /* initialises the rds parser */ | 81 | /* initialises the rds parser */ |
@@ -172,6 +204,9 @@ bool rds_process(uint16_t data[4]) | |||
172 | return false; | 204 | return false; |
173 | } | 205 | } |
174 | 206 | ||
207 | /* TODO: The caller really should provide the buffer in order to regulate | ||
208 | access */ | ||
209 | |||
175 | /* returns the programme identification code */ | 210 | /* returns the programme identification code */ |
176 | uint16_t rds_get_pi(void) | 211 | uint16_t rds_get_pi(void) |
177 | { | 212 | { |
@@ -181,12 +216,12 @@ uint16_t rds_get_pi(void) | |||
181 | /* returns the most recent valid programme service name */ | 216 | /* returns the most recent valid programme service name */ |
182 | char* rds_get_ps(void) | 217 | char* rds_get_ps(void) |
183 | { | 218 | { |
184 | return ps_copy; | 219 | return get_ps(); |
185 | } | 220 | } |
186 | 221 | ||
187 | /* returns the most recent valid RadioText message */ | 222 | /* returns the most recent valid RadioText message */ |
188 | char* rds_get_rt(void) | 223 | char* rds_get_rt(void) |
189 | { | 224 | { |
190 | return rt_copy; | 225 | return get_rt(); |
191 | } | 226 | } |
192 | 227 | ||
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) | |||
556 | } | 556 | } |
557 | 557 | ||
558 | #ifdef HAVE_RDS_CAP | 558 | #ifdef HAVE_RDS_CAP |
559 | |||
560 | #ifdef SI4700_RDS_ASYNC | ||
561 | /* Read raw RDS info for processing - asynchronously */ | ||
562 | |||
563 | /* Assumes regbuf is 32 bytes */ | ||
564 | void si4700_rds_read_raw_async(void) | ||
565 | { | ||
566 | si4700_read_raw_async((RDSD - STATUSRSSI + 1) * 2); | ||
567 | } | ||
568 | |||
569 | void si4700_rds_read_raw_async_complete(unsigned char *regbuf, | ||
570 | uint16_t data[4]) | ||
571 | { | ||
572 | const int index = (RDSA - STATUSRSSI) * 2; | ||
573 | |||
574 | for (int i = 0; i < 4; i++) { | ||
575 | data[i] = regbuf[index] << 8 | regbuf[index + 1]; | ||
576 | regbuf += 2; | ||
577 | } | ||
578 | } | ||
579 | |||
580 | /* Set the event flag */ | ||
581 | void si4700_rds_set_event(void) | ||
582 | { | ||
583 | rds_event = 1; | ||
584 | } | ||
585 | |||
586 | #else | ||
559 | /* Read raw RDS info for processing */ | 587 | /* Read raw RDS info for processing */ |
560 | bool si4700_rds_read_raw(uint16_t data[4]) | 588 | bool si4700_rds_read_raw(uint16_t data[4]) |
561 | { | 589 | { |
@@ -582,6 +610,7 @@ void si4700_rds_set_event(void) | |||
582 | rds_event = 1; | 610 | rds_event = 1; |
583 | mutex_unlock(&fmr_mutex); | 611 | mutex_unlock(&fmr_mutex); |
584 | } | 612 | } |
613 | #endif /* SI4700_RDS_ASYNC */ | ||
585 | 614 | ||
586 | char * si4700_get_rds_info(int setting) | 615 | char * si4700_get_rds_info(int setting) |
587 | { | 616 | { |