diff --git a/ad9361_baseband_auto_rate.c b/ad9361_baseband_auto_rate.c index 65f3499..3d25120 100644 --- a/ad9361_baseband_auto_rate.c +++ b/ad9361_baseband_auto_rate.c @@ -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; @@ -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; @@ -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", ¤t_rate); + attr = iio_channel_find_attr(chan, "sampling_frequency"); + if (!attr) + return -ENOENT; + + ret = iio_attr_read_longlong(attr, ¤t_rate); if (ret < 0) return ret; @@ -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) @@ -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) @@ -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); @@ -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); diff --git a/ad9361_design_taps.c b/ad9361_design_taps.c index faa00c0..8025dcf 100644 --- a/ad9361_design_taps.c +++ b/ad9361_design_taps.c @@ -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; @@ -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", ¤t_rate); + attr = iio_channel_find_attr(chanTX, "sampling_frequency"); + if (!attr) + return -ENOENT; + + ret = iio_attr_read_longlong(attr, ¤t_rate); if (ret < 0) return ret; @@ -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) @@ -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); @@ -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; diff --git a/ad9361_fmcomms5_phase_sync.c b/ad9361_fmcomms5_phase_sync.c index 7445812..b685209 100644 --- a/ad9361_fmcomms5_phase_sync.c +++ b/ad9361_fmcomms5_phase_sync.c @@ -103,6 +103,7 @@ double scale_phase_0_360(double val) void dds_tx_phase_rotation(struct iio_device *dev, double val) { + const struct iio_attr *attr; long long i, q; int d, j; @@ -115,15 +116,19 @@ void dds_tx_phase_rotation(struct iio_device *dev, double val) q = scale_phase_0_360(val) * 1000; for (j = 0; j < 8; j++) { + attr = iio_channel_find_attr(dds_out[d][j], "phase"); + if (!attr) + continue; + switch (j) { case 0: case 1: case 4: case 5: - iio_channel_attr_write_longlong(dds_out[d][j], "phase", i); + iio_attr_write_longlong(attr, i); break; default: - iio_channel_attr_write_longlong(dds_out[d][j], "phase", q); + iio_attr_write_longlong(attr, q); } } } @@ -164,6 +169,8 @@ void near_end_loopback_ctrl(unsigned channel, bool enable) void configure_ports(unsigned val) { + const struct iio_attr *attr; + struct iio_channel *chan; unsigned lp_slave, lp_master, sw; char *rx_port, *tx_port; @@ -220,24 +227,35 @@ void configure_ports(unsigned val) // Configure ADG918 switches #if !EXTERNAL_REFERENCE_TONE - iio_device_debug_attr_write_longlong(dev_phy, "calibration_switch_control", - sw); + attr = iio_device_find_debug_attr(dev_phy, "calibration_switch_control"); + if (attr) + iio_attr_write_longlong(attr, sw); #endif // Map ports to switch orientation - iio_channel_attr_write(iio_device_find_channel(dev_phy, "voltage0", false), - "rf_port_select", rx_port); - iio_channel_attr_write(iio_device_find_channel(dev_phy, "voltage0", true), - "rf_port_select", tx_port); - iio_channel_attr_write( - iio_device_find_channel(dev_phy_slave, "voltage0", false), - "rf_port_select", rx_port); - iio_channel_attr_write( - iio_device_find_channel(dev_phy_slave, "voltage0", true), - "rf_port_select", tx_port); + chan = iio_device_find_channel(dev_phy, "voltage0", false); + attr = iio_channel_find_attr(chan, "rf_port_select"); + if (attr) + iio_attr_write_string(attr, rx_port); + + chan = iio_device_find_channel(dev_phy, "voltage0", true); + attr = iio_channel_find_attr(chan, "rf_port_select"); + if (attr) + iio_attr_write_string(attr, tx_port); + + chan = iio_device_find_channel(dev_phy_slave, "voltage0", false); + attr = iio_channel_find_attr(chan, "rf_port_select"); + if (attr) + iio_attr_write_string(attr, rx_port); + + chan = iio_device_find_channel(dev_phy_slave, "voltage0", true); + attr = iio_channel_find_attr(chan, "rf_port_select"); + if (attr) + iio_attr_write_string(attr, tx_port); } int trx_phase_rotation(struct iio_device *dev, double val) { + const struct iio_attr *attr; struct iio_channel *out0, *out1; double phase, vcos, vsin; unsigned offset; @@ -271,13 +289,32 @@ int trx_phase_rotation(struct iio_device *dev, double val) return -ENODEV; if (out1 && out0) { - ret = iio_channel_attr_write_double(out0, "calibscale", (double)vcos); + attr = iio_channel_find_attr(out0, "calibscale"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_double(attr, (double)vcos); CHECK(ret); - ret = iio_channel_attr_write_double(out0, "calibphase", (double)(-1.0 * vsin)); + + attr = iio_channel_find_attr(out0, "calibphase"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_double(attr, (double)(-1.0 * vsin)); CHECK(ret); - ret = iio_channel_attr_write_double(out1, "calibscale", (double)vcos); + + attr = iio_channel_find_attr(out1, "calibscale"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_double(attr, (double)vcos); CHECK(ret); - ret = iio_channel_attr_write_double(out1, "calibphase", (double)vsin); + + attr = iio_channel_find_attr(out1, "calibphase"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_double(attr, (double)vsin); CHECK(ret); } } @@ -415,15 +452,28 @@ int calibrate_chain(struct iio_device *dev, double scale, double *phase) int quad_tracking(bool enable) { + const struct iio_attr *attr; struct iio_channel *chn = iio_device_find_channel(dev_phy, "voltage0", enable); if (chn == NULL) return -ENODEV; - iio_channel_attr_write(chn, "quadrature_tracking_en", "0"); + + attr = iio_channel_find_attr(chn, "quadrature_tracking_en"); + if (!attr) + return -ENOENT; + + iio_attr_write_string(attr, "0"); + chn = iio_device_find_channel(dev_phy_slave, "voltage0", enable); if (chn == NULL) return -ENODEV; - iio_channel_attr_write(chn, "quadrature_tracking_en", "0"); + + attr = iio_channel_find_attr(chn, "quadrature_tracking_en"); + if (!attr) + return -ENOENT; + + iio_attr_write_string(attr, "0"); + return 0; } @@ -432,6 +482,7 @@ int configure_transceiver(struct iio_device *dev, long long bw_hz, { int ret = 0; // Set up channels + const struct iio_attr *attr; struct iio_channel *chnRX1; struct iio_channel *chnTX1; struct iio_channel *chnRX2; @@ -441,10 +492,21 @@ int configure_transceiver(struct iio_device *dev, long long bw_hz, chnTX1 = iio_device_find_channel(dev, "altvoltage1", true); if (!(chnRX1 && chnTX1)) return -ENODEV; - ret = iio_channel_attr_write_longlong(chnRX1, "frequency", lo_hz); + + attr = iio_channel_find_attr(chnRX1, "frequency"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_longlong(attr, lo_hz); CHECK(ret); - ret = iio_channel_attr_write_longlong(chnTX1, "frequency", lo_hz); + + attr = iio_channel_find_attr(chnTX1, "frequency"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_longlong(attr, lo_hz); CHECK(ret); + // Set up gains to know good values chnRX1 = iio_device_find_channel(dev, "voltage0", false); chnTX1 = iio_device_find_channel(dev, "voltage0", true); @@ -452,18 +514,47 @@ int configure_transceiver(struct iio_device *dev, long long bw_hz, chnTX2 = iio_device_find_channel(dev, "voltage1", true); if (!(chnRX1 && chnTX1 && chnRX2 && chnTX2)) return -ENODEV; - ret = iio_channel_attr_write(chnRX1, "gain_control_mode", "manual"); + + attr = iio_channel_find_attr(chnRX1, "gain_control_mode"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_string(attr, "manual"); CHECK(ret); - ret = iio_channel_attr_write(chnRX2, "gain_control_mode", "manual"); + + attr = iio_channel_find_attr(chnRX2, "gain_control_mode"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_string(attr, "manual"); CHECK(ret); - ret = iio_channel_attr_write_double(chnRX1, "hardwaregain", 32.0); + + attr = iio_channel_find_attr(chnRX1, "hardwaregain"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_double(attr, 32.0); CHECK(ret); - ret = iio_channel_attr_write_double(chnRX2, "hardwaregain", 32.0); + attr = iio_channel_find_attr(chnRX2, "hardwaregain"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_double(attr, 32.0); CHECK(ret); - ret = iio_channel_attr_write_double(chnTX1, "hardwaregain", -20); + + attr = iio_channel_find_attr(chnTX1, "hardwaregain"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_double(attr, -20); CHECK(ret); - ret = iio_channel_attr_write_double(chnTX2, "hardwaregain", -20); + + attr = iio_channel_find_attr(chnTX2, "hardwaregain"); + if (!attr) + return -ENOENT; + + ret = iio_attr_write_double(attr, -20); CHECK(ret); return 0; @@ -471,13 +562,23 @@ int configure_transceiver(struct iio_device *dev, long long bw_hz, int configure_dds(double fs, double scale) { + const struct iio_attr *attr; long long freq = (long long)fs * 0.01; int i, j, ret = 0; for (i = 0; i < 2; i++) { for (j = 0; j < 8; j++) { - ret |= iio_channel_attr_write_longlong(dds_out[i][j], "frequency", freq); - ret |= iio_channel_attr_write_double(dds_out[i][j], "scale", scale); + attr = iio_channel_find_attr(dds_out[i][j], "frequency"); + if (!attr) + continue; + + ret |= iio_attr_write_longlong(attr, freq); + + attr = iio_channel_find_attr(dds_out[i][j], "scale"); + if (!attr) + continue; + + ret |= iio_attr_write_double(attr, scale); } dds_tx_phase_rotation(i ? dev_tx_slave : dev_tx, 0.0); @@ -598,6 +699,7 @@ int phase_sync(struct iio_context *ctx, long long sample_rate, long long lo) /* Synchronize all transmit and receive channels for FMComms5*/ int ad9361_fmcomms5_phase_sync(struct iio_context *ctx, long long lo) { + const struct iio_attr *attr; struct iio_channel *chan; struct iio_device *dev; long long sample_rate; @@ -607,10 +709,16 @@ int ad9361_fmcomms5_phase_sync(struct iio_context *ctx, long long lo) dev = iio_context_find_device(ctx, DEV_PHY_NAME); if (dev == NULL) return -ENODEV; + chan = iio_device_find_channel(dev, "voltage0", true); if (chan == NULL) return -ENODEV; - ret = iio_channel_attr_read_longlong(chan, "sampling_frequency", &sample_rate); + + attr = iio_channel_find_attr(chan, "sampling_frequency"); + if (!attr) + return -ENOENT; + + ret = iio_attr_read_longlong(attr, &sample_rate); CHECK(ret); ret = phase_sync(ctx, sample_rate, lo); diff --git a/ad9361_multichip_sync.c b/ad9361_multichip_sync.c index f4bd020..30417a6 100644 --- a/ad9361_multichip_sync.c +++ b/ad9361_multichip_sync.c @@ -45,6 +45,7 @@ int ad9361_multichip_sync(struct iio_device *master, struct iio_device **slaves, char ensm_mode[MAX_AD9361_SYNC_DEVS][20]; unsigned int i, step; bool mcs_is_debug_attr = !iio_device_find_attr(master, "multichip_sync"); + const struct iio_attr *attr_pri, *attr_sec; if (num_slaves >= MAX_AD9361_SYNC_DEVS || num_slaves < 1) return -EINVAL; @@ -54,18 +55,26 @@ int ad9361_multichip_sync(struct iio_device *master, struct iio_device **slaves, long long tx_sample_master_freq, tx_sample_slave_freq; tx_sample_master = iio_device_find_channel(master, "voltage0", true); - iio_channel_attr_read_longlong(tx_sample_master, "sampling_frequency", &tx_sample_master_freq); + attr_pri = iio_channel_find_attr(tx_sample_master, "sampling_frequency"); + if (!attr_pri) + return -ENOENT; + + iio_attr_read_longlong(attr_pri, &tx_sample_master_freq); for (i = 0; i < num_slaves; i++) { tx_sample_slave = iio_device_find_channel(slaves[i], "voltage0", true); if (tx_sample_slave == NULL) return -ENODEV; - iio_channel_attr_read_longlong(tx_sample_slave, "sampling_frequency", &tx_sample_slave_freq); + attr_sec = iio_channel_find_attr(tx_sample_slave, "sampling_frequency"); + if (!attr_sec) + return -ENOENT; + + iio_attr_read_longlong(attr_sec, &tx_sample_slave_freq); if (tx_sample_master_freq != tx_sample_slave_freq) { fprintf(stderr, "tx_sample_master_freq != tx_sample_slave_freq\nUpdating...\n"); - iio_channel_attr_write_longlong(tx_sample_slave, "sampling_frequency", tx_sample_master_freq); + iio_attr_write_longlong(attr_sec, tx_sample_master_freq); } } } @@ -82,35 +91,62 @@ int ad9361_multichip_sync(struct iio_device *master, struct iio_device **slaves, } /* Move the parts int ALERT for MCS */ - iio_device_attr_read_raw(master, "ensm_mode", ensm_mode[0], sizeof(ensm_mode)); - iio_device_attr_write(master, "ensm_mode", "alert"); + attr_pri = iio_device_find_attr(master, "ensm_mode"); + if (!attr_pri) + return -ENOENT; + + iio_attr_read_raw(attr_pri, ensm_mode[0], sizeof(ensm_mode)); + iio_attr_write_string(attr_pri, "alert"); for (i = 0; i < num_slaves; i++) { - iio_device_attr_read_raw(slaves[i], "ensm_mode", ensm_mode[i + 1], sizeof(ensm_mode)); - iio_device_attr_write(slaves[i], "ensm_mode", "alert"); + attr_sec = iio_device_find_attr(slaves[i], "ensm_mode"); + if (!attr_sec) + return -ENOENT; + + iio_attr_read_raw(attr_sec, ensm_mode[i + 1], sizeof(ensm_mode)); + iio_attr_write_string(attr_sec, "alert"); } + if (mcs_is_debug_attr) + attr_pri = iio_device_find_debug_attr(master, "multichip_sync"); + else + attr_pri = iio_device_find_attr(master, "multichip_sync"); + + if (!attr_pri) + return -ENOENT; + for (step = 0; step <= 5; step++) { for (i = 0; i < num_slaves; i++) { if (mcs_is_debug_attr) - iio_device_debug_attr_write_longlong(slaves[i], "multichip_sync", step); + attr_sec = iio_device_find_debug_attr(slaves[i], "multichip_sync"); else - iio_device_attr_write_longlong(slaves[i], "multichip_sync", step); + attr_sec = iio_device_find_attr(slaves[i], "multichip_sync"); + + if (!attr_sec) + return -ENOENT; + + iio_attr_write_longlong(attr_sec, step); } /* The master controls the SYNC GPIO */ - if (mcs_is_debug_attr) - iio_device_debug_attr_write_longlong(master, "multichip_sync", step); - else - iio_device_attr_write_longlong(master, "multichip_sync", step); + iio_attr_write_longlong(attr_pri, step); ad9361_sleep_ms(); } - iio_device_attr_write(master, "ensm_mode", ensm_mode[0]); + attr_pri = iio_device_find_attr(master, "ensm_mode"); + if (!attr_pri) + return -ENOENT; + + iio_attr_write_string(attr_pri, ensm_mode[0]); - for (i = 0; i < num_slaves; i++) - iio_device_attr_write(slaves[i], "ensm_mode", ensm_mode[i + 1]); + for (i = 0; i < num_slaves; i++) { + attr_sec = iio_device_find_attr(slaves[i], "ensm_mode"); + if (!attr_sec) + return -ENOENT; + + iio_attr_write_string(attr_sec, ensm_mode[i + 1]); + } return 0; } diff --git a/test/auto_rate_test_hw.c b/test/auto_rate_test_hw.c index 81dda95..a9b6067 100644 --- a/test/auto_rate_test_hw.c +++ b/test/auto_rate_test_hw.c @@ -14,6 +14,7 @@ int run_test(unsigned long rate, struct iio_device *dev) { + const struct iio_attr *attr; struct iio_channel *chan; long long current_rate; int ret; @@ -25,13 +26,20 @@ int run_test(unsigned long rate, struct iio_device *dev) printf("ad9361_set_bb_rate Failed: %d\n",ret); return ret; } + // Checks chan = iio_device_find_channel(dev, "voltage0", true); if (chan == NULL) return -ENODEV; - ret = iio_channel_attr_read_longlong(chan, "sampling_frequency", ¤t_rate); + + attr = iio_channel_find_attr(chan, "sampling_frequency"); + if (!attr) + return -ENOENT; + + ret = iio_attr_read_longlong(attr, ¤t_rate); if (ret < 0) return ret; + if (abs(current_rate != (long long) rate)> RATE_TOLERANCE_HZ) return -1;