GNSS-SDR  0.0.17
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 /* RX is input, TX is output */
36 enum iodev
37 {
38  RX,
39  TX
40 };
41 
42 /* common RX and TX streaming params */
43 struct stream_cfg
44 {
45  int64_t bw_hz; // Analog bandwidth in Hz
46  int64_t fs_hz; // Baseband sample rate in Hz
47  int64_t lo_hz; // Local oscillator frequency in Hz
48  const char *rfport; // Port name
49 };
50 
51 /* check return value of attr_write function */
52 void errchk(int v, const char *what);
53 
54 /* write attribute: int64_t int */
55 void wr_ch_lli(struct iio_channel *chn, const char *what, int64_t val);
56 
57 /* write attribute: string */
58 void wr_ch_str(struct iio_channel *chn, const char *what, const char *str);
59 
60 /* returns ad9361 phy device */
61 struct iio_device *get_ad9361_phy(struct iio_context *ctx);
62 
63 /* finds AD9361 streaming IIO devices */
64 bool get_ad9361_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev);
65 
66 /* finds AD9361 streaming IIO channels */
67 bool get_ad9361_stream_ch(struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, struct iio_channel **chn);
68 
69 /* finds AD9361 phy IIO configuration channel with id chid */
70 bool get_phy_chan(struct iio_context *ctx, enum iodev d, int chid, struct iio_channel **chn);
71 
72 /* finds AD9361 local oscillator IIO configuration channels */
73 bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn);
74 
75 /* applies streaming configuration through IIO */
76 bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, int chid);
77 
78 bool config_ad9361_rx_local(uint64_t bandwidth_,
79  uint64_t sample_rate_,
80  uint64_t freq_,
81  const std::string &rf_port_select_,
82  bool rx1_enable_,
83  bool rx2_enable_,
84  const std::string &gain_mode_rx1_,
85  const std::string &gain_mode_rx2_,
86  double rf_gain_rx1_,
87  double rf_gain_rx2_,
88  bool quadrature_,
89  bool rfdc_,
90  bool bbdc_,
91  std::string filter_source_,
92  std::string filter_filename_,
93  float Fpass_,
94  float Fstop_);
95 
96 bool config_ad9361_rx_remote(const std::string &remote_host,
97  uint64_t bandwidth_,
98  uint64_t sample_rate_,
99  uint64_t freq_,
100  const std::string &rf_port_select_,
101  bool rx1_enable_,
102  bool rx2_enable_,
103  const std::string &gain_mode_rx1_,
104  const std::string &gain_mode_rx2_,
105  double rf_gain_rx1_,
106  double rf_gain_rx2_,
107  bool quadrature_,
108  bool rfdc_,
109  bool bbdc_,
110  std::string filter_source_,
111  std::string filter_filename_,
112  float Fpass_,
113  float Fstop_);
114 
115 bool config_ad9361_lo_local(uint64_t bandwidth_,
116  uint64_t sample_rate_,
117  uint64_t freq_rf_tx_hz_,
118  double tx_attenuation_db_,
119  int64_t freq_dds_tx_hz_,
120  double scale_dds_dbfs_,
121  double phase_dds_deg_);
122 
123 bool config_ad9361_lo_remote(const std::string &remote_host,
124  uint64_t bandwidth_,
125  uint64_t sample_rate_,
126  uint64_t freq_rf_tx_hz_,
127  double tx_attenuation_db_,
128  int64_t freq_dds_tx_hz_,
129  double scale_dds_dbfs_,
130  double phase_dds_deg_);
131 
132 bool ad9361_disable_lo_remote(const std::string &remote_host);
133 
134 bool ad9361_disable_lo_local();
135 
136 bool load_fir_filter(std::string &filter, struct iio_device *phy);
137 
138 bool disable_ad9361_rx_local();
139 
140 bool disable_ad9361_rx_remote(const std::string &remote_host);
141 
142 
143 /** \} */
144 /** \} */
145 #endif // GNSS_SDR_AD9361_MANAGER_H