summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-04-24 10:46:12 -0700
committerJosh Blum <josh@joshknows.com>2010-04-24 10:46:12 -0700
commit300ddf7807e5dd7662b09023ab80da26dd878626 (patch)
tree6d1f6c31bf9db0ff67ef7e96e1a99c087a57a117
parent039eceb4b208b2ca5a3465d2f16c8d5a7c7276c7 (diff)
downloaduhd-300ddf7807e5dd7662b09023ab80da26dd878626.tar.gz
uhd-300ddf7807e5dd7662b09023ab80da26dd878626.tar.bz2
uhd-300ddf7807e5dd7662b09023ab80da26dd878626.zip
set dboard eeprom from dboard properties
-rw-r--r--host/include/uhd/usrp/dboard_eeprom.hpp17
-rw-r--r--host/include/uhd/usrp/dboard_iface.hpp10
-rw-r--r--host/include/uhd/usrp/dboard_manager.hpp1
-rw-r--r--host/include/uhd/usrp/dboard_props.hpp3
-rw-r--r--host/lib/usrp/dboard_eeprom.cpp25
-rw-r--r--host/lib/usrp/usrp2/dboard_iface.cpp12
-rw-r--r--host/lib/usrp/usrp2/dboard_impl.cpp41
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.cpp14
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp3
9 files changed, 84 insertions, 42 deletions
diff --git a/host/include/uhd/usrp/dboard_eeprom.hpp b/host/include/uhd/usrp/dboard_eeprom.hpp
index 6be88c85a..108027b46 100644
--- a/host/include/uhd/usrp/dboard_eeprom.hpp
+++ b/host/include/uhd/usrp/dboard_eeprom.hpp
@@ -32,20 +32,25 @@ struct UHD_API dboard_eeprom_t{
dboard_id_t id;
/*!
- * Create a dboard eeprom struct from the bytes read out of eeprom
- * \param buf the vector of bytes
+ * 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
*/
- dboard_eeprom_t(const uhd::byte_vector_t &buf = uhd::byte_vector_t(0));
+ dboard_eeprom_t(const uhd::byte_vector_t &bytes = uhd::byte_vector_t(0));
/*!
- * Get the bytes that would be written to dboard eeprom
+ * Get the bytes that would be written to dboard eeprom.
* \return a vector of bytes
*/
uhd::byte_vector_t get_eeprom_bytes(void);
/*!
- * Get the number of bytes to read out of eeprom.
- * \return the number of bytes we are interested in
+ * 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
*/
static size_t num_bytes(void);
};
diff --git a/host/include/uhd/usrp/dboard_iface.hpp b/host/include/uhd/usrp/dboard_iface.hpp
index 79b8ee664..1214a1a2f 100644
--- a/host/include/uhd/usrp/dboard_iface.hpp
+++ b/host/include/uhd/usrp/dboard_iface.hpp
@@ -95,19 +95,19 @@ public:
/*!
* Write to an I2C peripheral.
*
- * \param i2c_addr I2C bus address (7-bits)
- * \param buf the data to write
+ * \param addr I2C bus address (7-bits)
+ * \param bytes the data to write
*/
- virtual void write_i2c(int i2c_addr, const byte_vector_t &buf) = 0;
+ virtual void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes) = 0;
/*!
* Read from an I2C peripheral.
*
- * \param i2c_addr I2C bus address (7-bits)
+ * \param addr I2C bus address (7-bits)
* \param num_bytes number of bytes to read
* \return the data read if successful, else a zero length string.
*/
- virtual byte_vector_t read_i2c(int i2c_addr, size_t num_bytes) = 0;
+ virtual byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes) = 0;
/*!
* Write data to SPI bus peripheral.
diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp
index 6de64b02d..007d85bb4 100644
--- a/host/include/uhd/usrp/dboard_manager.hpp
+++ b/host/include/uhd/usrp/dboard_manager.hpp
@@ -33,7 +33,6 @@ namespace uhd{ namespace usrp{
* Provide wax::obj access to the subdevs inside.
*/
class UHD_API dboard_manager : boost::noncopyable{
-
public:
typedef boost::shared_ptr<dboard_manager> sptr;
diff --git a/host/include/uhd/usrp/dboard_props.hpp b/host/include/uhd/usrp/dboard_props.hpp
index 3b290319f..0208a6c2c 100644
--- a/host/include/uhd/usrp/dboard_props.hpp
+++ b/host/include/uhd/usrp/dboard_props.hpp
@@ -29,7 +29,8 @@ namespace uhd{ namespace usrp{
DBOARD_PROP_NAME = 'n', //ro, std::string
DBOARD_PROP_SUBDEV = 's', //ro, wax::obj
DBOARD_PROP_SUBDEV_NAMES = 'S', //ro, prop_names_t
- DBOARD_PROP_USED_SUBDEVS = 'u' //ro, prop_names_t
+ DBOARD_PROP_USED_SUBDEVS = 'u', //ro, prop_names_t
+ DBOARD_PROP_DBOARD_ID = 'i' //rw, dboard_id_t
//DBOARD_PROP_CODEC //ro, wax::obj //----> not sure, dont have to deal with yet
};
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);