diff options
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/usrp/dboard_eeprom.cpp | 25 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/dboard_iface.cpp | 12 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/dboard_impl.cpp | 41 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.cpp | 14 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.hpp | 3 |
5 files changed, 66 insertions, 29 deletions
diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp index a8fac602a..5ce0b2328 100644 --- a/host/lib/usrp/dboard_eeprom.cpp +++ b/host/lib/usrp/dboard_eeprom.cpp @@ -53,26 +53,37 @@ using namespace uhd::usrp; // daughterboard specific use //////////////////////////////////////////////////////////////////////// -dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &buf){ +//negative sum of bytes excluding checksum byte +static boost::uint8_t checksum(const byte_vector_t &bytes){ + int sum; + for (size_t i = 0; i < DB_EEPROM_CHKSUM; i++){ + sum += int(bytes.at(i)); + } + return (-sum) & 0xff; +} + +dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &bytes){ try{ - ASSERT_THROW(buf.size() >= num_bytes()); - ASSERT_THROW(buf[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); + ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN); + ASSERT_THROW(bytes[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); + ASSERT_THROW(bytes[DB_EEPROM_CHKSUM] == checksum(bytes)); id = \ - (boost::uint16_t(buf[DB_EEPROM_ID_LSB]) << 0) | - (boost::uint16_t(buf[DB_EEPROM_ID_MSB]) << 8) ; + (boost::uint16_t(bytes[DB_EEPROM_ID_LSB]) << 0) | + (boost::uint16_t(bytes[DB_EEPROM_ID_MSB]) << 8) ; }catch(const uhd::assert_error &e){ id = dboard_id::NONE; } } byte_vector_t dboard_eeprom_t::get_eeprom_bytes(void){ - byte_vector_t bytes(3); + byte_vector_t bytes(DB_EEPROM_CLEN, 0); //defaults to all zeros bytes[DB_EEPROM_MAGIC] = DB_EEPROM_MAGIC_VALUE; bytes[DB_EEPROM_ID_LSB] = boost::uint8_t(id >> 0); bytes[DB_EEPROM_ID_MSB] = boost::uint8_t(id >> 8); + bytes[DB_EEPROM_CHKSUM] = checksum(bytes); return bytes; } size_t dboard_eeprom_t::num_bytes(void){ - return 3; + return DB_EEPROM_CLEN; } diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index 9d9b745ae..9503c329b 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -42,8 +42,8 @@ public: void set_gpio_ddr(unit_t, boost::uint16_t); boost::uint16_t read_gpio(unit_t); - void write_i2c(int, const byte_vector_t &); - byte_vector_t read_i2c(int, size_t); + void write_i2c(boost::uint8_t, const byte_vector_t &); + byte_vector_t read_i2c(boost::uint8_t, size_t); double get_clock_rate(unit_t); void set_clock_enabled(unit_t, bool); @@ -212,12 +212,12 @@ boost::uint32_t usrp2_dboard_iface::read_write_spi( /*********************************************************************** * I2C **********************************************************************/ -void usrp2_dboard_iface::write_i2c(int i2c_addr, const byte_vector_t &buf){ - return _iface->write_i2c(i2c_addr, buf); +void usrp2_dboard_iface::write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){ + return _iface->write_i2c(addr, bytes); } -byte_vector_t usrp2_dboard_iface::read_i2c(int i2c_addr, size_t num_bytes){ - return _iface->read_i2c(i2c_addr, num_bytes); +byte_vector_t usrp2_dboard_iface::read_i2c(boost::uint8_t addr, size_t num_bytes){ + return _iface->read_i2c(addr, num_bytes); } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index d697f11f0..8952a9f75 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -18,7 +18,6 @@ #include "usrp2_impl.hpp" #include "usrp2_regs.hpp" -#include <uhd/usrp/dboard_eeprom.hpp> #include <uhd/usrp/subdev_props.hpp> #include <uhd/usrp/dboard_props.hpp> #include <uhd/utils/assert.hpp> @@ -34,16 +33,16 @@ using namespace uhd::usrp; * Helper Methods **********************************************************************/ void usrp2_impl::dboard_init(void){ - //extract the dboard ids - dboard_eeprom_t db_rx_eeprom(_iface->read_eeprom(I2C_ADDR_RX_DB, 0, dboard_eeprom_t::num_bytes())); - dboard_eeprom_t db_tx_eeprom(_iface->read_eeprom(I2C_ADDR_TX_DB, 0, dboard_eeprom_t::num_bytes())); + //read the dboard eeprom to extract the dboard ids + _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())); //create a new dboard interface and manager dboard_iface::sptr _dboard_iface( make_usrp2_dboard_iface(_iface, _clk_ctrl) ); _dboard_manager = dboard_manager::make( - db_rx_eeprom.id, db_tx_eeprom.id, _dboard_iface + _rx_db_eeprom.id, _tx_db_eeprom.id, _dboard_iface ); //load dboards @@ -120,19 +119,29 @@ void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ val = _rx_subdevs_in_use; return; + case DBOARD_PROP_DBOARD_ID: + val = _rx_db_eeprom.id; + return; + //case DBOARD_PROP_CODEC: // throw std::runtime_error("unhandled prop in usrp2 dboard"); } } void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ - if (key.as<dboard_prop_t>() == DBOARD_PROP_USED_SUBDEVS){ + switch(key.as<dboard_prop_t>()){ + case DBOARD_PROP_USED_SUBDEVS: _rx_subdevs_in_use = val.as<prop_names_t>(); update_rx_mux_config(); //if the val is bad, this will throw return; - } - throw std::runtime_error("Cannot set on usrp2 dboard"); + case DBOARD_PROP_DBOARD_ID: + _rx_db_eeprom.id = val.as<dboard_id_t>(); + _iface->write_eeprom(I2C_ADDR_RX_DB, 0, _tx_db_eeprom.get_eeprom_bytes()); + return; + + default: throw std::runtime_error("Cannot set read-only property on usrp2 dboard"); + } } /*********************************************************************** @@ -160,17 +169,27 @@ void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ val = _tx_subdevs_in_use; return; + case DBOARD_PROP_DBOARD_ID: + val = _tx_db_eeprom.id; + return; + //case DBOARD_PROP_CODEC: // throw std::runtime_error("unhandled prop in usrp2 dboard"); } } void usrp2_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){ - if (key.as<dboard_prop_t>() == DBOARD_PROP_USED_SUBDEVS){ + switch(key.as<dboard_prop_t>()){ + case DBOARD_PROP_USED_SUBDEVS: _tx_subdevs_in_use = val.as<prop_names_t>(); update_tx_mux_config(); //if the val is bad, this will throw return; - } - throw std::runtime_error("Cannot set on usrp2 dboard"); + 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()); + return; + + default: throw std::runtime_error("Cannot set read-only property on usrp2 dboard"); + } } diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index c639c0dfe..76ee5d6fe 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -136,8 +136,8 @@ public: /*********************************************************************** * EEPROM **********************************************************************/ - void write_eeprom(boost::uint8_t addr, boost::uint8_t offset, const byte_vector_t &buf){ - BOOST_FOREACH(boost::uint8_t byte, buf){ + void write_eeprom(boost::uint8_t addr, boost::uint8_t offset, const byte_vector_t &bytes){ + BOOST_FOREACH(boost::uint8_t byte, bytes){ //write a byte at a time, its easy that way byte_vector_t cmd = boost::assign::list_of(offset)(byte); this->write_i2c(addr, cmd); @@ -145,9 +145,13 @@ public: } byte_vector_t read_eeprom(boost::uint8_t addr, boost::uint8_t offset, size_t num_bytes){ - //do a zero byte write to start read cycle - write_i2c(addr, byte_vector_t(1, offset)); - return read_i2c(addr, num_bytes); + byte_vector_t bytes; + for (size_t i = 0; i < num_bytes; i++){ + //do a zero byte write to start read cycle + write_i2c(addr, byte_vector_t(1, offset)); + bytes.push_back(read_i2c(addr, 1).at(0)); + } + return bytes; } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index dbcee367b..1c9387744 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -25,6 +25,7 @@ #include <uhd/types/otw_type.hpp> #include <uhd/types/stream_cmd.hpp> #include <uhd/types/clock_config.hpp> +#include <uhd/usrp/dboard_eeprom.hpp> #include <boost/shared_ptr.hpp> #include <boost/function.hpp> #include <uhd/transport/vrt.hpp> @@ -161,12 +162,14 @@ private: void rx_dboard_set(const wax::obj &, const wax::obj &); wax_obj_proxy::sptr _rx_dboard_proxy; uhd::prop_names_t _rx_subdevs_in_use; + uhd::usrp::dboard_eeprom_t _rx_db_eeprom; //properties interface for tx dboard void tx_dboard_get(const wax::obj &, wax::obj &); void tx_dboard_set(const wax::obj &, const wax::obj &); wax_obj_proxy::sptr _tx_dboard_proxy; uhd::prop_names_t _tx_subdevs_in_use; + uhd::usrp::dboard_eeprom_t _tx_db_eeprom; void update_rx_mux_config(void); void update_tx_mux_config(void); |