From e6f3222e4a81180fbbd5c36bad4f952d36f343e6 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Tue, 10 May 2022 09:53:27 +0200 Subject: [PATCH 01/13] make the FPGA ad9361 signal source config_ad9361_rx_local function compatible with the AD-FMCOMMS5 analog front-end --- .../signal_source/libs/ad9361_manager.cc | 365 +++++++++++------- .../signal_source/libs/ad9361_manager.h | 7 + 2 files changed, 242 insertions(+), 130 deletions(-) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 49e17255a..4538e80dd 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -163,6 +163,162 @@ bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, en return true; } +int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sample_rate_, uint64_t freq_, const std::string &rf_port_select_, struct iio_context *ctx, + struct iio_device *ad9361_phy, struct iio_channel *rx_chan1, std::string filter_filename_, float Fpass_, float Fstop_) +{ + int ret; + if (filter_source_ == "Off") + { + struct stream_cfg rxcfg; + rxcfg.bw_hz = bandwidth_; + rxcfg.fs_hz = sample_rate_; + rxcfg.lo_hz = freq_; + rxcfg.rfport = rf_port_select_.c_str(); + + if (!cfg_ad9361_streaming_ch(ctx, &rxcfg, RX, 0)) + { + std::cout << "RX port 0 not found\n"; + throw std::runtime_error("AD9361 IIO RX port 0 not found"); + } + } + else if (filter_source_ == "Auto") + { + ret = ad9361_set_bb_rate(ad9361_phy, sample_rate_); + if (ret) + { + throw std::runtime_error("Unable to set BB rate"); + // set bw + // params.push_back("in_voltage_rf_bandwidth=" + boost::to_string(bandwidth)); + } + // wr_ch_str(rx_chan1, "rf_port_select", rf_port_select_.c_str()); + ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); + if (ret) + { + throw std::runtime_error("Unable to set rf_port_select"); + } + wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); + if (!get_lo_chan(ctx, RX, &rx_chan1)) + { + return -1; + } + wr_ch_lli(rx_chan1, "frequency", freq_); + } + else if (filter_source_ == "File") + { + try + { + if (!load_fir_filter(filter_filename_, ad9361_phy)) + { + throw std::runtime_error("Unable to load filter file"); + } + } + catch (const std::runtime_error &e) + { + std::cout << "Exception cached when configuring the RX FIR filter: " << e.what() << '\n'; + } + ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); + if (ret) + { + throw std::runtime_error("Unable to set rf_port_select"); + } + wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); + if (!get_lo_chan(ctx, RX, &rx_chan1)) + { + return -1; + } + wr_ch_lli(rx_chan1, "frequency", freq_); + } +#if LIBAD9361_VERSION_GREATER_THAN_01 + else if (filter_source_ == "Design") + { + ret = ad9361_set_bb_rate_custom_filter_manual( + ad9361_phy, sample_rate_, static_cast(Fpass_), static_cast(Fstop_), bandwidth_, bandwidth_); + if (ret) + { + throw std::runtime_error("Unable to set BB rate"); + } + ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); + if (ret) + { + throw std::runtime_error("Unable to set rf_port_select"); + } + wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); + if (!get_lo_chan(ctx, RX, &rx_chan1)) + { + return -1; + } + wr_ch_lli(rx_chan1, "frequency", freq_); + } +#endif + else + { + throw std::runtime_error("Unknown filter configuration"); + } + + // Filters can only be disabled after the sample rate has been set + if (filter_source_ == "Off") + { + ret = ad9361_set_trx_fir_enable(ad9361_phy, false); + if (ret) + { + throw std::runtime_error("Unable to disable filters"); + } + } + return 0; +} + +int setup_device_parameters(iio_device *ad9361_phy, bool quadrature_, bool rfdc_, bool bbdc_, const std::string &gain_mode_rx1_, const std::string &gain_mode_rx2_) +{ + int ret; + ret = iio_device_attr_write(ad9361_phy, "trx_rate_governor", "nominal"); + if (ret < 0) + { + std::cout << "Failed to set trx_rate_governor: " << ret << '\n'; + return ret; + } + ret = iio_device_attr_write(ad9361_phy, "ensm_mode", "fdd"); + if (ret < 0) + { + std::cout << "Failed to set ensm_mode: " << ret << '\n'; + return ret; + } + ret = iio_device_attr_write(ad9361_phy, "calib_mode", "auto"); + if (ret < 0) + { + std::cout << "Failed to set calib_mode: " << ret << '\n'; + return ret; + } + ret = iio_device_attr_write_bool(ad9361_phy, "in_voltage_quadrature_tracking_en", quadrature_); + if (ret < 0) + { + std::cout << "Failed to set in_voltage_quadrature_tracking_en: " << ret << '\n'; + return ret; + } + ret = iio_device_attr_write_bool(ad9361_phy, "in_voltage_rf_dc_offset_tracking_en", rfdc_); + if (ret < 0) + { + std::cout << "Failed to set in_voltage_rf_dc_offset_tracking_en: " << ret << '\n'; + return ret; + } + ret = iio_device_attr_write_bool(ad9361_phy, "in_voltage_bb_dc_offset_tracking_en", bbdc_); + if (ret < 0) + { + std::cout << "Failed to set in_voltage_bb_dc_offset_tracking_en: " << ret << '\n'; + return ret; + } + ret = iio_device_attr_write(ad9361_phy, "in_voltage0_gain_control_mode", gain_mode_rx1_.c_str()); + if (ret < 0) + { + std::cout << "Failed to set in_voltage0_gain_control_mode: " << ret << '\n'; + return ret; + } + ret = iio_device_attr_write(ad9361_phy, "in_voltage1_gain_control_mode", gain_mode_rx2_.c_str()); + if (ret < 0) + { + std::cout << "Failed to set in_voltage1_gain_control_mode: " << ret << '\n'; + } + return ret; +} bool config_ad9361_rx_local(uint64_t bandwidth_, uint64_t sample_rate_, @@ -205,6 +361,8 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, } #endif + // iio context + ctx = iio_create_default_context(); if (!ctx) { @@ -218,124 +376,87 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, throw std::runtime_error("AD9361 IIO No devices"); } + // AD9361-A struct iio_device *ad9361_phy; - ad9361_phy = iio_context_find_device(ctx, "ad9361-phy"); - - std::cout << "* Acquiring AD9361 streaming devices\n"; - if (!get_ad9361_stream_dev(ctx, RX, &rx)) + ad9361_phy = iio_context_find_device(ctx, RX_DEV_A.c_str()); + if (!ad9361_phy) { std::cout << "No rx dev found\n"; - throw std::runtime_error("AD9361 IIO No rx dev found"); + throw std::runtime_error("AD9361 IIO no rx dev found"); } - std::cout << "* Initializing AD9361 IIO streaming channels\n"; + // AD9361-B + struct iio_device *ad9361_phy_B; + bool enable_ad9361_b; + ad9361_phy_B = iio_context_find_device(ctx, RX_DEV_B.c_str()); + if (ad9361_phy_B) + { + enable_ad9361_b = true; + } + else + { + enable_ad9361_b = false; + } + + // set-up AD9361-A stream device + + std::cout << "* Acquiring AD9361 streaming devices\n"; + std::string rx_stream_dev_a = (enable_ad9361_b ? RX_STREAM_DEV_A : RX_STREAM_DEV); + rx = iio_context_find_device(ctx, rx_stream_dev_a.c_str()); + if (!rx) + { + std::cout << "No rx stream dev found\n"; + throw std::runtime_error("AD9361 IIO No rx stream dev found"); + } + + // get AD9361-A stream device channel 1 as rx channel 1 + if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan1)) { std::cout << "RX channel 1 not found\n"; throw std::runtime_error("RX channel 1 not found"); } - - if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan2)) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ctx, ad9361_phy, rx_chan1, filter_filename_, Fpass_, Fstop_) == -1) { - std::cout << "RX channel 2 not found\n"; - throw std::runtime_error("RX channel 2 not found"); + return false; } - if (filter_source_ == "Off") + if (enable_ad9361_b) { - struct stream_cfg rxcfg; - rxcfg.bw_hz = bandwidth_; - rxcfg.fs_hz = sample_rate_; - rxcfg.lo_hz = freq_; - rxcfg.rfport = rf_port_select_.c_str(); + // set-up AD9361-B stream device - if (!cfg_ad9361_streaming_ch(ctx, &rxcfg, RX, 0)) + std::cout << "* Acquiring AD9361 streaming devices\n"; + rx = iio_context_find_device(ctx, RX_STREAM_DEV_B.c_str()); + if (!rx) { - std::cout << "RX port 0 not found\n"; - throw std::runtime_error("AD9361 IIO RX port 0 not found"); + std::cout << "No rx stream dev found\n"; + throw std::runtime_error("AD9361 IIO No rx stream dev found"); } - } - else if (filter_source_ == "Auto") - { - ret = ad9361_set_bb_rate(ad9361_phy, sample_rate_); - if (ret) + + // get AD9361-A stream device channel 1 as rx channel 2 + + if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan2)) { - throw std::runtime_error("Unable to set BB rate"); - // set bw - // params.push_back("in_voltage_rf_bandwidth=" + boost::to_string(bandwidth)); + std::cout << "RX channel 1 not found\n"; + throw std::runtime_error("RX channel 1 not found"); } - // wr_ch_str(rx_chan1, "rf_port_select", rf_port_select_.c_str()); - ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); - if (ret) - { - throw std::runtime_error("Unable to set rf_port_select"); - } - wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); - if (!get_lo_chan(ctx, RX, &rx_chan1)) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ctx, ad9361_phy_B, rx_chan2, filter_filename_, Fpass_, Fstop_) == -1) { return false; } - wr_ch_lli(rx_chan1, "frequency", freq_); } - else if (filter_source_ == "File") - { - try - { - if (!load_fir_filter(filter_filename_, ad9361_phy)) - { - throw std::runtime_error("Unable to load filter file"); - } - } - catch (const std::runtime_error &e) - { - std::cout << "Exception cached when configuring the RX FIR filter: " << e.what() << '\n'; - } - ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); - if (ret) - { - throw std::runtime_error("Unable to set rf_port_select"); - } - wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); - if (!get_lo_chan(ctx, RX, &rx_chan1)) - { - return false; - } - wr_ch_lli(rx_chan1, "frequency", freq_); - } -#if LIBAD9361_VERSION_GREATER_THAN_01 - else if (filter_source_ == "Design") - { - ret = ad9361_set_bb_rate_custom_filter_manual( - ad9361_phy, sample_rate_, static_cast(Fpass_), static_cast(Fstop_), bandwidth_, bandwidth_); - if (ret) - { - throw std::runtime_error("Unable to set BB rate"); - } - ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); - if (ret) - { - throw std::runtime_error("Unable to set rf_port_select"); - } - wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); - if (!get_lo_chan(ctx, RX, &rx_chan1)) - { - return false; - } - wr_ch_lli(rx_chan1, "frequency", freq_); - } -#endif else { - throw std::runtime_error("Unknown filter configuration"); - } + // GET ad9361-A stream device channel 2 as rx channel 2 - // Filters can only be disabled after the sample rate has been set - if (filter_source_ == "Off") - { - ret = ad9361_set_trx_fir_enable(ad9361_phy, false); - if (ret) + if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan2)) { - throw std::runtime_error("Unable to disable filters"); + std::cout << "RX channel 2 not found\n"; + throw std::runtime_error("RX channel 2 not found"); + } + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ctx, ad9361_phy, rx_chan2, filter_filename_, Fpass_, Fstop_) == -1) + { + return false; } } @@ -353,46 +474,18 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, std::cout << "WARNING: No Rx channels enabled.\n"; } - ret = iio_device_attr_write(ad9361_phy, "trx_rate_governor", "nominal"); - if (ret < 0) + if (setup_device_parameters(ad9361_phy, quadrature_, rfdc_, bbdc_, gain_mode_rx1_, gain_mode_rx2_) < 0) { - std::cout << "Failed to set trx_rate_governor: " << ret << '\n'; + throw std::runtime_error("setup AD9361 device parameters failed"); } - ret = iio_device_attr_write(ad9361_phy, "ensm_mode", "fdd"); - if (ret < 0) + if (enable_ad9361_b) { - std::cout << "Failed to set ensm_mode: " << ret << '\n'; - } - ret = iio_device_attr_write(ad9361_phy, "calib_mode", "auto"); - if (ret < 0) - { - std::cout << "Failed to set calib_mode: " << ret << '\n'; - } - ret = iio_device_attr_write_bool(ad9361_phy, "in_voltage_quadrature_tracking_en", quadrature_); - if (ret < 0) - { - std::cout << "Failed to set in_voltage_quadrature_tracking_en: " << ret << '\n'; - } - ret = iio_device_attr_write_bool(ad9361_phy, "in_voltage_rf_dc_offset_tracking_en", rfdc_); - if (ret < 0) - { - std::cout << "Failed to set in_voltage_rf_dc_offset_tracking_en: " << ret << '\n'; - } - ret = iio_device_attr_write_bool(ad9361_phy, "in_voltage_bb_dc_offset_tracking_en", bbdc_); - if (ret < 0) - { - std::cout << "Failed to set in_voltage_bb_dc_offset_tracking_en: " << ret << '\n'; - } - ret = iio_device_attr_write(ad9361_phy, "in_voltage0_gain_control_mode", gain_mode_rx1_.c_str()); - if (ret < 0) - { - std::cout << "Failed to set in_voltage0_gain_control_mode: " << ret << '\n'; - } - ret = iio_device_attr_write(ad9361_phy, "in_voltage1_gain_control_mode", gain_mode_rx2_.c_str()); - if (ret < 0) - { - std::cout << "Failed to set in_voltage1_gain_control_mode: " << ret << '\n'; + if (setup_device_parameters(ad9361_phy_B, quadrature_, rfdc_, bbdc_, gain_mode_rx1_, gain_mode_rx2_) < 0) + { + throw std::runtime_error("setup AD9361 device parameters failed"); + } } + if (gain_mode_rx1_ == "manual") { ret = iio_device_attr_write_double(ad9361_phy, "in_voltage0_hardwaregain", rf_gain_rx1_); @@ -401,12 +494,24 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, std::cout << "Failed to set in_voltage0_hardwaregain: " << ret << '\n'; } } - if (gain_mode_rx2_ == "manual") + + if (!enable_ad9361_b) { - ret = iio_device_attr_write_double(ad9361_phy, "in_voltage1_hardwaregain", rf_gain_rx2_); + if (gain_mode_rx2_ == "manual") + { + ret = iio_device_attr_write_double(ad9361_phy, "in_voltage1_hardwaregain", rf_gain_rx2_); + if (ret < 0) + { + std::cout << "Failed to set in_voltage1_hardwaregain: " << ret << '\n'; + } + } + } + else + { + ret = iio_device_attr_write_double(ad9361_phy_B, "in_voltage0_hardwaregain", rf_gain_rx1_); if (ret < 0) { - std::cout << "Failed to set in_voltage1_hardwaregain: " << ret << '\n'; + std::cout << "Failed to set in_voltage0_hardwaregain: " << ret << '\n'; } } diff --git a/src/algorithms/signal_source/libs/ad9361_manager.h b/src/algorithms/signal_source/libs/ad9361_manager.h index 3d36c4c46..9ddbfbe80 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.h +++ b/src/algorithms/signal_source/libs/ad9361_manager.h @@ -32,6 +32,13 @@ #define FIR_BUF_SIZE 8192 +static const std::string RX_DEV_A = "ad9361-phy"; // one or two AD9361s are present +static const std::string RX_DEV_B = "ad9361-phy-B"; // one or two AD9361s are present +static const std::string RX_STREAM_DEV = "cf-ad9361-lpc"; // one AD9361 is present +static const std::string RX_STREAM_DEV_A = "cf-ad9361-A"; // two AD9361s are present +static const std::string RX_STREAM_DEV_B = "cf-ad9361-B"; // two AD9361s are present +static const std::string TX_STREAM_DEV = "cf-ad9361-dds-core-lpc"; + /* RX is input, TX is output */ enum iodev { From c2141f99fb8a6bc34a464ef4e3994a9bab5ac2bb Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Thu, 12 May 2022 17:53:27 +0200 Subject: [PATCH 02/13] update the AD9361 in_voltage1_hardwaregain only if the gain mode is set to manual --- src/algorithms/signal_source/libs/ad9361_manager.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 4538e80dd..834b43e5f 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -508,10 +508,13 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, } else { - ret = iio_device_attr_write_double(ad9361_phy_B, "in_voltage0_hardwaregain", rf_gain_rx1_); - if (ret < 0) + if (gain_mode_rx2_ == "manual") { - std::cout << "Failed to set in_voltage0_hardwaregain: " << ret << '\n'; + ret = iio_device_attr_write_double(ad9361_phy_B, "in_voltage1_hardwaregain", rf_gain_rx2_); + if (ret < 0) + { + std::cout << "Failed to set in_voltage1_hardwaregain: " << ret << '\n'; + } } } From a1d8d8c19d5d7ec3e920a9a5c6124b07af6c7ec2 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Fri, 13 May 2022 18:12:25 +0200 Subject: [PATCH 03/13] make the ad9361_manager functions flexible to allow the use of two AD9361 devices when using the FPGA. --- .../adapters/ad9361_fpga_signal_source.cc | 13 +- .../adapters/ad9361_fpga_signal_source.h | 3 +- .../signal_source/libs/ad9361_manager.cc | 335 ++++++------------ .../signal_source/libs/ad9361_manager.h | 3 +- 4 files changed, 128 insertions(+), 226 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc index 35ac26dac..c44e7b11c 100644 --- a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc @@ -59,7 +59,7 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(const ConfigurationInterface *con filename0_(configuration->property(role + ".filename", empty_string)), rf_gain_rx1_(configuration->property(role + ".gain_rx1", default_manual_gain_rx1)), rf_gain_rx2_(configuration->property(role + ".gain_rx1", default_manual_gain_rx2)), - freq_(configuration->property(role + ".freq", static_cast(GPS_L1_FREQ_HZ))), + freq0_(configuration->property(role + ".freq", 0)), sample_rate_(configuration->property(role + ".sampling_frequency", default_bandwidth)), bandwidth_(configuration->property(role + ".bandwidth", default_bandwidth)), samples_to_skip_(0), @@ -98,6 +98,12 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(const ConfigurationInterface *con const double seconds_to_skip = configuration->property(role + ".seconds_to_skip", 0.0); const size_t header_size = configuration->property(role + ".header_size", 0); + if (freq0_ == 0) + { + freq0_ = configuration->property(role + ".freq0", static_cast(GPS_L1_FREQ_HZ)); + freq1_ = configuration->property(role + ".freq1", static_cast(GPS_L5_FREQ_HZ)); + } + if (filter_auto_) { filter_source_ = configuration->property(role + ".filter_source", std::string("Auto")); @@ -340,12 +346,13 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(const ConfigurationInterface *con LOG(WARNING) << "Invalid configuration value for bandwidth parameter. Set to bandwidth=" << default_bandwidth; } - std::cout << "LO frequency : " << freq_ << " Hz\n"; + std::cout << "LO frequency : " << freq0_ << " Hz\n"; try { config_ad9361_rx_local(bandwidth_, sample_rate_, - freq_, + freq0_, + freq1_, rf_port_select_, rx1_enable_, rx2_enable_, diff --git a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.h b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.h index 62e3d2e63..c2feb998d 100644 --- a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.h +++ b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.h @@ -126,7 +126,8 @@ private: double rf_gain_rx1_; double rf_gain_rx2_; - uint64_t freq_; // frequency of local oscillator + uint64_t freq0_; // frequency of local oscillator for ADRV9361-A 0 + uint64_t freq1_; // frequency of local oscillator for ADRV9361-B (if present) uint64_t sample_rate_; uint64_t bandwidth_; uint64_t samples_to_skip_; diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 834b43e5f..48701d44e 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -92,32 +92,6 @@ bool get_ad9361_stream_ch(struct iio_context *ctx __attribute__((unused)), enum } -/* finds AD9361 phy IIO configuration channel with id chid */ -bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn) -{ - std::stringstream name; - switch (d) - { - case RX: - name.str(""); - name << "voltage"; - name << chid; - *chn = iio_device_find_channel(get_ad9361_phy(ctx), name.str().c_str(), false); - return *chn != nullptr; - break; - case TX: - name.str(""); - name << "voltage"; - name << chid; - *chn = iio_device_find_channel(get_ad9361_phy(ctx), name.str().c_str(), true); - return *chn != nullptr; - break; - default: - return false; - } -} - - /* finds AD9361 local oscillator IIO configuration channels */ bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn) { @@ -137,24 +111,15 @@ bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn /* applies streaming configuration through IIO */ -bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, int chid) +bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, iio_channel *chn) { - struct iio_channel *chn = nullptr; - // Configure phy and lo channels - // LOG(INFO)<<"* Acquiring AD9361 phy channel"<rfport); wr_ch_lli(chn, "rf_bandwidth", cfg->bw_hz); wr_ch_lli(chn, "sampling_frequency", cfg->fs_hz); // Configure LO channel - // LOG(INFO)<<"* Acquiring AD9361 "<(Fpass_), static_cast(Fstop_), bandwidth_, bandwidth_); + ad9361_phy_dev, sample_rate_, static_cast(Fpass_), static_cast(Fstop_), bandwidth_, bandwidth_); if (ret) { throw std::runtime_error("Unable to set BB rate"); } - ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); + ret = iio_device_attr_write(ad9361_phy_dev, "in_voltage0_rf_port_select", rf_port_select_.c_str()); if (ret) { throw std::runtime_error("Unable to set rf_port_select"); } - wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); - if (!get_lo_chan(ctx, RX, &rx_chan1)) + wr_ch_lli(rx_chan, "rf_bandwidth", bandwidth_); + if (!get_lo_chan(ctx, RX, &rx_chan)) { return -1; } - wr_ch_lli(rx_chan1, "frequency", freq_); + wr_ch_lli(rx_chan, "frequency", freq_); } #endif else @@ -258,7 +223,7 @@ int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sampl // Filters can only be disabled after the sample rate has been set if (filter_source_ == "Off") { - ret = ad9361_set_trx_fir_enable(ad9361_phy, false); + ret = ad9361_set_trx_fir_enable(ad9361_phy_dev, false); if (ret) { throw std::runtime_error("Unable to disable filters"); @@ -267,52 +232,52 @@ int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sampl return 0; } -int setup_device_parameters(iio_device *ad9361_phy, bool quadrature_, bool rfdc_, bool bbdc_, const std::string &gain_mode_rx1_, const std::string &gain_mode_rx2_) +int setup_device_parameters(iio_device *ad9361_phy_dev, bool quadrature_, bool rfdc_, bool bbdc_, const std::string &gain_mode_rx1_, const std::string &gain_mode_rx2_) { int ret; - ret = iio_device_attr_write(ad9361_phy, "trx_rate_governor", "nominal"); + ret = iio_device_attr_write(ad9361_phy_dev, "trx_rate_governor", "nominal"); if (ret < 0) { std::cout << "Failed to set trx_rate_governor: " << ret << '\n'; return ret; } - ret = iio_device_attr_write(ad9361_phy, "ensm_mode", "fdd"); + ret = iio_device_attr_write(ad9361_phy_dev, "ensm_mode", "fdd"); if (ret < 0) { std::cout << "Failed to set ensm_mode: " << ret << '\n'; return ret; } - ret = iio_device_attr_write(ad9361_phy, "calib_mode", "auto"); + ret = iio_device_attr_write(ad9361_phy_dev, "calib_mode", "auto"); if (ret < 0) { std::cout << "Failed to set calib_mode: " << ret << '\n'; return ret; } - ret = iio_device_attr_write_bool(ad9361_phy, "in_voltage_quadrature_tracking_en", quadrature_); + ret = iio_device_attr_write_bool(ad9361_phy_dev, "in_voltage_quadrature_tracking_en", quadrature_); if (ret < 0) { std::cout << "Failed to set in_voltage_quadrature_tracking_en: " << ret << '\n'; return ret; } - ret = iio_device_attr_write_bool(ad9361_phy, "in_voltage_rf_dc_offset_tracking_en", rfdc_); + ret = iio_device_attr_write_bool(ad9361_phy_dev, "in_voltage_rf_dc_offset_tracking_en", rfdc_); if (ret < 0) { std::cout << "Failed to set in_voltage_rf_dc_offset_tracking_en: " << ret << '\n'; return ret; } - ret = iio_device_attr_write_bool(ad9361_phy, "in_voltage_bb_dc_offset_tracking_en", bbdc_); + ret = iio_device_attr_write_bool(ad9361_phy_dev, "in_voltage_bb_dc_offset_tracking_en", bbdc_); if (ret < 0) { std::cout << "Failed to set in_voltage_bb_dc_offset_tracking_en: " << ret << '\n'; return ret; } - ret = iio_device_attr_write(ad9361_phy, "in_voltage0_gain_control_mode", gain_mode_rx1_.c_str()); + ret = iio_device_attr_write(ad9361_phy_dev, "in_voltage0_gain_control_mode", gain_mode_rx1_.c_str()); if (ret < 0) { std::cout << "Failed to set in_voltage0_gain_control_mode: " << ret << '\n'; return ret; } - ret = iio_device_attr_write(ad9361_phy, "in_voltage1_gain_control_mode", gain_mode_rx2_.c_str()); + ret = iio_device_attr_write(ad9361_phy_dev, "in_voltage1_gain_control_mode", gain_mode_rx2_.c_str()); if (ret < 0) { std::cout << "Failed to set in_voltage1_gain_control_mode: " << ret << '\n'; @@ -322,7 +287,8 @@ int setup_device_parameters(iio_device *ad9361_phy, bool quadrature_, bool rfdc_ bool config_ad9361_rx_local(uint64_t bandwidth_, uint64_t sample_rate_, - uint64_t freq_, + uint64_t freq0_, + uint64_t freq1_, const std::string &rf_port_select_, bool rx1_enable_, bool rx2_enable_, @@ -340,12 +306,12 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, { // RX stream config - std::cout << "AD9361 Acquiring IIO LOCAL context\n"; + struct iio_context *ctx; // Streaming devices struct iio_device *rx; + struct iio_channel *rx_chan0; struct iio_channel *rx_chan1; - struct iio_channel *rx_chan2; int ret; #ifndef LIBAD9361_VERSION_GREATER_THAN_01 @@ -362,7 +328,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, #endif // iio context - + std::cout << "Acquiring IIO LOCAL context\n"; ctx = iio_create_default_context(); if (!ctx) { @@ -378,10 +344,11 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, // AD9361-A struct iio_device *ad9361_phy; + std::cout << "Acquiring AD9361 phy devices\n"; ad9361_phy = iio_context_find_device(ctx, RX_DEV_A.c_str()); if (!ad9361_phy) { - std::cout << "No rx dev found\n"; + std::cout << "No " << RX_DEV_A << " dev found\n"; throw std::runtime_error("AD9361 IIO no rx dev found"); } @@ -391,32 +358,32 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, ad9361_phy_B = iio_context_find_device(ctx, RX_DEV_B.c_str()); if (ad9361_phy_B) { - enable_ad9361_b = true; + enable_ad9361_b = true; // the RF board has two AD9361 devices } else { - enable_ad9361_b = false; + enable_ad9361_b = false; // the RF board has one AD9361 device } // set-up AD9361-A stream device - std::cout << "* Acquiring AD9361 streaming devices\n"; std::string rx_stream_dev_a = (enable_ad9361_b ? RX_STREAM_DEV_A : RX_STREAM_DEV); + std::cout << "* Acquiring " << rx_stream_dev_a << " streaming device\n"; rx = iio_context_find_device(ctx, rx_stream_dev_a.c_str()); if (!rx) { - std::cout << "No rx stream dev found\n"; - throw std::runtime_error("AD9361 IIO No rx stream dev found"); + std::cout << "No " << rx_stream_dev_a << " stream dev found\n"; + throw std::runtime_error("AD9361 IIO No " + rx_stream_dev_a + " stream dev found"); } - // get AD9361-A stream device channel 1 as rx channel 1 - - if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan1)) + // get AD9361-A stream device channel 0 as rx channel 0 + std::cout << "* Acquiring " << rx_stream_dev_a << " phy channel 0\n"; + if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan0)) { - std::cout << "RX channel 1 not found\n"; - throw std::runtime_error("RX channel 1 not found"); + std::cout << rx_stream_dev_a << " channel 0 not found\n"; + throw std::runtime_error(rx_stream_dev_a + "RX channel 0 not found"); } - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ctx, ad9361_phy, rx_chan1, filter_filename_, Fpass_, Fstop_) == -1) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq0_, rf_port_select_, ctx, ad9361_phy, rx_chan0, filter_filename_, Fpass_, Fstop_) == -1) { return false; } @@ -425,36 +392,36 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, { // set-up AD9361-B stream device - std::cout << "* Acquiring AD9361 streaming devices\n"; + std::cout << "* Acquiring " << RX_STREAM_DEV_B << " streaming device\n"; rx = iio_context_find_device(ctx, RX_STREAM_DEV_B.c_str()); if (!rx) { - std::cout << "No rx stream dev found\n"; - throw std::runtime_error("AD9361 IIO No rx stream dev found"); + std::cout << "No " << RX_STREAM_DEV_B << " stream dev found\n"; + throw std::runtime_error("AD9361 IIO No " + RX_STREAM_DEV_B + " stream dev found"); } - // get AD9361-A stream device channel 1 as rx channel 2 - - if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan2)) + // get AD9361-B stream device channel 0 as rx channel 1 + std::cout << "* Acquiring " << RX_STREAM_DEV_B << " phy channel 0\n"; + if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan1)) { - std::cout << "RX channel 1 not found\n"; - throw std::runtime_error("RX channel 1 not found"); + std::cout << RX_STREAM_DEV_B << " channel 0 not found\n"; + throw std::runtime_error(RX_STREAM_DEV_B + "RX channel 0 not found"); } - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ctx, ad9361_phy_B, rx_chan2, filter_filename_, Fpass_, Fstop_) == -1) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq1_, rf_port_select_, ctx, ad9361_phy_B, rx_chan1, filter_filename_, Fpass_, Fstop_) == -1) { return false; } } else { - // GET ad9361-A stream device channel 2 as rx channel 2 - - if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan2)) + // GET ad9361-A stream device channel 1 as rx channel 1 + std::cout << "* Acquiring " << rx_stream_dev_a << " phy channel 1\n"; + if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan1)) { - std::cout << "RX channel 2 not found\n"; - throw std::runtime_error("RX channel 2 not found"); + std::cout << rx_stream_dev_a << " channel 1 not found\n"; + throw std::runtime_error(rx_stream_dev_a + "RX channel 1 not found"); } - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ctx, ad9361_phy, rx_chan2, filter_filename_, Fpass_, Fstop_) == -1) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq0_, rf_port_select_, ctx, ad9361_phy, rx_chan1, filter_filename_, Fpass_, Fstop_) == -1) { return false; } @@ -463,26 +430,28 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, std::cout << "* Enabling IIO streaming channels\n"; if (rx1_enable_) { - iio_channel_enable(rx_chan1); + iio_channel_enable(rx_chan0); } if (rx2_enable_) { - iio_channel_enable(rx_chan2); + iio_channel_enable(rx_chan1); } if (!rx1_enable_ and !rx2_enable_) { std::cout << "WARNING: No Rx channels enabled.\n"; } + std::cout << "configuring " << RX_DEV_A << " device parameters\n"; if (setup_device_parameters(ad9361_phy, quadrature_, rfdc_, bbdc_, gain_mode_rx1_, gain_mode_rx2_) < 0) { - throw std::runtime_error("setup AD9361 device parameters failed"); + throw std::runtime_error("configuring " + RX_DEV_A + " device parameters failed\n"); } if (enable_ad9361_b) { + std::cout << "configuring " << RX_DEV_B << " device parameters\n"; if (setup_device_parameters(ad9361_phy_B, quadrature_, rfdc_, bbdc_, gain_mode_rx1_, gain_mode_rx2_) < 0) { - throw std::runtime_error("setup AD9361 device parameters failed"); + throw std::runtime_error("configuring " + RX_DEV_B + " device parameters failed\n"); } } @@ -510,7 +479,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, { if (gain_mode_rx2_ == "manual") { - ret = iio_device_attr_write_double(ad9361_phy_B, "in_voltage1_hardwaregain", rf_gain_rx2_); + ret = iio_device_attr_write_double(ad9361_phy_B, "in_voltage0_hardwaregain", rf_gain_rx2_); if (ret < 0) { std::cout << "Failed to set in_voltage1_hardwaregain: " << ret << '\n'; @@ -548,8 +517,8 @@ bool config_ad9361_rx_remote(const std::string &remote_host, struct iio_context *ctx; // Streaming devices struct iio_device *rx; + struct iio_channel *rx_chan0; struct iio_channel *rx_chan1; - struct iio_channel *rx_chan2; #ifndef LIBAD9361_VERSION_GREATER_THAN_01 if (filter_source_ == "Design") @@ -592,124 +561,31 @@ bool config_ad9361_rx_remote(const std::string &remote_host, int ret; std::cout << "* Initializing AD9361 IIO streaming channels\n"; - if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan1)) + if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan0)) { std::cout << "RX channel 1 not found\n"; throw std::runtime_error("RX channel 1 not found"); } - if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan2)) + if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan1)) { std::cout << "RX channel 2 not found\n"; throw std::runtime_error("RX channel 2 not found"); } - if (filter_source_ == "Off") + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ctx, ad9361_phy, rx_chan0, filter_filename_, Fpass_, Fstop_) == -1) { - struct stream_cfg rxcfg; - rxcfg.bw_hz = bandwidth_; - rxcfg.fs_hz = sample_rate_; - rxcfg.lo_hz = freq_; - rxcfg.rfport = rf_port_select_.c_str(); - - if (!cfg_ad9361_streaming_ch(ctx, &rxcfg, RX, 0)) - { - std::cout << "RX port 0 not found\n"; - throw std::runtime_error("AD9361 IIO RX port 0 not found"); - } - } - else if (filter_source_ == "Auto") - { - ret = ad9361_set_bb_rate(ad9361_phy, sample_rate_); - if (ret) - { - throw std::runtime_error("Unable to set BB rate"); - // set bw - // params.push_back("in_voltage_rf_bandwidth=" + boost::to_string(bandwidth)); - } - // wr_ch_str(rx_chan1, "rf_port_select", rf_port_select_.c_str()); - ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); - if (ret) - { - throw std::runtime_error("Unable to set rf_port_select"); - } - wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); - if (!get_lo_chan(ctx, RX, &rx_chan1)) - { - return false; - } - wr_ch_lli(rx_chan1, "frequency", freq_); - } - else if (filter_source_ == "File") - { - try - { - if (!load_fir_filter(filter_filename_, ad9361_phy)) - { - throw std::runtime_error("Unable to load filter file"); - } - } - catch (const std::runtime_error &e) - { - std::cout << "Exception cached when configuring the RX FIR filter: " << e.what() << '\n'; - } - ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); - if (ret) - { - throw std::runtime_error("Unable to set rf_port_select"); - } - wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); - if (!get_lo_chan(ctx, RX, &rx_chan1)) - { - return false; - } - wr_ch_lli(rx_chan1, "frequency", freq_); - } -#if LIBAD9361_VERSION_GREATER_THAN_01 - else if (filter_source_ == "Design") - { - ret = ad9361_set_bb_rate_custom_filter_manual( - ad9361_phy, sample_rate_, static_cast(Fpass_), static_cast(Fstop_), bandwidth_, bandwidth_); - if (ret) - { - throw std::runtime_error("Unable to set BB rate"); - } - ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str()); - if (ret) - { - throw std::runtime_error("Unable to set rf_port_select"); - } - wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_); - if (!get_lo_chan(ctx, RX, &rx_chan1)) - { - return false; - } - wr_ch_lli(rx_chan1, "frequency", freq_); - } -#endif - else - { - throw std::runtime_error("Unknown filter configuration"); - } - - // Filters can only be disabled after the sample rate has been set - if (filter_source_ == "Off") - { - ret = ad9361_set_trx_fir_enable(ad9361_phy, false); - if (ret) - { - throw std::runtime_error("Unable to disable filters"); - } + return false; } std::cout << "* Enabling IIO streaming channels\n"; if (rx1_enable_) { - iio_channel_enable(rx_chan1); + iio_channel_enable(rx_chan0); } if (rx2_enable_) { - iio_channel_enable(rx_chan2); + iio_channel_enable(rx_chan1); } if (!rx1_enable_ and !rx2_enable_) { @@ -790,6 +666,7 @@ bool config_ad9361_lo_local(uint64_t bandwidth_, { // TX stream config std::cout << "Start of AD9361 TX Local Oscillator DDS configuration\n"; + struct iio_channel *tx_chan; struct stream_cfg txcfg; txcfg.bw_hz = bandwidth_; txcfg.fs_hz = sample_rate_; @@ -817,15 +694,23 @@ bool config_ad9361_lo_local(uint64_t bandwidth_, } std::cout << "* Configuring AD9361 for streaming TX\n"; - if (!cfg_ad9361_streaming_ch(ctx, &txcfg, TX, 0)) - { - std::cout << "TX port 0 not found\n"; - throw std::runtime_error("AD9361 IIO TX port 0 not found"); - } // ENABLE DDS on TX1 struct iio_device *ad9361_phy; ad9361_phy = iio_context_find_device(ctx, "ad9361-phy"); + + if (!get_ad9361_stream_ch(ctx, TX, ad9361_phy, 0, &tx_chan)) + { + std::cout << "TX channel 0 not found\n"; + throw std::runtime_error("TX channel 0 not found"); + } + + if (!cfg_ad9361_streaming_ch(ctx, &txcfg, TX, tx_chan)) + { + std::cout << "TX LO channel not found\n"; + throw std::runtime_error("TX LO channel not found"); + } + int ret; // set output amplifier attenuation ret = iio_device_attr_write_double(ad9361_phy, "out_voltage0_hardwaregain", -std::abs(tx_attenuation_db_)); @@ -932,6 +817,7 @@ bool config_ad9361_lo_remote(const std::string &remote_host, { // TX stream config std::cout << "Start of AD9361 TX Local Oscillator DDS configuration\n"; + struct iio_channel *tx_chan; struct stream_cfg txcfg; txcfg.bw_hz = bandwidth_; txcfg.fs_hz = sample_rate_; @@ -959,15 +845,22 @@ bool config_ad9361_lo_remote(const std::string &remote_host, } std::cout << "* Configuring AD9361 for streaming TX\n"; - if (!cfg_ad9361_streaming_ch(ctx, &txcfg, TX, 0)) - { - std::cout << "TX port 0 not found\n"; - throw std::runtime_error("AD9361 IIO TX port 0 not found"); - } // ENABLE DDS on TX1 struct iio_device *ad9361_phy; ad9361_phy = iio_context_find_device(ctx, "ad9361-phy"); + + if (!get_ad9361_stream_ch(ctx, TX, ad9361_phy, 0, &tx_chan)) + { + std::cout << "TX channel 0 not found\n"; + throw std::runtime_error("TX channel 0 not found"); + } + + if (!cfg_ad9361_streaming_ch(ctx, &txcfg, TX, tx_chan)) + { + std::cout << "TX LO channel not found\n"; + throw std::runtime_error("TX LO channel not found"); + } int ret; // set output amplifier attenuation ret = iio_device_attr_write_double(ad9361_phy, "out_voltage0_hardwaregain", -std::abs(tx_attenuation_db_)); @@ -1197,8 +1090,8 @@ bool disable_ad9361_rx_local() { struct iio_context *ctx; struct iio_device *rx; + struct iio_channel *rx_chan0; struct iio_channel *rx_chan1; - struct iio_channel *rx_chan2; ctx = iio_create_default_context(); if (!ctx) @@ -1219,20 +1112,20 @@ bool disable_ad9361_rx_local() return false; } - if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan1)) + if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan0)) { std::cout << "RX channel 1 not found when disabling RX channels\n"; return false; } - if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan2)) + if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan1)) { std::cout << "RX channel 2 not found when disabling RX channels\n"; return false; } + iio_channel_disable(rx_chan0); iio_channel_disable(rx_chan1); - iio_channel_disable(rx_chan2); iio_context_destroy(ctx); return true; } @@ -1242,8 +1135,8 @@ bool disable_ad9361_rx_remote(const std::string &remote_host) { struct iio_context *ctx; struct iio_device *rx; + struct iio_channel *rx_chan0; struct iio_channel *rx_chan1; - struct iio_channel *rx_chan2; ctx = iio_create_network_context(remote_host.c_str()); if (!ctx) @@ -1258,19 +1151,19 @@ bool disable_ad9361_rx_remote(const std::string &remote_host) return false; } - if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan1)) + if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan0)) { std::cout << "RX channel 1 not found at " << remote_host << " when disabling RX channels\n"; return false; } - if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan2)) + if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan1)) { std::cout << "RX channel 2 not found at " << remote_host << " when disabling RX channels\n"; return false; } + iio_channel_disable(rx_chan0); iio_channel_disable(rx_chan1); - iio_channel_disable(rx_chan2); iio_context_destroy(ctx); return true; } diff --git a/src/algorithms/signal_source/libs/ad9361_manager.h b/src/algorithms/signal_source/libs/ad9361_manager.h index 9ddbfbe80..2d93c2c57 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.h +++ b/src/algorithms/signal_source/libs/ad9361_manager.h @@ -84,7 +84,8 @@ bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, en bool config_ad9361_rx_local(uint64_t bandwidth_, uint64_t sample_rate_, - uint64_t freq_, + uint64_t freq0_, + uint64_t freq1_, const std::string &rf_port_select_, bool rx1_enable_, bool rx2_enable_, From 38ed8ced4ed1f1d0724d937be2d114365c989fb0 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Tue, 17 May 2022 10:49:13 +0200 Subject: [PATCH 04/13] configure the AD9361 digital filter on a per RX-channel basis. Keep the LO is the same for all RX channels in the same device. --- .../signal_source/libs/ad9361_manager.cc | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 48701d44e..337cf4197 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -111,21 +111,12 @@ bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn /* applies streaming configuration through IIO */ -bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, iio_channel *chn) +void cfg_ad9361_streaming_ch(struct stream_cfg *cfg, enum iodev type, iio_channel *chn) { // Configure phy and lo channels wr_ch_str(chn, "rf_port_select", cfg->rfport); wr_ch_lli(chn, "rf_bandwidth", cfg->bw_hz); wr_ch_lli(chn, "sampling_frequency", cfg->fs_hz); - - // Configure LO channel - std::cout << "* Acquiring LO channel " << (type == TX ? "TX" : "RX") << '\n'; - if (!get_lo_chan(ctx, type, &chn)) - { - return false; - } - wr_ch_lli(chn, "frequency", cfg->lo_hz); - return true; } int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sample_rate_, uint64_t freq_, const std::string &rf_port_select_, struct iio_context *ctx, @@ -139,12 +130,7 @@ int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sampl rxcfg.fs_hz = sample_rate_; rxcfg.lo_hz = freq_; rxcfg.rfport = rf_port_select_.c_str(); - - if (!cfg_ad9361_streaming_ch(ctx, &rxcfg, RX, rx_chan)) - { - std::cout << "RX LO channel not found\n"; - throw std::runtime_error("AD9361 IIO LO not found"); - } + cfg_ad9361_streaming_ch(&rxcfg, RX, rx_chan); } else if (filter_source_ == "Auto") { @@ -388,6 +374,15 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, return false; } + // Configure LO channel + std::cout << "* Acquiring LO channel RX\n"; + if (!get_lo_chan(ctx, RX, &rx_chan0)) + { + std::cout << "RX LO channel not found\n"; + throw std::runtime_error("RX LO channel not found"); + } + wr_ch_lli(rx_chan0, "frequency", freq0_); + if (enable_ad9361_b) { // set-up AD9361-B stream device @@ -578,6 +573,15 @@ bool config_ad9361_rx_remote(const std::string &remote_host, return false; } + // Configure LO channel + std::cout << "* Acquiring LO channel RX\n"; + if (!get_lo_chan(ctx, RX, &rx_chan0)) + { + std::cout << "RX LO channel not found\n"; + throw std::runtime_error("RX LO channel not found"); + } + wr_ch_lli(rx_chan0, "frequency", freq_); + std::cout << "* Enabling IIO streaming channels\n"; if (rx1_enable_) { @@ -705,11 +709,16 @@ bool config_ad9361_lo_local(uint64_t bandwidth_, throw std::runtime_error("TX channel 0 not found"); } - if (!cfg_ad9361_streaming_ch(ctx, &txcfg, TX, tx_chan)) + cfg_ad9361_streaming_ch(&txcfg, TX, tx_chan); + + // Configure LO channel + std::cout << "* Acquiring LO channel TX\n"; + if (!get_lo_chan(ctx, TX, &tx_chan)) { std::cout << "TX LO channel not found\n"; throw std::runtime_error("TX LO channel not found"); } + wr_ch_lli(tx_chan, "frequency", txcfg.lo_hz); int ret; // set output amplifier attenuation @@ -856,11 +865,17 @@ bool config_ad9361_lo_remote(const std::string &remote_host, throw std::runtime_error("TX channel 0 not found"); } - if (!cfg_ad9361_streaming_ch(ctx, &txcfg, TX, tx_chan)) + cfg_ad9361_streaming_ch(&txcfg, TX, tx_chan); + + // Configure LO channel + std::cout << "* Acquiring LO channel TX\n"; + if (!get_lo_chan(ctx, TX, &tx_chan)) { std::cout << "TX LO channel not found\n"; throw std::runtime_error("TX LO channel not found"); } + wr_ch_lli(tx_chan, "frequency", txcfg.lo_hz); + int ret; // set output amplifier attenuation ret = iio_device_attr_write_double(ad9361_phy, "out_voltage0_hardwaregain", -std::abs(tx_attenuation_db_)); From 4e37fa45adb8b3a27df2cb7665d329d25aae1580 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Tue, 17 May 2022 15:40:43 +0200 Subject: [PATCH 05/13] fix AD9361 configuration --- .../signal_source/libs/ad9361_manager.cc | 122 +++++++++++++----- 1 file changed, 89 insertions(+), 33 deletions(-) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 337cf4197..46650f984 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -91,19 +91,53 @@ bool get_ad9361_stream_ch(struct iio_context *ctx __attribute__((unused)), enum return *chn != nullptr; } - -/* finds AD9361 local oscillator IIO configuration channels */ -bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn) +/* finds AD9361 phy IIO configuration channel with id chid */ +bool get_phy_chan(struct iio_device *dev, enum iodev d, int chid, struct iio_channel **chn) { + std::stringstream name; switch (d) { - // LO chan is always output, i.e. true case RX: - *chn = iio_device_find_channel(get_ad9361_phy(ctx), "altvoltage0", true); + name.str(""); + name << "voltage"; + name << chid; + *chn = iio_device_find_channel(dev, name.str().c_str(), false); return *chn != nullptr; + break; case TX: - *chn = iio_device_find_channel(get_ad9361_phy(ctx), "altvoltage1", true); + name.str(""); + name << "voltage"; + name << chid; + *chn = iio_device_find_channel(dev, name.str().c_str(), true); return *chn != nullptr; + break; + default: + return false; + } +} + +/* finds AD9361 local oscillator IIO configuration channels */ +//bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn) +bool get_lo_chan(struct iio_device *dev, enum iodev d, int chid, struct iio_channel **chn) +{ + std::stringstream name; + switch (d) + { + // LO chan is always output, i.e. true + case RX: + name.str(""); + name << "altvoltage"; + name << chid; + *chn = iio_device_find_channel(dev, name.str().c_str(), true); + return *chn != nullptr; + break; + case TX: + name.str(""); + name << "altvoltage"; + name << chid; + *chn = iio_device_find_channel(dev, name.str().c_str(), true); + return *chn != nullptr; + break; default: return false; } @@ -111,7 +145,7 @@ bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn /* applies streaming configuration through IIO */ -void cfg_ad9361_streaming_ch(struct stream_cfg *cfg, enum iodev type, iio_channel *chn) +void cfg_ad9361_streaming_ch(struct stream_cfg *cfg, iio_channel *chn) { // Configure phy and lo channels wr_ch_str(chn, "rf_port_select", cfg->rfport); @@ -119,8 +153,8 @@ void cfg_ad9361_streaming_ch(struct stream_cfg *cfg, enum iodev type, iio_channe wr_ch_lli(chn, "sampling_frequency", cfg->fs_hz); } -int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sample_rate_, uint64_t freq_, const std::string &rf_port_select_, struct iio_context *ctx, - struct iio_device *ad9361_phy_dev, struct iio_channel *rx_chan, std::string filter_filename_, float Fpass_, float Fstop_) +int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sample_rate_, uint64_t freq_, const std::string &rf_port_select_, + struct iio_device *ad9361_phy_dev, struct iio_channel *rx_chan, struct iio_channel *chn, int chid, std::string filter_filename_, float Fpass_, float Fstop_) { int ret; if (filter_source_ == "Off") @@ -130,7 +164,7 @@ int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sampl rxcfg.fs_hz = sample_rate_; rxcfg.lo_hz = freq_; rxcfg.rfport = rf_port_select_.c_str(); - cfg_ad9361_streaming_ch(&rxcfg, RX, rx_chan); + cfg_ad9361_streaming_ch(&rxcfg, chn); } else if (filter_source_ == "Auto") { @@ -148,7 +182,7 @@ int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sampl throw std::runtime_error("Unable to set rf_port_select"); } wr_ch_lli(rx_chan, "rf_bandwidth", bandwidth_); - if (!get_lo_chan(ctx, RX, &rx_chan)) + if (!get_lo_chan(ad9361_phy_dev, RX, chid, &rx_chan)) { return -1; } @@ -173,7 +207,7 @@ int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sampl throw std::runtime_error("Unable to set rf_port_select"); } wr_ch_lli(rx_chan, "rf_bandwidth", bandwidth_); - if (!get_lo_chan(ctx, RX, &rx_chan)) + if (!get_lo_chan(ad9361_phy_dev, RX, chid, &rx_chan)) { return -1; } @@ -194,7 +228,7 @@ int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sampl throw std::runtime_error("Unable to set rf_port_select"); } wr_ch_lli(rx_chan, "rf_bandwidth", bandwidth_); - if (!get_lo_chan(ctx, RX, &rx_chan)) + if (!get_lo_chan(ad9361_phy_dev, RX, chid, &rx_chan)) { return -1; } @@ -296,8 +330,10 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, struct iio_context *ctx; // Streaming devices struct iio_device *rx; - struct iio_channel *rx_chan0; - struct iio_channel *rx_chan1; + struct iio_channel *rx_chan0; // stream channel 0 + struct iio_channel *rx_chan1; // stream channel 1 + struct iio_channel *chn; // phy channel + int ret; #ifndef LIBAD9361_VERSION_GREATER_THAN_01 @@ -369,19 +405,23 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, std::cout << rx_stream_dev_a << " channel 0 not found\n"; throw std::runtime_error(rx_stream_dev_a + "RX channel 0 not found"); } - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq0_, rf_port_select_, ctx, ad9361_phy, rx_chan0, filter_filename_, Fpass_, Fstop_) == -1) + + if (!get_phy_chan(ad9361_phy, RX, 0, &chn)) { return false; } - - // Configure LO channel - std::cout << "* Acquiring LO channel RX\n"; - if (!get_lo_chan(ctx, RX, &rx_chan0)) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq0_, rf_port_select_, ad9361_phy, rx_chan0, chn, 0, filter_filename_, Fpass_, Fstop_) == -1) { - std::cout << "RX LO channel not found\n"; - throw std::runtime_error("RX LO channel not found"); + return false; } - wr_ch_lli(rx_chan0, "frequency", freq0_); + // Configure LO channel + std::cout << "* Acquiring LO RX channel 0\n"; + if (!get_lo_chan(ad9361_phy, RX, 0, &chn)) + { + std::cout << "RX LO channel 0not found\n"; + throw std::runtime_error("RX LO channel 0not found"); + } + wr_ch_lli(chn, "frequency", freq0_); if (enable_ad9361_b) { @@ -402,10 +442,23 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, std::cout << RX_STREAM_DEV_B << " channel 0 not found\n"; throw std::runtime_error(RX_STREAM_DEV_B + "RX channel 0 not found"); } - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq1_, rf_port_select_, ctx, ad9361_phy_B, rx_chan1, filter_filename_, Fpass_, Fstop_) == -1) + + if (!get_phy_chan(ad9361_phy, RX, 1, &chn)) { return false; } + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq1_, rf_port_select_, ad9361_phy_B, rx_chan1, chn, 1, filter_filename_, Fpass_, Fstop_) == -1) + { + return false; + } + // Configure LO channel + std::cout << "* Acquiring LO RX channel 1\n"; + if (!get_lo_chan(ad9361_phy_B, RX, 1, &chn)) + { + std::cout << "RX LO channel 1 not found\n"; + throw std::runtime_error("RX LO channel 1 not found"); + } + wr_ch_lli(chn, "frequency", freq0_); } else { @@ -416,7 +469,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, std::cout << rx_stream_dev_a << " channel 1 not found\n"; throw std::runtime_error(rx_stream_dev_a + "RX channel 1 not found"); } - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq0_, rf_port_select_, ctx, ad9361_phy, rx_chan1, filter_filename_, Fpass_, Fstop_) == -1) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq0_, rf_port_select_, ad9361_phy, rx_chan1, chn, 1, filter_filename_, Fpass_, Fstop_) == -1) { return false; } @@ -514,6 +567,7 @@ bool config_ad9361_rx_remote(const std::string &remote_host, struct iio_device *rx; struct iio_channel *rx_chan0; struct iio_channel *rx_chan1; + struct iio_channel *chn; // phy channel #ifndef LIBAD9361_VERSION_GREATER_THAN_01 if (filter_source_ == "Design") @@ -561,21 +615,23 @@ bool config_ad9361_rx_remote(const std::string &remote_host, std::cout << "RX channel 1 not found\n"; throw std::runtime_error("RX channel 1 not found"); } - if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan1)) { std::cout << "RX channel 2 not found\n"; throw std::runtime_error("RX channel 2 not found"); } - - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ctx, ad9361_phy, rx_chan0, filter_filename_, Fpass_, Fstop_) == -1) + if (!get_phy_chan(ad9361_phy, RX, 0, &chn)) + { + return false; + } + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ad9361_phy, rx_chan0, chn, 0, filter_filename_, Fpass_, Fstop_) == -1) { return false; } // Configure LO channel std::cout << "* Acquiring LO channel RX\n"; - if (!get_lo_chan(ctx, RX, &rx_chan0)) + if (!get_lo_chan(ad9361_phy, RX, 0, &chn)) { std::cout << "RX LO channel not found\n"; throw std::runtime_error("RX LO channel not found"); @@ -709,11 +765,11 @@ bool config_ad9361_lo_local(uint64_t bandwidth_, throw std::runtime_error("TX channel 0 not found"); } - cfg_ad9361_streaming_ch(&txcfg, TX, tx_chan); + cfg_ad9361_streaming_ch(&txcfg, tx_chan); // Configure LO channel std::cout << "* Acquiring LO channel TX\n"; - if (!get_lo_chan(ctx, TX, &tx_chan)) + if (!get_lo_chan(ad9361_phy, TX, 1, &tx_chan)) { std::cout << "TX LO channel not found\n"; throw std::runtime_error("TX LO channel not found"); @@ -865,11 +921,11 @@ bool config_ad9361_lo_remote(const std::string &remote_host, throw std::runtime_error("TX channel 0 not found"); } - cfg_ad9361_streaming_ch(&txcfg, TX, tx_chan); + cfg_ad9361_streaming_ch(&txcfg, tx_chan); // Configure LO channel std::cout << "* Acquiring LO channel TX\n"; - if (!get_lo_chan(ctx, TX, &tx_chan)) + if (!get_lo_chan(ad9361_phy, TX, 1, &tx_chan)) { std::cout << "TX LO channel not found\n"; throw std::runtime_error("TX LO channel not found"); From 6b9941dd132b47499c493c050c785b28bd3741b4 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Tue, 17 May 2022 19:29:02 +0200 Subject: [PATCH 06/13] fix the configuration of the second AD9361 when it is present --- src/algorithms/signal_source/libs/ad9361_manager.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 46650f984..9be3dfcb2 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -443,7 +443,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, throw std::runtime_error(RX_STREAM_DEV_B + "RX channel 0 not found"); } - if (!get_phy_chan(ad9361_phy, RX, 1, &chn)) + if (!get_phy_chan(ad9361_phy_B, RX, 0, &chn)) { return false; } @@ -453,12 +453,12 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, } // Configure LO channel std::cout << "* Acquiring LO RX channel 1\n"; - if (!get_lo_chan(ad9361_phy_B, RX, 1, &chn)) + if (!get_lo_chan(ad9361_phy_B, RX, 0, &chn)) { std::cout << "RX LO channel 1 not found\n"; throw std::runtime_error("RX LO channel 1 not found"); } - wr_ch_lli(chn, "frequency", freq0_); + wr_ch_lli(chn, "frequency", freq1_); } else { @@ -497,7 +497,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, if (enable_ad9361_b) { std::cout << "configuring " << RX_DEV_B << " device parameters\n"; - if (setup_device_parameters(ad9361_phy_B, quadrature_, rfdc_, bbdc_, gain_mode_rx1_, gain_mode_rx2_) < 0) + if (setup_device_parameters(ad9361_phy_B, quadrature_, rfdc_, bbdc_, gain_mode_rx2_, gain_mode_rx2_) < 0) { throw std::runtime_error("configuring " + RX_DEV_B + " device parameters failed\n"); } From ab310a367adae5114de2abe67477215136d5e9a5 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Wed, 18 May 2022 18:04:43 +0200 Subject: [PATCH 07/13] fix gain_rx2 --- .../signal_source/adapters/ad9361_fpga_signal_source.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc index c44e7b11c..131c9235c 100644 --- a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc @@ -58,7 +58,7 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(const ConfigurationInterface *con filter_filename_(configuration->property(role + ".filter_filename", filter_file_)), filename0_(configuration->property(role + ".filename", empty_string)), rf_gain_rx1_(configuration->property(role + ".gain_rx1", default_manual_gain_rx1)), - rf_gain_rx2_(configuration->property(role + ".gain_rx1", default_manual_gain_rx2)), + rf_gain_rx2_(configuration->property(role + ".gain_rx2", default_manual_gain_rx2)), freq0_(configuration->property(role + ".freq", 0)), sample_rate_(configuration->property(role + ".sampling_frequency", default_bandwidth)), bandwidth_(configuration->property(role + ".bandwidth", default_bandwidth)), From 923398fa5e16b915d52172d90aaee7f57b94a594 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Thu, 19 May 2022 15:33:56 +0200 Subject: [PATCH 08/13] fixed disable_ad9361_rx_local --- .../signal_source/libs/ad9361_manager.cc | 53 +++++++++++++++---- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 9be3dfcb2..60125ad71 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -447,7 +447,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, { return false; } - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq1_, rf_port_select_, ad9361_phy_B, rx_chan1, chn, 1, filter_filename_, Fpass_, Fstop_) == -1) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq1_, rf_port_select_, ad9361_phy_B, rx_chan1, chn, 0, filter_filename_, Fpass_, Fstop_) == -1) { return false; } @@ -1177,22 +1177,56 @@ bool disable_ad9361_rx_local() return false; } - if (!get_ad9361_stream_dev(ctx, RX, &rx)) + // check if the second AD9361 is present + struct iio_device *ad9361_phy_B; + bool enable_ad9361_b; + ad9361_phy_B = iio_context_find_device(ctx, RX_DEV_B.c_str()); + if (ad9361_phy_B) { - std::cout << "No rx streams found when disabling RX channels\n"; - return false; + enable_ad9361_b = true; // the RF board has two AD9361 devices + } + else + { + enable_ad9361_b = false; // the RF board has one AD9361 device } + std::string rx_stream_dev_a = (enable_ad9361_b ? RX_STREAM_DEV_A : RX_STREAM_DEV); + rx = iio_context_find_device(ctx, rx_stream_dev_a.c_str()); + if (!rx) + { + std::cout << "No " << rx_stream_dev_a << " stream dev found when disabling RX channels\n"; + throw std::runtime_error("AD9361 IIO No " + rx_stream_dev_a + " stream dev found"); + } + + // get AD9361-A stream device channel 0 as rx channel 0 if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan0)) { - std::cout << "RX channel 1 not found when disabling RX channels\n"; - return false; + std::cout << rx_stream_dev_a << " channel 0 not found when disabling RX channels\n"; + throw std::runtime_error(rx_stream_dev_a + "RX channel 0 not found"); } - if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan1)) + if (enable_ad9361_b) { - std::cout << "RX channel 2 not found when disabling RX channels\n"; - return false; + rx = iio_context_find_device(ctx, RX_STREAM_DEV_B.c_str()); + if (!rx) + { + std::cout << "No " << RX_STREAM_DEV_B << " stream dev found when disabling RX channels\n"; + throw std::runtime_error("AD9361 IIO No " + RX_STREAM_DEV_B + " stream dev found"); + } + + if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan1)) + { + std::cout << RX_STREAM_DEV_B << " channel 0 not found when disabling RX channels\n"; + throw std::runtime_error(RX_STREAM_DEV_B + "RX channel 0 not found"); + } + } + else + { + if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan1)) + { + std::cout << rx_stream_dev_a << " channel 1 not found\n"; + throw std::runtime_error(rx_stream_dev_a + "RX channel 1 not found"); + } } iio_channel_disable(rx_chan0); @@ -1201,7 +1235,6 @@ bool disable_ad9361_rx_local() return true; } - bool disable_ad9361_rx_remote(const std::string &remote_host) { struct iio_context *ctx; From da47cadcffeaffb2263fd1700041fbca7d567849 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Thu, 19 May 2022 15:49:50 +0200 Subject: [PATCH 09/13] fix ad9361_manager comments --- src/algorithms/signal_source/libs/ad9361_manager.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 60125ad71..a92cb3f30 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -415,7 +415,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, return false; } // Configure LO channel - std::cout << "* Acquiring LO RX channel 0\n"; + std::cout << "* Acquiring " << RX_DEV_A << " LO RX channel 0\n"; if (!get_lo_chan(ad9361_phy, RX, 0, &chn)) { std::cout << "RX LO channel 0not found\n"; @@ -452,7 +452,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, return false; } // Configure LO channel - std::cout << "* Acquiring LO RX channel 1\n"; + std::cout << "* Acquiring " << RX_DEV_B << " LO RX channel 0\n"; if (!get_lo_chan(ad9361_phy_B, RX, 0, &chn)) { std::cout << "RX LO channel 1 not found\n"; From 8131bdffc59fa625b29321b8c670aeee7c4143a8 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Fri, 20 May 2022 16:54:00 +0200 Subject: [PATCH 10/13] perform fmComms5 specific mult-chip sync configuration --- src/algorithms/signal_source/libs/ad9361_manager.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index a92cb3f30..be1bf2d25 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -483,6 +483,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, if (rx2_enable_) { iio_channel_enable(rx_chan1); + ad9361_fmcomms5_multichip_sync(ctx, FIXUP_INTERFACE_TIMING | CHECK_SAMPLE_RATES); } if (!rx1_enable_ and !rx2_enable_) { From 6e368622e2897c35e87610d143a782100123fc6c Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Mon, 30 May 2022 09:02:22 +0200 Subject: [PATCH 11/13] Prefer initialization to assignment in constructors --- .../signal_source/adapters/ad9361_fpga_signal_source.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc index 131c9235c..4138c038d 100644 --- a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc @@ -60,6 +60,7 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(const ConfigurationInterface *con rf_gain_rx1_(configuration->property(role + ".gain_rx1", default_manual_gain_rx1)), rf_gain_rx2_(configuration->property(role + ".gain_rx2", default_manual_gain_rx2)), freq0_(configuration->property(role + ".freq", 0)), + freq1_(configuration->property(role + ".freq1", static_cast(GPS_L5_FREQ_HZ))), sample_rate_(configuration->property(role + ".sampling_frequency", default_bandwidth)), bandwidth_(configuration->property(role + ".bandwidth", default_bandwidth)), samples_to_skip_(0), @@ -100,8 +101,8 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(const ConfigurationInterface *con if (freq0_ == 0) { + // use ".freq0" freq0_ = configuration->property(role + ".freq0", static_cast(GPS_L1_FREQ_HZ)); - freq1_ = configuration->property(role + ".freq1", static_cast(GPS_L5_FREQ_HZ)); } if (filter_auto_) From 4c278cb3dfae39962938463299cf20463f7a1407 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Mon, 30 May 2022 11:12:38 +0200 Subject: [PATCH 12/13] removed commented code --- src/algorithms/signal_source/libs/ad9361_manager.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index be1bf2d25..71ffc0f63 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -117,7 +117,6 @@ bool get_phy_chan(struct iio_device *dev, enum iodev d, int chid, struct iio_cha } /* finds AD9361 local oscillator IIO configuration channels */ -//bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn) bool get_lo_chan(struct iio_device *dev, enum iodev d, int chid, struct iio_channel **chn) { std::stringstream name; From 037ad07478978c5140e5784e84aa732908822975 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 31 May 2022 07:34:12 +0200 Subject: [PATCH 13/13] Apply clang-tidy --- .../signal_source/libs/ad9361_manager.cc | 14 +++++++++----- src/algorithms/signal_source/libs/fpga_dma.cc | 13 +++++-------- src/algorithms/signal_source/libs/fpga_dma.h | 6 +++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 71ffc0f63..ccf02220f 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -22,6 +22,7 @@ #include // for ifstream #include #include +#include #include /* check return value of attr_write function */ @@ -91,6 +92,7 @@ bool get_ad9361_stream_ch(struct iio_context *ctx __attribute__((unused)), enum return *chn != nullptr; } + /* finds AD9361 phy IIO configuration channel with id chid */ bool get_phy_chan(struct iio_device *dev, enum iodev d, int chid, struct iio_channel **chn) { @@ -116,6 +118,7 @@ bool get_phy_chan(struct iio_device *dev, enum iodev d, int chid, struct iio_cha } } + /* finds AD9361 local oscillator IIO configuration channels */ bool get_lo_chan(struct iio_device *dev, enum iodev d, int chid, struct iio_channel **chn) { @@ -152,7 +155,8 @@ void cfg_ad9361_streaming_ch(struct stream_cfg *cfg, iio_channel *chn) wr_ch_lli(chn, "sampling_frequency", cfg->fs_hz); } -int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sample_rate_, uint64_t freq_, const std::string &rf_port_select_, + +int setup_filter(const std::string &filter_source_, uint64_t bandwidth_, uint64_t sample_rate_, uint64_t freq_, const std::string &rf_port_select_, struct iio_device *ad9361_phy_dev, struct iio_channel *rx_chan, struct iio_channel *chn, int chid, std::string filter_filename_, float Fpass_, float Fstop_) { int ret; @@ -251,6 +255,7 @@ int setup_filter(std::string filter_source_, uint64_t bandwidth_, uint64_t sampl return 0; } + int setup_device_parameters(iio_device *ad9361_phy_dev, bool quadrature_, bool rfdc_, bool bbdc_, const std::string &gain_mode_rx1_, const std::string &gain_mode_rx2_) { int ret; @@ -304,6 +309,7 @@ int setup_device_parameters(iio_device *ad9361_phy_dev, bool quadrature_, bool r return ret; } + bool config_ad9361_rx_local(uint64_t bandwidth_, uint64_t sample_rate_, uint64_t freq0_, @@ -325,7 +331,6 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, { // RX stream config - struct iio_context *ctx; // Streaming devices struct iio_device *rx; @@ -387,7 +392,6 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, } // set-up AD9361-A stream device - std::string rx_stream_dev_a = (enable_ad9361_b ? RX_STREAM_DEV_A : RX_STREAM_DEV); std::cout << "* Acquiring " << rx_stream_dev_a << " streaming device\n"; rx = iio_context_find_device(ctx, rx_stream_dev_a.c_str()); @@ -425,7 +429,6 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, if (enable_ad9361_b) { // set-up AD9361-B stream device - std::cout << "* Acquiring " << RX_STREAM_DEV_B << " streaming device\n"; rx = iio_context_find_device(ctx, RX_STREAM_DEV_B.c_str()); if (!rx) @@ -624,7 +627,7 @@ bool config_ad9361_rx_remote(const std::string &remote_host, { return false; } - if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ad9361_phy, rx_chan0, chn, 0, filter_filename_, Fpass_, Fstop_) == -1) + if (setup_filter(std::move(filter_source_), bandwidth_, sample_rate_, freq_, rf_port_select_, ad9361_phy, rx_chan0, chn, 0, std::move(filter_filename_), Fpass_, Fstop_) == -1) { return false; } @@ -1235,6 +1238,7 @@ bool disable_ad9361_rx_local() return true; } + bool disable_ad9361_rx_remote(const std::string &remote_host) { struct iio_context *ctx; diff --git a/src/algorithms/signal_source/libs/fpga_dma.cc b/src/algorithms/signal_source/libs/fpga_dma.cc index 8f4f48219..2d0b5c660 100644 --- a/src/algorithms/signal_source/libs/fpga_dma.cc +++ b/src/algorithms/signal_source/libs/fpga_dma.cc @@ -31,7 +31,7 @@ int Fpga_DMA::DMA_open() return tx_channel.fd; } - tx_channel.buf_ptr = (struct channel_buffer *)mmap(NULL, sizeof(struct channel_buffer) * TX_BUFFER_COUNT, + tx_channel.buf_ptr = (struct channel_buffer *)mmap(nullptr, sizeof(struct channel_buffer) * TX_BUFFER_COUNT, PROT_READ | PROT_WRITE, MAP_SHARED, tx_channel.fd, 0); if (tx_channel.buf_ptr == MAP_FAILED) { @@ -68,7 +68,7 @@ int Fpga_DMA::DMA_open() } -std::array *Fpga_DMA::get_buffer_address(void) +std::array *Fpga_DMA::get_buffer_address() const { #if INTPTR_MAX == INT64_MAX // 64-bit processor architecture return &tx_channel.buf_ptr[0].buffer; @@ -78,7 +78,7 @@ std::array *Fpga_DMA::get_buffer_address(void) } -int Fpga_DMA::DMA_write(int nbytes) +int Fpga_DMA::DMA_write(int nbytes) const { #if INTPTR_MAX == INT64_MAX // 64-bit processor architecture @@ -105,21 +105,18 @@ int Fpga_DMA::DMA_write(int nbytes) std::cerr << "Proxy DMA Tx transfer error " << '\n'; return -1; } - #else // 32-bit processor architecture - const int num_bytes_sent = write(tx_fd, buffer.data(), nbytes); if (num_bytes_sent != nbytes) { return -1; } - #endif - return 0; } -int Fpga_DMA::DMA_close() + +int Fpga_DMA::DMA_close() const { #if INTPTR_MAX == INT64_MAX // 64-bit processor architecture if (munmap(tx_channel.buf_ptr, sizeof(struct channel_buffer))) diff --git a/src/algorithms/signal_source/libs/fpga_dma.h b/src/algorithms/signal_source/libs/fpga_dma.h index b261d63ee..020d561e3 100644 --- a/src/algorithms/signal_source/libs/fpga_dma.h +++ b/src/algorithms/signal_source/libs/fpga_dma.h @@ -78,17 +78,17 @@ public: /*! * \brief Obtain DMA buffer address. */ - std::array *get_buffer_address(void); + std::array *get_buffer_address(void) const; /*! * \brief Transfer DMA data */ - int DMA_write(int nbytes); + int DMA_write(int nbytes) const; /*! * \brief Close the DMA device driver */ - int DMA_close(void); + int DMA_close(void) const; private: #if INTPTR_MAX == INT64_MAX // 64-bit processor architecture