From e83a941a9ff6094358602302212aed760341c873 Mon Sep 17 00:00:00 2001 From: Michael West Date: Fri, 15 Nov 2013 09:50:07 -0800 Subject: BUG #182: Refactored b2xx_fx3_utils to use files from UHD --- host/lib/transport/libusb1_base.cpp | 4 ++++ host/lib/usrp/b200/b200_iface.cpp | 4 +++- host/lib/usrp/b200/b200_iface.hpp | 10 ++++++++++ host/lib/usrp/b200/b200_impl.cpp | 17 ++++++++++------- 4 files changed, 27 insertions(+), 8 deletions(-) (limited to 'host/lib') diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp index 0ef53db0a..157edc199 100644 --- a/host/lib/transport/libusb1_base.cpp +++ b/host/lib/transport/libusb1_base.cpp @@ -274,6 +274,10 @@ public: return libusb::device_descriptor::make(this->get_device())->get().idProduct; } + bool firmware_loaded() { + return (get_manufacturer() == "Ettus Research LLC"); + } + private: libusb::device::sptr _dev; //always keep a reference to device }; diff --git a/host/lib/usrp/b200/b200_iface.cpp b/host/lib/usrp/b200/b200_iface.cpp index 1d05e159c..b87df2977 100644 --- a/host/lib/usrp/b200/b200_iface.cpp +++ b/host/lib/usrp/b200/b200_iface.cpp @@ -240,10 +240,12 @@ public: size_t num_bytes ){ byte_vector_t recv_bytes(num_bytes); - fx3_control_read(B200_VREQ_EEPROM_READ, + int bytes_read = fx3_control_read(B200_VREQ_EEPROM_READ, 0, offset | (boost::uint16_t(addr) << 8), (unsigned char*) &recv_bytes[0], num_bytes); + if (bytes_read != num_bytes) + throw uhd::io_error("Failed to read data from EEPROM."); return recv_bytes; } diff --git a/host/lib/usrp/b200/b200_iface.hpp b/host/lib/usrp/b200/b200_iface.hpp index 1247d1f86..6ba77f0ff 100644 --- a/host/lib/usrp/b200/b200_iface.hpp +++ b/host/lib/usrp/b200/b200_iface.hpp @@ -25,6 +25,12 @@ #include #include "ad9361_ctrl.hpp" +const static boost::uint16_t B200_VENDOR_ID = 0x2500; +const static boost::uint16_t B200_PRODUCT_ID = 0x0020; +const static boost::uint16_t FX3_VID = 0x04b4; +const static boost::uint16_t FX3_DEFAULT_PID = 0x00f3; +const static boost::uint16_t FX3_REENUM_PID = 0x00f0; + class b200_iface: boost::noncopyable, public virtual uhd::i2c_iface, public ad9361_ctrl_iface_type { public: @@ -64,6 +70,10 @@ public: //! send SPI through the FX3 virtual void transact_spi( unsigned char *tx_data, size_t num_tx_bits, \ unsigned char *rx_data, size_t num_rx_bits) = 0; + + virtual void write_eeprom(boost::uint16_t addr, boost::uint16_t offset, const uhd::byte_vector_t &bytes) = 0; + + virtual uhd::byte_vector_t read_eeprom(boost::uint16_t addr, boost::uint16_t offset, size_t num_bytes) = 0; }; diff --git a/host/lib/usrp/b200/b200_impl.cpp b/host/lib/usrp/b200/b200_impl.cpp index 0da388b93..30fdc7354 100644 --- a/host/lib/usrp/b200/b200_impl.cpp +++ b/host/lib/usrp/b200/b200_impl.cpp @@ -37,10 +37,6 @@ using namespace uhd; using namespace uhd::usrp; using namespace uhd::transport; -const boost::uint16_t B200_VENDOR_ID = 0x2500; -const boost::uint16_t B200_PRODUCT_ID = 0x0020; -const boost::uint16_t INIT_PRODUCT_ID = 0x00f0; - static const boost::posix_time::milliseconds REENUMERATION_TIMEOUT_MS(3000); //! mapping of frontend to radio perif index @@ -99,7 +95,7 @@ static device_addrs_t b200_find(const device_addr_t &hint) catch(const uhd::exception &){continue;} //ignore claimed //check if fw was already loaded - if (handle->get_manufacturer() != "Ettus Research LLC") + if (!(handle->firmware_loaded())) { b200_iface::make(control)->load_firmware(b200_fw_image); } @@ -160,8 +156,15 @@ 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; + if (device_addr.has_key("vid")) + sscanf(device_addr.get("vid").c_str(), "%x", &vid); + if (device_addr.has_key("pid")) + sscanf(device_addr.get("pid").c_str(), "%x", &pid); + std::vector device_list = - usb_device_handle::get_device_list(B200_VENDOR_ID, B200_PRODUCT_ID); + usb_device_handle::get_device_list(vid, pid); //locate the matching handle in the device list usb_device_handle::sptr handle; @@ -612,7 +615,7 @@ void b200_impl::setup_radio(const size_t dspno) /*********************************************************************** * loopback tests **********************************************************************/ - + void b200_impl::register_loopback_self_test(wb_iface::sptr iface) { bool test_fail = false; -- cgit v1.2.3 From 91c10b31f94f95f1588571e0580b09a8b354a2a3 Mon Sep 17 00:00:00 2001 From: Michael West Date: Mon, 18 Nov 2013 10:51:10 -0800 Subject: BUG #182: Cleaned up for proper dynamic linking of libuhd. --- host/lib/usrp/b200/b200_iface.hpp | 8 ++++++-- host/lib/usrp/b200/b200_impl.hpp | 4 ---- host/utils/CMakeLists.txt | 12 +++--------- host/utils/b2xx_fx3_utils.cpp | 9 +++++++++ 4 files changed, 18 insertions(+), 15 deletions(-) (limited to 'host/lib') diff --git a/host/lib/usrp/b200/b200_iface.hpp b/host/lib/usrp/b200/b200_iface.hpp index 6ba77f0ff..4b678b1f9 100644 --- a/host/lib/usrp/b200/b200_iface.hpp +++ b/host/lib/usrp/b200/b200_iface.hpp @@ -31,7 +31,11 @@ const static boost::uint16_t FX3_VID = 0x04b4; const static boost::uint16_t FX3_DEFAULT_PID = 0x00f3; const static boost::uint16_t FX3_REENUM_PID = 0x00f0; -class b200_iface: boost::noncopyable, public virtual uhd::i2c_iface, +static const std::string B200_FW_FILE_NAME = "usrp_b200_fw.hex"; +static const std::string B200_FPGA_FILE_NAME = "usrp_b200_fpga.bin"; +static const std::string B210_FPGA_FILE_NAME = "usrp_b210_fpga.bin"; + +class UHD_API b200_iface: boost::noncopyable, public virtual uhd::i2c_iface, public ad9361_ctrl_iface_type { public: typedef boost::shared_ptr sptr; @@ -41,7 +45,7 @@ public: * \param usb_ctrl a USB control transport * \return a new b200 interface object */ - static sptr make(uhd::transport::usb_control::sptr usb_ctrl); + static UHD_API sptr make(uhd::transport::usb_control::sptr usb_ctrl); //! query the device USB speed (2, 3) virtual boost::uint8_t get_usb_speed(void) = 0; diff --git a/host/lib/usrp/b200/b200_impl.hpp b/host/lib/usrp/b200/b200_impl.hpp index eced4a539..d96130dda 100644 --- a/host/lib/usrp/b200/b200_impl.hpp +++ b/host/lib/usrp/b200/b200_impl.hpp @@ -44,10 +44,6 @@ #include #include #include "recv_packet_demuxer_3000.hpp" - -static const std::string B200_FW_FILE_NAME = "usrp_b200_fw.hex"; -static const std::string B200_FPGA_FILE_NAME = "usrp_b200_fpga.bin"; -static const std::string B210_FPGA_FILE_NAME = "usrp_b210_fpga.bin"; static const boost::uint8_t B200_FW_COMPAT_NUM_MAJOR = 0x03; static const boost::uint8_t B200_FW_COMPAT_NUM_MINOR = 0x00; static const boost::uint16_t B200_FPGA_COMPAT_NUM = 0x02; diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index 1135ad031..f73690475 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -47,8 +47,11 @@ SET(util_share_sources IF(ENABLE_USB) LIST(APPEND util_share_sources fx2_init_eeprom.cpp + b2xx_fx3_utils ) INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS}) + # Additional include directories for b2xx_fx3_utils + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../lib/usrp/b200 ${CMAKE_CURRENT_SOURCE_DIR}/../lib/usrp/common) ENDIF(ENABLE_USB) IF(LINUX AND ENABLE_USB) @@ -67,15 +70,6 @@ FOREACH(util_source ${util_share_sources}) UHD_INSTALL(TARGETS ${util_name} RUNTIME DESTINATION ${PKG_LIB_DIR}/utils COMPONENT utilities) ENDFOREACH(util_source) -IF(ENABLE_USB) - # build b2xx_fx3_utils - INCLUDE_DIRECTORIES(../lib/usrp/b200) - INCLUDE_DIRECTORIES(../lib/usrp/common) - ADD_EXECUTABLE(b2xx_fx3_utils ../lib/transport/libusb1_base.cpp ../lib/usrp/b200/b200_iface.cpp b2xx_fx3_utils.cpp) - TARGET_LINK_LIBRARIES(b2xx_fx3_utils uhd ${Boost_LIBRARIES}) - UHD_INSTALL(TARGETS b2xx_fx3_utils RUNTIME DESTINATION ${PKG_LIB_DIR}/utils COMPONENT utilities) -ENDIF(ENABLE_USB) - UHD_INSTALL(TARGETS usrp_n2xx_simple_net_burner RUNTIME DESTINATION ${PKG_LIB_DIR}/utils COMPONENT utilities) #UHD images downloader configuration diff --git a/host/utils/b2xx_fx3_utils.cpp b/host/utils/b2xx_fx3_utils.cpp index e910ffc6c..d4e3b0f9a 100644 --- a/host/utils/b2xx_fx3_utils.cpp +++ b/host/utils/b2xx_fx3_utils.cpp @@ -38,6 +38,7 @@ #include #include #include +#include namespace po = boost::program_options; namespace fs = boost::filesystem; @@ -182,6 +183,8 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { if (!(handles[0]->firmware_loaded())) { + if (fw_file.empty()) + fw_file = uhd::find_image_path(B200_FW_FILE_NAME); b200->load_firmware(fw_file); // Now that the firmware is loaded, we need to re-open the device @@ -229,6 +232,8 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { if (!(handles[0]->firmware_loaded())) { // load FW + if (fw_file.empty()) + fw_file = uhd::find_image_path(B200_FW_FILE_NAME); b200->load_firmware(fw_file); // re-open device @@ -309,6 +314,8 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { if (!(handles[0]->firmware_loaded())) { + if (fw_file.empty()) + fw_file = uhd::find_image_path(B200_FW_FILE_NAME); b200->load_firmware(fw_file); // Now that the firmware is loaded, we need to re-open the device @@ -384,6 +391,8 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { if (!(handles[0]->firmware_loaded())) { // load FW + if (fw_file.empty()) + fw_file = uhd::find_image_path(B200_FW_FILE_NAME); b200->load_firmware(fw_file); // re-open device -- cgit v1.2.3 From 32b0b1a139a0ca4f9bfc544dccc1daa2e86fbb0e Mon Sep 17 00:00:00 2001 From: Michael West Date: Mon, 18 Nov 2013 12:40:24 -0800 Subject: More cleanup for dynamic linking. --- host/lib/usrp/b200/b200_iface.hpp | 2 +- host/utils/b2xx_fx3_utils.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'host/lib') diff --git a/host/lib/usrp/b200/b200_iface.hpp b/host/lib/usrp/b200/b200_iface.hpp index 4b678b1f9..5b6eeede4 100644 --- a/host/lib/usrp/b200/b200_iface.hpp +++ b/host/lib/usrp/b200/b200_iface.hpp @@ -45,7 +45,7 @@ public: * \param usb_ctrl a USB control transport * \return a new b200 interface object */ - static UHD_API sptr make(uhd::transport::usb_control::sptr usb_ctrl); + static sptr make(uhd::transport::usb_control::sptr usb_ctrl); //! query the device USB speed (2, 3) virtual boost::uint8_t get_usb_speed(void) = 0; diff --git a/host/utils/b2xx_fx3_utils.cpp b/host/utils/b2xx_fx3_utils.cpp index d4e3b0f9a..980d1c5f4 100644 --- a/host/utils/b2xx_fx3_utils.cpp +++ b/host/utils/b2xx_fx3_utils.cpp @@ -100,7 +100,7 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { po::notify(vm); if (vm.count("help")){ - std::cout << boost::format("B2xx Utilitiy Program %s") % desc << std::endl; + std::cout << boost::format("B2xx Utilitiy Program %s") % visible << std::endl; return ~0; } else if (vm.count("reset-usb")) { /* Okay, first, we need to discover what the path is to the ehci and @@ -519,7 +519,7 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { << std::endl; } else { - std::cout << boost::format("B2xx Utilitiy Program %s") % desc << std::endl; + std::cout << boost::format("B2xx Utilitiy Program %s") % visible << std::endl; return ~0; } -- cgit v1.2.3