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 ++++-- 3 files changed, 26 insertions(+), 18 deletions(-) (limited to 'host/lib') 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(); -- cgit v1.2.3