GNSS-SDR  0.0.13
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  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
11  *
12  * GNSS-SDR is a software defined Global Navigation
13  * Satellite Systems receiver
14  *
15  * This file is part of GNSS-SDR.
16  *
17  * SPDX-License-Identifier: GPL-3.0-or-later
18  *
19  * -----------------------------------------------------------------------------
20  */
21 
22 #ifndef GNSS_SDR_AD9361_MANAGER_H
23 #define GNSS_SDR_AD9361_MANAGER_H
24 
25 #include <iio.h>
26 #include <cstdint>
27 #include <string>
28 
29 #define FIR_BUF_SIZE 8192
30 
31 /* RX is input, TX is output */
32 enum iodev
33 {
34  RX,
35  TX
36 };
37 
38 /* common RX and TX streaming params */
39 struct stream_cfg
40 {
41  int64_t bw_hz; // Analog bandwidth in Hz
42  int64_t fs_hz; // Baseband sample rate in Hz
43  int64_t lo_hz; // Local oscillator frequency in Hz
44  const char *rfport; // Port name
45 };
46 
47 /* check return value of attr_write function */
48 void errchk(int v, const char *what);
49 
50 /* write attribute: int64_t int */
51 void wr_ch_lli(struct iio_channel *chn, const char *what, int64_t val);
52 
53 /* write attribute: string */
54 void wr_ch_str(struct iio_channel *chn, const char *what, const char *str);
55 
56 /* returns ad9361 phy device */
57 struct iio_device *get_ad9361_phy(struct iio_context *ctx);
58 
59 /* finds AD9361 streaming IIO devices */
60 bool get_ad9361_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev);
61 
62 /* finds AD9361 streaming IIO channels */
63 bool get_ad9361_stream_ch(struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, struct iio_channel **chn);
64 
65 /* finds AD9361 phy IIO configuration channel with id chid */
66 bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn);
67 
68 /* finds AD9361 local oscillator IIO configuration channels */
69 bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn);
70 
71 /* applies streaming configuration through IIO */
72 bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, int chid);
73 
74 bool config_ad9361_rx_local(uint64_t bandwidth_,
75  uint64_t sample_rate_,
76  uint64_t freq_,
77  const std::string &rf_port_select_,
78  bool rx1_enable_,
79  bool rx2_enable_,
80  const std::string &gain_mode_rx1_,
81  const std::string &gain_mode_rx2_,
82  double rf_gain_rx1_,
83  double rf_gain_rx2_,
84  bool quadrature_,
85  bool rfdc_,
86  bool bbdc_,
87  std::string filter_source_,
88  std::string filter_filename_,
89  float Fpass_,
90  float Fstop_);
91 
92 bool config_ad9361_rx_remote(const std::string &remote_host,
93  uint64_t bandwidth_,
94  uint64_t sample_rate_,
95  uint64_t freq_,
96  const std::string &rf_port_select_,
97  bool rx1_enable_,
98  bool rx2_enable_,
99  const std::string &gain_mode_rx1_,
100  const std::string &gain_mode_rx2_,
101  double rf_gain_rx1_,
102  double rf_gain_rx2_,
103  bool quadrature_,
104  bool rfdc_,
105  bool bbdc_,
106  std::string filter_source_,
107  std::string filter_filename_,
108  float Fpass_,
109  float Fstop_);
110 
111 bool config_ad9361_lo_local(uint64_t bandwidth_,
112  uint64_t sample_rate_,
113  uint64_t freq_rf_tx_hz_,
114  double tx_attenuation_db_,
115  int64_t freq_dds_tx_hz_,
116  double scale_dds_dbfs_,
117  double phase_dds_deg_);
118 
119 bool config_ad9361_lo_remote(const std::string &remote_host,
120  uint64_t bandwidth_,
121  uint64_t sample_rate_,
122  uint64_t freq_rf_tx_hz_,
123  double tx_attenuation_db_,
124  int64_t freq_dds_tx_hz_,
125  double scale_dds_dbfs_,
126  double phase_dds_deg_);
127 
128 bool ad9361_disable_lo_remote(const std::string &remote_host);
129 
130 bool ad9361_disable_lo_local();
131 
132 bool load_fir_filter(std::string &filter, struct iio_device *phy);
133 
134 bool disable_ad9361_rx_local();
135 
136 bool disable_ad9361_rx_remote(const std::string &remote_host);
137 
138 #endif // GNSS_SDR_AD9361_MANAGER_H