aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp2
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/usrp/usrp2')
-rw-r--r--host/lib/usrp/usrp2/dboard_iface.cpp44
-rw-r--r--host/lib/usrp/usrp2/dboard_impl.cpp52
-rw-r--r--host/lib/usrp/usrp2/dsp_impl.cpp10
-rw-r--r--host/lib/usrp/usrp2/fw_common.h17
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp8
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.cpp44
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.hpp11
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp3
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp3
9 files changed, 106 insertions, 86 deletions
diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp
index e9acddee6..9503c329b 100644
--- a/host/lib/usrp/usrp2/dboard_iface.cpp
+++ b/host/lib/usrp/usrp2/dboard_iface.cpp
@@ -24,7 +24,6 @@
#include <boost/assign/list_of.hpp>
#include <boost/asio.hpp> //htonl and ntohl
#include <boost/math/special_functions/round.hpp>
-#include <algorithm>
#include "ad7922_regs.hpp" //aux adc
#include "ad5624_regs.hpp" //aux dac
@@ -43,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);
@@ -213,43 +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){
- //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
- std::copy(buf.begin(), buf.end(), out_data.data.i2c_args.data);
-
- //send and recv
- usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data);
- ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE);
+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){
- //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 = _iface->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(num_bytes);
- std::copy(in_data.data.i2c_args.data, in_data.data.i2c_args.data + num_bytes, result.begin());
- return result;
+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 ee23dc83a..a68ae240e 100644
--- a/host/lib/usrp/usrp2/dboard_impl.cpp
+++ b/host/lib/usrp/usrp2/dboard_impl.cpp
@@ -33,22 +33,16 @@ using namespace uhd::usrp;
* Helper Methods
**********************************************************************/
void usrp2_impl::dboard_init(void){
- //grab the dboard ids over the control line
- usrp2_ctrl_data_t out_data;
- out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO);
- usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data);
- ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE);
-
- //extract the dboard ids an convert them
- dboard_id_t rx_dboard_id = ntohs(in_data.data.dboard_ids.rx_id);
- dboard_id_t tx_dboard_id = ntohs(in_data.data.dboard_ids.tx_id);
+ //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(
- rx_dboard_id, tx_dboard_id, _dboard_iface
+ _rx_db_eeprom.id, _tx_db_eeprom.id, _dboard_iface
);
//load dboards
@@ -125,19 +119,28 @@ void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){
val = _rx_subdevs_in_use;
return;
- //case DBOARD_PROP_CODEC:
- // throw std::runtime_error("unhandled prop in usrp2 dboard");
+ case DBOARD_PROP_DBOARD_ID:
+ val = _rx_db_eeprom.id;
+ return;
+
+ default: UHD_THROW_PROP_WRITE_ONLY();
}
}
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, _rx_db_eeprom.get_eeprom_bytes());
+ return;
+
+ default: UHD_THROW_PROP_READ_ONLY();
+ }
}
/***********************************************************************
@@ -165,17 +168,26 @@ void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){
val = _tx_subdevs_in_use;
return;
- //case DBOARD_PROP_CODEC:
- // throw std::runtime_error("unhandled prop in usrp2 dboard");
+ case DBOARD_PROP_DBOARD_ID:
+ val = _tx_db_eeprom.id;
+ return;
+
+ default: UHD_THROW_PROP_WRITE_ONLY();
}
}
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: UHD_THROW_PROP_READ_ONLY();
+ }
}
diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp
index 204277ba7..379276f7d 100644
--- a/host/lib/usrp/usrp2/dsp_impl.cpp
+++ b/host/lib/usrp/usrp2/dsp_impl.cpp
@@ -117,6 +117,8 @@ void usrp2_impl::ddc_get(const wax::obj &key, wax::obj &val){
case DSP_PROP_HOST_RATE:
val = get_master_clock_freq()/_ddc_decim;
return;
+
+ default: UHD_THROW_PROP_WRITE_ONLY();
}
}
@@ -139,8 +141,7 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){
}
return;
- default:
- throw std::runtime_error("Error: trying to set read-only property on usrp2 ddc0");
+ default: UHD_THROW_PROP_READ_ONLY();
}
}
@@ -200,6 +201,8 @@ void usrp2_impl::duc_get(const wax::obj &key, wax::obj &val){
case DSP_PROP_HOST_RATE:
val = get_master_clock_freq()/_duc_interp;
return;
+
+ default: UHD_THROW_PROP_WRITE_ONLY();
}
}
@@ -222,7 +225,6 @@ void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){
}
return;
- default:
- throw std::runtime_error("Error: trying to set read-only property on usrp2 duc0");
+ default: UHD_THROW_PROP_READ_ONLY();
}
}
diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h
index 640b37ec6..e80001ff2 100644
--- a/host/lib/usrp/usrp2/fw_common.h
+++ b/host/lib/usrp/usrp2/fw_common.h
@@ -34,7 +34,7 @@ extern "C" {
//defines the protocol version in this shared header
//increment this value when the protocol is changed
-#define USRP2_PROTO_VERSION 1
+#define USRP2_PROTO_VERSION 2
//used to differentiate control packets over data port
#define USRP2_INVALID_VRT_HEADER 0
@@ -61,9 +61,6 @@ typedef enum{
USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE = 'M',
USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO = 'n',
- USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO = 'd',
- USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE = 'D',
-
USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO = 's',
USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE = 'S',
@@ -82,9 +79,6 @@ typedef enum{
USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO = 'r',
USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE = 'R',
- USRP2_CTRL_ID_WHATS_THE_HARDWARE_REV_NOS_BRO = 'y',
- USRP2_CTRL_ID_TAKE_THE_HARDWARE_REV_NOS_DUDE = 'Y',
-
USRP2_CTRL_ID_PEACE_OUT = '~'
} usrp2_ctrl_id_t;
@@ -107,10 +101,6 @@ typedef struct{
_SINS_ uint32_t ip_addr;
_SINS_ uint8_t mac_addr[6];
struct {
- _SINS_ uint16_t rx_id;
- _SINS_ uint16_t tx_id;
- } dboard_ids;
- struct {
_SINS_ uint8_t dev;
_SINS_ uint8_t miso_edge;
_SINS_ uint8_t mosi_edge;
@@ -137,11 +127,6 @@ typedef struct{
_SINS_ uint32_t data;
_SINS_ uint8_t num_bytes; //1, 2, 4
} poke_args;
- struct {
- _SINS_ uint8_t major;
- _SINS_ uint8_t minor;
- _SINS_ uint8_t _pad[2];
- } hw_rev;
} data;
} usrp2_ctrl_data_t;
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index f94806c9f..2c185ec53 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -248,9 +248,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){
val = _clock_config;
return;
- default:
- throw std::runtime_error("Error: trying to get write-only property on usrp2 mboard");
-
+ default: UHD_THROW_PROP_WRITE_ONLY();
}
}
@@ -306,8 +304,6 @@ void usrp2_impl::mboard_set(const wax::obj &key, const wax::obj &val){
issue_ddc_stream_cmd(val.as<stream_cmd_t>());
return;
- default:
- throw std::runtime_error("Error: trying to set read-only property on usrp2 mboard");
-
+ default: UHD_THROW_PROP_READ_ONLY();
}
}
diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp
index 1b0dde1b4..27b6f8907 100644
--- a/host/lib/usrp/usrp2/usrp2_iface.cpp
+++ b/host/lib/usrp/usrp2/usrp2_iface.cpp
@@ -19,9 +19,11 @@
#include <uhd/utils/assert.hpp>
#include <uhd/types/dict.hpp>
#include <boost/thread.hpp>
+#include <boost/foreach.hpp>
#include <boost/asio.hpp> //used for htonl and ntohl
#include <boost/assign/list_of.hpp>
#include <stdexcept>
+#include <algorithm>
using namespace uhd;
@@ -90,6 +92,48 @@ public:
}
/***********************************************************************
+ * I2C
+ **********************************************************************/
+ void write_i2c(boost::uint8_t 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 = 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
+ std::copy(buf.begin(), buf.end(), out_data.data.i2c_args.data);
+
+ //send and recv
+ usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data);
+ ASSERT_THROW(htonl(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){
+ //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 = 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 = this->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(num_bytes);
+ std::copy(in_data.data.i2c_args.data, in_data.data.i2c_args.data + num_bytes, result.begin());
+ return result;
+ }
+
+/***********************************************************************
* Send/Recv over control
**********************************************************************/
usrp2_ctrl_data_t ctrl_send_and_recv(const usrp2_ctrl_data_t &out_data){
diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp
index 6667c8998..7158c58d0 100644
--- a/host/lib/usrp/usrp2/usrp2_iface.hpp
+++ b/host/lib/usrp/usrp2/usrp2_iface.hpp
@@ -25,12 +25,21 @@
#include <boost/cstdint.hpp>
#include "fw_common.h"
+////////////////////////////////////////////////////////////////////////
+// I2C addresses
+////////////////////////////////////////////////////////////////////////
+#define I2C_DEV_EEPROM 0x50 // 24LC02[45]: 7-bits 1010xxx
+#define I2C_ADDR_MBOARD (I2C_DEV_EEPROM | 0x0)
+#define I2C_ADDR_TX_DB (I2C_DEV_EEPROM | 0x4)
+#define I2C_ADDR_RX_DB (I2C_DEV_EEPROM | 0x5)
+////////////////////////////////////////////////////////////////////////
+
/*!
* The usrp2 interface class:
* Provides a set of functions to implementation layer.
* Including spi, peek, poke, control...
*/
-class usrp2_iface : boost::noncopyable{
+class usrp2_iface : public uhd::i2c_iface, boost::noncopyable{
public:
typedef boost::shared_ptr<usrp2_iface> sptr;
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index 0fa56c339..11ad812e1 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -202,9 +202,10 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){
val = size_t(_max_tx_samples_per_packet);
return;
+ default: UHD_THROW_PROP_WRITE_ONLY();
}
}
void usrp2_impl::set(const wax::obj &, const wax::obj &){
- throw std::runtime_error("Cannot set in usrp2 device");
+ UHD_THROW_PROP_READ_ONLY();
}
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);