1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-24 05:53:16 +00:00

Adding Local Oscillator generation for dual band operation using AD9361 FPGA source. Bug fix in FPGA flowgraph

This commit is contained in:
Javier Arribas 2018-03-27 14:24:07 +02:00
parent 376de5807f
commit ec09016750
5 changed files with 488 additions and 1 deletions

View File

@ -33,6 +33,7 @@
#include "ad9361_fpga_signal_source.h"
#include "configuration_interface.h"
#include "GPS_L1_CA.h"
#include "GPS_L2C.h"
#include <signal.h>
#include <stdio.h>
#include <glog/logging.h>
@ -191,6 +192,13 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface* configura
dump_ = configuration->property(role + ".dump", false);
dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file);
enable_dds_lo_=configuration->property(role + ".enable_dds_lo", false);
freq_rf_tx_hz_=configuration->property(role + ".freq_rf_tx_hz", GPS_L1_FREQ_HZ-GPS_L2_FREQ_HZ-1000);
freq_dds_tx_hz_=configuration->property(role + ".freq_dds_tx_hz", 1000);
scale_dds_dbfs_=configuration->property(role + ".scale_dds_dbfs", -3.0);
phase_dds_deg_=configuration->property(role + ".phase_dds_deg", 0.0);
tx_attenuation_db_=configuration->property(role + ".tx_attenuation_db", 0.0);
item_size_ = sizeof(gr_complex);
std::cout << "device address: " << uri_ << std::endl;
@ -199,6 +207,8 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface* configura
// AD9361 Frontend IC device operation
int ret;
// Streaming devices
struct iio_device *rx;
@ -258,6 +268,151 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface* configura
iio_channel_enable(rx0_i);
iio_channel_enable(rx0_q);
struct iio_device *ad9361_phy;
ad9361_phy= iio_context_find_device(ctx, "ad9361-phy");
ret=iio_device_attr_write(ad9361_phy,"trx_rate_governor","nominal");
if (ret < 0) {
std::cout<<"Failed to set trx_rate_governor: "<<ret<<std::endl;
}
ret=iio_device_attr_write(ad9361_phy,"ensm_mode","fdd");
if (ret < 0) {
std::cout<<"Failed to set ensm_mode: "<<ret<<std::endl;
}
ret=iio_device_attr_write(ad9361_phy,"calib_mode","auto");
if (ret < 0) {
std::cout<<"Failed to set calib_mode: "<<ret<<std::endl;
}
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<<std::endl;
}
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<<std::endl;
}
ret=iio_device_attr_write_double(ad9361_phy,"in_voltage0_hardwaregain",rf_gain_rx1_);
if (ret < 0) {
std::cout<<"Failed to set in_voltage0_hardwaregain: "<<ret<<std::endl;
}
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<<std::endl;
}
std::cout<<"End of AD9361 RX configuration.\n";
//LOCAL OSCILLATOR DDS GENERATOR FOR DUAL FREQUENCY OPERATION
if (enable_dds_lo_==true)
{
// TX stream config
std::cout<<"Start of AD9361 TX Local Oscillator DDS configuration\n";
struct stream_cfg txcfg;
txcfg.bw_hz = bandwidth_;
txcfg.fs_hz = sample_rate_;
txcfg.lo_hz = freq_rf_tx_hz_;
txcfg.rfport = "A";
//find tx device
struct iio_device *tx;
std::cout<<"* Acquiring AD9361 TX streaming devices\n";
if(!get_ad9361_stream_dev(ctx, TX, &tx))
{
std::cout<<"No tx dev found\n";
throw std::runtime_error("AD9361 IIO No tx dev found");
};
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
//set output amplifier attenuation
ret = iio_device_attr_write_double(ad9361_phy, "out_voltage0_hardwaregain", -tx_attenuation_db_);
if (ret < 0) {
std::cout<<"Failed to set out_voltage0_hardwaregain value "<<-tx_attenuation_db_<<" error "<<ret<<std::endl;
}
struct iio_device *dds;
dds= iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc");
struct iio_channel *dds_channel0_I;
dds_channel0_I = iio_device_find_channel(dds, "TX1_I_F1", true);
struct iio_channel *dds_channel0_Q;
dds_channel0_Q = iio_device_find_channel(dds, "TX1_Q_F1", true);
ret = iio_channel_attr_write_bool(dds_channel0_I, "raw", true);
if (ret < 0) {
std::cout<<"Failed to toggle DDS: "<<ret<<std::endl;
}
//set frequency, scale and phase
ret=iio_channel_attr_write_longlong(dds_channel0_I, "frequency",(long long) freq_dds_tx_hz_);
if (ret < 0) {
std::cout<<"Failed to set TX DDS frequency I: "<<ret<<std::endl;
}
ret=iio_channel_attr_write_longlong(dds_channel0_Q, "frequency",(long long) freq_dds_tx_hz_);
if (ret < 0) {
std::cout<<"Failed to set TX DDS frequency Q: "<<ret<<std::endl;
}
ret=iio_channel_attr_write_double(dds_channel0_I, "phase",0.0);
if (ret < 0) {
std::cout<<"Failed to set TX DDS phase I: "<<ret<<std::endl;
}
ret=iio_channel_attr_write_double(dds_channel0_Q, "phase",270000.0);
if (ret < 0) {
std::cout<<"Failed to set TX DDS phase Q: "<<ret<<std::endl;
}
ret=iio_channel_attr_write_double(dds_channel0_I, "scale",pow(10, scale_dds_dbfs_ / 20.0));
if (ret < 0) {
std::cout<<"Failed to set TX DDS scale I: "<<ret<<std::endl;
}
ret=iio_channel_attr_write_double(dds_channel0_Q, "scale",pow(10, scale_dds_dbfs_ / 20.0));
if (ret < 0) {
std::cout<<"Failed to set TX DDS scale Q: "<<ret<<std::endl;
}
//disable TX2
ret = iio_device_attr_write_double(ad9361_phy, "out_voltage1_hardwaregain", -89.0);
if (ret < 0) {
std::cout<<"Failed to set out_voltage1_hardwaregain value "<<-89.0<<" error "<<ret<<std::endl;
}
struct iio_channel *dds_channel1_I;
dds_channel1_I = iio_device_find_channel(dds, "TX2_I_F1", true);
struct iio_channel *dds_channel1_Q;
dds_channel1_Q = iio_device_find_channel(dds, "TX2_Q_F1", true);
ret=iio_channel_attr_write_double(dds_channel1_I, "scale",0);
if (ret < 0) {
std::cout<<"Failed to set TX2 DDS scale I: "<<ret<<std::endl;
}
ret=iio_channel_attr_write_double(dds_channel1_Q, "scale",0);
if (ret < 0) {
std::cout<<"Failed to set TX2 DDS scale Q: "<<ret<<std::endl;
}
}
}
@ -270,6 +425,33 @@ Ad9361FpgaSignalSource::~Ad9361FpgaSignalSource()
std::cout<<"* AD9361 Destroying context\n";
if (ctx) { iio_context_destroy(ctx); }
if (enable_dds_lo_)
{
struct iio_device *dds;
dds= iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc");
struct iio_channel *dds_channel0_I;
dds_channel0_I = iio_device_find_channel(dds, "TX1_I_F1", true);
struct iio_channel *dds_channel0_Q;
dds_channel0_Q = iio_device_find_channel(dds, "TX1_Q_F1", true);
int ret;
ret = iio_channel_attr_write_bool(dds_channel0_I, "raw", false);
if (ret < 0) {
std::cout<<"Failed to toggle DDS: "<<ret<<std::endl;
}
ret=iio_channel_attr_write_double(dds_channel0_I, "scale",0.0);
if (ret < 0) {
std::cout<<"Failed to set TX DDS scale I: "<<ret<<std::endl;
}
ret=iio_channel_attr_write_double(dds_channel0_Q, "scale",0.0);
if (ret < 0) {
std::cout<<"Failed to set TX DDS scale Q: "<<ret<<std::endl;
}
}
}

