aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2013-07-24 17:46:04 -0700
committerJosh Blum <josh@joshknows.com>2013-07-24 17:46:04 -0700
commit0aeac60394420de1952ebc230a6fa2f8593df80a (patch)
treef08d6ca1555dc2df15a79c3da6d32cad9a6224d7 /host/lib
parent690637f78685b2979a9f128ce3c82149b5421c46 (diff)
downloaduhd-0aeac60394420de1952ebc230a6fa2f8593df80a.tar.gz
uhd-0aeac60394420de1952ebc230a6fa2f8593df80a.tar.bz2
uhd-0aeac60394420de1952ebc230a6fa2f8593df80a.zip
uhd: allow for 16 bit i2c and eeprom addrs
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/types/serial.cpp61
-rw-r--r--host/lib/usrp/b100/dboard_iface.cpp8
-rw-r--r--host/lib/usrp/b200/b200_iface.cpp10
-rw-r--r--host/lib/usrp/common/fx2_ctrl.cpp8
-rw-r--r--host/lib/usrp/cores/i2c_core_100.cpp4
-rw-r--r--host/lib/usrp/cores/i2c_core_100_wb32.cpp12
-rw-r--r--host/lib/usrp/cores/i2c_core_200.cpp4
-rw-r--r--host/lib/usrp/e100/dboard_iface.cpp8
-rw-r--r--host/lib/usrp/e100/e100_ctrl.cpp4
-rw-r--r--host/lib/usrp/usrp1/dboard_iface.cpp8
-rw-r--r--host/lib/usrp/usrp1/usrp1_iface.cpp4
-rw-r--r--host/lib/usrp/usrp2/dboard_iface.cpp8
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.cpp4
13 files changed, 102 insertions, 41 deletions
diff --git a/host/lib/types/serial.cpp b/host/lib/types/serial.cpp
index 562261bb7..9b8336dd8 100644
--- a/host/lib/types/serial.cpp
+++ b/host/lib/types/serial.cpp
@@ -44,8 +44,8 @@ spi_config_t::spi_config_t(edge_t edge):
}
void i2c_iface::write_eeprom(
- boost::uint8_t addr,
- boost::uint8_t offset,
+ boost::uint16_t addr,
+ boost::uint16_t offset,
const byte_vector_t &bytes
){
for (size_t i = 0; i < bytes.size(); i++){
@@ -57,8 +57,8 @@ void i2c_iface::write_eeprom(
}
byte_vector_t i2c_iface::read_eeprom(
- boost::uint8_t addr,
- boost::uint8_t offset,
+ boost::uint16_t addr,
+ boost::uint16_t offset,
size_t num_bytes
){
byte_vector_t bytes;
@@ -70,6 +70,59 @@ byte_vector_t i2c_iface::read_eeprom(
return bytes;
}
+struct eeprom16_impl : i2c_iface
+{
+ eeprom16_impl(i2c_iface* internal)
+ {
+ _internal = internal;
+ }
+ i2c_iface* _internal;
+
+ byte_vector_t read_i2c(
+ boost::uint16_t addr,
+ size_t num_bytes
+ ){
+ return _internal->read_i2c(addr, num_bytes);
+ }
+
+ void write_i2c(
+ boost::uint16_t addr,
+ const byte_vector_t &bytes
+ ){
+ return _internal->write_i2c(addr, bytes);
+ }
+
+ byte_vector_t read_eeprom(
+ boost::uint16_t addr,
+ boost::uint16_t offset,
+ size_t num_bytes
+ ){
+ byte_vector_t cmd = boost::assign::list_of(offset >> 8)(offset & 0xff);
+ this->write_i2c(addr, cmd);
+ return this->read_i2c(addr, num_bytes);
+ }
+
+ void write_eeprom(
+ boost::uint16_t addr,
+ boost::uint16_t offset,
+ const byte_vector_t &bytes
+ ){
+ for (size_t i = 0; i < bytes.size(); i++)
+ {
+ //write a byte at a time, its easy that way
+ boost::uint16_t offset_i = offset+i;
+ byte_vector_t cmd = boost::assign::list_of(offset_i >> 8)(offset_i & 0xff)(bytes[i]);
+ this->write_i2c(addr, cmd);
+ boost::this_thread::sleep(boost::posix_time::milliseconds(10)); //worst case write
+ }
+ }
+};
+
+i2c_iface::sptr i2c_iface::eeprom16(void)
+{
+ return i2c_iface::sptr(new eeprom16_impl(this));
+}
+
boost::uint32_t spi_iface::read_spi(
int which_slave,
const spi_config_t &config,
diff --git a/host/lib/usrp/b100/dboard_iface.cpp b/host/lib/usrp/b100/dboard_iface.cpp
index 25604da72..efbba1c4c 100644
--- a/host/lib/usrp/b100/dboard_iface.cpp
+++ b/host/lib/usrp/b100/dboard_iface.cpp
@@ -73,8 +73,8 @@ public:
void set_gpio_debug(unit_t, int);
boost::uint16_t read_gpio(unit_t);
- void write_i2c(boost::uint8_t, const byte_vector_t &);
- byte_vector_t read_i2c(boost::uint8_t, size_t);
+ void write_i2c(boost::uint16_t, const byte_vector_t &);
+ byte_vector_t read_i2c(boost::uint16_t, size_t);
void write_spi(
unit_t unit,
@@ -219,11 +219,11 @@ boost::uint32_t b100_dboard_iface::read_write_spi(
/***********************************************************************
* I2C
**********************************************************************/
-void b100_dboard_iface::write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){
+void b100_dboard_iface::write_i2c(boost::uint16_t addr, const byte_vector_t &bytes){
return _i2c_iface->write_i2c(addr, bytes);
}
-byte_vector_t b100_dboard_iface::read_i2c(boost::uint8_t addr, size_t num_bytes){
+byte_vector_t b100_dboard_iface::read_i2c(boost::uint16_t addr, size_t num_bytes){
return _i2c_iface->read_i2c(addr, num_bytes);
}
diff --git a/host/lib/usrp/b200/b200_iface.cpp b/host/lib/usrp/b200/b200_iface.cpp
index 5173beacb..933df8499 100644
--- a/host/lib/usrp/b200/b200_iface.cpp
+++ b/host/lib/usrp/b200/b200_iface.cpp
@@ -211,18 +211,18 @@ public:
}
- void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes)
+ void write_i2c(boost::uint16_t addr, const byte_vector_t &bytes)
{
throw uhd::not_implemented_error("b200 write i2c");
}
- byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes)
+ byte_vector_t read_i2c(boost::uint16_t addr, size_t num_bytes)
{
throw uhd::not_implemented_error("b200 read i2c");
}
- void write_eeprom(boost::uint8_t addr, boost::uint8_t offset,
+ void write_eeprom(boost::uint16_t addr, boost::uint16_t offset,
const byte_vector_t &bytes)
{
fx3_control_write(B200_VREQ_EEPROM_WRITE,
@@ -232,8 +232,8 @@ public:
}
byte_vector_t read_eeprom(
- boost::uint8_t addr,
- boost::uint8_t offset,
+ boost::uint16_t addr,
+ boost::uint16_t offset,
size_t num_bytes
){
byte_vector_t recv_bytes(num_bytes);
diff --git a/host/lib/usrp/common/fx2_ctrl.cpp b/host/lib/usrp/common/fx2_ctrl.cpp
index 1f9cb84b3..6111efea9 100644
--- a/host/lib/usrp/common/fx2_ctrl.cpp
+++ b/host/lib/usrp/common/fx2_ctrl.cpp
@@ -411,8 +411,8 @@ public:
}
byte_vector_t read_eeprom(
- boost::uint8_t addr,
- boost::uint8_t offset,
+ boost::uint16_t addr,
+ boost::uint16_t offset,
size_t num_bytes
){
this->write_i2c(addr, byte_vector_t(1, offset));
@@ -432,7 +432,7 @@ public:
static const bool iface_debug = false;
static const size_t max_i2c_data_bytes = 64;
- void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes)
+ void write_i2c(boost::uint16_t addr, const byte_vector_t &bytes)
{
UHD_ASSERT_THROW(bytes.size() < max_i2c_data_bytes);
@@ -442,7 +442,7 @@ public:
uhd::runtime_error("USRP: failed i2c write");
}
- byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes)
+ byte_vector_t read_i2c(boost::uint16_t addr, size_t num_bytes)
{
UHD_ASSERT_THROW(num_bytes < max_i2c_data_bytes);
diff --git a/host/lib/usrp/cores/i2c_core_100.cpp b/host/lib/usrp/cores/i2c_core_100.cpp
index ceeb3f518..9e8a226f2 100644
--- a/host/lib/usrp/cores/i2c_core_100.cpp
+++ b/host/lib/usrp/cores/i2c_core_100.cpp
@@ -70,7 +70,7 @@ public:
}
void write_i2c(
- boost::uint8_t addr,
+ boost::uint16_t addr,
const byte_vector_t &bytes
){
_iface->poke16(REG_I2C_DATA, (addr << 1) | 0); //addr and read bit (0)
@@ -93,7 +93,7 @@ public:
}
byte_vector_t read_i2c(
- boost::uint8_t addr,
+ boost::uint16_t addr,
size_t num_bytes
){
byte_vector_t bytes;
diff --git a/host/lib/usrp/cores/i2c_core_100_wb32.cpp b/host/lib/usrp/cores/i2c_core_100_wb32.cpp
index b38d5b4bc..df6e6ff72 100644
--- a/host/lib/usrp/cores/i2c_core_100_wb32.cpp
+++ b/host/lib/usrp/cores/i2c_core_100_wb32.cpp
@@ -72,7 +72,7 @@ public:
}
void write_i2c(
- boost::uint8_t addr,
+ boost::uint16_t addr,
const byte_vector_t &bytes
){
_iface->poke32(REG_I2C_DATA, (addr << 1) | 0); //addr and read bit (0)
@@ -95,7 +95,7 @@ public:
}
byte_vector_t read_i2c(
- boost::uint8_t addr,
+ boost::uint16_t addr,
size_t num_bytes
){
byte_vector_t bytes;
@@ -119,6 +119,14 @@ public:
return bytes;
}
+ //override read_eeprom so we can write once, read all N bytes
+ //the default implementation calls read i2c once per byte
+ byte_vector_t read_eeprom(boost::uint16_t addr, boost::uint16_t offset, size_t num_bytes)
+ {
+ this->write_i2c(addr, byte_vector_t(1, offset));
+ return this->read_i2c(addr, num_bytes);
+ }
+
private:
void i2c_wait(void) {
for (size_t i = 0; i < 10; i++)
diff --git a/host/lib/usrp/cores/i2c_core_200.cpp b/host/lib/usrp/cores/i2c_core_200.cpp
index 1b882c54a..6010ac5a2 100644
--- a/host/lib/usrp/cores/i2c_core_200.cpp
+++ b/host/lib/usrp/cores/i2c_core_200.cpp
@@ -73,7 +73,7 @@ public:
}
void write_i2c(
- boost::uint8_t addr,
+ boost::uint16_t addr,
const byte_vector_t &bytes
){
this->poke(REG_I2C_WR_DATA, (addr << 1) | 0); //addr and read bit (0)
@@ -96,7 +96,7 @@ public:
}
byte_vector_t read_i2c(
- boost::uint8_t addr,
+ boost::uint16_t addr,
size_t num_bytes
){
byte_vector_t bytes;
diff --git a/host/lib/usrp/e100/dboard_iface.cpp b/host/lib/usrp/e100/dboard_iface.cpp
index 532b2dc9e..07d0049c8 100644
--- a/host/lib/usrp/e100/dboard_iface.cpp
+++ b/host/lib/usrp/e100/dboard_iface.cpp
@@ -73,8 +73,8 @@ public:
void set_gpio_debug(unit_t, int);
boost::uint16_t read_gpio(unit_t);
- void write_i2c(boost::uint8_t, const byte_vector_t &);
- byte_vector_t read_i2c(boost::uint8_t, size_t);
+ void write_i2c(boost::uint16_t, const byte_vector_t &);
+ byte_vector_t read_i2c(boost::uint16_t, size_t);
void write_spi(
unit_t unit,
@@ -219,11 +219,11 @@ boost::uint32_t e100_dboard_iface::read_write_spi(
/***********************************************************************
* I2C
**********************************************************************/
-void e100_dboard_iface::write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){
+void e100_dboard_iface::write_i2c(boost::uint16_t addr, const byte_vector_t &bytes){
return _i2c_iface->write_i2c(addr, bytes);
}
-byte_vector_t e100_dboard_iface::read_i2c(boost::uint8_t addr, size_t num_bytes){
+byte_vector_t e100_dboard_iface::read_i2c(boost::uint16_t addr, size_t num_bytes){
return _i2c_iface->read_i2c(addr, num_bytes);
}
diff --git a/host/lib/usrp/e100/e100_ctrl.cpp b/host/lib/usrp/e100/e100_ctrl.cpp
index c9c86c8af..cdbbff6dd 100644
--- a/host/lib/usrp/e100/e100_ctrl.cpp
+++ b/host/lib/usrp/e100/e100_ctrl.cpp
@@ -144,7 +144,7 @@ public:
::close(_node_fd);
}
- void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){
+ void write_i2c(boost::uint16_t addr, const byte_vector_t &bytes){
byte_vector_t rw_bytes(bytes);
//setup the message
@@ -163,7 +163,7 @@ public:
UHD_ASSERT_THROW(::ioctl(_node_fd, I2C_RDWR, &data) >= 0);
}
- byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes){
+ byte_vector_t read_i2c(boost::uint16_t addr, size_t num_bytes){
byte_vector_t bytes(num_bytes);
//setup the message
diff --git a/host/lib/usrp/usrp1/dboard_iface.cpp b/host/lib/usrp/usrp1/dboard_iface.cpp
index 39850d5d1..4c3141d9e 100644
--- a/host/lib/usrp/usrp1/dboard_iface.cpp
+++ b/host/lib/usrp/usrp1/dboard_iface.cpp
@@ -113,8 +113,8 @@ public:
void set_gpio_debug(unit_t, int);
boost::uint16_t read_gpio(unit_t);
- void write_i2c(boost::uint8_t, const byte_vector_t &);
- byte_vector_t read_i2c(boost::uint8_t, size_t);
+ void write_i2c(boost::uint16_t, const byte_vector_t &);
+ byte_vector_t read_i2c(boost::uint16_t, size_t);
void write_spi(unit_t unit,
const spi_config_t &config,
@@ -386,13 +386,13 @@ boost::uint32_t usrp1_dboard_iface::read_write_spi(unit_t unit,
/***********************************************************************
* I2C
**********************************************************************/
-void usrp1_dboard_iface::write_i2c(boost::uint8_t addr,
+void usrp1_dboard_iface::write_i2c(boost::uint16_t addr,
const byte_vector_t &bytes)
{
return _iface->write_i2c(addr, bytes);
}
-byte_vector_t usrp1_dboard_iface::read_i2c(boost::uint8_t addr,
+byte_vector_t usrp1_dboard_iface::read_i2c(boost::uint16_t addr,
size_t num_bytes)
{
return _iface->read_i2c(addr, num_bytes);
diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp
index 16b747e45..9301721aa 100644
--- a/host/lib/usrp/usrp1/usrp1_iface.cpp
+++ b/host/lib/usrp/usrp1/usrp1_iface.cpp
@@ -104,11 +104,11 @@ public:
/*******************************************************************
* I2C
******************************************************************/
- void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){
+ void write_i2c(boost::uint16_t addr, const byte_vector_t &bytes){
return _ctrl_transport->write_i2c(addr, bytes);
}
- byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes){
+ byte_vector_t read_i2c(boost::uint16_t addr, size_t num_bytes){
return _ctrl_transport->read_i2c(addr, num_bytes);
}
diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp
index edd9ef242..8f2d0f0dc 100644
--- a/host/lib/usrp/usrp2/dboard_iface.cpp
+++ b/host/lib/usrp/usrp2/dboard_iface.cpp
@@ -60,8 +60,8 @@ public:
void set_gpio_debug(unit_t, int);
boost::uint16_t read_gpio(unit_t);
- void write_i2c(boost::uint8_t, const byte_vector_t &);
- byte_vector_t read_i2c(boost::uint8_t, size_t);
+ void write_i2c(boost::uint16_t, const byte_vector_t &);
+ byte_vector_t read_i2c(boost::uint16_t, size_t);
void set_clock_rate(unit_t, double);
double get_clock_rate(unit_t);
@@ -229,11 +229,11 @@ boost::uint32_t usrp2_dboard_iface::read_write_spi(
/***********************************************************************
* I2C
**********************************************************************/
-void usrp2_dboard_iface::write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){
+void usrp2_dboard_iface::write_i2c(boost::uint16_t addr, const byte_vector_t &bytes){
return _i2c_iface->write_i2c(addr, bytes);
}
-byte_vector_t usrp2_dboard_iface::read_i2c(boost::uint8_t addr, size_t num_bytes){
+byte_vector_t usrp2_dboard_iface::read_i2c(boost::uint16_t addr, size_t num_bytes){
return _i2c_iface->read_i2c(addr, num_bytes);
}
diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp
index 8804433e7..3b230ca69 100644
--- a/host/lib/usrp/usrp2/usrp2_iface.cpp
+++ b/host/lib/usrp/usrp2/usrp2_iface.cpp
@@ -240,7 +240,7 @@ public:
/***********************************************************************
* I2C
**********************************************************************/
- void write_i2c(boost::uint8_t addr, const byte_vector_t &buf){
+ void write_i2c(boost::uint16_t addr, const byte_vector_t &buf){
//setup the out data
usrp2_ctrl_data_t out_data = usrp2_ctrl_data_t();
out_data.id = htonl(USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO);
@@ -258,7 +258,7 @@ public:
UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE);
}
- byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes){
+ byte_vector_t read_i2c(boost::uint16_t addr, size_t num_bytes){
//setup the out data
usrp2_ctrl_data_t out_data = usrp2_ctrl_data_t();
out_data.id = htonl(USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO);