From cea3d05095202413be12cd4792ab9f781cbccef7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 26 Oct 2010 14:14:01 -0700 Subject: uhd: replaced print warning with a post warning call and registry renamed print warning calls in the implementation fixed issue with dict::pop so it now works even if the value is not comparable --- host/lib/usrp/usrp1/mboard_impl.cpp | 2 +- host/lib/usrp/usrp1/usrp1_impl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index fe3774eb4..669b20efa 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -98,7 +98,7 @@ static boost::uint32_t calc_rx_mux( // for all quadrature sources: Z = 0 // for mixed sources: warning + Z = 0 int Z = (num_quads > 0)? 0 : 1; - if (num_quads != 0 and num_reals != 0) uhd::print_warning( + if (num_quads != 0 and num_reals != 0) uhd::warning::post( "Mixing real and quadrature rx subdevices is not supported.\n" "The Q input to the real source(s) will be non-zero.\n" ); diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 276ca86f6..314384e72 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -64,7 +64,7 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) ); } catch(...){ - uhd::print_warning( + uhd::warning::post( "Could not locate USRP1 firmware.\n" "Please install the images package.\n" ); -- cgit v1.2.3 From cb4e30ec501aa201c0ca5d2676f2d568ae24356b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 31 Oct 2010 11:04:42 -0700 Subject: uhd: added dict get method, used in usrp1 image loading --- host/include/uhd/types/dict.hpp | 8 ++++++++ host/include/uhd/types/dict.ipp | 8 ++++++++ host/lib/usrp/usrp1/usrp1_impl.cpp | 6 ++---- 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index b14fc5425..6166140a0 100644 --- a/host/include/uhd/types/dict.hpp +++ b/host/include/uhd/types/dict.hpp @@ -70,6 +70,14 @@ namespace uhd{ */ bool has_key(const Key &key) const; + /*! + * Get a value in the dict or default. + * \param key the key to look for + * \param def use if key not found + * \return the value or default + */ + const Val &get(const Key &key, const Val &def) const; + /*! * Get a value for the given key if it exists. * If the key is not found throw an error. diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp index 85071e6fd..4aab5de45 100644 --- a/host/include/uhd/types/dict.ipp +++ b/host/include/uhd/types/dict.ipp @@ -85,6 +85,14 @@ namespace uhd{ return false; } + template + const Val &dict::get(const Key &key, const Val &def) const{ + BOOST_FOREACH(const pair_t &p, _map){ + if (p.first == key) return p.second; + } + return def; + } + template const Val &dict::operator[](const Key &key) const{ BOOST_FOREACH(const pair_t &p, _map){ diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 314384e72..bc478c7fb 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -59,9 +59,7 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) //extract the firmware path for the USRP1 std::string usrp1_fw_image; try{ - usrp1_fw_image = find_image_path( - hint.has_key("fw")? hint["fw"] : "usrp1_fw.ihx" - ); + usrp1_fw_image = find_image_path(hint.get("fw", "usrp1_fw.ihx")); } catch(...){ uhd::warning::post( @@ -110,7 +108,7 @@ static device::sptr usrp1_make(const device_addr_t &device_addr){ //extract the FPGA path for the USRP1 std::string usrp1_fpga_image = find_image_path( - device_addr.has_key("fpga")? device_addr["fpga"] : "usrp1_fpga.rbf" + device_addr.get("fpga", "usrp1_fpga.rbf") ); //std::cout << "USRP1 FPGA image: " << usrp1_fpga_image << std::endl; -- cgit v1.2.3 From 0066ef2972f35d3d1ba7a9127f197fba9e754d88 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 4 Nov 2010 23:44:58 -0700 Subject: usrp: replaced device specific burner apps with one generic one for mboard eeproms --- host/lib/usrp/mboard_eeprom.cpp | 3 +- host/lib/usrp/usrp1/mboard_impl.cpp | 35 +++++--------- host/lib/usrp/usrp1/usrp1_impl.hpp | 2 + host/utils/CMakeLists.txt | 12 ++--- host/utils/usrp1_serial_burner.cpp | 75 ------------------------------ host/utils/usrp2_addr_burner.cpp | 91 ------------------------------------- host/utils/usrp_burn_db_eeprom.cpp | 6 +-- host/utils/usrp_burn_mb_eeprom.cpp | 79 ++++++++++++++++++++++++++++++++ 8 files changed, 101 insertions(+), 202 deletions(-) delete mode 100644 host/utils/usrp1_serial_burner.cpp delete mode 100644 host/utils/usrp2_addr_burner.cpp create mode 100644 host/utils/usrp_burn_mb_eeprom.cpp (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/mboard_eeprom.cpp b/host/lib/usrp/mboard_eeprom.cpp index 2f5d41c95..81dc6f194 100644 --- a/host/lib/usrp/mboard_eeprom.cpp +++ b/host/lib/usrp/mboard_eeprom.cpp @@ -40,8 +40,7 @@ static const size_t NAME_MAX_LEN = 32 - SERIAL_LEN; static const std::string bytes_to_string(const byte_vector_t &bytes){ std::string out; BOOST_FOREACH(boost::uint8_t byte, bytes){ - if (byte == '\0') return out; - if (byte < 32 or byte > 127) return ""; + if (byte < 32 or byte > 127) return out; out += byte; } return out; diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 669b20efa..d7ab46eb1 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -208,6 +208,8 @@ bool usrp1_impl::has_tx_halfband(void){ **********************************************************************/ void usrp1_impl::mboard_init(void) { + _mb_eeprom = mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_BXXX); + _mboard_proxy = wax_obj_proxy::make( boost::bind(&usrp1_impl::mboard_get, this, _1, _2), boost::bind(&usrp1_impl::mboard_set, this, _1, _2)); @@ -262,24 +264,10 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) { named_prop_t key = named_prop_t::extract(key_); - if(key_.type() == typeid(std::string)) { - if(key.as() == "serial") { - uhd::byte_vector_t buf; - buf.insert(buf.begin(), 248); - boost::this_thread::sleep(boost::posix_time::milliseconds(100)); - _iface->write_i2c(I2C_DEV_EEPROM, buf); - boost::this_thread::sleep(boost::posix_time::milliseconds(100)); - buf = _iface->read_i2c(I2C_DEV_EEPROM, 8); - val = std::string(buf.begin(), buf.end()); - } - - return; - } - //handle the get request conditioned on the key switch(key.as()){ case MBOARD_PROP_NAME: - val = std::string("usrp1 mboard - " + (*_mboard_proxy)[std::string("serial")].as()); + val = std::string("usrp1 mboard - " + _mb_eeprom["serial"]); return; case MBOARD_PROP_OTHERS: @@ -336,6 +324,10 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) val = _tx_subdev_spec; return; + case MBOARD_PROP_EEPROM_MAP: + val = _mb_eeprom; + return; + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -351,14 +343,6 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) std::cout << "USRP1 EEPROM image: " << usrp1_eeprom_image << std::endl; _ctrl_transport->usrp_load_eeprom(val.as()); } - - if(key.as() == "serial") { - std::string sernum = val.as(); - uhd::byte_vector_t buf(sernum.begin(), sernum.end()); - buf.insert(buf.begin(), 248); - _iface->write_i2c(I2C_DEV_EEPROM, buf); - } - return; } @@ -395,6 +379,11 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) _iface->poke32(FR_TX_MUX, calc_tx_mux(_tx_subdev_spec, _mboard_proxy->get_link())); return; + case MBOARD_PROP_EEPROM_MAP: + _mb_eeprom = val.as(); + _mb_eeprom.commit(*_iface, mboard_eeprom_t::MAP_BXXX); + return; + default: UHD_THROW_PROP_SET_ERROR(); } } diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp index ff4d40762..3eb221a52 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.hpp +++ b/host/lib/usrp/usrp1/usrp1_impl.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -158,6 +159,7 @@ private: void mboard_get(const wax::obj &, wax::obj &); void mboard_set(const wax::obj &, const wax::obj &); wax_obj_proxy::sptr _mboard_proxy; + uhd::usrp::mboard_eeprom_t _mb_eeprom; //xx dboard functions and settings void dboard_init(void); diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index a95864ca7..f0fa806c5 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -33,23 +33,19 @@ INSTALL(TARGETS ######################################################################## # Utilities that get installed into the share path ######################################################################## -ADD_EXECUTABLE(usrp2_addr_burner usrp2_addr_burner.cpp) -TARGET_LINK_LIBRARIES(usrp2_addr_burner uhd) - ADD_EXECUTABLE(usrp_burn_db_eeprom usrp_burn_db_eeprom.cpp) TARGET_LINK_LIBRARIES(usrp_burn_db_eeprom uhd) +ADD_EXECUTABLE(usrp_burn_mb_eeprom usrp_burn_mb_eeprom.cpp) +TARGET_LINK_LIBRARIES(usrp_burn_mb_eeprom uhd) + ADD_EXECUTABLE(usrp1_init_eeprom usrp1_init_eeprom.cpp) TARGET_LINK_LIBRARIES(usrp1_init_eeprom uhd) -ADD_EXECUTABLE(usrp1_serial_burner usrp1_serial_burner.cpp) -TARGET_LINK_LIBRARIES(usrp1_serial_burner uhd) - INSTALL(TARGETS - usrp2_addr_burner usrp_burn_db_eeprom + usrp_burn_mb_eeprom usrp1_init_eeprom - usrp1_serial_burner RUNTIME DESTINATION ${PKG_DATA_DIR}/utils ) diff --git a/host/utils/usrp1_serial_burner.cpp b/host/utils/usrp1_serial_burner.cpp deleted file mode 100644 index bf7d3d3bb..000000000 --- a/host/utils/usrp1_serial_burner.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// -// Copyright 2010 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 . -// - -#include -#include -#include -#include -#include -#include - -namespace po = boost::program_options; - -int UHD_SAFE_MAIN(int argc, char *argv[]){ - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("old", po::value(), "old USRP serial number (optional)") - ("new", po::value(), "new USRP serial number") - ; - - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - - //print the help message - if (vm.count("help")){ - std::cout << boost::format("USRP serial burner %s") % desc << std::endl; - return ~0; - } - - if(vm.count("new") == 0) { - std::cout << "error: must input --new arg" << std::endl; - return ~0; - } - - //load the options into the address - uhd::device_addr_t device_addr; - device_addr["type"] = "usrp1"; - if(vm.count("old")) device_addr["serial"] = vm["old"].as(); - - //find and create a control transport to do the writing. - - uhd::device_addrs_t found_addrs = uhd::device::find(device_addr); - - if (found_addrs.size() == 0){ - std::cerr << "No USRP devices found" << std::endl; - return ~0; - } - - for (size_t i = 0; i < found_addrs.size(); i++){ - uhd::device::sptr dev = uhd::device::make(found_addrs[i]); - wax::obj mb = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD]; - std::cout << "Writing serial number..." << std::endl; - mb[std::string("serial")] = vm["new"].as(); - std::cout << "Reading back serial number: " << mb[std::string("serial")].as() << std::endl; - } - - - std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl; - return 0; -} diff --git a/host/utils/usrp2_addr_burner.cpp b/host/utils/usrp2_addr_burner.cpp deleted file mode 100644 index f0e3434b7..000000000 --- a/host/utils/usrp2_addr_burner.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// -// Copyright 2010 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 . -// - -#include -#include -#include -#include -#include -#include - -namespace po = boost::program_options; - -int UHD_SAFE_MAIN(int argc, char *argv[]){ - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("addr", po::value(), "resolvable network address") - ("new-ip", po::value(), "new ip address (optional)") - ("new-mac", po::value(), "new mac address (optional)") - ; - - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - - //print the help message - if (vm.count("help")){ - std::cout << boost::format("USRP2 Address Burner %s") % desc << std::endl; - return ~0; - } - - //load the options into the address - uhd::device_addr_t device_addr; - device_addr["type"] = "usrp2"; - if (vm.count("addr")){ - device_addr["addr"] = vm["addr"].as(); - } - else{ - std::cerr << "Error: missing addr option" << std::endl; - return ~0; - } - - //create a usrp2 device - uhd::device::sptr u2_dev = uhd::device::make(device_addr); - //FIXME usees the default mboard for now (until the mimo link is supported) - wax::obj u2_mb = (*u2_dev)[uhd::usrp::DEVICE_PROP_MBOARD]; - std::cout << std::endl; - - //fetch and print current settings - std::cout << "Fetching current settings from usrp2 eeprom:" << std::endl; - std::string curr_ip = u2_mb[std::string("ip-addr")].as(); - std::cout << boost::format(" Current IP Address: %s") % curr_ip << std::endl; - std::string curr_mac = u2_mb[std::string("mac-addr")].as(); - std::cout << boost::format(" Current MAC Address: %s") % curr_mac << std::endl; - std::cout << " Done" << std::endl << std::endl; - - //try to set the new ip (if provided) - if (vm.count("new-ip")){ - std::cout << "Burning a new ip address into the usrp2 eeprom:" << std::endl; - std::string new_ip = vm["new-ip"].as(); - std::cout << boost::format(" New IP Address: %s") % new_ip << std::endl; - u2_mb[std::string("ip-addr")] = new_ip; - std::cout << " Done" << std::endl << std::endl; - } - - //try to set the new mac (if provided) - if (vm.count("new-mac")){ - std::cout << "Burning a new mac address into the usrp2 eeprom:" << std::endl; - std::string new_mac = vm["new-mac"].as(); - std::cout << boost::format(" New MAC Address: %s") % new_mac << std::endl; - u2_mb[std::string("mac-addr")] = new_mac; - std::cout << " Done" << std::endl << std::endl; - } - - std::cout << "Power-cycle the usrp2 for the changes to take effect." << std::endl; - return 0; -} diff --git a/host/utils/usrp_burn_db_eeprom.cpp b/host/utils/usrp_burn_db_eeprom.cpp index 64ecf75d6..9afd71a22 100644 --- a/host/utils/usrp_burn_db_eeprom.cpp +++ b/host/utils/usrp_burn_db_eeprom.cpp @@ -58,10 +58,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //print the help message if (vm.count("help")){ - std::cout << boost::format("USRP Burn DB EEPROM %s") % desc << std::endl; + std::cout << boost::format("USRP Burn Daughterboard EEPROM %s") % desc << std::endl; std::cout << boost::format( - "Omit the id argument to perform readback,\n" - "Or specify a new id to burn into the eeprom.\n" + "Omit the ID argument to perform readback,\n" + "Or specify a new ID to burn into the EEPROM.\n" ) << std::endl; return ~0; } diff --git a/host/utils/usrp_burn_mb_eeprom.cpp b/host/utils/usrp_burn_mb_eeprom.cpp new file mode 100644 index 000000000..8d0835222 --- /dev/null +++ b/host/utils/usrp_burn_mb_eeprom.cpp @@ -0,0 +1,79 @@ +// +// Copyright 2010 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 . +// + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace po = boost::program_options; + +int UHD_SAFE_MAIN(int argc, char *argv[]){ + std::string args, key, val; + + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("args", po::value(&args)->default_value(""), "device address args [default = \"\"]") + ("key", po::value(&key), "the indentifier for a value in EEPROM") + ("val", po::value(&val), "the new value to set, omit for readback") + ; + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help") or not vm.count("key")){ + std::cout << boost::format("USRP Burn Motherboard EEPROM %s") % desc << std::endl; + std::cout << boost::format( + "Omit the value argument to perform a readback,\n" + "Or specify a new value to burn into the EEPROM.\n" + ) << std::endl; + return ~0; + } + + std::cout << "Creating USRP device from address: " + args << std::endl; + uhd::device::sptr dev = uhd::device::make(args); + std::cout << std::endl; + + std::cout << "Fetching current settings from EEPROM..." << std::endl; + //FIXME the default mboard for now (may be others) + wax::obj mboard = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD]; + uhd::usrp::mboard_eeprom_t mb_eeprom = \ + mboard[uhd::usrp::MBOARD_PROP_EEPROM_MAP].as(); + if (not mb_eeprom.has_key(key)){ + std::cerr << boost::format("Cannot find value for EEPROM[%s]") % key << std::endl; + return ~0; + } + std::cout << boost::format(" EEPROM [\"%s\"] is \"%s\"") % key % mb_eeprom[key] << std::endl; + std::cout << std::endl; + + if (vm.count("val")){ + std::cout << boost::format("Setting EEPROM [\"%s\"] to \"%s\"...") % key % val << std::endl; + mb_eeprom[key] = val; + mboard[uhd::usrp::MBOARD_PROP_EEPROM_MAP] = mb_eeprom; + std::cout << "Power-cycle the USRP device for the changes to take effect." << std::endl; + } + + std::cout << "Done" << std::endl; + return 0; +} -- cgit v1.2.3 From 144ebf29327981db8422049b451852744619678d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 5 Nov 2010 01:01:51 -0700 Subject: usrp: implement name checking on dicovery (all platforms), separate usb serial from serial (for now) --- host/lib/usrp/mboard_eeprom.cpp | 17 +++++++++++++++-- host/lib/usrp/usrp1/mboard_impl.cpp | 10 ++++------ host/lib/usrp/usrp1/usrp1_iface.cpp | 4 +++- host/lib/usrp/usrp1/usrp1_iface.hpp | 3 +++ host/lib/usrp/usrp1/usrp1_impl.cpp | 13 +++++++++++-- host/lib/usrp/usrp1/usrp1_impl.hpp | 2 -- host/lib/usrp/usrp2/usrp2_impl.cpp | 18 ++++++++++++++++-- 7 files changed, 52 insertions(+), 15 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/mboard_eeprom.cpp b/host/lib/usrp/mboard_eeprom.cpp index 81dc6f194..89e83bd56 100644 --- a/host/lib/usrp/mboard_eeprom.cpp +++ b/host/lib/usrp/mboard_eeprom.cpp @@ -132,13 +132,20 @@ static void store_nxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ * Implementation of BXXX load/store **********************************************************************/ static const boost::uint8_t BXXX_EEPROM_ADDR = 0x50; +static const size_t USB_SERIAL_LEN = 16; static const uhd::dict USRP_BXXX_OFFSETS = boost::assign::map_list_of - ("serial", 0xf8) - ("name", 0xf8 + SERIAL_LEN) + ("usb-serial", 0xf8) + ("serial", 0xf8 + USB_SERIAL_LEN) + ("name", 0xf8 + USB_SERIAL_LEN + SERIAL_LEN) ; static void load_bxxx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ + //extract the usb serial + mb_eeprom["usb-serial"] = bytes_to_string(iface.read_eeprom( + BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["usb-serial"], USB_SERIAL_LEN + )); + //extract the serial mb_eeprom["serial"] = bytes_to_string(iface.read_eeprom( BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["serial"], SERIAL_LEN @@ -151,6 +158,12 @@ static void load_bxxx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ } static void store_bxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ + //store the usb serial + iface.write_eeprom( + BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["usb-serial"], + string_to_bytes(mb_eeprom["usb-serial"], USB_SERIAL_LEN) + ); + //store the serial iface.write_eeprom( BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["serial"], diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index d7ab46eb1..86f78a7a9 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -208,8 +208,6 @@ bool usrp1_impl::has_tx_halfband(void){ **********************************************************************/ void usrp1_impl::mboard_init(void) { - _mb_eeprom = mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_BXXX); - _mboard_proxy = wax_obj_proxy::make( boost::bind(&usrp1_impl::mboard_get, this, _1, _2), boost::bind(&usrp1_impl::mboard_set, this, _1, _2)); @@ -267,7 +265,7 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) //handle the get request conditioned on the key switch(key.as()){ case MBOARD_PROP_NAME: - val = std::string("usrp1 mboard - " + _mb_eeprom["serial"]); + val = std::string("usrp1 mboard - " + _iface->mb_eeprom["serial"]); return; case MBOARD_PROP_OTHERS: @@ -325,7 +323,7 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) return; case MBOARD_PROP_EEPROM_MAP: - val = _mb_eeprom; + val = _iface->mb_eeprom; return; default: UHD_THROW_PROP_GET_ERROR(); @@ -380,8 +378,8 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) return; case MBOARD_PROP_EEPROM_MAP: - _mb_eeprom = val.as(); - _mb_eeprom.commit(*_iface, mboard_eeprom_t::MAP_BXXX); + _iface->mb_eeprom = val.as(); + _iface->mb_eeprom.commit(*_iface, mboard_eeprom_t::MAP_BXXX); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp index 64ced2905..dcba3e819 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.cpp +++ b/host/lib/usrp/usrp1/usrp1_iface.cpp @@ -25,6 +25,7 @@ #include using namespace uhd; +using namespace uhd::usrp; using namespace uhd::transport; static const bool iface_debug = false; @@ -36,7 +37,8 @@ public: ******************************************************************/ usrp1_iface_impl(usrp_ctrl::sptr ctrl_transport) { - _ctrl_transport = ctrl_transport; + _ctrl_transport = ctrl_transport; + mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_BXXX); } ~usrp1_iface_impl(void) diff --git a/host/lib/usrp/usrp1/usrp1_iface.hpp b/host/lib/usrp/usrp1/usrp1_iface.hpp index 3f608584a..34a2330b5 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.hpp +++ b/host/lib/usrp/usrp1/usrp1_iface.hpp @@ -18,6 +18,7 @@ #ifndef INCLUDED_USRP1_IFACE_HPP #define INCLUDED_USRP1_IFACE_HPP +#include #include #include #include @@ -81,6 +82,8 @@ public: boost::uint16_t index, unsigned char* buff, boost::uint16_t length) = 0; + + uhd::usrp::mboard_eeprom_t mb_eeprom; }; #endif /* INCLUDED_USRP1_IFACE_HPP */ diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index bc478c7fb..6016b0979 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -56,6 +56,10 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) //return an empty list of addresses when type is set to non-usrp1 if (hint.has_key("type") and hint["type"] != "usrp1") return usrp1_addrs; + //Return an empty list of addresses when an address is specified, + //since an address is intended for a different, non-USB, device. + if (hint.has_key("addr")) return usrp1_addrs; + //extract the firmware path for the USRP1 std::string usrp1_fw_image; try{ @@ -89,11 +93,16 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) pid = USRP1_PRODUCT_ID; BOOST_FOREACH(usb_device_handle::sptr handle, usb_device_handle::get_device_list(vid, pid)) { + usrp1_iface::sptr iface = usrp1_iface::make(usrp_ctrl::make(usb_control::make(handle))); device_addr_t new_addr; new_addr["type"] = "usrp1"; + new_addr["name"] = iface->mb_eeprom["name"]; new_addr["serial"] = handle->get_serial(); - //this is a found usrp1 when a hint serial is not specified or it matches - if (not hint.has_key("serial") or hint["serial"] == new_addr["serial"]){ + //this is a found usrp1 when the hint serial and name match or blank + if ( + (not hint.has_key("name") or hint["name"] == new_addr["name"]) and + (not hint.has_key("serial") or hint["serial"] == new_addr["serial"]) + ){ usrp1_addrs.push_back(new_addr); } } diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp index 3eb221a52..ff4d40762 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.hpp +++ b/host/lib/usrp/usrp1/usrp1_impl.hpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -159,7 +158,6 @@ private: void mboard_get(const wax::obj &, wax::obj &); void mboard_set(const wax::obj &, const wax::obj &); wax_obj_proxy::sptr _mboard_proxy; - uhd::usrp::mboard_eeprom_t _mb_eeprom; //xx dboard functions and settings void dboard_init(void); diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index a680708ad..d94a8606e 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -61,7 +61,7 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ if (if_addrs.inet == asio::ip::address_v4::loopback().to_string()) continue; //create a new hint with this broadcast address - device_addr_t new_hint; + device_addr_t new_hint = hint; new_hint["addr"] = if_addrs.bcast; //call discover with the new hint and append results @@ -110,7 +110,21 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ device_addr_t new_addr; new_addr["type"] = "usrp2"; new_addr["addr"] = ip_addr.to_string(); - usrp2_addrs.push_back(new_addr); + //Attempt to read the name from the EEPROM and perform filtering. + //This operation can throw due to COMPAT mismatch. That is OK. + //We will allow the device to be found and the COMPAT mismatch + //will be thrown as an exception in the factory function. + try{ + new_addr["name"] = usrp2_iface::make(udp_simple::make_connected( + new_addr["addr"], num2str(USRP2_UDP_CTRL_PORT)) + )->mb_eeprom["name"]; + if (not hint.has_key("name") or hint["name"] == new_addr["name"]){ + usrp2_addrs.push_back(new_addr); + } + } + catch(const std::exception &){ + usrp2_addrs.push_back(new_addr); + } //dont break here, it will exit the while loop //just continue on to the next loop iteration } -- cgit v1.2.3 From 94a492dc40a6450ada3fe34a7440c31077d9690e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 5 Nov 2010 17:39:18 -0700 Subject: uhd: rename identifier for usrp1 eeprom, and fix offsets, add serial support to usrp2 --- firmware/fx2/usrp1/CMakeLists.txt | 2 +- host/include/uhd/usrp/mboard_eeprom.hpp | 2 +- host/lib/usrp/mboard_eeprom.cpp | 30 +++++++++-------- host/lib/usrp/usrp1/mboard_impl.cpp | 2 +- host/lib/usrp/usrp1/usrp1_iface.cpp | 2 +- host/lib/usrp/usrp2/usrp2_impl.cpp | 57 +++++++++++++++++---------------- 6 files changed, 50 insertions(+), 45 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/firmware/fx2/usrp1/CMakeLists.txt b/firmware/fx2/usrp1/CMakeLists.txt index 3d99a2ac1..6607bc7f2 100644 --- a/firmware/fx2/usrp1/CMakeLists.txt +++ b/firmware/fx2/usrp1/CMakeLists.txt @@ -77,7 +77,7 @@ set(eeprom1_sources add_custom_target(usrp1_eeprom ALL DEPENDS usrp1_boot COMMAND objcopy -I ihex -O binary usrp1_boot.ihx usrp1_boot.bin - COMMAND ${PYTHON_EXECUTABLE} ${BUILD_EEPROM} -r2 usrp1_boot.bin usrp1_eeprom.bin + COMMAND ${PYTHON_EXECUTABLE} ${BUILD_EEPROM} -r1 usrp1_boot.bin usrp1_eeprom.bin ) add_executable(usrp1_boot ${eeprom1_sources}) diff --git a/host/include/uhd/usrp/mboard_eeprom.hpp b/host/include/uhd/usrp/mboard_eeprom.hpp index bc3f1f8c9..f44275aad 100644 --- a/host/include/uhd/usrp/mboard_eeprom.hpp +++ b/host/include/uhd/usrp/mboard_eeprom.hpp @@ -37,7 +37,7 @@ namespace uhd{ namespace usrp{ //! Possible EEPROM maps types enum map_type{ MAP_NXXX, - MAP_BXXX + MAP_B1XX }; //! Make a new empty mboard eeprom diff --git a/host/lib/usrp/mboard_eeprom.cpp b/host/lib/usrp/mboard_eeprom.cpp index 81dc6f194..49d429674 100644 --- a/host/lib/usrp/mboard_eeprom.cpp +++ b/host/lib/usrp/mboard_eeprom.cpp @@ -94,6 +94,9 @@ static void load_nxxx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ mb_eeprom["name"] = bytes_to_string(iface.read_eeprom( NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["name"], NAME_MAX_LEN )); + + //empty serial correction: use the mac address + if (mb_eeprom["serial"].empty()) mb_eeprom["serial"] = mb_eeprom["mac-addr"]; } static void store_nxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ @@ -129,37 +132,38 @@ static void store_nxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ } /*********************************************************************** - * Implementation of BXXX load/store + * Implementation of B1XX load/store **********************************************************************/ -static const boost::uint8_t BXXX_EEPROM_ADDR = 0x50; +static const boost::uint8_t B1XX_EEPROM_ADDR = 0x50; +static const size_t B1XXX_SERIAL_LEN = 8; -static const uhd::dict USRP_BXXX_OFFSETS = boost::assign::map_list_of +static const uhd::dict USRP_B1XX_OFFSETS = boost::assign::map_list_of ("serial", 0xf8) - ("name", 0xf8 + SERIAL_LEN) + ("name", 0xf8 - NAME_MAX_LEN) ; -static void load_bxxx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ +static void load_b1xx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ //extract the serial mb_eeprom["serial"] = bytes_to_string(iface.read_eeprom( - BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["serial"], SERIAL_LEN + B1XX_EEPROM_ADDR, USRP_B1XX_OFFSETS["serial"], B1XXX_SERIAL_LEN )); //extract the name mb_eeprom["name"] = bytes_to_string(iface.read_eeprom( - BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["name"], NAME_MAX_LEN + B1XX_EEPROM_ADDR, USRP_B1XX_OFFSETS["name"], NAME_MAX_LEN )); } -static void store_bxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ +static void store_b1xx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ //store the serial iface.write_eeprom( - BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["serial"], - string_to_bytes(mb_eeprom["serial"], SERIAL_LEN) + B1XX_EEPROM_ADDR, USRP_B1XX_OFFSETS["serial"], + string_to_bytes(mb_eeprom["serial"], B1XXX_SERIAL_LEN) ); //store the name iface.write_eeprom( - BXXX_EEPROM_ADDR, USRP_BXXX_OFFSETS["name"], + B1XX_EEPROM_ADDR, USRP_B1XX_OFFSETS["name"], string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN) ); } @@ -174,13 +178,13 @@ mboard_eeprom_t::mboard_eeprom_t(void){ mboard_eeprom_t::mboard_eeprom_t(i2c_iface &iface, map_type map){ switch(map){ case MAP_NXXX: load_nxxx(*this, iface); break; - case MAP_BXXX: load_bxxx(*this, iface); break; + case MAP_B1XX: load_b1xx(*this, iface); break; } } void mboard_eeprom_t::commit(i2c_iface &iface, map_type map){ switch(map){ case MAP_NXXX: store_nxxx(*this, iface); break; - case MAP_BXXX: store_bxxx(*this, iface); break; + case MAP_B1XX: store_b1xx(*this, iface); break; } } diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 86f78a7a9..952da8dce 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -379,7 +379,7 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) case MBOARD_PROP_EEPROM_MAP: _iface->mb_eeprom = val.as(); - _iface->mb_eeprom.commit(*_iface, mboard_eeprom_t::MAP_BXXX); + _iface->mb_eeprom.commit(*_iface, mboard_eeprom_t::MAP_B1XX); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp index dcba3e819..691c51fe8 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.cpp +++ b/host/lib/usrp/usrp1/usrp1_iface.cpp @@ -38,7 +38,7 @@ public: usrp1_iface_impl(usrp_ctrl::sptr ctrl_transport) { _ctrl_transport = ctrl_transport; - mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_BXXX); + mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_B1XX); } ~usrp1_iface_impl(void) diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 6625cf3e7..5f549c4fd 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -102,36 +102,37 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ while(true){ size_t len = udp_transport->recv(asio::buffer(usrp2_ctrl_data_in_mem), DISCOVERY_TIMEOUT_MS); //std::cout << len << "\n"; - if (len > offsetof(usrp2_ctrl_data_t, data)){ - //handle the received data - switch(ntohl(ctrl_data_in->id)){ - case USRP2_CTRL_ID_WAZZUP_DUDE: - //make a boost asio ipv4 with the raw addr in host byte order - boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in->data.ip_addr)); - device_addr_t new_addr; - new_addr["type"] = "usrp2"; - new_addr["addr"] = ip_addr.to_string(); - //Attempt to read the name from the EEPROM and perform filtering. - //This operation can throw due to COMPAT mismatch. That is OK. - //We will allow the device to be found and the COMPAT mismatch - //will be thrown as an exception in the factory function. - try{ - new_addr["name"] = usrp2_iface::make(udp_simple::make_connected( - new_addr["addr"], num2str(USRP2_UDP_CTRL_PORT)) - )->mb_eeprom["name"]; - if (not hint.has_key("name") or hint["name"] == new_addr["name"]){ - usrp2_addrs.push_back(new_addr); - } + if (len > offsetof(usrp2_ctrl_data_t, data) and ntohl(ctrl_data_in->id) == USRP2_CTRL_ID_WAZZUP_DUDE){ + //make a boost asio ipv4 with the raw addr in host byte order + boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in->data.ip_addr)); + device_addr_t new_addr; + new_addr["type"] = "usrp2"; + new_addr["addr"] = ip_addr.to_string(); + //Attempt to read the name from the EEPROM and perform filtering. + //This operation can throw due to COMPAT mismatch. That is OK. + //We will allow the device to be found and the COMPAT mismatch + //will be thrown as an exception in the factory function. + try{ + mboard_eeprom_t mb_eeprom = usrp2_iface::make( + udp_simple::make_connected(new_addr["addr"], num2str(USRP2_UDP_CTRL_PORT)) + )->mb_eeprom; + new_addr["name"] = mb_eeprom["name"]; + new_addr["serial"] = mb_eeprom["serial"]; + if ( + (not hint.has_key("name") or hint["name"] == new_addr["name"]) and + (not hint.has_key("serial") or hint["serial"] == new_addr["serial"]) + ){ + usrp2_addrs.push_back(new_addr); } - catch(const std::exception &e){ - uhd::warning::post( - std::string("Ignoring discovered device\n") - + e.what() - ); - } - //dont break here, it will exit the while loop - //just continue on to the next loop iteration } + catch(const std::exception &e){ + uhd::warning::post( + std::string("Ignoring discovered device\n") + + e.what() + ); + } + //dont break here, it will exit the while loop + //just continue on to the next loop iteration } if (len == 0) break; //timeout } -- cgit v1.2.3 From 1a86e65a18ac7005f0a4dae3bc7fc26e8041267c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 5 Nov 2010 17:56:23 -0700 Subject: uhd: for eeprom writeback, write and set only those values changed --- host/lib/usrp/mboard_eeprom.cpp | 32 ++++++++++++++++++-------------- host/lib/usrp/usrp1/mboard_impl.cpp | 6 ++++-- host/lib/usrp/usrp2/mboard_impl.cpp | 6 ++++-- host/utils/usrp_burn_mb_eeprom.cpp | 24 +++++++++++++----------- 4 files changed, 39 insertions(+), 29 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/mboard_eeprom.cpp b/host/lib/usrp/mboard_eeprom.cpp index 49d429674..076d0b279 100644 --- a/host/lib/usrp/mboard_eeprom.cpp +++ b/host/lib/usrp/mboard_eeprom.cpp @@ -101,31 +101,35 @@ static void load_nxxx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ static void store_nxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ //parse the revision number - boost::uint16_t rev = boost::lexical_cast(mb_eeprom["rev"]); - byte_vector_t rev_lsb_msb = boost::assign::list_of - (boost::uint8_t(rev >> 0)) - (boost::uint8_t(rev >> 8)) - ; - iface.write_eeprom(NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["rev-lsb-msb"], rev_lsb_msb); + if (mb_eeprom.has_key("rev")){ + boost::uint16_t rev = boost::lexical_cast(mb_eeprom["rev"]); + byte_vector_t rev_lsb_msb = boost::assign::list_of + (boost::uint8_t(rev >> 0)) + (boost::uint8_t(rev >> 8)) + ; + iface.write_eeprom(NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["rev-lsb-msb"], rev_lsb_msb); + } //store the addresses - iface.write_eeprom( + if (mb_eeprom.has_key("mac-addr")) iface.write_eeprom( NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["mac-addr"], mac_addr_t::from_string(mb_eeprom["mac-addr"]).to_bytes() ); - byte_vector_t ip_addr_bytes(4); - std::copy(boost::asio::ip::address_v4::from_string(mb_eeprom["ip-addr"]).to_bytes(), ip_addr_bytes); - iface.write_eeprom(NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["ip-addr"], ip_addr_bytes); + if (mb_eeprom.has_key("ip-addr")){ + byte_vector_t ip_addr_bytes(4); + std::copy(boost::asio::ip::address_v4::from_string(mb_eeprom["ip-addr"]).to_bytes(), ip_addr_bytes); + iface.write_eeprom(NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["ip-addr"], ip_addr_bytes); + } //store the serial - iface.write_eeprom( + if (mb_eeprom.has_key("serial")) iface.write_eeprom( NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["serial"], string_to_bytes(mb_eeprom["serial"], SERIAL_LEN) ); //store the name - iface.write_eeprom( + if (mb_eeprom.has_key("name")) iface.write_eeprom( NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["name"], string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN) ); @@ -156,13 +160,13 @@ static void load_b1xx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ static void store_b1xx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ //store the serial - iface.write_eeprom( + if (mb_eeprom.has_key("serial")) iface.write_eeprom( B1XX_EEPROM_ADDR, USRP_B1XX_OFFSETS["serial"], string_to_bytes(mb_eeprom["serial"], B1XXX_SERIAL_LEN) ); //store the name - iface.write_eeprom( + if (mb_eeprom.has_key("name")) iface.write_eeprom( B1XX_EEPROM_ADDR, USRP_B1XX_OFFSETS["name"], string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN) ); diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 952da8dce..c1f0f1d38 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -378,8 +378,10 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) return; case MBOARD_PROP_EEPROM_MAP: - _iface->mb_eeprom = val.as(); - _iface->mb_eeprom.commit(*_iface, mboard_eeprom_t::MAP_B1XX); + // Step1: commit the map, writing only those values set. + // Step2: readback the entire eeprom map into the iface. + val.as().commit(*_iface, mboard_eeprom_t::MAP_B1XX); + _iface->mb_eeprom = mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_B1XX); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 079f096cb..df98ba275 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -314,8 +314,10 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){ return; case MBOARD_PROP_EEPROM_MAP: - _iface->mb_eeprom = val.as(); - _iface->mb_eeprom.commit(*_iface, mboard_eeprom_t::MAP_NXXX); + // Step1: commit the map, writing only those values set. + // Step2: readback the entire eeprom map into the iface. + val.as().commit(*_iface, mboard_eeprom_t::MAP_NXXX); + _iface->mb_eeprom = mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_NXXX); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/utils/usrp_burn_mb_eeprom.cpp b/host/utils/usrp_burn_mb_eeprom.cpp index 8d0835222..20e1b58b1 100644 --- a/host/utils/usrp_burn_mb_eeprom.cpp +++ b/host/utils/usrp_burn_mb_eeprom.cpp @@ -53,25 +53,27 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << "Creating USRP device from address: " + args << std::endl; uhd::device::sptr dev = uhd::device::make(args); - std::cout << std::endl; - - std::cout << "Fetching current settings from EEPROM..." << std::endl; //FIXME the default mboard for now (may be others) wax::obj mboard = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD]; - uhd::usrp::mboard_eeprom_t mb_eeprom = \ - mboard[uhd::usrp::MBOARD_PROP_EEPROM_MAP].as(); - if (not mb_eeprom.has_key(key)){ - std::cerr << boost::format("Cannot find value for EEPROM[%s]") % key << std::endl; - return ~0; - } - std::cout << boost::format(" EEPROM [\"%s\"] is \"%s\"") % key % mb_eeprom[key] << std::endl; std::cout << std::endl; + if (true /*always readback*/){ + std::cout << "Fetching current settings from EEPROM..." << std::endl; + uhd::usrp::mboard_eeprom_t mb_eeprom = \ + mboard[uhd::usrp::MBOARD_PROP_EEPROM_MAP].as(); + if (not mb_eeprom.has_key(key)){ + std::cerr << boost::format("Cannot find value for EEPROM[%s]") % key << std::endl; + return ~0; + } + std::cout << boost::format(" EEPROM [\"%s\"] is \"%s\"") % key % mb_eeprom[key] << std::endl; + std::cout << std::endl; + } if (vm.count("val")){ + uhd::usrp::mboard_eeprom_t mb_eeprom; mb_eeprom[key] = val; std::cout << boost::format("Setting EEPROM [\"%s\"] to \"%s\"...") % key % val << std::endl; - mb_eeprom[key] = val; mboard[uhd::usrp::MBOARD_PROP_EEPROM_MAP] = mb_eeprom; std::cout << "Power-cycle the USRP device for the changes to take effect." << std::endl; + std::cout << std::endl; } std::cout << "Done" << std::endl; -- cgit v1.2.3 From 8c434f7d63aca25b55d6d13dffcc1d7037261d4f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 10 Nov 2010 11:14:47 -0800 Subject: uhd: renamed enums to reflect new convention --- host/include/uhd/usrp/mboard_eeprom.hpp | 4 +-- host/lib/usrp/mboard_eeprom.cpp | 60 ++++++++++++++++----------------- host/lib/usrp/usrp1/mboard_impl.cpp | 4 +-- host/lib/usrp/usrp1/usrp1_iface.cpp | 2 +- host/lib/usrp/usrp2/mboard_impl.cpp | 4 +-- host/lib/usrp/usrp2/usrp2_iface.cpp | 2 +- 6 files changed, 38 insertions(+), 38 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/include/uhd/usrp/mboard_eeprom.hpp b/host/include/uhd/usrp/mboard_eeprom.hpp index f44275aad..530b177be 100644 --- a/host/include/uhd/usrp/mboard_eeprom.hpp +++ b/host/include/uhd/usrp/mboard_eeprom.hpp @@ -36,8 +36,8 @@ namespace uhd{ namespace usrp{ //! Possible EEPROM maps types enum map_type{ - MAP_NXXX, - MAP_B1XX + MAP_N100, + MAP_B000 }; //! Make a new empty mboard eeprom diff --git a/host/lib/usrp/mboard_eeprom.cpp b/host/lib/usrp/mboard_eeprom.cpp index 076d0b279..661030aa7 100644 --- a/host/lib/usrp/mboard_eeprom.cpp +++ b/host/lib/usrp/mboard_eeprom.cpp @@ -57,11 +57,11 @@ static const byte_vector_t string_to_bytes(const std::string &string, size_t max } /*********************************************************************** - * Implementation of NXXX load/store + * Implementation of N100 load/store **********************************************************************/ -static const boost::uint8_t NXXX_EEPROM_ADDR = 0x50; +static const boost::uint8_t N100_EEPROM_ADDR = 0x50; -static const uhd::dict USRP_NXXX_OFFSETS = boost::assign::map_list_of +static const uhd::dict USRP_N100_OFFSETS = boost::assign::map_list_of ("rev-lsb-msb", 0x00) ("mac-addr", 0x02) ("ip-addr", 0x08) @@ -70,36 +70,36 @@ static const uhd::dict USRP_NXXX_OFFSETS = boost::a ("name", 0x18 + SERIAL_LEN) ; -static void load_nxxx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ +static void load_n100(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ //extract the revision number - byte_vector_t rev_lsb_msb = iface.read_eeprom(NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["rev-lsb-msb"], 2); + byte_vector_t rev_lsb_msb = iface.read_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["rev-lsb-msb"], 2); boost::uint16_t rev = (boost::uint16_t(rev_lsb_msb.at(0)) << 0) | (boost::uint16_t(rev_lsb_msb.at(1)) << 8); mb_eeprom["rev"] = boost::lexical_cast(rev); //extract the addresses mb_eeprom["mac-addr"] = mac_addr_t::from_bytes(iface.read_eeprom( - NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["mac-addr"], 6 + N100_EEPROM_ADDR, USRP_N100_OFFSETS["mac-addr"], 6 )).to_string(); boost::asio::ip::address_v4::bytes_type ip_addr_bytes; - std::copy(iface.read_eeprom(NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["ip-addr"], 4), ip_addr_bytes); + std::copy(iface.read_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["ip-addr"], 4), ip_addr_bytes); mb_eeprom["ip-addr"] = boost::asio::ip::address_v4(ip_addr_bytes).to_string(); //extract the serial mb_eeprom["serial"] = bytes_to_string(iface.read_eeprom( - NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["serial"], SERIAL_LEN + N100_EEPROM_ADDR, USRP_N100_OFFSETS["serial"], SERIAL_LEN )); //extract the name mb_eeprom["name"] = bytes_to_string(iface.read_eeprom( - NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["name"], NAME_MAX_LEN + N100_EEPROM_ADDR, USRP_N100_OFFSETS["name"], NAME_MAX_LEN )); //empty serial correction: use the mac address if (mb_eeprom["serial"].empty()) mb_eeprom["serial"] = mb_eeprom["mac-addr"]; } -static void store_nxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ +static void store_n100(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ //parse the revision number if (mb_eeprom.has_key("rev")){ boost::uint16_t rev = boost::lexical_cast(mb_eeprom["rev"]); @@ -107,67 +107,67 @@ static void store_nxxx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ (boost::uint8_t(rev >> 0)) (boost::uint8_t(rev >> 8)) ; - iface.write_eeprom(NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["rev-lsb-msb"], rev_lsb_msb); + iface.write_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["rev-lsb-msb"], rev_lsb_msb); } //store the addresses if (mb_eeprom.has_key("mac-addr")) iface.write_eeprom( - NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["mac-addr"], + N100_EEPROM_ADDR, USRP_N100_OFFSETS["mac-addr"], mac_addr_t::from_string(mb_eeprom["mac-addr"]).to_bytes() ); if (mb_eeprom.has_key("ip-addr")){ byte_vector_t ip_addr_bytes(4); std::copy(boost::asio::ip::address_v4::from_string(mb_eeprom["ip-addr"]).to_bytes(), ip_addr_bytes); - iface.write_eeprom(NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["ip-addr"], ip_addr_bytes); + iface.write_eeprom(N100_EEPROM_ADDR, USRP_N100_OFFSETS["ip-addr"], ip_addr_bytes); } //store the serial if (mb_eeprom.has_key("serial")) iface.write_eeprom( - NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["serial"], + N100_EEPROM_ADDR, USRP_N100_OFFSETS["serial"], string_to_bytes(mb_eeprom["serial"], SERIAL_LEN) ); //store the name if (mb_eeprom.has_key("name")) iface.write_eeprom( - NXXX_EEPROM_ADDR, USRP_NXXX_OFFSETS["name"], + N100_EEPROM_ADDR, USRP_N100_OFFSETS["name"], string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN) ); } /*********************************************************************** - * Implementation of B1XX load/store + * Implementation of B000 load/store **********************************************************************/ -static const boost::uint8_t B1XX_EEPROM_ADDR = 0x50; -static const size_t B1XXX_SERIAL_LEN = 8; +static const boost::uint8_t B000_EEPROM_ADDR = 0x50; +static const size_t B000X_SERIAL_LEN = 8; -static const uhd::dict USRP_B1XX_OFFSETS = boost::assign::map_list_of +static const uhd::dict USRP_B000_OFFSETS = boost::assign::map_list_of ("serial", 0xf8) ("name", 0xf8 - NAME_MAX_LEN) ; -static void load_b1xx(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ +static void load_b000(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ //extract the serial mb_eeprom["serial"] = bytes_to_string(iface.read_eeprom( - B1XX_EEPROM_ADDR, USRP_B1XX_OFFSETS["serial"], B1XXX_SERIAL_LEN + B000_EEPROM_ADDR, USRP_B000_OFFSETS["serial"], B000X_SERIAL_LEN )); //extract the name mb_eeprom["name"] = bytes_to_string(iface.read_eeprom( - B1XX_EEPROM_ADDR, USRP_B1XX_OFFSETS["name"], NAME_MAX_LEN + B000_EEPROM_ADDR, USRP_B000_OFFSETS["name"], NAME_MAX_LEN )); } -static void store_b1xx(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ +static void store_b000(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ //store the serial if (mb_eeprom.has_key("serial")) iface.write_eeprom( - B1XX_EEPROM_ADDR, USRP_B1XX_OFFSETS["serial"], - string_to_bytes(mb_eeprom["serial"], B1XXX_SERIAL_LEN) + B000_EEPROM_ADDR, USRP_B000_OFFSETS["serial"], + string_to_bytes(mb_eeprom["serial"], B000X_SERIAL_LEN) ); //store the name if (mb_eeprom.has_key("name")) iface.write_eeprom( - B1XX_EEPROM_ADDR, USRP_B1XX_OFFSETS["name"], + B000_EEPROM_ADDR, USRP_B000_OFFSETS["name"], string_to_bytes(mb_eeprom["name"], NAME_MAX_LEN) ); } @@ -181,14 +181,14 @@ mboard_eeprom_t::mboard_eeprom_t(void){ mboard_eeprom_t::mboard_eeprom_t(i2c_iface &iface, map_type map){ switch(map){ - case MAP_NXXX: load_nxxx(*this, iface); break; - case MAP_B1XX: load_b1xx(*this, iface); break; + case MAP_N100: load_n100(*this, iface); break; + case MAP_B000: load_b000(*this, iface); break; } } void mboard_eeprom_t::commit(i2c_iface &iface, map_type map){ switch(map){ - case MAP_NXXX: store_nxxx(*this, iface); break; - case MAP_B1XX: store_b1xx(*this, iface); break; + case MAP_N100: store_n100(*this, iface); break; + case MAP_B000: store_b000(*this, iface); break; } } diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index c1f0f1d38..4df5ada0a 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -380,8 +380,8 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) case MBOARD_PROP_EEPROM_MAP: // Step1: commit the map, writing only those values set. // Step2: readback the entire eeprom map into the iface. - val.as().commit(*_iface, mboard_eeprom_t::MAP_B1XX); - _iface->mb_eeprom = mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_B1XX); + val.as().commit(*_iface, mboard_eeprom_t::MAP_B000); + _iface->mb_eeprom = mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_B000); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp index 691c51fe8..63fcd5777 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.cpp +++ b/host/lib/usrp/usrp1/usrp1_iface.cpp @@ -38,7 +38,7 @@ public: usrp1_iface_impl(usrp_ctrl::sptr ctrl_transport) { _ctrl_transport = ctrl_transport; - mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_B1XX); + mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_B000); } ~usrp1_iface_impl(void) diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index df98ba275..a6ca7f2d3 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -316,8 +316,8 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){ case MBOARD_PROP_EEPROM_MAP: // Step1: commit the map, writing only those values set. // Step2: readback the entire eeprom map into the iface. - val.as().commit(*_iface, mboard_eeprom_t::MAP_NXXX); - _iface->mb_eeprom = mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_NXXX); + val.as().commit(*_iface, mboard_eeprom_t::MAP_N100); + _iface->mb_eeprom = mboard_eeprom_t(*_iface, mboard_eeprom_t::MAP_N100); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index eb2685efa..09f3432d6 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -60,7 +60,7 @@ public: ) % int(USRP2_FPGA_COMPAT_NUM) % fpga_compat_num)); } - mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_NXXX); + mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_N100); } ~usrp2_iface_impl(void){ -- cgit v1.2.3