diff options
Diffstat (limited to 'host/lib/usrp/x300')
-rw-r--r-- | host/lib/usrp/x300/x300_adc_ctrl.cpp | 1 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_adc_dac_utils.cpp | 24 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_clock_ctrl.cpp | 5 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_dac_ctrl.cpp | 5 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_dboard_iface.cpp | 2 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_fw_ctrl.cpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_fw_uart.cpp | 5 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_image_loader.cpp | 2 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_impl.cpp | 180 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_impl.hpp | 9 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_io_impl.cpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_mb_eeprom.cpp | 2 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_radio_ctrl_impl.cpp | 267 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_radio_ctrl_impl.hpp | 15 |
14 files changed, 376 insertions, 153 deletions
diff --git a/host/lib/usrp/x300/x300_adc_ctrl.cpp b/host/lib/usrp/x300/x300_adc_ctrl.cpp index fed2ffaf7..d9d0cb168 100644 --- a/host/lib/usrp/x300/x300_adc_ctrl.cpp +++ b/host/lib/usrp/x300/x300_adc_ctrl.cpp @@ -21,7 +21,6 @@ #include <uhd/utils/log.hpp> #include <uhd/utils/safe_call.hpp> #include <uhd/exception.hpp> -#include <boost/foreach.hpp> using namespace uhd; diff --git a/host/lib/usrp/x300/x300_adc_dac_utils.cpp b/host/lib/usrp/x300/x300_adc_dac_utils.cpp index 6fd0ca50b..fda0bb6c9 100644 --- a/host/lib/usrp/x300/x300_adc_dac_utils.cpp +++ b/host/lib/usrp/x300/x300_adc_dac_utils.cpp @@ -147,7 +147,7 @@ void x300_impl::self_test_adcs(mboard_members_t& mb, uint32_t ramp_time_ms) { void x300_impl::extended_adc_test(mboard_members_t& mb, double duration_s) { static const size_t SECS_PER_ITER = 5; - UHD_MSG(status) << boost::format("Running Extended ADC Self-Test (Duration=%.0fs, %ds/iteration)...\n") + UHD_LOGGER_INFO("X300") << boost::format("Running Extended ADC Self-Test (Duration=%.0fs, %ds/iteration)...") % duration_s % SECS_PER_ITER; size_t num_iters = static_cast<size_t>(ceil(duration_s/SECS_PER_ITER)); @@ -159,18 +159,18 @@ void x300_impl::extended_adc_test(mboard_members_t& mb, double duration_s) time_strm.imbue(std::locale(std::locale::classic(), facet)); time_strm << boost::posix_time::second_clock::local_time(); //Run self-test - UHD_MSG(status) << boost::format("-- [%s] Iteration %06d... ") % time_strm.str() % (iter+1); + UHD_LOGGER_INFO("X300") << boost::format("Running ADC Test Iteration %06d... ") % (iter+1); try { self_test_adcs(mb, SECS_PER_ITER*1000); - UHD_MSG(status) << "passed" << std::endl; + UHD_LOGGER_INFO("X300") << boost::format("ADC Test Iteration %06d passed") % (iter+1); } catch(std::exception &e) { num_failures++; - UHD_MSG(status) << e.what() << std::endl; + UHD_LOGGER_ERROR("X300") << e.what(); } } if (num_failures == 0) { - UHD_MSG(status) << "Extended ADC Self-Test PASSED\n"; + UHD_LOGGER_INFO("X300") << "Extended ADC Self-Test PASSED"; } else { throw uhd::runtime_error( (boost::format("Extended ADC Self-Test FAILED!!! (%d/%d failures)\n") % num_failures % num_iters).str()); @@ -184,7 +184,7 @@ void x300_impl::extended_adc_test(mboard_members_t& mb, double duration_s) void x300_impl::self_cal_adc_capture_delay(mboard_members_t& mb, const size_t radio_i, bool print_status) { radio_perifs_t& perif = mb.radio_perifs[radio_i]; - if (print_status) UHD_MSG(status) << "Running ADC capture delay self-cal..." << std::flush; + if (print_status) UHD_LOGGER_INFO("X300") << "Running ADC capture delay self-cal..."; static const uint32_t NUM_DELAY_STEPS = 32; //The IDELAYE2 element has 32 steps static const uint32_t NUM_RETRIES = 2; //Retry self-cal if it fails in warmup situations @@ -247,7 +247,7 @@ void x300_impl::self_cal_adc_capture_delay(mboard_members_t& mb, const size_t ra } } } - //UHD_MSG(status) << (boost::format("CapTap=%d, Error=%d\n") % dly_tap % err_code); + //UHD_LOGGER_INFO("X300") << (boost::format("CapTap=%d, Error=%d") % dly_tap % err_code); } //Retry the self-cal if it fails @@ -277,13 +277,13 @@ void x300_impl::self_cal_adc_capture_delay(mboard_members_t& mb, const size_t ra if (print_status) { double tap_delay = (1.0e12 / mb.clock->get_master_clock_rate()) / (2*32); //in ps - UHD_MSG(status) << boost::format(" done (Tap=%d, Window=%d, TapDelay=%.3fps, Iter=%d)\n") % ideal_tap % (win_stop-win_start) % tap_delay % iter; + UHD_LOGGER_INFO("X300") << boost::format(" ADC capture delay self-cal done (Tap=%d, Window=%d, TapDelay=%.3fps, Iter=%d)") % ideal_tap % (win_stop-win_start) % tap_delay % iter; } } double x300_impl::self_cal_adc_xfer_delay(mboard_members_t& mb, bool apply_delay) { - UHD_MSG(status) << "Running ADC transfer delay self-cal: " << std::flush; + UHD_LOGGER_INFO("X300") << "Running ADC transfer delay self-cal: "; //Effective resolution of the self-cal. static const size_t NUM_DELAY_STEPS = 100; @@ -293,7 +293,6 @@ double x300_impl::self_cal_adc_xfer_delay(mboard_members_t& mb, bool apply_delay double delay_range = 2 * master_clk_period; double delay_incr = delay_range / NUM_DELAY_STEPS; - UHD_MSG(status) << "Measuring..." << std::flush; double cached_clk_delay = mb.clock->get_clock_delay(X300_CLOCK_WHICH_ADC0); double fpga_clk_delay = mb.clock->get_clock_delay(X300_CLOCK_WHICH_FPGA); @@ -339,7 +338,7 @@ double x300_impl::self_cal_adc_xfer_delay(mboard_members_t& mb, bool apply_delay err_code += 100; //Increment error code by 100 to indicate no lock } } - //UHD_MSG(status) << (boost::format("XferDelay=%fns, Error=%d\n") % delay % err_code); + //UHD_LOGGER_INFO("X300") << (boost::format("XferDelay=%fns, Error=%d") % delay % err_code); results.push_back(std::pair<double,bool>(delay, err_code==0)); } @@ -391,7 +390,6 @@ double x300_impl::self_cal_adc_xfer_delay(mboard_members_t& mb, bool apply_delay } if (apply_delay) { - UHD_MSG(status) << "Validating..." << std::flush; //Apply delay win_center = mb.clock->set_clock_delay(X300_CLOCK_WHICH_ADC0, win_center); //Sets ADC0 and ADC1 wait_for_clk_locked(mb, fw_regmap_t::clk_status_reg_t::LMK_LOCK, 0.1); @@ -407,7 +405,7 @@ double x300_impl::self_cal_adc_xfer_delay(mboard_members_t& mb, bool apply_delay mb.radio_perifs[r].adc->set_test_word("normal", "normal"); mb.radio_perifs[r].regmap->misc_outs_reg.write(radio_regmap_t::misc_outs_reg_t::ADC_CHECKER_ENABLED, 0); } - UHD_MSG(status) << (boost::format(" done (FPGA->ADC=%.3fns%s, Window=%.3fns)\n") % + UHD_LOGGER_INFO("X300") << (boost::format("ADC transfer delay self-cal done (FPGA->ADC=%.3fns%s, Window=%.3fns)") % (win_center-fpga_clk_delay) % (cycle_slip?" +cyc":"") % win_length); return win_center; diff --git a/host/lib/usrp/x300/x300_clock_ctrl.cpp b/host/lib/usrp/x300/x300_clock_ctrl.cpp index b8b100ceb..7307bcc66 100644 --- a/host/lib/usrp/x300/x300_clock_ctrl.cpp +++ b/host/lib/usrp/x300/x300_clock_ctrl.cpp @@ -303,9 +303,8 @@ public: //be close to what the client requested. } - UHD_LOGV(often) - << boost::format("x300_clock_ctrl::set_clock_delay: Which=%d, Requested=%f, Digital Taps=%d, Half Shift=%d, Analog Delay=%d (%s), Coerced Delay=%fns" - ) % which % delay_ns % ddly_value % (half_shift_en?"ON":"OFF") % ((int)adly_value) % (adly_en?"ON":"OFF") % coerced_delay << std::endl; + UHD_LOG_DEBUG("X300", boost::format("x300_clock_ctrl::set_clock_delay: Which=%d, Requested=%f, Digital Taps=%d, Half Shift=%d, Analog Delay=%d (%s), Coerced Delay=%fns" + ) % which % delay_ns % ddly_value % (half_shift_en?"ON":"OFF") % ((int)adly_value) % (adly_en?"ON":"OFF") % coerced_delay) //Apply settings switch (which) diff --git a/host/lib/usrp/x300/x300_dac_ctrl.cpp b/host/lib/usrp/x300/x300_dac_ctrl.cpp index 162eeb143..51b93662c 100644 --- a/host/lib/usrp/x300/x300_dac_ctrl.cpp +++ b/host/lib/usrp/x300/x300_dac_ctrl.cpp @@ -18,11 +18,10 @@ #include "x300_dac_ctrl.hpp" #include "x300_regs.hpp" #include <uhd/types/time_spec.hpp> -#include <uhd/utils/msg.hpp> #include <uhd/utils/log.hpp> #include <uhd/utils/safe_call.hpp> #include <uhd/exception.hpp> -#include <boost/foreach.hpp> +#include <boost/format.hpp> #include <boost/thread/thread.hpp> //sleep #define X300_DAC_FRONTEND_SYNC_FAILURE_FATAL @@ -243,7 +242,7 @@ public: if (failure_is_fatal) { throw uhd::runtime_error(msg); } else { - UHD_MSG(warning) << msg; + UHD_LOGGER_WARNING("X300") << msg; } } } diff --git a/host/lib/usrp/x300/x300_dboard_iface.cpp b/host/lib/usrp/x300/x300_dboard_iface.cpp index 092c888b0..e492fe2b3 100644 --- a/host/lib/usrp/x300/x300_dboard_iface.cpp +++ b/host/lib/usrp/x300/x300_dboard_iface.cpp @@ -34,7 +34,7 @@ x300_dboard_iface::x300_dboard_iface(const x300_dboard_iface_config_t &config): //reset the aux dacs _dac_regs[UNIT_RX] = ad5623_regs_t(); _dac_regs[UNIT_TX] = ad5623_regs_t(); - BOOST_FOREACH(unit_t unit, _dac_regs.keys()) + for(unit_t unit: _dac_regs.keys()) { _dac_regs[unit].data = 1; _dac_regs[unit].addr = ad5623_regs_t::ADDR_ALL; diff --git a/host/lib/usrp/x300/x300_fw_ctrl.cpp b/host/lib/usrp/x300/x300_fw_ctrl.cpp index d149dadf3..5ff40c966 100644 --- a/host/lib/usrp/x300/x300_fw_ctrl.cpp +++ b/host/lib/usrp/x300/x300_fw_ctrl.cpp @@ -19,7 +19,7 @@ #include "x300_fw_common.h" #include <uhd/transport/udp_simple.hpp> #include <uhd/utils/byteswap.hpp> -#include <uhd/utils/msg.hpp> +#include <uhd/utils/log.hpp> #include <uhd/exception.hpp> #include <boost/format.hpp> #include <boost/thread/mutex.hpp> @@ -61,7 +61,7 @@ public: { std::string error_msg = str(boost::format( "x300 fw communication failure #%u\n%s") % i % ex.what()); - if (errors) UHD_MSG(error) << error_msg << std::endl; + if (errors) UHD_LOGGER_ERROR("X300") << error_msg ; if (i == num_retries) throw uhd::io_error(error_msg); } } @@ -81,7 +81,7 @@ public: { std::string error_msg = str(boost::format( "x300 fw communication failure #%u\n%s") % i % ex.what()); - if (errors) UHD_MSG(error) << error_msg << std::endl; + if (errors) UHD_LOGGER_ERROR("X300") << error_msg ; if (i == num_retries) throw uhd::io_error(error_msg); } } diff --git a/host/lib/usrp/x300/x300_fw_uart.cpp b/host/lib/usrp/x300/x300_fw_uart.cpp index a2cbcc908..83a564997 100644 --- a/host/lib/usrp/x300/x300_fw_uart.cpp +++ b/host/lib/usrp/x300/x300_fw_uart.cpp @@ -18,11 +18,10 @@ #include "x300_impl.hpp" #include <uhd/types/wb_iface.hpp> #include "x300_regs.hpp" -#include <uhd/utils/msg.hpp> +#include <uhd/utils/log.hpp> #include <uhd/types/serial.hpp> #include <uhd/exception.hpp> #include <boost/format.hpp> -#include <boost/foreach.hpp> #include <boost/thread/thread.hpp> using namespace uhd; @@ -65,7 +64,7 @@ struct x300_uart_iface : uart_iface void write_uart(const std::string &buff) { boost::mutex::scoped_lock(_write_mutex); - BOOST_FOREACH(const char ch, buff) + for(const char ch: buff) { this->putchar(ch); } diff --git a/host/lib/usrp/x300/x300_image_loader.cpp b/host/lib/usrp/x300/x300_image_loader.cpp index f08b21f9b..e8c2a1329 100644 --- a/host/lib/usrp/x300/x300_image_loader.cpp +++ b/host/lib/usrp/x300/x300_image_loader.cpp @@ -167,7 +167,7 @@ static void x300_setup_session(x300_session_t &session, std::string err_msg = "Could not resolve given args to a single X-Series device.\n" "Applicable devices:\n"; - BOOST_FOREACH(const uhd::device_addr_t &dev, devs){ + for(const uhd::device_addr_t &dev: devs){ std::string identifier = dev.has_key("addr") ? "addr" : "resource"; diff --git a/host/lib/usrp/x300/x300_impl.cpp b/host/lib/usrp/x300/x300_impl.cpp index 4f3870357..08865f9a6 100644 --- a/host/lib/usrp/x300/x300_impl.cpp +++ b/host/lib/usrp/x300/x300_impl.cpp @@ -23,12 +23,11 @@ #include <boost/algorithm/string.hpp> #include <boost/asio.hpp> #include <uhd/utils/static.hpp> -#include <uhd/utils/msg.hpp> +#include <uhd/utils/log.hpp> #include <uhd/utils/paths.hpp> #include <uhd/utils/safe_call.hpp> #include <uhd/usrp/subdev_spec.hpp> #include <uhd/transport/if_addrs.hpp> -#include <boost/foreach.hpp> #include <boost/bind.hpp> #include <boost/make_shared.hpp> #include <boost/functional/hash.hpp> @@ -183,7 +182,7 @@ static device_addrs_t x300_find_pcie(const device_addr_t &hint, bool explicit_qu nirio_status status = niusrprio_session::enumerate(rpc_port_name, dev_info_vtr); if (explicit_query) nirio_status_to_exception(status, "x300_find_pcie: Error enumerating NI-RIO devices."); - BOOST_FOREACH(niusrprio_session::device_info &dev_info, dev_info_vtr) + for(niusrprio_session::device_info &dev_info: dev_info_vtr) { device_addr_t new_addr; new_addr["type"] = "x300"; @@ -278,7 +277,7 @@ device_addrs_t x300_find(const device_addr_t &hint_) { device_addrs_t found_devices; std::string error_msg; - BOOST_FOREACH(const device_addr_t &hint_i, hints) + for(const device_addr_t &hint_i: hints) { device_addrs_t found_devices_i = x300_find(hint_i); if (found_devices_i.size() != 1) error_msg += str(boost::format( @@ -310,11 +309,11 @@ device_addrs_t x300_find(const device_addr_t &hint_) } catch(const std::exception &ex) { - UHD_MSG(error) << "X300 Network discovery error " << ex.what() << std::endl; + UHD_LOGGER_ERROR("X300") << "X300 Network discovery error " << ex.what() ; } catch(...) { - UHD_MSG(error) << "X300 Network discovery unknown error " << std::endl; + UHD_LOGGER_ERROR("X300") << "X300 Network discovery unknown error " ; } return reply_addrs; } @@ -322,7 +321,7 @@ device_addrs_t x300_find(const device_addr_t &hint_) if (!hint.has_key("resource")) { //otherwise, no address was specified, send a broadcast on each interface - BOOST_FOREACH(const if_addrs_t &if_addrs, get_if_addrs()) + for(const if_addrs_t &if_addrs: get_if_addrs()) { //avoid the loopback device if (if_addrs.inet == asio::ip::address_v4::loopback().to_string()) continue; @@ -358,7 +357,7 @@ UHD_STATIC_BLOCK(register_x300_device) static void x300_load_fw(wb_iface::sptr fw_reg_ctrl, const std::string &file_name) { - UHD_MSG(status) << "Loading firmware " << file_name << std::flush; + UHD_LOGGER_INFO("X300") << "Loading firmware " << file_name; //load file into memory std::ifstream fw_file(file_name.c_str()); @@ -373,28 +372,52 @@ static void x300_load_fw(wb_iface::sptr fw_reg_ctrl, const std::string &file_nam //@TODO: FIXME: Since x300_ctrl_iface acks each write and traps exceptions, the first try for the last word // written will print an error because it triggers a FW reload and fails to reply. fw_reg_ctrl->poke32(SR_ADDR(BOOT_LDR_BASE, BL_DATA), uhd::byteswap(fw_file_buff[i/sizeof(uint32_t)])); - if ((i & 0x1fff) == 0) UHD_MSG(status) << "." << std::flush; } //Wait for fimrware to reboot. 3s is an upper bound boost::this_thread::sleep(boost::posix_time::milliseconds(3000)); - UHD_MSG(status) << " done!" << std::endl; + UHD_LOGGER_INFO("X300") << "Firmware loaded!" ; } -x300_impl::x300_impl(const uhd::device_addr_t &dev_addr) +x300_impl::x300_impl(const uhd::device_addr_t &dev_addr) : device3_impl() , _sid_framer(0) { - UHD_MSG(status) << "X300 initialization sequence..." << std::endl; + UHD_LOGGER_INFO("X300") << "X300 initialization sequence..."; _ignore_cal_file = dev_addr.has_key("ignore-cal-file"); _tree->create<std::string>("/name").set("X-Series Device"); const device_addrs_t device_args = separate_device_addr(dev_addr); _mb.resize(device_args.size()); - for (size_t i = 0; i < device_args.size(); i++) + + // Serialize the initialization process + if (dev_addr.has_key("serialize_init") or device_args.size() == 1) { + for (size_t i = 0; i < device_args.size(); i++) + { + this->setup_mb(i, device_args[i]); + } + return; + } + + + // Initialize groups of USRPs in parallel + size_t total_usrps = device_args.size(); + size_t num_usrps = 0; + while (num_usrps < total_usrps) { - this->setup_mb(i, device_args[i]); + size_t init_usrps = std::min(total_usrps - num_usrps, X300_MAX_INIT_THREADS); + boost::thread_group setup_threads; + for (size_t i = 0; i < init_usrps; i++) + { + size_t index = num_usrps + i; + setup_threads.create_thread( + boost::bind(&x300_impl::setup_mb, this, index, device_args[index]) + ); + } + setup_threads.join_all(); + num_usrps += init_usrps; } + } void x300_impl::mboard_members_t::discover_eth( @@ -412,15 +435,15 @@ void x300_impl::mboard_members_t::discover_eth( // Show a warning if there exists duplicate addresses in the mboard eeprom if (std::find(mb_eeprom_addrs.begin(), mb_eeprom_addrs.end(), mb_eeprom[key]) != mb_eeprom_addrs.end()) { - UHD_MSG(warning) << str(boost::format( + UHD_LOGGER_WARNING("X300") << str(boost::format( "Duplicate IP address %s found in mboard EEPROM. " "Device may not function properly.\nView and reprogram the values " - "using the usrp_burn_mb_eeprom utility.\n") % mb_eeprom[key]); + "using the usrp_burn_mb_eeprom utility.") % mb_eeprom[key]); } mb_eeprom_addrs.push_back(mb_eeprom[key]); } - BOOST_FOREACH(const std::string& addr, ip_addrs) { + for(const std::string& addr: ip_addrs) { x300_eth_conn_t conn_iface; conn_iface.addr = addr; conn_iface.type = X300_IFACE_NONE; @@ -442,7 +465,7 @@ void x300_impl::mboard_members_t::discover_eth( // Check default IP addresses if we couldn't // determine the IP from the mboard eeprom if (conn_iface.type == X300_IFACE_NONE) { - UHD_MSG(warning) << str(boost::format( + UHD_LOGGER_WARNING("X300") << str(boost::format( "Address %s not found in mboard EEPROM. Address may be wrong or " "the EEPROM may be corrupt.\n Attempting to continue with default " "IP addresses.\n") % conn_iface.addr @@ -505,6 +528,14 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) mboard_members_t &mb = _mb[mb_i]; mb.initialization_done = false; + const std::string thread_id( + boost::lexical_cast<std::string>(boost::this_thread::get_id()) + ); + const std::string thread_msg( + "Thread ID " + thread_id + " for motherboard " + + boost::lexical_cast<std::string>(mb_i) + ); + std::vector<std::string> eth_addrs; // Not choosing eth0 based on resource might cause user issues std::string eth0_addr = dev_addr.has_key("resource") ? dev_addr["resource"] : dev_addr["addr"]; @@ -536,7 +567,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) if (dev_addr.has_key("niusrpriorpc_port")) { rpc_port_name = dev_addr["niusrpriorpc_port"]; } - UHD_MSG(status) << boost::format("Connecting to niusrpriorpc at localhost:%s...\n") % rpc_port_name; + UHD_LOGGER_INFO("X300") << boost::format("Connecting to niusrpriorpc at localhost:%s...") % rpc_port_name; //Instantiate the correct lvbitx object nifpga_lvbitx::sptr lvbitx; @@ -553,7 +584,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) drivers have loaded successfully."); } //Load the lvbitx onto the device - UHD_MSG(status) << boost::format("Using LVBITX bitfile %s...\n") % lvbitx->get_bitfile_path(); + UHD_LOGGER_INFO("X300") << boost::format("Using LVBITX bitfile %s...") % lvbitx->get_bitfile_path(); mb.rio_fpga_interface.reset(new niusrprio_session(dev_addr["resource"], rpc_port_name)); nirio_status_chain(mb.rio_fpga_interface->open(lvbitx, dev_addr.has_key("download-fpga")), status); nirio_status_to_exception(status, "x300_impl: Could not initialize RIO session."); @@ -567,7 +598,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) _tree->create<double>(mb_path / "link_max_rate").set(X300_MAX_RATE_PCIE); } - BOOST_FOREACH(const std::string &key, dev_addr.keys()) + for(const std::string &key: dev_addr.keys()) { if (key.find("recv") != std::string::npos) mb.recv_args[key] = dev_addr[key]; if (key.find("send") != std::string::npos) mb.send_args[key] = dev_addr[key]; @@ -626,33 +657,33 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) ); } } catch(std::exception &e) { - UHD_MSG(error) << e.what() << std::endl; + UHD_LOGGER_ERROR("X300") << e.what() ; } if ((mb.recv_args.has_key("recv_frame_size")) && (req_max_frame_size.recv_frame_size > _max_frame_sizes.recv_frame_size)) { - UHD_MSG(warning) + UHD_LOGGER_WARNING("X300") << boost::format("You requested a receive frame size of (%lu) but your NIC's max frame size is (%lu).") % req_max_frame_size.recv_frame_size % _max_frame_sizes.recv_frame_size - << std::endl + << boost::format("Please verify your NIC's MTU setting using '%s' or set the recv_frame_size argument appropriately.") - % mtu_tool << std::endl + % mtu_tool << "UHD will use the auto-detected max frame size for this connection." - << std::endl; + ; } if ((mb.recv_args.has_key("send_frame_size")) && (req_max_frame_size.send_frame_size > _max_frame_sizes.send_frame_size)) { - UHD_MSG(warning) + UHD_LOGGER_WARNING("X300") << boost::format("You requested a send frame size of (%lu) but your NIC's max frame size is (%lu).") % req_max_frame_size.send_frame_size % _max_frame_sizes.send_frame_size - << std::endl + << boost::format("Please verify your NIC's MTU setting using '%s' or set the send_frame_size argument appropriately.") - % mtu_tool << std::endl + % mtu_tool << "UHD will use the auto-detected max frame size for this connection." - << std::endl; + ; } _tree->create<size_t>(mb_path / "mtu/recv").set(_max_frame_sizes.recv_frame_size); @@ -661,7 +692,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) } //create basic communication - UHD_MSG(status) << "Setup basic communication..." << std::endl; + UHD_LOGGER_INFO("X300") << "Setup basic communication..."; if (mb.xport_path == "nirio") { boost::mutex::scoped_lock(pcie_zpu_iface_registry_mutex); if (get_pcie_zpu_iface_registry().has_key(mb.get_pri_eth().addr)) { @@ -721,11 +752,10 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) const uint32_t nbor_addr = mb.zpu_ctrl->peek32(SR_ADDR(routes_addr, i*2+1)); if (node_addr != 0 and nbor_addr != 0) { - UHD_MSG(status) << boost::format("%u: %s -> %s") + UHD_LOGGER_INFO("X300") << boost::format("%u: %s -> %s") % i % asio::ip::address_v4(node_addr).to_string() - % asio::ip::address_v4(nbor_addr).to_string() - << std::endl; + % asio::ip::address_v4(nbor_addr).to_string(); } } */ @@ -733,11 +763,11 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) //////////////////////////////////////////////////////////////////// // setup the mboard eeprom //////////////////////////////////////////////////////////////////// - UHD_MSG(status) << "Loading values from EEPROM..." << std::endl; + UHD_LOGGER_INFO("X300") << "Loading values from EEPROM..."; x300_mb_eeprom_iface::sptr eeprom16 = x300_mb_eeprom_iface::make(mb.zpu_ctrl, mb.zpu_i2c); if (dev_addr.has_key("blank_eeprom")) { - UHD_MSG(warning) << "Obliterating the motherboard EEPROM..." << std::endl; + UHD_LOGGER_WARNING("X300") << "Obliterating the motherboard EEPROM..." ; eeprom16->write_eeprom(0x50, 0, byte_vector_t(256, 0xff)); } const mboard_eeprom_t mb_eeprom(*eeprom16, "X300"); @@ -747,9 +777,9 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) bool recover_mb_eeprom = dev_addr.has_key("recover_mb_eeprom"); if (recover_mb_eeprom) { - UHD_MSG(warning) << "UHD is operating in EEPROM Recovery Mode which disables hardware version " + UHD_LOGGER_WARNING("X300") << "UHD is operating in EEPROM Recovery Mode which disables hardware version " "checks.\nOperating in this mode may cause hardware damage and unstable " - "radio performance!"<< std::endl; + "radio performance!"; } //////////////////////////////////////////////////////////////////// @@ -829,7 +859,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) //////////////////////////////////////////////////////////////////// // create clock control objects //////////////////////////////////////////////////////////////////// - UHD_MSG(status) << "Setup RF frontend clocking..." << std::endl; + UHD_LOGGER_INFO("X300") << "Setup RF frontend clocking..."; //Initialize clock control registers. NOTE: This does not configure the LMK yet. mb.clock = x300_clock_ctrl::make(mb.zpu_spi, @@ -851,8 +881,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) .set_publisher(boost::bind(&x300_clock_ctrl::get_master_clock_rate, mb.clock)) ; - UHD_MSG(status) << "Radio 1x clock:" << (mb.clock->get_master_clock_rate()/1e6) - << std::endl; + UHD_LOGGER_INFO("X300") << "Radio 1x clock:" << (mb.clock->get_master_clock_rate()/1e6); //////////////////////////////////////////////////////////////////// // Create the GPSDO control @@ -862,18 +891,18 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) //otherwise if not disabled, look for the internal GPSDO if (mb.zpu_ctrl->peek32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_GPSDO_STATUS)) != dont_look_for_gpsdo) { - UHD_MSG(status) << "Detecting internal GPSDO.... " << std::flush; + UHD_LOGGER_INFO("X300") << "Detecting internal GPSDO.... "; try { mb.gps = gps_ctrl::make(x300_make_uart_iface(mb.zpu_ctrl)); } catch(std::exception &e) { - UHD_MSG(error) << "An error occurred making GPSDO control: " << e.what() << std::endl; + UHD_LOGGER_ERROR("X300") << "An error occurred making GPSDO control: " << e.what() ; } if (mb.gps and mb.gps->gps_detected()) { - BOOST_FOREACH(const std::string &name, mb.gps->get_sensors()) + for(const std::string &name: mb.gps->get_sensors()) { _tree->create<sensor_value_t>(mb_path / "sensors" / name) .set_publisher(boost::bind(&gps_ctrl::get_sensor, mb.gps, name)); @@ -886,14 +915,6 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) } //////////////////////////////////////////////////////////////////// - //clear router? - //////////////////////////////////////////////////////////////////// - for (size_t i = 0; i < 512; i++) { - mb.zpu_ctrl->poke32(SR_ADDR(SETXB_BASE, i), 0); - } - - - //////////////////////////////////////////////////////////////////// // setup time sources and properties //////////////////////////////////////////////////////////////////// _tree->create<std::string>(mb_path / "time_source" / "value") @@ -950,8 +971,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) n_rfnoc_blocks, X300_XB_DST_PCI + 1, /* base port */ uhd::sid_t(X300_SRC_ADDR0, 0, X300_DST_ADDR + mb_i, 0), - dev_addr, - mb.if_pkt_is_big_endian ? ENDIANNESS_BIG : ENDIANNESS_LITTLE + dev_addr ); //////////////// RFNOC ///////////////// @@ -961,11 +981,11 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) find_blocks<rfnoc::x300_radio_ctrl_impl>(radio_blockid_hint); if (not radio_ids.empty()) { if (radio_ids.size() > 2) { - UHD_MSG(warning) << "Too many Radio Blocks found. Using only the first two." << std::endl; + UHD_LOGGER_WARNING("X300") << "Too many Radio Blocks found. Using only the first two." ; radio_ids.resize(2); } - BOOST_FOREACH(const rfnoc::block_id_t &id, radio_ids) { + for(const rfnoc::block_id_t &id: radio_ids) { rfnoc::x300_radio_ctrl_impl::sptr radio(get_block_ctrl<rfnoc::x300_radio_ctrl_impl>(id)); mb.radios.push_back(radio); radio->setup_radio( @@ -1003,7 +1023,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) } } else { - UHD_MSG(status) << "No Radio Block found. Assuming radio-less operation." << std::endl; + UHD_LOGGER_INFO("X300") << "No Radio Block found. Assuming radio-less operation."; } /* end of radio block(s) initialization */ mb.initialization_done = true; @@ -1013,7 +1033,7 @@ x300_impl::~x300_impl(void) { try { - BOOST_FOREACH(mboard_members_t &mb, _mb) + for(mboard_members_t &mb: _mb) { //kill the claimer task and unclaim the device mb.claimer_task.reset(); @@ -1046,8 +1066,8 @@ uint32_t x300_impl::mboard_members_t::allocate_pcie_dma_chan(const uhd::sid_t &t if (_dma_chan_pool.count(raw_sid) == 0) { _dma_chan_pool[raw_sid] = _dma_chan_pool.size() + FIRST_DATA_CHANNEL; - UHD_LOG << "[X300] Assigning PCIe DMA channel " << _dma_chan_pool[raw_sid] - << " to SID " << tx_sid.to_pp_string_hex() << std::endl; + UHD_LOGGER_DEBUG("X300") << "[X300] Assigning PCIe DMA channel " << _dma_chan_pool[raw_sid] + << " to SID " << tx_sid.to_pp_string_hex() ; } if (_dma_chan_pool.size() + FIRST_DATA_CHANNEL > X300_PCIE_MAX_CHANNELS) { @@ -1072,6 +1092,7 @@ uhd::both_xports_t x300_impl::make_transport( zero_copy_xport_params default_buff_args; both_xports_t xports; + xports.endianness = mb.if_pkt_is_big_endian ? ENDIANNESS_BIG : ENDIANNESS_LITTLE; if (mb.xport_path == "nirio") { xports.send_sid = this->allocate_sid(mb, address, X300_SRC_ADDR0, X300_XB_DST_PCI); xports.recv_sid = xports.send_sid.reversed(); @@ -1181,23 +1202,23 @@ uhd::both_xports_t x300_impl::make_transport( /* Print a warning if the system's max available frame size is less than the most optimal * frame size for this type of connection. */ if (_max_frame_sizes.send_frame_size < eth_data_rec_frame_size) { - UHD_MSG(warning) + UHD_LOGGER_WARNING("X300") << boost::format("For this connection, UHD recommends a send frame size of at least %lu for best\nperformance, but your system's MTU will only allow %lu.") % eth_data_rec_frame_size % _max_frame_sizes.send_frame_size - << std::endl + << "This will negatively impact your maximum achievable sample rate." - << std::endl; + ; } if (_max_frame_sizes.recv_frame_size < eth_data_rec_frame_size) { - UHD_MSG(warning) + UHD_LOGGER_WARNING("X300") << boost::format("For this connection, UHD recommends a receive frame size of at least %lu for best\nperformance, but your system's MTU will only allow %lu.") % eth_data_rec_frame_size % _max_frame_sizes.recv_frame_size - << std::endl + << "This will negatively impact your maximum achievable sample rate." - << std::endl; + ; } size_t system_max_send_frame_size = (size_t) _max_frame_sizes.send_frame_size; @@ -1255,8 +1276,8 @@ uhd::both_xports_t x300_impl::make_transport( //send a mini packet with SID into the ZPU //ZPU will reprogram the ethernet framer - UHD_LOG << "programming packet for new xport on " - << interface_addr << " sid " << xports.send_sid << std::endl; + UHD_LOGGER_DEBUG("X300") << "programming packet for new xport on " + << interface_addr << " sid " << xports.send_sid ; //YES, get a __send__ buffer from the __recv__ socket //-- this is the only way to program the framer for recv: managed_send_buffer::sptr buff = xports.recv->get_send_buff(); @@ -1266,7 +1287,7 @@ uhd::both_xports_t x300_impl::make_transport( buff.reset(); //reprogram the ethernet dispatcher's udp port (should be safe to always set) - UHD_LOG << "reprogram the ethernet dispatcher's udp port" << std::endl; + UHD_LOGGER_DEBUG("X300") << "reprogram the ethernet dispatcher's udp port" ; mb.zpu_ctrl->poke32(SR_ADDR(SET0_BASE, (ZPU_SR_ETHINT0+8+3)), X300_VITA_UDP_PORT); mb.zpu_ctrl->poke32(SR_ADDR(SET0_BASE, (ZPU_SR_ETHINT1+8+3)), X300_VITA_UDP_PORT); @@ -1286,7 +1307,7 @@ uhd::sid_t x300_impl::allocate_sid( ) { uhd::sid_t sid = address; sid.set_src_addr(src_addr); - sid.set_src_endpoint(_sid_framer); + sid.set_src_endpoint(_sid_framer++); //increment for next setup // TODO Move all of this setup_mb() // Program the X300 to recognise it's own local address. @@ -1298,10 +1319,7 @@ uhd::sid_t x300_impl::allocate_sid( // This type of packet does not match the XB_LOCAL address and is looked up in the lower half of the CAM mb.zpu_ctrl->poke32(SR_ADDR(SETXB_BASE, 0 + src_addr), src_dst); - UHD_LOG << "done router config for sid " << sid << std::endl; - - //increment for next setup - _sid_framer++; + UHD_LOGGER_TRACE("X300") << "done router config for sid " << sid ; return sid; } @@ -1355,8 +1373,8 @@ void x300_impl::update_clock_source(mboard_members_t &mb, const std::string &sou throw uhd::runtime_error((boost::format("Reference Clock PLL failed to lock to %s source.") % source).str()); } else { //TODO: Re-enable this warning when we figure out a reliable lock time - //UHD_MSG(warning) << "Reference clock failed to lock to " + source + " during device initialization. " << - // "Check for the lock before operation or ignore this warning if using another clock source." << std::endl; + //UHD_LOGGER_WARNING("X300") << "Reference clock failed to lock to " + source + " during device initialization. " << + // "Check for the lock before operation or ignore this warning if using another clock source." ; } } } @@ -1381,7 +1399,7 @@ void x300_impl::update_clock_source(mboard_members_t &mb, const std::string &sou } // Reset ADCs and DACs - BOOST_FOREACH(rfnoc::x300_radio_ctrl_impl::sptr r, mb.radios) { + for(rfnoc::x300_radio_ctrl_impl::sptr r: mb.radios) { r->reset_codec(); } } @@ -1413,7 +1431,7 @@ void x300_impl::update_time_source(mboard_members_t &mb, const std::string &sour void x300_impl::sync_times(mboard_members_t &mb, const uhd::time_spec_t& t) { std::vector<rfnoc::block_id_t> radio_ids = find_blocks<rfnoc::x300_radio_ctrl_impl>("Radio"); - BOOST_FOREACH(const rfnoc::block_id_t &id, radio_ids) { + for(const rfnoc::block_id_t &id: radio_ids) { get_block_ctrl<rfnoc::x300_radio_ctrl_impl>(id)->set_time_sync(t); } @@ -1574,7 +1592,7 @@ x300_impl::frame_size_t x300_impl::determine_max_frame_size(const std::string &a size_t min_send_frame_size = sizeof(x300_mtu_t); size_t max_send_frame_size = std::min(user_frame_size.send_frame_size, X300_10GE_DATA_FRAME_MAX_SIZE) & size_t(~3); - UHD_MSG(status) << "Determining maximum frame size... "; + UHD_LOGGER_INFO("X300") << "Determining maximum frame size... "; while (min_recv_frame_size < max_recv_frame_size) { size_t test_frame_size = (max_recv_frame_size/2 + min_recv_frame_size/2 + 3) & ~3; @@ -1623,7 +1641,7 @@ x300_impl::frame_size_t x300_impl::determine_max_frame_size(const std::string &a // of the recv and send frame sizes. frame_size.recv_frame_size = std::min(min_recv_frame_size, min_send_frame_size); frame_size.send_frame_size = std::min(min_recv_frame_size, min_send_frame_size); - UHD_MSG(status) << frame_size.send_frame_size << " bytes." << std::endl; + UHD_LOGGER_INFO("X300") << "Maximum frame size: " << frame_size.send_frame_size << " bytes."; return frame_size; } @@ -1800,7 +1818,7 @@ x300_impl::x300_mboard_t x300_impl::get_mb_type_from_eeprom(const uhd::usrp::mbo case X310_2955R_PCIE_SSID_ADC_18: mb_type = USRP_X310_MB; break; default: - UHD_MSG(warning) << "X300 unknown product code in EEPROM: " << product_num << std::endl; + UHD_LOGGER_WARNING("X300") << "X300 unknown product code in EEPROM: " << product_num ; mb_type = UNKNOWN; break; } } diff --git a/host/lib/usrp/x300/x300_impl.hpp b/host/lib/usrp/x300/x300_impl.hpp index 14120bd1f..27f3f130e 100644 --- a/host/lib/usrp/x300/x300_impl.hpp +++ b/host/lib/usrp/x300/x300_impl.hpp @@ -39,6 +39,7 @@ #include <uhd/rfnoc/block_ctrl.hpp> ///////////// RFNOC ///////////////////// #include <boost/dynamic_bitset.hpp> +#include <atomic> static const std::string X300_FW_FILE_NAME = "usrp_x300_fw.bin"; static const std::string X300_DEFAULT_CLOCK_SOURCE = "internal"; @@ -76,6 +77,9 @@ static const size_t X300_ETH_MSG_NUM_FRAMES = 64; static const size_t X300_ETH_DATA_NUM_FRAMES = 32; static const double X300_DEFAULT_SYSREF_RATE = 10e6; +// Limit the number of initialization threads +static const size_t X300_MAX_INIT_THREADS = 10; + static const size_t X300_MAX_RATE_PCIE = 800000000; // bytes/s static const size_t X300_MAX_RATE_10GIGE = (size_t)( // bytes/s 10e9 / 8 * // wire speed multiplied by percentage of packets that is sample data @@ -215,7 +219,7 @@ private: //task for periodically reclaiming the device from others void claimer_loop(uhd::wb_iface::sptr); - size_t _sid_framer; + std::atomic<size_t> _sid_framer; uhd::sid_t allocate_sid( mboard_members_t &mb, @@ -286,9 +290,6 @@ private: /// More IO stuff uhd::device_addr_t get_tx_hints(size_t mb_index); uhd::device_addr_t get_rx_hints(size_t mb_index); - uhd::endianness_t get_transport_endianness(size_t mb_index) { - return _mb[mb_index].if_pkt_is_big_endian ? uhd::ENDIANNESS_BIG : uhd::ENDIANNESS_LITTLE; - }; void post_streamer_hooks(uhd::direction_t dir); }; diff --git a/host/lib/usrp/x300/x300_io_impl.cpp b/host/lib/usrp/x300/x300_io_impl.cpp index 1584cee24..eeff4091f 100644 --- a/host/lib/usrp/x300/x300_io_impl.cpp +++ b/host/lib/usrp/x300/x300_io_impl.cpp @@ -25,8 +25,6 @@ #include <boost/bind.hpp> #include <uhd/utils/tasks.hpp> #include <uhd/utils/log.hpp> -#include <uhd/utils/msg.hpp> -#include <boost/foreach.hpp> #include <boost/make_shared.hpp> using namespace uhd; @@ -73,7 +71,7 @@ void x300_impl::post_streamer_hooks(direction_t dir) // Loop through all tx streamers. Find all radios connected to one // streamer. Sync those. - BOOST_FOREACH(const boost::weak_ptr<uhd::tx_streamer> &streamer_w, _tx_streamers.vals()) { + for(const boost::weak_ptr<uhd::tx_streamer> &streamer_w: _tx_streamers.vals()) { const boost::shared_ptr<sph::send_packet_streamer> streamer = boost::dynamic_pointer_cast<sph::send_packet_streamer>(streamer_w.lock()); if (not streamer) { @@ -83,7 +81,7 @@ void x300_impl::post_streamer_hooks(direction_t dir) std::vector<rfnoc::x300_radio_ctrl_impl::sptr> radio_ctrl_blks = streamer->get_terminator()->find_downstream_node<rfnoc::x300_radio_ctrl_impl>(); try { - //UHD_MSG(status) << "[X300] syncing " << radio_ctrl_blks.size() << " radios " << std::endl; + //UHD_LOGGER_INFO("X300") << "[X300] syncing " << radio_ctrl_blks.size() << " radios " ; rfnoc::x300_radio_ctrl_impl::synchronize_dacs(radio_ctrl_blks); } catch(const uhd::io_error &ex) { diff --git a/host/lib/usrp/x300/x300_mb_eeprom.cpp b/host/lib/usrp/x300/x300_mb_eeprom.cpp index e39b36af8..084685991 100644 --- a/host/lib/usrp/x300/x300_mb_eeprom.cpp +++ b/host/lib/usrp/x300/x300_mb_eeprom.cpp @@ -33,7 +33,7 @@ #include "x300_impl.hpp" #include <uhd/exception.hpp> #include <uhd/utils/platform.hpp> -#include <uhd/utils/msg.hpp> +#include <uhd/utils/log.hpp> #include <uhd/utils/byteswap.hpp> #include <boost/thread.hpp> diff --git a/host/lib/usrp/x300/x300_radio_ctrl_impl.cpp b/host/lib/usrp/x300/x300_radio_ctrl_impl.cpp index 69eb51f55..e98980e5c 100644 --- a/host/lib/usrp/x300/x300_radio_ctrl_impl.cpp +++ b/host/lib/usrp/x300/x300_radio_ctrl_impl.cpp @@ -22,7 +22,7 @@ #include "gpio_atr_3000.hpp" #include "apply_corrections.hpp" #include <uhd/usrp/dboard_eeprom.hpp> -#include <uhd/utils/msg.hpp> +#include <uhd/utils/log.hpp> #include <uhd/usrp/dboard_iface.hpp> #include <uhd/rfnoc/node_ctrl_base.hpp> #include <uhd/transport/chdr.hpp> @@ -44,7 +44,7 @@ static const size_t IO_MASTER_RADIO = 0; UHD_RFNOC_RADIO_BLOCK_CONSTRUCTOR(x300_radio_ctrl) , _ignore_cal_file(false) { - UHD_RFNOC_BLOCK_TRACE() << "x300_radio_ctrl_impl::ctor() " << std::endl; + UHD_RFNOC_BLOCK_TRACE() << "x300_radio_ctrl_impl::ctor() " ; //////////////////////////////////////////////////////////////////// // Set up basic info @@ -82,7 +82,7 @@ UHD_RFNOC_RADIO_BLOCK_CONSTRUCTOR(x300_radio_ctrl) if (_radio_type==PRIMARY) { _fp_gpio = gpio_atr::gpio_atr_3000::make(ctrl, regs::sr_addr(regs::FP_GPIO), regs::RB_FP_GPIO); - BOOST_FOREACH(const gpio_atr::gpio_attr_map_t::value_type attr, gpio_atr::gpio_attr_map) { + for(const gpio_atr::gpio_attr_map_t::value_type attr: gpio_atr::gpio_attr_map) { _tree->create<uint32_t>(fs_path("gpio") / "FP0" / attr.second) .set(0) .add_coerced_subscriber(boost::bind(&gpio_atr::gpio_atr_3000::set_gpio_attr, _fp_gpio, attr.first, _1)); @@ -149,7 +149,7 @@ x300_radio_ctrl_impl::~x300_radio_ctrl_impl() _tree->remove(_root_path / "rx_fe_corrections"); _tree->remove(_root_path / "tx_fe_corrections"); if (_radio_type==PRIMARY) { - BOOST_FOREACH(const gpio_atr::gpio_attr_map_t::value_type attr, gpio_atr::gpio_attr_map) { + for(const gpio_atr::gpio_attr_map_t::value_type attr: gpio_atr::gpio_attr_map) { _tree->remove(fs_path("gpio") / "FP0" / attr.second); } _tree->remove(fs_path("gpio") / "FP0" / "READBACK"); @@ -171,7 +171,7 @@ double x300_radio_ctrl_impl::set_rate(double rate) { const double actual_rate = get_rate(); if (not uhd::math::frequencies_are_equal(rate, actual_rate)) { - UHD_MSG(warning) << "[X300 Radio] Requesting invalid sampling rate from device: " << rate/1e6 << " MHz. Actual rate is: " << actual_rate/1e6 << " MHz." << std::endl; + UHD_LOGGER_WARNING("X300 RADIO") << "Requesting invalid sampling rate from device: " << rate/1e6 << " MHz. Actual rate is: " << actual_rate/1e6 << " MHz." ; } // On X3x0, tick rate can't actually be changed at runtime return actual_rate; @@ -228,6 +228,20 @@ double x300_radio_ctrl_impl::get_rx_frequency(const size_t chan) ).get(); } +double x300_radio_ctrl_impl::set_rx_bandwidth(const double bandwidth, const size_t chan) +{ + return _tree->access<double>( + fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name / "bandwidth" / "value") + ).set(bandwidth).get(); +} + +double x300_radio_ctrl_impl::get_rx_bandwidth(const size_t chan) +{ + return _tree->access<double>( + fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name / "bandwidth" / "value") + ).get(); +} + double x300_radio_ctrl_impl::set_tx_gain(const double gain, const size_t chan) { //TODO: This is extremely hacky! @@ -238,7 +252,7 @@ double x300_radio_ctrl_impl::set_tx_gain(const double gain, const size_t chan) radio_ctrl_impl::set_tx_gain(actual_gain, chan); return gain; } else { - UHD_MSG(warning) << "set_tx_gain: could not apply gain for this daughterboard."; + UHD_LOGGER_WARNING("X300 RADIO") << "set_tx_gain: could not apply gain for this daughterboard."; radio_ctrl_impl::set_tx_gain(0.0, chan); return 0.0; } @@ -254,19 +268,209 @@ double x300_radio_ctrl_impl::set_rx_gain(const double gain, const size_t chan) radio_ctrl_impl::set_rx_gain(actual_gain, chan); return gain; } else { - UHD_MSG(warning) << "set_rx_gain: could not apply gain for this daughterboard."; + UHD_LOGGER_WARNING("X300 RADIO") << "set_rx_gain: could not apply gain for this daughterboard."; radio_ctrl_impl::set_tx_gain(0.0, chan); return 0.0; } } +std::vector<std::string> x300_radio_ctrl_impl::get_rx_lo_names(const size_t chan) +{ + fs_path rx_fe_fe_root = fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name); + + std::vector<std::string> lo_names; + if (_tree->exists(rx_fe_fe_root / "los")) { + for(const std::string &name: _tree->list(rx_fe_fe_root / "los")) { + lo_names.push_back(name); + } + } + return lo_names; +} + +std::vector<std::string> x300_radio_ctrl_impl::get_rx_lo_sources(const std::string &name, const size_t chan) +{ + fs_path rx_fe_fe_root = fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name); + + if (_tree->exists(rx_fe_fe_root / "los")) { + if (name == ALL_LOS) { + if (_tree->exists(rx_fe_fe_root / "los" / ALL_LOS)) { + //Special value ALL_LOS support atomically sets the source for all LOs + return _tree->access< std::vector<std::string> >(rx_fe_fe_root / "los" / ALL_LOS / "source" / "options").get(); + } else { + return std::vector<std::string>(); + } + } else { + if (_tree->exists(rx_fe_fe_root / "los")) { + return _tree->access< std::vector<std::string> >(rx_fe_fe_root / "los" / name / "source" / "options").get(); + } else { + throw uhd::runtime_error("Could not find LO stage " + name); + } + } + } else { + // If the daughterboard doesn't expose it's LO(s) then it can only be internal + return std::vector<std::string> (1, "internal"); + } +} + +void x300_radio_ctrl_impl::set_rx_lo_source(const std::string &src, const std::string &name, const size_t chan) +{ + fs_path rx_fe_fe_root = fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name); + + if (_tree->exists(rx_fe_fe_root / "los")) { + if (name == ALL_LOS) { + if (_tree->exists(rx_fe_fe_root / "los" / ALL_LOS)) { + //Special value ALL_LOS support atomically sets the source for all LOs + _tree->access<std::string>(rx_fe_fe_root / "los" / ALL_LOS / "source" / "value").set(src); + } else { + for(const std::string &n: _tree->list(rx_fe_fe_root / "los")) { + this->set_rx_lo_source(src, n, chan); + } + } + } else { + if (_tree->exists(rx_fe_fe_root / "los")) { + _tree->access<std::string>(rx_fe_fe_root / "los" / name / "source" / "value").set(src); + } else { + throw uhd::runtime_error("Could not find LO stage " + name); + } + } + } else { + throw uhd::runtime_error("This device does not support manual configuration of LOs"); + } +} + +const std::string x300_radio_ctrl_impl::get_rx_lo_source(const std::string &name, const size_t chan) +{ + fs_path rx_fe_fe_root = fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name); + + if (_tree->exists(rx_fe_fe_root / "los")) { + if (name == ALL_LOS) { + //Special value ALL_LOS support atomically sets the source for all LOs + return _tree->access<std::string>(rx_fe_fe_root / "los" / ALL_LOS / "source" / "value").get(); + } else { + if (_tree->exists(rx_fe_fe_root / "los")) { + return _tree->access<std::string>(rx_fe_fe_root / "los" / name / "source" / "value").get(); + } else { + throw uhd::runtime_error("Could not find LO stage " + name); + } + } + } else { + // If the daughterboard doesn't expose it's LO(s) then it can only be internal + return "internal"; + } +} + +void x300_radio_ctrl_impl::set_rx_lo_export_enabled(bool enabled, const std::string &name, const size_t chan) +{ + fs_path rx_fe_fe_root = fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name); + + if (_tree->exists(rx_fe_fe_root / "los")) { + if (name == ALL_LOS) { + if (_tree->exists(rx_fe_fe_root / "los" / ALL_LOS)) { + //Special value ALL_LOS support atomically sets the source for all LOs + _tree->access<bool>(rx_fe_fe_root / "los" / ALL_LOS / "export").set(enabled); + } else { + for(const std::string &n: _tree->list(rx_fe_fe_root / "los")) { + this->set_rx_lo_export_enabled(enabled, n, chan); + } + } + } else { + if (_tree->exists(rx_fe_fe_root / "los")) { + _tree->access<bool>(rx_fe_fe_root / "los" / name / "export").set(enabled); + } else { + throw uhd::runtime_error("Could not find LO stage " + name); + } + } + } else { + throw uhd::runtime_error("This device does not support manual configuration of LOs"); + } +} + +bool x300_radio_ctrl_impl::get_rx_lo_export_enabled(const std::string &name, const size_t chan) +{ + fs_path rx_fe_fe_root = fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name); + + if (_tree->exists(rx_fe_fe_root / "los")) { + if (name == ALL_LOS) { + //Special value ALL_LOS support atomically sets the source for all LOs + return _tree->access<bool>(rx_fe_fe_root / "los" / ALL_LOS / "export").get(); + } else { + if (_tree->exists(rx_fe_fe_root / "los")) { + return _tree->access<bool>(rx_fe_fe_root / "los" / name / "export").get(); + } else { + throw uhd::runtime_error("Could not find LO stage " + name); + } + } + } else { + // If the daughterboard doesn't expose it's LO(s), assume it cannot export + return false; + } +} + +double x300_radio_ctrl_impl::set_rx_lo_freq(double freq, const std::string &name, const size_t chan) +{ + fs_path rx_fe_fe_root = fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name); + + if (_tree->exists(rx_fe_fe_root / "los")) { + if (name == ALL_LOS) { + throw uhd::runtime_error("LO frequency must be set for each stage individually"); + } else { + if (_tree->exists(rx_fe_fe_root / "los")) { + _tree->access<double>(rx_fe_fe_root / "los" / name / "freq" / "value").set(freq); + return _tree->access<double>(rx_fe_fe_root / "los" / name / "freq" / "value").get(); + } else { + throw uhd::runtime_error("Could not find LO stage " + name); + } + } + } else { + throw uhd::runtime_error("This device does not support manual configuration of LOs"); + } +} + +double x300_radio_ctrl_impl::get_rx_lo_freq(const std::string &name, const size_t chan) +{ + fs_path rx_fe_fe_root = fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name); + + if (_tree->exists(rx_fe_fe_root / "los")) { + if (name == ALL_LOS) { + throw uhd::runtime_error("LO frequency must be retrieved for each stage individually"); + } else { + if (_tree->exists(rx_fe_fe_root / "los")) { + return _tree->access<double>(rx_fe_fe_root / "los" / name / "freq" / "value").get(); + } else { + throw uhd::runtime_error("Could not find LO stage " + name); + } + } + } else { + // Return actual RF frequency if the daughterboard doesn't expose it's LO(s) + return _tree->access<double>(rx_fe_fe_root / "freq" /" value").get(); + } +} + +freq_range_t x300_radio_ctrl_impl::get_rx_lo_freq_range(const std::string &name, const size_t chan) +{ + fs_path rx_fe_fe_root = fs_path("dboards" / _radio_slot / "rx_frontends" / _rx_fe_map.at(chan).db_fe_name); + + if (_tree->exists(rx_fe_fe_root / "los")) { + if (name == ALL_LOS) { + throw uhd::runtime_error("LO frequency range must be retrieved for each stage individually"); + } else { + if (_tree->exists(rx_fe_fe_root / "los")) { + return _tree->access<freq_range_t>(rx_fe_fe_root / "los" / name / "freq" / "range").get(); + } else { + throw uhd::runtime_error("Could not find LO stage " + name); + } + } + } else { + // Return the actual RF range if the daughterboard doesn't expose it's LO(s) + return _tree->access<meta_range_t>(rx_fe_fe_root / "freq" / "range").get(); + } +} + template <typename map_type> static size_t _get_chan_from_map(std::map<size_t, map_type> map, const std::string &fe) { - // TODO replace with 'auto' when possible - typedef typename std::map<size_t, map_type>::iterator chan_iterator; - for (chan_iterator it = map.begin(); it != map.end(); ++it) { + for (auto it = map.begin(); it != map.end(); ++it) { if (it->second.db_fe_name == fe) { return it->first; } @@ -380,7 +584,7 @@ void x300_radio_ctrl_impl::setup_radio( ); size_t rx_chan = 0, tx_chan = 0; - BOOST_FOREACH(const std::string& fe, _db_manager->get_rx_frontends()) { + for(const std::string& fe: _db_manager->get_rx_frontends()) { if (rx_chan >= _get_num_radios()) { break; } @@ -393,7 +597,7 @@ void x300_radio_ctrl_impl::setup_radio( _rx_fe_map[rx_chan].core->set_fe_connection(usrp::fe_connection_t(conn, if_freq)); rx_chan++; } - BOOST_FOREACH(const std::string& fe, _db_manager->get_tx_frontends()) { + for(const std::string& fe: _db_manager->get_tx_frontends()) { if (tx_chan >= _get_num_radios()) { break; } @@ -555,31 +759,26 @@ void x300_radio_ctrl_impl::self_test_adc(uint32_t ramp_time_ms) void x300_radio_ctrl_impl::extended_adc_test(const std::vector<x300_radio_ctrl_impl::sptr>& radios, double duration_s) { static const size_t SECS_PER_ITER = 5; - UHD_MSG(status) << boost::format("Running Extended ADC Self-Test (Duration=%.0fs, %ds/iteration)...\n") + UHD_LOGGER_INFO("X300 RADIO") << boost::format("Running Extended ADC Self-Test (Duration=%.0fs, %ds/iteration)...") % duration_s % SECS_PER_ITER; size_t num_iters = static_cast<size_t>(ceil(duration_s/SECS_PER_ITER)); size_t num_failures = 0; for (size_t iter = 0; iter < num_iters; iter++) { - //Print date and time - boost::posix_time::time_facet *facet = new boost::posix_time::time_facet("%d-%b-%Y %H:%M:%S"); - std::ostringstream time_strm; - time_strm.imbue(std::locale(std::locale::classic(), facet)); - time_strm << boost::posix_time::second_clock::local_time(); //Run self-test - UHD_MSG(status) << boost::format("-- [%s] Iteration %06d... ") % time_strm.str() % (iter+1); + UHD_LOGGER_INFO("X300 RADIO") << boost::format("Extended ADC Self-Test Iteration %06d... ") % (iter+1); try { for (size_t i = 0; i < radios.size(); i++) { radios[i]->self_test_adc((SECS_PER_ITER*1000)/radios.size()); } - UHD_MSG(status) << "passed" << std::endl; + UHD_LOGGER_INFO("X300 RADIO") << boost::format("Extended ADC Self-Test Iteration %06d passed ") % (iter+1); } catch(std::exception &e) { num_failures++; - UHD_MSG(status) << e.what() << std::endl; + UHD_LOGGER_ERROR("X300 RADIO") << e.what(); } } if (num_failures == 0) { - UHD_MSG(status) << "Extended ADC Self-Test PASSED\n"; + UHD_LOGGER_INFO("X300 RADIO") << "Extended ADC Self-Test PASSED"; } else { throw uhd::runtime_error( (boost::format("Extended ADC Self-Test FAILED!!! (%d/%d failures)\n") % num_failures % num_iters).str()); @@ -639,7 +838,7 @@ double x300_radio_ctrl_impl::self_cal_adc_xfer_delay( boost::function<void(double)> wait_for_clk_locked, bool apply_delay) { - UHD_MSG(status) << "Running ADC transfer delay self-cal: " << std::flush; + UHD_LOGGER_INFO("X300 RADIO") << "Running ADC transfer delay self-cal: "; //Effective resolution of the self-cal. static const size_t NUM_DELAY_STEPS = 100; @@ -649,7 +848,6 @@ double x300_radio_ctrl_impl::self_cal_adc_xfer_delay( double delay_range = 2 * master_clk_period; double delay_incr = delay_range / NUM_DELAY_STEPS; - UHD_MSG(status) << "Measuring..." << std::flush; double cached_clk_delay = clock->get_clock_delay(X300_CLOCK_WHICH_ADC0); double fpga_clk_delay = clock->get_clock_delay(X300_CLOCK_WHICH_FPGA); @@ -695,7 +893,7 @@ double x300_radio_ctrl_impl::self_cal_adc_xfer_delay( err_code += 100; //Increment error code by 100 to indicate no lock } } - //UHD_MSG(status) << (boost::format("XferDelay=%fns, Error=%d\n") % delay % err_code); + //UHD_LOGGER_INFO("X300 RADIO") << (boost::format("XferDelay=%fns, Error=%d") % delay % err_code); results.push_back(std::pair<double,bool>(delay, err_code==0)); } @@ -747,7 +945,6 @@ double x300_radio_ctrl_impl::self_cal_adc_xfer_delay( } if (apply_delay) { - UHD_MSG(status) << "Validating..." << std::flush; //Apply delay win_center = clock->set_clock_delay(X300_CLOCK_WHICH_ADC0, win_center); //Sets ADC0 and ADC1 wait_for_clk_locked(0.1); @@ -765,7 +962,7 @@ double x300_radio_ctrl_impl::self_cal_adc_xfer_delay( radios[r]->_adc->set_test_word("normal", "normal"); radios[r]->_regs->misc_outs_reg.write(radio_regmap_t::misc_outs_reg_t::ADC_CHECKER_ENABLED, 0); } - UHD_MSG(status) << (boost::format(" done (FPGA->ADC=%.3fns%s, Window=%.3fns)\n") % + UHD_LOGGER_INFO("X300 RADIO") << (boost::format("ADC transfer delay self-cal done (FPGA->ADC=%.3fns%s, Window=%.3fns)") % (win_center-fpga_clk_delay) % (cycle_slip?" +cyc":"") % win_length); return win_center; @@ -789,7 +986,7 @@ void x300_radio_ctrl_impl::_update_atr_leds(const std::string &rx_ant, const siz void x300_radio_ctrl_impl::_self_cal_adc_capture_delay(bool print_status) { - if (print_status) UHD_MSG(status) << "Running ADC capture delay self-cal..." << std::flush; + if (print_status) UHD_LOGGER_INFO("X300 RADIO") << "Running ADC capture delay self-cal..."; static const uint32_t NUM_DELAY_STEPS = 32; //The IDELAYE2 element has 32 steps static const uint32_t NUM_RETRIES = 2; //Retry self-cal if it fails in warmup situations @@ -813,8 +1010,8 @@ void x300_radio_ctrl_impl::_self_cal_adc_capture_delay(bool print_status) //and count deviations from the expected value _regs->misc_outs_reg.write(radio_regmap_t::misc_outs_reg_t::ADC_CHECKER_ENABLED, 0); _regs->misc_outs_reg.write(radio_regmap_t::misc_outs_reg_t::ADC_CHECKER_ENABLED, 1); - //10ms @ 200MHz = 2 million samples - boost::this_thread::sleep(boost::posix_time::milliseconds(10)); + //5ms @ 200MHz = 1 million samples + boost::this_thread::sleep(boost::posix_time::milliseconds(5)); if (_regs->misc_ins_reg.read(radio_regmap_t::misc_ins_reg_t::ADC_CHECKER0_I_LOCKED)) { err_code += _regs->misc_ins_reg.get(radio_regmap_t::misc_ins_reg_t::ADC_CHECKER0_I_ERROR); } else { @@ -828,8 +1025,8 @@ void x300_radio_ctrl_impl::_self_cal_adc_capture_delay(bool print_status) //and count deviations from the expected value _regs->misc_outs_reg.write(radio_regmap_t::misc_outs_reg_t::ADC_CHECKER_ENABLED, 0); _regs->misc_outs_reg.write(radio_regmap_t::misc_outs_reg_t::ADC_CHECKER_ENABLED, 1); - //10ms @ 200MHz = 2 million samples - boost::this_thread::sleep(boost::posix_time::milliseconds(10)); + //5ms @ 200MHz = 1 million samples + boost::this_thread::sleep(boost::posix_time::milliseconds(5)); if (_regs->misc_ins_reg.read(radio_regmap_t::misc_ins_reg_t::ADC_CHECKER0_Q_LOCKED)) { err_code += _regs->misc_ins_reg.get(radio_regmap_t::misc_ins_reg_t::ADC_CHECKER0_Q_ERROR); } else { @@ -852,7 +1049,7 @@ void x300_radio_ctrl_impl::_self_cal_adc_capture_delay(bool print_status) } } } - //UHD_MSG(status) << (boost::format("CapTap=%d, Error=%d\n") % dly_tap % err_code); + //UHD_LOGGER_INFO("X300 RADIO") << (boost::format("CapTap=%d, Error=%d") % dly_tap % err_code); } //Retry the self-cal if it fails @@ -882,7 +1079,7 @@ void x300_radio_ctrl_impl::_self_cal_adc_capture_delay(bool print_status) if (print_status) { double tap_delay = (1.0e12 / _radio_clk_rate) / (2*32); //in ps - UHD_MSG(status) << boost::format(" done (Tap=%d, Window=%d, TapDelay=%.3fps, Iter=%d)\n") % ideal_tap % (win_stop-win_start) % tap_delay % iter; + UHD_LOGGER_INFO("X300 RADIO") << boost::format("ADC capture delay self-cal done (Tap=%d, Window=%d, TapDelay=%.3fps, Iter=%d)") % ideal_tap % (win_stop-win_start) % tap_delay % iter; } } @@ -916,7 +1113,7 @@ void x300_radio_ctrl_impl::_set_command_time(const time_spec_t &spec, const size ***************************************************************************/ bool x300_radio_ctrl_impl::check_radio_config() { - UHD_RFNOC_BLOCK_TRACE() << "x300_radio_ctrl_impl::check_radio_config() " << std::endl; + UHD_RFNOC_BLOCK_TRACE() << "x300_radio_ctrl_impl::check_radio_config() " ; const fs_path rx_fe_path = fs_path("dboards" / _radio_slot / "rx_frontends"); for (size_t chan = 0; chan < _get_num_radios(); chan++) { if (_tree->exists(rx_fe_path / _rx_fe_map.at(chan).db_fe_name / "enabled")) { diff --git a/host/lib/usrp/x300/x300_radio_ctrl_impl.hpp b/host/lib/usrp/x300/x300_radio_ctrl_impl.hpp index 417c88f9e..4340bcc4f 100644 --- a/host/lib/usrp/x300/x300_radio_ctrl_impl.hpp +++ b/host/lib/usrp/x300/x300_radio_ctrl_impl.hpp @@ -56,12 +56,27 @@ public: double set_tx_frequency(const double freq, const size_t chan); double set_rx_frequency(const double freq, const size_t chan); + double set_rx_bandwidth(const double bandwidth, const size_t chan); double get_tx_frequency(const size_t chan); double get_rx_frequency(const size_t chan); + double get_rx_bandwidth(const size_t chan); double set_tx_gain(const double gain, const size_t chan); double set_rx_gain(const double gain, const size_t chan); + std::vector<std::string> get_rx_lo_names(const size_t chan); + std::vector<std::string> get_rx_lo_sources(const std::string &name, const size_t chan); + freq_range_t get_rx_lo_freq_range(const std::string &name, const size_t chan); + + void set_rx_lo_source(const std::string &src, const std::string &name, const size_t chan); + const std::string get_rx_lo_source(const std::string &name, const size_t chan); + + void set_rx_lo_export_enabled(bool enabled, const std::string &name, const size_t chan); + bool get_rx_lo_export_enabled(const std::string &name, const size_t chan); + + double set_rx_lo_freq(double freq, const std::string &name, const size_t chan); + double get_rx_lo_freq(const std::string &name, const size_t chan); + size_t get_chan_from_dboard_fe(const std::string &fe, const direction_t dir); std::string get_dboard_fe_from_chan(const size_t chan, const direction_t dir); |