From 38248b816c75bcf60eca69244d363cae2397ce47 Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Wed, 31 Mar 2010 17:43:20 -0700
Subject: Refactor ATR part of dboard interface (and some constants).

Added peek and poke to the dude/bro protocol.
Started moving more control code through peek and poke.
Added usrp_regs.hpp to be like memory map for slave perifs.
---
 host/lib/usrp/dboard/db_basic_and_lf.cpp |   4 +-
 host/lib/usrp/dboard_interface.cpp       |  13 ++-
 host/lib/usrp/dboard_manager.cpp         |  11 +--
 host/lib/usrp/usrp2/dboard_interface.cpp | 154 ++++++++++++-------------------
 host/lib/usrp/usrp2/fw_common.h          |  98 ++++++++------------
 host/lib/usrp/usrp2/usrp2_impl.cpp       |  24 +++++
 host/lib/usrp/usrp2/usrp2_impl.hpp       |   4 +
 host/lib/usrp/usrp2/usrp2_regs.hpp       |  57 ++++++++++++
 8 files changed, 199 insertions(+), 166 deletions(-)
 create mode 100644 host/lib/usrp/usrp2/usrp2_regs.hpp

(limited to 'host/lib')

diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp
index 50c868a24..977eb3d49 100644
--- a/host/lib/usrp/dboard/db_basic_and_lf.cpp
+++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp
@@ -88,7 +88,7 @@ UHD_STATIC_BLOCK(reg_dboards){
 basic_rx::basic_rx(ctor_args_t const& args, double max_freq) : rx_dboard_base(args){
     _max_freq = max_freq;
     // set the gpios to safe values (all inputs)
-    get_interface()->set_gpio_ddr(dboard_interface::GPIO_RX_BANK, 0x0000);
+    get_interface()->set_gpio_ddr(dboard_interface::GPIO_BANK_RX, 0x0000);
 }
 
 basic_rx::~basic_rx(void){
@@ -199,7 +199,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){
 basic_tx::basic_tx(ctor_args_t const& args, double max_freq) : tx_dboard_base(args){
     _max_freq = max_freq;
     // set the gpios to safe values (all inputs)
-    get_interface()->set_gpio_ddr(dboard_interface::GPIO_TX_BANK, 0x0000);
+    get_interface()->set_gpio_ddr(dboard_interface::GPIO_BANK_TX, 0x0000);
 }
 
 basic_tx::~basic_tx(void){
diff --git a/host/lib/usrp/dboard_interface.cpp b/host/lib/usrp/dboard_interface.cpp
index f6d6b6456..c40c9b398 100644
--- a/host/lib/usrp/dboard_interface.cpp
+++ b/host/lib/usrp/dboard_interface.cpp
@@ -29,26 +29,25 @@ dboard_interface::~dboard_interface(void){
 
 void dboard_interface::write_spi(
     spi_dev_t dev,
-    spi_push_t push,
+    spi_edge_t edge,
     const byte_vector_t &buf
 ){
-    transact_spi(dev, SPI_LATCH_RISE, push, buf, false); //dont readback
+    transact_spi(dev, edge, buf, false); //dont readback
 }
 
 dboard_interface::byte_vector_t dboard_interface::read_spi(
     spi_dev_t dev,
-    spi_latch_t latch,
+    spi_edge_t edge,
     size_t num_bytes
 ){
     byte_vector_t buf(num_bytes, 0x00); //dummy data
-    return transact_spi(dev, latch, SPI_PUSH_RISE, buf, true); //readback
+    return transact_spi(dev, edge, buf, true); //readback
 }
 
 dboard_interface::byte_vector_t dboard_interface::read_write_spi(
     spi_dev_t dev,
-    spi_latch_t latch,
-    spi_push_t push,
+    spi_edge_t edge,
     const byte_vector_t &buf
 ){
-    return transact_spi(dev, latch, push, buf, true); //readback
+    return transact_spi(dev, edge, buf, true); //readback
 }
diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp
index 15be7eedc..5c063d51d 100644
--- a/host/lib/usrp/dboard_manager.cpp
+++ b/host/lib/usrp/dboard_manager.cpp
@@ -275,12 +275,9 @@ wax::obj dboard_manager_impl::get_tx_subdev(const std::string &subdev_name){
 void dboard_manager_impl::set_nice_gpio_pins(void){
     //std::cout << "Set nice GPIO pins" << std::endl;
 
-    _interface->set_gpio_ddr(dboard_interface::GPIO_RX_BANK, 0x0000); //all inputs
-    _interface->set_gpio_ddr(dboard_interface::GPIO_TX_BANK, 0x0000);
+    _interface->set_gpio_ddr(dboard_interface::GPIO_BANK_RX, 0x0000); //all inputs
+    _interface->set_atr_reg(dboard_interface::GPIO_BANK_RX, dboard_interface::ATR_REG_IDLE, 0x0000); //all low
 
-    _interface->write_gpio(dboard_interface::GPIO_RX_BANK, 0x0000); //all zeros
-    _interface->write_gpio(dboard_interface::GPIO_TX_BANK, 0x0000);
-
-    _interface->set_atr_reg(dboard_interface::GPIO_RX_BANK, 0x0000, 0x0000, 0x0000); //software controlled
-    _interface->set_atr_reg(dboard_interface::GPIO_TX_BANK, 0x0000, 0x0000, 0x0000);
+    _interface->set_gpio_ddr(dboard_interface::GPIO_BANK_TX, 0x0000); //all inputs
+    _interface->set_atr_reg(dboard_interface::GPIO_BANK_TX, dboard_interface::ATR_REG_IDLE, 0x0000); //all low
 }
diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp
index 5a7d870b4..0bf4fa2e6 100644
--- a/host/lib/usrp/usrp2/dboard_interface.cpp
+++ b/host/lib/usrp/usrp2/dboard_interface.cpp
@@ -15,8 +15,12 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
-#include <uhd/utils/assert.hpp>
 #include "usrp2_impl.hpp"
+#include "usrp2_regs.hpp"
+#include <uhd/types/dict.hpp>
+#include <uhd/utils/assert.hpp>
+#include <boost/assign/list_of.hpp>
+#include <cstddef>
 
 using namespace uhd::usrp;
 
@@ -28,9 +32,8 @@ public:
     void write_aux_dac(unit_type_t, int, int);
     int read_aux_adc(unit_type_t, int);
 
-    void set_atr_reg(gpio_bank_t, boost::uint16_t, boost::uint16_t, boost::uint16_t);
+    void set_atr_reg(gpio_bank_t, atr_reg_t, boost::uint16_t);
     void set_gpio_ddr(gpio_bank_t, boost::uint16_t);
-    void write_gpio(gpio_bank_t, boost::uint16_t);
     boost::uint16_t read_gpio(gpio_bank_t);
 
     void write_i2c(int, const byte_vector_t &);
@@ -41,14 +44,21 @@ public:
 
 private:
     byte_vector_t transact_spi(
-        spi_dev_t dev,
-        spi_latch_t latch,
-        spi_push_t push,
-        const byte_vector_t &buf,
-        bool readback
+        spi_dev_t, spi_edge_t, const byte_vector_t &, bool
     );
 
     usrp2_impl *_impl;
+
+    //shadows
+    boost::uint32_t _ddr_shadow;
+    uhd::dict<atr_reg_t, uint32_t> _atr_reg_shadows;
+
+    //utilities
+    static int bank_to_shift(gpio_bank_t bank){
+        static const uhd::dict<gpio_bank_t, int> _bank_to_shift = \
+        boost::assign::map_list_of(GPIO_BANK_RX, 0)(GPIO_BANK_TX, 16);
+        return _bank_to_shift[bank];
+    }
 };
 
 /***********************************************************************
@@ -63,6 +73,7 @@ dboard_interface::sptr make_usrp2_dboard_interface(usrp2_impl *impl){
  **********************************************************************/
 usrp2_dboard_interface::usrp2_dboard_interface(usrp2_impl *impl){
     _impl = impl;
+    _ddr_shadow = 0;
 }
 
 usrp2_dboard_interface::~usrp2_dboard_interface(void){
@@ -83,70 +94,43 @@ double usrp2_dboard_interface::get_tx_clock_rate(void){
 /***********************************************************************
  * GPIO
  **********************************************************************/
-/*!
- * Static function to convert a gpio bank enum
- * to an over-the-wire value for the usrp2 control.
- * \param bank the dboard interface gpio bank enum
- * \return an over the wire representation
- */
-static boost::uint8_t gpio_bank_to_otw(dboard_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;
-    }
-    throw std::invalid_argument("unknown gpio bank type");
-}
-
 void usrp2_dboard_interface::set_gpio_ddr(gpio_bank_t bank, boost::uint16_t value){
-    //setup the out data
-    usrp2_ctrl_data_t out_data;
-    out_data.id = htonl(USRP2_CTRL_ID_USE_THESE_GPIO_DDR_SETTINGS_BRO);
-    out_data.data.gpio_config.bank = gpio_bank_to_otw(bank);
-    out_data.data.gpio_config.value = htons(value);
-    out_data.data.gpio_config.mask = htons(0xffff);
-
-    //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_GOT_THE_GPIO_DDR_SETTINGS_DUDE);
-}
-
-void usrp2_dboard_interface::write_gpio(gpio_bank_t bank, boost::uint16_t value){
-    //setup the out data
-    usrp2_ctrl_data_t out_data;
-    out_data.id = htonl(USRP2_CTRL_ID_SET_YOUR_GPIO_PIN_OUTS_BRO);
-    out_data.data.gpio_config.bank = gpio_bank_to_otw(bank);
-    out_data.data.gpio_config.value = htons(value);
-    out_data.data.gpio_config.mask = htons(0xffff);
-
-    //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_I_SET_THE_GPIO_PIN_OUTS_DUDE);
+    //calculate the new 32 bit ddr value
+    int shift = bank_to_shift(bank);
+    boost::uint32_t new_ddr_val =
+        (_ddr_shadow & ~(boost::uint32_t(0xffff) << shift)) //zero out new bits
+        | (boost::uint32_t(value) << shift); //or'ed in the new bits
+
+    //poke in the value and shadow
+    _impl->poke(offsetof(gpio_regs_t, ddr) + 0xC800, new_ddr_val);
+    _ddr_shadow = new_ddr_val;
 }
 
 boost::uint16_t usrp2_dboard_interface::read_gpio(gpio_bank_t bank){
-    //setup the out data
-    usrp2_ctrl_data_t out_data;
-    out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_GPIO_PIN_VALS_BRO);
-    out_data.data.gpio_config.bank = gpio_bank_to_otw(bank);
-
-    //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_HERE_IS_YOUR_GPIO_PIN_VALS_DUDE);
-    return ntohs(in_data.data.gpio_config.value);
+    boost::uint32_t data = _impl->peek(offsetof(gpio_regs_t, io) + 0xC800);
+    return boost::uint16_t(data >> bank_to_shift(bank));
 }
 
-void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, boost::uint16_t tx_value, boost::uint16_t rx_value, boost::uint16_t mask){
-    //setup the out data
-    usrp2_ctrl_data_t out_data;
-    out_data.id = htonl(USRP2_CTRL_ID_USE_THESE_ATR_SETTINGS_BRO);
-    out_data.data.atr_config.bank = gpio_bank_to_otw(bank);
-    out_data.data.atr_config.tx_value = htons(tx_value);
-    out_data.data.atr_config.rx_value = htons(rx_value);
-    out_data.data.atr_config.mask = htons(mask);
-
-    //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_GOT_THE_ATR_SETTINGS_DUDE);
+void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t reg, boost::uint16_t value){
+    //map the atr reg to an offset in register space
+    static const uhd::dict<atr_reg_t, int> reg_to_offset = boost::assign::map_list_of
+        (ATR_REG_IDLE, ATR_IDLE) (ATR_REG_TXONLY, ATR_TX)
+        (ATR_REG_RXONLY, ATR_RX) (ATR_REG_BOTH, ATR_FULL)
+    ;
+    int offset = reg_to_offset[reg];
+
+    //ensure a value exists in the shadow
+    if (not _atr_reg_shadows.has_key(reg)) _atr_reg_shadows[reg] = 0;
+
+    //calculate the new 32 bit atr value
+    int shift = bank_to_shift(bank);
+    boost::uint32_t new_atr_val =
+        (_atr_reg_shadows[reg] & ~(boost::uint32_t(0xffff) << shift)) //zero out new bits
+        | (boost::uint32_t(value) << shift); //or'ed in the new bits
+
+    //poke in the value and shadow
+    _impl->poke(offsetof(atr_regs_t, v) + 0xE400 + offset, new_atr_val);
+    _atr_reg_shadows[reg] = new_atr_val;
 }
 
 /***********************************************************************
@@ -160,44 +144,29 @@ void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, boost::uint16_t tx_va
  */
 static boost::uint8_t spi_dev_to_otw(dboard_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;
+    case uhd::usrp::dboard_interface::SPI_DEV_TX: return USRP2_DIR_TX;
+    case uhd::usrp::dboard_interface::SPI_DEV_RX: return USRP2_DIR_RX;
     }
     throw std::invalid_argument("unknown spi device type");
 }
 
 /*!
- * Static function to convert a spi latch enum
- * to an over-the-wire value for the usrp2 control.
- * \param latch the dboard interface spi latch enum
- * \return an over the wire representation
- */
-static boost::uint8_t spi_latch_to_otw(dboard_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;
-    }
-    throw std::invalid_argument("unknown spi latch type");
-}
-
-/*!
- * Static function to convert a spi push enum
+ * Static function to convert a spi edge enum
  * to an over-the-wire value for the usrp2 control.
- * \param push the dboard interface spi push enum
+ * \param edge the dboard interface spi edge enum
  * \return an over the wire representation
  */
-static boost::uint8_t spi_push_to_otw(dboard_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;
+static boost::uint8_t spi_edge_to_otw(dboard_interface::spi_edge_t edge){
+    switch(edge){
+    case uhd::usrp::dboard_interface::SPI_EDGE_RISE: return USRP2_CLK_EDGE_RISE;
+    case uhd::usrp::dboard_interface::SPI_EDGE_FALL: return USRP2_CLK_EDGE_FALL;
     }
-    throw std::invalid_argument("unknown spi push type");
+    throw std::invalid_argument("unknown spi edge type");
 }
 
 dboard_interface::byte_vector_t usrp2_dboard_interface::transact_spi(
     spi_dev_t dev,
-    spi_latch_t latch,
-    spi_push_t push,
+    spi_edge_t edge,
     const byte_vector_t &buf,
     bool readback
 ){
@@ -205,8 +174,7 @@ dboard_interface::byte_vector_t usrp2_dboard_interface::transact_spi(
     usrp2_ctrl_data_t out_data;
     out_data.id = htonl(USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO);
     out_data.data.spi_args.dev = spi_dev_to_otw(dev);
-    out_data.data.spi_args.latch = spi_latch_to_otw(latch);
-    out_data.data.spi_args.push = spi_push_to_otw(push);
+    out_data.data.spi_args.edge = spi_edge_to_otw(edge);
     out_data.data.spi_args.readback = (readback)? 1 : 0;
     out_data.data.spi_args.bytes = buf.size();
 
diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h
index 30fee6c32..565154305 100644
--- a/host/lib/usrp/usrp2/fw_common.h
+++ b/host/lib/usrp/usrp2/fw_common.h
@@ -45,67 +45,61 @@ extern "C" {
 #define USRP2_UDP_DATA_PORT 49153
 
 typedef enum{
-    USRP2_CTRL_ID_HUH_WHAT,
+    USRP2_CTRL_ID_HUH_WHAT = ' ',
     //USRP2_CTRL_ID_FOR_SURE, //TODO error condition enums
     //USRP2_CTRL_ID_SUX_MAN,
 
-    USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO,
-    USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE,
-    USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO,
+    USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO = 'a',
+    USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE = 'A',
+    USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO = 'b',
 
-    USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO,
-    USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE,
-    USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO,
+    USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO = 'm',
+    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,
-    USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE,
+    USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO = 'd',
+    USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE = 'D',
 
-    USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO,
-    USRP2_CTRL_ID_GOT_THE_NEW_CLOCK_CONFIG_DUDE,
+    USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO = 'c',
+    USRP2_CTRL_ID_GOT_THE_NEW_CLOCK_CONFIG_DUDE = 'C',
 
-    USRP2_CTRL_ID_USE_THESE_GPIO_DDR_SETTINGS_BRO,
-    USRP2_CTRL_ID_GOT_THE_GPIO_DDR_SETTINGS_DUDE,
+    USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO = 's',
+    USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE = 'S',
 
-    USRP2_CTRL_ID_SET_YOUR_GPIO_PIN_OUTS_BRO,
-    USRP2_CTRL_ID_I_SET_THE_GPIO_PIN_OUTS_DUDE,
+    USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO = 'i',
+    USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE = 'I',
 
-    USRP2_CTRL_ID_GIVE_ME_YOUR_GPIO_PIN_VALS_BRO,
-    USRP2_CTRL_ID_HERE_IS_YOUR_GPIO_PIN_VALS_DUDE,
+    USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO = 'h',
+    USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE = 'H',
 
-    USRP2_CTRL_ID_USE_THESE_ATR_SETTINGS_BRO,
-    USRP2_CTRL_ID_GOT_THE_ATR_SETTINGS_DUDE,
+    USRP2_CTRL_ID_WRITE_THIS_TO_THE_AUX_DAC_BRO = 'x',
+    USRP2_CTRL_ID_DONE_WITH_THAT_AUX_DAC_DUDE = 'X',
 
-    USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO,
-    USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE,
+    USRP2_CTRL_ID_READ_FROM_THIS_AUX_ADC_BRO = 'y',
+    USRP2_CTRL_ID_DONE_WITH_THAT_AUX_ADC_DUDE = 'Y',
 
-    USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO,
-    USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE,
+    USRP2_CTRL_ID_SETUP_THIS_DDC_FOR_ME_BRO = '\\',
+    USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE = '/',
 
-    USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO,
-    USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE,
+    USRP2_CTRL_ID_SEND_STREAM_COMMAND_FOR_ME_BRO = '{',
+    USRP2_CTRL_ID_GOT_THAT_STREAM_COMMAND_DUDE = '}',
 
-    USRP2_CTRL_ID_WRITE_THIS_TO_THE_AUX_DAC_BRO,
-    USRP2_CTRL_ID_DONE_WITH_THAT_AUX_DAC_DUDE,
+    USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO = '\'',
+    USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE = '"',
 
-    USRP2_CTRL_ID_READ_FROM_THIS_AUX_ADC_BRO,
-    USRP2_CTRL_ID_DONE_WITH_THAT_AUX_ADC_DUDE,
+    USRP2_CTRL_ID_GOT_A_NEW_TIME_FOR_YOU_BRO = '<',
+    USRP2_CTRL_ID_SWEET_I_GOT_THAT_TIME_DUDE = '>',
 
-    USRP2_CTRL_ID_SETUP_THIS_DDC_FOR_ME_BRO,
-    USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE,
+    USRP2_CTRL_ID_UPDATE_THOSE_MUX_SETTINGS_BRO = '-',
+    USRP2_CTRL_ID_UPDATED_THE_MUX_SETTINGS_DUDE = '_',
 
-    USRP2_CTRL_ID_SEND_STREAM_COMMAND_FOR_ME_BRO,
-    USRP2_CTRL_ID_GOT_THAT_STREAM_COMMAND_DUDE,
+    USRP2_CTRL_ID_POKE_THIS_REGISTER_FOR_ME_BRO = 'p',
+    USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE = 'P',
 
-    USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO,
-    USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE,
+    USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO = 'r',
+    USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE = 'R',
 
-    USRP2_CTRL_ID_GOT_A_NEW_TIME_FOR_YOU_BRO,
-    USRP2_CTRL_ID_SWEET_I_GOT_THAT_TIME_DUDE,
-
-    USRP2_CTRL_ID_UPDATE_THOSE_MUX_SETTINGS_BRO,
-    USRP2_CTRL_ID_UPDATED_THE_MUX_SETTINGS_DUDE,
-
-    USRP2_CTRL_ID_PEACE_OUT
+    USRP2_CTRL_ID_PEACE_OUT = '~'
 
 } usrp2_ctrl_id_t;
 
@@ -151,23 +145,9 @@ typedef struct{
             _SINS_ uint8_t ref_source;
             _SINS_ uint8_t _pad;
         } clock_config;
-        struct {
-            _SINS_ uint8_t bank;
-            _SINS_ uint8_t _pad[3];
-            _SINS_ uint16_t value;
-            _SINS_ uint16_t mask;
-        } gpio_config;
-        struct {
-            _SINS_ uint8_t bank;
-            _SINS_ uint8_t _pad[3];
-            _SINS_ uint16_t tx_value;
-            _SINS_ uint16_t rx_value;
-            _SINS_ uint16_t mask;
-        } atr_config;
         struct {
             _SINS_ uint8_t dev;
-            _SINS_ uint8_t latch;
-            _SINS_ uint8_t push;
+            _SINS_ uint8_t edge;
             _SINS_ uint8_t readback;
             _SINS_ uint8_t bytes;
             _SINS_ uint8_t data[sizeof(_SINS_ uint32_t)];
@@ -210,6 +190,10 @@ typedef struct{
             _SINS_ uint32_t rx_mux;
             _SINS_ uint32_t tx_mux;
         } mux_args;
+        struct {
+            _SINS_ uint32_t addr;
+            _SINS_ uint32_t data;
+        } poke_args;
     } data;
 } usrp2_ctrl_data_t;
 
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index b0ee395fb..e89fe8a63 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -173,6 +173,30 @@ double usrp2_impl::get_master_clock_freq(void){
     return 100e6;
 }
 
+void usrp2_impl::poke(boost::uint32_t addr, boost::uint32_t data){
+    //setup the out data
+    usrp2_ctrl_data_t out_data;
+    out_data.id = htonl(USRP2_CTRL_ID_POKE_THIS_REGISTER_FOR_ME_BRO);
+    out_data.data.poke_args.addr = htonl(addr);
+    out_data.data.poke_args.data = htonl(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_OMG_POKED_REGISTER_SO_BAD_DUDE);
+}
+
+boost::uint32_t usrp2_impl::peek(boost::uint32_t addr){
+    //setup the out data
+    usrp2_ctrl_data_t out_data;
+    out_data.id = htonl(USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO);
+    out_data.data.poke_args.addr = htonl(addr);
+
+    //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_WOAH_I_DEFINITELY_PEEKED_IT_DUDE);
+    return ntohl(out_data.data.poke_args.data);
+}
+
 /***********************************************************************
  * Control Send/Recv
  **********************************************************************/
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index 3468a0cf1..1b6175195 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -102,6 +102,10 @@ public:
     //performs a control transaction
     usrp2_ctrl_data_t ctrl_send_and_recv(const usrp2_ctrl_data_t &);
 
+    //peek and poke registers
+    void poke(boost::uint32_t addr, boost::uint32_t data);
+    boost::uint32_t peek(boost::uint32_t addr);
+
     //misc access methods
     double get_master_clock_freq(void);
 
diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp
new file mode 100644
index 000000000..9cf0b1fbc
--- /dev/null
+++ b/host/lib/usrp/usrp2/usrp2_regs.hpp
@@ -0,0 +1,57 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_USRP2_REGS_HPP
+#define INCLUDED_USRP2_REGS_HPP
+
+#include <boost/cstdint.hpp>
+
+////////////////////////////////////////////////
+// GPIO, Slave 4
+//
+// These go to the daughterboard i/o pins
+
+#define GPIO_BASE 0xC800
+
+typedef struct {
+    boost::uint32_t    io;       // tx data in high 16, rx in low 16
+    boost::uint32_t    ddr;      // 32 bits, 1 means output. tx in high 16, rx in low 16
+    boost::uint32_t    tx_sel;   // 16 2-bit fields select which source goes to TX DB
+    boost::uint32_t    rx_sel;   // 16 2-bit fields select which source goes to RX DB
+} gpio_regs_t;
+
+// each 2-bit sel field is layed out this way
+#define GPIO_SEL_SW	   0 // if pin is an output, set by software in the io reg
+#define	GPIO_SEL_ATR	   1 // if pin is an output, set by ATR logic
+#define	GPIO_SEL_DEBUG_0   2 // if pin is an output, debug lines from FPGA fabric
+#define	GPIO_SEL_DEBUG_1   3 // if pin is an output, debug lines from FPGA fabric
+
+///////////////////////////////////////////////////
+// ATR Controller, Slave 11
+
+#define ATR_BASE  0xE400
+
+typedef struct {
+    boost::uint32_t	v[16];
+} atr_regs_t;
+
+#define	ATR_IDLE	0x0	// indicies into v
+#define ATR_TX		0x1
+#define	ATR_RX		0x2
+#define	ATR_FULL	0x3
+
+#endif /* INCLUDED_USRP2_REGS_HPP */
-- 
cgit v1.2.3


From f15df8146cffb6cf42e0365396484af085be5df4 Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Wed, 31 Mar 2010 18:55:48 -0700
Subject: Moved dsp (rx and tx), time config, and clock config (mostly) into
 the host.

---
 firmware/microblaze/apps/txrx.c     | 116 ------------------------
 host/lib/usrp/usrp2/dboard_impl.cpp |  30 +++----
 host/lib/usrp/usrp2/dsp_impl.cpp    |  56 ++++++------
 host/lib/usrp/usrp2/fw_common.h     |  56 ------------
 host/lib/usrp/usrp2/mboard_impl.cpp |  56 +++++-------
 host/lib/usrp/usrp2/usrp2_impl.hpp  |   3 +-
 host/lib/usrp/usrp2/usrp2_regs.hpp  | 173 ++++++++++++++++++++++++++++++++++--
 7 files changed, 231 insertions(+), 259 deletions(-)

(limited to 'host/lib')

diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c
index 926260bac..430ae2fac 100644
--- a/firmware/microblaze/apps/txrx.c
+++ b/firmware/microblaze/apps/txrx.c
@@ -249,47 +249,6 @@ void handle_udp_ctrl_packet(
         ctrl_data_out.data.dboard_ids.rx_id = read_dboard_eeprom(I2C_ADDR_RX_A);
         break;
 
-    /*******************************************************************
-     * Clock Config
-     ******************************************************************/
-    case USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO:
-        //TODO handle MC_PROVIDE_CLK_TO_MIMO when we do MIMO setup
-        ctrl_data_out.id = USRP2_CTRL_ID_GOT_THE_NEW_CLOCK_CONFIG_DUDE;
-
-        //handle the 10 mhz ref source
-        uint32_t ref_flags = 0;
-        switch(ctrl_data_out.data.clock_config.ref_source){
-        case USRP2_REF_SOURCE_INT:
-            ref_flags = MC_WE_DONT_LOCK; break;
-        case USRP2_REF_SOURCE_SMA:
-            ref_flags = MC_WE_LOCK_TO_SMA; break;
-        case USRP2_REF_SOURCE_MIMO:
-            ref_flags = MC_WE_LOCK_TO_MIMO; break;
-        }
-        clocks_mimo_config(ref_flags & MC_REF_CLK_MASK);
-
-        //handle the pps config
-        uint32_t pps_flags = 0;
-
-        //fill in the pps polarity flags
-        switch(ctrl_data_out.data.clock_config.pps_polarity){
-        case USRP2_PPS_POLARITY_POS:
-            pps_flags |= 0x01 << 0; break;
-        case USRP2_PPS_POLARITY_NEG:
-            pps_flags |= 0x00 << 0; break;
-        }
-
-        //fill in the pps source flags
-        switch(ctrl_data_out.data.clock_config.pps_source){
-        case USRP2_PPS_SOURCE_SMA:
-            pps_flags |= 0x00 << 1; break;
-        case USRP2_PPS_SOURCE_MIMO:
-            pps_flags |= 0x01 << 1; break;
-        }
-        sr_time64->flags = pps_flags;
-
-        break;
-
     /*******************************************************************
      * SPI
      ******************************************************************/
@@ -385,34 +344,6 @@ void handle_udp_ctrl_packet(
         ctrl_data_out.id = USRP2_CTRL_ID_DONE_WITH_THAT_AUX_ADC_DUDE;
         break;
 
-    /*******************************************************************
-     * DDC
-     ******************************************************************/
-    case USRP2_CTRL_ID_SETUP_THIS_DDC_FOR_ME_BRO:
-        dsp_rx_regs->freq = ctrl_data_in->data.ddc_args.freq_word;
-        dsp_rx_regs->scale_iq = ctrl_data_in->data.ddc_args.scale_iq;
-
-        //setup the interp and half band filters
-        {
-            uint32_t decim = ctrl_data_in->data.ddc_args.decim;
-            uint32_t hb1 = 0;
-            uint32_t hb2 = 0;
-            if (!(decim & 1)){
-              hb2 = 1;
-              decim = decim >> 1;
-            }
-            if (!(decim & 1)){
-              hb1 = 1;
-              decim = decim >> 1;
-            }
-            uint32_t decim_word = (hb1<<9) | (hb2<<8) | decim;
-            dsp_rx_regs->decim_rate = decim_word;
-            printf("Decim: %d, register %d\n", ctrl_data_in->data.ddc_args.decim, decim_word);
-        }
-
-        ctrl_data_out.id = USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE;
-        break;
-
     /*******************************************************************
      * Streaming
      ******************************************************************/
@@ -477,53 +408,6 @@ void handle_udp_ctrl_packet(
         break;
     }
 
-    /*******************************************************************
-     * DUC
-     ******************************************************************/
-    case USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO:
-        dsp_tx_regs->freq = ctrl_data_in->data.duc_args.freq_word;
-        dsp_tx_regs->scale_iq = ctrl_data_in->data.duc_args.scale_iq;
-
-        //setup the interp and half band filters
-        {
-            uint32_t interp = ctrl_data_in->data.duc_args.interp;
-            uint32_t hb1 = 0;
-            uint32_t hb2 = 0;
-            if (!(interp & 1)){
-              hb2 = 1;
-              interp = interp >> 1;
-            }
-            if (!(interp & 1)){
-              hb1 = 1;
-              interp = interp >> 1;
-            }
-            uint32_t interp_word = (hb1<<9) | (hb2<<8) | interp;
-            dsp_tx_regs->interp_rate = interp_word;
-            printf("Interp: %d, register %d\n", ctrl_data_in->data.duc_args.interp, interp_word);
-        }
-
-        ctrl_data_out.id = USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE;
-        break;
-
-    /*******************************************************************
-     * Time Config
-     ******************************************************************/
-    case USRP2_CTRL_ID_GOT_A_NEW_TIME_FOR_YOU_BRO:
-        sr_time64->imm = (ctrl_data_in->data.time_args.now == 0)? 0 : 1;
-        sr_time64->ticks = ctrl_data_in->data.time_args.ticks;
-        sr_time64->secs = ctrl_data_in->data.time_args.secs; //set this last to latch the regs
-        ctrl_data_out.id = USRP2_CTRL_ID_SWEET_I_GOT_THAT_TIME_DUDE;
-        break;
-
-    /*******************************************************************
-     * MUX Config
-     ******************************************************************/
-    case USRP2_CTRL_ID_UPDATE_THOSE_MUX_SETTINGS_BRO:
-        dsp_rx_regs->rx_mux = ctrl_data_in->data.mux_args.rx_mux;
-        dsp_tx_regs->tx_mux = ctrl_data_in->data.mux_args.tx_mux;
-        ctrl_data_out.id = USRP2_CTRL_ID_UPDATED_THE_MUX_SETTINGS_DUDE;
-        break;
-
     /*******************************************************************
      * Peek and Poke Register
      ******************************************************************/
diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp
index fd72aeaa4..86ee52594 100644
--- a/host/lib/usrp/usrp2/dboard_impl.cpp
+++ b/host/lib/usrp/usrp2/dboard_impl.cpp
@@ -15,10 +15,12 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
+
+#include "usrp2_impl.hpp"
+#include "usrp2_regs.hpp"
 #include <uhd/utils/assert.hpp>
-#include <uhd/types/clock_config.hpp>
 #include <boost/format.hpp>
-#include "usrp2_impl.hpp"
+#include <cstddef>
 
 using namespace uhd;
 using namespace uhd::usrp;
@@ -57,11 +59,13 @@ void usrp2_impl::dboard_init(void){
 
     //init the subdevs in use (use the first subdevice)
     _rx_subdevs_in_use = prop_names_t(1, _dboard_manager->get_rx_subdev_names().at(0));
+    update_rx_mux_config();
+
     _tx_subdevs_in_use = prop_names_t(1, _dboard_manager->get_tx_subdev_names().at(0));
-    update_mux_config();
+    update_tx_mux_config();
 }
 
-void usrp2_impl::update_mux_config(void){
+void usrp2_impl::update_rx_mux_config(void){
     //calculate the rx mux
     boost::uint32_t rx_mux = 0;
     ASSERT_THROW(_rx_subdevs_in_use.size() == 1);
@@ -76,6 +80,10 @@ void usrp2_impl::update_mux_config(void){
         rx_mux = (((rx_mux >> 0) & 0x3) << 2) | (((rx_mux >> 2) & 0x3) << 0);
     }
 
+    this->poke(offsetof(dsp_rx_regs_t, rx_mux) + DSP_RX_BASE, rx_mux);
+}
+
+void usrp2_impl::update_tx_mux_config(void){
     //calculate the tx mux
     boost::uint32_t tx_mux = 0x10;
     ASSERT_THROW(_tx_subdevs_in_use.size() == 1);
@@ -85,15 +93,7 @@ void usrp2_impl::update_mux_config(void){
         tx_mux = (((tx_mux >> 0) & 0x1) << 1) | (((tx_mux >> 1) & 0x1) << 0);
     }
 
-    //setup the out data
-    usrp2_ctrl_data_t out_data;
-    out_data.id = htonl(USRP2_CTRL_ID_UPDATE_THOSE_MUX_SETTINGS_BRO);
-    out_data.data.mux_args.rx_mux = htonl(rx_mux);
-    out_data.data.mux_args.tx_mux = htonl(tx_mux);
-
-    //send and recv
-    usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data);
-    ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_UPDATED_THE_MUX_SETTINGS_DUDE);
+    this->poke(offsetof(dsp_tx_regs_t, tx_mux) + DSP_TX_BASE, tx_mux);
 }
 
 /***********************************************************************
@@ -129,7 +129,7 @@ void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){
 void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){
     if (key.as<dboard_prop_t>() == DBOARD_PROP_USED_SUBDEVS){
         _rx_subdevs_in_use = val.as<prop_names_t>();
-        update_mux_config(); //if the val is bad, this will throw
+        update_rx_mux_config(); //if the val is bad, this will throw
         return;
     }
 
@@ -169,7 +169,7 @@ void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){
 void usrp2_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){
     if (key.as<dboard_prop_t>() == DBOARD_PROP_USED_SUBDEVS){
         _tx_subdevs_in_use = val.as<prop_names_t>();
-        update_mux_config(); //if the val is bad, this will throw
+        update_tx_mux_config(); //if the val is bad, this will throw
         return;
     }
 
diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp
index 0d43fac0e..6edfec61a 100644
--- a/host/lib/usrp/usrp2/dsp_impl.cpp
+++ b/host/lib/usrp/usrp2/dsp_impl.cpp
@@ -15,11 +15,13 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
+#include "usrp2_impl.hpp"
+#include "usrp2_regs.hpp"
 #include <uhd/utils/assert.hpp>
 #include <boost/format.hpp>
 #include <boost/assign/list_of.hpp>
 #include <boost/math/special_functions/round.hpp>
-#include "usrp2_impl.hpp"
+#include <cstddef>
 
 using namespace uhd;
 
@@ -64,25 +66,25 @@ void usrp2_impl::init_ddc_config(void){
     update_ddc_config();
 
     //initial command that kills streaming (in case if was left on)
-    //issue_ddc_stream_cmd(TODO)
+    stream_cmd_t stream_cmd_off;
+    stream_cmd_off.stream_now = true;
+    stream_cmd_off.continuous = false;
+    stream_cmd_off.num_samps = 0;
+    issue_ddc_stream_cmd(stream_cmd_off);
 }
 
 void usrp2_impl::update_ddc_config(void){
-    //setup the out data
-    usrp2_ctrl_data_t out_data;
-    out_data.id = htonl(USRP2_CTRL_ID_SETUP_THIS_DDC_FOR_ME_BRO);
-    out_data.data.ddc_args.freq_word = htonl(
-        calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq())
+    //set the decimation
+    this->poke(
+        offsetof(dsp_rx_regs_t, decim_rate) + DSP_RX_BASE, _ddc_decim
     );
-    out_data.data.ddc_args.decim = htonl(_ddc_decim);
+
+    //set the scaling
     static const boost::int16_t default_rx_scale_iq = 1024;
-    out_data.data.ddc_args.scale_iq = htonl(
+    this->poke(
+        offsetof(dsp_rx_regs_t, scale_iq) + DSP_RX_BASE,
         calculate_iq_scale_word(default_rx_scale_iq, default_rx_scale_iq)
     );
-
-    //send and recv
-    usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data);
-    ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE);
 }
 
 void usrp2_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){
@@ -172,7 +174,10 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){
         ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0);
         ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0);
         _ddc_freq = new_freq; //shadow
-        update_ddc_config();
+        this->poke( //set the cordic
+            offsetof(dsp_rx_regs_t, freq) + DSP_RX_BASE,
+            calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq())
+        );
         return;
     }
     else if (key_name == "stream_cmd"){
@@ -210,20 +215,16 @@ void usrp2_impl::update_duc_config(void){
     double interp_cubed = std::pow(double(tmp_interp), 3);
     boost::int16_t scale = rint((4096*std::pow(2, ceil(log2(interp_cubed))))/(1.65*interp_cubed));
 
-    //setup the out data
-    usrp2_ctrl_data_t out_data;
-    out_data.id = htonl(USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO);
-    out_data.data.duc_args.freq_word = htonl(
-        calculate_freq_word_and_update_actual_freq(_duc_freq, get_master_clock_freq())
+    //set the interpolation
+    this->poke(
+        offsetof(dsp_tx_regs_t, interp_rate) + DSP_TX_BASE, _ddc_decim
     );
-    out_data.data.duc_args.interp = htonl(_duc_interp);
-    out_data.data.duc_args.scale_iq = htonl(
+
+    //set the scaling
+    this->poke(
+        offsetof(dsp_tx_regs_t, scale_iq) + DSP_TX_BASE,
         calculate_iq_scale_word(scale, scale)
     );
-
-    //send and recv
-    usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data);
-    ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE);
 }
 
 /***********************************************************************
@@ -297,7 +298,10 @@ void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){
         ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0);
         ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0);
         _duc_freq = new_freq; //shadow
-        update_duc_config();
+        this->poke( //set the cordic
+            offsetof(dsp_tx_regs_t, freq) + DSP_TX_BASE,
+            calculate_freq_word_and_update_actual_freq(_duc_freq, get_master_clock_freq())
+        );
         return;
     }
 
diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h
index 565154305..c168614ee 100644
--- a/host/lib/usrp/usrp2/fw_common.h
+++ b/host/lib/usrp/usrp2/fw_common.h
@@ -60,9 +60,6 @@ typedef enum{
     USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO = 'd',
     USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE = 'D',
 
-    USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO = 'c',
-    USRP2_CTRL_ID_GOT_THE_NEW_CLOCK_CONFIG_DUDE = 'C',
-
     USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO = 's',
     USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE = 'S',
 
@@ -78,21 +75,9 @@ typedef enum{
     USRP2_CTRL_ID_READ_FROM_THIS_AUX_ADC_BRO = 'y',
     USRP2_CTRL_ID_DONE_WITH_THAT_AUX_ADC_DUDE = 'Y',
 
-    USRP2_CTRL_ID_SETUP_THIS_DDC_FOR_ME_BRO = '\\',
-    USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE = '/',
-
     USRP2_CTRL_ID_SEND_STREAM_COMMAND_FOR_ME_BRO = '{',
     USRP2_CTRL_ID_GOT_THAT_STREAM_COMMAND_DUDE = '}',
 
-    USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO = '\'',
-    USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE = '"',
-
-    USRP2_CTRL_ID_GOT_A_NEW_TIME_FOR_YOU_BRO = '<',
-    USRP2_CTRL_ID_SWEET_I_GOT_THAT_TIME_DUDE = '>',
-
-    USRP2_CTRL_ID_UPDATE_THOSE_MUX_SETTINGS_BRO = '-',
-    USRP2_CTRL_ID_UPDATED_THE_MUX_SETTINGS_DUDE = '_',
-
     USRP2_CTRL_ID_POKE_THIS_REGISTER_FOR_ME_BRO = 'p',
     USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE = 'P',
 
@@ -103,22 +88,6 @@ typedef enum{
 
 } usrp2_ctrl_id_t;
 
-typedef enum{
-    USRP2_PPS_SOURCE_SMA,
-    USRP2_PPS_SOURCE_MIMO
-} usrp2_pps_source_t;
-
-typedef enum{
-    USRP2_PPS_POLARITY_POS,
-    USRP2_PPS_POLARITY_NEG
-} usrp2_pps_polarity_t;
-
-typedef enum{
-    USRP2_REF_SOURCE_INT,
-    USRP2_REF_SOURCE_SMA,
-    USRP2_REF_SOURCE_MIMO
-} usrp2_ref_source_t;
-
 typedef enum{
     USRP2_DIR_RX,
     USRP2_DIR_TX
@@ -139,12 +108,6 @@ typedef struct{
             _SINS_ uint16_t rx_id;
             _SINS_ uint16_t tx_id;
         } dboard_ids;
-        struct {
-            _SINS_ uint8_t pps_source;
-            _SINS_ uint8_t pps_polarity;
-            _SINS_ uint8_t ref_source;
-            _SINS_ uint8_t _pad;
-        } clock_config;
         struct {
             _SINS_ uint8_t dev;
             _SINS_ uint8_t edge;
@@ -163,11 +126,6 @@ typedef struct{
             _SINS_ uint8_t _pad[2];
             _SINS_ uint32_t value;
         } aux_args;
-        struct {
-            _SINS_ uint32_t freq_word;
-            _SINS_ uint32_t decim;
-            _SINS_ uint32_t scale_iq;
-        } ddc_args;
         struct {
             _SINS_ uint8_t now; //stream now?
             _SINS_ uint8_t continuous; //auto-reload commmands?
@@ -176,20 +134,6 @@ typedef struct{
             _SINS_ uint32_t ticks;
             _SINS_ uint32_t num_samps;
         } stream_cmd;
-        struct {
-            _SINS_ uint32_t freq_word;
-            _SINS_ uint32_t interp;
-            _SINS_ uint32_t scale_iq;
-        } duc_args;
-        struct {
-            _SINS_ uint32_t secs;
-            _SINS_ uint32_t ticks;
-            _SINS_ uint8_t now;
-        } time_args;
-        struct {
-            _SINS_ uint32_t rx_mux;
-            _SINS_ uint32_t tx_mux;
-        } mux_args;
         struct {
             _SINS_ uint32_t addr;
             _SINS_ uint32_t data;
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index 35dfd6287..eff53c5b2 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -15,9 +15,12 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
+#include "usrp2_impl.hpp"
+#include "usrp2_regs.hpp"
 #include <uhd/utils/assert.hpp>
 #include <uhd/types/mac_addr.hpp>
-#include "usrp2_impl.hpp"
+#include <uhd/types/dict.hpp>
+#include <cstddef>
 
 using namespace uhd;
 
@@ -46,55 +49,36 @@ void usrp2_impl::init_clock_config(void){
 }
 
 void usrp2_impl::update_clock_config(void){
-    //setup the out data
-    usrp2_ctrl_data_t out_data;
-    out_data.id = htonl(USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO);
-
-    //translate ref source enums
-    switch(_clock_config.ref_source){
-    case clock_config_t::REF_INT:
-        out_data.data.clock_config.ref_source = USRP2_REF_SOURCE_INT; break;
-    case clock_config_t::REF_SMA:
-        out_data.data.clock_config.ref_source = USRP2_REF_SOURCE_SMA; break;
-    case clock_config_t::REF_MIMO:
-        out_data.data.clock_config.ref_source = USRP2_REF_SOURCE_MIMO; break;
-    default: throw std::runtime_error("usrp2: unhandled clock configuration ref source");
-    }
+    boost::uint32_t pps_flags = 0;
 
     //translate pps source enums
     switch(_clock_config.pps_source){
-    case clock_config_t::PPS_SMA:
-        out_data.data.clock_config.pps_source = USRP2_PPS_SOURCE_SMA; break;
-    case clock_config_t::PPS_MIMO:
-        out_data.data.clock_config.pps_source = USRP2_PPS_SOURCE_MIMO; break;
+    case clock_config_t::PPS_SMA:  pps_flags |= PPS_FLAG_SMA;  break;
+    case clock_config_t::PPS_MIMO: pps_flags |= PPS_FLAG_MIMO; break;
     default: throw std::runtime_error("usrp2: unhandled clock configuration pps source");
     }
 
     //translate pps polarity enums
     switch(_clock_config.pps_polarity){
-    case clock_config_t::PPS_POS:
-        out_data.data.clock_config.pps_source = USRP2_PPS_POLARITY_POS; break;
-    case clock_config_t::PPS_NEG:
-        out_data.data.clock_config.pps_source = USRP2_PPS_POLARITY_NEG; break;
+    case clock_config_t::PPS_POS: pps_flags |= PPS_FLAG_POSEDGE; break;
+    case clock_config_t::PPS_NEG: pps_flags |= PPS_FLAG_NEGEDGE; break;
     default: throw std::runtime_error("usrp2: unhandled clock configuration pps polarity");
     }
 
-    //send and recv
-    usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data);
-    ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THE_NEW_CLOCK_CONFIG_DUDE);
+    //set the pps flags
+    this->poke(offsetof(sr_time64_t, flags) + TIME64_BASE, pps_flags);
+
+    //TODO clock source ref 10mhz (spi ad9510)
 }
 
 void usrp2_impl::set_time_spec(const time_spec_t &time_spec, bool now){
-    //setup the out data
-    usrp2_ctrl_data_t out_data;
-    out_data.id = htonl(USRP2_CTRL_ID_GOT_A_NEW_TIME_FOR_YOU_BRO);
-    out_data.data.time_args.secs  = htonl(time_spec.secs);
-    out_data.data.time_args.ticks = htonl(time_spec.ticks);
-    out_data.data.time_args.now   = (now)? 1 : 0;
-
-    //send and recv
-    usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data);
-    ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_SWEET_I_GOT_THAT_TIME_DUDE);
+    //set ticks and seconds
+    this->poke(offsetof(sr_time64_t, secs) + TIME64_BASE, time_spec.secs);
+    this->poke(offsetof(sr_time64_t, ticks) + TIME64_BASE, time_spec.ticks);
+
+    //set the register to latch it all in
+    boost::uint32_t imm_flags = (now)? TIME64_LATCH_NOW : TIME64_LATCH_NEXT_PPS;
+    this->poke(offsetof(sr_time64_t, imm) + TIME64_BASE, imm_flags);
 }
 
 /***********************************************************************
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index 1b6175195..55be420cd 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -172,7 +172,8 @@ private:
     void tx_dboard_set(const wax::obj &, const wax::obj &);
     uhd::dict<std::string, wax_obj_proxy::sptr> _tx_dboards;
     uhd::prop_names_t _tx_subdevs_in_use;
-    void update_mux_config(void);
+    void update_rx_mux_config(void);
+    void update_tx_mux_config(void);
 
     //methods and shadows for the ddc dsp
     std::vector<size_t> _allowed_decim_and_interp_rates;
diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp
index 9cf0b1fbc..7d868c264 100644
--- a/host/lib/usrp/usrp2/usrp2_regs.hpp
+++ b/host/lib/usrp/usrp2/usrp2_regs.hpp
@@ -20,6 +20,161 @@
 
 #include <boost/cstdint.hpp>
 
+////////////////////////////////////////////////////
+// Settings Bus, Slave #7, Not Byte Addressable!
+//
+// Output-only from processor point-of-view.
+// 1KB of address space (== 256 32-bit write-only regs)
+
+
+#define MISC_OUTPUT_BASE        0xD400
+#define TX_PROTOCOL_ENGINE_BASE 0xD480
+#define RX_PROTOCOL_ENGINE_BASE 0xD4C0
+#define BUFFER_POOL_CTRL_BASE   0xD500
+#define LAST_SETTING_REG        0xD7FC  // last valid setting register
+
+#define SR_MISC 0
+#define SR_TX_PROT_ENG 32
+#define SR_RX_PROT_ENG 48
+#define SR_BUFFER_POOL_CTRL 64
+#define SR_UDP_SM 96
+#define SR_TX_DSP 208
+#define SR_TX_CTRL 224
+#define SR_RX_DSP 160
+#define SR_RX_CTRL 176
+#define SR_TIME64 192
+#define SR_SIMTIMER 198
+#define SR_LAST 255
+
+#define _SR_ADDR(sr)    (MISC_OUTPUT_BASE + (sr) * sizeof(uint32_t))
+
+/////////////////////////////////////////////////
+// VITA49 64 bit time (write only)
+////////////////////////////////////////////////
+
+#define TIME64_BASE _SR_ADDR(SR_TIME64)
+
+  /*!
+   * \brief Time 64 flags
+   *
+   * <pre>
+   *
+   *    3                   2                   1                       
+   *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+   * +-----------------------------------------------------------+-+-+
+   * |                                                           |S|P|
+   * +-----------------------------------------------------------+-+-+
+   *
+   * P - PPS edge selection (0=negedge, 1=posedge, default=0)
+   * S - Source (0=sma, 1=mimo, 0=default)
+   *
+   * </pre>
+   */
+typedef struct {
+    boost::uint32_t secs;   // value to set absolute secs to on next PPS
+    boost::uint32_t ticks;  // value to set absolute ticks to on next PPS
+    boost::uint32_t flags;  // flags - see chart above
+    boost::uint32_t imm;    // set immediate (0=latch on next pps, 1=latch immediate, default=0)
+} sr_time64_t;
+
+//pps flags (see above)
+#define PPS_FLAG_NEGEDGE (0 << 0)
+#define PPS_FLAG_POSEDGE (1 << 0)
+#define PPS_FLAG_SMA     (0 << 1)
+#define PPS_FLAG_MIMO    (1 << 1)
+
+#define TIME64_LATCH_NOW 1
+#define TIME64_LATCH_NEXT_PPS 0
+
+/////////////////////////////////////////////////
+// DSP TX Regs
+////////////////////////////////////////////////
+
+#define DSP_TX_BASE _SR_ADDR(SR_TX_DSP)
+
+typedef struct {
+    boost::int32_t      freq;
+    boost::uint32_t     scale_iq;       // {scale_i,scale_q}
+    boost::uint32_t     interp_rate;
+    boost::uint32_t     _padding0;      // padding for the tx_mux
+                                        //   NOT freq, scale, interp
+  /*!
+   * \brief output mux configuration.
+   *
+   * <pre>
+   *     3                   2                   1                       
+   *   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+   *  +-------------------------------+-------+-------+-------+-------+
+   *  |                                               | DAC1  |  DAC0 |
+   *  +-------------------------------+-------+-------+-------+-------+
+   * 
+   *  There are N DUCs (1 now) with complex inputs and outputs.
+   *  There are two DACs.
+   * 
+   *  Each 4-bit DACx field specifies the source for the DAC
+   *  Each subfield is coded like this: 
+   * 
+   *     3 2 1 0
+   *    +-------+
+   *    |   N   |
+   *    +-------+
+   * 
+   *  N specifies which DUC output is connected to this DAC.
+   * 
+   *   N   which interp output
+   *  ---  -------------------
+   *   0   DUC 0 I
+   *   1   DUC 0 Q
+   *   2   DUC 1 I
+   *   3   DUC 1 Q
+   *   F   All Zeros
+   *   
+   * The default value is 0x10
+   * </pre>
+   */
+    boost::uint32_t tx_mux;
+
+} dsp_tx_regs_t;
+
+/////////////////////////////////////////////////
+// DSP RX Regs
+////////////////////////////////////////////////
+
+#define DSP_RX_BASE _SR_ADDR(SR_RX_DSP)
+
+typedef struct {
+    boost::int32_t      freq;
+    boost::uint32_t     scale_iq;       // {scale_i,scale_q}
+    boost::uint32_t     decim_rate;
+    boost::uint32_t     dcoffset_i;     // Bit 31 high sets fixed offset mode, using lower 14 bits,
+                                        // otherwise it is automatic 
+    boost::uint32_t     dcoffset_q;     // Bit 31 high sets fixed offset mode, using lower 14 bits
+
+  /*!
+   * \brief input mux configuration.
+   *
+   * This determines which ADC (or constant zero) is connected to 
+   * each DDC input.  There are N DDCs (1 now).  Each has two inputs.
+   *
+   * <pre>
+   * Mux value:
+   *
+   *    3                   2                   1                       
+   *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+   * +-------+-------+-------+-------+-------+-------+-------+-------+
+   * |                                                       |Q0 |I0 |
+   * +-------+-------+-------+-------+-------+-------+-------+-------+
+   *
+   * Each 2-bit I field is either 00 (A/D A), 01 (A/D B) or 1X (const zero)
+   * Each 2-bit Q field is either 00 (A/D A), 01 (A/D B) or 1X (const zero)
+   *
+   * The default value is 0x4
+   * </pre>
+   */
+    boost::uint32_t     rx_mux;        // called adc_mux in dsp_core_rx.v
+
+} dsp_rx_regs_t;
+
 ////////////////////////////////////////////////
 // GPIO, Slave 4
 //
@@ -35,10 +190,10 @@ typedef struct {
 } gpio_regs_t;
 
 // each 2-bit sel field is layed out this way
-#define GPIO_SEL_SW	   0 // if pin is an output, set by software in the io reg
-#define	GPIO_SEL_ATR	   1 // if pin is an output, set by ATR logic
-#define	GPIO_SEL_DEBUG_0   2 // if pin is an output, debug lines from FPGA fabric
-#define	GPIO_SEL_DEBUG_1   3 // if pin is an output, debug lines from FPGA fabric
+#define GPIO_SEL_SW        0 // if pin is an output, set by software in the io reg
+#define GPIO_SEL_ATR       1 // if pin is an output, set by ATR logic
+#define GPIO_SEL_DEBUG_0   2 // if pin is an output, debug lines from FPGA fabric
+#define GPIO_SEL_DEBUG_1   3 // if pin is an output, debug lines from FPGA fabric
 
 ///////////////////////////////////////////////////
 // ATR Controller, Slave 11
@@ -46,12 +201,12 @@ typedef struct {
 #define ATR_BASE  0xE400
 
 typedef struct {
-    boost::uint32_t	v[16];
+    boost::uint32_t v[16];
 } atr_regs_t;
 
-#define	ATR_IDLE	0x0	// indicies into v
-#define ATR_TX		0x1
-#define	ATR_RX		0x2
-#define	ATR_FULL	0x3
+#define ATR_IDLE    0x0 // indicies into v
+#define ATR_TX      0x1
+#define ATR_RX      0x2
+#define ATR_FULL    0x3
 
 #endif /* INCLUDED_USRP2_REGS_HPP */
-- 
cgit v1.2.3


From f01b1a394fbf7304aefc0231f500a52db457767a Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Wed, 31 Mar 2010 19:25:22 -0700
Subject: added spi slaves to regs, use std copy for buffs

---
 firmware/microblaze/apps/txrx.c          |  2 +-
 host/lib/usrp/usrp2/dboard_interface.cpp | 25 +++++++++----------------
 host/lib/usrp/usrp2/usrp2_regs.hpp       | 13 +++++++++++++
 3 files changed, 23 insertions(+), 17 deletions(-)

(limited to 'host/lib')

diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c
index 430ae2fac..39a503091 100644
--- a/firmware/microblaze/apps/txrx.c
+++ b/firmware/microblaze/apps/txrx.c
@@ -264,7 +264,7 @@ void handle_udp_ctrl_packet(
             //transact
             uint32_t result = spi_transact(
                 (ctrl_data_in->data.spi_args.readback == 0)? SPI_TXONLY : SPI_TXRX,
-                (ctrl_data_in->data.spi_args.dev == USRP2_DIR_RX)? SPI_SS_RX_DB : SPI_SS_TX_DB,
+                ctrl_data_in->data.spi_args.dev,
                 data, num_bytes*8, //length in bits
                 (ctrl_data_in->data.spi_args.edge == USRP2_CLK_EDGE_RISE)? SPIF_PUSH_RISE : SPIF_PUSH_FALL |
                 (ctrl_data_in->data.spi_args.edge == USRP2_CLK_EDGE_RISE)? SPIF_LATCH_RISE : SPIF_LATCH_FALL
diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp
index 0bf4fa2e6..f5fe68152 100644
--- a/host/lib/usrp/usrp2/dboard_interface.cpp
+++ b/host/lib/usrp/usrp2/dboard_interface.cpp
@@ -20,6 +20,7 @@
 #include <uhd/types/dict.hpp>
 #include <uhd/utils/assert.hpp>
 #include <boost/assign/list_of.hpp>
+#include <algorithm>
 #include <cstddef>
 
 using namespace uhd::usrp;
@@ -144,8 +145,8 @@ void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t reg, boost:
  */
 static boost::uint8_t spi_dev_to_otw(dboard_interface::spi_dev_t dev){
     switch(dev){
-    case uhd::usrp::dboard_interface::SPI_DEV_TX: return USRP2_DIR_TX;
-    case uhd::usrp::dboard_interface::SPI_DEV_RX: return USRP2_DIR_RX;
+    case uhd::usrp::dboard_interface::SPI_DEV_TX: return SPI_SS_TX_DB;
+    case uhd::usrp::dboard_interface::SPI_DEV_RX: return SPI_SS_RX_DB;
     }
     throw std::invalid_argument("unknown spi device type");
 }
@@ -182,9 +183,7 @@ dboard_interface::byte_vector_t usrp2_dboard_interface::transact_spi(
     ASSERT_THROW(buf.size() <= sizeof(out_data.data.spi_args.data));
 
     //copy in the data
-    for (size_t i = 0; i < buf.size(); i++){
-        out_data.data.spi_args.data[i] = buf[i];
-    }
+    std::copy(buf.begin(), buf.end(), out_data.data.spi_args.data);
 
     //send and recv
     usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data);
@@ -192,10 +191,8 @@ dboard_interface::byte_vector_t usrp2_dboard_interface::transact_spi(
     ASSERT_THROW(in_data.data.spi_args.bytes == buf.size());
 
     //copy out the data
-    byte_vector_t result;
-    for (size_t i = 0; i < buf.size(); i++){
-        result.push_back(in_data.data.spi_args.data[i]);
-    }
+    byte_vector_t result(buf.size());
+    std::copy(in_data.data.spi_args.data, in_data.data.spi_args.data + buf.size(), result.begin());
     return result;
 }
 
@@ -213,9 +210,7 @@ void usrp2_dboard_interface::write_i2c(int i2c_addr, const byte_vector_t &buf){
     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];
-    }
+    std::copy(buf.begin(), buf.end(), out_data.data.i2c_args.data);
 
     //send and recv
     usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data);
@@ -238,10 +233,8 @@ dboard_interface::byte_vector_t usrp2_dboard_interface::read_i2c(int i2c_addr, s
     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]);
-    }
+    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;
 }
 
diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp
index 7d868c264..b7fd239a6 100644
--- a/host/lib/usrp/usrp2/usrp2_regs.hpp
+++ b/host/lib/usrp/usrp2/usrp2_regs.hpp
@@ -48,6 +48,19 @@
 
 #define _SR_ADDR(sr)    (MISC_OUTPUT_BASE + (sr) * sizeof(uint32_t))
 
+/////////////////////////////////////////////////
+// SPI Slave Constants
+////////////////////////////////////////////////
+// Masks for controlling different peripherals
+#define SPI_SS_AD9510    1
+#define SPI_SS_AD9777    2
+#define SPI_SS_RX_DAC    4
+#define SPI_SS_RX_ADC    8
+#define SPI_SS_RX_DB    16
+#define SPI_SS_TX_DAC   32
+#define SPI_SS_TX_ADC   64
+#define SPI_SS_TX_DB   128
+
 /////////////////////////////////////////////////
 // VITA49 64 bit time (write only)
 ////////////////////////////////////////////////
-- 
cgit v1.2.3


From 792fad3afca0eb45fdc3eb27b5d1678c507d4724 Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Thu, 1 Apr 2010 13:30:34 -0700
Subject: use defined constants for the register addresses

---
 host/lib/usrp/usrp2/dboard_impl.cpp      |   5 +-
 host/lib/usrp/usrp2/dboard_interface.cpp |  15 ++---
 host/lib/usrp/usrp2/dsp_impl.cpp         |  23 ++-----
 host/lib/usrp/usrp2/mboard_impl.cpp      |  19 +++---
 host/lib/usrp/usrp2/usrp2_regs.hpp       | 112 ++++++++++++-------------------
 5 files changed, 67 insertions(+), 107 deletions(-)

(limited to 'host/lib')

diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp
index 86ee52594..29fb32eeb 100644
--- a/host/lib/usrp/usrp2/dboard_impl.cpp
+++ b/host/lib/usrp/usrp2/dboard_impl.cpp
@@ -20,7 +20,6 @@
 #include "usrp2_regs.hpp"
 #include <uhd/utils/assert.hpp>
 #include <boost/format.hpp>
-#include <cstddef>
 
 using namespace uhd;
 using namespace uhd::usrp;
@@ -80,7 +79,7 @@ void usrp2_impl::update_rx_mux_config(void){
         rx_mux = (((rx_mux >> 0) & 0x3) << 2) | (((rx_mux >> 2) & 0x3) << 0);
     }
 
-    this->poke(offsetof(dsp_rx_regs_t, rx_mux) + DSP_RX_BASE, rx_mux);
+    this->poke(FR_DSP_RX_MUX, rx_mux);
 }
 
 void usrp2_impl::update_tx_mux_config(void){
@@ -93,7 +92,7 @@ void usrp2_impl::update_tx_mux_config(void){
         tx_mux = (((tx_mux >> 0) & 0x1) << 1) | (((tx_mux >> 1) & 0x1) << 0);
     }
 
-    this->poke(offsetof(dsp_tx_regs_t, tx_mux) + DSP_TX_BASE, tx_mux);
+    this->poke(FR_DSP_TX_MUX, tx_mux);
 }
 
 /***********************************************************************
diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp
index f5fe68152..4160ad467 100644
--- a/host/lib/usrp/usrp2/dboard_interface.cpp
+++ b/host/lib/usrp/usrp2/dboard_interface.cpp
@@ -21,7 +21,6 @@
 #include <uhd/utils/assert.hpp>
 #include <boost/assign/list_of.hpp>
 #include <algorithm>
-#include <cstddef>
 
 using namespace uhd::usrp;
 
@@ -103,22 +102,22 @@ void usrp2_dboard_interface::set_gpio_ddr(gpio_bank_t bank, boost::uint16_t valu
         | (boost::uint32_t(value) << shift); //or'ed in the new bits
 
     //poke in the value and shadow
-    _impl->poke(offsetof(gpio_regs_t, ddr) + 0xC800, new_ddr_val);
+    _impl->poke(FR_GPIO_DDR, new_ddr_val);
     _ddr_shadow = new_ddr_val;
 }
 
 boost::uint16_t usrp2_dboard_interface::read_gpio(gpio_bank_t bank){
-    boost::uint32_t data = _impl->peek(offsetof(gpio_regs_t, io) + 0xC800);
+    boost::uint32_t data = _impl->peek(FR_GPIO_IO);
     return boost::uint16_t(data >> bank_to_shift(bank));
 }
 
 void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t reg, boost::uint16_t value){
     //map the atr reg to an offset in register space
-    static const uhd::dict<atr_reg_t, int> reg_to_offset = boost::assign::map_list_of
-        (ATR_REG_IDLE, ATR_IDLE) (ATR_REG_TXONLY, ATR_TX)
-        (ATR_REG_RXONLY, ATR_RX) (ATR_REG_BOTH, ATR_FULL)
+    static const uhd::dict<atr_reg_t, int> reg_to_addr = boost::assign::map_list_of
+        (ATR_REG_IDLE, FR_ATR_IDLE) (ATR_REG_TXONLY, FR_ATR_TX)
+        (ATR_REG_RXONLY, FR_ATR_RX) (ATR_REG_BOTH, FR_ATR_FULL)
     ;
-    int offset = reg_to_offset[reg];
+    ASSERT_THROW(reg_to_addr.has_key(reg));
 
     //ensure a value exists in the shadow
     if (not _atr_reg_shadows.has_key(reg)) _atr_reg_shadows[reg] = 0;
@@ -130,7 +129,7 @@ void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t reg, boost:
         | (boost::uint32_t(value) << shift); //or'ed in the new bits
 
     //poke in the value and shadow
-    _impl->poke(offsetof(atr_regs_t, v) + 0xE400 + offset, new_atr_val);
+    _impl->poke(reg_to_addr[reg], new_atr_val);
     _atr_reg_shadows[reg] = new_atr_val;
 }
 
diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp
index 6edfec61a..d50c1ad56 100644
--- a/host/lib/usrp/usrp2/dsp_impl.cpp
+++ b/host/lib/usrp/usrp2/dsp_impl.cpp
@@ -21,7 +21,6 @@
 #include <boost/format.hpp>
 #include <boost/assign/list_of.hpp>
 #include <boost/math/special_functions/round.hpp>
-#include <cstddef>
 
 using namespace uhd;
 
@@ -75,14 +74,11 @@ void usrp2_impl::init_ddc_config(void){
 
 void usrp2_impl::update_ddc_config(void){
     //set the decimation
-    this->poke(
-        offsetof(dsp_rx_regs_t, decim_rate) + DSP_RX_BASE, _ddc_decim
-    );
+    this->poke(FR_DSP_RX_DECIM_RATE, _ddc_decim);
 
     //set the scaling
     static const boost::int16_t default_rx_scale_iq = 1024;
-    this->poke(
-        offsetof(dsp_rx_regs_t, scale_iq) + DSP_RX_BASE,
+    this->poke(FR_DSP_RX_SCALE_IQ,
         calculate_iq_scale_word(default_rx_scale_iq, default_rx_scale_iq)
     );
 }
@@ -174,8 +170,7 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){
         ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0);
         ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0);
         _ddc_freq = new_freq; //shadow
-        this->poke( //set the cordic
-            offsetof(dsp_rx_regs_t, freq) + DSP_RX_BASE,
+        this->poke(FR_DSP_RX_FREQ,
             calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq())
         );
         return;
@@ -216,15 +211,10 @@ void usrp2_impl::update_duc_config(void){
     boost::int16_t scale = rint((4096*std::pow(2, ceil(log2(interp_cubed))))/(1.65*interp_cubed));
 
     //set the interpolation
-    this->poke(
-        offsetof(dsp_tx_regs_t, interp_rate) + DSP_TX_BASE, _ddc_decim
-    );
+    this->poke(FR_DSP_TX_INTERP_RATE, _ddc_decim);
 
     //set the scaling
-    this->poke(
-        offsetof(dsp_tx_regs_t, scale_iq) + DSP_TX_BASE,
-        calculate_iq_scale_word(scale, scale)
-    );
+    this->poke(FR_DSP_TX_SCALE_IQ, calculate_iq_scale_word(scale, scale));
 }
 
 /***********************************************************************
@@ -298,8 +288,7 @@ void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){
         ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0);
         ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0);
         _duc_freq = new_freq; //shadow
-        this->poke( //set the cordic
-            offsetof(dsp_tx_regs_t, freq) + DSP_TX_BASE,
+        this->poke(FR_DSP_TX_FREQ,
             calculate_freq_word_and_update_actual_freq(_duc_freq, get_master_clock_freq())
         );
         return;
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index eff53c5b2..7b658b22d 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -20,7 +20,6 @@
 #include <uhd/utils/assert.hpp>
 #include <uhd/types/mac_addr.hpp>
 #include <uhd/types/dict.hpp>
-#include <cstddef>
 
 using namespace uhd;
 
@@ -53,32 +52,32 @@ void usrp2_impl::update_clock_config(void){
 
     //translate pps source enums
     switch(_clock_config.pps_source){
-    case clock_config_t::PPS_SMA:  pps_flags |= PPS_FLAG_SMA;  break;
-    case clock_config_t::PPS_MIMO: pps_flags |= PPS_FLAG_MIMO; break;
+    case clock_config_t::PPS_SMA:  pps_flags |= FRF_TIME64_PPS_SMA;  break;
+    case clock_config_t::PPS_MIMO: pps_flags |= FRF_TIME64_PPS_MIMO; break;
     default: throw std::runtime_error("usrp2: unhandled clock configuration pps source");
     }
 
     //translate pps polarity enums
     switch(_clock_config.pps_polarity){
-    case clock_config_t::PPS_POS: pps_flags |= PPS_FLAG_POSEDGE; break;
-    case clock_config_t::PPS_NEG: pps_flags |= PPS_FLAG_NEGEDGE; break;
+    case clock_config_t::PPS_POS: pps_flags |= FRF_TIME64_PPS_POSEDGE; break;
+    case clock_config_t::PPS_NEG: pps_flags |= FRF_TIME64_PPS_NEGEDGE; break;
     default: throw std::runtime_error("usrp2: unhandled clock configuration pps polarity");
     }
 
     //set the pps flags
-    this->poke(offsetof(sr_time64_t, flags) + TIME64_BASE, pps_flags);
+    this->poke(FR_TIME64_FLAGS, pps_flags);
 
     //TODO clock source ref 10mhz (spi ad9510)
 }
 
 void usrp2_impl::set_time_spec(const time_spec_t &time_spec, bool now){
     //set ticks and seconds
-    this->poke(offsetof(sr_time64_t, secs) + TIME64_BASE, time_spec.secs);
-    this->poke(offsetof(sr_time64_t, ticks) + TIME64_BASE, time_spec.ticks);
+    this->poke(FR_TIME64_SECS, time_spec.secs);
+    this->poke(FR_TIME64_TICKS, time_spec.ticks);
 
     //set the register to latch it all in
-    boost::uint32_t imm_flags = (now)? TIME64_LATCH_NOW : TIME64_LATCH_NEXT_PPS;
-    this->poke(offsetof(sr_time64_t, imm) + TIME64_BASE, imm_flags);
+    boost::uint32_t imm_flags = (now)? FRF_TIME64_LATCH_NOW : FRF_TIME64_LATCH_NEXT_PPS;
+    this->poke(FR_TIME64_IMM, imm_flags);
 }
 
 /***********************************************************************
diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp
index b7fd239a6..10545d712 100644
--- a/host/lib/usrp/usrp2/usrp2_regs.hpp
+++ b/host/lib/usrp/usrp2/usrp2_regs.hpp
@@ -28,10 +28,10 @@
 
 
 #define MISC_OUTPUT_BASE        0xD400
-#define TX_PROTOCOL_ENGINE_BASE 0xD480
-#define RX_PROTOCOL_ENGINE_BASE 0xD4C0
-#define BUFFER_POOL_CTRL_BASE   0xD500
-#define LAST_SETTING_REG        0xD7FC  // last valid setting register
+//#define TX_PROTOCOL_ENGINE_BASE 0xD480
+//#define RX_PROTOCOL_ENGINE_BASE 0xD4C0
+//#define BUFFER_POOL_CTRL_BASE   0xD500
+//#define LAST_SETTING_REG        0xD7FC  // last valid setting register
 
 #define SR_MISC 0
 #define SR_TX_PROT_ENG 32
@@ -46,7 +46,7 @@
 #define SR_SIMTIMER 198
 #define SR_LAST 255
 
-#define _SR_ADDR(sr)    (MISC_OUTPUT_BASE + (sr) * sizeof(uint32_t))
+#define _SR_ADDR(sr)    (MISC_OUTPUT_BASE + (sr) * sizeof(boost::uint32_t))
 
 /////////////////////////////////////////////////
 // SPI Slave Constants
@@ -64,9 +64,6 @@
 /////////////////////////////////////////////////
 // VITA49 64 bit time (write only)
 ////////////////////////////////////////////////
-
-#define TIME64_BASE _SR_ADDR(SR_TIME64)
-
   /*!
    * \brief Time 64 flags
    *
@@ -83,34 +80,27 @@
    *
    * </pre>
    */
-typedef struct {
-    boost::uint32_t secs;   // value to set absolute secs to on next PPS
-    boost::uint32_t ticks;  // value to set absolute ticks to on next PPS
-    boost::uint32_t flags;  // flags - see chart above
-    boost::uint32_t imm;    // set immediate (0=latch on next pps, 1=latch immediate, default=0)
-} sr_time64_t;
+#define FR_TIME64_SECS  _SR_ADDR(SR_TIME64 + 0)  // value to set absolute secs to on next PPS
+#define FR_TIME64_TICKS _SR_ADDR(SR_TIME64 + 1)  // value to set absolute ticks to on next PPS
+#define FR_TIME64_FLAGS _SR_ADDR(SR_TIME64 + 2)  // flags - see chart above
+#define FR_TIME64_IMM   _SR_ADDR(SR_TIME64 + 3) // set immediate (0=latch on next pps, 1=latch immediate, default=0)
 
 //pps flags (see above)
-#define PPS_FLAG_NEGEDGE (0 << 0)
-#define PPS_FLAG_POSEDGE (1 << 0)
-#define PPS_FLAG_SMA     (0 << 1)
-#define PPS_FLAG_MIMO    (1 << 1)
+#define FRF_TIME64_PPS_NEGEDGE (0 << 0)
+#define FRF_TIME64_PPS_POSEDGE (1 << 0)
+#define FRF_TIME64_PPS_SMA     (0 << 1)
+#define FRF_TIME64_PPS_MIMO    (1 << 1)
 
-#define TIME64_LATCH_NOW 1
-#define TIME64_LATCH_NEXT_PPS 0
+#define FRF_TIME64_LATCH_NOW 1
+#define FRF_TIME64_LATCH_NEXT_PPS 0
 
 /////////////////////////////////////////////////
 // DSP TX Regs
 ////////////////////////////////////////////////
+#define FR_DSP_TX_FREQ         _SR_ADDR(SR_TX_DSP + 0)
+#define FR_DSP_TX_SCALE_IQ     _SR_ADDR(SR_TX_DSP + 1) // {scale_i,scale_q}
+#define FR_DSP_TX_INTERP_RATE  _SR_ADDR(SR_TX_DSP + 2)
 
-#define DSP_TX_BASE _SR_ADDR(SR_TX_DSP)
-
-typedef struct {
-    boost::int32_t      freq;
-    boost::uint32_t     scale_iq;       // {scale_i,scale_q}
-    boost::uint32_t     interp_rate;
-    boost::uint32_t     _padding0;      // padding for the tx_mux
-                                        //   NOT freq, scale, interp
   /*!
    * \brief output mux configuration.
    *
@@ -145,24 +135,17 @@ typedef struct {
    * The default value is 0x10
    * </pre>
    */
-    boost::uint32_t tx_mux;
-
-} dsp_tx_regs_t;
+#define FR_DSP_TX_MUX  _SR_ADDR(SR_TX_DSP + 4)
 
 /////////////////////////////////////////////////
 // DSP RX Regs
 ////////////////////////////////////////////////
-
-#define DSP_RX_BASE _SR_ADDR(SR_RX_DSP)
-
-typedef struct {
-    boost::int32_t      freq;
-    boost::uint32_t     scale_iq;       // {scale_i,scale_q}
-    boost::uint32_t     decim_rate;
-    boost::uint32_t     dcoffset_i;     // Bit 31 high sets fixed offset mode, using lower 14 bits,
-                                        // otherwise it is automatic 
-    boost::uint32_t     dcoffset_q;     // Bit 31 high sets fixed offset mode, using lower 14 bits
-
+#define FR_DSP_RX_FREQ         _SR_ADDR(SR_RX_DSP + 0)
+#define FR_DSP_RX_SCALE_IQ     _SR_ADDR(SR_RX_DSP + 1) // {scale_i,scale_q}
+#define FR_DSP_RX_DECIM_RATE   _SR_ADDR(SR_RX_DSP + 2)
+#define FR_DSP_RX_DCOFFSET_I   _SR_ADDR(SR_RX_DSP + 3) // Bit 31 high sets fixed offset mode, using lower 14 bits,
+                                                       // otherwise it is automatic 
+#define FR_DSP_RX_DCOFFSET_Q   _SR_ADDR(SR_RX_DSP + 4) // Bit 31 high sets fixed offset mode, using lower 14 bits
   /*!
    * \brief input mux configuration.
    *
@@ -184,42 +167,33 @@ typedef struct {
    * The default value is 0x4
    * </pre>
    */
-    boost::uint32_t     rx_mux;        // called adc_mux in dsp_core_rx.v
-
-} dsp_rx_regs_t;
+#define FR_DSP_RX_MUX  _SR_ADDR(SR_RX_DSP + 5)         // called adc_mux in dsp_core_rx.v
 
 ////////////////////////////////////////////////
 // GPIO, Slave 4
+////////////////////////////////////////////////
 //
 // These go to the daughterboard i/o pins
-
-#define GPIO_BASE 0xC800
-
-typedef struct {
-    boost::uint32_t    io;       // tx data in high 16, rx in low 16
-    boost::uint32_t    ddr;      // 32 bits, 1 means output. tx in high 16, rx in low 16
-    boost::uint32_t    tx_sel;   // 16 2-bit fields select which source goes to TX DB
-    boost::uint32_t    rx_sel;   // 16 2-bit fields select which source goes to RX DB
-} gpio_regs_t;
+//
+#define _FR_GPIO_ADDR(off) (0xC800 + (off) * sizeof(boost::uint32_t))
+#define FR_GPIO_IO     _FR_GPIO_ADDR(0)       // tx data in high 16, rx in low 16
+#define FR_GPIO_DDR    _FR_GPIO_ADDR(1)       // 32 bits, 1 means output. tx in high 16, rx in low 16
+#define FR_GPIO_TX_SEL _FR_GPIO_ADDR(2)       // 16 2-bit fields select which source goes to TX DB
+#define FR_GPIO_RX_SEL _FR_GPIO_ADDR(3)       // 16 2-bit fields select which source goes to RX DB
 
 // each 2-bit sel field is layed out this way
-#define GPIO_SEL_SW        0 // if pin is an output, set by software in the io reg
-#define GPIO_SEL_ATR       1 // if pin is an output, set by ATR logic
-#define GPIO_SEL_DEBUG_0   2 // if pin is an output, debug lines from FPGA fabric
-#define GPIO_SEL_DEBUG_1   3 // if pin is an output, debug lines from FPGA fabric
+#define FRF_GPIO_SEL_SW        0 // if pin is an output, set by software in the io reg
+#define FRF_GPIO_SEL_ATR       1 // if pin is an output, set by ATR logic
+#define FRF_GPIO_SEL_DEBUG_0   2 // if pin is an output, debug lines from FPGA fabric
+#define FRF_GPIO_SEL_DEBUG_1   3 // if pin is an output, debug lines from FPGA fabric
 
 ///////////////////////////////////////////////////
 // ATR Controller, Slave 11
-
-#define ATR_BASE  0xE400
-
-typedef struct {
-    boost::uint32_t v[16];
-} atr_regs_t;
-
-#define ATR_IDLE    0x0 // indicies into v
-#define ATR_TX      0x1
-#define ATR_RX      0x2
-#define ATR_FULL    0x3
+////////////////////////////////////////////////
+#define _FR_ATR_ADDR(off) (0xE400 + (off) * sizeof(boost::uint32_t))
+#define FR_ATR_IDLE    _FR_ATR_ADDR(0) // tx data in high 16, rx in low 16
+#define FR_ATR_TX      _FR_ATR_ADDR(1)
+#define FR_ATR_RX      _FR_ATR_ADDR(2)
+#define FR_ATR_FULL    _FR_ATR_ADDR(3)
 
 #endif /* INCLUDED_USRP2_REGS_HPP */
-- 
cgit v1.2.3


From 91ef18021c0f0f5fe8ff7705e23b5f1a6b25162f Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Thu, 1 Apr 2010 15:08:52 -0700
Subject: moved props into usrp and multiple hpp files

---
 host/examples/rx_timed_samples.cpp         |   1 -
 host/include/uhd/CMakeLists.txt            |   1 -
 host/include/uhd/props.hpp                 | 145 -----------------------------
 host/include/uhd/usrp/CMakeLists.txt       |  10 ++
 host/include/uhd/usrp/dboard_interface.hpp |   8 +-
 host/include/uhd/usrp/dboard_manager.hpp   |   2 +-
 host/include/uhd/usrp/dboard_props.hpp     |  38 ++++++++
 host/include/uhd/usrp/device_props.hpp     |  57 ++++++++++++
 host/include/uhd/usrp/dsp_props.hpp        |  40 ++++++++
 host/include/uhd/usrp/mboard_props.hpp     |  50 ++++++++++
 host/include/uhd/usrp/subdev_props.hpp     |  49 ++++++++++
 host/include/uhd/utils/CMakeLists.txt      |   1 +
 host/include/uhd/utils/props.hpp           |  48 ++++++++++
 host/lib/gain_handler.cpp                  |   2 +-
 host/lib/simple_device.cpp                 |   6 +-
 host/lib/tune_helper.cpp                   |   3 +-
 host/lib/usrp/dboard/db_basic_and_lf.cpp   |   2 +-
 host/lib/usrp/dboard_manager.cpp           |   1 +
 host/lib/usrp/usrp2/dboard_impl.cpp        |   2 +
 host/lib/usrp/usrp2/dboard_interface.cpp   |   4 +-
 host/lib/usrp/usrp2/dsp_impl.cpp           |   2 +
 host/lib/usrp/usrp2/mboard_impl.cpp        |   2 +
 host/lib/usrp/usrp2/usrp2_impl.cpp         |   1 +
 host/test/gain_handler_test.cpp            |   2 +-
 host/utils/uhd_find_devices.cpp            |   1 -
 host/utils/usrp2_burner.cpp                |   4 +-
 26 files changed, 320 insertions(+), 162 deletions(-)
 delete mode 100644 host/include/uhd/props.hpp
 create mode 100644 host/include/uhd/usrp/dboard_props.hpp
 create mode 100644 host/include/uhd/usrp/device_props.hpp
 create mode 100644 host/include/uhd/usrp/dsp_props.hpp
 create mode 100644 host/include/uhd/usrp/mboard_props.hpp
 create mode 100644 host/include/uhd/usrp/subdev_props.hpp
 create mode 100644 host/include/uhd/utils/props.hpp

(limited to 'host/lib')

diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp
index 88e112584..b3516e686 100644
--- a/host/examples/rx_timed_samples.cpp
+++ b/host/examples/rx_timed_samples.cpp
@@ -17,7 +17,6 @@
 
 #include <uhd/utils/safe_main.hpp>
 #include <uhd/simple_device.hpp>
-#include <uhd/props.hpp>
 #include <boost/program_options.hpp>
 #include <boost/format.hpp>
 #include <iostream>
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt
index b364f78cd..1c5202caa 100644
--- a/host/include/uhd/CMakeLists.txt
+++ b/host/include/uhd/CMakeLists.txt
@@ -24,7 +24,6 @@ ADD_SUBDIRECTORY(utils)
 INSTALL(FILES
     config.hpp
     device.hpp
-    props.hpp
     simple_device.hpp
     wax.hpp
     DESTINATION ${INCLUDE_DIR}/uhd
diff --git a/host/include/uhd/props.hpp b/host/include/uhd/props.hpp
deleted file mode 100644
index 01746f853..000000000
--- a/host/include/uhd/props.hpp
+++ /dev/null
@@ -1,145 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef INCLUDED_UHD_PROPS_HPP
-#define INCLUDED_UHD_PROPS_HPP
-
-#include <uhd/config.hpp>
-#include <uhd/wax.hpp>
-#include <boost/tuple/tuple.hpp>
-#include <vector>
-#include <string>
-
-namespace uhd{
-
-    //typedef for handling named properties
-    typedef std::vector<std::string> prop_names_t;
-    typedef boost::tuple<wax::obj, std::string> named_prop_t;
-
-    /*!
-     * Utility function to separate a named property into its components.
-     * \param key a reference to the prop object
-     * \param name a reference to the name object
-     */
-    inline UHD_API named_prop_t //must be exported as part of the api to work (TODO move guts to cpp file)
-    extract_named_prop(const wax::obj &key, const std::string &name = ""){
-        if (key.type() == typeid(named_prop_t)){
-            return key.as<named_prop_t>();
-        }
-        return named_prop_t(key, name);
-    }
-
-    /*!
-    * Possible device properties:
-    *   In general, a device will have a single mboard.
-    *   In certain mimo applications, multiple boards
-    *   will be present in the interface for configuration.
-    */
-    enum device_prop_t{
-        DEVICE_PROP_NAME,              //ro, std::string
-        DEVICE_PROP_MBOARD,            //ro, wax::obj
-        DEVICE_PROP_MBOARD_NAMES,      //ro, prop_names_t
-        DEVICE_PROP_MAX_RX_SAMPLES,    //ro, size_t
-        DEVICE_PROP_MAX_TX_SAMPLES     //ro, size_t
-    };
-
-    /*!
-    * Possible device mboard properties:
-    *   The general mboard properties are listed below.
-    *   Custom properties can be identified with a string
-    *   and discovered though the others property.
-    */
-    enum mboard_prop_t{
-        MBOARD_PROP_NAME,              //ro, std::string
-        MBOARD_PROP_OTHERS,            //ro, prop_names_t
-        MBOARD_PROP_CLOCK_RATE,        //ro, freq_t
-        MBOARD_PROP_RX_DSP,            //ro, wax::obj
-        MBOARD_PROP_RX_DSP_NAMES,      //ro, prop_names_t
-        MBOARD_PROP_TX_DSP,            //ro, wax::obj
-        MBOARD_PROP_TX_DSP_NAMES,      //ro, prop_names_t
-        MBOARD_PROP_RX_DBOARD,         //ro, wax::obj
-        MBOARD_PROP_RX_DBOARD_NAMES,   //ro, prop_names_t
-        MBOARD_PROP_TX_DBOARD,         //ro, wax::obj
-        MBOARD_PROP_TX_DBOARD_NAMES,   //ro, prop_names_t
-        MBOARD_PROP_CLOCK_CONFIG,      //rw, clock_config_t
-        MBOARD_PROP_TIME_NOW,          //wo, time_spec_t
-        MBOARD_PROP_TIME_NEXT_PPS      //wo, time_spec_t
-    };
-
-    /*!
-    * Possible device dsp properties:
-    *   A dsp can have a wide range of possible properties.
-    *   A ddc would have a properties "decim", "freq", "taps"...
-    *   Other properties could be gains, complex scalars, enables...
-    *   For this reason the only required properties of a dsp is a name
-    *   and a property to get list of other possible properties.
-    */
-    enum dsp_prop_t{
-        DSP_PROP_NAME,                 //ro, std::string
-        DSP_PROP_OTHERS                //ro, prop_names_t
-    };
-
-    /*!
-    * Possible device dboard properties
-    */
-    enum dboard_prop_t{
-        DBOARD_PROP_NAME,              //ro, std::string
-        DBOARD_PROP_SUBDEV,            //ro, wax::obj
-        DBOARD_PROP_SUBDEV_NAMES,      //ro, prop_names_t
-        DBOARD_PROP_USED_SUBDEVS       //ro, prop_names_t
-        //DBOARD_PROP_CODEC              //ro, wax::obj //----> not sure, dont have to deal with yet
-    }; 
-
-    /*! ------ not dealing with yet, commented out ------------
-    * Possible device codec properties:
-    *   A codec is expected to have a rate and gain elements.
-    *   Other properties can be discovered through the others prop.
-    */
-    /*enum codec_prop_t{
-        CODEC_PROP_NAME,               //ro, std::string
-        CODEC_PROP_OTHERS,             //ro, prop_names_t
-        CODEC_PROP_GAIN,               //rw, gain_t
-        CODEC_PROP_GAIN_RANGE,         //ro, gain_range_t
-        CODEC_PROP_GAIN_NAMES,         //ro, prop_names_t
-        //CODEC_PROP_CLOCK_RATE          //ro, freq_t //----> not sure we care to know
-    };*/
-
-    /*!
-    * Possible device subdev properties
-    */
-    enum subdev_prop_t{
-        SUBDEV_PROP_NAME,              //ro, std::string
-        SUBDEV_PROP_OTHERS,            //ro, prop_names_t
-        SUBDEV_PROP_GAIN,              //rw, gain_t
-        SUBDEV_PROP_GAIN_RANGE,        //ro, gain_range_t
-        SUBDEV_PROP_GAIN_NAMES,        //ro, prop_names_t
-        SUBDEV_PROP_FREQ,              //rw, freq_t
-        SUBDEV_PROP_FREQ_RANGE,        //ro, freq_range_t
-        SUBDEV_PROP_ANTENNA,           //rw, std::string
-        SUBDEV_PROP_ANTENNA_NAMES,     //ro, prop_names_t
-        SUBDEV_PROP_ENABLED,           //rw, bool
-        SUBDEV_PROP_QUADRATURE,        //ro, bool
-        SUBDEV_PROP_IQ_SWAPPED,        //ro, bool
-        SUBDEV_PROP_SPECTRUM_INVERTED, //ro, bool
-        SUBDEV_PROP_LO_INTERFERES      //ro, bool
-        //SUBDEV_PROP_RSSI,              //ro, gain_t //----> not on all boards, use named prop
-        //SUBDEV_PROP_BANDWIDTH          //rw, freq_t //----> not on all boards, use named prop
-    };
-
-} //namespace uhd
-
-#endif /* INCLUDED_UHD_PROPS_HPP */
diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt
index bab01fdeb..d0f385f13 100644
--- a/host/include/uhd/usrp/CMakeLists.txt
+++ b/host/include/uhd/usrp/CMakeLists.txt
@@ -17,10 +17,20 @@
 
 
 INSTALL(FILES
+    #### props headers ###
+    dboard_props.hpp
+    device_props.hpp
+    dsp_props.hpp
+    mboard_props.hpp
+    subdev_props.hpp
+
+    #### dboard headers ###
     dboard_base.hpp
     dboard_id.hpp
     dboard_interface.hpp
     dboard_manager.hpp
+
+    ### usrp headers ###
     usrp1e.hpp
     usrp2.hpp
     DESTINATION ${INCLUDE_DIR}/uhd/usrp
diff --git a/host/include/uhd/usrp/dboard_interface.hpp b/host/include/uhd/usrp/dboard_interface.hpp
index 8ff0c5d2f..b3bab131d 100644
--- a/host/include/uhd/usrp/dboard_interface.hpp
+++ b/host/include/uhd/usrp/dboard_interface.hpp
@@ -62,10 +62,10 @@ public:
 
     //possible atr registers
     enum atr_reg_t{
-        ATR_REG_IDLE   = 'i',
-        ATR_REG_TXONLY = 't',
-        ATR_REG_RXONLY = 'r',
-        ATR_REG_BOTH   = 'b'
+        ATR_REG_IDLE        = 'i',
+        ATR_REG_TX_ONLY     = 't',
+        ATR_REG_RX_ONLY     = 'r',
+        ATR_REG_FULL_DUPLEX = 'f'
     };
 
     //structors
diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp
index c7c091220..ed8ee73ef 100644
--- a/host/include/uhd/usrp/dboard_manager.hpp
+++ b/host/include/uhd/usrp/dboard_manager.hpp
@@ -19,7 +19,7 @@
 #define INCLUDED_UHD_USRP_DBOARD_MANAGER_HPP
 
 #include <uhd/config.hpp>
-#include <uhd/props.hpp>
+#include <uhd/utils/props.hpp>
 #include <uhd/usrp/dboard_base.hpp>
 #include <uhd/usrp/dboard_id.hpp>
 #include <boost/utility.hpp>
diff --git a/host/include/uhd/usrp/dboard_props.hpp b/host/include/uhd/usrp/dboard_props.hpp
new file mode 100644
index 000000000..08c4eef6a
--- /dev/null
+++ b/host/include/uhd/usrp/dboard_props.hpp
@@ -0,0 +1,38 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_DBOARD_PROPS_HPP
+#define INCLUDED_UHD_USRP_DBOARD_PROPS_HPP
+
+#include <uhd/utils/props.hpp>
+
+namespace uhd{ namespace usrp{
+
+    /*!
+     * Possible device dboard properties
+     */
+    enum dboard_prop_t{
+        DBOARD_PROP_NAME,              //ro, std::string
+        DBOARD_PROP_SUBDEV,            //ro, wax::obj
+        DBOARD_PROP_SUBDEV_NAMES,      //ro, prop_names_t
+        DBOARD_PROP_USED_SUBDEVS       //ro, prop_names_t
+        //DBOARD_PROP_CODEC              //ro, wax::obj //----> not sure, dont have to deal with yet
+    }; 
+
+}} //namespace
+
+#endif /* INCLUDED_UHD_USRP_DBOARD_PROPS_HPP */
diff --git a/host/include/uhd/usrp/device_props.hpp b/host/include/uhd/usrp/device_props.hpp
new file mode 100644
index 000000000..dcfa26240
--- /dev/null
+++ b/host/include/uhd/usrp/device_props.hpp
@@ -0,0 +1,57 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_DEVICE_PROPS_HPP
+#define INCLUDED_UHD_USRP_DEVICE_PROPS_HPP
+
+#include <uhd/utils/props.hpp>
+
+namespace uhd{ namespace usrp{
+
+    /*!
+     * Possible device properties:
+     *   In general, a device will have a single mboard.
+     *   In certain mimo applications, multiple boards
+     *   will be present in the interface for configuration.
+     */
+    enum device_prop_t{
+        DEVICE_PROP_NAME,              //ro, std::string
+        DEVICE_PROP_MBOARD,            //ro, wax::obj
+        DEVICE_PROP_MBOARD_NAMES,      //ro, prop_names_t
+        DEVICE_PROP_MAX_RX_SAMPLES,    //ro, size_t
+        DEVICE_PROP_MAX_TX_SAMPLES     //ro, size_t
+    };
+
+    ////////////////////////////////////////////////////////////////////////
+    /*! ------ not dealing with yet, commented out ------------
+    * Possible device codec properties:
+    *   A codec is expected to have a rate and gain elements.
+    *   Other properties can be discovered through the others prop.
+    */
+    /*enum codec_prop_t{
+        CODEC_PROP_NAME,               //ro, std::string
+        CODEC_PROP_OTHERS,             //ro, prop_names_t
+        CODEC_PROP_GAIN,               //rw, gain_t
+        CODEC_PROP_GAIN_RANGE,         //ro, gain_range_t
+        CODEC_PROP_GAIN_NAMES,         //ro, prop_names_t
+        //CODEC_PROP_CLOCK_RATE          //ro, freq_t //----> not sure we care to know
+    };*/
+
+
+}} //namespace
+
+#endif /* INCLUDED_UHD_USRP_DEVICE_PROPS_HPP */
diff --git a/host/include/uhd/usrp/dsp_props.hpp b/host/include/uhd/usrp/dsp_props.hpp
new file mode 100644
index 000000000..ef3f771df
--- /dev/null
+++ b/host/include/uhd/usrp/dsp_props.hpp
@@ -0,0 +1,40 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_DSP_PROPS_HPP
+#define INCLUDED_UHD_USRP_DSP_PROPS_HPP
+
+#include <uhd/utils/props.hpp>
+
+namespace uhd{ namespace usrp{
+
+    /*!
+     * Possible device dsp properties:
+     *   A dsp can have a wide range of possible properties.
+     *   A ddc would have a properties "decim", "freq", "taps"...
+     *   Other properties could be gains, complex scalars, enables...
+     *   For this reason the only required properties of a dsp is a name
+     *   and a property to get list of other possible properties.
+     */
+    enum dsp_prop_t{
+        DSP_PROP_NAME,                 //ro, std::string
+        DSP_PROP_OTHERS                //ro, prop_names_t
+    };
+
+}} //namespace
+
+#endif /* INCLUDED_UHD_USRP_DSP_PROPS_HPP */
diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp
new file mode 100644
index 000000000..ddb95ef0d
--- /dev/null
+++ b/host/include/uhd/usrp/mboard_props.hpp
@@ -0,0 +1,50 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_MBOARD_PROPS_HPP
+#define INCLUDED_UHD_USRP_MBOARD_PROPS_HPP
+
+#include <uhd/utils/props.hpp>
+
+namespace uhd{ namespace usrp{
+
+    /*!
+     * Possible device mboard properties:
+     *   The general mboard properties are listed below.
+     *   Custom properties can be identified with a string
+     *   and discovered though the others property.
+     */
+    enum mboard_prop_t{
+        MBOARD_PROP_NAME,              //ro, std::string
+        MBOARD_PROP_OTHERS,            //ro, prop_names_t
+        MBOARD_PROP_CLOCK_RATE,        //ro, double
+        MBOARD_PROP_RX_DSP,            //ro, wax::obj
+        MBOARD_PROP_RX_DSP_NAMES,      //ro, prop_names_t
+        MBOARD_PROP_TX_DSP,            //ro, wax::obj
+        MBOARD_PROP_TX_DSP_NAMES,      //ro, prop_names_t
+        MBOARD_PROP_RX_DBOARD,         //ro, wax::obj
+        MBOARD_PROP_RX_DBOARD_NAMES,   //ro, prop_names_t
+        MBOARD_PROP_TX_DBOARD,         //ro, wax::obj
+        MBOARD_PROP_TX_DBOARD_NAMES,   //ro, prop_names_t
+        MBOARD_PROP_CLOCK_CONFIG,      //rw, clock_config_t
+        MBOARD_PROP_TIME_NOW,          //wo, time_spec_t
+        MBOARD_PROP_TIME_NEXT_PPS      //wo, time_spec_t
+    };
+
+}} //namespace
+
+#endif /* INCLUDED_UHD_USRP_MBOARD_PROPS_HPP */
diff --git a/host/include/uhd/usrp/subdev_props.hpp b/host/include/uhd/usrp/subdev_props.hpp
new file mode 100644
index 000000000..667f34f9c
--- /dev/null
+++ b/host/include/uhd/usrp/subdev_props.hpp
@@ -0,0 +1,49 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_SUBDEV_PROPS_HPP
+#define INCLUDED_UHD_USRP_SUBDEV_PROPS_HPP
+
+#include <uhd/utils/props.hpp>
+
+namespace uhd{ namespace usrp{
+
+    /*!
+     * Possible device subdev properties
+     */
+    enum subdev_prop_t{
+        SUBDEV_PROP_NAME,              //ro, std::string
+        SUBDEV_PROP_OTHERS,            //ro, prop_names_t
+        SUBDEV_PROP_GAIN,              //rw, float
+        SUBDEV_PROP_GAIN_RANGE,        //ro, gain_range_t
+        SUBDEV_PROP_GAIN_NAMES,        //ro, prop_names_t
+        SUBDEV_PROP_FREQ,              //rw, double
+        SUBDEV_PROP_FREQ_RANGE,        //ro, freq_range_t
+        SUBDEV_PROP_ANTENNA,           //rw, std::string
+        SUBDEV_PROP_ANTENNA_NAMES,     //ro, prop_names_t
+        SUBDEV_PROP_ENABLED,           //rw, bool
+        SUBDEV_PROP_QUADRATURE,        //ro, bool
+        SUBDEV_PROP_IQ_SWAPPED,        //ro, bool
+        SUBDEV_PROP_SPECTRUM_INVERTED, //ro, bool
+        SUBDEV_PROP_LO_INTERFERES      //ro, bool
+        //SUBDEV_PROP_RSSI,              //ro, float //----> not on all boards, use named prop
+        //SUBDEV_PROP_BANDWIDTH          //rw, double //----> not on all boards, use named prop
+    };
+
+}} //namespace
+
+#endif /* INCLUDED_UHD_USRP_SUBDEV_PROPS_HPP */
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt
index 1b673f44a..2bb72e31d 100644
--- a/host/include/uhd/utils/CMakeLists.txt
+++ b/host/include/uhd/utils/CMakeLists.txt
@@ -19,6 +19,7 @@ INSTALL(FILES
     algorithm.hpp
     assert.hpp
     gain_handler.hpp
+    props.hpp
     safe_main.hpp
     static.hpp
     tune_helper.hpp
diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp
new file mode 100644
index 000000000..fdbc17d1c
--- /dev/null
+++ b/host/include/uhd/utils/props.hpp
@@ -0,0 +1,48 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_PROPS_COMMON_HPP
+#define INCLUDED_UHD_USRP_PROPS_COMMON_HPP
+
+#include <uhd/config.hpp>
+#include <uhd/wax.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <vector>
+#include <string>
+
+namespace uhd{
+
+    //typedef for handling named properties
+    typedef std::vector<std::string> prop_names_t;
+    typedef boost::tuple<wax::obj, std::string> named_prop_t;
+
+    /*!
+     * Utility function to separate a named property into its components.
+     * \param key a reference to the prop object
+     * \param name a reference to the name object
+     */
+    inline UHD_API named_prop_t //must be exported as part of the api to work (TODO move guts to cpp file)
+    extract_named_prop(const wax::obj &key, const std::string &name = ""){
+        if (key.type() == typeid(named_prop_t)){
+            return key.as<named_prop_t>();
+        }
+        return named_prop_t(key, name);
+    }
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_USRP_PROPS_COMMON_HPP */
diff --git a/host/lib/gain_handler.cpp b/host/lib/gain_handler.cpp
index daf629f0b..36e2e8ed3 100644
--- a/host/lib/gain_handler.cpp
+++ b/host/lib/gain_handler.cpp
@@ -18,7 +18,7 @@
 #include <uhd/utils/gain_handler.hpp>
 #include <uhd/utils/assert.hpp>
 #include <uhd/types/ranges.hpp>
-#include <uhd/props.hpp>
+#include <uhd/utils/props.hpp>
 #include <boost/assign/list_of.hpp>
 #include <boost/foreach.hpp>
 #include <boost/format.hpp>
diff --git a/host/lib/simple_device.cpp b/host/lib/simple_device.cpp
index 25beb45a9..801516353 100644
--- a/host/lib/simple_device.cpp
+++ b/host/lib/simple_device.cpp
@@ -18,12 +18,16 @@
 #include <uhd/simple_device.hpp>
 #include <uhd/utils/tune_helper.hpp>
 #include <uhd/utils/assert.hpp>
-#include <uhd/props.hpp>
+#include <uhd/usrp/subdev_props.hpp>
+#include <uhd/usrp/mboard_props.hpp>
+#include <uhd/usrp/device_props.hpp>
+#include <uhd/usrp/dboard_props.hpp>
 #include <boost/foreach.hpp>
 #include <boost/format.hpp>
 #include <stdexcept>
 
 using namespace uhd;
+using namespace uhd::usrp;
 
 /***********************************************************************
  * Helper Functions
diff --git a/host/lib/tune_helper.cpp b/host/lib/tune_helper.cpp
index 1e5c4cd0d..381685578 100644
--- a/host/lib/tune_helper.cpp
+++ b/host/lib/tune_helper.cpp
@@ -17,10 +17,11 @@
 
 #include <uhd/utils/tune_helper.hpp>
 #include <uhd/utils/algorithm.hpp>
-#include <uhd/props.hpp>
+#include <uhd/usrp/subdev_props.hpp>
 #include <cmath>
 
 using namespace uhd;
+using namespace uhd::usrp;
 
 /***********************************************************************
  * Tune Helper Function
diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp
index 977eb3d49..be4e646ed 100644
--- a/host/lib/usrp/dboard/db_basic_and_lf.cpp
+++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp
@@ -15,7 +15,7 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
-#include <uhd/props.hpp>
+#include <uhd/usrp/subdev_props.hpp>
 #include <uhd/types/ranges.hpp>
 #include <uhd/utils/assert.hpp>
 #include <uhd/utils/static.hpp>
diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp
index 5c063d51d..3a5cf3a35 100644
--- a/host/lib/usrp/dboard_manager.cpp
+++ b/host/lib/usrp/dboard_manager.cpp
@@ -16,6 +16,7 @@
 //
 
 #include <uhd/usrp/dboard_manager.hpp>
+#include <uhd/usrp/subdev_props.hpp>
 #include <uhd/utils/gain_handler.hpp>
 #include <uhd/utils/static.hpp>
 #include <uhd/utils/assert.hpp>
diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp
index 29fb32eeb..30883cd50 100644
--- a/host/lib/usrp/usrp2/dboard_impl.cpp
+++ b/host/lib/usrp/usrp2/dboard_impl.cpp
@@ -18,6 +18,8 @@
 
 #include "usrp2_impl.hpp"
 #include "usrp2_regs.hpp"
+#include <uhd/usrp/subdev_props.hpp>
+#include <uhd/usrp/dboard_props.hpp>
 #include <uhd/utils/assert.hpp>
 #include <boost/format.hpp>
 
diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp
index 4160ad467..dcd6453a8 100644
--- a/host/lib/usrp/usrp2/dboard_interface.cpp
+++ b/host/lib/usrp/usrp2/dboard_interface.cpp
@@ -114,8 +114,8 @@ boost::uint16_t usrp2_dboard_interface::read_gpio(gpio_bank_t bank){
 void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t reg, boost::uint16_t value){
     //map the atr reg to an offset in register space
     static const uhd::dict<atr_reg_t, int> reg_to_addr = boost::assign::map_list_of
-        (ATR_REG_IDLE, FR_ATR_IDLE) (ATR_REG_TXONLY, FR_ATR_TX)
-        (ATR_REG_RXONLY, FR_ATR_RX) (ATR_REG_BOTH, FR_ATR_FULL)
+        (ATR_REG_IDLE, FR_ATR_IDLE) (ATR_REG_TX_ONLY, FR_ATR_TX)
+        (ATR_REG_RX_ONLY, FR_ATR_RX) (ATR_REG_FULL_DUPLEX, FR_ATR_FULL)
     ;
     ASSERT_THROW(reg_to_addr.has_key(reg));
 
diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp
index d50c1ad56..d70248682 100644
--- a/host/lib/usrp/usrp2/dsp_impl.cpp
+++ b/host/lib/usrp/usrp2/dsp_impl.cpp
@@ -17,12 +17,14 @@
 
 #include "usrp2_impl.hpp"
 #include "usrp2_regs.hpp"
+#include <uhd/usrp/dsp_props.hpp>
 #include <uhd/utils/assert.hpp>
 #include <boost/format.hpp>
 #include <boost/assign/list_of.hpp>
 #include <boost/math/special_functions/round.hpp>
 
 using namespace uhd;
+using namespace uhd::usrp;
 
 static const size_t default_decim = 16;
 static const size_t default_interp = 16;
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index 7b658b22d..7594c85fa 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -17,11 +17,13 @@
 
 #include "usrp2_impl.hpp"
 #include "usrp2_regs.hpp"
+#include <uhd/usrp/mboard_props.hpp>
 #include <uhd/utils/assert.hpp>
 #include <uhd/types/mac_addr.hpp>
 #include <uhd/types/dict.hpp>
 
 using namespace uhd;
+using namespace uhd::usrp;
 
 /***********************************************************************
  * Helper Methods
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index e89fe8a63..b3a22e175 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -16,6 +16,7 @@
 //
 
 #include <uhd/transport/if_addrs.hpp>
+#include <uhd/usrp/device_props.hpp>
 #include <uhd/utils/assert.hpp>
 #include <uhd/utils/static.hpp>
 #include <boost/format.hpp>
diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp
index 76b065ce2..72d26e1c2 100644
--- a/host/test/gain_handler_test.cpp
+++ b/host/test/gain_handler_test.cpp
@@ -19,7 +19,7 @@
 #include <uhd/utils/gain_handler.hpp>
 #include <uhd/types/ranges.hpp>
 #include <uhd/types/dict.hpp>
-#include <uhd/props.hpp>
+#include <uhd/utils/props.hpp>
 #include <boost/bind.hpp>
 #include <iostream>
 
diff --git a/host/utils/uhd_find_devices.cpp b/host/utils/uhd_find_devices.cpp
index b328216d0..6c945cbca 100644
--- a/host/utils/uhd_find_devices.cpp
+++ b/host/utils/uhd_find_devices.cpp
@@ -17,7 +17,6 @@
 
 #include <uhd/utils/safe_main.hpp>
 #include <uhd/device.hpp>
-#include <uhd/props.hpp>
 #include <boost/program_options.hpp>
 #include <boost/format.hpp>
 #include <iostream>
diff --git a/host/utils/usrp2_burner.cpp b/host/utils/usrp2_burner.cpp
index b24425316..9c1bf72fe 100644
--- a/host/utils/usrp2_burner.cpp
+++ b/host/utils/usrp2_burner.cpp
@@ -17,7 +17,7 @@
 
 #include <uhd/utils/safe_main.hpp>
 #include <uhd/usrp/usrp2.hpp>
-#include <uhd/props.hpp>
+#include <uhd/usrp/device_props.hpp>
 #include <boost/program_options.hpp>
 #include <boost/format.hpp>
 #include <iostream>
@@ -56,7 +56,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
     //create a usrp2 device
     uhd::device::sptr u2_dev = uhd::usrp::usrp2::make(device_addr);
     //FIXME usees the default mboard for now (until the mimo link is supported)
-    wax::obj u2_mb = (*u2_dev)[uhd::DEVICE_PROP_MBOARD];
+    wax::obj u2_mb = (*u2_dev)[uhd::usrp::DEVICE_PROP_MBOARD];
     std::cout << std::endl;
 
     //fetch and print current settings
-- 
cgit v1.2.3


From 54e8b566f6d1efecfd5fdc2c14bb287fd551089e Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Thu, 1 Apr 2010 16:01:46 -0700
Subject: Moved usrp specific things into usrp directories and namespaces.

Renamed simple device to simple usrp (it was usrp specific).
Moved tune helper to usrp dir for same reason.
---
 host/examples/rx_timed_samples.cpp     |   4 +-
 host/include/uhd/CMakeLists.txt        |   1 -
 host/include/uhd/simple_device.hpp     |  97 ---------------
 host/include/uhd/usrp/CMakeLists.txt   |   5 +
 host/include/uhd/usrp/simple_usrp.hpp  |  97 +++++++++++++++
 host/include/uhd/usrp/tune_helper.hpp  |  79 +++++++++++++
 host/include/uhd/utils/CMakeLists.txt  |   1 -
 host/include/uhd/utils/props.hpp       |   6 +-
 host/include/uhd/utils/tune_helper.hpp |  79 -------------
 host/lib/CMakeLists.txt                |   4 +-
 host/lib/simple_device.cpp             | 207 ---------------------------------
 host/lib/tune_helper.cpp               | 126 --------------------
 host/lib/usrp/simple_usrp.cpp          | 207 +++++++++++++++++++++++++++++++++
 host/lib/usrp/tune_helper.cpp          | 126 ++++++++++++++++++++
 14 files changed, 521 insertions(+), 518 deletions(-)
 delete mode 100644 host/include/uhd/simple_device.hpp
 create mode 100644 host/include/uhd/usrp/simple_usrp.hpp
 create mode 100644 host/include/uhd/usrp/tune_helper.hpp
 delete mode 100644 host/include/uhd/utils/tune_helper.hpp
 delete mode 100644 host/lib/simple_device.cpp
 delete mode 100644 host/lib/tune_helper.cpp
 create mode 100644 host/lib/usrp/simple_usrp.cpp
 create mode 100644 host/lib/usrp/tune_helper.cpp

(limited to 'host/lib')

diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp
index b3516e686..58b5af9da 100644
--- a/host/examples/rx_timed_samples.cpp
+++ b/host/examples/rx_timed_samples.cpp
@@ -16,7 +16,7 @@
 //
 
 #include <uhd/utils/safe_main.hpp>
-#include <uhd/simple_device.hpp>
+#include <uhd/usrp/simple_usrp.hpp>
 #include <boost/program_options.hpp>
 #include <boost/format.hpp>
 #include <iostream>
@@ -52,7 +52,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
     std::cout << std::endl;
     std::cout << boost::format("Creating the usrp device with: %s...")
         % transport_args << std::endl;
-    uhd::simple_device::sptr sdev = uhd::simple_device::make(transport_args);
+    uhd::usrp::simple_usrp::sptr sdev = uhd::usrp::simple_usrp::make(transport_args);
     uhd::device::sptr dev = sdev->get_device();
     std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl;
 
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt
index 1c5202caa..d63062032 100644
--- a/host/include/uhd/CMakeLists.txt
+++ b/host/include/uhd/CMakeLists.txt
@@ -24,7 +24,6 @@ ADD_SUBDIRECTORY(utils)
 INSTALL(FILES
     config.hpp
     device.hpp
-    simple_device.hpp
     wax.hpp
     DESTINATION ${INCLUDE_DIR}/uhd
 )
diff --git a/host/include/uhd/simple_device.hpp b/host/include/uhd/simple_device.hpp
deleted file mode 100644
index 52928367a..000000000
--- a/host/include/uhd/simple_device.hpp
+++ /dev/null
@@ -1,97 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef INCLUDED_UHD_SIMPLE_DEVICE_HPP
-#define INCLUDED_UHD_SIMPLE_DEVICE_HPP
-
-#include <uhd/config.hpp>
-#include <uhd/device.hpp>
-#include <uhd/types/ranges.hpp>
-#include <uhd/types/stream_cmd.hpp>
-#include <uhd/types/tune_result.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/utility.hpp>
-#include <vector>
-
-namespace uhd{
-
-/*!
- * The simple UHD device class:
- * A simple device facilitates ease-of-use for most use-case scenarios.
- * The wrapper provides convenience functions to tune the devices
- * as well as to set the dboard gains, antennas, and other properties.
- */
-class UHD_API simple_device : boost::noncopyable{
-public:
-    typedef boost::shared_ptr<simple_device> sptr;
-    static sptr make(const std::string &args);
-
-    virtual device::sptr get_device(void) = 0;
-
-    virtual std::string get_name(void) = 0;
-
-    /*******************************************************************
-     * Timing
-     ******************************************************************/
-    virtual void set_time_now(const time_spec_t &time_spec) = 0;
-    virtual void set_time_next_pps(const time_spec_t &time_spec) = 0;
-
-    /*******************************************************************
-     * Streaming
-     ******************************************************************/
-    virtual void issue_stream_cmd(const stream_cmd_t &stream_cmd) = 0;
-
-    /*******************************************************************
-     * RX methods
-     ******************************************************************/
-    virtual void set_rx_rate(double rate) = 0;
-    virtual double get_rx_rate(void) = 0;
-    virtual std::vector<double> get_rx_rates(void) = 0;
-
-    virtual tune_result_t set_rx_freq(double freq) = 0;
-    virtual freq_range_t get_rx_freq_range(void) = 0;
-
-    virtual void set_rx_gain(float gain) = 0;
-    virtual float get_rx_gain(void) = 0;
-    virtual gain_range_t get_rx_gain_range(void) = 0;
-
-    virtual void set_rx_antenna(const std::string &ant) = 0;
-    virtual std::string get_rx_antenna(void) = 0;
-    virtual std::vector<std::string> get_rx_antennas(void) = 0;
-
-    /*******************************************************************
-     * TX methods
-     ******************************************************************/
-    virtual void set_tx_rate(double rate) = 0;
-    virtual double get_tx_rate(void) = 0;
-    virtual std::vector<double> get_tx_rates(void) = 0;
-
-    virtual tune_result_t set_tx_freq(double freq) = 0;
-    virtual freq_range_t get_tx_freq_range(void) = 0;
-
-    virtual void set_tx_gain(float gain) = 0;
-    virtual float get_tx_gain(void) = 0;
-    virtual gain_range_t get_tx_gain_range(void) = 0;
-
-    virtual void set_tx_antenna(const std::string &ant) = 0;
-    virtual std::string get_tx_antenna(void) = 0;
-    virtual std::vector<std::string> get_tx_antennas(void) = 0;
-};
-
-} //namespace uhd
-
-#endif /* INCLUDED_UHD_SIMPLE_DEVICE_HPP */
diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt
index d0f385f13..7815a4fb9 100644
--- a/host/include/uhd/usrp/CMakeLists.txt
+++ b/host/include/uhd/usrp/CMakeLists.txt
@@ -33,5 +33,10 @@ INSTALL(FILES
     ### usrp headers ###
     usrp1e.hpp
     usrp2.hpp
+
+    ### utilities ###
+    tune_helper.hpp
+    simple_usrp.hpp
+
     DESTINATION ${INCLUDE_DIR}/uhd/usrp
 )
diff --git a/host/include/uhd/usrp/simple_usrp.hpp b/host/include/uhd/usrp/simple_usrp.hpp
new file mode 100644
index 000000000..dea1cabda
--- /dev/null
+++ b/host/include/uhd/usrp/simple_usrp.hpp
@@ -0,0 +1,97 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_SIMPLE_USRP_HPP
+#define INCLUDED_UHD_USRP_SIMPLE_USRP_HPP
+
+#include <uhd/config.hpp>
+#include <uhd/device.hpp>
+#include <uhd/types/ranges.hpp>
+#include <uhd/types/stream_cmd.hpp>
+#include <uhd/types/tune_result.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/utility.hpp>
+#include <vector>
+
+namespace uhd{ namespace usrp{
+
+/*!
+ * The simple USRP device class:
+ * A simple usrp facilitates ease-of-use for most use-case scenarios.
+ * The wrapper provides convenience functions to tune the devices
+ * as well as to set the dboard gains, antennas, and other properties.
+ */
+class UHD_API simple_usrp : boost::noncopyable{
+public:
+    typedef boost::shared_ptr<simple_usrp> sptr;
+    static sptr make(const std::string &args);
+
+    virtual device::sptr get_device(void) = 0;
+
+    virtual std::string get_name(void) = 0;
+
+    /*******************************************************************
+     * Timing
+     ******************************************************************/
+    virtual void set_time_now(const time_spec_t &time_spec) = 0;
+    virtual void set_time_next_pps(const time_spec_t &time_spec) = 0;
+
+    /*******************************************************************
+     * Streaming
+     ******************************************************************/
+    virtual void issue_stream_cmd(const stream_cmd_t &stream_cmd) = 0;
+
+    /*******************************************************************
+     * RX methods
+     ******************************************************************/
+    virtual void set_rx_rate(double rate) = 0;
+    virtual double get_rx_rate(void) = 0;
+    virtual std::vector<double> get_rx_rates(void) = 0;
+
+    virtual tune_result_t set_rx_freq(double freq) = 0;
+    virtual freq_range_t get_rx_freq_range(void) = 0;
+
+    virtual void set_rx_gain(float gain) = 0;
+    virtual float get_rx_gain(void) = 0;
+    virtual gain_range_t get_rx_gain_range(void) = 0;
+
+    virtual void set_rx_antenna(const std::string &ant) = 0;
+    virtual std::string get_rx_antenna(void) = 0;
+    virtual std::vector<std::string> get_rx_antennas(void) = 0;
+
+    /*******************************************************************
+     * TX methods
+     ******************************************************************/
+    virtual void set_tx_rate(double rate) = 0;
+    virtual double get_tx_rate(void) = 0;
+    virtual std::vector<double> get_tx_rates(void) = 0;
+
+    virtual tune_result_t set_tx_freq(double freq) = 0;
+    virtual freq_range_t get_tx_freq_range(void) = 0;
+
+    virtual void set_tx_gain(float gain) = 0;
+    virtual float get_tx_gain(void) = 0;
+    virtual gain_range_t get_tx_gain_range(void) = 0;
+
+    virtual void set_tx_antenna(const std::string &ant) = 0;
+    virtual std::string get_tx_antenna(void) = 0;
+    virtual std::vector<std::string> get_tx_antennas(void) = 0;
+};
+
+}}
+
+#endif /* INCLUDED_UHD_USRP_SIMPLE_USRP_HPP */
diff --git a/host/include/uhd/usrp/tune_helper.hpp b/host/include/uhd/usrp/tune_helper.hpp
new file mode 100644
index 000000000..f1e276d4f
--- /dev/null
+++ b/host/include/uhd/usrp/tune_helper.hpp
@@ -0,0 +1,79 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_TUNE_HELPER_HPP
+#define INCLUDED_UHD_USRP_TUNE_HELPER_HPP
+
+#include <uhd/config.hpp>
+#include <uhd/wax.hpp>
+#include <uhd/types/tune_result.hpp>
+
+namespace uhd{ namespace usrp{
+
+/*!
+ * Tune a rx chain to the desired frequency:
+ * The IF of the subdevice is set as close as possible to
+ * the given target frequency + the LO offset (when applicable).
+ * The ddc cordic is setup to bring the IF down to baseband.
+ * \param subdev the dboard subdevice object with properties
+ * \param ddc the ddc properties object (with "if_rate", "bb_rate", "freq")
+ * \param target_freq the desired center frequency
+ * \param lo_offset an offset for the subdevice IF from center
+ * \return a tune result struct
+ */
+UHD_API tune_result_t tune_rx_subdev_and_ddc(
+    wax::obj subdev, wax::obj ddc,
+    double target_freq, double lo_offset
+);
+
+/*!
+ * Tune a rx chain to the desired frequency:
+ * Same as the above, except the LO offset
+ * is calculated based on the subdevice and BW.
+ */
+UHD_API tune_result_t tune_rx_subdev_and_ddc(
+    wax::obj subdev, wax::obj ddc, double target_freq
+);
+
+/*!
+ * Tune a tx chain to the desired frequency:
+ * The IF of the subdevice is set as close as possible to
+ * the given target frequency + the LO offset (when applicable).
+ * The duc cordic is setup to bring the baseband up to IF.
+ * \param subdev the dboard subdevice object with properties
+ * \param duc the duc properties object (with "if_rate", "bb_rate", "freq")
+ * \param target_freq the desired center frequency
+ * \param lo_offset an offset for the subdevice IF from center
+ * \return a tune result struct
+ */
+UHD_API tune_result_t tune_tx_subdev_and_duc(
+    wax::obj subdev, wax::obj duc,
+    double target_freq, double lo_offset
+);
+
+/*!
+ * Tune a tx chain to the desired frequency:
+ * Same as the above, except the LO offset
+ * is calculated based on the subdevice and BW.
+ */
+UHD_API tune_result_t tune_tx_subdev_and_duc(
+    wax::obj subdev, wax::obj duc, double target_freq
+);
+
+}}
+
+#endif /* INCLUDED_UHD_USRP_TUNE_HELPER_HPP */
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt
index 2bb72e31d..2831ab0b0 100644
--- a/host/include/uhd/utils/CMakeLists.txt
+++ b/host/include/uhd/utils/CMakeLists.txt
@@ -22,6 +22,5 @@ INSTALL(FILES
     props.hpp
     safe_main.hpp
     static.hpp
-    tune_helper.hpp
     DESTINATION ${INCLUDE_DIR}/uhd/utils
 )
diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp
index fdbc17d1c..6be0b2ce5 100644
--- a/host/include/uhd/utils/props.hpp
+++ b/host/include/uhd/utils/props.hpp
@@ -15,8 +15,8 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
-#ifndef INCLUDED_UHD_USRP_PROPS_COMMON_HPP
-#define INCLUDED_UHD_USRP_PROPS_COMMON_HPP
+#ifndef INCLUDED_UHD_UTILS_PROPS_HPP
+#define INCLUDED_UHD_UTILS_PROPS_HPP
 
 #include <uhd/config.hpp>
 #include <uhd/wax.hpp>
@@ -45,4 +45,4 @@ namespace uhd{
 
 } //namespace uhd
 
-#endif /* INCLUDED_UHD_USRP_PROPS_COMMON_HPP */
+#endif /* INCLUDED_UHD_UTILS_PROPS_HPP */
diff --git a/host/include/uhd/utils/tune_helper.hpp b/host/include/uhd/utils/tune_helper.hpp
deleted file mode 100644
index 958d1eceb..000000000
--- a/host/include/uhd/utils/tune_helper.hpp
+++ /dev/null
@@ -1,79 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef INCLUDED_UHD_UTILS_TUNE_HELPER_HPP
-#define INCLUDED_UHD_UTILS_TUNE_HELPER_HPP
-
-#include <uhd/config.hpp>
-#include <uhd/wax.hpp>
-#include <uhd/types/tune_result.hpp>
-
-namespace uhd{
-
-/*!
- * Tune a rx chain to the desired frequency:
- * The IF of the subdevice is set as close as possible to
- * the given target frequency + the LO offset (when applicable).
- * The ddc cordic is setup to bring the IF down to baseband.
- * \param subdev the dboard subdevice object with properties
- * \param ddc the ddc properties object (with "if_rate", "bb_rate", "freq")
- * \param target_freq the desired center frequency
- * \param lo_offset an offset for the subdevice IF from center
- * \return a tune result struct
- */
-UHD_API tune_result_t tune_rx_subdev_and_ddc(
-    wax::obj subdev, wax::obj ddc,
-    double target_freq, double lo_offset
-);
-
-/*!
- * Tune a rx chain to the desired frequency:
- * Same as the above, except the LO offset
- * is calculated based on the subdevice and BW.
- */
-UHD_API tune_result_t tune_rx_subdev_and_ddc(
-    wax::obj subdev, wax::obj ddc, double target_freq
-);
-
-/*!
- * Tune a tx chain to the desired frequency:
- * The IF of the subdevice is set as close as possible to
- * the given target frequency + the LO offset (when applicable).
- * The duc cordic is setup to bring the baseband up to IF.
- * \param subdev the dboard subdevice object with properties
- * \param duc the duc properties object (with "if_rate", "bb_rate", "freq")
- * \param target_freq the desired center frequency
- * \param lo_offset an offset for the subdevice IF from center
- * \return a tune result struct
- */
-UHD_API tune_result_t tune_tx_subdev_and_duc(
-    wax::obj subdev, wax::obj duc,
-    double target_freq, double lo_offset
-);
-
-/*!
- * Tune a tx chain to the desired frequency:
- * Same as the above, except the LO offset
- * is calculated based on the subdevice and BW.
- */
-UHD_API tune_result_t tune_tx_subdev_and_duc(
-    wax::obj subdev, wax::obj duc, double target_freq
-);
-
-} //namespace uhd
-
-#endif /* INCLUDED_UHD_UTILS_TUNE_HELPER_HPP */
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt
index b205bad5b..a5345cae4 100644
--- a/host/lib/CMakeLists.txt
+++ b/host/lib/CMakeLists.txt
@@ -22,8 +22,6 @@ SET(libuhd_sources
     device.cpp
     gain_handler.cpp
     load_modules.cpp
-    simple_device.cpp
-    tune_helper.cpp
     types.cpp
     wax.cpp
     transport/if_addrs.cpp
@@ -32,7 +30,9 @@ SET(libuhd_sources
     usrp/dboard/db_basic_and_lf.cpp
     usrp/dboard_base.cpp
     usrp/dboard_interface.cpp
+    usrp/simple_usrp.cpp
     usrp/dboard_manager.cpp
+    usrp/tune_helper.cpp
     usrp/usrp2/dboard_impl.cpp
     usrp/usrp2/dboard_interface.cpp
     usrp/usrp2/dsp_impl.cpp
diff --git a/host/lib/simple_device.cpp b/host/lib/simple_device.cpp
deleted file mode 100644
index 801516353..000000000
--- a/host/lib/simple_device.cpp
+++ /dev/null
@@ -1,207 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#include <uhd/simple_device.hpp>
-#include <uhd/utils/tune_helper.hpp>
-#include <uhd/utils/assert.hpp>
-#include <uhd/usrp/subdev_props.hpp>
-#include <uhd/usrp/mboard_props.hpp>
-#include <uhd/usrp/device_props.hpp>
-#include <uhd/usrp/dboard_props.hpp>
-#include <boost/foreach.hpp>
-#include <boost/format.hpp>
-#include <stdexcept>
-
-using namespace uhd;
-using namespace uhd::usrp;
-
-/***********************************************************************
- * Helper Functions
- **********************************************************************/
-static std::vector<double> get_xx_rates(wax::obj decerps, wax::obj rate){
-    std::vector<double> rates;
-    BOOST_FOREACH(size_t decerp, decerps.as<std::vector<size_t> >()){
-        rates.push_back(rate.as<double>()/decerp);
-    }
-    return rates;
-}
-
-/***********************************************************************
- * Simple Device Implementation
- **********************************************************************/
-class simple_device_impl : public simple_device{
-public:
-    simple_device_impl(const device_addr_t &addr){
-        _dev = device::make(addr);
-        _mboard = (*_dev)[DEVICE_PROP_MBOARD];
-        _rx_ddc = _mboard[named_prop_t(MBOARD_PROP_RX_DSP, "ddc0")];
-        _tx_duc = _mboard[named_prop_t(MBOARD_PROP_TX_DSP, "duc0")];
-
-        //extract rx subdevice
-        wax::obj rx_dboard = _mboard[MBOARD_PROP_RX_DBOARD];
-        std::string rx_subdev_in_use = rx_dboard[DBOARD_PROP_USED_SUBDEVS].as<prop_names_t>().at(0);
-        _rx_subdev = rx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, rx_subdev_in_use)];
-
-        //extract tx subdevice
-        wax::obj tx_dboard = _mboard[MBOARD_PROP_TX_DBOARD];
-        std::string tx_subdev_in_use = tx_dboard[DBOARD_PROP_USED_SUBDEVS].as<prop_names_t>().at(0);
-        _tx_subdev = tx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, tx_subdev_in_use)];
-    }
-
-    ~simple_device_impl(void){
-        /* NOP */
-    }
-
-    device::sptr get_device(void){
-        return _dev;
-    }
-
-    std::string get_name(void){
-        return _mboard[MBOARD_PROP_NAME].as<std::string>();
-    }
-
-    /*******************************************************************
-     * Timing
-     ******************************************************************/
-    void set_time_now(const time_spec_t &time_spec){
-        _mboard[MBOARD_PROP_TIME_NOW] = time_spec;
-    }
-
-    void set_time_next_pps(const time_spec_t &time_spec){
-        _mboard[MBOARD_PROP_TIME_NEXT_PPS] = time_spec;
-    }
-
-    /*******************************************************************
-     * Streaming
-     ******************************************************************/
-    void issue_stream_cmd(const stream_cmd_t &stream_cmd){
-        _rx_ddc[std::string("stream_cmd")] = stream_cmd;
-    }
-
-    /*******************************************************************
-     * RX methods
-     ******************************************************************/
-    void set_rx_rate(double rate){
-        double samp_rate = _rx_ddc[std::string("if_rate")].as<double>();
-        assert_has(get_rx_rates(), rate, "simple device rx rate");
-        _rx_ddc[std::string("decim")] = size_t(samp_rate/rate);
-    }
-
-    double get_rx_rate(void){
-        return _rx_ddc[std::string("bb_rate")].as<double>();
-    }
-
-    std::vector<double> get_rx_rates(void){
-        return get_xx_rates(_rx_ddc[std::string("decims")], _rx_ddc[std::string("if_rate")]);
-    }
-
-    tune_result_t set_rx_freq(double target_freq){
-        return tune_rx_subdev_and_ddc(_rx_subdev, _rx_ddc, target_freq);
-    }
-
-    freq_range_t get_rx_freq_range(void){
-        return _rx_subdev[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>();
-    }
-
-    void set_rx_gain(float gain){
-        _rx_subdev[SUBDEV_PROP_GAIN] = gain;
-    }
-
-    float get_rx_gain(void){
-        return _rx_subdev[SUBDEV_PROP_GAIN].as<float>();
-    }
-
-    gain_range_t get_rx_gain_range(void){
-        return _rx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
-    }
-
-    void set_rx_antenna(const std::string &ant){
-        _rx_subdev[SUBDEV_PROP_ANTENNA] = ant;
-    }
-
-    std::string get_rx_antenna(void){
-        return _rx_subdev[SUBDEV_PROP_ANTENNA].as<std::string>();
-    }
-
-    std::vector<std::string> get_rx_antennas(void){
-        return _rx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<std::vector<std::string> >();
-    }
-
-    /*******************************************************************
-     * TX methods
-     ******************************************************************/
-    void set_tx_rate(double rate){
-        double samp_rate = _tx_duc[std::string("if_rate")].as<double>();
-        assert_has(get_tx_rates(), rate, "simple device tx rate");
-        _tx_duc[std::string("interp")] = size_t(samp_rate/rate);
-    }
-
-    double get_tx_rate(void){
-        return _tx_duc[std::string("bb_rate")].as<double>();
-    }
-
-    std::vector<double> get_tx_rates(void){
-        return get_xx_rates(_tx_duc[std::string("interps")], _tx_duc[std::string("if_rate")]);
-    }
-
-    tune_result_t set_tx_freq(double target_freq){
-        return tune_tx_subdev_and_duc(_tx_subdev, _tx_duc, target_freq);
-    }
-
-    freq_range_t get_tx_freq_range(void){
-        return _tx_subdev[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>();
-    }
-
-    void set_tx_gain(float gain){
-        _tx_subdev[SUBDEV_PROP_GAIN] = gain;
-    }
-
-    float get_tx_gain(void){
-        return _tx_subdev[SUBDEV_PROP_GAIN].as<float>();
-    }
-
-    gain_range_t get_tx_gain_range(void){
-        return _tx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
-    }
-
-    void set_tx_antenna(const std::string &ant){
-        _tx_subdev[SUBDEV_PROP_ANTENNA] = ant;
-    }
-
-    std::string get_tx_antenna(void){
-        return _tx_subdev[SUBDEV_PROP_ANTENNA].as<std::string>();
-    }
-
-    std::vector<std::string> get_tx_antennas(void){
-        return _tx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<std::vector<std::string> >();
-    }
-
-private:
-    device::sptr _dev;
-    wax::obj _mboard;
-    wax::obj _rx_ddc;
-    wax::obj _tx_duc;
-    wax::obj _rx_subdev;
-    wax::obj _tx_subdev;
-};
-
-/***********************************************************************
- * The Make Function
- **********************************************************************/
-simple_device::sptr simple_device::make(const std::string &args){
-    return sptr(new simple_device_impl(device_addr_t::from_args_str(args)));
-}
diff --git a/host/lib/tune_helper.cpp b/host/lib/tune_helper.cpp
deleted file mode 100644
index 381685578..000000000
--- a/host/lib/tune_helper.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-#include <uhd/utils/tune_helper.hpp>
-#include <uhd/utils/algorithm.hpp>
-#include <uhd/usrp/subdev_props.hpp>
-#include <cmath>
-
-using namespace uhd;
-using namespace uhd::usrp;
-
-/***********************************************************************
- * Tune Helper Function
- **********************************************************************/
-static tune_result_t tune_xx_subdev_and_dxc(
-    bool is_tx,
-    wax::obj subdev, wax::obj dxc,
-    double target_freq, double lo_offset
-){
-    wax::obj subdev_freq_proxy = subdev[SUBDEV_PROP_FREQ];
-    bool subdev_quadrature = subdev[SUBDEV_PROP_QUADRATURE].as<bool>();
-    bool subdev_spectrum_inverted = subdev[SUBDEV_PROP_SPECTRUM_INVERTED].as<bool>();
-    wax::obj dxc_freq_proxy = dxc[std::string("freq")];
-    double dxc_sample_rate = dxc[std::string("if_rate")].as<double>();
-
-    // Ask the d'board to tune as closely as it can to target_freq+lo_offset
-    double target_inter_freq = target_freq + lo_offset;
-    subdev_freq_proxy = target_inter_freq;
-    double actual_inter_freq = subdev_freq_proxy.as<double>();
-
-    // Calculate the DDC setting that will downconvert the baseband from the
-    // daughterboard to our target frequency.
-    double delta_freq = target_freq - actual_inter_freq;
-    double delta_sign = std::signum(delta_freq);
-    delta_freq *= delta_sign;
-    delta_freq = std::fmod(delta_freq, dxc_sample_rate);
-    bool inverted = delta_freq > dxc_sample_rate/2.0;
-    double target_dxc_freq = inverted? (delta_freq - dxc_sample_rate) : (-delta_freq);
-    target_dxc_freq *= delta_sign;
-
-    // If the spectrum is inverted, and the daughterboard doesn't do
-    // quadrature downconversion, we can fix the inversion by flipping the
-    // sign of the dxc_freq...  (This only happens using the basic_rx board)
-    if (subdev_spectrum_inverted){
-        inverted = not inverted;
-    }
-    if (inverted and not subdev_quadrature){
-        target_dxc_freq *= -1.0;
-        inverted = not inverted;
-    }
-    // down conversion versus up conversion, fight!
-    // your mother is ugly and your going down...
-    target_dxc_freq *= (is_tx)? -1.0 : +1.0;
-
-    dxc_freq_proxy = target_dxc_freq;
-    double actual_dxc_freq = dxc_freq_proxy.as<double>();
-
-    //return some kind of tune result tuple/struct
-    tune_result_t tune_result;
-    tune_result.target_inter_freq = target_inter_freq;
-    tune_result.actual_inter_freq = actual_inter_freq;
-    tune_result.target_dxc_freq = target_dxc_freq;
-    tune_result.actual_dxc_freq = actual_dxc_freq;
-    tune_result.spectrum_inverted = inverted;
-    return tune_result;
-}
-
-/***********************************************************************
- * RX Tune
- **********************************************************************/
-tune_result_t uhd::tune_rx_subdev_and_ddc(
-    wax::obj subdev, wax::obj ddc,
-    double target_freq, double lo_offset
-){
-    bool is_tx = false;
-    return tune_xx_subdev_and_dxc(is_tx, subdev, ddc, target_freq, lo_offset);
-}
-
-tune_result_t uhd::tune_rx_subdev_and_ddc(
-    wax::obj subdev, wax::obj ddc,
-    double target_freq
-){
-    double lo_offset = 0.0;
-    //if the local oscillator will be in the passband, use an offset
-    if (subdev[SUBDEV_PROP_LO_INTERFERES].as<bool>()){
-        lo_offset = 2.0*ddc[std::string("bb_rate")].as<double>();
-    }
-    return tune_rx_subdev_and_ddc(subdev, ddc, target_freq, lo_offset);
-}
-
-/***********************************************************************
- * TX Tune
- **********************************************************************/
-tune_result_t uhd::tune_tx_subdev_and_duc(
-    wax::obj subdev, wax::obj duc,
-    double target_freq, double lo_offset
-){
-    bool is_tx = true;
-    return tune_xx_subdev_and_dxc(is_tx, subdev, duc, target_freq, lo_offset);
-}
-
-tune_result_t uhd::tune_tx_subdev_and_duc(
-    wax::obj subdev, wax::obj duc,
-    double target_freq
-){
-    double lo_offset = 0.0;
-    //if the local oscillator will be in the passband, use an offset
-    if (subdev[SUBDEV_PROP_LO_INTERFERES].as<bool>()){
-        lo_offset = 2.0*duc[std::string("bb_rate")].as<double>();
-    }
-    return tune_tx_subdev_and_duc(subdev, duc, target_freq, lo_offset);
-}
diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp
new file mode 100644
index 000000000..4bd47dc3f
--- /dev/null
+++ b/host/lib/usrp/simple_usrp.cpp
@@ -0,0 +1,207 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/usrp/simple_usrp.hpp>
+#include <uhd/usrp/tune_helper.hpp>
+#include <uhd/utils/assert.hpp>
+#include <uhd/usrp/subdev_props.hpp>
+#include <uhd/usrp/mboard_props.hpp>
+#include <uhd/usrp/device_props.hpp>
+#include <uhd/usrp/dboard_props.hpp>
+#include <boost/foreach.hpp>
+#include <boost/format.hpp>
+#include <stdexcept>
+
+using namespace uhd;
+using namespace uhd::usrp;
+
+/***********************************************************************
+ * Helper Functions
+ **********************************************************************/
+static std::vector<double> get_xx_rates(wax::obj decerps, wax::obj rate){
+    std::vector<double> rates;
+    BOOST_FOREACH(size_t decerp, decerps.as<std::vector<size_t> >()){
+        rates.push_back(rate.as<double>()/decerp);
+    }
+    return rates;
+}
+
+/***********************************************************************
+ * Simple Device Implementation
+ **********************************************************************/
+class simple_usrp_impl : public simple_usrp{
+public:
+    simple_usrp_impl(const device_addr_t &addr){
+        _dev = device::make(addr);
+        _mboard = (*_dev)[DEVICE_PROP_MBOARD];
+        _rx_ddc = _mboard[named_prop_t(MBOARD_PROP_RX_DSP, "ddc0")];
+        _tx_duc = _mboard[named_prop_t(MBOARD_PROP_TX_DSP, "duc0")];
+
+        //extract rx subdevice
+        wax::obj rx_dboard = _mboard[MBOARD_PROP_RX_DBOARD];
+        std::string rx_subdev_in_use = rx_dboard[DBOARD_PROP_USED_SUBDEVS].as<prop_names_t>().at(0);
+        _rx_subdev = rx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, rx_subdev_in_use)];
+
+        //extract tx subdevice
+        wax::obj tx_dboard = _mboard[MBOARD_PROP_TX_DBOARD];
+        std::string tx_subdev_in_use = tx_dboard[DBOARD_PROP_USED_SUBDEVS].as<prop_names_t>().at(0);
+        _tx_subdev = tx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, tx_subdev_in_use)];
+    }
+
+    ~simple_usrp_impl(void){
+        /* NOP */
+    }
+
+    device::sptr get_device(void){
+        return _dev;
+    }
+
+    std::string get_name(void){
+        return _mboard[MBOARD_PROP_NAME].as<std::string>();
+    }
+
+    /*******************************************************************
+     * Timing
+     ******************************************************************/
+    void set_time_now(const time_spec_t &time_spec){
+        _mboard[MBOARD_PROP_TIME_NOW] = time_spec;
+    }
+
+    void set_time_next_pps(const time_spec_t &time_spec){
+        _mboard[MBOARD_PROP_TIME_NEXT_PPS] = time_spec;
+    }
+
+    /*******************************************************************
+     * Streaming
+     ******************************************************************/
+    void issue_stream_cmd(const stream_cmd_t &stream_cmd){
+        _rx_ddc[std::string("stream_cmd")] = stream_cmd;
+    }
+
+    /*******************************************************************
+     * RX methods
+     ******************************************************************/
+    void set_rx_rate(double rate){
+        double samp_rate = _rx_ddc[std::string("if_rate")].as<double>();
+        assert_has(get_rx_rates(), rate, "simple device rx rate");
+        _rx_ddc[std::string("decim")] = size_t(samp_rate/rate);
+    }
+
+    double get_rx_rate(void){
+        return _rx_ddc[std::string("bb_rate")].as<double>();
+    }
+
+    std::vector<double> get_rx_rates(void){
+        return get_xx_rates(_rx_ddc[std::string("decims")], _rx_ddc[std::string("if_rate")]);
+    }
+
+    tune_result_t set_rx_freq(double target_freq){
+        return tune_rx_subdev_and_ddc(_rx_subdev, _rx_ddc, target_freq);
+    }
+
+    freq_range_t get_rx_freq_range(void){
+        return _rx_subdev[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>();
+    }
+
+    void set_rx_gain(float gain){
+        _rx_subdev[SUBDEV_PROP_GAIN] = gain;
+    }
+
+    float get_rx_gain(void){
+        return _rx_subdev[SUBDEV_PROP_GAIN].as<float>();
+    }
+
+    gain_range_t get_rx_gain_range(void){
+        return _rx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
+    }
+
+    void set_rx_antenna(const std::string &ant){
+        _rx_subdev[SUBDEV_PROP_ANTENNA] = ant;
+    }
+
+    std::string get_rx_antenna(void){
+        return _rx_subdev[SUBDEV_PROP_ANTENNA].as<std::string>();
+    }
+
+    std::vector<std::string> get_rx_antennas(void){
+        return _rx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<std::vector<std::string> >();
+    }
+
+    /*******************************************************************
+     * TX methods
+     ******************************************************************/
+    void set_tx_rate(double rate){
+        double samp_rate = _tx_duc[std::string("if_rate")].as<double>();
+        assert_has(get_tx_rates(), rate, "simple device tx rate");
+        _tx_duc[std::string("interp")] = size_t(samp_rate/rate);
+    }
+
+    double get_tx_rate(void){
+        return _tx_duc[std::string("bb_rate")].as<double>();
+    }
+
+    std::vector<double> get_tx_rates(void){
+        return get_xx_rates(_tx_duc[std::string("interps")], _tx_duc[std::string("if_rate")]);
+    }
+
+    tune_result_t set_tx_freq(double target_freq){
+        return tune_tx_subdev_and_duc(_tx_subdev, _tx_duc, target_freq);
+    }
+
+    freq_range_t get_tx_freq_range(void){
+        return _tx_subdev[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>();
+    }
+
+    void set_tx_gain(float gain){
+        _tx_subdev[SUBDEV_PROP_GAIN] = gain;
+    }
+
+    float get_tx_gain(void){
+        return _tx_subdev[SUBDEV_PROP_GAIN].as<float>();
+    }
+
+    gain_range_t get_tx_gain_range(void){
+        return _tx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
+    }
+
+    void set_tx_antenna(const std::string &ant){
+        _tx_subdev[SUBDEV_PROP_ANTENNA] = ant;
+    }
+
+    std::string get_tx_antenna(void){
+        return _tx_subdev[SUBDEV_PROP_ANTENNA].as<std::string>();
+    }
+
+    std::vector<std::string> get_tx_antennas(void){
+        return _tx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<std::vector<std::string> >();
+    }
+
+private:
+    device::sptr _dev;
+    wax::obj _mboard;
+    wax::obj _rx_ddc;
+    wax::obj _tx_duc;
+    wax::obj _rx_subdev;
+    wax::obj _tx_subdev;
+};
+
+/***********************************************************************
+ * The Make Function
+ **********************************************************************/
+simple_usrp::sptr simple_usrp::make(const std::string &args){
+    return sptr(new simple_usrp_impl(device_addr_t::from_args_str(args)));
+}
diff --git a/host/lib/usrp/tune_helper.cpp b/host/lib/usrp/tune_helper.cpp
new file mode 100644
index 000000000..79a6aff7b
--- /dev/null
+++ b/host/lib/usrp/tune_helper.cpp
@@ -0,0 +1,126 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/usrp/tune_helper.hpp>
+#include <uhd/utils/algorithm.hpp>
+#include <uhd/usrp/subdev_props.hpp>
+#include <cmath>
+
+using namespace uhd;
+using namespace uhd::usrp;
+
+/***********************************************************************
+ * Tune Helper Function
+ **********************************************************************/
+static tune_result_t tune_xx_subdev_and_dxc(
+    bool is_tx,
+    wax::obj subdev, wax::obj dxc,
+    double target_freq, double lo_offset
+){
+    wax::obj subdev_freq_proxy = subdev[SUBDEV_PROP_FREQ];
+    bool subdev_quadrature = subdev[SUBDEV_PROP_QUADRATURE].as<bool>();
+    bool subdev_spectrum_inverted = subdev[SUBDEV_PROP_SPECTRUM_INVERTED].as<bool>();
+    wax::obj dxc_freq_proxy = dxc[std::string("freq")];
+    double dxc_sample_rate = dxc[std::string("if_rate")].as<double>();
+
+    // Ask the d'board to tune as closely as it can to target_freq+lo_offset
+    double target_inter_freq = target_freq + lo_offset;
+    subdev_freq_proxy = target_inter_freq;
+    double actual_inter_freq = subdev_freq_proxy.as<double>();
+
+    // Calculate the DDC setting that will downconvert the baseband from the
+    // daughterboard to our target frequency.
+    double delta_freq = target_freq - actual_inter_freq;
+    double delta_sign = std::signum(delta_freq);
+    delta_freq *= delta_sign;
+    delta_freq = std::fmod(delta_freq, dxc_sample_rate);
+    bool inverted = delta_freq > dxc_sample_rate/2.0;
+    double target_dxc_freq = inverted? (delta_freq - dxc_sample_rate) : (-delta_freq);
+    target_dxc_freq *= delta_sign;
+
+    // If the spectrum is inverted, and the daughterboard doesn't do
+    // quadrature downconversion, we can fix the inversion by flipping the
+    // sign of the dxc_freq...  (This only happens using the basic_rx board)
+    if (subdev_spectrum_inverted){
+        inverted = not inverted;
+    }
+    if (inverted and not subdev_quadrature){
+        target_dxc_freq *= -1.0;
+        inverted = not inverted;
+    }
+    // down conversion versus up conversion, fight!
+    // your mother is ugly and your going down...
+    target_dxc_freq *= (is_tx)? -1.0 : +1.0;
+
+    dxc_freq_proxy = target_dxc_freq;
+    double actual_dxc_freq = dxc_freq_proxy.as<double>();
+
+    //return some kind of tune result tuple/struct
+    tune_result_t tune_result;
+    tune_result.target_inter_freq = target_inter_freq;
+    tune_result.actual_inter_freq = actual_inter_freq;
+    tune_result.target_dxc_freq = target_dxc_freq;
+    tune_result.actual_dxc_freq = actual_dxc_freq;
+    tune_result.spectrum_inverted = inverted;
+    return tune_result;
+}
+
+/***********************************************************************
+ * RX Tune
+ **********************************************************************/
+tune_result_t uhd::usrp::tune_rx_subdev_and_ddc(
+    wax::obj subdev, wax::obj ddc,
+    double target_freq, double lo_offset
+){
+    bool is_tx = false;
+    return tune_xx_subdev_and_dxc(is_tx, subdev, ddc, target_freq, lo_offset);
+}
+
+tune_result_t uhd::usrp::tune_rx_subdev_and_ddc(
+    wax::obj subdev, wax::obj ddc,
+    double target_freq
+){
+    double lo_offset = 0.0;
+    //if the local oscillator will be in the passband, use an offset
+    if (subdev[SUBDEV_PROP_LO_INTERFERES].as<bool>()){
+        lo_offset = 2.0*ddc[std::string("bb_rate")].as<double>();
+    }
+    return tune_rx_subdev_and_ddc(subdev, ddc, target_freq, lo_offset);
+}
+
+/***********************************************************************
+ * TX Tune
+ **********************************************************************/
+tune_result_t uhd::usrp::tune_tx_subdev_and_duc(
+    wax::obj subdev, wax::obj duc,
+    double target_freq, double lo_offset
+){
+    bool is_tx = true;
+    return tune_xx_subdev_and_dxc(is_tx, subdev, duc, target_freq, lo_offset);
+}
+
+tune_result_t uhd::usrp::tune_tx_subdev_and_duc(
+    wax::obj subdev, wax::obj duc,
+    double target_freq
+){
+    double lo_offset = 0.0;
+    //if the local oscillator will be in the passband, use an offset
+    if (subdev[SUBDEV_PROP_LO_INTERFERES].as<bool>()){
+        lo_offset = 2.0*duc[std::string("bb_rate")].as<double>();
+    }
+    return tune_tx_subdev_and_duc(subdev, duc, target_freq, lo_offset);
+}
-- 
cgit v1.2.3


From f1f4865119605c66ffece113a621308d82512d23 Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Thu, 1 Apr 2010 16:37:25 -0700
Subject: hardcoded values for enum props, added clock get/set for simple usrp

---
 host/include/uhd/usrp/dboard_props.hpp |  8 ++++----
 host/include/uhd/usrp/device_props.hpp | 10 +++++-----
 host/include/uhd/usrp/dsp_props.hpp    |  4 ++--
 host/include/uhd/usrp/mboard_props.hpp | 28 ++++++++++++++--------------
 host/include/uhd/usrp/simple_usrp.hpp  |  9 ++++-----
 host/include/uhd/usrp/subdev_props.hpp | 28 ++++++++++++++--------------
 host/lib/usrp/simple_usrp.cpp          | 17 +++++++++++------
 7 files changed, 54 insertions(+), 50 deletions(-)

(limited to 'host/lib')

diff --git a/host/include/uhd/usrp/dboard_props.hpp b/host/include/uhd/usrp/dboard_props.hpp
index 08c4eef6a..3b290319f 100644
--- a/host/include/uhd/usrp/dboard_props.hpp
+++ b/host/include/uhd/usrp/dboard_props.hpp
@@ -26,10 +26,10 @@ namespace uhd{ namespace usrp{
      * Possible device dboard properties
      */
     enum dboard_prop_t{
-        DBOARD_PROP_NAME,              //ro, std::string
-        DBOARD_PROP_SUBDEV,            //ro, wax::obj
-        DBOARD_PROP_SUBDEV_NAMES,      //ro, prop_names_t
-        DBOARD_PROP_USED_SUBDEVS       //ro, prop_names_t
+        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_CODEC              //ro, wax::obj //----> not sure, dont have to deal with yet
     }; 
 
diff --git a/host/include/uhd/usrp/device_props.hpp b/host/include/uhd/usrp/device_props.hpp
index dcfa26240..b8f6f5cd4 100644
--- a/host/include/uhd/usrp/device_props.hpp
+++ b/host/include/uhd/usrp/device_props.hpp
@@ -29,11 +29,11 @@ namespace uhd{ namespace usrp{
      *   will be present in the interface for configuration.
      */
     enum device_prop_t{
-        DEVICE_PROP_NAME,              //ro, std::string
-        DEVICE_PROP_MBOARD,            //ro, wax::obj
-        DEVICE_PROP_MBOARD_NAMES,      //ro, prop_names_t
-        DEVICE_PROP_MAX_RX_SAMPLES,    //ro, size_t
-        DEVICE_PROP_MAX_TX_SAMPLES     //ro, size_t
+        DEVICE_PROP_NAME           = 'n', //ro, std::string
+        DEVICE_PROP_MBOARD         = 'm', //ro, wax::obj
+        DEVICE_PROP_MBOARD_NAMES   = 'M', //ro, prop_names_t
+        DEVICE_PROP_MAX_RX_SAMPLES = 'r', //ro, size_t
+        DEVICE_PROP_MAX_TX_SAMPLES = 't'  //ro, size_t
     };
 
     ////////////////////////////////////////////////////////////////////////
diff --git a/host/include/uhd/usrp/dsp_props.hpp b/host/include/uhd/usrp/dsp_props.hpp
index ef3f771df..60c0df942 100644
--- a/host/include/uhd/usrp/dsp_props.hpp
+++ b/host/include/uhd/usrp/dsp_props.hpp
@@ -31,8 +31,8 @@ namespace uhd{ namespace usrp{
      *   and a property to get list of other possible properties.
      */
     enum dsp_prop_t{
-        DSP_PROP_NAME,                 //ro, std::string
-        DSP_PROP_OTHERS                //ro, prop_names_t
+        DSP_PROP_NAME   = 'n', //ro, std::string
+        DSP_PROP_OTHERS = 'o'  //ro, prop_names_t
     };
 
 }} //namespace
diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp
index ddb95ef0d..cfc1f412e 100644
--- a/host/include/uhd/usrp/mboard_props.hpp
+++ b/host/include/uhd/usrp/mboard_props.hpp
@@ -29,20 +29,20 @@ namespace uhd{ namespace usrp{
      *   and discovered though the others property.
      */
     enum mboard_prop_t{
-        MBOARD_PROP_NAME,              //ro, std::string
-        MBOARD_PROP_OTHERS,            //ro, prop_names_t
-        MBOARD_PROP_CLOCK_RATE,        //ro, double
-        MBOARD_PROP_RX_DSP,            //ro, wax::obj
-        MBOARD_PROP_RX_DSP_NAMES,      //ro, prop_names_t
-        MBOARD_PROP_TX_DSP,            //ro, wax::obj
-        MBOARD_PROP_TX_DSP_NAMES,      //ro, prop_names_t
-        MBOARD_PROP_RX_DBOARD,         //ro, wax::obj
-        MBOARD_PROP_RX_DBOARD_NAMES,   //ro, prop_names_t
-        MBOARD_PROP_TX_DBOARD,         //ro, wax::obj
-        MBOARD_PROP_TX_DBOARD_NAMES,   //ro, prop_names_t
-        MBOARD_PROP_CLOCK_CONFIG,      //rw, clock_config_t
-        MBOARD_PROP_TIME_NOW,          //wo, time_spec_t
-        MBOARD_PROP_TIME_NEXT_PPS      //wo, time_spec_t
+        MBOARD_PROP_NAME            = 'n', //ro, std::string
+        MBOARD_PROP_OTHERS          = 'o', //ro, prop_names_t
+        MBOARD_PROP_CLOCK_RATE      = 'c', //ro, double
+        MBOARD_PROP_RX_DSP          = 'd', //ro, wax::obj
+        MBOARD_PROP_RX_DSP_NAMES    = 'D', //ro, prop_names_t
+        MBOARD_PROP_TX_DSP          = 'u', //ro, wax::obj
+        MBOARD_PROP_TX_DSP_NAMES    = 'U', //ro, prop_names_t
+        MBOARD_PROP_RX_DBOARD       = 'e', //ro, wax::obj
+        MBOARD_PROP_RX_DBOARD_NAMES = 'E', //ro, prop_names_t
+        MBOARD_PROP_TX_DBOARD       = 'v', //ro, wax::obj
+        MBOARD_PROP_TX_DBOARD_NAMES = 'V', //ro, prop_names_t
+        MBOARD_PROP_CLOCK_CONFIG    = 'C', //rw, clock_config_t
+        MBOARD_PROP_TIME_NOW        = 't', //wo, time_spec_t
+        MBOARD_PROP_TIME_NEXT_PPS   = 'T'  //wo, time_spec_t
     };
 
 }} //namespace
diff --git a/host/include/uhd/usrp/simple_usrp.hpp b/host/include/uhd/usrp/simple_usrp.hpp
index dea1cabda..2d6ad2a0f 100644
--- a/host/include/uhd/usrp/simple_usrp.hpp
+++ b/host/include/uhd/usrp/simple_usrp.hpp
@@ -22,6 +22,7 @@
 #include <uhd/device.hpp>
 #include <uhd/types/ranges.hpp>
 #include <uhd/types/stream_cmd.hpp>
+#include <uhd/types/clock_config.hpp>
 #include <uhd/types/tune_result.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/utility.hpp>
@@ -45,15 +46,13 @@ public:
     virtual std::string get_name(void) = 0;
 
     /*******************************************************************
-     * Timing
+     * Misc
      ******************************************************************/
     virtual void set_time_now(const time_spec_t &time_spec) = 0;
     virtual void set_time_next_pps(const time_spec_t &time_spec) = 0;
-
-    /*******************************************************************
-     * Streaming
-     ******************************************************************/
     virtual void issue_stream_cmd(const stream_cmd_t &stream_cmd) = 0;
+    virtual void set_clock_config(const clock_config_t &clock_config) = 0;
+    virtual double get_clock_rate(void) = 0;
 
     /*******************************************************************
      * RX methods
diff --git a/host/include/uhd/usrp/subdev_props.hpp b/host/include/uhd/usrp/subdev_props.hpp
index 667f34f9c..92d18340b 100644
--- a/host/include/uhd/usrp/subdev_props.hpp
+++ b/host/include/uhd/usrp/subdev_props.hpp
@@ -26,20 +26,20 @@ namespace uhd{ namespace usrp{
      * Possible device subdev properties
      */
     enum subdev_prop_t{
-        SUBDEV_PROP_NAME,              //ro, std::string
-        SUBDEV_PROP_OTHERS,            //ro, prop_names_t
-        SUBDEV_PROP_GAIN,              //rw, float
-        SUBDEV_PROP_GAIN_RANGE,        //ro, gain_range_t
-        SUBDEV_PROP_GAIN_NAMES,        //ro, prop_names_t
-        SUBDEV_PROP_FREQ,              //rw, double
-        SUBDEV_PROP_FREQ_RANGE,        //ro, freq_range_t
-        SUBDEV_PROP_ANTENNA,           //rw, std::string
-        SUBDEV_PROP_ANTENNA_NAMES,     //ro, prop_names_t
-        SUBDEV_PROP_ENABLED,           //rw, bool
-        SUBDEV_PROP_QUADRATURE,        //ro, bool
-        SUBDEV_PROP_IQ_SWAPPED,        //ro, bool
-        SUBDEV_PROP_SPECTRUM_INVERTED, //ro, bool
-        SUBDEV_PROP_LO_INTERFERES      //ro, bool
+        SUBDEV_PROP_NAME              = 'n', //ro, std::string
+        SUBDEV_PROP_OTHERS            = 'o', //ro, prop_names_t
+        SUBDEV_PROP_GAIN              = 'g', //rw, float
+        SUBDEV_PROP_GAIN_RANGE        = 'r', //ro, gain_range_t
+        SUBDEV_PROP_GAIN_NAMES        = 'G', //ro, prop_names_t
+        SUBDEV_PROP_FREQ              = 'f', //rw, double
+        SUBDEV_PROP_FREQ_RANGE        = 'F', //ro, freq_range_t
+        SUBDEV_PROP_ANTENNA           = 'a', //rw, std::string
+        SUBDEV_PROP_ANTENNA_NAMES     = 'A', //ro, prop_names_t
+        SUBDEV_PROP_ENABLED           = 'e', //rw, bool
+        SUBDEV_PROP_QUADRATURE        = 'q', //ro, bool
+        SUBDEV_PROP_IQ_SWAPPED        = 'i', //ro, bool
+        SUBDEV_PROP_SPECTRUM_INVERTED = 's', //ro, bool
+        SUBDEV_PROP_LO_INTERFERES     = 'l'  //ro, bool
         //SUBDEV_PROP_RSSI,              //ro, float //----> not on all boards, use named prop
         //SUBDEV_PROP_BANDWIDTH          //rw, double //----> not on all boards, use named prop
     };
diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp
index 4bd47dc3f..a0551a630 100644
--- a/host/lib/usrp/simple_usrp.cpp
+++ b/host/lib/usrp/simple_usrp.cpp
@@ -75,7 +75,7 @@ public:
     }
 
     /*******************************************************************
-     * Timing
+     * Misc
      ******************************************************************/
     void set_time_now(const time_spec_t &time_spec){
         _mboard[MBOARD_PROP_TIME_NOW] = time_spec;
@@ -85,13 +85,18 @@ public:
         _mboard[MBOARD_PROP_TIME_NEXT_PPS] = time_spec;
     }
 
-    /*******************************************************************
-     * Streaming
-     ******************************************************************/
     void issue_stream_cmd(const stream_cmd_t &stream_cmd){
         _rx_ddc[std::string("stream_cmd")] = stream_cmd;
     }
 
+    void set_clock_config(const clock_config_t &clock_config){
+        _mboard[MBOARD_PROP_CLOCK_CONFIG] = clock_config;
+    }
+
+    double get_clock_rate(void){
+        return _mboard[MBOARD_PROP_CLOCK_RATE].as<double>();
+    }
+
     /*******************************************************************
      * RX methods
      ******************************************************************/
@@ -138,7 +143,7 @@ public:
     }
 
     std::vector<std::string> get_rx_antennas(void){
-        return _rx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<std::vector<std::string> >();
+        return _rx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
     }
 
     /*******************************************************************
@@ -187,7 +192,7 @@ public:
     }
 
     std::vector<std::string> get_tx_antennas(void){
-        return _tx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<std::vector<std::string> >();
+        return _tx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
     }
 
 private:
-- 
cgit v1.2.3