View File

@ -94,6 +94,14 @@ private:
std::string filter_file_;
bool filter_auto_;
//DDS configuration for LO generation for external mixer
bool enable_dds_lo_;
unsigned long freq_rf_tx_hz_;
unsigned long freq_dds_tx_hz_;
double scale_dds_dbfs_;
double phase_dds_deg_;
double tx_attenuation_db_;
unsigned int in_stream_;
unsigned int out_stream_;

View File

@ -0,0 +1,166 @@
/*!
* \file ad9361_manager.cc
* \brief An Analog Devices AD9361 front-end configuration library wrapper for configure some functions via iiod link.
* \author Javier Arribas, jarribas(at)cttc.es
*
* This file contains information taken from librtlsdr:
* http://git.osmocom.org/rtl-sdr/
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "ad9361_manager.h"
#include <glog/logging.h>
#include <stdio.h> //only for snprintf
#include <math.h>
#include <iostream>
/* check return value of attr_write function */
static void errchk(int v, const char* what) {
if (v < 0)
{
LOG(WARNING)<<"Error "<<v<<" writing to channel "<<what<<" value may not be supported. ";
}
}
/* write attribute: long long int */
static void wr_ch_lli(struct iio_channel *chn, const char* what, long long val)
{
errchk(iio_channel_attr_write_longlong(chn, what, val), what);
}
/* write attribute: string */
static void wr_ch_str(struct iio_channel *chn, const char* what, const char* str)
{
errchk(iio_channel_attr_write(chn, what, str), what);
}
/* helper function generating channel names */
static char* get_ch_name(const char* type, int id)
{
snprintf(tmpstr, sizeof(tmpstr), "%s%d", type, id);
return tmpstr;
}
/* returns ad9361 phy device */
static struct iio_device* get_ad9361_phy(struct iio_context *ctx)
{
struct iio_device *dev = iio_context_find_device(ctx, "ad9361-phy");
return dev;
}
/* finds AD9361 streaming IIO devices */
static bool get_ad9361_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev)
{
switch (d) {
case TX: *dev = iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc"); return *dev != NULL;
case RX: *dev = iio_context_find_device(ctx, "cf-ad9361-lpc"); return *dev != NULL;
default: return false;
}
}
/* finds AD9361 streaming IIO channels */
static bool get_ad9361_stream_ch(struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, struct iio_channel **chn)
{
*chn = iio_device_find_channel(dev, get_ch_name("voltage", chid), d == TX);
if (!*chn)
*chn = iio_device_find_channel(dev, get_ch_name("altvoltage", chid), d == TX);
return *chn != NULL;
}
/* finds AD9361 phy IIO configuration channel with id chid */
static bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn)
{
switch (d) {
case RX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("voltage", chid), false); return *chn != NULL;
case TX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("voltage", chid), true); return *chn != NULL;
default: return false;
}
}
/* finds AD9361 local oscillator IIO configuration channels */
static bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn)
{
switch (d) {
// LO chan is always output, i.e. true
case RX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("altvoltage", 0), true); return *chn != NULL;
case TX: *chn = iio_device_find_channel(get_ad9361_phy(ctx), get_ch_name("altvoltage", 1), true); return *chn != NULL;
default: return false;
}
}
/* applies streaming configuration through IIO */
bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, int chid)
{
struct iio_channel *chn = NULL;
// Configure phy and lo channels
LOG(INFO)<<"* Acquiring AD9361 phy channel"<<chid;
if (!get_phy_chan(ctx, type, chid, &chn)) { return false; }
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
LOG(INFO)<<"* Acquiring AD9361 "<<type == TX ? "TX" : "RX";
if (!get_lo_chan(ctx, type, &chn)) { return false; }
wr_ch_lli(chn, "frequency", cfg->lo_hz);
return true;
}
static bool set_dds_cw_tone(struct iio_device *dac1, struct iio_channel *chn, double freq_hz, double scale_dbfs, double phase_deg)
{
//ENABLE DDS
int ret;
ret = iio_channel_attr_write_bool(iio_device_find_channel(dac1, "altvoltage0", true), "raw", true);
if (ret < 0) {
std::cout<<"Failed to toggle DDS: "<<ret<<std::endl;
return false;
}
//set frequency, scale and phase
ret=iio_channel_attr_write_longlong(chn, "frequency",(long long) freq_hz);
if (ret < 0) {
std::cout<<"Failed to set TX DDS frequency: "<<ret<<std::endl;
return false;
}
ret=iio_channel_attr_write_double(chn, "phase",phase_deg);
if (ret < 0) {
std::cout<<"Failed to set TX DDS phase: "<<ret<<std::endl;
return false;
}
ret=iio_channel_attr_write_double(chn, "scale",pow(10, scale_dbfs / 20.0));
if (ret < 0) {
std::cout<<"Failed to set TX DDS scale: "<<ret<<std::endl;
return false;
}
return true;
}

