GNSS-SDR  0.0.19
An Open Source GNSS Software Defined Receiver
ad9361_manager.h
Go to the documentation of this file.
1 /*!
2  * \file ad9361_manager.h
3  * \brief An Analog Devices AD9361 front-end configuration library wrapper for configure some functions via iiod link.
4  * \author Javier Arribas, jarribas(at)cttc.es
5  *
6  * This file contains information taken from librtlsdr:
7  * https://git.osmocom.org/rtl-sdr
8  *
9  * -----------------------------------------------------------------------------
10  *
11  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
12  * This file is part of GNSS-SDR.
13  *
14  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
15  * SPDX-License-Identifier: GPL-3.0-or-later
16  *
17  * -----------------------------------------------------------------------------
18  */
19 
20 #ifndef GNSS_SDR_AD9361_MANAGER_H
21 #define GNSS_SDR_AD9361_MANAGER_H
22 
23 #include <iio.h>
24 #include <cstdint>
25 #include <string>
26 
27 /** \addtogroup Signal_Source
28  * \{ */
29 /** \addtogroup Signal_Source_libs signal_source_libs
30  * Library with utilities for signal sources.
31  * \{ */
32 
33 #define FIR_BUF_SIZE 8192
34 
35 static const std::string RX_DEV_A = "ad9361-phy"; // one or two AD9361s are present
36 static const std::string RX_DEV_B = "ad9361-phy-B"; // one or two AD9361s are present
37 static const std::string RX_STREAM_DEV = "cf-ad9361-lpc"; // one AD9361 is present
38 static const std::string RX_STREAM_DEV_A = "cf-ad9361-A"; // two AD9361s are present
39 static const std::string RX_STREAM_DEV_B = "cf-ad9361-B"; // two AD9361s are present
40 static const std::string TX_STREAM_DEV = "cf-ad9361-dds-core-lpc";
41 
42 /* RX is input, TX is output */
43 enum iodev
44 {
45  RX,
46  TX
47 };
48 
49 /* common RX and TX streaming params */
50 struct stream_cfg
51 {
52  int64_t bw_hz; // Analog bandwidth in Hz
53  int64_t fs_hz; // Baseband sample rate in Hz
54  int64_t lo_hz; // Local oscillator frequency in Hz
55  const char *rfport; // Port name
56 };
57 
58 /* check return value of attr_write function */
59 void errchk(int v, const char *what);
60 
61 /* write attribute: int64_t int */
62 void wr_ch_lli(struct iio_channel *chn, const char *what, int64_t val);
63 
64 /* write attribute: string */
65 void wr_ch_str(struct iio_channel *chn, const char *what, const char *str);
66 
67 /* returns ad9361 phy device */
68 struct iio_device *get_ad9361_phy(struct iio_context *ctx);
69 
70 /* finds AD9361 streaming IIO devices */
71 bool get_ad9361_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev);
72 
73 /* finds AD9361 streaming IIO channels */
74 bool get_ad9361_stream_ch(struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, struct iio_channel **chn);
75 
76 /* finds AD9361 phy IIO configuration channel with id chid */
77 bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn);
78 
79 /* finds AD9361 local oscillator IIO configuration channels */
80 bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn);
81 
82 /* applies streaming configuration through IIO */
83 bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, int chid);
84 
85 bool config_ad9361_rx_local(uint64_t bandwidth_,
86  uint64_t sample_rate_,
87  uint64_t freq0_,
88  uint64_t freq1_,
89  const std::string &rf_port_select_,
90  bool rx1_enable_,
91  bool rx2_enable_,
92  const std::string &gain_mode_rx1_,
93  const std::string &gain_mode_rx2_,
94  double rf_gain_rx1_,
95  double rf_gain_rx2_,
96  bool quadrature_,
97  bool rfdc_,
98  bool bbdc_,
99  std::string filter_source_,
100  std::string filter_filename_,
101  float Fpass_,
102  float Fstop_);
103 
104 bool config_ad9361_rx_remote(const std::string &remote_host,
105  uint64_t bandwidth_,
106  uint64_t sample_rate_,
107  uint64_t freq_,
108  const std::string &rf_port_select_,
109  bool rx1_enable_,
110  bool rx2_enable_,
111  const std::string &gain_mode_rx1_,
112  const std::string &gain_mode_rx2_,
113  double rf_gain_rx1_,
114  double rf_gain_rx2_,
115  bool quadrature_,
116  bool rfdc_,
117  bool bbdc_,
118  std::string filter_source_,
119  std::string filter_filename_,
120  float Fpass_,
121  float Fstop_);
122 
123 bool config_ad9361_lo_local(uint64_t bandwidth_,
124  uint64_t sample_rate_,
125  uint64_t freq_rf_tx_hz_,
126  double tx_attenuation_db_,
127  int64_t freq_dds_tx_hz_,
128  double scale_dds_dbfs_,
129  double phase_dds_deg_);
130 
131 bool config_ad9361_lo_remote(const std::string &remote_host,
132  uint64_t bandwidth_,
133  uint64_t sample_rate_,
134  uint64_t freq_rf_tx_hz_,
135  double tx_attenuation_db_,
136  int64_t freq_dds_tx_hz_,
137  double scale_dds_dbfs_,
138  double phase_dds_deg_);
139 
140 bool ad9361_disable_lo_remote(const std::string &remote_host);
141 
142 bool ad9361_disable_lo_local();
143 
144 bool load_fir_filter(std::string &filter, struct iio_device *phy);
145 
146 bool disable_ad9361_rx_local();
147 
148 bool disable_ad9361_rx_remote(const std::string &remote_host);
149 
150 
151 /** \} */
152 /** \} */
153 #endif // GNSS_SDR_AD9361_MANAGER_H