3 * Copyright 2003,2004,2008,2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <usrp/usrp_basic.h>
28 #include "usrp/usrp_prims.h"
29 #include "usrp_interfaces.h"
30 #include "fpga_regs_common.h"
31 #include "fpga_regs_standard.h"
33 #include "db_boards.h"
42 using namespace ad9862;
44 #define NELEM(x) (sizeof (x) / sizeof (x[0]))
47 static const double POLLING_INTERVAL = 0.1; // seconds
50 //////////////////////////////////////////////////////////////////
54 ////////////////////////////////////////////////////////////////
61 // CLKOUT1 = CLKIN = 64 MHz
62 // CLKOUT2 = CLKIN = 64 MHz
63 // ADC is clocked at 64 MHz
64 // DAC is clocked at 128 MHz
66 static unsigned char common_regs[] = {
68 REG_DLL, (DLL_DISABLE_INTERNAL_XTAL_OSC
71 REG_CLKOUT, CLKOUT2_EQ_DLL_OVER_2,
72 REG_AUX_ADC_CLK, AUX_ADC_CLK_CLK_OVER_4
76 usrp_basic::usrp_basic (int which_board,
77 struct usb_dev_handle *
78 open_interface (struct usb_device *dev),
79 const std::string fpga_filename,
80 const std::string firmware_filename)
82 d_usb_data_rate (16000000), // SWAG, see below
83 d_bytes_per_poll ((int) (POLLING_INTERVAL * d_usb_data_rate)),
84 d_verbose (false), d_fpga_master_clock_freq(64000000), d_db(2)
87 * SWAG: Scientific Wild Ass Guess.
89 * d_usb_data_rate is used only to determine how often to poll for over- and under-runs.
90 * We defualt it to 1/2 of our best case. Classes derived from usrp_basic (e.g.,
91 * usrp_standard_tx and usrp_standard_rx) call set_usb_data_rate() to tell us the
92 * actual rate. This doesn't change our throughput, that's determined by the signal
93 * processing code in the FPGA (which we know nothing about), and the system limits
94 * determined by libusb, fusb_*, and the underlying drivers.
96 memset (d_fpga_shadows, 0, sizeof (d_fpga_shadows));
98 usrp_one_time_init ();
100 if (!usrp_load_standard_bits (which_board, false, fpga_filename, firmware_filename))
101 throw std::runtime_error ("usrp_basic/usrp_load_standard_bits");
103 struct usb_device *dev = usrp_find_device (which_board);
105 fprintf (stderr, "usrp_basic: can't find usrp[%d]\n", which_board);
106 throw std::runtime_error ("usrp_basic/usrp_find_device");
109 if (!(usrp_usrp_p(dev) && usrp_hw_rev(dev) >= 1)){
110 fprintf (stderr, "usrp_basic: sorry, this code only works with USRP revs >= 1\n");
111 throw std::runtime_error ("usrp_basic/bad_rev");
114 if ((d_udh = open_interface (dev)) == 0)
115 throw std::runtime_error ("usrp_basic/open_interface");
117 // initialize registers that are common to rx and tx
119 if (!usrp_9862_write_many_all (d_udh, common_regs, sizeof (common_regs))){
120 fprintf (stderr, "usrp_basic: failed to init common AD9862 regs\n");
121 throw std::runtime_error ("usrp_basic/init_9862");
124 _write_fpga_reg (FR_MODE, 0); // ensure we're in normal mode
125 _write_fpga_reg (FR_DEBUG_EN, 0); // disable debug outputs
128 usrp_basic::~usrp_basic ()
130 // shutdown_daughterboards(); // call from ~usrp_basic_{tx,rx}
132 d_db.resize(0); // forget db shared ptrs