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/b100 | |
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/b100')
-rw-r--r-- | host/lib/usrp/b100/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/usrp/b100/b100_impl.cpp | 9 | ||||
-rw-r--r-- | host/lib/usrp/b100/b100_impl.hpp | 3 | ||||
-rw-r--r-- | host/lib/usrp/b100/mb_eeprom.cpp | 91 |
4 files changed, 97 insertions, 7 deletions
diff --git a/host/lib/usrp/b100/CMakeLists.txt b/host/lib/usrp/b100/CMakeLists.txt index 66129458c..93177fce3 100644 --- a/host/lib/usrp/b100/CMakeLists.txt +++ b/host/lib/usrp/b100/CMakeLists.txt @@ -29,6 +29,7 @@ IF(ENABLE_B100) ${CMAKE_CURRENT_SOURCE_DIR}/codec_ctrl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dboard_iface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/io_impl.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mb_eeprom.cpp ${CMAKE_CURRENT_SOURCE_DIR}/usb_zero_copy_wrapper.cpp ) ENDIF(ENABLE_B100) diff --git a/host/lib/usrp/b100/b100_impl.cpp b/host/lib/usrp/b100/b100_impl.cpp index 27af43c48..110c5ff87 100644 --- a/host/lib/usrp/b100/b100_impl.cpp +++ b/host/lib/usrp/b100/b100_impl.cpp @@ -108,7 +108,8 @@ static device_addrs_t b100_find(const device_addr_t &hint) catch(const uhd::exception &){continue;} //ignore claimed fx2_ctrl::sptr fx2_ctrl = fx2_ctrl::make(control); - const mboard_eeprom_t mb_eeprom = mboard_eeprom_t(*fx2_ctrl, B100_EEPROM_MAP_KEY); + const mboard_eeprom_t mb_eeprom = + b100_impl::get_mb_eeprom(fx2_ctrl); device_addr_t new_addr; new_addr["type"] = "b100"; new_addr["name"] = mb_eeprom["name"]; @@ -283,7 +284,7 @@ b100_impl::b100_impl(const device_addr_t &device_addr){ //////////////////////////////////////////////////////////////////// // setup the mboard eeprom //////////////////////////////////////////////////////////////////// - const mboard_eeprom_t mb_eeprom(*_fx2_ctrl, B100_EEPROM_MAP_KEY); + const mboard_eeprom_t mb_eeprom = this->get_mb_eeprom(_fx2_ctrl); _tree->create<mboard_eeprom_t>(mb_path / "eeprom") .set(mb_eeprom) .add_coerced_subscriber(boost::bind(&b100_impl::set_mb_eeprom, this, _1)); @@ -561,10 +562,6 @@ double b100_impl::update_rx_codec_gain(const double gain){ return _codec_ctrl->get_rx_pga_gain('A'); } -void b100_impl::set_mb_eeprom(const uhd::usrp::mboard_eeprom_t &mb_eeprom){ - mb_eeprom.commit(*_fx2_ctrl, B100_EEPROM_MAP_KEY); -} - void b100_impl::set_db_eeprom(const std::string &type, const uhd::usrp::dboard_eeprom_t &db_eeprom){ if (type == "rx") db_eeprom.store(*_fpga_i2c_ctrl, I2C_ADDR_RX_A); if (type == "tx") db_eeprom.store(*_fpga_i2c_ctrl, I2C_ADDR_TX_A); diff --git a/host/lib/usrp/b100/b100_impl.hpp b/host/lib/usrp/b100/b100_impl.hpp index ba4b3cd90..4faf69b64 100644 --- a/host/lib/usrp/b100/b100_impl.hpp +++ b/host/lib/usrp/b100/b100_impl.hpp @@ -53,7 +53,6 @@ static const uint32_t B100_TX_ASYNC_SID = 10; static const uint32_t B100_CTRL_MSG_SID = 20; static const double B100_DEFAULT_TICK_RATE = 64e6; static const size_t B100_MAX_PKT_BYTE_LIMIT = 2048; -static const std::string B100_EEPROM_MAP_KEY = "B100"; static const size_t B100_MAX_RATE_USB2 = 32000000; // bytes/s #define I2C_ADDR_TX_A (I2C_DEV_EEPROM | 0x4) @@ -105,6 +104,8 @@ public: uhd::tx_streamer::sptr get_tx_stream(const uhd::stream_args_t &args); bool recv_async_msg(uhd::async_metadata_t &, double); + static uhd::usrp::mboard_eeprom_t get_mb_eeprom(uhd::i2c_iface::sptr); + private: //controllers fifo_ctrl_excelsior::sptr _fifo_ctrl; diff --git a/host/lib/usrp/b100/mb_eeprom.cpp b/host/lib/usrp/b100/mb_eeprom.cpp new file mode 100644 index 000000000..be7137b7b --- /dev/null +++ b/host/lib/usrp/b100/mb_eeprom.cpp @@ -0,0 +1,91 @@ +// +// Copyright 2017 Ettus Research (National Instruments Corp.) +// +// SPDX-License-Identifier: GPL-3.0 +// + +#include "b100_impl.hpp" +#include "eeprom_utils.hpp" +#include <uhd/usrp/mboard_eeprom.hpp> + +namespace { + const uint8_t B100_EEPROM_ADDR = 0x50; + + //use char array so we dont need to attribute packed + struct b100_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 b100_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( + B100_EEPROM_ADDR, + offsetof(b100_eeprom_map, revision), + 2 + ) + ); + + //extract the product code + mb_eeprom["product"] = uint16_bytes_to_string( + iface->read_eeprom( + B100_EEPROM_ADDR, + offsetof(b100_eeprom_map, product), + 2 + ) + ); + + //extract the serial + mb_eeprom["serial"] = bytes_to_string(iface->read_eeprom( + B100_EEPROM_ADDR, offsetof(b100_eeprom_map, serial), SERIAL_LEN + )); + + //extract the name + mb_eeprom["name"] = bytes_to_string(iface->read_eeprom( + B100_EEPROM_ADDR, offsetof(b100_eeprom_map, name), NAME_MAX_LEN + )); + + return mb_eeprom; +} + +void b100_impl::set_mb_eeprom( + const uhd::usrp::mboard_eeprom_t &mb_eeprom +) { + auto &iface = _fx2_ctrl; + + //parse the revision number + if (mb_eeprom.has_key("revision")) iface->write_eeprom( + B100_EEPROM_ADDR, offsetof(b100_eeprom_map, revision), + string_to_uint16_bytes(mb_eeprom["revision"]) + ); + + //parse the product code + if (mb_eeprom.has_key("product")) iface->write_eeprom( + B100_EEPROM_ADDR, offsetof(b100_eeprom_map, product), + string_to_uint16_bytes(mb_eeprom["product"]) + ); + + //store the serial + if (mb_eeprom.has_key("serial")) iface->write_eeprom( + B100_EEPROM_ADDR, offsetof(b100_eeprom_map, serial), + string_to_bytes(mb_eeprom["serial"], SERIAL_LEN) + ); + + //store the name + if (mb_eeprom.has_key("name")) iface->write_eeprom( + B100_EEPROM_ADDR, offsetof(b100_eeprom_map, name), + string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN) + ); +} + |