Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treewide: update move to libiio 1.0i API #104

Open
wants to merge 1 commit into
base: staging/libiio1-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 49 additions & 17 deletions ad9361_baseband_auto_rate.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,34 @@ static int16_t fir_64_2[] = {

int ad9361_set_trx_fir_enable(struct iio_device *dev, int enable)
{
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);
int ret;

const struct iio_attr *attr = iio_device_find_attr(dev, "in_out_voltage_filter_fir_en");
if (!attr) {
attr = iio_channel_find_attr(iio_device_find_channel(dev, "out", false),
"voltage_filter_fir_en");
if (!attr)
return -ENOENT;
}

ret = iio_attr_write_bool(attr, !!enable);
return ret;
}

int ad9361_get_trx_fir_enable(struct iio_device *dev, int *enable)
{
int ret;
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);
const struct iio_attr *attr = iio_device_find_attr(dev, "in_out_voltage_filter_fir_en");
if (!attr) {
attr = iio_channel_find_attr(iio_device_find_channel(dev, "out", false),
"voltage_filter_fir_en");
if (!attr)
return -ENOENT;
}

ret = iio_attr_read_bool(attr, &value);
if (!ret)
*enable = value;

Expand All @@ -80,6 +90,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 *attr;
long long current_rate;
int dec, taps, ret, i, enable, len = 0;
int16_t *fir;
Expand Down Expand Up @@ -107,7 +118,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);
attr = iio_channel_find_attr(chan, "sampling_frequency");
if (!attr)
return -ENOENT;

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

Expand All @@ -117,7 +132,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(attr, 3000000);

ret = ad9361_set_trx_fir_enable(dev, false);
if (ret < 0)
Expand All @@ -136,7 +151,11 @@ int ad9361_set_bb_rate(struct iio_device *dev, unsigned long rate)

len += snprintf(buf + len, FIR_BUF_SIZE - len, "\n");

ret = iio_device_attr_write_raw(dev, "filter_fir_config", buf, len);
attr = iio_device_find_attr(dev, "filter_fir_config");
if (!attr)
return -ENOENT;

ret = iio_attr_write_raw(attr, buf, len);
free (buf);

if (ret < 0)
Expand All @@ -146,7 +165,11 @@ int ad9361_set_bb_rate(struct iio_device *dev, unsigned long rate)
int dacrate, txrate, max;
char readbuf[100];

ret = iio_device_attr_read_raw(dev, "tx_path_rates", readbuf, sizeof(readbuf));
attr = iio_device_find_attr(dev, "tx_path_rates");
if (!attr)
return -ENOENT;

ret = iio_attr_read_raw(attr, readbuf, sizeof(readbuf));
if (ret < 0)
return ret;
ret = sscanf(readbuf, "BBPLL:%*d DAC:%d T2:%*d T1:%*d TF:%*d TXSAMP:%d", &dacrate, &txrate);
Expand All @@ -156,18 +179,27 @@ int ad9361_set_bb_rate(struct iio_device *dev, unsigned long rate)
if (txrate == 0)
return -EINVAL;

attr = iio_channel_find_attr(chan, "sampling_frequency");
if (!attr)
return -ENOENT;

max = (dacrate / txrate) * 16;
if (max < taps)
iio_channel_attr_write_longlong(chan, "sampling_frequency", 3000000);
iio_attr_write_longlong(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(attr, rate);
if (ret < 0)
return ret;
} else {
ret = iio_channel_attr_write_longlong(chan, "sampling_frequency", rate);
attr = iio_channel_find_attr(chan, "sampling_frequency");
if (!attr)
return -ENOENT;

ret = iio_attr_write_longlong(attr, rate);
if (ret < 0)
return ret;
ret = ad9361_set_trx_fir_enable(dev, true);
Expand Down
55 changes: 44 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 *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);
attr = iio_channel_find_attr(chanTX, "sampling_frequency");
if (!attr)
return -ENOENT;

ret = iio_attr_read_longlong(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(attr, 3000000);

ret = ad9361_set_trx_fir_enable(dev, false);
if (ret < 0)
Expand All @@ -250,38 +255,56 @@ int apply_custom_filter(struct iio_device *dev, unsigned dec_tx,

len += snprintf(buf + len, FIR_BUF_SIZE - len, "\n");

ret = iio_device_attr_write_raw(dev, "filter_fir_config", buf, len);
attr = iio_device_find_attr(dev, "filter_fir_config");
if (!attr)
return -ENOENT;

ret = iio_attr_write_raw(attr, buf, len);
free (buf);

if (ret < 0)
return ret;

if (rate <= (25000000 / 12)) {

int dacrate, txrate, max;
char readbuf[100];
ret = iio_device_attr_read_raw(dev, "tx_path_rates", readbuf, sizeof(readbuf));

attr = iio_device_find_attr(dev, "tx_path_rates");
if (!attr)
return -ENOENT;

ret = iio_attr_read_raw(attr, readbuf, sizeof(readbuf));
if (ret < 0)
return ret;

ret = sscanf(readbuf, "BBPLL:%*d DAC:%d T2:%*d T1:%*d TF:%*d TXSAMP:%d",
&dacrate, &txrate);
if (ret != 2)
return -EFAULT;

if (txrate == 0)
return -EINVAL;

attr = iio_channel_find_attr(chanTX, "sampling_frequency");
if (!attr)
return -ENOENT;

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

iio_attr_write_longlong(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(attr, rate);
if (ret < 0)
return ret;
} else {
ret = iio_channel_attr_write_longlong(chanTX, "sampling_frequency", rate);
attr = iio_channel_find_attr(chanTX, "sampling_frequency");
if (!attr)
return -ENOENT;

ret = iio_attr_write_longlong(attr, rate);
if (ret < 0)
return ret;
ret = ad9361_set_trx_fir_enable(dev, true);
Expand All @@ -292,10 +315,20 @@ 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);

attr = iio_channel_find_attr(chanTX, "rf_bandwidth");
if (!attr)
return -ENOENT;

ret = iio_attr_write_longlong(attr, wnom_tx);
if (ret < 0)
return ret;
ret = iio_channel_attr_write_longlong(chanRX, "rf_bandwidth", wnom_rx);

attr = iio_channel_find_attr(chanRX, "rf_bandwidth");
if (!attr)
return -ENOENT;

ret = iio_attr_write_longlong(attr, wnom_rx);
if (ret < 0)
return ret;

Expand Down
Loading