2010-08-13 23:20:41 +00:00
|
|
|
//
|
2014-07-17 18:50:50 +00:00
|
|
|
// Copyright 2010-2012,2014 Ettus Research LLC
|
2010-08-13 23:20:41 +00:00
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "usrp1_impl.hpp"
|
2011-05-05 02:53:01 +00:00
|
|
|
#include <uhd/utils/log.hpp>
|
2011-03-10 22:37:34 +00:00
|
|
|
#include <uhd/utils/safe_call.hpp>
|
2010-08-13 23:20:41 +00:00
|
|
|
#include <uhd/transport/usb_control.hpp>
|
2011-05-05 01:36:10 +00:00
|
|
|
#include <uhd/utils/msg.hpp>
|
2014-03-28 15:16:21 +00:00
|
|
|
#include <uhd/utils/cast.hpp>
|
2011-02-24 22:54:24 +00:00
|
|
|
#include <uhd/exception.hpp>
|
2010-08-13 23:20:41 +00:00
|
|
|
#include <uhd/utils/static.hpp>
|
2010-08-20 01:23:19 +00:00
|
|
|
#include <uhd/utils/images.hpp>
|
2010-08-13 23:20:41 +00:00
|
|
|
#include <boost/format.hpp>
|
2010-08-16 01:49:06 +00:00
|
|
|
#include <boost/assign/list_of.hpp>
|
2010-08-13 23:20:41 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2010-08-20 01:23:19 +00:00
|
|
|
#include <boost/thread/thread.hpp>
|
2010-09-29 22:35:54 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2011-10-21 23:38:45 +00:00
|
|
|
#include <boost/math/special_functions/round.hpp>
|
2011-10-10 18:51:29 +00:00
|
|
|
#include <cstdio>
|
2010-08-13 23:20:41 +00:00
|
|
|
|
|
|
|
|
using namespace uhd;
|
|
|
|
|
using namespace uhd::usrp;
|
|
|
|
|
using namespace uhd::transport;
|
|
|
|
|
|
2010-08-31 23:44:30 +00:00
|
|
|
const boost::uint16_t USRP1_VENDOR_ID = 0xfffe;
|
|
|
|
|
const boost::uint16_t USRP1_PRODUCT_ID = 0x0002;
|
|
|
|
|
const boost::uint16_t FX2_VENDOR_ID = 0x04b4;
|
|
|
|
|
const boost::uint16_t FX2_PRODUCT_ID = 0x8613;
|
2012-01-17 23:32:23 +00:00
|
|
|
static const boost::posix_time::milliseconds REENUMERATION_TIMEOUT_MS(3000);
|
2010-08-31 23:44:30 +00:00
|
|
|
|
2010-08-16 01:49:06 +00:00
|
|
|
const std::vector<usrp1_impl::dboard_slot_t> usrp1_impl::_dboard_slots = boost::assign::list_of
|
|
|
|
|
(usrp1_impl::DBOARD_SLOT_A)(usrp1_impl::DBOARD_SLOT_B)
|
|
|
|
|
;
|
|
|
|
|
|
2010-08-13 23:20:41 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Discovery
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
static device_addrs_t usrp1_find(const device_addr_t &hint)
|
|
|
|
|
{
|
|
|
|
|
device_addrs_t usrp1_addrs;
|
|
|
|
|
|
|
|
|
|
//return an empty list of addresses when type is set to non-usrp1
|
|
|
|
|
if (hint.has_key("type") and hint["type"] != "usrp1") return usrp1_addrs;
|
|
|
|
|
|
2014-02-04 19:04:07 +00:00
|
|
|
//Return an empty list of addresses when an address or resource is specified,
|
|
|
|
|
//since an address and resource is intended for a different, non-USB, device.
|
|
|
|
|
if (hint.has_key("addr") || hint.has_key("resource")) return usrp1_addrs;
|
2010-11-05 08:01:51 +00:00
|
|
|
|
2014-03-28 15:16:21 +00:00
|
|
|
boost::uint16_t vid, pid;
|
2011-10-10 18:51:29 +00:00
|
|
|
|
|
|
|
|
if(hint.has_key("vid") && hint.has_key("pid") && hint.has_key("type") && hint["type"] == "usrp1") {
|
2014-03-28 15:16:21 +00:00
|
|
|
vid = uhd::cast::hexstr_cast<boost::uint16_t>(hint.get("vid"));
|
|
|
|
|
pid = uhd::cast::hexstr_cast<boost::uint16_t>(hint.get("pid"));
|
2011-10-10 18:51:29 +00:00
|
|
|
} else {
|
|
|
|
|
vid = USRP1_VENDOR_ID;
|
|
|
|
|
pid = USRP1_PRODUCT_ID;
|
|
|
|
|
}
|
2010-08-31 23:44:30 +00:00
|
|
|
|
2010-09-28 18:08:41 +00:00
|
|
|
// Important note:
|
|
|
|
|
// The get device list calls are nested inside the for loop.
|
|
|
|
|
// This allows the usb guts to decontruct when not in use,
|
|
|
|
|
// so that re-enumeration after fw load can occur successfully.
|
|
|
|
|
// This requirement is a courtesy of libusb1.0 on windows.
|
2010-08-13 23:20:41 +00:00
|
|
|
|
|
|
|
|
//find the usrps and load firmware
|
2012-01-28 03:09:58 +00:00
|
|
|
size_t found = 0;
|
2010-09-28 18:08:41 +00:00
|
|
|
BOOST_FOREACH(usb_device_handle::sptr handle, usb_device_handle::get_device_list(vid, pid)) {
|
2011-03-03 02:21:54 +00:00
|
|
|
//extract the firmware path for the USRP1
|
|
|
|
|
std::string usrp1_fw_image;
|
|
|
|
|
try{
|
|
|
|
|
usrp1_fw_image = find_image_path(hint.get("fw", "usrp1_fw.ihx"));
|
|
|
|
|
}
|
|
|
|
|
catch(...){
|
2012-06-07 19:30:21 +00:00
|
|
|
UHD_MSG(warning) << boost::format("Could not locate USRP1 firmware. %s") % print_images_error();
|
2011-03-03 02:21:54 +00:00
|
|
|
}
|
2011-05-05 02:53:01 +00:00
|
|
|
UHD_LOG << "USRP1 firmware image: " << usrp1_fw_image << std::endl;
|
2011-03-03 02:21:54 +00:00
|
|
|
|
2011-03-30 00:27:17 +00:00
|
|
|
usb_control::sptr control;
|
2011-09-19 23:14:12 +00:00
|
|
|
try{control = usb_control::make(handle, 0);}
|
2011-03-30 00:27:17 +00:00
|
|
|
catch(const uhd::exception &){continue;} //ignore claimed
|
|
|
|
|
|
2011-06-14 22:32:11 +00:00
|
|
|
fx2_ctrl::make(control)->usrp_load_firmware(usrp1_fw_image);
|
2012-01-28 03:09:58 +00:00
|
|
|
found++;
|
2010-08-13 23:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-31 23:44:30 +00:00
|
|
|
//get descriptors again with serial number, but using the initialized VID/PID now since we have firmware
|
|
|
|
|
vid = USRP1_VENDOR_ID;
|
|
|
|
|
pid = USRP1_PRODUCT_ID;
|
2010-08-26 19:21:50 +00:00
|
|
|
|
2012-01-17 23:32:23 +00:00
|
|
|
const boost::system_time timeout_time = boost::get_system_time() + REENUMERATION_TIMEOUT_MS;
|
|
|
|
|
|
|
|
|
|
//search for the device until found or timeout
|
2012-01-28 03:09:58 +00:00
|
|
|
while (boost::get_system_time() < timeout_time and usrp1_addrs.empty() and found != 0)
|
2012-01-17 23:32:23 +00:00
|
|
|
{
|
|
|
|
|
BOOST_FOREACH(usb_device_handle::sptr handle, usb_device_handle::get_device_list(vid, pid))
|
|
|
|
|
{
|
|
|
|
|
usb_control::sptr control;
|
|
|
|
|
try{control = usb_control::make(handle, 0);}
|
|
|
|
|
catch(const uhd::exception &){continue;} //ignore claimed
|
|
|
|
|
|
|
|
|
|
fx2_ctrl::sptr fx2_ctrl = fx2_ctrl::make(control);
|
2012-05-12 21:20:26 +00:00
|
|
|
const mboard_eeprom_t mb_eeprom(*fx2_ctrl, USRP1_EEPROM_MAP_KEY);
|
2012-01-17 23:32:23 +00:00
|
|
|
device_addr_t new_addr;
|
|
|
|
|
new_addr["type"] = "usrp1";
|
|
|
|
|
new_addr["name"] = mb_eeprom["name"];
|
|
|
|
|
new_addr["serial"] = handle->get_serial();
|
|
|
|
|
//this is a found usrp1 when the hint serial and name match or blank
|
|
|
|
|
if (
|
|
|
|
|
(not hint.has_key("name") or hint["name"] == new_addr["name"]) and
|
|
|
|
|
(not hint.has_key("serial") or hint["serial"] == new_addr["serial"])
|
|
|
|
|
){
|
|
|
|
|
usrp1_addrs.push_back(new_addr);
|
|
|
|
|
}
|
2010-10-01 18:54:22 +00:00
|
|
|
}
|
2010-08-13 23:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return usrp1_addrs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* Make
|
|
|
|
|
**********************************************************************/
|
2010-10-05 17:30:28 +00:00
|
|
|
static device::sptr usrp1_make(const device_addr_t &device_addr){
|
2011-07-01 18:33:03 +00:00
|
|
|
return device::sptr(new usrp1_impl(device_addr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UHD_STATIC_BLOCK(register_usrp1_device){
|
2014-07-17 18:50:50 +00:00
|
|
|
device::register_device(&usrp1_find, &usrp1_make, device::USRP);
|
2011-07-01 18:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* Structors
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
usrp1_impl::usrp1_impl(const device_addr_t &device_addr){
|
2011-05-05 03:40:36 +00:00
|
|
|
UHD_MSG(status) << "Opening a USRP1 device..." << std::endl;
|
2014-07-17 18:50:50 +00:00
|
|
|
_type = device::USRP;
|
2010-09-29 22:35:54 +00:00
|
|
|
|
2010-08-20 01:23:19 +00:00
|
|
|
//extract the FPGA path for the USRP1
|
|
|
|
|
std::string usrp1_fpga_image = find_image_path(
|
2010-10-31 18:04:42 +00:00
|
|
|
device_addr.get("fpga", "usrp1_fpga.rbf")
|
2010-08-20 01:23:19 +00:00
|
|
|
);
|
2011-05-05 02:53:01 +00:00
|
|
|
UHD_LOG << "USRP1 FPGA image: " << usrp1_fpga_image << std::endl;
|
2010-08-13 23:20:41 +00:00
|
|
|
|
|
|
|
|
//try to match the given device address with something on the USB bus
|
2010-08-26 19:21:50 +00:00
|
|
|
std::vector<usb_device_handle::sptr> device_list =
|
2010-08-31 23:44:30 +00:00
|
|
|
usb_device_handle::get_device_list(USRP1_VENDOR_ID, USRP1_PRODUCT_ID);
|
2010-08-13 23:20:41 +00:00
|
|
|
|
2010-10-05 17:30:28 +00:00
|
|
|
//locate the matching handle in the device list
|
|
|
|
|
usb_device_handle::sptr handle;
|
|
|
|
|
BOOST_FOREACH(usb_device_handle::sptr dev_handle, device_list) {
|
|
|
|
|
if (dev_handle->get_serial() == device_addr["serial"]){
|
|
|
|
|
handle = dev_handle;
|
2010-08-13 23:20:41 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-05 17:30:28 +00:00
|
|
|
UHD_ASSERT_THROW(handle.get() != NULL); //better be found
|
|
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Create controller objects
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
//usb_control::sptr usb_ctrl = usb_control::make(handle);
|
2011-09-19 23:14:12 +00:00
|
|
|
_fx2_ctrl = fx2_ctrl::make(usb_control::make(handle, 0));
|
2011-07-01 18:33:03 +00:00
|
|
|
_fx2_ctrl->usrp_load_fpga(usrp1_fpga_image);
|
|
|
|
|
_fx2_ctrl->usrp_init();
|
|
|
|
|
_data_transport = usb_zero_copy::make(
|
2010-10-05 17:30:28 +00:00
|
|
|
handle, // identifier
|
2011-09-19 23:14:12 +00:00
|
|
|
2, 6, // IN interface, endpoint
|
|
|
|
|
1, 2, // OUT interface, endpoint
|
2010-10-05 17:30:28 +00:00
|
|
|
device_addr // param hints
|
|
|
|
|
);
|
2011-07-01 18:33:03 +00:00
|
|
|
_iface = usrp1_iface::make(_fx2_ctrl);
|
|
|
|
|
_soft_time_ctrl = soft_time_ctrl::make(
|
|
|
|
|
boost::bind(&usrp1_impl::rx_stream_on_off, this, _1)
|
2010-08-18 18:06:57 +00:00
|
|
|
);
|
2011-07-01 18:33:03 +00:00
|
|
|
_dbc["A"]; _dbc["B"]; //ensure that keys exist
|
|
|
|
|
|
|
|
|
|
// Normal mode with no loopback or Rx counting
|
|
|
|
|
_iface->poke32(FR_MODE, 0x00000000);
|
|
|
|
|
_iface->poke32(FR_DEBUG_EN, 0x00000000);
|
|
|
|
|
|
|
|
|
|
UHD_LOG
|
|
|
|
|
<< "USRP1 Capabilities" << std::endl
|
|
|
|
|
<< " number of duc's: " << get_num_ddcs() << std::endl
|
|
|
|
|
<< " number of ddc's: " << get_num_ducs() << std::endl
|
|
|
|
|
<< " rx halfband: " << has_rx_halfband() << std::endl
|
|
|
|
|
<< " tx halfband: " << has_tx_halfband() << std::endl
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Initialize the properties tree
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2012-02-10 03:02:43 +00:00
|
|
|
_rx_dc_offset_shadow = 0;
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree = property_tree::make();
|
|
|
|
|
_tree->create<std::string>("/name").set("USRP1 Device");
|
2011-07-22 08:19:03 +00:00
|
|
|
const fs_path mb_path = "/mboards/0";
|
2012-04-20 21:14:27 +00:00
|
|
|
_tree->create<std::string>(mb_path / "name").set("USRP1");
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<std::string>(mb_path / "load_eeprom")
|
|
|
|
|
.subscribe(boost::bind(&fx2_ctrl::usrp_load_eeprom, _fx2_ctrl, _1));
|
|
|
|
|
|
2012-09-13 17:43:15 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// create user-defined control objects
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
_tree->create<std::pair<boost::uint8_t, boost::uint32_t> >(mb_path / "user" / "regs")
|
|
|
|
|
.subscribe(boost::bind(&usrp1_impl::set_reg, this, _1));
|
|
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// setup the mboard eeprom
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2012-05-12 21:20:26 +00:00
|
|
|
const mboard_eeprom_t mb_eeprom(*_fx2_ctrl, USRP1_EEPROM_MAP_KEY);
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<mboard_eeprom_t>(mb_path / "eeprom")
|
|
|
|
|
.set(mb_eeprom)
|
|
|
|
|
.subscribe(boost::bind(&usrp1_impl::set_mb_eeprom, this, _1));
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// create clock control objects
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
_master_clock_rate = 64e6;
|
2011-10-11 19:12:25 +00:00
|
|
|
if (device_addr.has_key("mcr")){
|
|
|
|
|
try{
|
|
|
|
|
_master_clock_rate = boost::lexical_cast<double>(device_addr["mcr"]);
|
|
|
|
|
}
|
|
|
|
|
catch(const std::exception &e){
|
|
|
|
|
UHD_MSG(error) << "Error parsing FPGA clock rate from device address: " << e.what() << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (not mb_eeprom["mcr"].empty()){
|
|
|
|
|
try{
|
2011-07-01 18:33:03 +00:00
|
|
|
_master_clock_rate = boost::lexical_cast<double>(mb_eeprom["mcr"]);
|
2011-10-11 19:12:25 +00:00
|
|
|
}
|
|
|
|
|
catch(const std::exception &e){
|
|
|
|
|
UHD_MSG(error) << "Error parsing FPGA clock rate from EEPROM: " << e.what() << std::endl;
|
|
|
|
|
}
|
2011-07-01 18:33:03 +00:00
|
|
|
}
|
|
|
|
|
UHD_MSG(status) << boost::format("Using FPGA clock rate of %fMHz...") % (_master_clock_rate/1e6) << std::endl;
|
2011-10-11 19:12:25 +00:00
|
|
|
_tree->create<double>(mb_path / "tick_rate")
|
2012-01-05 20:34:53 +00:00
|
|
|
.subscribe(boost::bind(&usrp1_impl::update_tick_rate, this, _1))
|
|
|
|
|
.set(_master_clock_rate);
|
2011-07-01 18:33:03 +00:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// create codec control objects
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
BOOST_FOREACH(const std::string &db, _dbc.keys()){
|
|
|
|
|
_dbc[db].codec = usrp1_codec_ctrl::make(_iface, (db == "A")? SPI_ENABLE_CODEC_A : SPI_ENABLE_CODEC_B);
|
2011-07-22 08:19:03 +00:00
|
|
|
const fs_path rx_codec_path = mb_path / "rx_codecs" / db;
|
|
|
|
|
const fs_path tx_codec_path = mb_path / "tx_codecs" / db;
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<std::string>(rx_codec_path / "name").set("ad9522");
|
|
|
|
|
_tree->create<meta_range_t>(rx_codec_path / "gains/pga/range").set(usrp1_codec_ctrl::rx_pga_gain_range);
|
|
|
|
|
_tree->create<double>(rx_codec_path / "gains/pga/value")
|
2013-11-08 23:15:19 +00:00
|
|
|
.coerce(boost::bind(&usrp1_impl::update_rx_codec_gain, this, db, _1))
|
|
|
|
|
.set(0.0);
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<std::string>(tx_codec_path / "name").set("ad9522");
|
|
|
|
|
_tree->create<meta_range_t>(tx_codec_path / "gains/pga/range").set(usrp1_codec_ctrl::tx_pga_gain_range);
|
|
|
|
|
_tree->create<double>(tx_codec_path / "gains/pga/value")
|
|
|
|
|
.subscribe(boost::bind(&usrp1_codec_ctrl::set_tx_pga_gain, _dbc[db].codec, _1))
|
2013-11-08 23:15:19 +00:00
|
|
|
.publish(boost::bind(&usrp1_codec_ctrl::get_tx_pga_gain, _dbc[db].codec))
|
|
|
|
|
.set(0.0);
|
2011-07-01 18:33:03 +00:00
|
|
|
}
|
2010-08-13 23:20:41 +00:00
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// and do the misc mboard sensors
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
//none for now...
|
|
|
|
|
_tree->create<int>(mb_path / "sensors"); //phony property so this dir exists
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// create frontend control objects
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
_tree->create<subdev_spec_t>(mb_path / "rx_subdev_spec")
|
2012-05-12 04:30:29 +00:00
|
|
|
.set(subdev_spec_t())
|
2011-07-01 18:33:03 +00:00
|
|
|
.subscribe(boost::bind(&usrp1_impl::update_rx_subdev_spec, this, _1));
|
|
|
|
|
_tree->create<subdev_spec_t>(mb_path / "tx_subdev_spec")
|
2012-05-12 04:30:29 +00:00
|
|
|
.set(subdev_spec_t())
|
2011-07-01 18:33:03 +00:00
|
|
|
.subscribe(boost::bind(&usrp1_impl::update_tx_subdev_spec, this, _1));
|
|
|
|
|
|
2011-10-21 23:38:45 +00:00
|
|
|
BOOST_FOREACH(const std::string &db, _dbc.keys()){
|
2011-10-26 02:26:11 +00:00
|
|
|
const fs_path rx_fe_path = mb_path / "rx_frontends" / db;
|
|
|
|
|
_tree->create<std::complex<double> >(rx_fe_path / "dc_offset" / "value")
|
2011-10-21 23:38:45 +00:00
|
|
|
.coerce(boost::bind(&usrp1_impl::set_rx_dc_offset, this, db, _1))
|
|
|
|
|
.set(std::complex<double>(0.0, 0.0));
|
2011-10-26 02:26:11 +00:00
|
|
|
_tree->create<bool>(rx_fe_path / "dc_offset" / "enable")
|
2011-10-21 23:38:45 +00:00
|
|
|
.subscribe(boost::bind(&usrp1_impl::set_enb_rx_dc_offset, this, db, _1))
|
|
|
|
|
.set(true);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// create rx dsp control objects
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2011-08-09 02:36:16 +00:00
|
|
|
_tree->create<int>(mb_path / "rx_dsps"); //dummy in case we have none
|
2011-07-01 18:33:03 +00:00
|
|
|
for (size_t dspno = 0; dspno < get_num_ddcs(); dspno++){
|
2011-07-22 08:19:03 +00:00
|
|
|
fs_path rx_dsp_path = mb_path / str(boost::format("rx_dsps/%u") % dspno);
|
2011-10-16 17:43:48 +00:00
|
|
|
_tree->create<meta_range_t>(rx_dsp_path / "rate/range")
|
|
|
|
|
.publish(boost::bind(&usrp1_impl::get_rx_dsp_host_rates, this));
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<double>(rx_dsp_path / "rate/value")
|
2011-10-16 17:43:48 +00:00
|
|
|
.set(1e6) //some default rate
|
2011-10-07 01:41:59 +00:00
|
|
|
.coerce(boost::bind(&usrp1_impl::update_rx_samp_rate, this, dspno, _1));
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<double>(rx_dsp_path / "freq/value")
|
|
|
|
|
.coerce(boost::bind(&usrp1_impl::update_rx_dsp_freq, this, dspno, _1));
|
|
|
|
|
_tree->create<meta_range_t>(rx_dsp_path / "freq/range")
|
2011-10-11 19:12:25 +00:00
|
|
|
.publish(boost::bind(&usrp1_impl::get_rx_dsp_freq_range, this));
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<stream_cmd_t>(rx_dsp_path / "stream_cmd");
|
|
|
|
|
if (dspno == 0){
|
|
|
|
|
//only subscribe the callback for dspno 0 since it will stream all dsps
|
|
|
|
|
_tree->access<stream_cmd_t>(rx_dsp_path / "stream_cmd")
|
|
|
|
|
.subscribe(boost::bind(&soft_time_ctrl::issue_stream_cmd, _soft_time_ctrl, _1));
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-13 23:20:41 +00:00
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// create tx dsp control objects
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2011-08-09 02:36:16 +00:00
|
|
|
_tree->create<int>(mb_path / "tx_dsps"); //dummy in case we have none
|
2011-07-01 18:33:03 +00:00
|
|
|
for (size_t dspno = 0; dspno < get_num_ducs(); dspno++){
|
2011-07-22 08:19:03 +00:00
|
|
|
fs_path tx_dsp_path = mb_path / str(boost::format("tx_dsps/%u") % dspno);
|
2011-10-16 17:43:48 +00:00
|
|
|
_tree->create<meta_range_t>(tx_dsp_path / "rate/range")
|
|
|
|
|
.publish(boost::bind(&usrp1_impl::get_tx_dsp_host_rates, this));
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<double>(tx_dsp_path / "rate/value")
|
2011-10-16 17:43:48 +00:00
|
|
|
.set(1e6) //some default rate
|
2011-10-07 01:41:59 +00:00
|
|
|
.coerce(boost::bind(&usrp1_impl::update_tx_samp_rate, this, dspno, _1));
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<double>(tx_dsp_path / "freq/value")
|
|
|
|
|
.coerce(boost::bind(&usrp1_impl::update_tx_dsp_freq, this, dspno, _1));
|
2011-10-11 19:12:25 +00:00
|
|
|
_tree->create<meta_range_t>(tx_dsp_path / "freq/range")
|
|
|
|
|
.publish(boost::bind(&usrp1_impl::get_tx_dsp_freq_range, this));
|
2011-07-01 18:33:03 +00:00
|
|
|
}
|
2010-08-13 23:20:41 +00:00
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// create time control objects
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
_tree->create<time_spec_t>(mb_path / "time/now")
|
|
|
|
|
.publish(boost::bind(&soft_time_ctrl::get_time, _soft_time_ctrl))
|
|
|
|
|
.subscribe(boost::bind(&soft_time_ctrl::set_time, _soft_time_ctrl, _1));
|
|
|
|
|
|
2011-07-02 16:32:00 +00:00
|
|
|
_tree->create<std::vector<std::string> >(mb_path / "clock_source/options").set(std::vector<std::string>(1, "internal"));
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<std::vector<std::string> >(mb_path / "time_source/options").set(std::vector<std::string>(1, "none"));
|
2011-07-02 16:32:00 +00:00
|
|
|
_tree->create<std::string>(mb_path / "clock_source/value").set("internal");
|
2011-07-01 18:33:03 +00:00
|
|
|
_tree->create<std::string>(mb_path / "time_source/value").set("none");
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// create dboard control objects
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
BOOST_FOREACH(const std::string &db, _dbc.keys()){
|
|
|
|
|
|
|
|
|
|
//read the dboard eeprom to extract the dboard ids
|
|
|
|
|
dboard_eeprom_t rx_db_eeprom, tx_db_eeprom, gdb_eeprom;
|
|
|
|
|
rx_db_eeprom.load(*_fx2_ctrl, (db == "A")? (I2C_ADDR_RX_A) : (I2C_ADDR_RX_B));
|
|
|
|
|
tx_db_eeprom.load(*_fx2_ctrl, (db == "A")? (I2C_ADDR_TX_A) : (I2C_ADDR_TX_B));
|
|
|
|
|
gdb_eeprom.load(*_fx2_ctrl, (db == "A")? (I2C_ADDR_TX_A ^ 5) : (I2C_ADDR_TX_B ^ 5));
|
|
|
|
|
|
2012-09-28 23:58:28 +00:00
|
|
|
//disable rx dc offset if LFRX
|
|
|
|
|
if (rx_db_eeprom.id == 0x000f) _tree->access<bool>(mb_path / "rx_frontends" / db / "dc_offset" / "enable").set(false);
|
|
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
//create the properties and register subscribers
|
|
|
|
|
_tree->create<dboard_eeprom_t>(mb_path / "dboards" / db/ "rx_eeprom")
|
|
|
|
|
.set(rx_db_eeprom)
|
|
|
|
|
.subscribe(boost::bind(&usrp1_impl::set_db_eeprom, this, db, "rx", _1));
|
|
|
|
|
_tree->create<dboard_eeprom_t>(mb_path / "dboards" / db/ "tx_eeprom")
|
|
|
|
|
.set(tx_db_eeprom)
|
|
|
|
|
.subscribe(boost::bind(&usrp1_impl::set_db_eeprom, this, db, "tx", _1));
|
|
|
|
|
_tree->create<dboard_eeprom_t>(mb_path / "dboards" / db/ "gdb_eeprom")
|
|
|
|
|
.set(gdb_eeprom)
|
|
|
|
|
.subscribe(boost::bind(&usrp1_impl::set_db_eeprom, this, db, "gdb", _1));
|
|
|
|
|
|
|
|
|
|
//create a new dboard interface and manager
|
|
|
|
|
_dbc[db].dboard_iface = make_dboard_iface(
|
|
|
|
|
_iface, _dbc[db].codec,
|
|
|
|
|
(db == "A")? DBOARD_SLOT_A : DBOARD_SLOT_B,
|
|
|
|
|
_master_clock_rate, rx_db_eeprom.id
|
|
|
|
|
);
|
|
|
|
|
_tree->create<dboard_iface::sptr>(mb_path / "dboards" / db/ "iface").set(_dbc[db].dboard_iface);
|
|
|
|
|
_dbc[db].dboard_manager = dboard_manager::make(
|
2011-07-30 17:11:49 +00:00
|
|
|
rx_db_eeprom.id, tx_db_eeprom.id, gdb_eeprom.id,
|
|
|
|
|
_dbc[db].dboard_iface, _tree->subtree(mb_path / "dboards" / db)
|
2011-07-01 18:33:03 +00:00
|
|
|
);
|
2010-08-13 23:20:41 +00:00
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
//init the subdev specs if we have a dboard (wont leave this loop empty)
|
|
|
|
|
if (rx_db_eeprom.id != dboard_id_t::none() or _rx_subdev_spec.empty()){
|
2011-07-30 17:11:49 +00:00
|
|
|
_rx_subdev_spec = subdev_spec_t(db + ":" + _tree->list(mb_path / "dboards" / db / "rx_frontends").at(0));
|
2011-07-01 18:33:03 +00:00
|
|
|
}
|
|
|
|
|
if (tx_db_eeprom.id != dboard_id_t::none() or _tx_subdev_spec.empty()){
|
2011-07-30 17:11:49 +00:00
|
|
|
_tx_subdev_spec = subdev_spec_t(db + ":" + _tree->list(mb_path / "dboards" / db / "tx_frontends").at(0));
|
2011-07-01 18:33:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-08-13 23:20:41 +00:00
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
//initialize io handling
|
|
|
|
|
this->io_init();
|
2010-08-13 23:20:41 +00:00
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
// do some post-init tasks
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2011-10-05 21:41:57 +00:00
|
|
|
this->update_rates();
|
2012-02-28 21:35:50 +00:00
|
|
|
|
|
|
|
|
//reset cordic rates and their properties to zero
|
|
|
|
|
BOOST_FOREACH(const std::string &name, _tree->list(mb_path / "rx_dsps")){
|
|
|
|
|
_tree->access<double>(mb_path / "rx_dsps" / name / "freq" / "value").set(0.0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-09 02:36:16 +00:00
|
|
|
if (_tree->list(mb_path / "rx_dsps").size() > 0)
|
|
|
|
|
_tree->access<subdev_spec_t>(mb_path / "rx_subdev_spec").set(_rx_subdev_spec);
|
|
|
|
|
if (_tree->list(mb_path / "tx_dsps").size() > 0)
|
|
|
|
|
_tree->access<subdev_spec_t>(mb_path / "tx_subdev_spec").set(_tx_subdev_spec);
|
2014-04-01 17:37:52 +00:00
|
|
|
_tree->create<double>(mb_path / "link_max_rate").set(USRP1_MAX_RATE_USB2);
|
2010-08-13 23:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 17:54:51 +00:00
|
|
|
usrp1_impl::~usrp1_impl(void){
|
|
|
|
|
UHD_SAFE_CALL(
|
|
|
|
|
this->enable_rx(false);
|
|
|
|
|
this->enable_tx(false);
|
|
|
|
|
)
|
2012-03-29 18:59:27 +00:00
|
|
|
_soft_time_ctrl->stop(); //stops cmd task before proceeding
|
2011-09-02 21:07:13 +00:00
|
|
|
_io_impl.reset(); //stops vandal before other stuff gets deconstructed
|
2011-07-19 17:54:51 +00:00
|
|
|
}
|
2010-08-13 23:20:41 +00:00
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
/*!
|
|
|
|
|
* Capabilities Register
|
|
|
|
|
*
|
|
|
|
|
* 3 2 1 0
|
|
|
|
|
* 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
|
|
|
|
* +-----------------------------------------------+-+-----+-+-----+
|
|
|
|
|
* | Reserved |T|DUCs |R|DDCs |
|
|
|
|
|
* +-----------------------------------------------+-+-----+-+-----+
|
|
|
|
|
*/
|
|
|
|
|
size_t usrp1_impl::get_num_ddcs(void){
|
|
|
|
|
boost::uint32_t regval = _iface->peek32(FR_RB_CAPS);
|
|
|
|
|
return (regval >> 0) & 0x0007;
|
2010-08-20 01:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
size_t usrp1_impl::get_num_ducs(void){
|
|
|
|
|
boost::uint32_t regval = _iface->peek32(FR_RB_CAPS);
|
|
|
|
|
return (regval >> 4) & 0x0007;
|
|
|
|
|
}
|
2010-08-13 23:20:41 +00:00
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
bool usrp1_impl::has_rx_halfband(void){
|
|
|
|
|
boost::uint32_t regval = _iface->peek32(FR_RB_CAPS);
|
|
|
|
|
return (regval >> 3) & 0x0001;
|
|
|
|
|
}
|
2010-08-13 23:20:41 +00:00
|
|
|
|
2011-07-01 18:33:03 +00:00
|
|
|
bool usrp1_impl::has_tx_halfband(void){
|
|
|
|
|
boost::uint32_t regval = _iface->peek32(FR_RB_CAPS);
|
|
|
|
|
return (regval >> 7) & 0x0001;
|
2010-08-13 23:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2011-07-01 18:33:03 +00:00
|
|
|
* Properties callback methods below
|
2010-08-13 23:20:41 +00:00
|
|
|
**********************************************************************/
|
2011-07-01 18:33:03 +00:00
|
|
|
void usrp1_impl::set_mb_eeprom(const uhd::usrp::mboard_eeprom_t &mb_eeprom){
|
2012-05-12 21:20:26 +00:00
|
|
|
mb_eeprom.commit(*_fx2_ctrl, USRP1_EEPROM_MAP_KEY);
|
2011-07-01 18:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void usrp1_impl::set_db_eeprom(const std::string &db, const std::string &type, const uhd::usrp::dboard_eeprom_t &db_eeprom){
|
|
|
|
|
if (type == "rx") db_eeprom.store(*_fx2_ctrl, (db == "A")? (I2C_ADDR_RX_A) : (I2C_ADDR_RX_B));
|
|
|
|
|
if (type == "tx") db_eeprom.store(*_fx2_ctrl, (db == "A")? (I2C_ADDR_TX_A) : (I2C_ADDR_TX_B));
|
|
|
|
|
if (type == "gdb") db_eeprom.store(*_fx2_ctrl, (db == "A")? (I2C_ADDR_TX_A ^ 5) : (I2C_ADDR_TX_B ^ 5));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double usrp1_impl::update_rx_codec_gain(const std::string &db, const double gain){
|
|
|
|
|
//set gain on both I and Q, readback on one
|
|
|
|
|
//TODO in the future, gains should have individual control
|
|
|
|
|
_dbc[db].codec->set_rx_pga_gain(gain, 'A');
|
|
|
|
|
_dbc[db].codec->set_rx_pga_gain(gain, 'B');
|
|
|
|
|
return _dbc[db].codec->get_rx_pga_gain('A');
|
2010-08-13 23:20:41 +00:00
|
|
|
}
|
2011-10-11 19:12:25 +00:00
|
|
|
|
|
|
|
|
uhd::meta_range_t usrp1_impl::get_rx_dsp_freq_range(void){
|
|
|
|
|
return meta_range_t(-_master_clock_rate/2, +_master_clock_rate/2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uhd::meta_range_t usrp1_impl::get_tx_dsp_freq_range(void){
|
|
|
|
|
//magic scalar comes from codec control:
|
|
|
|
|
return meta_range_t(-_master_clock_rate*0.6875, +_master_clock_rate*0.6875);
|
|
|
|
|
}
|
2011-10-21 23:38:45 +00:00
|
|
|
|
|
|
|
|
void usrp1_impl::set_enb_rx_dc_offset(const std::string &db, const bool enb){
|
|
|
|
|
const size_t shift = (db == "A")? 0 : 2;
|
|
|
|
|
_rx_dc_offset_shadow &= ~(0x3 << shift); //clear bits
|
2011-11-08 19:29:45 +00:00
|
|
|
_rx_dc_offset_shadow |= ((enb)? 0x3 : 0x0) << shift;
|
2011-10-21 23:38:45 +00:00
|
|
|
_iface->poke32(FR_DC_OFFSET_CL_EN, _rx_dc_offset_shadow & 0xf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::complex<double> usrp1_impl::set_rx_dc_offset(const std::string &db, const std::complex<double> &offset){
|
|
|
|
|
const boost::int32_t i_off = boost::math::iround(offset.real() * (1ul << 31));
|
|
|
|
|
const boost::int32_t q_off = boost::math::iround(offset.imag() * (1ul << 31));
|
|
|
|
|
|
|
|
|
|
if (db == "A"){
|
|
|
|
|
_iface->poke32(FR_ADC_OFFSET_0, i_off);
|
|
|
|
|
_iface->poke32(FR_ADC_OFFSET_1, q_off);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (db == "B"){
|
|
|
|
|
_iface->poke32(FR_ADC_OFFSET_2, i_off);
|
|
|
|
|
_iface->poke32(FR_ADC_OFFSET_3, q_off);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::complex<double>(double(i_off) * (1ul << 31), double(q_off) * (1ul << 31));
|
|
|
|
|
}
|
2012-09-13 17:43:15 +00:00
|
|
|
|
|
|
|
|
void usrp1_impl::set_reg(const std::pair<boost::uint8_t, boost::uint32_t> ®)
|
|
|
|
|
{
|
|
|
|
|
_iface->poke32(reg.first, reg.second);
|
|
|
|
|
}
|