View File

@ -0,0 +1,130 @@
/*!
* \file ad9361_manager.h
* \brief An Analog Devices AD9361 front-end configuration library wrapper for configure some functions via iiod link.
* \author Javier Arribas, jarribas(at)cttc.es
*
* This file contains information taken from librtlsdr:
* http://git.osmocom.org/rtl-sdr/
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef __AD9361_MANAGER__
#define __AD9361_MANAGER__
#ifdef __APPLE__
#include <iio/iio.h>
#else
#include <iio.h>
#endif
/* RX is input, TX is output */
enum iodev { RX, TX };
/* common RX and TX streaming params */
struct stream_cfg {
long long bw_hz; // Analog banwidth in Hz
long long fs_hz; // Baseband sample rate in Hz
long long lo_hz; // Local oscillator frequency in Hz
const char* rfport; // Port name
};
enum dds_tone_type {
TX1_T1_I,
TX1_T2_I,
TX1_T1_Q,
TX1_T2_Q,
TX2_T1_I,
TX2_T2_I,
TX2_T1_Q,
TX2_T2_Q,
TX3_T1_I,
TX3_T2_I,
TX3_T1_Q,
TX3_T2_Q,
TX4_T1_I,
TX4_T2_I,
TX4_T1_Q,
TX4_T2_Q
};
enum dds_widget_type {
WIDGET_FREQUENCY,
WIDGET_SCALE,
WIDGET_PHASE
};
#define DDS_DISABLED 0
#define DDS_ONE_TONE 1
#define DDS_TWO_TONE 2
#define DDS_INDEPDENT 3
#define DDS_BUFFER 4
/* static scratch mem for strings */
static char tmpstr[64];
/* IIO structs required for streaming */
static struct iio_context *ctx = NULL;
static struct iio_channel *rx0_i = NULL;
static struct iio_channel *rx0_q = NULL;
/* check return value of attr_write function */
static void errchk(int v, const char* what);
/* write attribute: long long int */
static void wr_ch_lli(struct iio_channel *chn, const char* what, long long val);
/* write attribute: string */
static void wr_ch_str(struct iio_channel *chn, const char* what, const char* str);
/* helper function generating channel names */
static char* get_ch_name(const char* type, int id);
/* returns ad9361 phy device */
static struct iio_device* get_ad9361_phy(struct iio_context *ctx);
/* finds AD9361 streaming IIO devices */
static bool get_ad9361_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev);
/* finds AD9361 streaming IIO channels */
static bool get_ad9361_stream_ch(struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, struct iio_channel **chn);
/* finds AD9361 phy IIO configuration channel with id chid */
static bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn);
/* finds AD9361 local oscillator IIO configuration channels */
static 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);
static bool set_dds_cw_tone(struct iio_device *dac1, double freq_hz, double scale_dbfs, double phase_deg);
#endif

View File

@ -262,7 +262,8 @@ void GNSSFlowgraph::connect()
for (unsigned int i = 0; i < channels_count_; i++)
{
bool FPGA_enabled = configuration_->property(sig_conditioner_.at(selected_signal_conditioner_ID)->role() + ".enable_FPGA", false);
bool FPGA_enabled = configuration_->property(sig_source_.at(0)->role() + ".enable_FPGA", false);
if (FPGA_enabled == false)
{
selected_signal_conditioner_ID = configuration_->property("Channel" + boost::lexical_cast<std::string>(i) + ".RF_channel_ID", 0);