diff options
Diffstat (limited to 'host')
32 files changed, 761 insertions, 379 deletions
diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 28ad6b968..45d0cd940 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -210,8 +210,8 @@ UHD_INSTALL(FILES # Images download directory for utils/uhd_images_downloader.py ######################################################################## -SET(UHD_IMAGES_MD5SUM "596a2476126bb5fd792ec685d88f8365") -SET(UHD_IMAGES_DOWNLOAD_SRC "http://files.ettus.com/binaries/maint_images/archive/uhd-images_003.007.000-release.zip") +SET(UHD_IMAGES_MD5SUM "00784ebb5243b0abb15db305f557e230") +SET(UHD_IMAGES_DOWNLOAD_SRC "http://files.ettus.com/binaries/maint_images/archive/uhd-images_003.007.000-48-ge1c32905.zip") ######################################################################## # Register top level components diff --git a/host/cmake/Modules/UHDPackage.cmake b/host/cmake/Modules/UHDPackage.cmake index 44a8f3622..a98a52fc7 100644 --- a/host/cmake/Modules/UHDPackage.cmake +++ b/host/cmake/Modules/UHDPackage.cmake @@ -1,5 +1,5 @@ # -# Copyright 2010-2013 Ettus Research LLC +# Copyright 2010-2014 Ettus Research LLC # # 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 @@ -200,4 +200,7 @@ IF(MSVC) ENDIF(MSVC) ######################################################################## +IF(NOT ${CPACK_GENERATOR} STREQUAL NSIS) + SET(CPACK_SET_DESTDIR "ON") +ENDIF(NOT ${CPACK_GENERATOR} STREQUAL NSIS) INCLUDE(CPack) #include after setting vars diff --git a/host/docs/usrp_x3x0_config.rst b/host/docs/usrp_x3x0_config.rst index 9cb000275..22ef8c595 100644 --- a/host/docs/usrp_x3x0_config.rst +++ b/host/docs/usrp_x3x0_config.rst @@ -69,19 +69,20 @@ Configuring the MTU ------------------------------------- In order to achieve maximum performance, we recommend setting the MTU size to 9000 for 10 GigE and 1500 for 1 GigE. It is possible to use smaller MTUs, but this -can affect performance. With some NICs, setting the MTU too high can also cause issues, -though. To set the MTU to 9000, you can use the following command: +can affect performance. With some NICs, setting the MTU too high can also cause issues. +To set the MTU to 9000, you can use the following command: :: sudo ifconfig <interface> mtu 9000 # For 10 GigE + sudo ifconfig <interface> mtu 1500 # For 1 GigE Using these MTUs will set the frame sizes for UHD communication to 8000 and 1472, respectively. In some cases, specifying the frame size manually by adding the argument "<send/recv>_frame_size=1472" can solve issues. Note that a frame size of 1472 will limit -the available sampling rate, although this is likely not a problem issue on 1 GigE. +the available sampling rate, although this is not a problem on 1 GigE. Configuring the Firewall diff --git a/host/include/uhd/transport/nirio/nirio_driver_iface.h b/host/include/uhd/transport/nirio/nirio_driver_iface.h index 46a1146de..5b430b43d 100644 --- a/host/include/uhd/transport/nirio/nirio_driver_iface.h +++ b/host/include/uhd/transport/nirio/nirio_driver_iface.h @@ -1,5 +1,5 @@ // -// Copyright 2013 Ettus Research LLC +// Copyright 2013-2014 Ettus Research LLC // // 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 @@ -28,7 +28,7 @@ #pragma warning(disable:4201) // nonstandard extension used : nameless struct/union #include <WinIoCtl.h> #pragma warning(default:4201) -#elif defined(UHD_PLATFORM_MACOS) || defined(UHD_PLATFORM_BSD) +#elif !defined(UHD_PLATFORM_LINUX) #include <IOKit/IOKitLib.h> #endif @@ -445,10 +445,8 @@ static inline void init_syncop_out_params(nirio_syncop_out_params_t& param, void typedef int rio_dev_handle_t; #elif defined(UHD_PLATFORM_WIN32) typedef HANDLE rio_dev_handle_t; -#elif defined(UHD_PLATFORM_MACOS) || defined(UHD_PLATFORM_BSD) - typedef io_connect_t rio_dev_handle_t; #else - #error OS not supported by nirio_driver_iface. + typedef io_connect_t rio_dev_handle_t; #endif static const rio_dev_handle_t INVALID_RIO_HANDLE = ((rio_dev_handle_t)-1); @@ -492,15 +490,13 @@ static const rio_dev_handle_t INVALID_RIO_HANDLE = ((rio_dev_handle_t)-1); bool is_null() { return addr == NULL; } }; -#elif defined(UHD_PLATFORM_MACOS) || defined(UHD_PLATFORM_BSD) +#else struct rio_mmap_t { rio_mmap_t() : addr(NULL) {} void *addr; bool is_null() { return addr == NULL; } }; -#else - #error OS not supported by nirio_driver_iface. #endif nirio_status rio_open( diff --git a/host/include/uhd/transport/udp_zero_copy.hpp b/host/include/uhd/transport/udp_zero_copy.hpp index 8fb5115c2..de4721be0 100644 --- a/host/include/uhd/transport/udp_zero_copy.hpp +++ b/host/include/uhd/transport/udp_zero_copy.hpp @@ -56,6 +56,8 @@ public: * * \param addr a string representing the destination address * \param port a string representing the destination port + * \param default_buff_args Default values for frame sizes and num frames + * \param[out] buff_params_out Returns the actual buffer sizes * \param hints optional parameters to pass to the underlying transport */ static sptr make( diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp index 8bd0f4354..23117f128 100644 --- a/host/lib/transport/libusb1_base.cpp +++ b/host/lib/transport/libusb1_base.cpp @@ -21,6 +21,7 @@ #include <uhd/utils/log.hpp> #include <uhd/utils/tasks.hpp> #include <uhd/types/dict.hpp> +#include <uhd/types/serial.hpp> #include <boost/weak_ptr.hpp> #include <boost/thread/mutex.hpp> #include <boost/foreach.hpp> @@ -184,7 +185,14 @@ public: ); if (ret < 0) return ""; //on error, just return empty string - return std::string((char *)buff, ret); + std::string string_descriptor((char *)buff, ret); + byte_vector_t string_vec(string_descriptor.begin(), string_descriptor.end()); + std::string out; + BOOST_FOREACH(boost::uint8_t byte, string_vec){ + if (byte < 32 or byte > 127) return out; + out += byte; + } + return out; } private: diff --git a/host/lib/transport/nirio/CMakeLists.txt b/host/lib/transport/nirio/CMakeLists.txt index 6a33da6c5..5f12e91df 100644 --- a/host/lib/transport/nirio/CMakeLists.txt +++ b/host/lib/transport/nirio/CMakeLists.txt @@ -39,10 +39,8 @@ LIBUHD_APPEND_SOURCES( IF(WIN32) LIBUHD_APPEND_SOURCES(${CMAKE_CURRENT_SOURCE_DIR}/nirio_driver_iface_win.cpp) -ELSE(WIN32) - IF(APPLE) - LIBUHD_APPEND_SOURCES(${CMAKE_CURRENT_SOURCE_DIR}/nirio_driver_iface_macos.cpp) - ELSE(APPLE) - LIBUHD_APPEND_SOURCES(${CMAKE_CURRENT_SOURCE_DIR}/nirio_driver_iface_linux.cpp) - ENDIF(APPLE) +ELSEIF(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") #Built-in variable encompasses all UNIX-like systems + LIBUHD_APPEND_SOURCES(${CMAKE_CURRENT_SOURCE_DIR}/nirio_driver_iface_linux.cpp) +ELSE() + LIBUHD_APPEND_SOURCES(${CMAKE_CURRENT_SOURCE_DIR}/nirio_driver_iface_unsupported.cpp) ENDIF(WIN32) diff --git a/host/lib/transport/nirio/nirio_driver_iface_macos.cpp b/host/lib/transport/nirio/nirio_driver_iface_unsupported.cpp index 1a1142525..1a1142525 100644 --- a/host/lib/transport/nirio/nirio_driver_iface_macos.cpp +++ b/host/lib/transport/nirio/nirio_driver_iface_unsupported.cpp diff --git a/host/lib/transport/nirio/rpc/rpc_client.cpp b/host/lib/transport/nirio/rpc/rpc_client.cpp index c16a844c1..f8dc26b50 100644 --- a/host/lib/transport/nirio/rpc/rpc_client.cpp +++ b/host/lib/transport/nirio/rpc/rpc_client.cpp @@ -133,9 +133,12 @@ const boost::system::error_code& rpc_client::call( CHAIN_BLOCKING_XFER( boost::asio::write(_socket, boost::asio::buffer(&_request.header, sizeof(_request.header))), sizeof(_request.header), status); - CHAIN_BLOCKING_XFER( - boost::asio::write(_socket, boost::asio::buffer(&(*_request.data.begin()), _request.data.size())), - _request.data.size(), status); + if (not _request.data.empty()) + { + CHAIN_BLOCKING_XFER( + boost::asio::write(_socket, boost::asio::buffer(&(*_request.data.begin()), _request.data.size())), + _request.data.size(), status); + } } catch (boost::exception&) { status = false; } @@ -171,15 +174,20 @@ void rpc_client::_handle_response_hdr(const boost::system::error_code& err, size if (!_exec_err && (transferred == expected)) { //Response header received. Verify that it is expected if (func_args_header_t::match_function(_request.header, _response.header)) { - _response.data.resize(_response.header.func_args_size); - - //Wait for response data - boost::asio::async_read(_socket, - boost::asio::buffer(&(*_response.data.begin()), _response.data.size()), - boost::bind(&rpc_client::_handle_response_data, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred, - _response.data.size())); + if (_response.header.func_args_size) + { + _response.data.resize(_response.header.func_args_size); + + //Wait for response data + boost::asio::async_read(_socket, + boost::asio::buffer(&(*_response.data.begin()), _response.data.size()), + boost::bind(&rpc_client::_handle_response_data, this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred, + _response.data.size())); + } else { + _handle_response_data(err, 0, 0); + } } else { //Unexpected response. Ignore it. UHD_LOG << "rpc_client received garbage responses." << std::endl; diff --git a/host/lib/transport/super_recv_packet_handler.hpp b/host/lib/transport/super_recv_packet_handler.hpp index 5fdf2594d..5c84327a4 100644 --- a/host/lib/transport/super_recv_packet_handler.hpp +++ b/host/lib/transport/super_recv_packet_handler.hpp @@ -154,28 +154,12 @@ public: /*! * Flush all transports in the streamer: - * This calls into get_and_process_single_packet(), - * so the sequence and flow control are handled. - * However, the packet payload is discarded. + * The packet payload is discarded. */ void flush_all(const double timeout = 0.0) { - increment_buffer_info(); //increment to next buffer - - for (size_t i = 0; i < _props.size(); i++) - { - while (true) //while (_props.at(i).get_buff(timeout)); - { - //receive a single packet from the transport - try - { - if (get_and_process_single_packet(i, - get_prev_buffer_info(), - get_curr_buffer_info(), - timeout) == PACKET_TIMEOUT_ERROR) break; - }catch(...){} - } - } + _flush_all(timeout); + return; } /*! @@ -379,12 +363,12 @@ private: ******************************************************************/ UHD_INLINE packet_type get_and_process_single_packet( const size_t index, - buffers_info_type &prev_buffer_info, - buffers_info_type &curr_buffer_info, + per_buffer_info_type &prev_buffer_info, + per_buffer_info_type &curr_buffer_info, double timeout ){ //get a single packet from the transport layer - managed_recv_buffer::sptr &buff = curr_buffer_info[index].buff; + managed_recv_buffer::sptr &buff = curr_buffer_info.buff; buff = _props[index].get_buff(timeout); if (buff.get() == NULL) return PACKET_TIMEOUT_ERROR; @@ -405,7 +389,7 @@ private: } //extract packet info - per_buffer_info_type &info = curr_buffer_info[index]; + per_buffer_info_type &info = curr_buffer_info; info.ifpi.num_packet_words32 = num_packet_words32 - _header_offset_words32; info.vrt_hdr = buff->cast<const boost::uint32_t *>() + _header_offset_words32; _vrt_unpacker(info.vrt_hdr, info.ifpi); @@ -442,7 +426,7 @@ private: #endif //3) check for out of order timestamps - if (info.ifpi.has_tsf and prev_buffer_info[index].time > info.time){ + if (info.ifpi.has_tsf and prev_buffer_info.time > info.time){ return PACKET_TIMESTAMP_ERROR; } @@ -450,6 +434,33 @@ private: return PACKET_IF_DATA; } + void _flush_all(double timeout) + { + for (size_t i = 0; i < _props.size(); i++) + { + per_buffer_info_type prev_buffer_info, curr_buffer_info; + while (true) + { + //receive a single packet from the transport + try + { + // call into get_and_process_single_packet() + // to make sure flow control is handled + if (get_and_process_single_packet( + i, + prev_buffer_info, + curr_buffer_info, + timeout) == PACKET_TIMEOUT_ERROR) break; + } catch(...){} + prev_buffer_info = curr_buffer_info; + curr_buffer_info.reset(); + } + } + get_prev_buffer_info().reset(); + get_curr_buffer_info().reset(); + get_next_buffer_info().reset(); + } + /******************************************************************* * Alignment check: * Check the received packet for alignment and mark accordingly. @@ -509,7 +520,7 @@ private: //receive a single packet from the transport try{ packet = get_and_process_single_packet( - index, prev_info, curr_info, timeout + index, prev_info[index], curr_info[index], timeout ); } @@ -545,7 +556,9 @@ private: curr_info.metadata.time_spec = next_info[index].time; curr_info.metadata.error_code = rx_metadata_t::error_code_t(get_context_code(next_info[index].vrt_hdr, next_info[index].ifpi)); if (curr_info.metadata.error_code == rx_metadata_t::ERROR_CODE_OVERFLOW){ + rx_metadata_t metadata = curr_info.metadata; _props[index].handle_overflow(); + curr_info.metadata = metadata; UHD_MSG(fastpath) << "O"; } return; diff --git a/host/lib/transport/udp_wsa_zero_copy.cpp b/host/lib/transport/udp_wsa_zero_copy.cpp index 031d26374..52382f84d 100644 --- a/host/lib/transport/udp_wsa_zero_copy.cpp +++ b/host/lib/transport/udp_wsa_zero_copy.cpp @@ -276,6 +276,36 @@ public: size_t get_num_send_frames(void) const {return _num_send_frames;} size_t get_send_frame_size(void) const {return _send_frame_size;} + //! Read back the socket's buffer space reserved for receives + size_t get_recv_buff_size(void) { + int recv_buff_size = 0; + int opt_len = sizeof(recv_buff_size); + getsockopt( + _sock_fd, + SOL_SOCKET, + SO_RCVBUF, + (char *)&recv_buff_size, + (int *)&opt_len + ); + + return (size_t) recv_buff_size; + } + + //! Read back the socket's buffer space reserved for sends + size_t get_send_buff_size(void) { + int send_buff_size = 0; + int opt_len = sizeof(send_buff_size); + getsockopt( + _sock_fd, + SOL_SOCKET, + SO_SNDBUF, + (char *)&send_buff_size, + (int *)&opt_len + ); + + return (size_t) send_buff_size; + } + private: //memory management -> buffers and fifos const size_t _recv_frame_size, _num_recv_frames; @@ -292,6 +322,25 @@ private: /*********************************************************************** * UDP zero copy make function **********************************************************************/ +void check_usr_buff_size( + size_t actual_buff_size, + size_t user_buff_size, // Set this to zero for no user-defined preference + const std::string tx_rx +){ + UHD_LOG << boost::format( + "Target %s sock buff size: %d bytes\n" + "Actual %s sock buff size: %d bytes" + ) % tx_rx % user_buff_size % tx_rx % actual_buff_size << std::endl; + if ((user_buff_size != 0.0) and (actual_buff_size < user_buff_size)) UHD_MSG(warning) << boost::format( + "The %s buffer could not be resized sufficiently.\n" + "Target sock buff size: %d bytes.\n" + "Actual sock buff size: %d bytes.\n" + "See the transport application notes on buffer resizing.\n" + ) % tx_rx % user_buff_size % actual_buff_size; +} + + + udp_zero_copy::sptr udp_zero_copy::make( const std::string &addr, const std::string &port, @@ -306,6 +355,34 @@ udp_zero_copy::sptr udp_zero_copy::make( xport_params.num_recv_frames = size_t(hints.cast<double>("num_recv_frames", default_buff_args.num_recv_frames)); xport_params.send_frame_size = size_t(hints.cast<double>("send_frame_size", default_buff_args.send_frame_size)); xport_params.num_send_frames = size_t(hints.cast<double>("num_send_frames", default_buff_args.num_send_frames)); - - return sptr(new udp_zero_copy_wsa_impl(addr, port, xport_params, hints)); + + //extract buffer size hints from the device addr and check if they match up + size_t usr_recv_buff_size = size_t(hints.cast<double>("recv_buff_size", 0.0)); + size_t usr_send_buff_size = size_t(hints.cast<double>("send_buff_size", 0.0)); + if (hints.has_key("recv_buff_size")) { + if (usr_recv_buff_size < xport_params.recv_frame_size * xport_params.num_recv_frames) { + throw uhd::value_error((boost::format( + "recv_buff_size must be equal to or greater than (num_recv_frames * recv_frame_size) where num_recv_frames=%d, recv_frame_size=%d") + % xport_params.num_recv_frames % xport_params.recv_frame_size).str()); + } + } + if (hints.has_key("send_buff_size")) { + if (usr_send_buff_size < xport_params.send_frame_size * xport_params.num_send_frames) { + throw uhd::value_error((boost::format( + "send_buff_size must be equal to or greater than (num_send_frames * send_frame_size) where num_send_frames=%d, send_frame_size=%d") + % xport_params.num_send_frames % xport_params.send_frame_size).str()); + } + } + + udp_zero_copy_wsa_impl::sptr udp_trans( + new udp_zero_copy_wsa_impl(addr, port, xport_params, hints) + ); + + // Read back the actual socket buffer sizes + buff_params_out.recv_buff_size = udp_trans->get_recv_buff_size(); + buff_params_out.send_buff_size = udp_trans->get_send_buff_size(); + check_usr_buff_size(buff_params_out.recv_buff_size, usr_recv_buff_size, "recv"); + check_usr_buff_size(buff_params_out.send_buff_size, usr_send_buff_size, "send"); + + return udp_trans; } diff --git a/host/lib/usrp/b200/b200_iface.cpp b/host/lib/usrp/b200/b200_iface.cpp index 5d799bf01..efb9b3a35 100644 --- a/host/lib/usrp/b200/b200_iface.cpp +++ b/host/lib/usrp/b200/b200_iface.cpp @@ -19,6 +19,7 @@ #include <uhd/config.hpp> #include <uhd/utils/msg.hpp> +#include <uhd/utils/log.hpp> #include <uhd/exception.hpp> #include <boost/functional/hash.hpp> #include <boost/thread/thread.hpp> @@ -32,6 +33,12 @@ #include <iomanip> #include <libusb.h> +//! libusb_error_name is only in newer API +#ifndef HAVE_LIBUSB_ERROR_NAME + #define libusb_error_name(code) \ + str(boost::format("LIBUSB_ERROR_CODE %d") % code) +#endif + using namespace uhd; using namespace uhd::transport; @@ -298,10 +305,10 @@ public: } } - void ad9361_transact(const unsigned char in_buff[64], unsigned char out_buff[64]) { - const int bytes_to_write = 64; - const int bytes_to_read = 64; - const size_t read_retries = 30; + void ad9361_transact(const unsigned char in_buff[AD9361_DISPATCH_PACKET_SIZE], unsigned char out_buff[AD9361_DISPATCH_PACKET_SIZE]) { + const int bytes_to_write = AD9361_DISPATCH_PACKET_SIZE; + const int bytes_to_read = AD9361_DISPATCH_PACKET_SIZE; + const size_t read_retries = 5; int ret = fx3_control_write(B200_VREQ_AD9361_CTRL_WRITE, 0x00, 0x00, (unsigned char *)in_buff, bytes_to_write); if (ret < 0) @@ -311,9 +318,26 @@ public: for (size_t i = 0; i < read_retries; i++) { - ret = fx3_control_read(B200_VREQ_AD9361_CTRL_READ, 0x00, 0x00, out_buff, bytes_to_read, 1000); + ret = fx3_control_read(B200_VREQ_AD9361_CTRL_READ, 0x00, 0x00, out_buff, bytes_to_read, 3000); if (ret < 0) - throw uhd::io_error((boost::format("Failed to read AD9361 (%d: %s)") % ret % libusb_error_name(ret)).str()); + { + if (ret == LIBUSB_ERROR_TIMEOUT) + { + UHD_LOG << (boost::format("Failed to read AD9361 (%d: %s). Retrying (%d of %d)...") + % ret + % libusb_error_name(ret) + % (i+1) + % read_retries + ) << std::endl; + } + else + { + throw uhd::io_error((boost::format("Failed to read AD9361 (%d: %s)") + % ret + % libusb_error_name(ret) + ).str()); + } + } if (ret == bytes_to_read) return; @@ -682,7 +706,7 @@ public: const size_t percent_before = size_t((bytes_sent*100)/file_size); bytes_sent += transfer_count; const size_t percent_after = size_t((bytes_sent*100)/file_size); - if (percent_before/10 != percent_after/10) + if (percent_before != percent_after) { UHD_MSG(status) << "\b\b\b\b" << std::setw(3) << percent_after << "%" << std::flush; } diff --git a/host/lib/usrp/b200/b200_impl.cpp b/host/lib/usrp/b200/b200_impl.cpp index 74e61143b..9dd3a424d 100644 --- a/host/lib/usrp/b200/b200_impl.cpp +++ b/host/lib/usrp/b200/b200_impl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2012-2013 Ettus Research LLC +// Copyright 2012-2014 Ettus Research LLC // // 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 @@ -32,6 +32,7 @@ #include <boost/functional/hash.hpp> #include <cstdio> #include <ctime> +#include <cmath> using namespace uhd; using namespace uhd::usrp; @@ -156,12 +157,12 @@ b200_impl::b200_impl(const device_addr_t &device_addr) const fs_path mb_path = "/mboards/0"; //try to match the given device address with something on the USB bus - uint16_t vid = B200_VENDOR_ID; - uint16_t pid = B200_PRODUCT_ID; + boost::uint16_t vid = B200_VENDOR_ID; + boost::uint16_t pid = B200_PRODUCT_ID; if (device_addr.has_key("vid")) - sscanf(device_addr.get("vid").c_str(), "%x", &vid); + sscanf(device_addr.get("vid").c_str(), "%hx", &vid); if (device_addr.has_key("pid")) - sscanf(device_addr.get("pid").c_str(), "%x", &pid); + sscanf(device_addr.get("pid").c_str(), "%hx", &pid); std::vector<usb_device_handle::sptr> device_list = usb_device_handle::get_device_list(vid, pid); @@ -373,12 +374,15 @@ b200_impl::b200_impl(const device_addr_t &device_addr) //////////////////////////////////////////////////////////////////// // create frontend mapping //////////////////////////////////////////////////////////////////// + std::vector<size_t> default_map(2, 0); default_map[1] = 1; // Set this to A->0 B->1 even if there's only A + _tree->create<std::vector<size_t> >(mb_path / "rx_chan_dsp_mapping").set(default_map); + _tree->create<std::vector<size_t> >(mb_path / "tx_chan_dsp_mapping").set(default_map); _tree->create<subdev_spec_t>(mb_path / "rx_subdev_spec") .set(subdev_spec_t()) - .subscribe(boost::bind(&b200_impl::update_rx_subdev_spec, this, _1)); + .subscribe(boost::bind(&b200_impl::update_subdev_spec, this, "rx", _1)); _tree->create<subdev_spec_t>(mb_path / "tx_subdev_spec") .set(subdev_spec_t()) - .subscribe(boost::bind(&b200_impl::update_tx_subdev_spec, this, _1)); + .subscribe(boost::bind(&b200_impl::update_subdev_spec, this, "tx", _1)); //////////////////////////////////////////////////////////////////// // setup radio control @@ -659,9 +663,40 @@ void b200_impl::codec_loopback_self_test(wb_iface::sptr iface) /*********************************************************************** * Sample and tick rate comprehension below **********************************************************************/ +void b200_impl::enforce_tick_rate_limits(size_t chan_count, double tick_rate, const char* direction /*= NULL*/) +{ + const size_t max_chans = 2; + if (chan_count > max_chans) + { + throw uhd::value_error(boost::str( + boost::format("cannot not setup %d %s channels (maximum is %d)") + % chan_count + % (direction ? direction : "data") + % max_chans + )); + } + else + { + const double max_tick_rate = ((chan_count <= 1) ? AD9361_1_CHAN_CLOCK_RATE_MAX : AD9361_2_CHAN_CLOCK_RATE_MAX); + if (tick_rate > max_tick_rate) + { + throw uhd::value_error(boost::str( + boost::format("current master clock rate (%.2f MHz) exceeds maximum possible master clock rate (%.2f MHz) when using %d %s channels") + % (tick_rate/1e6) + % (max_tick_rate/1e6) + % chan_count + % (direction ? direction : "data") + )); + } + } +} + double b200_impl::set_tick_rate(const double rate) { UHD_MSG(status) << "Asking for clock rate " << rate/1e6 << " MHz\n"; + + check_tick_rate_with_current_streamers(rate); // Defined in b200_io_impl.cpp + _tick_rate = _codec_ctrl->set_clock_rate(rate); UHD_MSG(status) << "Actually got clock rate " << _tick_rate/1e6 << " MHz\n"; diff --git a/host/lib/usrp/b200/b200_impl.hpp b/host/lib/usrp/b200/b200_impl.hpp index c88d14ad5..7d98a8f8d 100644 --- a/host/lib/usrp/b200/b200_impl.hpp +++ b/host/lib/usrp/b200/b200_impl.hpp @@ -91,6 +91,7 @@ public: uhd::rx_streamer::sptr get_rx_stream(const uhd::stream_args_t &args); uhd::tx_streamer::sptr get_tx_stream(const uhd::stream_args_t &args); bool recv_async_msg(uhd::async_metadata_t &, double); + void check_streamer_args(const uhd::stream_args_t &args, double tick_rate, const char* direction = NULL); private: //controllers @@ -127,8 +128,7 @@ private: void set_mb_eeprom(const uhd::usrp::mboard_eeprom_t &); void check_fw_compat(void); void check_fpga_compat(void); - void update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &); - void update_tx_subdev_spec(const uhd::usrp::subdev_spec_t &); + void update_subdev_spec(const std::string &tx_rx, const uhd::usrp::subdev_spec_t &); void update_time_source(const std::string &); void update_clock_source(const std::string &); void update_bandsel(const std::string& which, double freq); @@ -150,8 +150,12 @@ private: bool ant_rx2; }; std::vector<radio_perifs_t> _radio_perifs; - void setup_radio(const size_t which_radio); - void handle_overflow(const size_t index); + + /*! \brief Setup the DSP chain for one radio front-end. + * + */ + void setup_radio(const size_t radio_index); + void handle_overflow(const size_t radio_index); struct gpio_state { boost::uint32_t tx_bandsel_a, tx_bandsel_b, rx_bandsel_a, rx_bandsel_b, rx_bandsel_c, codec_arst, mimo, ref_sel; @@ -174,13 +178,15 @@ private: void update_enables(void); void update_atrs(void); - void update_tick_rate(const double); - void update_rx_samp_rate(const size_t, const double); - void update_tx_samp_rate(const size_t, const double); - double _tick_rate; double get_tick_rate(void){return _tick_rate;} double set_tick_rate(const double rate); + void update_tick_rate(const double); + void enforce_tick_rate_limits(size_t chan_count, double tick_rate, const char* direction = NULL); + void check_tick_rate_with_current_streamers(double rate); + + void update_rx_samp_rate(const size_t, const double); + void update_tx_samp_rate(const size_t, const double); }; #endif /* INCLUDED_B200_IMPL_HPP */ diff --git a/host/lib/usrp/b200/b200_io_impl.cpp b/host/lib/usrp/b200/b200_io_impl.cpp index 4768aa37b..9f6d593fe 100644 --- a/host/lib/usrp/b200/b200_io_impl.cpp +++ b/host/lib/usrp/b200/b200_io_impl.cpp @@ -23,6 +23,7 @@ #include "async_packet_handler.hpp" #include <boost/bind.hpp> #include <boost/make_shared.hpp> +#include <set> using namespace uhd; using namespace uhd::usrp; @@ -31,8 +32,47 @@ using namespace uhd::transport; /*********************************************************************** * update streamer rates **********************************************************************/ +void b200_impl::check_tick_rate_with_current_streamers(double rate) +{ + size_t max_tx_chan_count = 0, max_rx_chan_count = 0; + BOOST_FOREACH(radio_perifs_t &perif, _radio_perifs) + { + { + boost::shared_ptr<sph::recv_packet_streamer> rx_streamer = + boost::dynamic_pointer_cast<sph::recv_packet_streamer>(perif.rx_streamer.lock()); + if (rx_streamer) + max_rx_chan_count = std::max(max_rx_chan_count, rx_streamer->get_num_channels()); + } + + { + boost::shared_ptr<sph::send_packet_streamer> tx_streamer = + boost::dynamic_pointer_cast<sph::send_packet_streamer>(perif.tx_streamer.lock()); + if (tx_streamer) + max_tx_chan_count = std::max(max_tx_chan_count, tx_streamer->get_num_channels()); + } + } + + // Defined in b200_impl.cpp + enforce_tick_rate_limits(max_rx_chan_count, rate, "RX"); + enforce_tick_rate_limits(max_tx_chan_count, rate, "TX"); +} + +void b200_impl::check_streamer_args(const uhd::stream_args_t &args, double tick_rate, const char* direction /*= NULL*/) +{ + std::set<size_t> chans_set; + for (size_t stream_i = 0; stream_i < args.channels.size(); stream_i++) + { + const size_t chan = args.channels[stream_i]; + chans_set.insert(chan); + } + + enforce_tick_rate_limits(chans_set.size(), tick_rate, direction); // Defined in b200_impl.cpp +} + void b200_impl::update_tick_rate(const double rate) { + check_tick_rate_with_current_streamers(rate); + BOOST_FOREACH(radio_perifs_t &perif, _radio_perifs) { boost::shared_ptr<sph::recv_packet_streamer> my_streamer = @@ -72,44 +112,31 @@ void b200_impl::update_tx_samp_rate(const size_t dspno, const double rate) /*********************************************************************** * frontend selection **********************************************************************/ -void b200_impl::update_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec) +void b200_impl::update_subdev_spec(const std::string &tx_rx, const uhd::usrp::subdev_spec_t &spec) { //sanity checking - if (spec.size()) validate_subdev_spec(_tree, spec, "rx"); + if (spec.size()) validate_subdev_spec(_tree, spec, tx_rx); UHD_ASSERT_THROW(spec.size() <= _radio_perifs.size()); - if (spec.size() > 0) + if (spec.size() >= 1) { UHD_ASSERT_THROW(spec[0].db_name == "A"); - UHD_ASSERT_THROW(spec[0].sd_name == "A"); + UHD_ASSERT_THROW(spec[0].sd_name == "A" or spec[0].sd_name == "B"); } - if (spec.size() > 1) + if (spec.size() == 2) { - //TODO we can support swapping at a later date, only this combo is supported UHD_ASSERT_THROW(spec[1].db_name == "A"); - UHD_ASSERT_THROW(spec[1].sd_name == "B"); + UHD_ASSERT_THROW( + (spec[0].sd_name == "A" and spec[1].sd_name == "B") or + (spec[0].sd_name == "B" and spec[1].sd_name == "A") + ); } - this->update_enables(); -} - -void b200_impl::update_tx_subdev_spec(const uhd::usrp::subdev_spec_t &spec) -{ - //sanity checking - if (spec.size()) validate_subdev_spec(_tree, spec, "tx"); - UHD_ASSERT_THROW(spec.size() <= _radio_perifs.size()); - - if (spec.size() > 0) - { - UHD_ASSERT_THROW(spec[0].db_name == "A"); - UHD_ASSERT_THROW(spec[0].sd_name == "A"); - } - if (spec.size() > 1) - { - //TODO we can support swapping at a later date, only this combo is supported - UHD_ASSERT_THROW(spec[1].db_name == "A"); - UHD_ASSERT_THROW(spec[1].sd_name == "B"); + std::vector<size_t> chan_to_dsp_map(spec.size(), 0); + for (size_t i = 0; i < spec.size(); i++) { + chan_to_dsp_map[i] = (spec[i].sd_name == "A") ? 0 : 1; } + _tree->access<std::vector<size_t> >("/mboards/0" / (tx_rx + "_chan_dsp_mapping")).set(chan_to_dsp_map); this->update_enables(); } @@ -235,16 +262,19 @@ rx_streamer::sptr b200_impl::get_rx_stream(const uhd::stream_args_t &args_) if (args.otw_format.empty()) args.otw_format = "sc16"; args.channels = args.channels.empty()? std::vector<size_t>(1, 0) : args.channels; + check_streamer_args(args, this->get_tick_rate(), "RX"); + boost::shared_ptr<sph::recv_packet_streamer> my_streamer; for (size_t stream_i = 0; stream_i < args.channels.size(); stream_i++) { - const size_t chan = args.channels[stream_i]; - radio_perifs_t &perif = _radio_perifs[chan]; + const size_t radio_index = _tree->access<std::vector<size_t> >("/mboards/0/rx_chan_dsp_mapping") + .get().at(args.channels[stream_i]); + radio_perifs_t &perif = _radio_perifs[radio_index]; if (args.otw_format == "sc16") perif.ctrl->poke32(TOREG(SR_RX_FMT), 0); if (args.otw_format == "sc12") perif.ctrl->poke32(TOREG(SR_RX_FMT), 1); if (args.otw_format == "fc32") perif.ctrl->poke32(TOREG(SR_RX_FMT), 2); if (args.otw_format == "sc8") perif.ctrl->poke32(TOREG(SR_RX_FMT), 3); - const boost::uint32_t sid = chan?B200_RX_DATA1_SID:B200_RX_DATA0_SID; + const boost::uint32_t sid = radio_index ? B200_RX_DATA1_SID : B200_RX_DATA0_SID; //calculate packet size static const size_t hdr_size = 0 @@ -283,7 +313,7 @@ rx_streamer::sptr b200_impl::get_rx_stream(const uhd::stream_args_t &args_) &recv_packet_demuxer_3000::get_recv_buff, _demux, sid, _1 ), true /*flush*/); my_streamer->set_overflow_handler(stream_i, boost::bind( - &b200_impl::handle_overflow, this, chan + &b200_impl::handle_overflow, this, radio_index )); my_streamer->set_issue_stream_cmd(stream_i, boost::bind( &rx_vita_core_3000::issue_stream_command, perif.framer, _1 @@ -292,21 +322,21 @@ rx_streamer::sptr b200_impl::get_rx_stream(const uhd::stream_args_t &args_) //sets all tick and samp rates on this streamer this->update_tick_rate(this->get_tick_rate()); - _tree->access<double>(str(boost::format("/mboards/0/rx_dsps/%u/rate/value") % chan)).update(); + _tree->access<double>(str(boost::format("/mboards/0/rx_dsps/%u/rate/value") % radio_index)).update(); } this->update_enables(); return my_streamer; } -void b200_impl::handle_overflow(const size_t i) +void b200_impl::handle_overflow(const size_t radio_index) { boost::shared_ptr<sph::recv_packet_streamer> my_streamer = - boost::dynamic_pointer_cast<sph::recv_packet_streamer>(_radio_perifs[i].rx_streamer.lock()); + boost::dynamic_pointer_cast<sph::recv_packet_streamer>(_radio_perifs[radio_index].rx_streamer.lock()); if (my_streamer->get_num_channels() == 2) //MIMO time { //find out if we were in continuous mode before stopping - const bool in_continuous_streaming_mode = _radio_perifs[i].framer->in_continuous_streaming_mode(); + const bool in_continuous_streaming_mode = _radio_perifs[radio_index].framer->in_continuous_streaming_mode(); //stop streaming my_streamer->issue_stream_cmd(stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); //flush demux @@ -319,11 +349,11 @@ void b200_impl::handle_overflow(const size_t i) { stream_cmd_t stream_cmd(stream_cmd_t::STREAM_MODE_START_CONTINUOUS); stream_cmd.stream_now = false; - stream_cmd.time_spec = _radio_perifs[i].time64->get_time_now() + time_spec_t(0.01); + stream_cmd.time_spec = _radio_perifs[radio_index].time64->get_time_now() + time_spec_t(0.01); my_streamer->issue_stream_cmd(stream_cmd); } } - else _radio_perifs[i].framer->handle_overflow(); + else _radio_perifs[radio_index].framer->handle_overflow(); } /*********************************************************************** @@ -337,11 +367,14 @@ tx_streamer::sptr b200_impl::get_tx_stream(const uhd::stream_args_t &args_) if (args.otw_format.empty()) args.otw_format = "sc16"; args.channels = args.channels.empty()? std::vector<size_t>(1, 0) : args.channels; + check_streamer_args(args, this->get_tick_rate(), "TX"); + boost::shared_ptr<sph::send_packet_streamer> my_streamer; for (size_t stream_i = 0; stream_i < args.channels.size(); stream_i++) { - const size_t chan = args.channels[stream_i]; - radio_perifs_t &perif = _radio_perifs[chan]; + const size_t radio_index = _tree->access<std::vector<size_t> >("/mboards/0/tx_chan_dsp_mapping") + .get().at(args.channels[stream_i]); + radio_perifs_t &perif = _radio_perifs[radio_index]; if (args.otw_format == "sc16") perif.ctrl->poke32(TOREG(SR_TX_FMT), 0); if (args.otw_format == "sc12") perif.ctrl->poke32(TOREG(SR_TX_FMT), 1); if (args.otw_format == "fc32") perif.ctrl->poke32(TOREG(SR_TX_FMT), 2); @@ -382,13 +415,13 @@ tx_streamer::sptr b200_impl::get_tx_stream(const uhd::stream_args_t &args_) my_streamer->set_async_receiver(boost::bind( &async_md_type::pop_with_timed_wait, _async_task_data->async_md, _1, _2 )); - my_streamer->set_xport_chan_sid(stream_i, true, chan?B200_TX_DATA1_SID:B200_TX_DATA0_SID); + my_streamer->set_xport_chan_sid(stream_i, true, radio_index ? B200_TX_DATA1_SID : B200_TX_DATA0_SID); my_streamer->set_enable_trailer(false); //TODO not implemented trailer support yet perif.tx_streamer = my_streamer; //store weak pointer //sets all tick and samp rates on this streamer this->update_tick_rate(this->get_tick_rate()); - _tree->access<double>(str(boost::format("/mboards/0/tx_dsps/%u/rate/value") % chan)).update(); + _tree->access<double>(str(boost::format("/mboards/0/tx_dsps/%u/rate/value") % radio_index)).update(); } this->update_enables(); diff --git a/host/lib/usrp/common/ad9361_ctrl.cpp b/host/lib/usrp/common/ad9361_ctrl.cpp index 1afa2fbb7..10496f2a9 100644 --- a/host/lib/usrp/common/ad9361_ctrl.cpp +++ b/host/lib/usrp/common/ad9361_ctrl.cpp @@ -151,7 +151,7 @@ struct ad9361_ctrl_impl : public ad9361_ctrl //handle errors const size_t len = my_strnlen(out->error_msg, AD9361_TRANSACTION_MAX_ERROR_MSG); const std::string error_msg(out->error_msg, len); - if (not error_msg.empty()) throw uhd::runtime_error("ad9361 do transaction: " + error_msg); + if (not error_msg.empty()) throw uhd::runtime_error("[ad9361_ctrl::do_transaction] firmware reported: \"" + error_msg + "\""); //return result done! return *out; diff --git a/host/lib/usrp/common/ad9361_ctrl.hpp b/host/lib/usrp/common/ad9361_ctrl.hpp index fd8012764..098b5dae8 100644 --- a/host/lib/usrp/common/ad9361_ctrl.hpp +++ b/host/lib/usrp/common/ad9361_ctrl.hpp @@ -27,10 +27,17 @@ #include <vector> #include <string> +#include "ad9361_transaction.h" + + +static const double AD9361_CLOCK_RATE_MAX = 61.44e6; +static const double AD9361_1_CHAN_CLOCK_RATE_MAX = AD9361_CLOCK_RATE_MAX; +static const double AD9361_2_CHAN_CLOCK_RATE_MAX = (AD9361_1_CHAN_CLOCK_RATE_MAX / 2); + struct ad9361_ctrl_iface_type { - virtual void ad9361_transact(const unsigned char in_buff[64], unsigned char out_buff[64]) = 0; + virtual void ad9361_transact(const unsigned char in_buff[AD9361_DISPATCH_PACKET_SIZE], unsigned char out_buff[AD9361_DISPATCH_PACKET_SIZE]) = 0; }; typedef boost::shared_ptr<ad9361_ctrl_iface_type> ad9361_ctrl_iface_sptr; @@ -42,18 +49,18 @@ struct ad9361_ctrl_over_zc : ad9361_ctrl_iface_type _xport = xport; } - void ad9361_transact(const unsigned char in_buff[64], unsigned char out_buff[64]) + void ad9361_transact(const unsigned char in_buff[AD9361_DISPATCH_PACKET_SIZE], unsigned char out_buff[AD9361_DISPATCH_PACKET_SIZE]) { { uhd::transport::managed_send_buffer::sptr buff = _xport->get_send_buff(10.0); - if (not buff or buff->size() < 64) throw std::runtime_error("ad9361_ctrl_over_zc send timeout"); - std::memcpy(buff->cast<void *>(), in_buff, 64); - buff->commit(64); + if (not buff or buff->size() < AD9361_DISPATCH_PACKET_SIZE) throw std::runtime_error("ad9361_ctrl_over_zc send timeout"); + std::memcpy(buff->cast<void *>(), in_buff, AD9361_DISPATCH_PACKET_SIZE); + buff->commit(AD9361_DISPATCH_PACKET_SIZE); } { uhd::transport::managed_recv_buffer::sptr buff = _xport->get_recv_buff(10.0); - if (not buff or buff->size() < 64) throw std::runtime_error("ad9361_ctrl_over_zc recv timeout"); - std::memcpy(out_buff, buff->cast<const void *>(), 64); + if (not buff or buff->size() < AD9361_DISPATCH_PACKET_SIZE) throw std::runtime_error("ad9361_ctrl_over_zc recv timeout"); + std::memcpy(out_buff, buff->cast<const void *>(), AD9361_DISPATCH_PACKET_SIZE); } } @@ -100,7 +107,7 @@ public: static uhd::meta_range_t get_clock_rate_range(void) { //return uhd::meta_range_t(220e3, 61.44e6); - return uhd::meta_range_t(5e6, 61.44e6); //5 MHz DCM low end + return uhd::meta_range_t(5e6, AD9361_CLOCK_RATE_MAX); //5 MHz DCM low end } //! set the filter bandwidth for the frontend diff --git a/host/lib/usrp/common/ad9361_transaction.h b/host/lib/usrp/common/ad9361_transaction.h index 7cbad5908..693f32e41 100644 --- a/host/lib/usrp/common/ad9361_transaction.h +++ b/host/lib/usrp/common/ad9361_transaction.h @@ -25,8 +25,8 @@ extern "C" { #endif //various constants -#define AD9361_TRANSACTION_VERSION 0x4 -#define AD9361_TRANSACTION_MAX_ERROR_MSG 40 +#define AD9361_TRANSACTION_VERSION 0x4 +#define AD9361_DISPATCH_PACKET_SIZE 64 //action types #define AD9361_ACTION_ECHO 0 @@ -100,6 +100,7 @@ typedef struct } ad9361_transaction_t; +#define AD9361_TRANSACTION_MAX_ERROR_MSG (AD9361_DISPATCH_PACKET_SIZE - (sizeof(ad9361_transaction_t)-4)-1) // -4 for 'error_msg' alignment padding, -1 for terminating \0 #ifdef __cplusplus } diff --git a/host/lib/usrp/common/adf435x_common.cpp b/host/lib/usrp/common/adf435x_common.cpp index f0df6a334..972a69388 100644 --- a/host/lib/usrp/common/adf435x_common.cpp +++ b/host/lib/usrp/common/adf435x_common.cpp @@ -16,8 +16,11 @@ // #include "adf435x_common.hpp" + #include <uhd/types/tune_request.hpp> #include <uhd/utils/log.hpp> +#include <cmath> + using namespace uhd; diff --git a/host/lib/usrp/gps_ctrl.cpp b/host/lib/usrp/gps_ctrl.cpp index c0d44abd5..6f5c75dec 100644 --- a/host/lib/usrp/gps_ctrl.cpp +++ b/host/lib/usrp/gps_ctrl.cpp @@ -30,7 +30,6 @@ #include "boost/tuple/tuple.hpp" #include "boost/foreach.hpp" -#include <boost/container/vector.hpp> using namespace uhd; using namespace boost::gregorian; diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 182e774fc..f08709669 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -35,14 +35,20 @@ using namespace uhd::usrp; const std::string multi_usrp::ALL_GAINS = ""; -UHD_INLINE std::string string_vector_to_string(std::vector<std::string> values, std::string delimeter = std::string(" ")) +UHD_INLINE std::string string_vector_to_string(std::vector<std::string> values, std::string delimiter = std::string(" ")) { std::string out = ""; for (std::vector<std::string>::iterator iter = values.begin(); iter != values.end(); iter++) - out += delimeter + *iter; + { + out += (iter != values.begin() ? delimiter : "") + *iter; + } return out; } +#define THROW_GAIN_NAME_ERROR(name,chan,dir) throw uhd::exception::runtime_error( \ + (boost::format("%s: gain \"%s\" not found for channel %d.\nAvailable gains: %s\n") % \ + __FUNCTION__ % name % chan % string_vector_to_string(get_##dir##_gain_names(chan))).str()); + /*********************************************************************** * Helper methods **********************************************************************/ @@ -671,10 +677,7 @@ public: try { return rx_gain_group(chan)->set_value(gain, name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,rx); } } @@ -682,10 +685,7 @@ public: try { return rx_gain_group(chan)->get_value(name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,rx); } } @@ -693,10 +693,7 @@ public: try { return rx_gain_group(chan)->get_range(name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,rx); } } @@ -861,10 +858,7 @@ public: try { return tx_gain_group(chan)->set_value(gain, name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,tx); } } @@ -872,10 +866,7 @@ public: try { return tx_gain_group(chan)->get_value(name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,tx); } } @@ -883,10 +874,7 @@ public: try { return tx_gain_group(chan)->get_range(name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,tx); } } @@ -1073,6 +1061,12 @@ private: fs_path rx_dsp_root(const size_t chan) { mboard_chan_pair mcp = rx_chan_to_mcp(chan); + if (_tree->exists(mb_root(mcp.mboard) / "rx_chan_dsp_mapping")) { + std::vector<size_t> map = _tree->access<std::vector<size_t> >(mb_root(mcp.mboard) / "rx_chan_dsp_mapping").get(); + UHD_ASSERT_THROW(map.size() > mcp.chan); + mcp.chan = map[mcp.chan]; + } + try { const std::string name = _tree->list(mb_root(mcp.mboard) / "rx_dsps").at(mcp.chan); @@ -1087,6 +1081,11 @@ private: fs_path tx_dsp_root(const size_t chan) { mboard_chan_pair mcp = tx_chan_to_mcp(chan); + if (_tree->exists(mb_root(mcp.mboard) / "tx_chan_dsp_mapping")) { + std::vector<size_t> map = _tree->access<std::vector<size_t> >(mb_root(mcp.mboard) / "tx_chan_dsp_mapping").get(); + UHD_ASSERT_THROW(map.size() > mcp.chan); + mcp.chan = map[mcp.chan]; + } try { const std::string name = _tree->list(mb_root(mcp.mboard) / "tx_dsps").at(mcp.chan); diff --git a/host/lib/usrp/x300/x300_clock_ctrl.cpp b/host/lib/usrp/x300/x300_clock_ctrl.cpp index a986928a7..a8b30a0ab 100644 --- a/host/lib/usrp/x300/x300_clock_ctrl.cpp +++ b/host/lib/usrp/x300/x300_clock_ctrl.cpp @@ -48,6 +48,10 @@ x300_clock_ctrl_impl(uhd::spi_iface::sptr spiface, set_master_clock_rate(master_clock_rate); } +void reset_clocks() { + set_master_clock_rate(_master_clock_rate); +} + void sync_clocks(void) { //soft sync: //put the sync IO into output mode - FPGA must be input diff --git a/host/lib/usrp/x300/x300_clock_ctrl.hpp b/host/lib/usrp/x300/x300_clock_ctrl.hpp index 0e3caf900..e9904d25c 100644 --- a/host/lib/usrp/x300/x300_clock_ctrl.hpp +++ b/host/lib/usrp/x300/x300_clock_ctrl.hpp @@ -78,6 +78,12 @@ public: * \param true = on, false = off */ virtual void set_ref_out(const bool) = 0; + + /*! Reset the clocks. + * Should be called if the reference clock changes + * to reduce the time required to achieve a lock. + */ + virtual void reset_clocks(void) = 0; }; #endif /* INCLUDED_X300_CLOCK_CTRL_HPP */ diff --git a/host/lib/usrp/x300/x300_fw_common.h b/host/lib/usrp/x300/x300_fw_common.h index c470e9bff..632391644 100644 --- a/host/lib/usrp/x300/x300_fw_common.h +++ b/host/lib/usrp/x300/x300_fw_common.h @@ -31,7 +31,7 @@ extern "C" { #define X300_FW_COMPAT_MAJOR 3 #define X300_FW_COMPAT_MINOR 0 -#define X300_FPGA_COMPAT_MAJOR 3 +#define X300_FPGA_COMPAT_MAJOR 4 //shared memory sections - in between the stack and the program space #define X300_FW_SHMEM_BASE 0x6000 diff --git a/host/lib/usrp/x300/x300_impl.cpp b/host/lib/usrp/x300/x300_impl.cpp index b20897fc6..e492b2238 100644 --- a/host/lib/usrp/x300/x300_impl.cpp +++ b/host/lib/usrp/x300/x300_impl.cpp @@ -430,16 +430,16 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) // Detect the frame size on the path to the USRP try { - max_frame_sizes = determine_max_frame_size(mb.addr, req_max_frame_size); + _max_frame_sizes = determine_max_frame_size(mb.addr, req_max_frame_size); } catch(std::exception &e) { UHD_MSG(error) << e.what() << std::endl; } if ((mb.recv_args.has_key("recv_frame_size")) - && (req_max_frame_size.recv_frame_size < max_frame_sizes.recv_frame_size)) { + && (req_max_frame_size.recv_frame_size < _max_frame_sizes.recv_frame_size)) { UHD_MSG(warning) << 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 + % 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 << "UHD will use the auto-detected max frame size for this connection." @@ -447,10 +447,10 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) } if ((mb.recv_args.has_key("send_frame_size")) - && (req_max_frame_size.send_frame_size < max_frame_sizes.send_frame_size)) { + && (req_max_frame_size.send_frame_size < _max_frame_sizes.send_frame_size)) { UHD_MSG(warning) << 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 + % 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 << "UHD will use the auto-detected max frame size for this connection." @@ -458,8 +458,6 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) } } - const std::vector<std::string> DB_NAMES = boost::assign::list_of("A")("B"); - //create basic communication UHD_MSG(status) << "Setup basic communication..." << std::endl; if (mb.xport_path == "nirio") { @@ -579,20 +577,10 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) //////////////////////////////////////////////////////////////////// UHD_MSG(status) << "Setup RF frontend clocking..." << std::endl; - // Init shadow and clock source; the device comes up with it's internal - // clock source before locking to something else (if requested). - mb.clock_control_regs__clock_source = 0; - mb.clock_control_regs__pps_select = 0; - mb.clock_control_regs__pps_out_enb = 0; - mb.clock_control_regs__tcxo_enb = 1; - mb.clock_control_regs__gpsdo_pwr = 1; - this->update_clock_source(mb, "internal"); - this->update_clock_control(mb); - - size_t hw_rev = 0; + mb.hw_rev = 0; if(mb_eeprom.has_key("revision") and not mb_eeprom["revision"].empty()) { try { - hw_rev = boost::lexical_cast<size_t>(mb_eeprom["revision"]); + mb.hw_rev = boost::lexical_cast<size_t>(mb_eeprom["revision"]); } catch(...) { UHD_MSG(warning) << "Revision in EEPROM is invalid! Please reprogram your EEPROM." << std::endl; } @@ -600,17 +588,38 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) UHD_MSG(warning) << "No revision detected MB EEPROM must be reprogrammed!" << std::endl; } - if(hw_rev == 0) { + if(mb.hw_rev == 0) { UHD_MSG(warning) << "Defaulting to X300 RevD Clock Settings. This will result in non-optimal lock times." << std::endl; - hw_rev = X300_REV("D"); + mb.hw_rev = X300_REV("D"); } + //Initialize clock control with internal references and GPSDO power on. + mb.clock_control_regs_clock_source = ZPU_SR_CLOCK_CTRL_CLK_SRC_INTERNAL; + mb.clock_control_regs_pps_select = ZPU_SR_CLOCK_CTRL_PPS_SRC_INTERNAL; + mb.clock_control_regs_pps_out_enb = 0; + mb.clock_control_regs_tcxo_enb = 1; + mb.clock_control_regs_gpsdo_pwr = 1; + this->update_clock_control(mb); + + //Create clock control mb.clock = x300_clock_ctrl::make(mb.zpu_spi, 1 /*slaveno*/, - hw_rev, + mb.hw_rev, dev_addr.cast<double>("master_clock_rate", X300_DEFAULT_TICK_RATE), dev_addr.cast<double>("system_ref_rate", X300_DEFAULT_SYSREF_RATE)); + //wait for reference clock to lock + if(mb.hw_rev > 4) + { + try { + //FIXME: Need to verify timeout value to make sure lock can be achieved in < 1.0 seconds + wait_for_ref_locked(mb.zpu_ctrl, 1.0); + } catch (uhd::runtime_error &e) { + //Silently fail for now, but fix after we have the correct timeout value + //UHD_MSG(warning) << "Clock failed to lock to internal source during initialization." << std::endl; + } + } + //////////////////////////////////////////////////////////////////// // create clock properties //////////////////////////////////////////////////////////////////// @@ -664,8 +673,8 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) // setup radios //////////////////////////////////////////////////////////////////// UHD_MSG(status) << "Initialize Radio control..." << std::endl; - this->setup_radio(mb_i, 0, DB_NAMES[0]); - this->setup_radio(mb_i, 1, DB_NAMES[1]); + this->setup_radio(mb_i, "A"); + this->setup_radio(mb_i, "B"); //////////////////////////////////////////////////////////////////// // front panel gpio @@ -732,10 +741,13 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) //////////////////////////////////////////////////////////////////// // create frontend mapping //////////////////////////////////////////////////////////////////// + std::vector<size_t> default_map(2, 0); default_map[1] = 1; + _tree->create<std::vector<size_t> >(mb_path / "rx_chan_dsp_mapping").set(default_map); + _tree->create<std::vector<size_t> >(mb_path / "tx_chan_dsp_mapping").set(default_map); _tree->create<subdev_spec_t>(mb_path / "rx_subdev_spec") - .subscribe(boost::bind(&x300_impl::update_rx_subdev_spec, this, mb_i, _1)); + .subscribe(boost::bind(&x300_impl::update_subdev_spec, this, "rx", mb_i, _1)); _tree->create<subdev_spec_t>(mb_path / "tx_subdev_spec") - .subscribe(boost::bind(&x300_impl::update_tx_subdev_spec, this, mb_i, _1)); + .subscribe(boost::bind(&x300_impl::update_subdev_spec, this, "tx", mb_i, _1)); //////////////////////////////////////////////////////////////////// // and do the misc mboard sensors @@ -767,30 +779,42 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) _tree->access<subdev_spec_t>(mb_path / "rx_subdev_spec").set(rx_fe_spec); _tree->access<subdev_spec_t>(mb_path / "tx_subdev_spec").set(tx_fe_spec); - //GPS installed: use external ref, time, and init time spec - if (mb.gps and mb.gps->gps_detected()) - { - UHD_MSG(status) << "Setting references to the internal GPSDO" << std::endl; - _tree->access<std::string>(mb_path / "time_source" / "value").set("gpsdo"); - _tree->access<std::string>(mb_path / "clock_source" / "value").set("gpsdo"); - UHD_MSG(status) << "Initializing time to the internal GPSDO" << std::endl; - const time_t tp = time_t(mb.gps->get_sensor("gps_time").to_int()+1); - _tree->access<time_spec_t>(mb_path / "time" / "pps").set(time_spec_t(tp)); - } - else - { - _tree->access<std::string>(mb_path / "time_source" / "value").set("external"); + UHD_MSG(status) << "Initializing clock and PPS references..." << std::endl; + try { + //First, try external source _tree->access<std::string>(mb_path / "clock_source" / "value").set("external"); - boost::this_thread::sleep(boost::posix_time::milliseconds(100)); - if (this->get_ref_locked(mb.zpu_ctrl).to_bool()) - { - UHD_MSG(status) << "Setting references to external sources" << std::endl; - } - else + wait_for_ref_locked(mb.zpu_ctrl, 1.0); + _tree->access<std::string>(mb_path / "time_source" / "value").set("external"); + UHD_MSG(status) << "References initialized to external sources" << std::endl; + } catch (uhd::exception::runtime_error &e) { + //No external source detected - set to the GPSDO if installed + if (mb.gps and mb.gps->gps_detected()) { - UHD_MSG(status) << "Setting references to internal sources" << std::endl; - _tree->access<std::string>(mb_path / "time_source" / "value").set("internal"); + _tree->access<std::string>(mb_path / "clock_source" / "value").set("gpsdo"); + try { + wait_for_ref_locked(mb.zpu_ctrl, 1.0); + } catch (uhd::exception::runtime_error &e) { + UHD_MSG(warning) << "Clock reference failed to lock to GPSDO during device initialization. " << + "Check for the lock before operation or ignore this warning if using another clock source." << std::endl; + } + _tree->access<std::string>(mb_path / "time_source" / "value").set("gpsdo"); + UHD_MSG(status) << "References initialized to GPSDO sources" << std::endl; + UHD_MSG(status) << "Initializing time to the GPSDO time" << std::endl; + const time_t tp = time_t(mb.gps->get_sensor("gps_time").to_int()+1); + _tree->access<time_spec_t>(mb_path / "time" / "pps").set(time_spec_t(tp)); + //wait for time to be set (timeout after 1 second) + for (int i = 0; i < 10 && tp != (_tree->access<time_spec_t>(mb_path / "time" / "pps").get()).get_full_secs(); i++) + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + } else { _tree->access<std::string>(mb_path / "clock_source" / "value").set("internal"); + try { + wait_for_ref_locked(mb.zpu_ctrl, 1.0); + } catch (uhd::exception::runtime_error &e) { + UHD_MSG(warning) << "Clock reference failed to lock to internal source during device initialization. " << + "Check for the lock before operation or ignore this warning if using another clock source." << std::endl; + } + _tree->access<std::string>(mb_path / "time_source" / "value").set("internal"); + UHD_MSG(status) << "References initialized to internal sources" << std::endl; } } } @@ -824,20 +848,21 @@ static void check_adc(wb_iface::sptr iface, const boost::uint32_t val) UHD_ASSERT_THROW(adc_rb == val); } -void x300_impl::setup_radio(const size_t mb_i, const size_t i, const std::string &db_name) +void x300_impl::setup_radio(const size_t mb_i, const std::string &slot_name) { const fs_path mb_path = "/mboards/"+boost::lexical_cast<std::string>(mb_i); + UHD_ASSERT_THROW(mb_i < _mb.size()); mboard_members_t &mb = _mb[mb_i]; - radio_perifs_t &perif = mb.radio_perifs[i]; - const size_t dspno = i; + const size_t radio_index = mb.get_radio_index(slot_name); + radio_perifs_t &perif = mb.radio_perifs[radio_index]; //////////////////////////////////////////////////////////////////// // radio control //////////////////////////////////////////////////////////////////// - uint8_t dest = (i == 0)? X300_XB_DST_R0 : X300_XB_DST_R1; + uint8_t dest = (radio_index == 0)? X300_XB_DST_R0 : X300_XB_DST_R1; boost::uint32_t ctrl_sid; both_xports_t xport = this->make_transport(mb_i, dest, X300_RADIO_DEST_PREFIX_CTRL, device_addr_t(), ctrl_sid); - perif.ctrl = radio_ctrl_core_3000::make(mb.if_pkt_is_big_endian, xport.recv, xport.send, ctrl_sid, db_name); + perif.ctrl = radio_ctrl_core_3000::make(mb.if_pkt_is_big_endian, xport.recv, xport.send, ctrl_sid, slot_name); perif.ctrl->poke32(TOREG(SR_MISC_OUTS), (1 << 2)); //reset adc + dac perif.ctrl->poke32(TOREG(SR_MISC_OUTS), (1 << 1) | (1 << 0)); //out of reset + dac enable @@ -883,20 +908,20 @@ void x300_impl::setup_radio(const size_t mb_i, const size_t i, const std::string //////////////////////////////////////////////////////////////// // create codec control objects //////////////////////////////////////////////////////////////// - _tree->create<int>(mb_path / "rx_codecs" / db_name / "gains"); //phony property so this dir exists - _tree->create<int>(mb_path / "tx_codecs" / db_name / "gains"); //phony property so this dir exists - _tree->create<std::string>(mb_path / "rx_codecs" / db_name / "name").set("ads62p48"); - _tree->create<std::string>(mb_path / "tx_codecs" / db_name / "name").set("ad9146"); + _tree->create<int>(mb_path / "rx_codecs" / slot_name / "gains"); //phony property so this dir exists + _tree->create<int>(mb_path / "tx_codecs" / slot_name / "gains"); //phony property so this dir exists + _tree->create<std::string>(mb_path / "rx_codecs" / slot_name / "name").set("ads62p48"); + _tree->create<std::string>(mb_path / "tx_codecs" / slot_name / "name").set("ad9146"); - _tree->create<meta_range_t>(mb_path / "rx_codecs" / db_name / "gains" / "digital" / "range").set(meta_range_t(0, 6.0, 0.5)); - _tree->create<double>(mb_path / "rx_codecs" / db_name / "gains" / "digital" / "value") + _tree->create<meta_range_t>(mb_path / "rx_codecs" / slot_name / "gains" / "digital" / "range").set(meta_range_t(0, 6.0, 0.5)); + _tree->create<double>(mb_path / "rx_codecs" / slot_name / "gains" / "digital" / "value") .subscribe(boost::bind(&x300_adc_ctrl::set_gain, perif.adc, _1)).set(0); //////////////////////////////////////////////////////////////////// // front end corrections //////////////////////////////////////////////////////////////////// perif.rx_fe = rx_frontend_core_200::make(perif.ctrl, TOREG(SR_RX_FRONT)); - const fs_path rx_fe_path = mb_path / "rx_frontends" / db_name; + const fs_path rx_fe_path = mb_path / "rx_frontends" / slot_name; _tree->create<std::complex<double> >(rx_fe_path / "dc_offset" / "value") .coerce(boost::bind(&rx_frontend_core_200::set_dc_offset, perif.rx_fe, _1)) .set(std::complex<double>(0.0, 0.0)); @@ -908,7 +933,7 @@ void x300_impl::setup_radio(const size_t mb_i, const size_t i, const std::string .set(std::complex<double>(0.0, 0.0)); perif.tx_fe = tx_frontend_core_200::make(perif.ctrl, TOREG(SR_TX_FRONT)); - const fs_path tx_fe_path = mb_path / "tx_frontends" / db_name; + const fs_path tx_fe_path = mb_path / "tx_frontends" / slot_name; _tree->create<std::complex<double> >(tx_fe_path / "dc_offset" / "value") .coerce(boost::bind(&tx_frontend_core_200::set_dc_offset, perif.tx_fe, _1)) .set(std::complex<double>(0.0, 0.0)); @@ -927,12 +952,12 @@ void x300_impl::setup_radio(const size_t mb_i, const size_t i, const std::string _tree->access<double>(mb_path / "tick_rate") .subscribe(boost::bind(&rx_vita_core_3000::set_tick_rate, perif.framer, _1)) .subscribe(boost::bind(&rx_dsp_core_3000::set_tick_rate, perif.ddc, _1)); - const fs_path rx_dsp_path = mb_path / "rx_dsps" / str(boost::format("%u") % dspno); + const fs_path rx_dsp_path = mb_path / "rx_dsps" / str(boost::format("%u") % radio_index); _tree->create<meta_range_t>(rx_dsp_path / "rate" / "range") .publish(boost::bind(&rx_dsp_core_3000::get_host_rates, perif.ddc)); _tree->create<double>(rx_dsp_path / "rate" / "value") .coerce(boost::bind(&rx_dsp_core_3000::set_host_rate, perif.ddc, _1)) - .subscribe(boost::bind(&x300_impl::update_rx_samp_rate, this, boost::ref(mb), dspno, _1)) + .subscribe(boost::bind(&x300_impl::update_rx_samp_rate, this, boost::ref(mb), radio_index, _1)) .set(1e6); _tree->create<double>(rx_dsp_path / "freq" / "value") .coerce(boost::bind(&rx_dsp_core_3000::set_freq, perif.ddc, _1)) @@ -951,12 +976,12 @@ void x300_impl::setup_radio(const size_t mb_i, const size_t i, const std::string _tree->access<double>(mb_path / "tick_rate") .subscribe(boost::bind(&tx_vita_core_3000::set_tick_rate, perif.deframer, _1)) .subscribe(boost::bind(&tx_dsp_core_3000::set_tick_rate, perif.duc, _1)); - const fs_path tx_dsp_path = mb_path / "tx_dsps" / str(boost::format("%u") % dspno); + const fs_path tx_dsp_path = mb_path / "tx_dsps" / str(boost::format("%u") % radio_index); _tree->create<meta_range_t>(tx_dsp_path / "rate" / "range") .publish(boost::bind(&tx_dsp_core_3000::get_host_rates, perif.duc)); _tree->create<double>(tx_dsp_path / "rate" / "value") .coerce(boost::bind(&tx_dsp_core_3000::set_host_rate, perif.duc, _1)) - .subscribe(boost::bind(&x300_impl::update_tx_samp_rate, this, boost::ref(mb), dspno, _1)) + .subscribe(boost::bind(&x300_impl::update_tx_samp_rate, this, boost::ref(mb), radio_index, _1)) .set(1e6); _tree->create<double>(tx_dsp_path / "freq" / "value") .coerce(boost::bind(&tx_dsp_core_3000::set_freq, perif.duc, _1)) @@ -975,14 +1000,15 @@ void x300_impl::setup_radio(const size_t mb_i, const size_t i, const std::string //////////////////////////////////////////////////////////////////// // create RF frontend interfacing //////////////////////////////////////////////////////////////////// - const size_t j = (db_name == "B")? 0x2 : 0x0; - _tree->create<dboard_eeprom_t>(mb_path / "dboards" / db_name / "rx_eeprom") + const fs_path db_path = (mb_path / "dboards" / slot_name); + const size_t j = (slot_name == "B")? 0x2 : 0x0; + _tree->create<dboard_eeprom_t>(db_path / "rx_eeprom") .set(mb.db_eeproms[X300_DB0_RX_EEPROM | j]) .subscribe(boost::bind(&x300_impl::set_db_eeprom, this, mb.zpu_i2c, (0x50 | X300_DB0_RX_EEPROM | j), _1)); - _tree->create<dboard_eeprom_t>(mb_path / "dboards" / db_name / "tx_eeprom") + _tree->create<dboard_eeprom_t>(db_path / "tx_eeprom") .set(mb.db_eeproms[X300_DB0_TX_EEPROM | j]) .subscribe(boost::bind(&x300_impl::set_db_eeprom, this, mb.zpu_i2c, (0x50 | X300_DB0_TX_EEPROM | j), _1)); - _tree->create<dboard_eeprom_t>(mb_path / "dboards" / db_name / "gdb_eeprom") + _tree->create<dboard_eeprom_t>(db_path / "gdb_eeprom") .set(mb.db_eeproms[X300_DB0_GDB_EEPROM | j]) .subscribe(boost::bind(&x300_impl::set_db_eeprom, this, mb.zpu_i2c, (0x50 | X300_DB0_GDB_EEPROM | j), _1)); @@ -994,33 +1020,33 @@ void x300_impl::setup_radio(const size_t mb_i, const size_t i, const std::string db_config.tx_spi_slaveno = DB_TX_SEN; db_config.i2c = mb.zpu_i2c; db_config.clock = mb.clock; - db_config.which_rx_clk = (db_name == "A")? X300_CLOCK_WHICH_DB0_RX : X300_CLOCK_WHICH_DB1_RX; - db_config.which_tx_clk = (db_name == "A")? X300_CLOCK_WHICH_DB0_TX : X300_CLOCK_WHICH_DB1_TX; - db_config.dboard_slot = (db_name == "A")? 0 : 1; - _dboard_ifaces[db_name] = x300_make_dboard_iface(db_config); + db_config.which_rx_clk = (slot_name == "A")? X300_CLOCK_WHICH_DB0_RX : X300_CLOCK_WHICH_DB1_RX; + db_config.which_tx_clk = (slot_name == "A")? X300_CLOCK_WHICH_DB0_TX : X300_CLOCK_WHICH_DB1_TX; + db_config.dboard_slot = (slot_name == "A")? 0 : 1; + _dboard_ifaces[db_path] = x300_make_dboard_iface(db_config); //create a new dboard manager - _tree->create<dboard_iface::sptr>(mb_path / "dboards" / db_name / "iface").set(_dboard_ifaces[db_name]); - _dboard_managers[db_name] = dboard_manager::make( + _tree->create<dboard_iface::sptr>(db_path / "iface").set(_dboard_ifaces[db_path]); + _dboard_managers[db_path] = dboard_manager::make( mb.db_eeproms[X300_DB0_RX_EEPROM | j].id, mb.db_eeproms[X300_DB0_TX_EEPROM | j].id, mb.db_eeproms[X300_DB0_GDB_EEPROM | j].id, - _dboard_ifaces[db_name], - _tree->subtree(mb_path / "dboards" / db_name) + _dboard_ifaces[db_path], + _tree->subtree(db_path) ); //now that dboard is created -- register into rx antenna event - const std::string fe_name = _tree->list(mb_path / "dboards" / db_name / "rx_frontends").front(); - _tree->access<std::string>(mb_path / "dboards" / db_name / "rx_frontends" / fe_name / "antenna" / "value") - .subscribe(boost::bind(&x300_impl::update_atr_leds, this, mb.radio_perifs[i].leds, _1)); - this->update_atr_leds(mb.radio_perifs[i].leds, ""); //init anyway, even if never called + const std::string fe_name = _tree->list(db_path / "rx_frontends").front(); + _tree->access<std::string>(db_path / "rx_frontends" / fe_name / "antenna" / "value") + .subscribe(boost::bind(&x300_impl::update_atr_leds, this, mb.radio_perifs[radio_index].leds, _1)); + this->update_atr_leds(mb.radio_perifs[radio_index].leds, ""); //init anyway, even if never called //bind frontend corrections to the dboard freq props - const fs_path db_rx_fe_path = mb_path / "dboards" / db_name / "rx_frontends"; + const fs_path db_rx_fe_path = db_path / "rx_frontends"; BOOST_FOREACH(const std::string &name, _tree->list(db_rx_fe_path)) { _tree->access<double>(db_rx_fe_path / name / "freq" / "value") - .subscribe(boost::bind(&x300_impl::set_rx_fe_corrections, this, mb_path, db_name, _1)); + .subscribe(boost::bind(&x300_impl::set_rx_fe_corrections, this, mb_path, slot_name, _1)); } } @@ -1120,29 +1146,28 @@ x300_impl::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) { + if (_max_frame_sizes.send_frame_size < eth_data_rec_frame_size) { UHD_MSG(warning) << 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 + % _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) { + if (_max_frame_sizes.recv_frame_size < eth_data_rec_frame_size) { UHD_MSG(warning) << 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 + % _max_frame_sizes.recv_frame_size << std::endl << "This will negatively impact your maximum achievable sample rate." << std::endl; } - // Account for headers - size_t system_max_send_frame_size = (size_t) max_frame_sizes.send_frame_size - 64; - size_t system_max_recv_frame_size = (size_t) max_frame_sizes.recv_frame_size - 64; + size_t system_max_send_frame_size = (size_t) _max_frame_sizes.send_frame_size; + size_t system_max_recv_frame_size = (size_t) _max_frame_sizes.recv_frame_size; // Make sure frame sizes do not exceed the max available value supported by UHD default_buff_args.send_frame_size = @@ -1165,7 +1190,7 @@ x300_impl::both_xports_t x300_impl::make_transport( ? X300_ETH_DATA_NUM_FRAMES : X300_ETH_MSG_NUM_FRAMES; - //make a new transport - fpga has no idea how to talk to use on this yet + //make a new transport - fpga has no idea how to talk to us on this yet udp_zero_copy::buff_params buff_params; xports.recv = udp_zero_copy::make(mb.addr, BOOST_STRINGIZE(X300_VITA_UDP_PORT), @@ -1289,60 +1314,112 @@ void x300_impl::register_loopback_self_test(wb_iface::sptr iface) void x300_impl::set_time_source_out(mboard_members_t &mb, const bool enb) { - mb.clock_control_regs__pps_out_enb = enb? 1 : 0; + mb.clock_control_regs_pps_out_enb = enb? 1 : 0; this->update_clock_control(mb); } void x300_impl::update_clock_control(mboard_members_t &mb) { - const size_t reg = mb.clock_control_regs__clock_source - | (mb.clock_control_regs__pps_select << 2) - | (mb.clock_control_regs__pps_out_enb << 3) - | (mb.clock_control_regs__tcxo_enb << 4) - | (mb.clock_control_regs__gpsdo_pwr << 5) + const size_t reg = mb.clock_control_regs_clock_source + | (mb.clock_control_regs_pps_select << 2) + | (mb.clock_control_regs_pps_out_enb << 4) + | (mb.clock_control_regs_tcxo_enb << 5) + | (mb.clock_control_regs_gpsdo_pwr << 6) ; mb.zpu_ctrl->poke32(SR_ADDR(SET0_BASE, ZPU_SR_CLOCK_CTRL), reg); } void x300_impl::update_clock_source(mboard_members_t &mb, const std::string &source) { - mb.clock_control_regs__clock_source = 0; + mb.clock_control_regs_clock_source = 0; + mb.clock_control_regs_tcxo_enb = 0; if (source == "internal") { - mb.clock_control_regs__clock_source = 0x2; - - mb.clock_control_regs__tcxo_enb = (source == "internal")? 1 : 0; + mb.clock_control_regs_clock_source = ZPU_SR_CLOCK_CTRL_CLK_SRC_INTERNAL; + mb.clock_control_regs_tcxo_enb = 1; } else if (source == "external") { - mb.clock_control_regs__clock_source = 0x0; + mb.clock_control_regs_clock_source = ZPU_SR_CLOCK_CTRL_CLK_SRC_EXTERNAL; } else if (source == "gpsdo") { - mb.clock_control_regs__clock_source = 0x3; + mb.clock_control_regs_clock_source = ZPU_SR_CLOCK_CTRL_CLK_SRC_GPSDO; } else { throw uhd::key_error("update_clock_source: unknown source: " + source); } this->update_clock_control(mb); + + //reset the clock control + //without this, the lock time is long and can be as much as 30 seconds + mb.clock->reset_clocks(); + + /* FIXME: implement when we know the correct timeouts + * //wait for lock + * double timeout = 1.0; + * try { + * if (mb.hw_rev > 4) + * wait_for_ref_locked(mb.zpu_ctrl, timeout); + * } catch (uhd::runtime_error &e) { + * //failed to lock on reference + * throw uhd::runtime_error((boost::format("Clock failed to lock to %s source.") % source).str()); + * } + */ } void x300_impl::update_time_source(mboard_members_t &mb, const std::string &source) { if (source == "internal") { - // no action needed + mb.clock_control_regs_pps_select = ZPU_SR_CLOCK_CTRL_PPS_SRC_INTERNAL; } else if (source == "external") { - mb.clock_control_regs__pps_select = (source == "external")? 1 : 0; + mb.clock_control_regs_pps_select = ZPU_SR_CLOCK_CTRL_PPS_SRC_EXTERNAL; } else if (source == "gpsdo") { - // no action needed + mb.clock_control_regs_pps_select = ZPU_SR_CLOCK_CTRL_PPS_SRC_GPSDO; } else { throw uhd::key_error("update_time_source: unknown source: " + source); } this->update_clock_control(mb); + + //check for valid pps + if (!is_pps_present(mb.zpu_ctrl)) + { + throw uhd::runtime_error((boost::format("The %d PPS was not detected. Please check the PPS source and try again.") % source).str()); + } +} + +void x300_impl::wait_for_ref_locked(wb_iface::sptr ctrl, double timeout) +{ + boost::system_time timeout_time = boost::get_system_time() + boost::posix_time::milliseconds(timeout * 1000.0); + do + { + if (get_ref_locked(ctrl).to_bool()) + return; + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + } while (boost::get_system_time() < timeout_time); + + //failed to lock on reference + throw uhd::runtime_error("The reference clock failed to lock."); } sensor_value_t x300_impl::get_ref_locked(wb_iface::sptr ctrl) { - const bool lock = (ctrl->peek32(SR_ADDR(SET0_BASE, ZPU_RB_CLK_STATUS)) & (1 << 2)) != 0; + uint32_t clk_status = ctrl->peek32(SR_ADDR(SET0_BASE, ZPU_RB_CLK_STATUS)); + const bool lock = ((clk_status & ZPU_RB_CLK_STATUS_LMK_LOCK) != 0); return sensor_value_t("Ref", lock, "locked", "unlocked"); } +bool x300_impl::is_pps_present(wb_iface::sptr ctrl) +{ + // The ZPU_RB_CLK_STATUS_PPS_DETECT bit toggles with each rising edge of the PPS. + // We monitor it for up to 1.5 seconds looking for it to toggle. + uint32_t pps_detect = ctrl->peek32(SR_ADDR(SET0_BASE, ZPU_RB_CLK_STATUS)) & ZPU_RB_CLK_STATUS_PPS_DETECT; + for (int i = 0; i < 15; i++) + { + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + uint32_t clk_status = ctrl->peek32(SR_ADDR(SET0_BASE, ZPU_RB_CLK_STATUS)); + if (pps_detect != (clk_status & ZPU_RB_CLK_STATUS_PPS_DETECT)) + return true; + } + return false; +} + void x300_impl::set_db_eeprom(i2c_iface::sptr i2c, const size_t addr, const uhd::usrp::dboard_eeprom_t &db_eeprom) { db_eeprom.store(*i2c, addr); diff --git a/host/lib/usrp/x300/x300_impl.hpp b/host/lib/usrp/x300/x300_impl.hpp index 1fb3676a0..259ea253d 100644 --- a/host/lib/usrp/x300/x300_impl.hpp +++ b/host/lib/usrp/x300/x300_impl.hpp @@ -82,8 +82,8 @@ static const double X300_DEFAULT_SYSREF_RATE = 10e6; #define X300_XB_DST_E0 0 #define X300_XB_DST_E1 1 -#define X300_XB_DST_R0 2 -#define X300_XB_DST_R1 3 +#define X300_XB_DST_R0 2 // Radio 0 -> Slot A +#define X300_XB_DST_R1 3 // Radio 1 -> Slot B #define X300_XB_DST_CE0 4 #define X300_XB_DST_CE1 5 #define X300_XB_DST_CE2 5 @@ -191,12 +191,13 @@ private: i2c_core_100_wb32::sptr zpu_i2c; //perifs in each radio - radio_perifs_t radio_perifs[2]; + radio_perifs_t radio_perifs[2]; //!< This is hardcoded s.t. radio_perifs[0] points to slot A and [1] to B uhd::usrp::dboard_eeprom_t db_eeproms[8]; - - //per mboard frontend mapping - uhd::usrp::subdev_spec_t rx_fe_map; - uhd::usrp::subdev_spec_t tx_fe_map; + //! Return the index of a radio component, given a slot name. This means DSPs, radio_perifs + size_t get_radio_index(const std::string &slot_name) { + UHD_ASSERT_THROW(slot_name == "A" or slot_name == "B"); + return slot_name == "A" ? 0 : 1; + } //other perifs on mboard x300_clock_ctrl::sptr clock; @@ -204,14 +205,16 @@ private: gpio_core_200::sptr fp_gpio; //clock control register bits - int clock_control_regs__clock_source; - int clock_control_regs__pps_select; - int clock_control_regs__pps_out_enb; - int clock_control_regs__tcxo_enb; - int clock_control_regs__gpsdo_pwr; + int clock_control_regs_clock_source; + int clock_control_regs_pps_select; + int clock_control_regs_pps_out_enb; + int clock_control_regs_tcxo_enb; + int clock_control_regs_gpsdo_pwr; //which FPGA image is loaded std::string loaded_fpga_image; + + size_t hw_rev; }; std::vector<mboard_members_t> _mb; @@ -222,7 +225,20 @@ private: void register_loopback_self_test(uhd::wb_iface::sptr iface); - void setup_radio(const size_t, const size_t which_radio, const std::string &db_name); + /*! \brief Initialize the radio component on a given slot. + * + * Call this function once per slot (A and B) and motherboard to initialize all the radio components. + * This will: + * - Reset and init DACs and ADCs + * - Setup controls for DAC, ADC, SPI and LEDs + * - Self test ADC + * - Sync DACs (for MIMO) + * - Initialize the property tree for control objects etc. (gain, rate...) + * + * \param mb_i Motherboard index + * \param slot_name Slot name (A or B). + */ + void setup_radio(const size_t, const std::string &slot_name); size_t _sid_framer; struct sid_config_t @@ -253,7 +269,7 @@ private: size_t recv_frame_size; size_t send_frame_size; }; - frame_size_t max_frame_sizes; + frame_size_t _max_frame_sizes; /*! * Automatically determine the maximum frame size available by sending a UDP packet @@ -288,8 +304,15 @@ private: void set_rx_fe_corrections(const uhd::fs_path &mb_path, const std::string &fe_name, const double lo_freq); - void update_rx_subdev_spec(const size_t, const uhd::usrp::subdev_spec_t &spec); - void update_tx_subdev_spec(const size_t, const uhd::usrp::subdev_spec_t &spec); + /*! Update the IQ MUX settings for the radio peripheral according to given subdev spec. + * + * Also checks if the given subdev is valid for this device and updates the channel to DSP mapping. + * + * \param tx_rx "tx" or "rx", depending where you're setting the subdev spec + * \param mb_i Mainboard index number. + * \param spec Subdev spec + */ + void update_subdev_spec(const std::string &tx_rx, const size_t mb_i, const uhd::usrp::subdev_spec_t &spec); void set_tick_rate(mboard_members_t &, const double); void update_tick_rate(mboard_members_t &, const double); @@ -302,6 +325,8 @@ private: void update_time_source(mboard_members_t&, const std::string &); uhd::sensor_value_t get_ref_locked(uhd::wb_iface::sptr); + void wait_for_ref_locked(uhd::wb_iface::sptr, double timeout = 0.0); + bool is_pps_present(uhd::wb_iface::sptr); void set_db_eeprom(uhd::i2c_iface::sptr i2c, const size_t, const uhd::usrp::dboard_eeprom_t &); void set_mb_eeprom(uhd::i2c_iface::sptr i2c, const uhd::usrp::mboard_eeprom_t &); diff --git a/host/lib/usrp/x300/x300_io_impl.cpp b/host/lib/usrp/x300/x300_io_impl.cpp index 00a31b8d6..85de34a54 100644 --- a/host/lib/usrp/x300/x300_io_impl.cpp +++ b/host/lib/usrp/x300/x300_io_impl.cpp @@ -77,76 +77,52 @@ void x300_impl::update_tx_samp_rate(mboard_members_t &mb, const size_t dspno, co /*********************************************************************** * Setup dboard muxing for IQ **********************************************************************/ -void x300_impl::update_rx_subdev_spec(const size_t mb_i, const subdev_spec_t &spec) +void x300_impl::update_subdev_spec(const std::string &tx_rx, const size_t mb_i, const subdev_spec_t &spec) { + UHD_ASSERT_THROW(tx_rx == "tx" or tx_rx == "rx"); + UHD_ASSERT_THROW(mb_i < _mb.size()); const std::string mb_name = boost::lexical_cast<std::string>(mb_i); - fs_path root = "/mboards/"+mb_name+"/dboards"; + fs_path mb_root = "/mboards/" + mb_name; //sanity checking - validate_subdev_spec(_tree, spec, "rx", mb_name); + validate_subdev_spec(_tree, spec, tx_rx, mb_name); UHD_ASSERT_THROW(spec.size() <= 2); - if (spec.size() > 0) UHD_ASSERT_THROW(spec[0].db_name == "A"); - if (spec.size() > 1) UHD_ASSERT_THROW(spec[1].db_name == "B"); - - //setup mux for this spec - for (size_t i = 0; i < 2; i++) - { - //extract db name - const std::string db_name = (i == 0)? "A" : "B"; - if (i < spec.size()) UHD_ASSERT_THROW(spec[i].db_name == db_name); - - //extract fe name - std::string fe_name; - if (i < spec.size()) fe_name = spec[i].sd_name; - else fe_name = _tree->list(root / db_name / "rx_frontends").front(); - - //extract connection - const std::string conn = _tree->access<std::string>(root / db_name / "rx_frontends" / fe_name / "connection").get(); - - //swap condition - const bool fe_swapped = (conn == "QI" or conn == "Q"); - _mb[mb_i].radio_perifs[i].ddc->set_mux(conn, fe_swapped); - //see usrp/io_impl.cpp if multiple DSPs share the frontend: - _mb[mb_i].radio_perifs[i].rx_fe->set_mux(fe_swapped); + if (spec.size() == 1) { + UHD_ASSERT_THROW(spec[0].db_name == "A" || spec[0].db_name == "B"); + } + else if (spec.size() == 2) { + UHD_ASSERT_THROW( + (spec[0].db_name == "A" && spec[1].db_name == "B") || + (spec[0].db_name == "B" && spec[1].db_name == "A") + ); } - _mb[mb_i].rx_fe_map = spec; -} - -void x300_impl::update_tx_subdev_spec(const size_t mb_i, const subdev_spec_t &spec) -{ - const std::string mb_name = boost::lexical_cast<std::string>(mb_i); - fs_path root = "/mboards/"+mb_name+"/dboards"; - - //sanity checking - validate_subdev_spec(_tree, spec, "tx", mb_name); - UHD_ASSERT_THROW(spec.size() <= 2); - if (spec.size() > 0) UHD_ASSERT_THROW(spec[0].db_name == "A"); - if (spec.size() > 1) UHD_ASSERT_THROW(spec[1].db_name == "B"); - - //set the mux for this spec - for (size_t i = 0; i < 2; i++) + std::vector<size_t> chan_to_dsp_map(spec.size(), 0); + // setup mux for this spec + for (size_t i = 0; i < spec.size(); i++) { - //extract db name - const std::string db_name = (i == 0)? "A" : "B"; - if (i < spec.size()) UHD_ASSERT_THROW(spec[i].db_name == db_name); - - //extract fe name - std::string fe_name; - if (i < spec.size()) fe_name = spec[i].sd_name; - else fe_name = _tree->list(root / db_name / "tx_frontends").front(); + const int radio_idx = _mb[mb_i].get_radio_index(spec[i].db_name); + chan_to_dsp_map[i] = radio_idx; //extract connection - const std::string conn = _tree->access<std::string>(root / db_name / "tx_frontends" / fe_name / "connection").get(); - - //swap condition - _mb[mb_i].radio_perifs[i].tx_fe->set_mux(conn); + const std::string conn = _tree->access<std::string>(mb_root / "dboards" / spec[i].db_name / (tx_rx + "_frontends") / spec[i].sd_name / "connection").get(); + if (tx_rx == "tx") { + //swap condition + _mb[mb_i].radio_perifs[radio_idx].tx_fe->set_mux(conn); + } else { + //swap condition + const bool fe_swapped = (conn == "QI" or conn == "Q"); + _mb[mb_i].radio_perifs[radio_idx].ddc->set_mux(conn, fe_swapped); + //see usrp/io_impl.cpp if multiple DSPs share the frontend: + _mb[mb_i].radio_perifs[radio_idx].rx_fe->set_mux(fe_swapped); + } } - _mb[mb_i].tx_fe_map = spec; + _tree->access<std::vector<size_t> >(mb_root / (tx_rx + "_chan_dsp_mapping")).set(chan_to_dsp_map); } + /*********************************************************************** * VITA stuff **********************************************************************/ @@ -375,16 +351,28 @@ rx_streamer::sptr x300_impl::get_rx_stream(const uhd::stream_args_t &args_) boost::shared_ptr<sph::recv_packet_streamer> my_streamer; for (size_t stream_i = 0; stream_i < args.channels.size(); stream_i++) { + // Find the mainboard and subdev that corresponds to channel args.channels[stream_i] const size_t chan = args.channels[stream_i]; - size_t mb_chan = chan, mb_index = 0; - BOOST_FOREACH(mboard_members_t &mb, _mb) - { - if (mb_chan < mb.rx_fe_map.size()) break; - else mb_chan -= mb.rx_fe_map.size(); - mb_index++; + size_t mb_chan = chan, mb_index; + for (mb_index = 0; mb_index < _mb.size(); mb_index++) { + const subdev_spec_t &curr_subdev_spec = + _tree->access<subdev_spec_t>("/mboards/" + boost::lexical_cast<std::string>(mb_index) / "rx_subdev_spec").get(); + if (mb_chan < curr_subdev_spec.size()) { + break; + } else { + mb_chan -= curr_subdev_spec.size(); + } } + + // Find the DSP that corresponds to this mainboard and subdev + UHD_ASSERT_THROW(mb_index < _mb.size()); mboard_members_t &mb = _mb[mb_index]; - radio_perifs_t &perif = mb.radio_perifs[mb_chan]; + const std::vector<size_t> dsp_map = _tree->access<std::vector<size_t> >("/mboards/" + boost::lexical_cast<std::string>(mb_index) / "rx_chan_dsp_mapping") + .get(); //.at(mb_chan); + UHD_ASSERT_THROW(mb_chan < dsp_map.size()); + const size_t radio_index = dsp_map[mb_chan]; + UHD_ASSERT_THROW(radio_index < 2); + radio_perifs_t &perif = mb.radio_perifs[radio_index]; //setup the dsp transport hints (default to a large recv buff) device_addr_t device_addr = mb.recv_args; @@ -405,7 +393,7 @@ rx_streamer::sptr x300_impl::get_rx_stream(const uhd::stream_args_t &args_) } //allocate sid and create transport - uint8_t dest = (mb_chan == 0)? X300_XB_DST_R0 : X300_XB_DST_R1; + uint8_t dest = (radio_index == 0)? X300_XB_DST_R0 : X300_XB_DST_R1; boost::uint32_t data_sid; UHD_LOG << "creating rx stream " << device_addr.to_string() << std::endl; both_xports_t xport = this->make_transport(mb_index, dest, X300_RADIO_DEST_PREFIX_RX, device_addr, data_sid); @@ -419,9 +407,9 @@ rx_streamer::sptr x300_impl::get_rx_stream(const uhd::stream_args_t &args_) - sizeof(vrt::if_packet_info_t().cid) //no class id ever used - sizeof(vrt::if_packet_info_t().tsi) //no int time ever used ; - const size_t bpp = xport.recv->get_recv_frame_size() - hdr_size; - const size_t bpi = convert::get_bytes_per_item(args.otw_format); - const size_t spp = unsigned(args.args.cast<double>("spp", bpp/bpi)); + const size_t bpp = xport.recv->get_recv_frame_size() - hdr_size; // bytes per packet + const size_t bpi = convert::get_bytes_per_item(args.otw_format); // bytes per item + const size_t spp = unsigned(args.args.cast<double>("spp", bpp/bpi)); // samples per packet //make the new streamer given the samples per packet if (not my_streamer) my_streamer = boost::make_shared<sph::recv_packet_streamer>(spp); @@ -488,12 +476,12 @@ rx_streamer::sptr x300_impl::get_rx_stream(const uhd::stream_args_t &args_) ); //Store a weak pointer to prevent a streamer->x300_impl->streamer circular dependency - mb.rx_streamers[mb_chan] = boost::weak_ptr<sph::recv_packet_streamer>(my_streamer); + mb.rx_streamers[radio_index] = boost::weak_ptr<sph::recv_packet_streamer>(my_streamer); //sets all tick and samp rates on this streamer const fs_path mb_path = "/mboards/"+boost::lexical_cast<std::string>(mb_index); _tree->access<double>(mb_path / "tick_rate").update(); - _tree->access<double>(mb_path / "rx_dsps" / boost::lexical_cast<std::string>(mb_chan) / "rate" / "value").update(); + _tree->access<double>(mb_path / "rx_dsps" / boost::lexical_cast<std::string>(radio_index) / "rate" / "value").update(); } return my_streamer; @@ -552,22 +540,29 @@ tx_streamer::sptr x300_impl::get_tx_stream(const uhd::stream_args_t &args_) boost::shared_ptr<sph::send_packet_streamer> my_streamer; for (size_t stream_i = 0; stream_i < args.channels.size(); stream_i++) { + // Find the mainboard and subdev that corresponds to channel args.channels[stream_i] const size_t chan = args.channels[stream_i]; - size_t mb_chan = chan, mb_index = 0; - BOOST_FOREACH(mboard_members_t &mb, _mb) - { - if (mb_chan < mb.tx_fe_map.size()) break; - else mb_chan -= mb.tx_fe_map.size(); - mb_index++; + size_t mb_chan = chan, mb_index; + for (mb_index = 0; mb_index < _mb.size(); mb_index++) { + const subdev_spec_t &curr_subdev_spec = + _tree->access<subdev_spec_t>("/mboards/" + boost::lexical_cast<std::string>(mb_index) / "tx_subdev_spec").get(); + if (mb_chan < curr_subdev_spec.size()) { + break; + } else { + mb_chan -= curr_subdev_spec.size(); + } } + // Find the DSP that corresponds to this mainboard and subdev mboard_members_t &mb = _mb[mb_index]; - radio_perifs_t &perif = mb.radio_perifs[mb_chan]; + const size_t radio_index = _tree->access<std::vector<size_t> >("/mboards/" + boost::lexical_cast<std::string>(mb_index) / "tx_chan_dsp_mapping") + .get().at(mb_chan); + radio_perifs_t &perif = mb.radio_perifs[radio_index]; //setup the dsp transport hints (TODO) device_addr_t device_addr = mb.send_args; //allocate sid and create transport - uint8_t dest = (mb_chan == 0)? X300_XB_DST_R0 : X300_XB_DST_R1; + uint8_t dest = (radio_index == 0)? X300_XB_DST_R0 : X300_XB_DST_R1; boost::uint32_t data_sid; UHD_LOG << "creating tx stream " << device_addr.to_string() << std::endl; both_xports_t xport = this->make_transport(mb_index, dest, X300_RADIO_DEST_PREFIX_TX, device_addr, data_sid); @@ -640,12 +635,12 @@ tx_streamer::sptr x300_impl::get_tx_stream(const uhd::stream_args_t &args_) my_streamer->set_enable_trailer(false); //TODO not implemented trailer support yet //Store a weak pointer to prevent a streamer->x300_impl->streamer circular dependency - mb.tx_streamers[mb_chan] = boost::weak_ptr<sph::send_packet_streamer>(my_streamer); + mb.tx_streamers[radio_index] = boost::weak_ptr<sph::send_packet_streamer>(my_streamer); //sets all tick and samp rates on this streamer const fs_path mb_path = "/mboards/"+boost::lexical_cast<std::string>(mb_index); _tree->access<double>(mb_path / "tick_rate").update(); - _tree->access<double>(mb_path / "tx_dsps" / boost::lexical_cast<std::string>(mb_chan) / "rate" / "value").update(); + _tree->access<double>(mb_path / "tx_dsps" / boost::lexical_cast<std::string>(radio_index) / "rate" / "value").update(); } return my_streamer; diff --git a/host/lib/usrp/x300/x300_regs.hpp b/host/lib/usrp/x300/x300_regs.hpp index e4ae76a38..fb1786deb 100644 --- a/host/lib/usrp/x300/x300_regs.hpp +++ b/host/lib/usrp/x300/x300_regs.hpp @@ -68,12 +68,26 @@ localparam ZPU_SR_SPI = 32; localparam ZPU_SR_ETHINT0 = 40; localparam ZPU_SR_ETHINT1 = 56; +//clock controls +#define ZPU_SR_CLOCK_CTRL_CLK_SRC_EXTERNAL 0x00 +#define ZPU_SR_CLOCK_CTRL_CLK_SRC_INTERNAL 0x02 +#define ZPU_SR_CLOCK_CTRL_CLK_SRC_GPSDO 0x03 +#define ZPU_SR_CLOCK_CTRL_PPS_SRC_EXTERNAL 0x00 +#define ZPU_SR_CLOCK_CTRL_PPS_SRC_INTERNAL 0x02 +#define ZPU_SR_CLOCK_CTRL_PPS_SRC_GPSDO 0x03 + localparam ZPU_RB_SPI = 2; localparam ZPU_RB_CLK_STATUS = 3; localparam ZPU_RB_COMPAT_NUM = 6; localparam ZPU_RB_ETH_TYPE0 = 4; localparam ZPU_RB_ETH_TYPE1 = 5; +//clock status +#define ZPU_RB_CLK_STATUS_LMK_STATUS (0x3 << 0) +#define ZPU_RB_CLK_STATUS_LMK_LOCK (0x1 << 2) +#define ZPU_RB_CLK_STATUS_LMK_HOLDOVER (0x1 << 3) +#define ZPU_RB_CLK_STATUS_PPS_DETECT (0x1 << 4) + //spi slaves on radio #define DB_DAC_SEN (1 << 7) #define DB_ADC_SEN (1 << 6) diff --git a/host/utils/uhd_cal_rx_iq_balance.cpp b/host/utils/uhd_cal_rx_iq_balance.cpp index 5fb494114..551da7544 100644 --- a/host/utils/uhd_cal_rx_iq_balance.cpp +++ b/host/utils/uhd_cal_rx_iq_balance.cpp @@ -20,6 +20,7 @@ #include <uhd/utils/safe_main.hpp> #include <uhd/utils/paths.hpp> #include <uhd/utils/algorithm.hpp> +#include <uhd/utils/msg.hpp> #include <uhd/usrp/multi_usrp.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> @@ -93,7 +94,7 @@ static double tune_rx_and_tx(uhd::usrp::multi_usrp::sptr usrp, const double rx_l * Main **********************************************************************/ int UHD_SAFE_MAIN(int argc, char *argv[]){ - std::string args; + std::string args, subdev, serial; double tx_wave_ampl, tx_offset; double freq_start, freq_stop, freq_step; size_t nsamps; @@ -102,7 +103,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ desc.add_options() ("help", "help message") ("verbose", "enable some verbose") - ("args", po::value<std::string>(&args)->default_value(""), "device address args [default = \"\"]") + ("args", po::value<std::string>(&args)->default_value(""), "Device address args [default = \"\"]") + ("subdev", po::value<std::string>(&subdev), "Subdevice specification (default: first subdevice, often 'A')") ("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts") ("tx_offset", po::value<double>(&tx_offset)->default_value(.9344e6), "TX LO offset from the RX LO in Hz") ("freq_start", po::value<double>(&freq_start), "Frequency start in Hz (do not specify for default)") @@ -129,6 +131,15 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); + // Configure subdev + if (vm.count("subdev")) { + usrp->set_tx_subdev_spec(subdev); + usrp->set_rx_subdev_spec(subdev); + } + UHD_MSG(status) << "Running calibration for " << usrp->get_tx_subdev_name(0) << std::endl; + serial = get_serial(usrp, "tx"); + UHD_MSG(status) << "Daughterboard serial: " << serial << std::endl; + //set the antennas to cal if (not uhd::has(usrp->get_rx_antennas(), "CAL") or not uhd::has(usrp->get_tx_antennas(), "CAL")){ throw std::runtime_error("This board does not have the CAL antenna option, cannot self-calibrate."); @@ -158,6 +169,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ if (not vm.count("freq_start")) freq_start = usrp->get_rx_freq_range().start() + 50e6; if (not vm.count("freq_stop")) freq_stop = usrp->get_rx_freq_range().stop() - 50e6; + UHD_MSG(status) << boost::format("Calibration frequency range: %d MHz -> %d MHz") % (freq_start/1e6) % (freq_stop/1e6) << std::endl; for (double rx_lo_i = freq_start; rx_lo_i <= freq_stop; rx_lo_i += freq_step){ const double rx_lo = tune_rx_and_tx(usrp, rx_lo_i, tx_offset); @@ -238,7 +250,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ threads.interrupt_all(); threads.join_all(); - store_results(usrp, results, "RX", "rx", "iq"); + store_results(results, "RX", "rx", "iq", serial); return EXIT_SUCCESS; } diff --git a/host/utils/uhd_cal_tx_dc_offset.cpp b/host/utils/uhd_cal_tx_dc_offset.cpp index c9cf757f4..eb82db826 100644 --- a/host/utils/uhd_cal_tx_dc_offset.cpp +++ b/host/utils/uhd_cal_tx_dc_offset.cpp @@ -20,6 +20,7 @@ #include <uhd/utils/safe_main.hpp> #include <uhd/utils/paths.hpp> #include <uhd/utils/algorithm.hpp> +#include <uhd/utils/msg.hpp> #include <uhd/usrp/multi_usrp.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> @@ -94,7 +95,7 @@ static double tune_rx_and_tx(uhd::usrp::multi_usrp::sptr usrp, const double tx_l * Main **********************************************************************/ int UHD_SAFE_MAIN(int argc, char *argv[]){ - std::string args; + std::string args, subdev, serial; double tx_wave_freq, tx_wave_ampl, rx_offset; double freq_start, freq_stop, freq_step; size_t nsamps; @@ -104,6 +105,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("help", "help message") ("verbose", "enable some verbose") ("args", po::value<std::string>(&args)->default_value(""), "device address args [default = \"\"]") + ("subdev", po::value<std::string>(&subdev), "Subdevice specification (default: first subdevice, often 'A')") ("tx_wave_freq", po::value<double>(&tx_wave_freq)->default_value(507.123e3), "Transmit wave frequency in Hz") ("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts") ("rx_offset", po::value<double>(&rx_offset)->default_value(.9344e6), "RX LO offset from the TX LO in Hz") @@ -131,6 +133,15 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); + // Configure subdev + if (vm.count("subdev")) { + usrp->set_tx_subdev_spec(subdev); + usrp->set_rx_subdev_spec(subdev); + } + UHD_MSG(status) << "Running calibration for " << usrp->get_tx_subdev_name(0) << std::endl; + serial = get_serial(usrp, "tx"); + UHD_MSG(status) << "Daughterboard serial: " << serial << std::endl; + //set the antennas to cal if (not uhd::has(usrp->get_rx_antennas(), "CAL") or not uhd::has(usrp->get_tx_antennas(), "CAL")){ throw std::runtime_error("This board does not have the CAL antenna option, cannot self-calibrate."); @@ -160,6 +171,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ if (not vm.count("freq_start")) freq_start = usrp->get_tx_freq_range().start() + 50e6; if (not vm.count("freq_stop")) freq_stop = usrp->get_tx_freq_range().stop() - 50e6; + UHD_MSG(status) << boost::format("Calibration frequency range: %d MHz -> %d MHz") % (freq_start/1e6) % (freq_stop/1e6) << std::endl; for (double tx_lo_i = freq_start; tx_lo_i <= freq_stop; tx_lo_i += freq_step){ const double tx_lo = tune_rx_and_tx(usrp, tx_lo_i, rx_offset); @@ -235,7 +247,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ threads.interrupt_all(); threads.join_all(); - store_results(usrp, results, "TX", "tx", "dc"); + store_results(results, "TX", "tx", "dc", serial); return EXIT_SUCCESS; } diff --git a/host/utils/uhd_cal_tx_iq_balance.cpp b/host/utils/uhd_cal_tx_iq_balance.cpp index 20d018edf..786aac061 100644 --- a/host/utils/uhd_cal_tx_iq_balance.cpp +++ b/host/utils/uhd_cal_tx_iq_balance.cpp @@ -20,6 +20,7 @@ #include <uhd/utils/safe_main.hpp> #include <uhd/utils/paths.hpp> #include <uhd/utils/algorithm.hpp> +#include <uhd/utils/msg.hpp> #include <uhd/usrp/multi_usrp.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> @@ -95,7 +96,7 @@ static double tune_rx_and_tx(uhd::usrp::multi_usrp::sptr usrp, const double tx_l * Main **********************************************************************/ int UHD_SAFE_MAIN(int argc, char *argv[]){ - std::string args; + std::string args, subdev, serial; double tx_wave_freq, tx_wave_ampl, rx_offset; double freq_start, freq_stop, freq_step; size_t nsamps; @@ -105,6 +106,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ ("help", "help message") ("verbose", "enable some verbose") ("args", po::value<std::string>(&args)->default_value(""), "device address args [default = \"\"]") + ("subdev", po::value<std::string>(&subdev), "Subdevice specification (default: first subdevice, often 'A')") ("tx_wave_freq", po::value<double>(&tx_wave_freq)->default_value(507.123e3), "Transmit wave frequency in Hz") ("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts") ("rx_offset", po::value<double>(&rx_offset)->default_value(.9344e6), "RX LO offset from the TX LO in Hz") @@ -122,7 +124,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ if (vm.count("help")){ std::cout << boost::format("USRP Generate TX IQ Balance Calibration Table %s") % desc << std::endl; std::cout << - "This application measures leakage between RX and TX on an XCVR daughterboard to self-calibrate.\n" + "This application measures leakage between RX and TX on a daughterboard to self-calibrate.\n" << std::endl; return EXIT_FAILURE; } @@ -132,6 +134,15 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl; uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); + // Configure subdev + if (vm.count("subdev")) { + usrp->set_tx_subdev_spec(subdev); + usrp->set_rx_subdev_spec(subdev); + } + UHD_MSG(status) << "Running calibration for " << usrp->get_tx_subdev_name(0) << std::endl; + serial = get_serial(usrp, "tx"); + UHD_MSG(status) << "Daughterboard serial: " << serial << std::endl; + //set the antennas to cal if (not uhd::has(usrp->get_rx_antennas(), "CAL") or not uhd::has(usrp->get_tx_antennas(), "CAL")){ throw std::runtime_error("This board does not have the CAL antenna option, cannot self-calibrate."); @@ -161,6 +172,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ if (not vm.count("freq_start")) freq_start = usrp->get_tx_freq_range().start() + 50e6; if (not vm.count("freq_stop")) freq_stop = usrp->get_tx_freq_range().stop() - 50e6; + UHD_MSG(status) << boost::format("Calibration frequency range: %d MHz -> %d MHz") % (freq_start/1e6) % (freq_stop/1e6) << std::endl; for (double tx_lo_i = freq_start; tx_lo_i <= freq_stop; tx_lo_i += freq_step){ const double tx_lo = tune_rx_and_tx(usrp, tx_lo_i, rx_offset); @@ -241,7 +253,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ threads.interrupt_all(); threads.join_all(); - store_results(usrp, results, "TX", "tx", "iq"); + store_results(results, "TX", "tx", "iq", serial); return EXIT_SUCCESS; } + diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp index 40626dfaa..5aff5e22f 100644 --- a/host/utils/usrp_cal_utils.hpp +++ b/host/utils/usrp_cal_utils.hpp @@ -179,27 +179,37 @@ static inline void write_samples_to_file( outfile.close(); } + /*********************************************************************** - * Store data to file + * Retrieve d'board serial **********************************************************************/ -static void store_results( +static std::string get_serial( uhd::usrp::multi_usrp::sptr usrp, - const std::vector<result_t> &results, - const std::string &XX, - const std::string &xx, - const std::string &what + const std::string &tx_rx ){ - //extract eeprom serial uhd::property_tree::sptr tree = usrp->get_device()->get_tree(); - const uhd::fs_path db_path = "/mboards/0/dboards/A/" + xx + "_eeprom"; + uhd::usrp::subdev_spec_t subdev_spec = usrp->get_rx_subdev_spec(); + const uhd::fs_path db_path = "/mboards/0/dboards/" + subdev_spec[0].db_name + "/" + tx_rx + "_eeprom"; const uhd::usrp::dboard_eeprom_t db_eeprom = tree->access<uhd::usrp::dboard_eeprom_t>(db_path).get(); + return db_eeprom.serial; +} +/*********************************************************************** + * Store data to file + **********************************************************************/ +static void store_results( + const std::vector<result_t> &results, + const std::string &XX, // "TX" or "RX" + const std::string &xx, // "tx" or "rx" + const std::string &what, // Type of test, e.g. "iq", + const std::string &serial +){ //make the calibration file path fs::path cal_data_path = fs::path(uhd::get_app_path()) / ".uhd"; fs::create_directory(cal_data_path); cal_data_path = cal_data_path / "cal"; fs::create_directory(cal_data_path); - cal_data_path = cal_data_path / str(boost::format("%s_%s_cal_v0.2_%s.csv") % xx % what % db_eeprom.serial); + cal_data_path = cal_data_path / str(boost::format("%s_%s_cal_v0.2_%s.csv") % xx % what % serial); if (fs::exists(cal_data_path)){ fs::rename(cal_data_path, cal_data_path.string() + str(boost::format(".%d") % time(NULL))); } @@ -207,7 +217,7 @@ static void store_results( //fill the calibration file std::ofstream cal_data(cal_data_path.string().c_str()); cal_data << boost::format("name, %s Frontend Calibration\n") % XX; - cal_data << boost::format("serial, %s\n") % db_eeprom.serial; + cal_data << boost::format("serial, %s\n") % serial; cal_data << boost::format("timestamp, %d\n") % time(NULL); cal_data << boost::format("version, 0, 1\n"); cal_data << boost::format("DATA STARTS HERE\n"); @@ -259,3 +269,4 @@ static void capture_samples( throw std::runtime_error("did not get all the samples requested"); } } + |