Skip to content

Commit

Permalink
Replace iio_channel_attr_* with the libiio v1.x iio_attr_* API
Browse files Browse the repository at this point in the history
Signed-off-by: Dan <[email protected]>
  • Loading branch information
dNechita committed Nov 26, 2024
1 parent 5a92ab5 commit cc2a0c8
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 68 deletions.
34 changes: 24 additions & 10 deletions ad9361_baseband_auto_rate.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,32 @@ static int16_t fir_64_2[] = {

int ad9361_set_trx_fir_enable(struct iio_device *dev, int enable)
{
const struct iio_attr *attr;
int ret = iio_device_attr_write_bool(dev,
"in_out_voltage_filter_fir_en", !!enable);
if (ret < 0)
ret = iio_channel_attr_write_bool(iio_device_find_channel(dev, "out", false),
"voltage_filter_fir_en", !!enable);
if (ret < 0) {
attr = iio_channel_find_attr(
iio_device_find_channel(dev, "out", false),
"voltage_filter_fir_en");
if (attr)
ret = iio_attr_write_bool(attr, !!enable);
}
return ret;
}

int ad9361_get_trx_fir_enable(struct iio_device *dev, int *enable)
{
const struct iio_attr *chAttr;
bool value;

int ret = iio_device_attr_read_bool(dev, "in_out_voltage_filter_fir_en", &value);

if (ret < 0)
ret = iio_channel_attr_read_bool(iio_device_find_channel(dev, "out", false),
"voltage_filter_fir_en", &value);
chAttr = iio_channel_find_attr(
iio_device_find_channel(dev, "out", false),
"voltage_filter_fir_en");
if (chAttr)
ret = iio_attr_read_bool(chAttr, &value);

if (!ret)
*enable = value;
Expand All @@ -80,6 +89,7 @@ int ad9361_get_trx_fir_enable(struct iio_device *dev, int *enable)
int ad9361_set_bb_rate(struct iio_device *dev, unsigned long rate)
{
struct iio_channel *chan;
const struct iio_attr *v0_samplfreq_attr;
long long current_rate;
int dec, taps, ret, i, enable, len = 0;
int16_t *fir;
Expand Down Expand Up @@ -107,7 +117,11 @@ int ad9361_set_bb_rate(struct iio_device *dev, unsigned long rate)
if (chan == NULL)
return -ENODEV;

ret = iio_channel_attr_read_longlong(chan, "sampling_frequency", &current_rate);
v0_samplfreq_attr = iio_channel_find_attr(chan, "sampling_frequency");
if (!v0_samplfreq_attr)
return -ENODEV;

ret = iio_attr_read_longlong(v0_samplfreq_attr, &current_rate);
if (ret < 0)
return ret;

Expand All @@ -117,7 +131,7 @@ int ad9361_set_bb_rate(struct iio_device *dev, unsigned long rate)

if (enable) {
if (current_rate <= (25000000 / 12))
iio_channel_attr_write_longlong(chan, "sampling_frequency", 3000000);
iio_attr_write_longlong(v0_samplfreq_attr, 3000000);

ret = ad9361_set_trx_fir_enable(dev, false);
if (ret < 0)
Expand Down Expand Up @@ -158,16 +172,16 @@ int ad9361_set_bb_rate(struct iio_device *dev, unsigned long rate)

max = (dacrate / txrate) * 16;
if (max < taps)
iio_channel_attr_write_longlong(chan, "sampling_frequency", 3000000);
iio_attr_write_longlong(v0_samplfreq_attr, 3000000);

ret = ad9361_set_trx_fir_enable(dev, true);
if (ret < 0)
return ret;
ret = iio_channel_attr_write_longlong(chan, "sampling_frequency", rate);
ret = iio_attr_write_longlong(v0_samplfreq_attr, rate);
if (ret < 0)
return ret;
} else {
ret = iio_channel_attr_write_longlong(chan, "sampling_frequency", rate);
ret = iio_attr_write_longlong(v0_samplfreq_attr, rate);
if (ret < 0)
return ret;
ret = ad9361_set_trx_fir_enable(dev, true);
Expand Down
33 changes: 22 additions & 11 deletions ad9361_design_taps.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ int apply_custom_filter(struct iio_device *dev, unsigned dec_tx,
unsigned long wnom_tx, unsigned long wnom_rx)
{
struct iio_channel *chanTX, *chanRX;
const struct iio_attr *tx_samplfreq_attr, *attr;
long long current_rate;
int ret, i, enable, len = 0;
char *buf;
Expand All @@ -218,7 +219,11 @@ int apply_custom_filter(struct iio_device *dev, unsigned dec_tx,
if (chanTX == NULL)
return -ENODEV;

ret = iio_channel_attr_read_longlong(chanTX, "sampling_frequency", &current_rate);
tx_samplfreq_attr = iio_channel_find_attr(chanTX, "sampling_frequency");
if (!tx_samplfreq_attr)
return -ENODEV;

ret = iio_attr_read_longlong(tx_samplfreq_attr, &current_rate);
if (ret < 0)
return ret;

Expand All @@ -228,7 +233,7 @@ int apply_custom_filter(struct iio_device *dev, unsigned dec_tx,

if (enable) {
if (current_rate <= (25000000 / 12))
iio_channel_attr_write_longlong(chanTX, "sampling_frequency", 3000000);
iio_attr_write_longlong(tx_samplfreq_attr, 3000000);

ret = ad9361_set_trx_fir_enable(dev, false);
if (ret < 0)
Expand Down Expand Up @@ -271,17 +276,17 @@ int apply_custom_filter(struct iio_device *dev, unsigned dec_tx,
return -EINVAL;
max = (dacrate / txrate) * 16;
if (max < taps)
iio_channel_attr_write_longlong(chanTX, "sampling_frequency", 3000000);
iio_attr_write_longlong(tx_samplfreq_attr, 3000000);


ret = ad9361_set_trx_fir_enable(dev, true);
if (ret < 0)
return ret;
ret = iio_channel_attr_write_longlong(chanTX, "sampling_frequency", rate);
ret = iio_attr_write_longlong(tx_samplfreq_attr, rate);
if (ret < 0)
return ret;
} else {
ret = iio_channel_attr_write_longlong(chanTX, "sampling_frequency", rate);
ret = iio_attr_write_longlong(tx_samplfreq_attr, rate);
if (ret < 0)
return ret;
ret = ad9361_set_trx_fir_enable(dev, true);
Expand All @@ -292,12 +297,18 @@ int apply_custom_filter(struct iio_device *dev, unsigned dec_tx,
chanRX = iio_device_find_channel(dev, "voltage0", false);
if (chanRX == NULL)
return -ENODEV;
ret = iio_channel_attr_write_longlong(chanTX, "rf_bandwidth", wnom_tx);
if (ret < 0)
return ret;
ret = iio_channel_attr_write_longlong(chanRX, "rf_bandwidth", wnom_rx);
if (ret < 0)
return ret;
attr = iio_channel_find_attr(chanTX, "rf_bandwidth");
if (attr) {
ret = iio_attr_write_longlong(attr, wnom_tx);
if (ret < 0)
return ret;
}
attr = iio_channel_find_attr(chanRX, "rf_bandwidth");
if (attr) {
ret = iio_attr_write_longlong(attr, wnom_rx);
if (ret < 0)
return ret;
}

return 0;
}
Expand Down
Loading

0 comments on commit cc2a0c8

Please sign in to comment.