diff options
author | Josh Blum <josh@joshknows.com> | 2011-02-22 10:57:53 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-02-22 10:57:53 -0800 |
commit | de35e125bc6e09fbe4da60f8f18390c137c77c43 (patch) | |
tree | 733f6d4411388f45a1dce6e79e556a14f439213a | |
parent | 814a5c40c6fbaedba3dafabbe30d00a05af6a274 (diff) | |
download | uhd-de35e125bc6e09fbe4da60f8f18390c137c77c43.tar.gz uhd-de35e125bc6e09fbe4da60f8f18390c137c77c43.tar.bz2 uhd-de35e125bc6e09fbe4da60f8f18390c137c77c43.zip |
uhd: simplify dboard eeprom code by passing iface into load/store
-rw-r--r-- | host/include/uhd/usrp/dboard_eeprom.hpp | 28 | ||||
-rw-r--r-- | host/lib/usrp/dboard_eeprom.cpp | 18 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/dboard_impl.cpp | 21 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/dboard_impl.cpp | 10 | ||||
-rw-r--r-- | host/lib/usrp/usrp_e100/dboard_impl.cpp | 10 |
5 files changed, 39 insertions, 48 deletions
diff --git a/host/include/uhd/usrp/dboard_eeprom.hpp b/host/include/uhd/usrp/dboard_eeprom.hpp index bbad0eee4..394d71dd6 100644 --- a/host/include/uhd/usrp/dboard_eeprom.hpp +++ b/host/include/uhd/usrp/dboard_eeprom.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 @@ -26,6 +26,7 @@ namespace uhd{ namespace usrp{ struct UHD_API dboard_eeprom_t{ + //! The ID for the daughterboard type dboard_id_t id; @@ -33,27 +34,24 @@ struct UHD_API dboard_eeprom_t{ std::string serial; /*! - * Create a dboard eeprom struct from the bytes read out of eeprom. - * The constructor will parse out the dboard id from a vector of bytes. - * To be valid, the bytes vector should be at least num_bytes() long. - * If the parsing fails due to bad checksum or incomplete length, - * the dboard id in this struct will be set to dboard_id::NONE. - * \param bytes the vector of bytes + * Create an empty dboard eeprom struct. */ - dboard_eeprom_t(const uhd::byte_vector_t &bytes = uhd::byte_vector_t(0)); + dboard_eeprom_t(void); /*! - * Get the bytes that would be written to dboard eeprom. - * \return a vector of bytes + * Load the object with bytes from the eeprom. + * \param iface the serial interface with i2c + * \param addr the i2c address for the eeprom */ - uhd::byte_vector_t get_eeprom_bytes(void); + void load(i2c_iface &iface, boost::uint8_t addr); /*! - * Get the number of bytes in the dboard eeprom segment. - * Use this value when reading out of the dboard eeprom. - * \return the number of bytes used by dboard eeprom + * Store the object to bytes in the eeprom. + * \param iface the serial interface with i2c + * \param addr the i2c address for the eeprom */ - static size_t num_bytes(void); + void store(i2c_iface &iface, boost::uint8_t addr); + }; }} //namespace diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp index 60d13548a..c47390bf8 100644 --- a/host/lib/usrp/dboard_eeprom.cpp +++ b/host/lib/usrp/dboard_eeprom.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 @@ -95,7 +95,14 @@ static boost::uint8_t checksum(const byte_vector_t &bytes){ return boost::uint8_t(sum); } -dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &bytes){ +dboard_eeprom_t::dboard_eeprom_t(void){ + id = dboard_id_t::none(); + serial = ""; +} + +void dboard_eeprom_t::load(i2c_iface &iface, boost::uint8_t addr){ + byte_vector_t bytes = iface.read_eeprom(addr, 0, DB_EEPROM_CLEN); + if (_dboard_eeprom_debug){ for (size_t i = 0; i < bytes.size(); i++){ std::cout << boost::format( @@ -127,7 +134,7 @@ dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &bytes){ } } -byte_vector_t dboard_eeprom_t::get_eeprom_bytes(void){ +void dboard_eeprom_t::store(i2c_iface &iface, boost::uint8_t addr){ byte_vector_t bytes(DB_EEPROM_CLEN, 0); //defaults to all zeros bytes[DB_EEPROM_MAGIC] = DB_EEPROM_MAGIC_VALUE; @@ -141,9 +148,6 @@ byte_vector_t dboard_eeprom_t::get_eeprom_bytes(void){ //load the checksum bytes[DB_EEPROM_CHKSUM] = checksum(bytes); - return bytes; -} -size_t dboard_eeprom_t::num_bytes(void){ - return DB_EEPROM_CLEN; + iface.write_eeprom(addr, 0, bytes); } diff --git a/host/lib/usrp/usrp1/dboard_impl.cpp b/host/lib/usrp/usrp1/dboard_impl.cpp index 2a2762a82..d794b8653 100644 --- a/host/lib/usrp/usrp1/dboard_impl.cpp +++ b/host/lib/usrp/usrp1/dboard_impl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 @@ -57,13 +57,8 @@ void usrp1_impl::dboard_init(void) BOOST_FOREACH(dboard_slot_t dboard_slot, _dboard_slots){ //read the tx and rx dboard eeproms - _rx_db_eeproms[dboard_slot] = dboard_eeprom_t(_iface->read_eeprom( - get_rx_ee_addr(dboard_slot), 0, dboard_eeprom_t::num_bytes() - )); - - _tx_db_eeproms[dboard_slot] = dboard_eeprom_t(_iface->read_eeprom( - get_tx_ee_addr(dboard_slot), 0, dboard_eeprom_t::num_bytes() - )); + _rx_db_eeproms[dboard_slot].load(*_iface, get_rx_ee_addr(dboard_slot)); + _tx_db_eeproms[dboard_slot].load(*_iface, get_tx_ee_addr(dboard_slot)); //create a new dboard interface and manager _dboard_ifaces[dboard_slot] = make_dboard_iface( @@ -143,10 +138,7 @@ void usrp1_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val, dboard_ switch(key.as<dboard_prop_t>()) { case DBOARD_PROP_DBOARD_ID: _rx_db_eeproms[dboard_slot].id = val.as<dboard_id_t>(); - _iface->write_eeprom( - get_rx_ee_addr(dboard_slot), 0, - _rx_db_eeproms[dboard_slot].get_eeprom_bytes() - ); + _rx_db_eeproms[dboard_slot].store(*_iface, get_rx_ee_addr(dboard_slot)); return; default: @@ -208,10 +200,7 @@ void usrp1_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val, dboard_ switch(key.as<dboard_prop_t>()) { case DBOARD_PROP_DBOARD_ID: _tx_db_eeproms[dboard_slot].id = val.as<dboard_id_t>(); - _iface->write_eeprom( - get_tx_ee_addr(dboard_slot), 0, - _tx_db_eeproms[dboard_slot].get_eeprom_bytes() - ); + _tx_db_eeproms[dboard_slot].store(*_iface, get_tx_ee_addr(dboard_slot)); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 4192c4f78..52da50132 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 @@ -35,8 +35,8 @@ using namespace uhd::usrp; **********************************************************************/ void usrp2_mboard_impl::dboard_init(void){ //read the dboard eeprom to extract the dboard ids - _rx_db_eeprom = dboard_eeprom_t(_iface->read_eeprom(USRP2_I2C_ADDR_RX_DB, 0, dboard_eeprom_t::num_bytes())); - _tx_db_eeprom = dboard_eeprom_t(_iface->read_eeprom(USRP2_I2C_ADDR_TX_DB, 0, dboard_eeprom_t::num_bytes())); + _rx_db_eeprom.load(*_iface, USRP2_I2C_ADDR_RX_DB); + _tx_db_eeprom.load(*_iface, USRP2_I2C_ADDR_TX_DB); //create a new dboard interface and manager _dboard_iface = make_usrp2_dboard_iface(_iface, _clock_ctrl); @@ -105,7 +105,7 @@ void usrp2_mboard_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ case DBOARD_PROP_DBOARD_ID: _rx_db_eeprom.id = val.as<dboard_id_t>(); - _iface->write_eeprom(USRP2_I2C_ADDR_RX_DB, 0, _rx_db_eeprom.get_eeprom_bytes()); + _rx_db_eeprom.store(*_iface, USRP2_I2C_ADDR_RX_DB); return; default: UHD_THROW_PROP_SET_ERROR(); @@ -162,7 +162,7 @@ void usrp2_mboard_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){ case DBOARD_PROP_DBOARD_ID: _tx_db_eeprom.id = val.as<dboard_id_t>(); - _iface->write_eeprom(USRP2_I2C_ADDR_TX_DB, 0, _tx_db_eeprom.get_eeprom_bytes()); + _tx_db_eeprom.store(*_iface, USRP2_I2C_ADDR_TX_DB); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp_e100/dboard_impl.cpp b/host/lib/usrp/usrp_e100/dboard_impl.cpp index 9f2bfb8ae..4297d41f1 100644 --- a/host/lib/usrp/usrp_e100/dboard_impl.cpp +++ b/host/lib/usrp/usrp_e100/dboard_impl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 @@ -31,8 +31,8 @@ using namespace uhd::usrp; * Dboard Initialization **********************************************************************/ void usrp_e100_impl::dboard_init(void){ - _rx_db_eeprom = dboard_eeprom_t(_iface->read_eeprom(I2C_ADDR_RX_DB, 0, dboard_eeprom_t::num_bytes())); - _tx_db_eeprom = dboard_eeprom_t(_iface->read_eeprom(I2C_ADDR_TX_DB, 0, dboard_eeprom_t::num_bytes())); + _rx_db_eeprom.load(*_iface, I2C_ADDR_RX_DB); + _tx_db_eeprom.load(*_iface, I2C_ADDR_TX_DB); //create a new dboard interface and manager _dboard_iface = make_usrp_e100_dboard_iface( @@ -105,7 +105,7 @@ void usrp_e100_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ switch(key.as<dboard_prop_t>()){ case DBOARD_PROP_DBOARD_ID: _rx_db_eeprom.id = val.as<dboard_id_t>(); - _iface->write_eeprom(I2C_ADDR_RX_DB, 0, _rx_db_eeprom.get_eeprom_bytes()); + _rx_db_eeprom.store(*_iface, I2C_ADDR_RX_DB); return; default: UHD_THROW_PROP_SET_ERROR(); @@ -164,7 +164,7 @@ void usrp_e100_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){ switch(key.as<dboard_prop_t>()){ case DBOARD_PROP_DBOARD_ID: _tx_db_eeprom.id = val.as<dboard_id_t>(); - _iface->write_eeprom(I2C_ADDR_TX_DB, 0, _tx_db_eeprom.get_eeprom_bytes()); + _tx_db_eeprom.store(*_iface, I2C_ADDR_TX_DB); return; default: UHD_THROW_PROP_SET_ERROR(); |