summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-02-17 17:33:26 -0800
committerJosh Blum <josh@joshknows.com>2010-02-17 17:33:26 -0800
commitb9497ba5b8ff66856e13100160275ddc4a884db0 (patch)
tree03790382c28bdff95671f4a3550be3d05521fdb5
parent4fb4572e1a16f54439f57655f90e0fc937c57c1e (diff)
downloaduhd-b9497ba5b8ff66856e13100160275ddc4a884db0.tar.gz
uhd-b9497ba5b8ff66856e13100160275ddc4a884db0.tar.bz2
uhd-b9497ba5b8ff66856e13100160275ddc4a884db0.zip
Added i2c control transactions in fw and host
-rw-r--r--firmware/microblaze/apps/txrx.c28
-rw-r--r--host/include/uhd/usrp/dboard/interface.hpp4
-rw-r--r--host/lib/usrp/mboard/usrp2/dboard_interface.cpp58
-rw-r--r--host/lib/usrp/mboard/usrp2/dboard_interface.hpp4
-rw-r--r--host/lib/usrp/mboard/usrp2/fw_common.h11
5 files changed, 96 insertions, 9 deletions
diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c
index fde7529ac..2cf3c46ed 100644
--- a/firmware/microblaze/apps/txrx.c
+++ b/firmware/microblaze/apps/txrx.c
@@ -44,6 +44,7 @@
#include <vrt/bits.h>
#include "usrp2/fw_common.h"
#include <db.h>
+#include <i2c.h>
#define FW_SETS_SEQNO 1 // define to 0 or 1 (FIXME must be 1 for now)
@@ -319,6 +320,33 @@ void handle_udp_ctrl_packet(
}
break;
+ /*******************************************************************
+ * I2C
+ ******************************************************************/
+ case USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO:{
+ uint8_t num_bytes = ctrl_data_in->data.i2c_args.bytes;
+ i2c_read(
+ ctrl_data_in->data.i2c_args.addr,
+ ctrl_data_out.data.i2c_args.data,
+ num_bytes
+ );
+ ctrl_data_out.id = USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE;
+ ctrl_data_out.data.i2c_args.bytes = num_bytes;
+ }
+ break;
+
+ case USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO:{
+ uint8_t num_bytes = ctrl_data_in->data.i2c_args.bytes;
+ i2c_write(
+ ctrl_data_in->data.i2c_args.addr,
+ ctrl_data_in->data.i2c_args.data,
+ num_bytes
+ );
+ ctrl_data_out.id = USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE;
+ ctrl_data_out.data.i2c_args.bytes = num_bytes;
+ }
+ break;
+
default:
ctrl_data_out.id = USRP2_CTRL_ID_HUH_WHAT;
diff --git a/host/include/uhd/usrp/dboard/interface.hpp b/host/include/uhd/usrp/dboard/interface.hpp
index e066f2061..495304338 100644
--- a/host/include/uhd/usrp/dboard/interface.hpp
+++ b/host/include/uhd/usrp/dboard/interface.hpp
@@ -126,10 +126,10 @@ public:
/*!
* \brief Read from I2C peripheral
* \param i2c_addr I2C bus address (7-bits)
- * \param len number of bytes to read
+ * \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 len) = 0;
+ virtual byte_vector_t read_i2c(int i2c_addr, size_t num_bytes) = 0;
/*!
* \brief Write data to SPI bus peripheral.
diff --git a/host/lib/usrp/mboard/usrp2/dboard_interface.cpp b/host/lib/usrp/mboard/usrp2/dboard_interface.cpp
index d244e0bee..fd51558f2 100644
--- a/host/lib/usrp/mboard/usrp2/dboard_interface.cpp
+++ b/host/lib/usrp/mboard/usrp2/dboard_interface.cpp
@@ -19,6 +19,8 @@
#include "dboard_interface.hpp"
#include "fw_common.h"
+using namespace uhd::usrp::dboard;
+
/***********************************************************************
* Structors
**********************************************************************/
@@ -50,7 +52,7 @@ double dboard_interface::get_tx_clock_rate(void){
* \param bank the dboard interface gpio bank enum
* \return an over the wire representation
*/
-static uint8_t gpio_bank_to_otw(uhd::usrp::dboard::interface::gpio_bank_t bank){
+static uint8_t gpio_bank_to_otw(interface::gpio_bank_t bank){
switch(bank){
case uhd::usrp::dboard::interface::GPIO_TX_BANK: return USRP2_DIR_TX;
case uhd::usrp::dboard::interface::GPIO_RX_BANK: return USRP2_DIR_RX;
@@ -119,7 +121,7 @@ void dboard_interface::set_atr_reg(gpio_bank_t bank, uint16_t tx_value, uint16_t
* \param dev the dboard interface spi dev enum
* \return an over the wire representation
*/
-static uint8_t spi_dev_to_otw(uhd::usrp::dboard::interface::spi_dev_t dev){
+static uint8_t spi_dev_to_otw(interface::spi_dev_t dev){
switch(dev){
case uhd::usrp::dboard::interface::SPI_TX_DEV: return USRP2_DIR_TX;
case uhd::usrp::dboard::interface::SPI_RX_DEV: return USRP2_DIR_RX;
@@ -133,7 +135,7 @@ static uint8_t spi_dev_to_otw(uhd::usrp::dboard::interface::spi_dev_t dev){
* \param latch the dboard interface spi latch enum
* \return an over the wire representation
*/
-static uint8_t spi_latch_to_otw(uhd::usrp::dboard::interface::spi_latch_t latch){
+static uint8_t spi_latch_to_otw(interface::spi_latch_t latch){
switch(latch){
case uhd::usrp::dboard::interface::SPI_LATCH_RISE: return USRP2_CLK_EDGE_RISE;
case uhd::usrp::dboard::interface::SPI_LATCH_FALL: return USRP2_CLK_EDGE_FALL;
@@ -147,7 +149,7 @@ static uint8_t spi_latch_to_otw(uhd::usrp::dboard::interface::spi_latch_t latch)
* \param push the dboard interface spi push enum
* \return an over the wire representation
*/
-static uint8_t spi_push_to_otw(uhd::usrp::dboard::interface::spi_push_t push){
+static uint8_t spi_push_to_otw(interface::spi_push_t push){
switch(push){
case uhd::usrp::dboard::interface::SPI_PUSH_RISE: return USRP2_CLK_EDGE_RISE;
case uhd::usrp::dboard::interface::SPI_PUSH_FALL: return USRP2_CLK_EDGE_FALL;
@@ -155,7 +157,7 @@ static uint8_t spi_push_to_otw(uhd::usrp::dboard::interface::spi_push_t push){
throw std::invalid_argument("unknown spi push type");
}
-uhd::usrp::dboard::interface::byte_vector_t dboard_interface::transact_spi(
+interface::byte_vector_t dboard_interface::transact_spi(
spi_dev_t dev,
spi_latch_t latch,
spi_push_t push,
@@ -191,3 +193,49 @@ uhd::usrp::dboard::interface::byte_vector_t dboard_interface::transact_spi(
}
return result;
}
+
+/***********************************************************************
+ * I2C
+ **********************************************************************/
+void dboard_interface::write_i2c(int i2c_addr, const byte_vector_t &buf){
+ //setup the out data
+ usrp2_ctrl_data_t out_data;
+ out_data.id = htonl(USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO);
+ out_data.data.i2c_args.addr = i2c_addr;
+ out_data.data.i2c_args.bytes = buf.size();
+
+ //limitation of i2c transaction size
+ ASSERT_THROW(buf.size() <= sizeof(out_data.data.i2c_args.data));
+
+ //copy in the data
+ for (size_t i = 0; i < buf.size(); i++){
+ out_data.data.i2c_args.data[i] = buf[i];
+ }
+
+ //send and recv
+ usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data);
+ ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE);
+}
+
+interface::byte_vector_t dboard_interface::read_i2c(int i2c_addr, size_t num_bytes){
+ //setup the out data
+ usrp2_ctrl_data_t out_data;
+ out_data.id = htonl(USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO);
+ out_data.data.i2c_args.addr = i2c_addr;
+ out_data.data.i2c_args.bytes = num_bytes;
+
+ //limitation of i2c transaction size
+ ASSERT_THROW(num_bytes <= sizeof(out_data.data.i2c_args.data));
+
+ //send and recv
+ usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data);
+ ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE);
+ ASSERT_THROW(in_data.data.i2c_args.addr = num_bytes);
+
+ //copy out the data
+ byte_vector_t result;
+ for (size_t i = 0; i < num_bytes; i++){
+ result.push_back(in_data.data.i2c_args.data[i]);
+ }
+ return result;
+}
diff --git a/host/lib/usrp/mboard/usrp2/dboard_interface.hpp b/host/lib/usrp/mboard/usrp2/dboard_interface.hpp
index 8880eaf97..fb197a87a 100644
--- a/host/lib/usrp/mboard/usrp2/dboard_interface.hpp
+++ b/host/lib/usrp/mboard/usrp2/dboard_interface.hpp
@@ -39,9 +39,9 @@ public:
uint16_t read_gpio(gpio_bank_t);
- void write_i2c(int, const byte_vector_t &){}
+ void write_i2c(int, const byte_vector_t &);
- byte_vector_t read_i2c(int, size_t){return byte_vector_t();}
+ byte_vector_t read_i2c(int, size_t);
double get_rx_clock_rate(void);
diff --git a/host/lib/usrp/mboard/usrp2/fw_common.h b/host/lib/usrp/mboard/usrp2/fw_common.h
index 8e5810a14..91cb88c53 100644
--- a/host/lib/usrp/mboard/usrp2/fw_common.h
+++ b/host/lib/usrp/mboard/usrp2/fw_common.h
@@ -66,6 +66,12 @@ typedef enum{
USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO,
USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE,
+ USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO,
+ USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE,
+
+ USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO,
+ USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE,
+
USRP2_CTRL_ID_PEACE_OUT
} usrp2_ctrl_id_t;
@@ -133,6 +139,11 @@ typedef struct{
uint8_t bytes;
uint8_t data[sizeof(uint32_t)];
} spi_args;
+ struct {
+ uint8_t addr;
+ uint8_t bytes;
+ uint8_t data[sizeof(uint32_t)];
+ } i2c_args;
} data;
} usrp2_ctrl_data_t;