root / host / lib / usrp / b100 / b100_impl.cpp @ 4bcab9c5
History | View | Annotate | Download (21.4 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2011 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#include "b100_impl.hpp" |
| 19 |
#include "b100_ctrl.hpp" |
| 20 |
#include "fpga_regs_standard.h" |
| 21 |
#include "usrp_i2c_addr.h" |
| 22 |
#include "usrp_commands.h" |
| 23 |
#include <uhd/transport/usb_control.hpp> |
| 24 |
#include "ctrl_packet.hpp" |
| 25 |
#include <uhd/utils/msg.hpp> |
| 26 |
#include <uhd/exception.hpp> |
| 27 |
#include <uhd/utils/static.hpp> |
| 28 |
#include <uhd/utils/images.hpp> |
| 29 |
#include <uhd/utils/safe_call.hpp> |
| 30 |
#include <boost/format.hpp> |
| 31 |
#include <boost/assign/list_of.hpp> |
| 32 |
#include <boost/filesystem.hpp> |
| 33 |
#include <boost/thread/thread.hpp> |
| 34 |
#include <boost/lexical_cast.hpp> |
| 35 |
#include "b100_regs.hpp" |
| 36 |
|
| 37 |
using namespace uhd; |
| 38 |
using namespace uhd::usrp; |
| 39 |
using namespace uhd::transport; |
| 40 |
|
| 41 |
const boost::uint16_t B100_VENDOR_ID = 0x2500; |
| 42 |
const boost::uint16_t B100_PRODUCT_ID = 0x0001; |
| 43 |
const boost::uint16_t FX2_VENDOR_ID = 0x04b4; |
| 44 |
const boost::uint16_t FX2_PRODUCT_ID = 0x8613; |
| 45 |
|
| 46 |
/***********************************************************************
|
| 47 |
* Discovery
|
| 48 |
**********************************************************************/
|
| 49 |
static device_addrs_t b100_find(const device_addr_t &hint) |
| 50 |
{
|
| 51 |
device_addrs_t b100_addrs; |
| 52 |
|
| 53 |
//return an empty list of addresses when type is set to non-b100
|
| 54 |
if (hint.has_key("type") and hint["type"] != "b100") return b100_addrs; |
| 55 |
|
| 56 |
//Return an empty list of addresses when an address is specified,
|
| 57 |
//since an address is intended for a different, non-USB, device.
|
| 58 |
if (hint.has_key("addr")) return b100_addrs; |
| 59 |
|
| 60 |
boost::uint16_t vid = hint.has_key("uninit") ? FX2_VENDOR_ID : B100_VENDOR_ID;
|
| 61 |
boost::uint16_t pid = hint.has_key("uninit") ? FX2_PRODUCT_ID : B100_PRODUCT_ID;
|
| 62 |
|
| 63 |
// Important note:
|
| 64 |
// The get device list calls are nested inside the for loop.
|
| 65 |
// This allows the usb guts to decontruct when not in use,
|
| 66 |
// so that re-enumeration after fw load can occur successfully.
|
| 67 |
// This requirement is a courtesy of libusb1.0 on windows.
|
| 68 |
|
| 69 |
//find the usrps and load firmware
|
| 70 |
BOOST_FOREACH(usb_device_handle::sptr handle, usb_device_handle::get_device_list(vid, pid)) {
|
| 71 |
//extract the firmware path for the b100
|
| 72 |
std::string b100_fw_image;
|
| 73 |
try{
|
| 74 |
b100_fw_image = find_image_path(hint.get("fw", B100_FW_FILE_NAME));
|
| 75 |
} |
| 76 |
catch(...){
|
| 77 |
UHD_MSG(warning) << boost::format( |
| 78 |
"Could not locate B100 firmware.\n"
|
| 79 |
"Please install the images package.\n"
|
| 80 |
); |
| 81 |
return b100_addrs;
|
| 82 |
} |
| 83 |
UHD_LOG << "the firmware image: " << b100_fw_image << std::endl;
|
| 84 |
|
| 85 |
usb_control::sptr control; |
| 86 |
try{control = usb_control::make(handle);}
|
| 87 |
catch(const uhd::exception &){continue;} //ignore claimed |
| 88 |
|
| 89 |
fx2_ctrl::make(control)->usrp_load_firmware(b100_fw_image); |
| 90 |
} |
| 91 |
|
| 92 |
//get descriptors again with serial number, but using the initialized VID/PID now since we have firmware
|
| 93 |
vid = B100_VENDOR_ID; |
| 94 |
pid = B100_PRODUCT_ID; |
| 95 |
|
| 96 |
BOOST_FOREACH(usb_device_handle::sptr handle, usb_device_handle::get_device_list(vid, pid)) {
|
| 97 |
device_addr_t new_addr; |
| 98 |
new_addr["type"] = "b100"; |
| 99 |
new_addr["serial"] = handle->get_serial();
|
| 100 |
|
| 101 |
//Attempt to read the name from the EEPROM and perform filtering.
|
| 102 |
try{
|
| 103 |
usb_control::sptr control = usb_control::make(handle); |
| 104 |
fx2_ctrl::sptr fx2_ctrl = fx2_ctrl::make(control); |
| 105 |
const mboard_eeprom_t mb_eeprom = mboard_eeprom_t(*fx2_ctrl, mboard_eeprom_t::MAP_B000);
|
| 106 |
new_addr["name"] = mb_eeprom["name"]; |
| 107 |
} |
| 108 |
catch(const uhd::exception &){ |
| 109 |
//set these values as empty string so the device may still be found
|
| 110 |
//and the filter's below can still operate on the discovered device
|
| 111 |
new_addr["name"] = ""; |
| 112 |
} |
| 113 |
|
| 114 |
//this is a found b100 when the hint serial and name match or blank
|
| 115 |
if (
|
| 116 |
(not hint.has_key("name") or hint["name"] == new_addr["name"]) and |
| 117 |
(not hint.has_key("serial") or hint["serial"] == new_addr["serial"]) |
| 118 |
){
|
| 119 |
b100_addrs.push_back(new_addr); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
return b100_addrs;
|
| 124 |
} |
| 125 |
|
| 126 |
/***********************************************************************
|
| 127 |
* Make
|
| 128 |
**********************************************************************/
|
| 129 |
static device::sptr b100_make(const device_addr_t &device_addr){ |
| 130 |
return device::sptr(new b100_impl(device_addr)); |
| 131 |
} |
| 132 |
|
| 133 |
UHD_STATIC_BLOCK(register_b100_device){
|
| 134 |
device::register_device(&b100_find, &b100_make); |
| 135 |
} |
| 136 |
|
| 137 |
/***********************************************************************
|
| 138 |
* Structors
|
| 139 |
**********************************************************************/
|
| 140 |
b100_impl::b100_impl(const device_addr_t &device_addr){
|
| 141 |
|
| 142 |
//extract the FPGA path for the B100
|
| 143 |
std::string b100_fpga_image = find_image_path(
|
| 144 |
device_addr.has_key("fpga")? device_addr["fpga"] : B100_FPGA_FILE_NAME |
| 145 |
); |
| 146 |
|
| 147 |
//try to match the given device address with something on the USB bus
|
| 148 |
std::vector<usb_device_handle::sptr> device_list = |
| 149 |
usb_device_handle::get_device_list(B100_VENDOR_ID, B100_PRODUCT_ID); |
| 150 |
|
| 151 |
//locate the matching handle in the device list
|
| 152 |
usb_device_handle::sptr handle; |
| 153 |
BOOST_FOREACH(usb_device_handle::sptr dev_handle, device_list) {
|
| 154 |
if (dev_handle->get_serial() == device_addr["serial"]){ |
| 155 |
handle = dev_handle; |
| 156 |
break;
|
| 157 |
} |
| 158 |
} |
| 159 |
UHD_ASSERT_THROW(handle.get() != NULL); //better be found |
| 160 |
|
| 161 |
//create control objects and a data transport
|
| 162 |
usb_control::sptr fx2_transport = usb_control::make(handle); |
| 163 |
_fx2_ctrl = fx2_ctrl::make(fx2_transport); |
| 164 |
this->check_fw_compat(); //check after making fx2 |
| 165 |
//-- setup clock after making fx2 and before loading fpga --//
|
| 166 |
_clock_ctrl = b100_clock_ctrl::make(_fx2_ctrl, device_addr.cast<double>("master_clock_rate", B100_DEFAULT_TICK_RATE)); |
| 167 |
_fx2_ctrl->usrp_load_fpga(b100_fpga_image); |
| 168 |
|
| 169 |
device_addr_t data_xport_args; |
| 170 |
data_xport_args["recv_frame_size"] = device_addr.get("recv_frame_size", "16384"); |
| 171 |
data_xport_args["num_recv_frames"] = device_addr.get("num_recv_frames", "16"); |
| 172 |
data_xport_args["send_frame_size"] = device_addr.get("send_frame_size", "16384"); |
| 173 |
data_xport_args["num_send_frames"] = device_addr.get("num_send_frames", "16"); |
| 174 |
|
| 175 |
_data_transport = usb_zero_copy::make_wrapper( |
| 176 |
usb_zero_copy::make( |
| 177 |
handle, // identifier
|
| 178 |
6, // IN endpoint |
| 179 |
2, // OUT endpoint |
| 180 |
data_xport_args // param hints
|
| 181 |
) |
| 182 |
); |
| 183 |
|
| 184 |
//create the control transport
|
| 185 |
device_addr_t ctrl_xport_args; |
| 186 |
ctrl_xport_args["recv_frame_size"] = boost::lexical_cast<std::string>(CTRL_PACKET_LENGTH); |
| 187 |
ctrl_xport_args["num_recv_frames"] = "16"; |
| 188 |
ctrl_xport_args["send_frame_size"] = boost::lexical_cast<std::string>(CTRL_PACKET_LENGTH); |
| 189 |
ctrl_xport_args["num_send_frames"] = "4"; |
| 190 |
|
| 191 |
_ctrl_transport = usb_zero_copy::make( |
| 192 |
handle, |
| 193 |
8,
|
| 194 |
4,
|
| 195 |
ctrl_xport_args |
| 196 |
); |
| 197 |
|
| 198 |
////////////////////////////////////////////////////////////////////
|
| 199 |
// Create controller objects
|
| 200 |
////////////////////////////////////////////////////////////////////
|
| 201 |
_fpga_ctrl = b100_ctrl::make(_ctrl_transport); |
| 202 |
this->enable_gpif(true); //TODO best place to put this? |
| 203 |
this->check_fpga_compat(); //check after making control |
| 204 |
_fpga_i2c_ctrl = i2c_core_100::make(_fpga_ctrl, B100_REG_SLAVE(3));
|
| 205 |
_fpga_spi_ctrl = spi_core_100::make(_fpga_ctrl, B100_REG_SLAVE(2));
|
| 206 |
|
| 207 |
////////////////////////////////////////////////////////////////////
|
| 208 |
// Initialize the properties tree
|
| 209 |
////////////////////////////////////////////////////////////////////
|
| 210 |
_tree = property_tree::make(); |
| 211 |
_tree->create<std::string>("/name").set("B-Series Device"); |
| 212 |
const property_tree::path_type mb_path = "/mboards/0"; |
| 213 |
_tree->create<std::string>(mb_path / "name").set("B100 (B-Hundo)"); |
| 214 |
_tree->create<std::string>(mb_path / "load_eeprom") |
| 215 |
.subscribe(boost::bind(&fx2_ctrl::usrp_load_eeprom, _fx2_ctrl, _1)); |
| 216 |
|
| 217 |
////////////////////////////////////////////////////////////////////
|
| 218 |
// setup the mboard eeprom
|
| 219 |
////////////////////////////////////////////////////////////////////
|
| 220 |
const mboard_eeprom_t mb_eeprom(*_fx2_ctrl, mboard_eeprom_t::MAP_B000);
|
| 221 |
_tree->create<mboard_eeprom_t>(mb_path / "eeprom")
|
| 222 |
.set(mb_eeprom) |
| 223 |
.subscribe(boost::bind(&b100_impl::set_mb_eeprom, this, _1));
|
| 224 |
|
| 225 |
////////////////////////////////////////////////////////////////////
|
| 226 |
// create clock control objects
|
| 227 |
////////////////////////////////////////////////////////////////////
|
| 228 |
//^^^ clock created up top, just reg props here... ^^^
|
| 229 |
_tree->create<double>(mb_path / "tick_rate") |
| 230 |
.publish(boost::bind(&b100_clock_ctrl::get_fpga_clock_rate, _clock_ctrl)) |
| 231 |
.subscribe(boost::bind(&b100_impl::update_tick_rate, this, _1));
|
| 232 |
|
| 233 |
////////////////////////////////////////////////////////////////////
|
| 234 |
// create codec control objects
|
| 235 |
////////////////////////////////////////////////////////////////////
|
| 236 |
_codec_ctrl = b100_codec_ctrl::make(_fpga_spi_ctrl); |
| 237 |
const property_tree::path_type rx_codec_path = mb_path / "rx_codecs/A"; |
| 238 |
const property_tree::path_type tx_codec_path = mb_path / "tx_codecs/A"; |
| 239 |
_tree->create<std::string>(rx_codec_path / "name").set("ad9522"); |
| 240 |
_tree->create<meta_range_t>(rx_codec_path / "gains/pga/range").set(b100_codec_ctrl::rx_pga_gain_range);
|
| 241 |
_tree->create<double>(rx_codec_path / "gains/pga/value") |
| 242 |
.coerce(boost::bind(&b100_impl::update_rx_codec_gain, this, _1));
|
| 243 |
_tree->create<std::string>(tx_codec_path / "name").set("ad9522"); |
| 244 |
_tree->create<meta_range_t>(tx_codec_path / "gains/pga/range").set(b100_codec_ctrl::tx_pga_gain_range);
|
| 245 |
_tree->create<double>(tx_codec_path / "gains/pga/value") |
| 246 |
.subscribe(boost::bind(&b100_codec_ctrl::set_tx_pga_gain, _codec_ctrl, _1)) |
| 247 |
.publish(boost::bind(&b100_codec_ctrl::get_tx_pga_gain, _codec_ctrl)); |
| 248 |
|
| 249 |
////////////////////////////////////////////////////////////////////
|
| 250 |
// and do the misc mboard sensors
|
| 251 |
////////////////////////////////////////////////////////////////////
|
| 252 |
//none for now...
|
| 253 |
_tree->create<int>(mb_path / "sensors"); //phony property so this dir exists |
| 254 |
|
| 255 |
////////////////////////////////////////////////////////////////////
|
| 256 |
// create frontend control objects
|
| 257 |
////////////////////////////////////////////////////////////////////
|
| 258 |
_rx_fe = rx_frontend_core_200::make(_fpga_ctrl, B100_REG_SR_ADDR(B100_SR_RX_FRONT)); |
| 259 |
_tx_fe = tx_frontend_core_200::make(_fpga_ctrl, B100_REG_SR_ADDR(B100_SR_TX_FRONT)); |
| 260 |
//TODO lots of properties to expose here for frontends
|
| 261 |
_tree->create<subdev_spec_t>(mb_path / "rx_subdev_spec")
|
| 262 |
.subscribe(boost::bind(&b100_impl::update_rx_subdev_spec, this, _1));
|
| 263 |
_tree->create<subdev_spec_t>(mb_path / "tx_subdev_spec")
|
| 264 |
.subscribe(boost::bind(&b100_impl::update_tx_subdev_spec, this, _1));
|
| 265 |
|
| 266 |
////////////////////////////////////////////////////////////////////
|
| 267 |
// create rx dsp control objects
|
| 268 |
////////////////////////////////////////////////////////////////////
|
| 269 |
_rx_dsps.push_back(rx_dsp_core_200::make( |
| 270 |
_fpga_ctrl, B100_REG_SR_ADDR(B100_SR_RX_DSP0), B100_REG_SR_ADDR(B100_SR_RX_CTRL0), B100_RX_SID_BASE + 0
|
| 271 |
)); |
| 272 |
_rx_dsps.push_back(rx_dsp_core_200::make( |
| 273 |
_fpga_ctrl, B100_REG_SR_ADDR(B100_SR_RX_DSP1), B100_REG_SR_ADDR(B100_SR_RX_CTRL1), B100_RX_SID_BASE + 1
|
| 274 |
)); |
| 275 |
for (size_t dspno = 0; dspno < _rx_dsps.size(); dspno++){ |
| 276 |
_tree->access<double>(mb_path / "tick_rate") |
| 277 |
.subscribe(boost::bind(&rx_dsp_core_200::set_tick_rate, _rx_dsps[dspno], _1)); |
| 278 |
property_tree::path_type rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno);
|
| 279 |
_tree->create<double>(rx_dsp_path / "rate/value") |
| 280 |
.coerce(boost::bind(&rx_dsp_core_200::set_host_rate, _rx_dsps[dspno], _1)) |
| 281 |
.subscribe(boost::bind(&b100_impl::update_rx_samp_rate, this, _1));
|
| 282 |
_tree->create<double>(rx_dsp_path / "freq/value") |
| 283 |
.coerce(boost::bind(&rx_dsp_core_200::set_freq, _rx_dsps[dspno], _1)); |
| 284 |
_tree->create<meta_range_t>(rx_dsp_path / "freq/range")
|
| 285 |
.publish(boost::bind(&rx_dsp_core_200::get_freq_range, _rx_dsps[dspno])); |
| 286 |
_tree->create<stream_cmd_t>(rx_dsp_path / "stream_cmd")
|
| 287 |
.subscribe(boost::bind(&rx_dsp_core_200::issue_stream_command, _rx_dsps[dspno], _1)); |
| 288 |
} |
| 289 |
|
| 290 |
////////////////////////////////////////////////////////////////////
|
| 291 |
// create tx dsp control objects
|
| 292 |
////////////////////////////////////////////////////////////////////
|
| 293 |
_tx_dsp = tx_dsp_core_200::make( |
| 294 |
_fpga_ctrl, B100_REG_SR_ADDR(B100_SR_TX_DSP), B100_REG_SR_ADDR(B100_SR_TX_CTRL), B100_TX_ASYNC_SID |
| 295 |
); |
| 296 |
_tree->access<double>(mb_path / "tick_rate") |
| 297 |
.subscribe(boost::bind(&tx_dsp_core_200::set_tick_rate, _tx_dsp, _1)); |
| 298 |
_tree->create<double>(mb_path / "tx_dsps/0/rate/value") |
| 299 |
.coerce(boost::bind(&tx_dsp_core_200::set_host_rate, _tx_dsp, _1)) |
| 300 |
.subscribe(boost::bind(&b100_impl::update_tx_samp_rate, this, _1));
|
| 301 |
_tree->create<double>(mb_path / "tx_dsps/0/freq/value") |
| 302 |
.coerce(boost::bind(&tx_dsp_core_200::set_freq, _tx_dsp, _1)); |
| 303 |
_tree->create<meta_range_t>(mb_path / "tx_dsps/0/freq/range")
|
| 304 |
.publish(boost::bind(&tx_dsp_core_200::get_freq_range, _tx_dsp)); |
| 305 |
|
| 306 |
////////////////////////////////////////////////////////////////////
|
| 307 |
// create time control objects
|
| 308 |
////////////////////////////////////////////////////////////////////
|
| 309 |
time64_core_200::readback_bases_type time64_rb_bases; |
| 310 |
time64_rb_bases.rb_secs_now = B100_REG_RB_TIME_NOW_SECS; |
| 311 |
time64_rb_bases.rb_ticks_now = B100_REG_RB_TIME_NOW_TICKS; |
| 312 |
time64_rb_bases.rb_secs_pps = B100_REG_RB_TIME_PPS_SECS; |
| 313 |
time64_rb_bases.rb_ticks_pps = B100_REG_RB_TIME_PPS_TICKS; |
| 314 |
_time64 = time64_core_200::make( |
| 315 |
_fpga_ctrl, B100_REG_SR_ADDR(B100_SR_TIME64), time64_rb_bases |
| 316 |
); |
| 317 |
_tree->access<double>(mb_path / "tick_rate") |
| 318 |
.subscribe(boost::bind(&time64_core_200::set_tick_rate, _time64, _1)); |
| 319 |
_tree->create<time_spec_t>(mb_path / "time/now")
|
| 320 |
.publish(boost::bind(&time64_core_200::get_time_now, _time64)) |
| 321 |
.subscribe(boost::bind(&time64_core_200::set_time_now, _time64, _1)); |
| 322 |
_tree->create<time_spec_t>(mb_path / "time/pps")
|
| 323 |
.publish(boost::bind(&time64_core_200::get_time_last_pps, _time64)) |
| 324 |
.subscribe(boost::bind(&time64_core_200::set_time_next_pps, _time64, _1)); |
| 325 |
//setup time source props
|
| 326 |
_tree->create<std::string>(mb_path / "time_source/value") |
| 327 |
.subscribe(boost::bind(&time64_core_200::set_time_source, _time64, _1)); |
| 328 |
_tree->create<std::vector<std::string> >(mb_path / "time_source/options") |
| 329 |
.publish(boost::bind(&time64_core_200::get_time_sources, _time64)); |
| 330 |
//setup reference source props
|
| 331 |
_tree->create<std::string>(mb_path / "clock_source/value") |
| 332 |
.subscribe(boost::bind(&b100_impl::update_clock_source, this, _1));
|
| 333 |
static const std::vector<std::string> clock_sources = boost::assign::list_of("internal")("external")("auto"); |
| 334 |
_tree->create<std::vector<std::string> >(mb_path / "clock_source/options").set(clock_sources); |
| 335 |
|
| 336 |
////////////////////////////////////////////////////////////////////
|
| 337 |
// create dboard control objects
|
| 338 |
////////////////////////////////////////////////////////////////////
|
| 339 |
|
| 340 |
//read the dboard eeprom to extract the dboard ids
|
| 341 |
dboard_eeprom_t rx_db_eeprom, tx_db_eeprom, gdb_eeprom; |
| 342 |
rx_db_eeprom.load(*_fpga_i2c_ctrl, I2C_ADDR_RX_A); |
| 343 |
tx_db_eeprom.load(*_fpga_i2c_ctrl, I2C_ADDR_TX_A); |
| 344 |
gdb_eeprom.load(*_fpga_i2c_ctrl, I2C_ADDR_TX_A ^ 5);
|
| 345 |
|
| 346 |
//create the properties and register subscribers
|
| 347 |
_tree->create<dboard_eeprom_t>(mb_path / "dboards/A/rx_eeprom")
|
| 348 |
.set(rx_db_eeprom) |
| 349 |
.subscribe(boost::bind(&b100_impl::set_db_eeprom, this, "rx", _1)); |
| 350 |
_tree->create<dboard_eeprom_t>(mb_path / "dboards/A/tx_eeprom")
|
| 351 |
.set(tx_db_eeprom) |
| 352 |
.subscribe(boost::bind(&b100_impl::set_db_eeprom, this, "tx", _1)); |
| 353 |
_tree->create<dboard_eeprom_t>(mb_path / "dboards/A/gdb_eeprom")
|
| 354 |
.set(gdb_eeprom) |
| 355 |
.subscribe(boost::bind(&b100_impl::set_db_eeprom, this, "gdb", _1)); |
| 356 |
|
| 357 |
//create a new dboard interface and manager
|
| 358 |
_dboard_iface = make_b100_dboard_iface(_fpga_ctrl, _fpga_i2c_ctrl, _fpga_spi_ctrl, _clock_ctrl, _codec_ctrl); |
| 359 |
_tree->create<dboard_iface::sptr>(mb_path / "dboards/A/iface").set(_dboard_iface);
|
| 360 |
_dboard_manager = dboard_manager::make( |
| 361 |
rx_db_eeprom.id, |
| 362 |
((gdb_eeprom.id == dboard_id_t::none())? tx_db_eeprom : gdb_eeprom).id, |
| 363 |
_dboard_iface |
| 364 |
); |
| 365 |
BOOST_FOREACH(const std::string &name, _dboard_manager->get_rx_subdev_names()){ |
| 366 |
dboard_manager::populate_prop_tree_from_subdev( |
| 367 |
_tree, mb_path / "dboards/A/rx_frontends" / name,
|
| 368 |
_dboard_manager->get_rx_subdev(name) |
| 369 |
); |
| 370 |
} |
| 371 |
BOOST_FOREACH(const std::string &name, _dboard_manager->get_tx_subdev_names()){ |
| 372 |
dboard_manager::populate_prop_tree_from_subdev( |
| 373 |
_tree, mb_path / "dboards/A/tx_frontends" / name,
|
| 374 |
_dboard_manager->get_tx_subdev(name) |
| 375 |
); |
| 376 |
} |
| 377 |
|
| 378 |
//initialize io handling
|
| 379 |
this->io_init();
|
| 380 |
|
| 381 |
////////////////////////////////////////////////////////////////////
|
| 382 |
// do some post-init tasks
|
| 383 |
////////////////////////////////////////////////////////////////////
|
| 384 |
_tree->access<double>(mb_path / "tick_rate").update() //update and then subscribe the clock callback |
| 385 |
.subscribe(boost::bind(&b100_clock_ctrl::set_fpga_clock_rate, _clock_ctrl, _1)); |
| 386 |
|
| 387 |
//and now that the tick rate is set, init the host rates to something
|
| 388 |
BOOST_FOREACH(const std::string &name, _tree->list(mb_path / "rx_dsps")){ |
| 389 |
_tree->access<double>(mb_path / "rx_dsps" / name / "rate" / "value").set(1e6); |
| 390 |
} |
| 391 |
BOOST_FOREACH(const std::string &name, _tree->list(mb_path / "tx_dsps")){ |
| 392 |
_tree->access<double>(mb_path / "tx_dsps" / name / "rate" / "value").set(1e6); |
| 393 |
} |
| 394 |
|
| 395 |
_tree->access<subdev_spec_t>(mb_path / "rx_subdev_spec").set(subdev_spec_t("A:"+_dboard_manager->get_rx_subdev_names()[0])); |
| 396 |
_tree->access<subdev_spec_t>(mb_path / "tx_subdev_spec").set(subdev_spec_t("A:"+_dboard_manager->get_tx_subdev_names()[0])); |
| 397 |
_tree->access<std::string>(mb_path / "clock_source/value").set("internal"); |
| 398 |
_tree->access<std::string>(mb_path / "time_source/value").set("none"); |
| 399 |
} |
| 400 |
|
| 401 |
b100_impl::~b100_impl(void){
|
| 402 |
//set an empty async callback now that we deconstruct
|
| 403 |
_fpga_ctrl->set_async_cb(b100_ctrl::async_cb_type()); |
| 404 |
} |
| 405 |
|
| 406 |
void b100_impl::check_fw_compat(void){ |
| 407 |
unsigned char data[4]; //useless data buffer |
| 408 |
const boost::uint16_t fw_compat_num = _fx2_ctrl->usrp_control_read(
|
| 409 |
VRQ_FW_COMPAT, 0, 0, data, sizeof(data) |
| 410 |
); |
| 411 |
if (fw_compat_num != B100_FW_COMPAT_NUM){
|
| 412 |
throw uhd::runtime_error(str(boost::format(
|
| 413 |
"Expected firmware compatibility number 0x%x, but got 0x%x:\n"
|
| 414 |
"The firmware build is not compatible with the host code build."
|
| 415 |
) % B100_FW_COMPAT_NUM % fw_compat_num)); |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
void b100_impl::check_fpga_compat(void){ |
| 420 |
const boost::uint16_t fpga_compat_num = _fpga_ctrl->peek16(B100_REG_MISC_COMPAT);
|
| 421 |
if (fpga_compat_num != B100_FPGA_COMPAT_NUM){
|
| 422 |
throw uhd::runtime_error(str(boost::format(
|
| 423 |
"Expected FPGA compatibility number 0x%x, but got 0x%x:\n"
|
| 424 |
"The FPGA build is not compatible with the host code build."
|
| 425 |
) % B100_FPGA_COMPAT_NUM % fpga_compat_num)); |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
double b100_impl::update_rx_codec_gain(const double gain){ |
| 430 |
//set gain on both I and Q, readback on one
|
| 431 |
//TODO in the future, gains should have individual control
|
| 432 |
_codec_ctrl->set_rx_pga_gain(gain, 'A');
|
| 433 |
_codec_ctrl->set_rx_pga_gain(gain, 'B');
|
| 434 |
return _codec_ctrl->get_rx_pga_gain('A'); |
| 435 |
} |
| 436 |
|
| 437 |
void b100_impl::set_mb_eeprom(const uhd::usrp::mboard_eeprom_t &mb_eeprom){ |
| 438 |
mb_eeprom.commit(*_fx2_ctrl, mboard_eeprom_t::MAP_B000); |
| 439 |
} |
| 440 |
|
| 441 |
void b100_impl::set_db_eeprom(const std::string &type, const uhd::usrp::dboard_eeprom_t &db_eeprom){ |
| 442 |
if (type == "rx") db_eeprom.store(*_fpga_i2c_ctrl, I2C_ADDR_RX_A); |
| 443 |
if (type == "tx") db_eeprom.store(*_fpga_i2c_ctrl, I2C_ADDR_TX_A); |
| 444 |
if (type == "gdb") db_eeprom.store(*_fpga_i2c_ctrl, I2C_ADDR_TX_A ^ 5); |
| 445 |
} |
| 446 |
|
| 447 |
void b100_impl::update_clock_source(const std::string &source){ |
| 448 |
if (source == "auto") _clock_ctrl->use_auto_ref(); |
| 449 |
else if (source == "internal") _clock_ctrl->use_internal_ref(); |
| 450 |
else if (source == "external") _clock_ctrl->use_external_ref(); |
| 451 |
else throw uhd::runtime_error("unhandled clock configuration reference source: " + source); |
| 452 |
} |
| 453 |
|
| 454 |
////////////////// some GPIF preparation related stuff /////////////////
|
| 455 |
void b100_impl::reset_gpif(const boost::uint16_t ep) { |
| 456 |
_fx2_ctrl->usrp_control_write(VRQ_RESET_GPIF, ep, ep, 0, 0); |
| 457 |
} |
| 458 |
|
| 459 |
void b100_impl::enable_gpif(const bool en) { |
| 460 |
_fx2_ctrl->usrp_control_write(VRQ_ENABLE_GPIF, en ? 1 : 0, 0, 0, 0); |
| 461 |
} |
| 462 |
|
| 463 |
void b100_impl::clear_fpga_fifo(void) { |
| 464 |
_fx2_ctrl->usrp_control_write(VRQ_CLEAR_FPGA_FIFO, 0, 0, 0, 0); |
| 465 |
} |