Skip to content

Commit

Permalink
plugins: adrv9002: default to 0 value if attributes cannot be read in…
Browse files Browse the repository at this point in the history
… Live Device preset

- some attributes cannot be read if channel is disabled

Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w committed Jan 26, 2024
1 parent 616f5d9 commit 42180db
Showing 1 changed file with 12 additions and 56 deletions.
68 changes: 12 additions & 56 deletions plugins/adrv9002.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,21 +1388,11 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin

// tx.enabled
ret = iio_channel_attr_read(tx, "en", buf, sizeof(buf));
if(ret < 0) {
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "en",
ret);
goto iio_error;
}
tx_config[chann].enabled = atoi(buf);
tx_config[chann].enabled = ret < 0 ? 0 : 1;

// tx.sample_rate_hz
ret = iio_channel_attr_read(tx, "sampling_frequency", buf, sizeof(buf));
if(ret < 0) {
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str,
"sampling_frequency", ret);
goto iio_error;
}
tx_config[chann].sample_rate_hz = atoi(buf);
tx_config[chann].sample_rate_hz = ret < 0 ? 0 : atoi(buf);

// tx.frequency_offset_correction_enable
tx_config[chann].frequency_offset_correction_enable =
Expand All @@ -1414,12 +1404,7 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin

// tx.channel_bandwidth_hz
ret = iio_channel_attr_read(tx, "rf_bandwidth", buf, sizeof(buf));
if(ret < 0) {
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str,
"rf_bandwidth", ret);
goto iio_error;
}
tx_config[chann].channel_bandwidth_hz = atoi(buf);
tx_config[chann].channel_bandwidth_hz = ret < 0 ? 0 : atoi(buf);

// tx.elb_type
tx_config[chann].elb_type = default_cfg.radio_cfg.tx_config[chann].elb_type; // TODO
Expand All @@ -1441,21 +1426,11 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin

// rx.enabled
ret = iio_channel_attr_read(rx, "en", buf, sizeof(buf));
if(ret < 0) {
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str, "en",
ret);
goto iio_error;
}
rx_config[chann].enabled = atoi(buf);
rx_config[chann].enabled = ret < 0 ? 0 : 1;

// rx.sample_rate_hz
ret = iio_channel_attr_read(rx, "sampling_frequency", buf, sizeof(buf));
if(ret < 0) {
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str,
"sampling_frequency", ret);
goto iio_error;
}
rx_config[chann].sample_rate_hz = atoi(buf);
rx_config[chann].sample_rate_hz = ret < 0 ? 0 : atoi(buf);

// rx.frequency_offset_correction_enable
rx_config[chann].frequency_offset_correction_enable =
Expand All @@ -1467,22 +1442,12 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin

// rx.channel_bandwidth_hz
ret = iio_channel_attr_read(rx, "rf_bandwidth", buf, sizeof(buf));
if(ret < 0) {
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str,
"rf_bandwidth", ret);
goto iio_error;
}
rx_config[chann].channel_bandwidth_hz = atoi(buf);
rx_config[chann].channel_bandwidth_hz = ret < 0 ? 0 : atoi(buf);

// rx.adc_high_performance_mode
ret = iio_device_debug_attr_read(priv->adrv9002, chann == 0 ? "rx0_adc_type" : "rx1_adc_type",
buf, sizeof(buf));
if(ret < 0) {
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str,
chann == 0 ? "rx0_adc_type" : "rx1_adc_type", ret);
goto iio_error;
}
rx_config[chann].adc_high_performance_mode = strstr(buf, "HP") != NULL;
rx_config[chann].adc_high_performance_mode = ret < 0 ? 0 : strstr(buf, "HP") != NULL;

// rx.analog_filter_biquad
rx_config[chann].analog_filter_biquad =
Expand All @@ -1497,37 +1462,28 @@ static int profile_gen_config_get_from_device(struct adrv9002_config *cfg, gpoin

// rx.nco_frequency_hz
ret = iio_channel_attr_read(rx, "nco_frequency", buf, sizeof(buf));
if(ret < 0) {
if(ret == -ENOTSUPP) {
rx_config[chann].nco_frequency_hz = 0;
} else {
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str,
"nco_frequency", ret);
goto iio_error;
}
} else {
rx_config[chann].nco_frequency_hz = atoi(buf);
}
rx_config[chann].nco_frequency_hz = ret < 0 ? 0 : atoi(buf);

// rx.rf_port
rx_config[chann].rf_port = default_cfg.radio_cfg.rx_config[chann].rf_port; // TODO

radio_config.rx_config[chann] = rx_config[chann];

// tx.orx_enabled
ret = iio_channel_attr_read(rx, "orx_en", buf, sizeof(buf));
if(ret < 0) {
if(ret == -ENODEV) {
tx_config[chann].orx_enabled =
radio_config.tx_config[chann].orx_enabled =
default_cfg.radio_cfg.tx_config[chann].orx_enabled; // Temporary fix
} else {
sprintf(message, "\nFailed to get channel: %s attr: %s! error code: %d", chann_str,
"orx_en", ret);
goto iio_error;
}
} else {
tx_config[chann].orx_enabled = atoi(buf);
radio_config.tx_config[chann].orx_enabled = atoi(buf);
}

radio_config.rx_config[chann] = rx_config[chann];
}

cfg->radio_cfg = radio_config;
Expand Down

0 comments on commit 42180db

Please sign in to comment.