diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-01-17 10:00:47 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-01-17 10:00:47 -0800 |
commit | 52ca2e0b8045c254c2be1911e77e8bd3d94ceeab (patch) | |
tree | c7e1a93eeadd65bb13db1aa68974da495114f046 /host/lib | |
parent | 46febf986ae5e89ebb0c350fd9aa42aaa6383997 (diff) | |
parent | 95ff7e859d57829e428d41d7746e28c228b983ba (diff) | |
download | uhd-52ca2e0b8045c254c2be1911e77e8bd3d94ceeab.tar.gz uhd-52ca2e0b8045c254c2be1911e77e8bd3d94ceeab.tar.bz2 uhd-52ca2e0b8045c254c2be1911e77e8bd3d94ceeab.zip |
Merge branch 'maint'
Diffstat (limited to 'host/lib')
24 files changed, 418 insertions, 68 deletions
diff --git a/host/lib/experts/expert_container.cpp b/host/lib/experts/expert_container.cpp index 1d945aa42..b9c78f9f5 100644 --- a/host/lib/experts/expert_container.cpp +++ b/host/lib/experts/expert_container.cpp @@ -294,11 +294,11 @@ protected: EX_LOG(0, str(boost::format("add_data_node(%s)") % data_node->get_name())); if (data_node->get_class() == CLASS_WORKER) { throw uhd::runtime_error("Supplied node " + data_node->get_name() + " is not a data/property node."); - delete data_node; + // Throw leaves data_node undeleted } if (_datanode_map.find(data_node->get_name()) != _datanode_map.end()) { throw uhd::runtime_error("Data node with name " + data_node->get_name() + " already exists"); - delete data_node; + // Throw leaves data node undeleted } try { @@ -335,11 +335,9 @@ protected: EX_LOG(0, str(boost::format("add_worker(%s)") % worker->get_name())); if (worker->get_class() != CLASS_WORKER) { throw uhd::runtime_error("Supplied node " + worker->get_name() + " is not a worker node."); - delete worker; } if (_worker_map.find(worker->get_name()) != _worker_map.end()) { throw uhd::runtime_error("Resolver with name " + worker->get_name() + " already exists."); - delete worker; } try { diff --git a/host/lib/rfnoc/block_ctrl_base.cpp b/host/lib/rfnoc/block_ctrl_base.cpp index fa4928a69..4ee577891 100644 --- a/host/lib/rfnoc/block_ctrl_base.cpp +++ b/host/lib/rfnoc/block_ctrl_base.cpp @@ -504,7 +504,6 @@ std::string block_ctrl_base::get_arg(const std::string &key, const size_t port) } UHD_THROW_INVALID_CODE_PATH(); - return ""; } std::string block_ctrl_base::get_arg_type(const std::string &key, const size_t port) const diff --git a/host/lib/rfnoc/nocscript/function_table.cpp b/host/lib/rfnoc/nocscript/function_table.cpp index bebceb8dc..a4e36c1a1 100644 --- a/host/lib/rfnoc/nocscript/function_table.cpp +++ b/host/lib/rfnoc/nocscript/function_table.cpp @@ -31,7 +31,7 @@ class function_table_impl : public function_table expression::type_t return_type; function_ptr function; - function_info() {}; + function_info(): return_type(expression::TYPE_INT) {}; function_info(const expression::type_t return_type_, const function_ptr &function_) : return_type(return_type_), function(function_) {}; diff --git a/host/lib/rfnoc/xports.hpp b/host/lib/rfnoc/xports.hpp index 1ce05c6c8..7bd4f2fc8 100644 --- a/host/lib/rfnoc/xports.hpp +++ b/host/lib/rfnoc/xports.hpp @@ -25,6 +25,7 @@ namespace uhd { */ struct both_xports_t { + both_xports_t(): recv_buff_size(0), send_buff_size(0) {} uhd::transport::zero_copy_if::sptr recv; uhd::transport::zero_copy_if::sptr send; size_t recv_buff_size; diff --git a/host/lib/usrp/common/ad9361_driver/ad9361_device.cpp b/host/lib/usrp/common/ad9361_driver/ad9361_device.cpp index 45ebf78bf..e2ed2c77d 100644 --- a/host/lib/usrp/common/ad9361_driver/ad9361_device.cpp +++ b/host/lib/usrp/common/ad9361_driver/ad9361_device.cpp @@ -491,8 +491,8 @@ double ad9361_device_t::_calibrate_secondary_tx_filter(double req_rfbw) } else if ((bbbw_mhz * 2) > 24) { reg0d0 = 0x57; } else { - throw uhd::runtime_error("[ad9361_device_t] Cal2ndTxFil: INVALID_CODE_PATH bad bbbw_mhz"); reg0d0 = 0x00; + throw uhd::runtime_error("[ad9361_device_t] Cal2ndTxFil: INVALID_CODE_PATH bad bbbw_mhz"); } /* Translate resistor values to register settings. */ @@ -996,8 +996,8 @@ void ad9361_device_t::_program_gain_table() { gain_table = gain_table_4000mhz_to_6000mhz; new_gain_table = 3; } else { - throw uhd::runtime_error("[ad9361_device_t] Wrong _rx_freq value"); new_gain_table = 1; + throw uhd::runtime_error("[ad9361_device_t] Wrong _rx_freq value"); } /* Only re-program the gain table if there has been a band change. */ diff --git a/host/lib/usrp/common/ad9361_driver/ad9361_device.h b/host/lib/usrp/common/ad9361_driver/ad9361_device.h index ae065d78e..f3d24d6b9 100644 --- a/host/lib/usrp/common/ad9361_driver/ad9361_device.h +++ b/host/lib/usrp/common/ad9361_driver/ad9361_device.h @@ -40,7 +40,15 @@ public: enum chain_t { CHAIN_1, CHAIN_2, CHAIN_BOTH }; ad9361_device_t(ad9361_params::sptr client, ad9361_io::sptr io_iface) : - _client_params(client), _io_iface(io_iface) { + _client_params(client), _io_iface(io_iface), + _bbpll_freq(0.0), _adcclock_freq(0.0), _req_clock_rate(0.0), + _req_coreclk(0.0), _rx_bbf_tunediv(0), _curr_gain_table(0), + _rx1_gain(0.0), _rx2_gain(0.0), _tx1_gain(0.0), _tx2_gain(0.0), + _tfir_factor(0), _rfir_factor(0), + _rx1_agc_mode(GAIN_MODE_MANUAL), _rx2_agc_mode(GAIN_MODE_MANUAL), + _rx1_agc_enable(false), _rx2_agc_enable(false), + _use_dc_offset_tracking(false), _use_iq_balance_tracking(false) + { /* * This Boost.Assign to_container() workaround is necessary because STL containers @@ -213,7 +221,11 @@ private: //Methods void _set_filter_lp_tia_sec(direction_t direction, filter_info_base::sptr filter); private: //Members - typedef struct { + struct chip_regs_t + { + chip_regs_t(): + vcodivs(0), inputsel(0), rxfilt(0), txfilt(0), + bbpll(0), bbftune_config(0), bbftune_mode(0) {} uint8_t vcodivs; uint8_t inputsel; uint8_t rxfilt; @@ -221,7 +233,7 @@ private: //Members uint8_t bbpll; uint8_t bbftune_config; uint8_t bbftune_mode; - } chip_regs_t; + }; struct filter_query_helper { diff --git a/host/lib/usrp/cores/rx_frontend_core_3000.cpp b/host/lib/usrp/cores/rx_frontend_core_3000.cpp index 1c4674a8a..e7d25eb8c 100644 --- a/host/lib/usrp/cores/rx_frontend_core_3000.cpp +++ b/host/lib/usrp/cores/rx_frontend_core_3000.cpp @@ -170,7 +170,6 @@ public: default: return _adc_rate; } - return _adc_rate; } private: diff --git a/host/lib/usrp/dboard/twinrx/twinrx_gain_tables.cpp b/host/lib/usrp/dboard/twinrx/twinrx_gain_tables.cpp index 5cc8b49f3..783ded8cc 100644 --- a/host/lib/usrp/dboard/twinrx/twinrx_gain_tables.cpp +++ b/host/lib/usrp/dboard/twinrx/twinrx_gain_tables.cpp @@ -836,7 +836,6 @@ const twinrx_gain_table twinrx_gain_table::lookup_table } } throw runtime_error("NO GAIN TABLE SELECTED"); - return twinrx_gain_table(HIGHBAND1_TABLE); } const twinrx_gain_config_t& twinrx_gain_table::find_by_index(size_t index) const { diff --git a/host/lib/usrp/device3/device3_io_impl.cpp b/host/lib/usrp/device3/device3_io_impl.cpp index b3a34afe3..bb98b1031 100644 --- a/host/lib/usrp/device3/device3_io_impl.cpp +++ b/host/lib/usrp/device3/device3_io_impl.cpp @@ -38,7 +38,7 @@ using namespace uhd; using namespace uhd::usrp; using namespace uhd::transport; -//! CVITA uses 12-Bit sequence numbers +//! CHDR uses 12-Bit sequence numbers static const uint32_t HW_SEQ_NUM_MASK = 0xfff; diff --git a/host/lib/usrp/e300/e300_global_regs.hpp b/host/lib/usrp/e300/e300_global_regs.hpp index 3b6b26239..c56cff298 100644 --- a/host/lib/usrp/e300/e300_global_regs.hpp +++ b/host/lib/usrp/e300/e300_global_regs.hpp @@ -24,6 +24,7 @@ namespace uhd { namespace usrp { namespace e300 { struct global_regs_transaction_t { + global_regs_transaction_t(): is_poke(0), addr(0), data(0), pad(0) {} uint32_t is_poke; uint32_t addr; uint32_t data; diff --git a/host/lib/usrp/e300/e300_i2c.hpp b/host/lib/usrp/e300/e300_i2c.hpp index 98a1f80aa..1c5e06bba 100644 --- a/host/lib/usrp/e300/e300_i2c.hpp +++ b/host/lib/usrp/e300/e300_i2c.hpp @@ -27,6 +27,7 @@ namespace uhd { namespace usrp { namespace e300 { struct i2c_transaction_t { + i2c_transaction_t(): reg(0), addr(0), data(0), type(0) {}; uint16_t reg; uint8_t addr; uint8_t data; diff --git a/host/lib/usrp/e300/e300_impl.hpp b/host/lib/usrp/e300/e300_impl.hpp index 632424438..50d78fdd4 100644 --- a/host/lib/usrp/e300/e300_impl.hpp +++ b/host/lib/usrp/e300/e300_impl.hpp @@ -189,7 +189,8 @@ private: // types { gpio_t() : pps_sel(global_regs::PPS_INT), mimo(0), codec_arst(0), tx_bandsels(0), - rx_bandsel_a(0), rx_bandsel_b(0), rx_bandsel_c(0) + rx_bandsel_a(0), rx_bandsel_b(0), rx_bandsel_c(0), + time_sync(0) {} uint32_t pps_sel; diff --git a/host/lib/usrp/mboard_eeprom.cpp b/host/lib/usrp/mboard_eeprom.cpp index 5c0014a89..0e6cb8574 100644 --- a/host/lib/usrp/mboard_eeprom.cpp +++ b/host/lib/usrp/mboard_eeprom.cpp @@ -235,52 +235,88 @@ struct x300_eeprom_map static void load_x300(mboard_eeprom_t &mb_eeprom, i2c_iface &iface) { + byte_vector_t bytes = iface.read_eeprom(X300_EEPROM_ADDR, 0, sizeof (struct x300_eeprom_map)); + + if (bytes.size() == 0) + { + return; + } + //extract the revision number mb_eeprom["revision"] = uint16_bytes_to_string( - iface.read_eeprom(X300_EEPROM_ADDR, offsetof(x300_eeprom_map, revision), 2) + byte_vector_t( + bytes.begin() + offsetof(x300_eeprom_map, revision), + bytes.begin() + (offsetof(x300_eeprom_map, revision)+2)) ); //extract the revision compat number mb_eeprom["revision_compat"] = uint16_bytes_to_string( - iface.read_eeprom(X300_EEPROM_ADDR, offsetof(x300_eeprom_map, revision_compat), 2) + byte_vector_t( + bytes.begin() + offsetof(x300_eeprom_map, revision_compat), + bytes.begin() + (offsetof(x300_eeprom_map, revision_compat)+2)) ); //extract the product code mb_eeprom["product"] = uint16_bytes_to_string( - iface.read_eeprom(X300_EEPROM_ADDR, offsetof(x300_eeprom_map, product), 2) + byte_vector_t( + bytes.begin() + offsetof(x300_eeprom_map, product), + bytes.begin() + (offsetof(x300_eeprom_map, product)+2)) ); //extract the mac addresses - mb_eeprom["mac-addr0"] = mac_addr_t::from_bytes(iface.read_eeprom( - X300_EEPROM_ADDR, offsetof(x300_eeprom_map, mac_addr0), 6 - )).to_string(); - mb_eeprom["mac-addr1"] = mac_addr_t::from_bytes(iface.read_eeprom( - X300_EEPROM_ADDR, offsetof(x300_eeprom_map, mac_addr1), 6 - )).to_string(); + mb_eeprom["mac-addr0"] = mac_addr_t::from_bytes( + byte_vector_t( + bytes.begin() + offsetof(x300_eeprom_map, mac_addr0), + bytes.begin() + (offsetof(x300_eeprom_map, mac_addr0)+6)) + ).to_string(); + mb_eeprom["mac-addr1"] = mac_addr_t::from_bytes( + byte_vector_t( + bytes.begin() + offsetof(x300_eeprom_map, mac_addr1), + bytes.begin() + (offsetof(x300_eeprom_map, mac_addr1)+6)) + ).to_string(); //extract the ip addresses boost::asio::ip::address_v4::bytes_type ip_addr_bytes; - byte_copy(iface.read_eeprom(X300_EEPROM_ADDR, offsetof(x300_eeprom_map, gateway), 4), ip_addr_bytes); + byte_copy( + byte_vector_t( + bytes.begin() + offsetof(x300_eeprom_map, gateway), + bytes.begin() + (offsetof(x300_eeprom_map, gateway)+4)), + ip_addr_bytes + ); mb_eeprom["gateway"] = boost::asio::ip::address_v4(ip_addr_bytes).to_string(); for (size_t i = 0; i < 4; i++) { const std::string n(1, i+'0'); - byte_copy(iface.read_eeprom(X300_EEPROM_ADDR, offsetof(x300_eeprom_map, ip_addr)+(i*4), 4), ip_addr_bytes); + byte_copy( + byte_vector_t( + bytes.begin() + (offsetof(x300_eeprom_map, ip_addr)+(i*4)), + bytes.begin() + (offsetof(x300_eeprom_map, ip_addr)+(i*4)+4)), + ip_addr_bytes + ); mb_eeprom["ip-addr"+n] = boost::asio::ip::address_v4(ip_addr_bytes).to_string(); - byte_copy(iface.read_eeprom(X300_EEPROM_ADDR, offsetof(x300_eeprom_map, subnet)+(i*4), 4), ip_addr_bytes); + byte_copy( + byte_vector_t( + bytes.begin() + (offsetof(x300_eeprom_map, subnet)+(i*4)), + bytes.begin() + (offsetof(x300_eeprom_map, subnet)+(i*4)+4)), + ip_addr_bytes + ); mb_eeprom["subnet"+n] = boost::asio::ip::address_v4(ip_addr_bytes).to_string(); } //extract the serial - mb_eeprom["serial"] = bytes_to_string(iface.read_eeprom( - X300_EEPROM_ADDR, offsetof(x300_eeprom_map, serial), SERIAL_LEN - )); + mb_eeprom["serial"] = bytes_to_string( + byte_vector_t( + bytes.begin() + offsetof(x300_eeprom_map, serial), + bytes.begin() + (offsetof(x300_eeprom_map, serial)+SERIAL_LEN)) + ); //extract the name - mb_eeprom["name"] = bytes_to_string(iface.read_eeprom( - X300_EEPROM_ADDR, offsetof(x300_eeprom_map, name), NAME_MAX_LEN - )); + mb_eeprom["name"] = bytes_to_string( + byte_vector_t( + bytes.begin() + offsetof(x300_eeprom_map, name), + bytes.begin() + (offsetof(x300_eeprom_map, name)+NAME_MAX_LEN)) + ); } static void store_x300(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface) diff --git a/host/lib/usrp/n230/n230_resource_manager.cpp b/host/lib/usrp/n230/n230_resource_manager.cpp index 826db5ed2..b96de542a 100644 --- a/host/lib/usrp/n230/n230_resource_manager.cpp +++ b/host/lib/usrp/n230/n230_resource_manager.cpp @@ -487,10 +487,11 @@ bool n230_resource_manager::_radio_data_loopback_self_test(wb_iface::sptr iface) const uint32_t rb_tx = uint32_t(rb_word64 >> 32); const uint32_t rb_rx = uint32_t(rb_word64 & 0xffffffff); test_fail = word32 != rb_tx or word32 != rb_rx; - if (test_fail) + if (test_fail){ UHD_MSG(fastpath) << boost::format("mismatch (exp:%x, got:%x and %x)... ") % word32 % rb_tx % rb_rx; break; //exit loop on any failure } + } /* Zero out the idle data. */ iface->poke32(fpga::sr_addr(fpga::SR_RADIO_CODEC_IDLE), 0); diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index 9fde9a626..1dafe5721 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -182,7 +182,7 @@ void usrp2_dboard_iface::set_clock_enabled(unit_t unit, bool enb){ switch(unit){ case UNIT_RX: _clock_ctrl->enable_rx_dboard_clock(enb); return; case UNIT_TX: _clock_ctrl->enable_tx_dboard_clock(enb); return; - case UNIT_BOTH: set_clock_enabled(UNIT_RX, enb); set_clock_enabled(UNIT_TX, enb); return; + default: UHD_THROW_INVALID_CODE_PATH(); } } diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index 199436fa2..224519944 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -433,7 +433,7 @@ rx_streamer::sptr usrp2_impl::get_rx_stream(const uhd::stream_args_t &args_){ ; const size_t bpp = _mbc[_mbc.keys().front()].rx_dsp_xports[0]->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 spp = args.args.cast<size_t>("spp", bpp/bpi); //make the new streamer given the samples per packet boost::shared_ptr<sph::recv_packet_streamer> my_streamer = boost::make_shared<sph::recv_packet_streamer>(spp); diff --git a/host/lib/usrp/usrp2/n200_image_loader.cpp b/host/lib/usrp/usrp2/n200_image_loader.cpp index 16cc7b08a..c68484600 100644 --- a/host/lib/usrp/usrp2/n200_image_loader.cpp +++ b/host/lib/usrp/usrp2/n200_image_loader.cpp @@ -324,7 +324,7 @@ static void n200_validate_fpga_image(n200_session_t &session){ image_file.seekg(0, std::ios::beg); image_file.read((char*)test_bytes, 63); bool is_good = false; - for(int i = 0; i < 63; i++){ + for(int i = 0; i < 62; i++){ if(test_bytes[i] == 255) continue; else if(test_bytes[i] == 170 and test_bytes[i+1] == 153){ diff --git a/host/lib/usrp/x300/CMakeLists.txt b/host/lib/usrp/x300/CMakeLists.txt index ea237b008..5f8e83e1c 100644 --- a/host/lib/usrp/x300/CMakeLists.txt +++ b/host/lib/usrp/x300/CMakeLists.txt @@ -34,6 +34,7 @@ IF(ENABLE_X300) ${CMAKE_CURRENT_SOURCE_DIR}/x300_dboard_iface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/x300_clock_ctrl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/x300_image_loader.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/x300_mb_eeprom.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cdecode.c ) ENDIF(ENABLE_X300) diff --git a/host/lib/usrp/x300/x300_fw_common.h b/host/lib/usrp/x300/x300_fw_common.h index aae0f769c..b83449666 100644 --- a/host/lib/usrp/x300/x300_fw_common.h +++ b/host/lib/usrp/x300/x300_fw_common.h @@ -32,7 +32,7 @@ extern "C" { #define X300_REVISION_COMPAT 7 #define X300_REVISION_MIN 2 #define X300_FW_COMPAT_MAJOR 5 -#define X300_FW_COMPAT_MINOR 0 +#define X300_FW_COMPAT_MINOR 1 #define X300_FPGA_COMPAT_MAJOR 0x21 //shared memory sections - in between the stack and the program space @@ -49,6 +49,9 @@ extern "C" { #define X300_FW_SHMEM_UART_WORDS32 10 #define X300_FW_SHMEM_ROUTE_MAP_ADDR 11 #define X300_FW_SHMEM_ROUTE_MAP_LEN 12 +#define X300_FW_SHMEM_IDENT 13 // (13-39) EEPROM values in use +#define X300_FW_SHMEM_DEBUG 128 +#define X300_FW_SHMEM_ADDR(offset) X300_FW_SHMEM_BASE + (4 * (offset)) #define X300_FW_NUM_BYTES (1 << 15) //64k #define X300_FW_COMMS_MTU (1 << 13) //8k @@ -94,6 +97,30 @@ extern "C" { typedef struct { + //indentifying numbers + unsigned char revision[2]; + unsigned char product[2]; + uint8_t _pad0[4]; + + //all the mac addrs + uint8_t mac_addr0[6]; + uint8_t _pad1[2]; + uint8_t mac_addr1[6]; + uint8_t _pad2[2]; + + //all the IP addrs + uint32_t gateway; + uint32_t subnet[4]; + uint32_t ip_addr[4]; + uint8_t _pad3[16]; + + //names and serials + unsigned char name[23]; + unsigned char serial[9]; +} x300_eeprom_map_t; + +typedef struct +{ uint32_t flags; uint32_t sequence; uint32_t addr; diff --git a/host/lib/usrp/x300/x300_impl.cpp b/host/lib/usrp/x300/x300_impl.cpp index cd85ea141..83c687637 100644 --- a/host/lib/usrp/x300/x300_impl.cpp +++ b/host/lib/usrp/x300/x300_impl.cpp @@ -18,6 +18,7 @@ #include "x300_impl.hpp" #include "x300_lvbitx.hpp" #include "x310_lvbitx.hpp" +#include "x300_mb_eeprom.hpp" #include "apply_corrections.hpp" #include <boost/algorithm/string.hpp> #include <boost/asio.hpp> @@ -121,12 +122,16 @@ static device_addrs_t x300_find_with_addr(const device_addr_t &hint) false /* Suppress timeout errors */ ); - if (x300_impl::is_claimed(zpu_ctrl)) continue; //claimed by another process new_addr["fpga"] = get_fpga_option(zpu_ctrl); i2c_core_100_wb32::sptr zpu_i2c = i2c_core_100_wb32::make(zpu_ctrl, I2C1_BASE); - i2c_iface::sptr eeprom16 = zpu_i2c->eeprom16(); - const mboard_eeprom_t mb_eeprom(*eeprom16, "X300"); + x300_mb_eeprom_iface::sptr eeprom_iface = x300_mb_eeprom_iface::make(zpu_ctrl, zpu_i2c); + const mboard_eeprom_t mb_eeprom(*eeprom_iface, "X300"); + if (mb_eeprom.size() == 0 or x300_impl::claim_status(zpu_ctrl) == x300_impl::CLAIMED_BY_OTHER) + { + // Skip device claimed by another process + continue; + } new_addr["name"] = mb_eeprom["name"]; new_addr["serial"] = mb_eeprom["serial"]; switch (x300_impl::get_mb_type_from_eeprom(mb_eeprom)) { @@ -221,7 +226,6 @@ static device_addrs_t x300_find_pcie(const device_addr_t &hint, bool explicit_qu //We don't put this zpu_ctrl in the registry because we need //a persistent niriok_proxy associated with the object } - if (x300_impl::is_claimed(zpu_ctrl)) continue; //claimed by another process //Attempt to autodetect the FPGA type if (not hint.has_key("fpga")) { @@ -229,8 +233,13 @@ static device_addrs_t x300_find_pcie(const device_addr_t &hint, bool explicit_qu } i2c_core_100_wb32::sptr zpu_i2c = i2c_core_100_wb32::make(zpu_ctrl, I2C1_BASE); - i2c_iface::sptr eeprom16 = zpu_i2c->eeprom16(); - const mboard_eeprom_t mb_eeprom(*eeprom16, "X300"); + x300_mb_eeprom_iface::sptr eeprom_iface = x300_mb_eeprom_iface::make(zpu_ctrl, zpu_i2c); + const mboard_eeprom_t mb_eeprom(*eeprom_iface, "X300"); + if (mb_eeprom.size() == 0 or x300_impl::claim_status(zpu_ctrl) == x300_impl::CLAIMED_BY_OTHER) + { + // Skip device claimed by another process + continue; + } new_addr["name"] = mb_eeprom["name"]; new_addr["serial"] = mb_eeprom["serial"]; } @@ -307,12 +316,7 @@ device_addrs_t x300_find(const device_addr_t &hint_) { UHD_MSG(error) << "X300 Network discovery unknown error " << std::endl; } - BOOST_FOREACH(const device_addr_t &reply_addr, reply_addrs) - { - device_addrs_t new_addrs = x300_find_with_addr(reply_addr); - addrs.insert(addrs.begin(), new_addrs.begin(), new_addrs.end()); - } - return addrs; + return reply_addrs; } if (!hint.has_key("resource")) @@ -671,6 +675,10 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) mb.get_pri_eth().addr, BOOST_STRINGIZE(X300_FW_COMMS_UDP_PORT))); } + // Claim device + if (not try_to_claim(mb.zpu_ctrl)) { + throw uhd::runtime_error("Failed to claim device"); + } mb.claimer_task = uhd::task::make(boost::bind(&x300_impl::claimer_loop, this, mb.zpu_ctrl)); //extract the FW path for the X300 @@ -726,7 +734,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) // setup the mboard eeprom //////////////////////////////////////////////////////////////////// UHD_MSG(status) << "Loading values from EEPROM..." << std::endl; - i2c_iface::sptr eeprom16 = mb.zpu_i2c->eeprom16(); + x300_mb_eeprom_iface::sptr eeprom16 = x300_mb_eeprom_iface::make(mb.zpu_ctrl, mb.zpu_i2c); if (dev_addr.has_key("blank_eeprom")) { UHD_MSG(warning) << "Obliterating the motherboard EEPROM..." << std::endl; @@ -1002,8 +1010,7 @@ x300_impl::~x300_impl(void) mb.claimer_task.reset(); { //Critical section boost::mutex::scoped_lock(pcie_zpu_iface_registry_mutex); - mb.zpu_ctrl->poke32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_CLAIM_TIME), 0); - mb.zpu_ctrl->poke32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_CLAIM_SRC), 0); + release(mb.zpu_ctrl); //If the process is killed, the entire registry will disappear so we //don't need to worry about unclean shutdowns here. get_pcie_zpu_iface_registry().pop(mb.get_pri_eth().addr); @@ -1457,24 +1464,58 @@ void x300_impl::set_mb_eeprom(i2c_iface::sptr i2c, const mboard_eeprom_t &mb_eep void x300_impl::claimer_loop(wb_iface::sptr iface) { - { //Critical section - boost::mutex::scoped_lock(claimer_mutex); - iface->poke32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_CLAIM_TIME), uint32_t(time(NULL))); - iface->poke32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_CLAIM_SRC), get_process_hash()); - } + claim(iface); boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); //1 second } -bool x300_impl::is_claimed(wb_iface::sptr iface) +x300_impl::claim_status_t x300_impl::claim_status(wb_iface::sptr iface) { - boost::mutex::scoped_lock(claimer_mutex); - - //If timed out then device is definitely unclaimed - if (iface->peek32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_CLAIM_STATUS)) == 0) - return false; + //If timed out, then device is definitely unclaimed + if (iface->peek32(X300_FW_SHMEM_ADDR(X300_FW_SHMEM_CLAIM_STATUS)) == 0) + return UNCLAIMED; //otherwise check claim src to determine if another thread with the same src has claimed the device - return iface->peek32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_CLAIM_SRC)) != get_process_hash(); + uint32_t hash = iface->peek32(X300_FW_SHMEM_ADDR(X300_FW_SHMEM_CLAIM_SRC)); + return (hash == get_process_hash() ? CLAIMED_BY_US : CLAIMED_BY_OTHER); +} + +void x300_impl::claim(wb_iface::sptr iface) +{ + iface->poke32(X300_FW_SHMEM_ADDR(X300_FW_SHMEM_CLAIM_TIME), uint32_t(time(NULL))); + iface->poke32(X300_FW_SHMEM_ADDR(X300_FW_SHMEM_CLAIM_SRC), get_process_hash()); +} + +bool x300_impl::try_to_claim(wb_iface::sptr iface, long timeout) +{ + boost::system_time start_time = boost::get_system_time(); + while (1) + { + claim_status_t status = claim_status(iface); + if (status == UNCLAIMED) + { + claim(iface); + // It takes the claimer 10ms to update status, so wait 20ms before verifying claim + boost::this_thread::sleep(boost::posix_time::milliseconds(20)); + continue; + } + if (status == CLAIMED_BY_US) + { + break; + } + if (boost::get_system_time() - start_time > boost::posix_time::milliseconds(timeout)) + { + // Another process owns the device - give up + return false; + } + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + } + return true; +} + +void x300_impl::release(wb_iface::sptr iface) +{ + iface->poke32(X300_FW_SHMEM_ADDR(X300_FW_SHMEM_CLAIM_TIME), 0); + iface->poke32(X300_FW_SHMEM_ADDR(X300_FW_SHMEM_CLAIM_SRC), 0); } /*********************************************************************** diff --git a/host/lib/usrp/x300/x300_impl.hpp b/host/lib/usrp/x300/x300_impl.hpp index 53ef012d4..55b055d44 100644 --- a/host/lib/usrp/x300/x300_impl.hpp +++ b/host/lib/usrp/x300/x300_impl.hpp @@ -129,9 +129,12 @@ public: void setup_mb(const size_t which, const uhd::device_addr_t &); ~x300_impl(void); - // used by x300_find_with_addr to find X300 devices. - static boost::mutex claimer_mutex; //All claims and checks in this process are serialized - static bool is_claimed(uhd::wb_iface::sptr); + // device claim functions + enum claim_status_t {UNCLAIMED, CLAIMED_BY_US, CLAIMED_BY_OTHER}; + static claim_status_t claim_status(uhd::wb_iface::sptr iface); + static void claim(uhd::wb_iface::sptr iface); + static bool try_to_claim(uhd::wb_iface::sptr iface, long timeout = 2000); + static void release(uhd::wb_iface::sptr iface); enum x300_mboard_t { USRP_X300_MB, USRP_X310_MB, UNKNOWN diff --git a/host/lib/usrp/x300/x300_mb_eeprom.cpp b/host/lib/usrp/x300/x300_mb_eeprom.cpp new file mode 100644 index 000000000..e39b36af8 --- /dev/null +++ b/host/lib/usrp/x300/x300_mb_eeprom.cpp @@ -0,0 +1,190 @@ +// +// Copyright 2013-2016 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +/* + * x300_mb_eeprom_iface + * This interface was created to prevent MB EEPROM corruption while reading + * data during discovery. For devices with firmware version newer than 5.0, + * the EEPROM data is read into firmware memory and available without + * claiming the device. For devices with firmware versions 5.0 and older, + * the code makes sure to claim the device before driving the I2C bus. This + * has the unfortunate side effect of preventing multiple processes from + * discovering the device simultaneously, but is far better than having EEPROM + * corruption. + */ + +#include "x300_mb_eeprom.hpp" +#include "x300_fw_common.h" +#include "x300_regs.hpp" +#include "x300_impl.hpp" +#include <uhd/exception.hpp> +#include <uhd/utils/platform.hpp> +#include <uhd/utils/msg.hpp> +#include <uhd/utils/byteswap.hpp> +#include <boost/thread.hpp> + +using namespace uhd; + +static const uint32_t X300_FW_SHMEM_IDENT_MIN_VERSION = 0x50001; + +class x300_mb_eeprom_iface_impl : public x300_mb_eeprom_iface +{ +public: + + x300_mb_eeprom_iface_impl(wb_iface::sptr wb, i2c_iface::sptr i2c) : _wb(wb), _i2c(i2c) + { + _compat_num = _wb->peek32(X300_FW_SHMEM_ADDR(X300_FW_SHMEM_COMPAT_NUM)); + } + + ~x300_mb_eeprom_iface_impl() + { + /* NOP */ + } + + /*! + * Write bytes over the i2c. + * \param addr the address + * \param buf the vector of bytes + */ + void write_i2c( + uint16_t addr, + const byte_vector_t &buf + ) + { + UHD_ASSERT_THROW(addr == MBOARD_EEPROM_ADDR); + if (x300_impl::claim_status(_wb) != x300_impl::CLAIMED_BY_US) + { + throw uhd::io_error("Attempted to write MB EEPROM without claim to device."); + } + _i2c->write_i2c(addr, buf); + } + + /*! + * Read bytes over the i2c. + * \param addr the address + * \param num_bytes number of bytes to read + * \return a vector of bytes + */ + byte_vector_t read_i2c( + uint16_t addr, + size_t num_bytes + ) + { + UHD_ASSERT_THROW(addr == MBOARD_EEPROM_ADDR); + byte_vector_t bytes; + if (_compat_num > X300_FW_SHMEM_IDENT_MIN_VERSION) + { + bytes = read_eeprom(addr, 0, num_bytes); + } else { + x300_impl::claim_status_t status = x300_impl::claim_status(_wb); + // Claim device before driving the I2C bus + if (status == x300_impl::CLAIMED_BY_US or x300_impl::try_to_claim(_wb)) + { + bytes = _i2c->read_i2c(addr, num_bytes); + if (status != x300_impl::CLAIMED_BY_US) + { + // We didn't originally have the claim, so give it up + x300_impl::release(_wb); + } + } + } + return bytes; + } + + /*! + * Write bytes to an eeprom. + * \param addr the address + * \param offset byte offset + * \param buf the vector of bytes + */ + void write_eeprom( + uint16_t addr, + uint16_t offset, + const byte_vector_t &buf + ) + { + UHD_ASSERT_THROW(addr == MBOARD_EEPROM_ADDR); + if (x300_impl::claim_status(_wb) != x300_impl::CLAIMED_BY_US) + { + throw uhd::io_error("Attempted to write MB EEPROM without claim to device."); + } + _i2c->write_eeprom(addr, offset, buf); + } + + /*! + * Read bytes from an eeprom. + * \param addr the address + * \param offset byte offset + * \param num_bytes number of bytes to read + * \return a vector of bytes + */ + byte_vector_t read_eeprom( + uint16_t addr, + uint16_t offset, + size_t num_bytes + ) + { + UHD_ASSERT_THROW(addr == MBOARD_EEPROM_ADDR); + byte_vector_t bytes; + x300_impl::claim_status_t status = x300_impl::claim_status(_wb); + if (_compat_num >= X300_FW_SHMEM_IDENT_MIN_VERSION) + { + // Get MB EEPROM data from firmware memory + if (num_bytes == 0) return bytes; + + size_t bytes_read = 0; + for (size_t word = offset / 4; bytes_read < num_bytes; word++) + { + uint32_t value = byteswap(_wb->peek32(X300_FW_SHMEM_ADDR(X300_FW_SHMEM_IDENT + word))); + for (size_t byte = offset % 4; byte < 4 and bytes_read < num_bytes; byte++) + { + bytes.push_back(uint8_t((value >> (byte * 8)) & 0xff)); + bytes_read++; + } + } + } else { + // Claim device before driving the I2C bus + if (status == x300_impl::CLAIMED_BY_US or x300_impl::try_to_claim(_wb)) + { + bytes = _i2c->read_eeprom(addr, offset, num_bytes); + if (status != x300_impl::CLAIMED_BY_US) + { + // We didn't originally have the claim, so give it up + x300_impl::release(_wb); + } + } + } + return bytes; + } + + +private: + wb_iface::sptr _wb; + i2c_iface::sptr _i2c; + uint32_t _compat_num; +}; + +x300_mb_eeprom_iface::~x300_mb_eeprom_iface(void) +{ + /* NOP */ +} + +x300_mb_eeprom_iface::sptr x300_mb_eeprom_iface::make(wb_iface::sptr wb, i2c_iface::sptr i2c) +{ + return boost::make_shared<x300_mb_eeprom_iface_impl>(wb, i2c->eeprom16()); +} + diff --git a/host/lib/usrp/x300/x300_mb_eeprom.hpp b/host/lib/usrp/x300/x300_mb_eeprom.hpp new file mode 100644 index 000000000..0649855c6 --- /dev/null +++ b/host/lib/usrp/x300/x300_mb_eeprom.hpp @@ -0,0 +1,37 @@ +// +// Copyright 2016 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 +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef INCLUDED_X300_MB_EEPROM_HPP +#define INCLUDED_X300_MB_EEPROM_HPP + +#include <uhd/config.hpp> +#include <uhd/types/serial.hpp> +#include <boost/utility.hpp> +#include <boost/shared_ptr.hpp> +#include <uhd/types/wb_iface.hpp> + +class x300_mb_eeprom_iface : public uhd::i2c_iface +{ +public: + typedef boost::shared_ptr<x300_mb_eeprom_iface> sptr; + + virtual ~x300_mb_eeprom_iface(void) = 0; + + static sptr make(uhd::wb_iface::sptr wb, uhd::i2c_iface::sptr i2c); +}; + +#endif /* INCLUDED_X300_MB_EEPROM_HPP */ diff --git a/host/lib/usrp/x300/x300_regs.hpp b/host/lib/usrp/x300/x300_regs.hpp index 6e7c47a64..d908bfb34 100644 --- a/host/lib/usrp/x300/x300_regs.hpp +++ b/host/lib/usrp/x300/x300_regs.hpp @@ -33,6 +33,9 @@ static const int BL_DATA = 1; #define I2C1_BASE 0xff00 #define SR_ADDR(base, offset) ((base) + (offset)*4) +//I2C1 device addresses +#define MBOARD_EEPROM_ADDR 0x50 + static const int ZPU_SR_LEDS = 00; static const int ZPU_SR_SW_RST = 01; static const int ZPU_SR_CLOCK_CTRL = 02; |