diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-09-26 18:22:25 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-09-29 10:50:56 -0700 |
commit | 83dde40090e0bbd91c304602cc0e3c365f7878bb (patch) | |
tree | c404968e3d6d35795f331ade6ad3c176f3c1bc8b /host/lib/usrp/b200 | |
parent | 59736a5bf512db83a6bd7250e14b13c7464770fc (diff) | |
download | uhd-83dde40090e0bbd91c304602cc0e3c365f7878bb.tar.gz uhd-83dde40090e0bbd91c304602cc0e3c365f7878bb.tar.bz2 uhd-83dde40090e0bbd91c304602cc0e3c365f7878bb.zip |
uhd: Changed mboard_eeprom_t interface, refactored MB EEPROM code
- uhd::usrp::mboard_eeprom_t is now simply a map. Its commit() method
has no utility being a public API call, because the user never gets
access to the appropriate I2C object (Minor API breakage)
- The central mboard_eeprom.cpp file was broken up and put into many
smaller compilation units in every device's implementation folder.
- Renamed some of the constants (e.g. B000_* -> USRP1_*, N100_* ->
N200_*)
- Removed the N000_* EEPROM code, because, well, you know, there's no
such device
Diffstat (limited to 'host/lib/usrp/b200')
-rw-r--r-- | host/lib/usrp/b200/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_image_loader.cpp | 12 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_impl.cpp | 9 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_impl.hpp | 2 | ||||
-rw-r--r-- | host/lib/usrp/b200/b200_mb_eeprom.cpp | 82 |
5 files changed, 94 insertions, 12 deletions
diff --git a/host/lib/usrp/b200/CMakeLists.txt b/host/lib/usrp/b200/CMakeLists.txt index 4b9e2de55..f5c6e28b2 100644 --- a/host/lib/usrp/b200/CMakeLists.txt +++ b/host/lib/usrp/b200/CMakeLists.txt @@ -30,5 +30,6 @@ IF(ENABLE_B200) ${CMAKE_CURRENT_SOURCE_DIR}/b200_io_impl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/b200_uart.cpp ${CMAKE_CURRENT_SOURCE_DIR}/b200_cores.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/b200_mb_eeprom.cpp ) ENDIF(ENABLE_B200) diff --git a/host/lib/usrp/b200/b200_image_loader.cpp b/host/lib/usrp/b200/b200_image_loader.cpp index af79a59fc..4d0f8d937 100644 --- a/host/lib/usrp/b200/b200_image_loader.cpp +++ b/host/lib/usrp/b200/b200_image_loader.cpp @@ -46,8 +46,8 @@ static b200_iface::sptr get_b200_iface(const image_loader::image_loader_args_t& if(dev_handles.size() > 0){ for(usb_device_handle::sptr dev_handle: dev_handles){ if(dev_handle->firmware_loaded()){ - iface = b200_iface::make(usb_control::make(dev_handle,0)); - eeprom = mboard_eeprom_t(*iface, "B200"); + iface = b200_iface::make(usb_control::make(dev_handle, 0)); + eeprom = b200_impl::get_mb_eeprom(iface); if(user_specified){ if(image_loader_args.args.has_key("serial") and eeprom.get("serial") != image_loader_args.args.get("serial")){ @@ -73,8 +73,10 @@ static b200_iface::sptr get_b200_iface(const image_loader::image_loader_args_t& std::string err_msg = "Could not resolve given args to a single B2XX device.\n" "Applicable devices:\n"; - for(usb_device_handle::sptr dev_handle: applicable_dev_handles){ - eeprom = mboard_eeprom_t(*b200_iface::make(usb_control::make(dev_handle,0)), "B200"); + for (usb_device_handle::sptr dev_handle: applicable_dev_handles) { + eeprom = b200_impl::get_mb_eeprom( + b200_iface::make(usb_control::make(dev_handle, 0)) + ); err_msg += str(boost::format(" * %s (serial=%s)\n") % B2XX_STR_NAMES.get(get_b200_product(dev_handle, mb_eeprom), "B2XX") % mb_eeprom.get("serial")); @@ -88,7 +90,7 @@ static b200_iface::sptr get_b200_iface(const image_loader::image_loader_args_t& // No applicable devices found, return empty sptr so we can exit iface.reset(); - mb_eeprom = mboard_eeprom_t(); + mb_eeprom = eeprom; return iface; } diff --git a/host/lib/usrp/b200/b200_impl.cpp b/host/lib/usrp/b200/b200_impl.cpp index a513e1336..134cba208 100644 --- a/host/lib/usrp/b200/b200_impl.cpp +++ b/host/lib/usrp/b200/b200_impl.cpp @@ -220,7 +220,7 @@ static device_addrs_t b200_find(const device_addr_t &hint) catch(const uhd::exception &){continue;} //ignore claimed b200_iface::sptr iface = b200_iface::make(control); - const mboard_eeprom_t mb_eeprom = mboard_eeprom_t(*iface, "B200"); + const mboard_eeprom_t mb_eeprom = b200_impl::get_mb_eeprom(iface); device_addr_t new_addr; new_addr["type"] = "b200"; @@ -362,7 +362,7 @@ b200_impl::b200_impl(const uhd::device_addr_t& device_addr, usb_device_handle::s //////////////////////////////////////////////////////////////////// // setup the mboard eeprom //////////////////////////////////////////////////////////////////// - const mboard_eeprom_t mb_eeprom(*_iface, "B200"); + const mboard_eeprom_t mb_eeprom = get_mb_eeprom(_iface); _tree->create<mboard_eeprom_t>(mb_path / "eeprom") .set(mb_eeprom) .add_coerced_subscriber(boost::bind(&b200_impl::set_mb_eeprom, this, _1)); @@ -983,11 +983,6 @@ void b200_impl::check_fpga_compat(void) % compat_major % compat_minor)); } -void b200_impl::set_mb_eeprom(const uhd::usrp::mboard_eeprom_t &mb_eeprom) -{ - mb_eeprom.commit(*_iface, "B200"); -} - /*********************************************************************** * Reference time and clock **********************************************************************/ diff --git a/host/lib/usrp/b200/b200_impl.hpp b/host/lib/usrp/b200/b200_impl.hpp index 1c756c56d..a8288df0f 100644 --- a/host/lib/usrp/b200/b200_impl.hpp +++ b/host/lib/usrp/b200/b200_impl.hpp @@ -124,6 +124,8 @@ public: // uhd::value_error. void check_streamer_args(const uhd::stream_args_t &args, double tick_rate, const std::string &direction = ""); + static uhd::usrp::mboard_eeprom_t get_mb_eeprom(uhd::i2c_iface::sptr); + private: b200_product_t _product; size_t _revision; diff --git a/host/lib/usrp/b200/b200_mb_eeprom.cpp b/host/lib/usrp/b200/b200_mb_eeprom.cpp new file mode 100644 index 000000000..e56e6f2ec --- /dev/null +++ b/host/lib/usrp/b200/b200_mb_eeprom.cpp @@ -0,0 +1,82 @@ +// +// Copyright 2017 Ettus Research (National Instruments Corp.) +// +// SPDX-License-Identifier: GPL-3.0 +// + +#include "b200_impl.hpp" +#include "eeprom_utils.hpp" +#include <uhd/usrp/mboard_eeprom.hpp> + +namespace { + /* On the B200, this field indicates the slave address. From the FX3, this + * address is always 0. */ + static const uint8_t B200_EEPROM_SLAVE_ADDR = 0x04; + + //use char array so we dont need to attribute packed + struct b200_eeprom_map{ + unsigned char _r[220]; + unsigned char revision[2]; + unsigned char product[2]; + unsigned char name[NAME_MAX_LEN]; + unsigned char serial[SERIAL_LEN]; + }; +} + +using namespace uhd; +using uhd::usrp::mboard_eeprom_t; + +mboard_eeprom_t b200_impl::get_mb_eeprom(uhd::i2c_iface::sptr iface) +{ + mboard_eeprom_t mb_eeprom; + + //extract the revision number + mb_eeprom["revision"] = uint16_bytes_to_string( + iface->read_eeprom(B200_EEPROM_SLAVE_ADDR, offsetof(b200_eeprom_map, revision), 2) + ); + + //extract the product code + mb_eeprom["product"] = uint16_bytes_to_string( + iface->read_eeprom(B200_EEPROM_SLAVE_ADDR, offsetof(b200_eeprom_map, product), 2) + ); + + //extract the serial + mb_eeprom["serial"] = bytes_to_string(iface->read_eeprom( + B200_EEPROM_SLAVE_ADDR, offsetof(b200_eeprom_map, serial), SERIAL_LEN + )); + + //extract the name + mb_eeprom["name"] = bytes_to_string(iface->read_eeprom( + B200_EEPROM_SLAVE_ADDR, offsetof(b200_eeprom_map, name), NAME_MAX_LEN + )); + + return mb_eeprom; +} + +void b200_impl::set_mb_eeprom(const mboard_eeprom_t &mb_eeprom) +{ + //parse the revision number + if (mb_eeprom.has_key("revision")) _iface->write_eeprom( + B200_EEPROM_SLAVE_ADDR, offsetof(b200_eeprom_map, revision), + string_to_uint16_bytes(mb_eeprom["revision"]) + ); + + //parse the product code + if (mb_eeprom.has_key("product")) _iface->write_eeprom( + B200_EEPROM_SLAVE_ADDR, offsetof(b200_eeprom_map, product), + string_to_uint16_bytes(mb_eeprom["product"]) + ); + + //store the serial + if (mb_eeprom.has_key("serial")) _iface->write_eeprom( + B200_EEPROM_SLAVE_ADDR, offsetof(b200_eeprom_map, serial), + string_to_bytes(mb_eeprom["serial"], SERIAL_LEN) + ); + + //store the name + if (mb_eeprom.has_key("name")) _iface->write_eeprom( + B200_EEPROM_SLAVE_ADDR, offsetof(b200_eeprom_map, name), + string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN) + ); +} + |