2 // Copyright 2008,2009 Free Software Foundation, Inc.
4 // This file is part of GNU Radio
6 // GNU Radio is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either asversion 3, or (at your option)
11 // GNU Radio is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with GNU Radio; see the file COPYING. If not, write to
18 // the Free Software Foundation, Inc., 51 Franklin Street,
19 // Boston, MA 02110-1301, USA.
26 #include <usrp/db_base.h>
27 #include <db_base_impl.h>
30 tune_result::tune_result(double baseband, double dxc, double residual, bool inv)
31 : ok(false), baseband_freq(baseband), dxc_freq(dxc),
32 residual_freq(residual), inverted(inv)
36 tune_result::~tune_result()
42 /*****************************************************************************/
44 db_base::db_base(usrp_basic_sptr usrp, int which)
45 : d_is_shutdown(false), d_raw_usrp(usrp.get()), d_which(which), d_lo_offset(0.0)
59 // do whatever there is to do to shutdown
66 return usrp()->daughterboard_id(d_which);
72 return usrp_dbid_to_string(dbid());
76 db_base::side_and_name()
79 return "A: " + name();
81 return "B: " + name();
84 // Function to bypass ADC buffers. Any board which is DC-coupled
85 // should bypass the buffers
88 db_base::bypass_adc_buffers(bool bypass)
91 // throw std::runtime_error("TX Board has no adc buffers\n");
96 ok &= usrp()->set_adc_buffer_bypass(0, bypass);
97 ok &= usrp()->set_adc_buffer_bypass(1, bypass);
100 ok &= usrp()->set_adc_buffer_bypass(2, bypass);
101 ok &= usrp()->set_adc_buffer_bypass(3, bypass);
107 db_base::set_atr_mask(int v)
109 // Set Auto T/R mask.
110 return usrp()->write_atr_mask(d_which, v);
114 db_base::set_atr_txval(int v)
116 // Set Auto T/R register value to be used when transmitting.
117 return usrp()->write_atr_txval(d_which, v);
121 db_base::set_atr_rxval(int v)
123 // Set Auto T/R register value to be used when receiving.
124 return usrp()->write_atr_rxval(d_which, v);
128 db_base::set_atr_tx_delay(int v)
130 // Set Auto T/R delay (in clock ticks) from when Tx fifo gets data to
131 // when T/R switches.
132 return usrp()->write_atr_tx_delay(v);
136 db_base::set_atr_rx_delay(int v)
138 // Set Auto T/R delay (in clock ticks) from when Tx fifo goes empty to
139 // when T/R switches.
140 return usrp()->write_atr_rx_delay(v);
144 db_base::i_and_q_swapped()
146 // Return True if this is a quadrature device and (for RX) ADC 0 is Q
147 // or (for TX) DAC 0 is Q
152 db_base::spectrum_inverted()
154 // Return True if the dboard gives an inverted spectrum
160 db_base::set_enable(bool on)
162 // For tx daughterboards, this controls the transmitter enable.
164 return true; // default is nop
168 db_base::set_auto_tr(bool on)
170 // Enable automatic Transmit/Receive switching (ATR).
172 // Should be overridden in subclasses that care. This will typically
173 // set the atr_mask, txval and rxval.
179 db_base::set_lo_offset(double offset)
181 // Set how much LO is offset from requested frequency
183 d_lo_offset = offset;
188 db_base::select_rx_antenna(int which_antenna)
190 // Specify which antenna port to use for reception.
191 // Should be overriden by daughterboards that care.
193 return which_antenna == 0;
197 db_base::select_rx_antenna(const std::string &which_antenna)
199 // Specify which antenna port to use for reception.
200 // Should be overriden by daughterboards that care.
202 return which_antenna == "";
206 // Reference Clock section
208 // Control whether a reference clock is sent to the daughterboards,
209 // and what frequency
211 // Bit 7 -- 1 turns on refclk, 0 allows IO use
212 // Bits 6:0 Divider value
216 db_base::_refclk_freq()
218 return usrp()->fpga_master_clock_freq() / _refclk_divisor();
222 db_base::_enable_refclk(bool enable)
224 int CLOCK_OUT = 1; // Clock is on lowest bit
225 int REFCLK_ENABLE = 0x80;
226 int REFCLK_DIVISOR_MASK = 0x7f;
229 usrp()->_write_oe(d_which, CLOCK_OUT, CLOCK_OUT); // output enable
230 usrp()->write_refclk(d_which, (_refclk_divisor() & REFCLK_DIVISOR_MASK) | REFCLK_ENABLE);
233 usrp()->write_refclk(d_which, 0);
238 db_base::_refclk_divisor()
240 // Return value to stick in REFCLK_DIVISOR register
241 throw std::runtime_error("_reflck_divisor() called from base class\n");;
245 db_base::set_bw(float bw)
247 // Set baseband bandwidth (board specific)
248 // Should be overriden by boards that implement variable IF filtering (e.g., DBSRX)
252 std::ostream &operator<<(std::ostream &os, db_base &x)
254 os << x.side_and_name();