2 // Copyright 2008 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.
23 #include <db_base_impl.h>
26 tune_result::tune_result(double baseband, double dxc, double residual, bool inv)
27 : ok(false), baseband_freq(baseband), dxc_freq(dxc),
28 residual_freq(residual), inverted(inv)
32 tune_result::~tune_result()
38 /*****************************************************************************/
40 db_base::db_base(usrp_basic_sptr usrp, int which)
41 : d_is_shutdown(false), d_raw_usrp(usrp.get()), d_which(which), d_lo_offset(0.0)
55 // do whatever there is to do to shutdown
62 return usrp()->daughterboard_id(d_which);
68 return usrp_dbid_to_string(dbid());
72 db_base::side_and_name()
75 return "A: " + name();
77 return "B: " + name();
80 // Function to bypass ADC buffers. Any board which is DC-coupled
81 // should bypass the buffers
84 db_base::bypass_adc_buffers(bool bypass)
87 // throw std::runtime_error("TX Board has no adc buffers\n");
92 ok &= usrp()->set_adc_buffer_bypass(0, bypass);
93 ok &= usrp()->set_adc_buffer_bypass(1, bypass);
96 ok &= usrp()->set_adc_buffer_bypass(2, bypass);
97 ok &= usrp()->set_adc_buffer_bypass(3, bypass);
103 db_base::set_atr_mask(int v)
105 // Set Auto T/R mask.
106 return usrp()->write_atr_mask(d_which, v);
110 db_base::set_atr_txval(int v)
112 // Set Auto T/R register value to be used when transmitting.
113 return usrp()->write_atr_txval(d_which, v);
117 db_base::set_atr_rxval(int v)
119 // Set Auto T/R register value to be used when receiving.
120 return usrp()->write_atr_rxval(d_which, v);
124 db_base::set_atr_tx_delay(int v)
126 // Set Auto T/R delay (in clock ticks) from when Tx fifo gets data to
127 // when T/R switches.
128 return usrp()->write_atr_tx_delay(v);
132 db_base::set_atr_rx_delay(int v)
134 // Set Auto T/R delay (in clock ticks) from when Tx fifo goes empty to
135 // when T/R switches.
136 return usrp()->write_atr_rx_delay(v);
140 db_base::i_and_q_swapped()
142 // Return True if this is a quadrature device and (for RX) ADC 0 is Q
143 // or (for TX) DAC 0 is Q
148 db_base::spectrum_inverted()
150 // Return True if the dboard gives an inverted spectrum
156 db_base::set_enable(bool on)
158 // For tx daughterboards, this controls the transmitter enable.
160 return true; // default is nop
164 db_base::set_auto_tr(bool on)
166 // Enable automatic Transmit/Receive switching (ATR).
168 // Should be overridden in subclasses that care. This will typically
169 // set the atr_mask, txval and rxval.
175 db_base::set_lo_offset(double offset)
177 // Set how much LO is offset from requested frequency
179 d_lo_offset = offset;
184 db_base::select_rx_antenna(int which_antenna)
186 // Specify which antenna port to use for reception.
187 // Should be overriden by daughterboards that care.
189 return which_antenna == 0;
193 db_base::select_rx_antenna(const std::string &which_antenna)
195 // Specify which antenna port to use for reception.
196 // Should be overriden by daughterboards that care.
198 return which_antenna == "";
202 // Reference Clock section
204 // Control whether a reference clock is sent to the daughterboards,
205 // and what frequency
207 // Bit 7 -- 1 turns on refclk, 0 allows IO use
208 // Bits 6:0 Divider value
212 db_base::_refclk_freq()
214 return usrp()->fpga_master_clock_freq() / _refclk_divisor();
218 db_base::_enable_refclk(bool enable)
220 int CLOCK_OUT = 1; // Clock is on lowest bit
221 int REFCLK_ENABLE = 0x80;
222 int REFCLK_DIVISOR_MASK = 0x7f;
225 usrp()->_write_oe(d_which, CLOCK_OUT, CLOCK_OUT); // output enable
226 usrp()->write_refclk(d_which, (_refclk_divisor() & REFCLK_DIVISOR_MASK) | REFCLK_ENABLE);
229 usrp()->write_refclk(d_which, 0);
234 db_base::_refclk_divisor()
236 // Return value to stick in REFCLK_DIVISOR register
237 throw std::runtime_error("_reflck_divisor() called from base class\n");;
241 db_base::set_bw(float bw)
243 // Set baseband bandwidth (board specific)
244 // Should be overriden by boards that implement variable IF filtering (e.g., DBSRX)
248 std::ostream &operator<<(std::ostream &os, db_base &x)
250 os << x.side_and_name();