aboutsummaryrefslogtreecommitdiffstats
path: root/binding/radio_impl_tef665x.c
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2020-12-06 16:17:51 -0500
committerScott Murray <scott.murray@konsulko.com>2020-12-06 16:24:43 -0500
commit47d61abc94a8c7140c3950329890d0f71f5714eb (patch)
tree23458664ae2611950d75330d15b88154cf3ceff3 /binding/radio_impl_tef665x.c
parentd4fb6eb7a4648b74f930af667f9231226e4ce208 (diff)
Rework hardware probing and RTL-SDR helper startup
The lazy startup of the separate helper program for the RTL-SDR backend on playback start was incorrect with respect to the expected behavior the frequency setting verbs. This was not visible during usage by the radio application, but was triggering failures in several tests in the pyagl binding wrapper test suite. To facilitate starting the helper during backend initialization, the probing part of the backend "init" has been split into a separate "probe" function, and all backends have been updated to reflect this change. Logic has been added to enforce that "init" is only called after "probe" has succeeded for a backend, and a comment has been added to radio_impl.h to document this intended behavior. Bug-AGL: SPEC-3717 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: Ic37331a92bae7cc01ee448e69894fa5f49d08a74
Diffstat (limited to 'binding/radio_impl_tef665x.c')
-rw-r--r--binding/radio_impl_tef665x.c46
1 files changed, 34 insertions, 12 deletions
diff --git a/binding/radio_impl_tef665x.c b/binding/radio_impl_tef665x.c
index 504f155..9bad684 100644
--- a/binding/radio_impl_tef665x.c
+++ b/binding/radio_impl_tef665x.c
@@ -137,9 +137,10 @@ static band_plan_t known_am_band_plans[1] = {
static unsigned int fm_bandplan = 2;
static unsigned int am_bandplan = 0;
-static bool corking = false;
-static bool present = false;
-static bool scanning = false;
+static bool corking;
+static bool present;
+static bool initialized;
+static bool scanning;
// stream state
static GstElement *pipeline;
@@ -1626,7 +1627,8 @@ static int i2c_init(const char *i2c, int state, uint32_t *i2c_file_desc)
static void tef665x_start(void)
{
int ret;
- if(!present)
+
+ if(!initialized)
return;
_debug("file_desc ", file_desc);
@@ -2078,7 +2080,7 @@ static void tef665x_stop(void)
GstEvent *event;
audio_set_mute(file_desc, 1);
- if(present && running) {
+ if(initialized && running) {
// Stop pipeline
running = false;
ret = gst_element_set_state(pipeline, GST_STATE_PAUSED);
@@ -2093,13 +2095,12 @@ static void tef665x_stop(void)
}
}
-static int tef665x_init()
+static int tef665x_probe()
{
- char gst_pipeline_str[GST_PIPELINE_LEN];
int rc;
- current_am_frequency = known_am_band_plans[am_bandplan].min;
- current_fm_frequency = known_fm_band_plans[fm_bandplan].min;
+ if(present)
+ return 0;
rc = i2c_init(I2C_DEV, _open, &file_desc);
if(rc < 0) {
@@ -2114,6 +2115,24 @@ static int tef665x_init()
return -1;
}
+ present = true;
+ return 0;
+}
+
+static int tef665x_init()
+{
+ char gst_pipeline_str[GST_PIPELINE_LEN];
+ int rc;
+
+ if(!present)
+ return -1;
+
+ if(initialized)
+ return 0;
+
+ current_am_frequency = known_am_band_plans[am_bandplan].min;
+ current_fm_frequency = known_fm_band_plans[fm_bandplan].min;
+
current_band = BAND_AM;
radio_powerSwitch(file_desc, 1);
@@ -2150,12 +2169,12 @@ static int tef665x_init()
rc = gst_bus_add_watch(gst_element_get_bus(pipeline), (GstBusFunc) handle_message, NULL);
_debug("gst_bus_add_watch rc", rc);
- present = true;
-
//Initialize Mutex Lock for Scan and RDS
pthread_mutex_init(&scan_mutex, NULL);
pthread_mutex_init (&RDS_Mutex, NULL);
+ initialized = true;
+
tef665x_start();
return 0;
}
@@ -2226,7 +2245,8 @@ static void tef665x_set_alternative_frequency(uint32_t frequency)
static void tef665x_set_frequency(uint32_t frequency)
{
uint32_t fd = 0;
- if(!present)
+
+ if(!initialized)
return;
if(scanning)
@@ -2357,8 +2377,10 @@ static uint32_t tef665x_get_frequency_step(radio_band_t band)
}
return ret;
}
+
radio_impl_ops_t tef665x_impl_ops = {
.name = "TEF665x",
+ .probe = tef665x_probe,
.init = tef665x_init,
.start = tef665x_start,
.stop = tef665x_stop,