summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-04-16 12:58:42 +0000
committerJosh Blum <josh@joshknows.com>2010-04-16 12:58:42 +0000
commit839d9c39542db356ad1b955e3a3d9e7aabb071bc (patch)
tree0bb8a08c6d7e046a4a2199fb73a56264bc10f7ec
parent835cb56ef820a69e1e6e0ccde7c5a0e78ca5ad25 (diff)
downloaduhd-839d9c39542db356ad1b955e3a3d9e7aabb071bc.tar.gz
uhd-839d9c39542db356ad1b955e3a3d9e7aabb071bc.tar.bz2
uhd-839d9c39542db356ad1b955e3a3d9e7aabb071bc.zip
pulled in master and got usrp-e code compiling
-rwxr-xr-xhost/apps/omap_debug/fetch-kernel.sh2
-rwxr-xr-xhost/apps/omap_debug/fetch-module.sh2
-rw-r--r--host/lib/CMakeLists.txt3
-rw-r--r--host/lib/usrp/usrp_e/dboard_iface.cpp (renamed from host/lib/usrp/usrp_e/dboard_interface.cpp)158
-rw-r--r--host/lib/usrp/usrp_e/dboard_impl.cpp6
-rw-r--r--host/lib/usrp/usrp_e/mboard_impl.cpp4
-rw-r--r--host/lib/usrp/usrp_e/usrp_e_iface.cpp135
-rw-r--r--host/lib/usrp/usrp_e/usrp_e_iface.hpp97
-rw-r--r--host/lib/usrp/usrp_e/usrp_e_impl.cpp89
-rw-r--r--host/lib/usrp/usrp_e/usrp_e_impl.hpp26
10 files changed, 342 insertions, 180 deletions
diff --git a/host/apps/omap_debug/fetch-kernel.sh b/host/apps/omap_debug/fetch-kernel.sh
index a3cddb339..f25f139fa 100755
--- a/host/apps/omap_debug/fetch-kernel.sh
+++ b/host/apps/omap_debug/fetch-kernel.sh
@@ -1,4 +1,4 @@
-if [ $GHQ]; then
+if [ $GHQ ]; then
scp $GHQ_USER@astro:/workspace/usrp1-e-dev/kernel_usrp/arch/arm/boot/uImage /media/mmcblk0p1/uImage
else
scp balister@192.168.1.167:src/git/kernel_usrp/arch/arm/boot/uImage /media/mmcblk0p1/uImage
diff --git a/host/apps/omap_debug/fetch-module.sh b/host/apps/omap_debug/fetch-module.sh
index 52fbd4040..0957ad7b4 100755
--- a/host/apps/omap_debug/fetch-module.sh
+++ b/host/apps/omap_debug/fetch-module.sh
@@ -1,5 +1,5 @@
if [ $GHQ ]; then
- scp $GHQ_USER@astro:/workspace/usrp1-e-dev/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc
+ scp $GHQ_USER@astro:/workspace/usrp1-e-dev/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.34-rc1/kernel/drivers/misc
else
scp balister@192.168.1.167:src/git/kernel_usrp/drivers/misc/usrp_e.ko /lib/modules/2.6.33-rc3/kernel/drivers/misc
fi
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt
index dfcb88ec9..ff7f2c0df 100644
--- a/host/lib/CMakeLists.txt
+++ b/host/lib/CMakeLists.txt
@@ -138,11 +138,12 @@ IF(HAVE_USRP_E_REQUIRED_HEADERS)
MESSAGE(STATUS " Building usrp-e support.")
LIST(APPEND libuhd_sources
usrp/usrp_e/dboard_impl.cpp
- usrp/usrp_e/dboard_interface.cpp
+ usrp/usrp_e/dboard_iface.cpp
usrp/usrp_e/dsp_impl.cpp
usrp/usrp_e/fpga-downloader.cc
usrp/usrp_e/mboard_impl.cpp
usrp/usrp_e/usrp_e_impl.cpp
+ usrp/usrp_e/usrp_e_iface.cpp
)
ELSE(HAVE_USRP_E_REQUIRED_HEADERS)
MESSAGE(STATUS " Skipping usrp-e support.")
diff --git a/host/lib/usrp/usrp_e/dboard_interface.cpp b/host/lib/usrp/usrp_e/dboard_iface.cpp
index 47948f3d0..12e8fe206 100644
--- a/host/lib/usrp/usrp_e/dboard_interface.cpp
+++ b/host/lib/usrp/usrp_e/dboard_iface.cpp
@@ -15,149 +15,155 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#include "usrp_e_impl.hpp"
+#include "usrp_e_iface.hpp"
#include "usrp_e_regs.hpp"
+#include <uhd/usrp/dboard_iface.hpp>
#include <uhd/types/dict.hpp>
#include <uhd/utils/assert.hpp>
#include <boost/assign/list_of.hpp>
-#include <algorithm> //std::copy
-#include <linux/usrp_e.h>
+#include <linux/usrp_e.h> //i2c and spi constants
using namespace uhd::usrp;
-class usrp_e_dboard_interface : public dboard_interface{
+class usrp_e_dboard_iface : public dboard_iface{
public:
- usrp_e_dboard_interface(usrp_e_impl *impl);
- ~usrp_e_dboard_interface(void);
+ usrp_e_dboard_iface(usrp_e_iface::sptr iface);
+ ~usrp_e_dboard_iface(void);
- void write_aux_dac(unit_type_t, int, int);
- int read_aux_adc(unit_type_t, int);
+ void write_aux_dac(unit_t, int, float);
+ float read_aux_adc(unit_t, int);
- void set_atr_reg(gpio_bank_t, atr_reg_t, boost::uint16_t);
- void set_gpio_ddr(gpio_bank_t, boost::uint16_t);
- boost::uint16_t read_gpio(gpio_bank_t);
+ void set_atr_reg(unit_t, atr_reg_t, boost::uint16_t);
+ void set_gpio_ddr(unit_t, boost::uint16_t);
+ boost::uint16_t read_gpio(unit_t);
void write_i2c(int, const byte_vector_t &);
byte_vector_t read_i2c(int, size_t);
- double get_rx_clock_rate(void);
- double get_tx_clock_rate(void);
+ void write_spi(
+ unit_t unit,
+ const spi_config_t &config,
+ boost::uint32_t data,
+ size_t num_bits
+ );
-private:
- byte_vector_t transact_spi(
- spi_dev_t dev,
- spi_edge_t edge,
- const byte_vector_t &buf,
- bool readback
+ boost::uint32_t read_write_spi(
+ unit_t unit,
+ const spi_config_t &config,
+ boost::uint32_t data,
+ size_t num_bits
);
- usrp_e_impl *_impl;
+ double get_clock_rate(unit_t);
+ void set_clock_enabled(unit_t, bool);
+
+private:
+ usrp_e_iface::sptr _iface;
};
/***********************************************************************
* Make Function
**********************************************************************/
-dboard_interface::sptr make_usrp_e_dboard_interface(usrp_e_impl *impl){
- return dboard_interface::sptr(new usrp_e_dboard_interface(impl));
+dboard_iface::sptr make_usrp_e_dboard_iface(usrp_e_iface::sptr iface){
+ return dboard_iface::sptr(new usrp_e_dboard_iface(iface));
}
/***********************************************************************
* Structors
**********************************************************************/
-usrp_e_dboard_interface::usrp_e_dboard_interface(usrp_e_impl *impl){
- _impl = impl;
+usrp_e_dboard_iface::usrp_e_dboard_iface(usrp_e_iface::sptr iface){
+ _iface = iface;
}
-usrp_e_dboard_interface::~usrp_e_dboard_interface(void){
+usrp_e_dboard_iface::~usrp_e_dboard_iface(void){
/* NOP */
}
/***********************************************************************
* Clock Rates
**********************************************************************/
-double usrp_e_dboard_interface::get_rx_clock_rate(void){
+double usrp_e_dboard_iface::get_clock_rate(unit_t){
throw std::runtime_error("not implemented");
}
-double usrp_e_dboard_interface::get_tx_clock_rate(void){
+void usrp_e_dboard_iface::set_clock_enabled(unit_t, bool){
throw std::runtime_error("not implemented");
}
/***********************************************************************
* GPIO
**********************************************************************/
-void usrp_e_dboard_interface::set_gpio_ddr(gpio_bank_t bank, boost::uint16_t value){
+void usrp_e_dboard_iface::set_gpio_ddr(unit_t bank, boost::uint16_t value){
//define mapping of gpio bank to register address
- static const uhd::dict<gpio_bank_t, boost::uint32_t> bank_to_addr = boost::assign::map_list_of
- (GPIO_BANK_RX, UE_REG_GPIO_RX_DDR)
- (GPIO_BANK_TX, UE_REG_GPIO_TX_DDR)
+ static const uhd::dict<unit_t, boost::uint32_t> bank_to_addr = boost::assign::map_list_of
+ (UNIT_RX, UE_REG_GPIO_RX_DDR)
+ (UNIT_TX, UE_REG_GPIO_TX_DDR)
;
- _impl->poke16(bank_to_addr[bank], value);
+ _iface->poke16(bank_to_addr[bank], value);
}
-boost::uint16_t usrp_e_dboard_interface::read_gpio(gpio_bank_t bank){
+boost::uint16_t usrp_e_dboard_iface::read_gpio(unit_t bank){
//define mapping of gpio bank to register address
- static const uhd::dict<gpio_bank_t, boost::uint32_t> bank_to_addr = boost::assign::map_list_of
- (GPIO_BANK_RX, UE_REG_GPIO_RX_IO)
- (GPIO_BANK_TX, UE_REG_GPIO_TX_IO)
+ static const uhd::dict<unit_t, boost::uint32_t> bank_to_addr = boost::assign::map_list_of
+ (UNIT_RX, UE_REG_GPIO_RX_IO)
+ (UNIT_TX, UE_REG_GPIO_TX_IO)
;
- return _impl->peek16(bank_to_addr[bank]);
+ return _iface->peek16(bank_to_addr[bank]);
}
-void usrp_e_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t atr, boost::uint16_t value){
+void usrp_e_dboard_iface::set_atr_reg(unit_t bank, atr_reg_t atr, boost::uint16_t value){
//define mapping of bank to atr regs to register address
static const uhd::dict<
- gpio_bank_t, uhd::dict<atr_reg_t, boost::uint32_t>
+ unit_t, uhd::dict<atr_reg_t, boost::uint32_t>
> bank_to_atr_to_addr = boost::assign::map_list_of
- (GPIO_BANK_RX, boost::assign::map_list_of
+ (UNIT_RX, boost::assign::map_list_of
(ATR_REG_IDLE, UE_REG_ATR_IDLE_RXSIDE)
(ATR_REG_TX_ONLY, UE_REG_ATR_INTX_RXSIDE)
(ATR_REG_RX_ONLY, UE_REG_ATR_INRX_RXSIDE)
(ATR_REG_FULL_DUPLEX, UE_REG_ATR_FULL_RXSIDE)
)
- (GPIO_BANK_TX, boost::assign::map_list_of
+ (UNIT_TX, boost::assign::map_list_of
(ATR_REG_IDLE, UE_REG_ATR_IDLE_TXSIDE)
(ATR_REG_TX_ONLY, UE_REG_ATR_INTX_TXSIDE)
(ATR_REG_RX_ONLY, UE_REG_ATR_INRX_TXSIDE)
(ATR_REG_FULL_DUPLEX, UE_REG_ATR_FULL_TXSIDE)
)
;
- _impl->poke16(bank_to_atr_to_addr[bank][atr], value);
+ _iface->poke16(bank_to_atr_to_addr[bank][atr], value);
}
/***********************************************************************
* SPI
**********************************************************************/
-dboard_interface::byte_vector_t usrp_e_dboard_interface::transact_spi(
- spi_dev_t dev,
- spi_edge_t edge,
- const byte_vector_t &buf,
- bool readback
-){
- //load data struct
- usrp_e_spi data;
- data.readback = (readback)? UE_SPI_TXRX : UE_SPI_TXONLY;
- data.slave = (dev == SPI_DEV_RX)? UE_SPI_CTRL_RXNEG : UE_SPI_CTRL_TXNEG;
- data.length = buf.size() * 8; //bytes to bits
- boost::uint8_t *data_bytes = reinterpret_cast<boost::uint8_t*>(&data.data);
-
- //load the data
- ASSERT_THROW(buf.size() <= sizeof(data.data));
- std::copy(buf.begin(), buf.end(), data_bytes);
-
- //load the flags
- data.flags = 0;
- data.flags |= (edge == SPI_EDGE_RISE)? UE_SPI_LATCH_RISE : UE_SPI_LATCH_FALL;
- data.flags |= (edge == SPI_EDGE_RISE)? UE_SPI_PUSH_RISE : UE_SPI_PUSH_FALL;
+/*!
+ * Static function to convert a unit type to a spi slave device number.
+ * \param unit the dboard interface unit type enum
+ * \return the slave device number
+ */
+static boost::uint32_t unit_to_otw_spi_dev(dboard_iface::unit_t unit){
+ switch(unit){
+ case dboard_iface::UNIT_TX: return UE_SPI_CTRL_TXNEG;
+ case dboard_iface::UNIT_RX: return UE_SPI_CTRL_RXNEG;
+ }
+ throw std::invalid_argument("unknown unit type");
+}
- //call the spi ioctl
- _impl->ioctl(USRP_E_SPI, &data);
+void usrp_e_dboard_iface::write_spi(
+ unit_t unit,
+ const spi_config_t &config,
+ boost::uint32_t data,
+ size_t num_bits
+){
+ _iface->transact_spi(unit_to_otw_spi_dev(unit), config, data, num_bits, false /*no rb*/);
+}
- //unload the data
- byte_vector_t ret(data.length/8); //bits to bytes
- ASSERT_THROW(ret.size() <= sizeof(data.data));
- std::copy(data_bytes, data_bytes+ret.size(), ret.begin());
- return ret;
+boost::uint32_t usrp_e_dboard_iface::read_write_spi(
+ unit_t unit,
+ const spi_config_t &config,
+ boost::uint32_t data,
+ size_t num_bits
+){
+ return _iface->transact_spi(unit_to_otw_spi_dev(unit), config, data, num_bits, true /*rb*/);
}
/***********************************************************************
@@ -165,7 +171,7 @@ dboard_interface::byte_vector_t usrp_e_dboard_interface::transact_spi(
**********************************************************************/
static const size_t max_i2c_data_bytes = 10;
-void usrp_e_dboard_interface::write_i2c(int i2c_addr, const byte_vector_t &buf){
+void usrp_e_dboard_iface::write_i2c(int i2c_addr, const byte_vector_t &buf){
//allocate some memory for this transaction
ASSERT_THROW(buf.size() <= max_i2c_data_bytes);
boost::uint8_t mem[sizeof(usrp_e_i2c) + max_i2c_data_bytes];
@@ -177,10 +183,10 @@ void usrp_e_dboard_interface::write_i2c(int i2c_addr, const byte_vector_t &buf){
std::copy(buf.begin(), buf.end(), data.data);
//call the spi ioctl
- _impl->ioctl(USRP_E_I2C_WRITE, &data);
+ _iface->ioctl(USRP_E_I2C_WRITE, &data);
}
-dboard_interface::byte_vector_t usrp_e_dboard_interface::read_i2c(int i2c_addr, size_t num_bytes){
+dboard_iface::byte_vector_t usrp_e_dboard_iface::read_i2c(int i2c_addr, size_t num_bytes){
//allocate some memory for this transaction
ASSERT_THROW(num_bytes <= max_i2c_data_bytes);
boost::uint8_t mem[sizeof(usrp_e_i2c) + max_i2c_data_bytes];
@@ -191,7 +197,7 @@ dboard_interface::byte_vector_t usrp_e_dboard_interface::read_i2c(int i2c_addr,
data.len = num_bytes;
//call the spi ioctl
- _impl->ioctl(USRP_E_I2C_READ, &data);
+ _iface->ioctl(USRP_E_I2C_READ, &data);
//unload the data
byte_vector_t ret(data.len);
@@ -203,10 +209,10 @@ dboard_interface::byte_vector_t usrp_e_dboard_interface::read_i2c(int i2c_addr,
/***********************************************************************
* Aux DAX/ADC
**********************************************************************/
-void usrp_e_dboard_interface::write_aux_dac(dboard_interface::unit_type_t unit, int which, int value){
+void usrp_e_dboard_iface::write_aux_dac(dboard_iface::unit_t unit, int which, float value){
throw std::runtime_error("not implemented");
}
-int usrp_e_dboard_interface::read_aux_adc(dboard_interface::unit_type_t unit, int which){
+float usrp_e_dboard_iface::read_aux_adc(dboard_iface::unit_t unit, int which){
throw std::runtime_error("not implemented");
}
diff --git a/host/lib/usrp/usrp_e/dboard_impl.cpp b/host/lib/usrp/usrp_e/dboard_impl.cpp
index 7c87361e0..df0f1d9a9 100644
--- a/host/lib/usrp/usrp_e/dboard_impl.cpp
+++ b/host/lib/usrp/usrp_e/dboard_impl.cpp
@@ -28,11 +28,11 @@ void usrp_e_impl::dboard_init(void){
dboard_id_t tx_dboard_id = dboard_id::NONE;
//create a new dboard interface and manager
- dboard_interface::sptr dboard_interface(
- make_usrp_e_dboard_interface(this)
+ dboard_iface::sptr dboard_iface(
+ make_usrp_e_dboard_iface(_iface)
);
_dboard_manager = dboard_manager::make(
- rx_dboard_id, tx_dboard_id, dboard_interface
+ rx_dboard_id, tx_dboard_id, dboard_iface
);
//setup the dboard proxies
diff --git a/host/lib/usrp/usrp_e/mboard_impl.cpp b/host/lib/usrp/usrp_e/mboard_impl.cpp
index ba15c394d..2d225c6ea 100644
--- a/host/lib/usrp/usrp_e/mboard_impl.cpp
+++ b/host/lib/usrp/usrp_e/mboard_impl.cpp
@@ -75,8 +75,8 @@ void usrp_e_impl::mboard_get(const wax::obj &key_, wax::obj &val){
val = prop_names_t(1, ""); //vector of size 1 with empty string
return;
- case MBOARD_PROP_CLOCK_RATE:
- //val = TODO probably remove this property
+ case MBOARD_PROP_STREAM_CMD:
+ //val = TODO
return;
case MBOARD_PROP_RX_DSP:
diff --git a/host/lib/usrp/usrp_e/usrp_e_iface.cpp b/host/lib/usrp/usrp_e/usrp_e_iface.cpp
new file mode 100644
index 000000000..d4c988211
--- /dev/null
+++ b/host/lib/usrp/usrp_e/usrp_e_iface.cpp
@@ -0,0 +1,135 @@
+//
+// 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 "usrp_e_iface.hpp"
+#include <sys/ioctl.h> //ioctl
+#include <linux/usrp_e.h> //ioctl structures and constants
+#include <boost/format.hpp>
+#include <stdexcept>
+
+class usrp_e_iface_impl : public usrp_e_iface{
+public:
+
+ /*******************************************************************
+ * Structors
+ ******************************************************************/
+ usrp_e_iface_impl(int node_fd){
+ _node_fd = node_fd;
+ }
+
+ ~usrp_e_iface_impl(void){
+ /* NOP */
+ }
+
+ /*******************************************************************
+ * IOCTL: provides the communication base for all other calls
+ ******************************************************************/
+ void ioctl(int request, void *mem){
+ if (::ioctl(_node_fd, request, mem) < 0){
+ throw std::runtime_error(str(
+ boost::format("ioctl failed with request %d") % request
+ ));
+ }
+ }
+
+ /*******************************************************************
+ * Peek and Poke
+ ******************************************************************/
+ void poke32(boost::uint32_t addr, boost::uint32_t value){
+ //load the data struct
+ usrp_e_ctl32 data;
+ data.offset = addr;
+ data.count = 1;
+ data.buf[0] = value;
+
+ //call the ioctl
+ this->ioctl(USRP_E_WRITE_CTL32, &data);
+ }
+
+ void poke16(boost::uint32_t addr, boost::uint16_t value){
+ //load the data struct
+ usrp_e_ctl16 data;
+ data.offset = addr;
+ data.count = 1;
+ data.buf[0] = value;
+
+ //call the ioctl
+ this->ioctl(USRP_E_WRITE_CTL16, &data);
+ }
+
+ boost::uint32_t peek32(boost::uint32_t addr){
+ //load the data struct
+ usrp_e_ctl32 data;
+ data.offset = addr;
+ data.count = 1;
+
+ //call the ioctl
+ this->ioctl(USRP_E_READ_CTL32, &data);
+
+ return data.buf[0];
+ }
+
+ boost::uint16_t peek16(boost::uint32_t addr){
+ //load the data struct
+ usrp_e_ctl16 data;
+ data.offset = addr;
+ data.count = 1;
+
+ //call the ioctl
+ this->ioctl(USRP_E_READ_CTL16, &data);
+
+ return data.buf[0];
+ }
+
+ /*******************************************************************
+ * SPI
+ ******************************************************************/
+ boost::uint32_t transact_spi(
+ int which_slave,
+ const uhd::usrp::spi_config_t &config,
+ boost::uint32_t bits,
+ size_t num_bits,
+ bool readback
+ ){
+ //load data struct
+ usrp_e_spi data;
+ data.readback = (readback)? UE_SPI_TXRX : UE_SPI_TXONLY;
+ data.slave = which_slave;
+ data.length = num_bits;
+ data.data = bits;
+
+ //load the flags
+ data.flags = 0;
+ data.flags |= (config.miso_edge == uhd::usrp::spi_config_t::EDGE_RISE)? UE_SPI_LATCH_RISE : UE_SPI_LATCH_FALL;
+ data.flags |= (config.mosi_edge == uhd::usrp::spi_config_t::EDGE_RISE)? UE_SPI_PUSH_FALL : UE_SPI_PUSH_RISE;
+
+ //call the spi ioctl
+ this->ioctl(USRP_E_SPI, &data);
+
+ //unload the data
+ return data.data;
+ }
+
+private: int _node_fd;
+};
+
+/***********************************************************************
+ * Public Make Function
+ **********************************************************************/
+usrp_e_iface::sptr usrp_e_iface::make(int node_fd){
+ return sptr(new usrp_e_iface_impl(node_fd));
+}
diff --git a/host/lib/usrp/usrp_e/usrp_e_iface.hpp b/host/lib/usrp/usrp_e/usrp_e_iface.hpp
new file mode 100644
index 000000000..4fc3bb33d
--- /dev/null
+++ b/host/lib/usrp/usrp_e/usrp_e_iface.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_USRP_E_IFACE_HPP
+#define INCLUDED_USRP_E_IFACE_HPP
+
+#include <uhd/transport/udp_simple.hpp>
+#include <uhd/usrp/dboard_iface.hpp> //spi config
+#include <boost/shared_ptr.hpp>
+#include <boost/utility.hpp>
+#include <boost/cstdint.hpp>
+
+/*!
+ * The usrp-e interface class:
+ * Provides a set of functions to implementation layer.
+ * Including spi, peek, poke, control...
+ */
+class usrp_e_iface : boost::noncopyable{
+public:
+ typedef boost::shared_ptr<usrp_e_iface> sptr;
+
+ /*!
+ * Make a new usrp-e interface with the control transport.
+ * \param node_fd the file descriptor for the kernel module node
+ * \return a new usrp-e interface object
+ */
+ static sptr make(int node_fd);
+
+ /*!
+ * Perform an ioctl call on the device node file descriptor.
+ * This will throw when the internal ioctl call fails.
+ * \param request the control word
+ * \param mem pointer to some memory
+ */
+ virtual void ioctl(int request, void *mem) = 0;
+
+ /*!
+ * Write a register (32 bits)
+ * \param addr the address
+ * \param data the 32bit data
+ */
+ virtual void poke32(boost::uint32_t addr, boost::uint32_t data) = 0;
+
+ /*!
+ * Read a register (32 bits)
+ * \param addr the address
+ * \return the 32bit data
+ */
+ virtual boost::uint32_t peek32(boost::uint32_t addr) = 0;
+
+ /*!
+ * Write a register (16 bits)
+ * \param addr the address
+ * \param data the 16bit data
+ */
+ virtual void poke16(boost::uint32_t addr, boost::uint16_t data) = 0;
+
+ /*!
+ * Read a register (16 bits)
+ * \param addr the address
+ * \return the 16bit data
+ */
+ virtual boost::uint16_t peek16(boost::uint32_t addr) = 0;
+
+ /*!
+ * Perform an spi transaction.
+ * \param which_slave the slave device number
+ * \param config spi config args
+ * \param data the bits to write
+ * \param num_bits how many bits in data
+ * \param readback true to readback a value
+ * \return spi data if readback set
+ */
+ virtual boost::uint32_t transact_spi(
+ int which_slave,
+ const uhd::usrp::spi_config_t &config,
+ boost::uint32_t data,
+ size_t num_bits,
+ bool readback
+ ) = 0;
+};
+
+#endif /* INCLUDED_USRP_E_IFACE_HPP */
diff --git a/host/lib/usrp/usrp_e/usrp_e_impl.cpp b/host/lib/usrp/usrp_e/usrp_e_impl.cpp
index 3fefd6787..4d08210e2 100644
--- a/host/lib/usrp/usrp_e/usrp_e_impl.cpp
+++ b/host/lib/usrp/usrp_e/usrp_e_impl.cpp
@@ -22,8 +22,6 @@
#include <boost/format.hpp>
#include <boost/filesystem.hpp>
#include <fcntl.h> //open
-#include <sys/ioctl.h> //ioctl
-#include <linux/usrp_e.h>
using namespace uhd;
using namespace uhd::usrp;
@@ -43,30 +41,24 @@ static std::string abs_path(const std::string &file_path){
/***********************************************************************
* Discovery
**********************************************************************/
-device_addrs_t usrp_e::find(const device_addr_t &device_addr){
+device_addrs_t usrp_e::find(const device_addr_t &hint){
device_addrs_t usrp_e_addrs;
- //if a node was provided, use it and only it
- if (device_addr.has_key("node")){
- if (not fs::exists(device_addr["node"])) return usrp_e_addrs;
+ //device node not provided, assume its 0
+ if (not hint.has_key("node")){
+ device_addr_t new_addr = hint;
+ new_addr["node"] = "/dev/usrp_e0";
+ return usrp_e::find(new_addr);
+ }
+
+ //use the given device node name
+ if (fs::exists(hint["node"])){
device_addr_t new_addr;
new_addr["name"] = "USRP-E";
- new_addr["node"] = abs_path(device_addr["node"]);
+ new_addr["node"] = abs_path(hint["node"]);
usrp_e_addrs.push_back(new_addr);
}
- //otherwise look for a few nodes at small indexes
- else{
- for(size_t i = 0; i < 5; i++){
- std::string node = str(boost::format("/dev/usrp1_e%d") % i);
- if (not fs::exists(node)) continue;
- device_addr_t new_addr;
- new_addr["name"] = "USRP-E";
- new_addr["node"] = abs_path(node);
- usrp_e_addrs.push_back(new_addr);
- }
- }
-
return usrp_e_addrs;
}
@@ -88,6 +80,8 @@ usrp_e_impl::usrp_e_impl(const std::string &node){
));
}
+ _iface = usrp_e_iface::make(_node_fd);
+
//initialize the mboard
mboard_init();
@@ -105,63 +99,6 @@ usrp_e_impl::~usrp_e_impl(void){
}
/***********************************************************************
- * Misc Methods
- **********************************************************************/
-void usrp_e_impl::ioctl(int request, void *mem){
- if (::ioctl(_node_fd, request, mem) < 0){
- throw std::runtime_error(str(
- boost::format("ioctl failed with request %d") % request
- ));
- }
-}
-
-void usrp_e_impl::poke32(boost::uint32_t addr, boost::uint32_t value){
- //load the data struct
- usrp_e_ctl32 data;
- data.offset = addr;
- data.count = 1;
- data.buf[0] = value;
-
- //call the ioctl
- this->ioctl(USRP_E_WRITE_CTL32, &data);
-}
-
-void usrp_e_impl::poke16(boost::uint32_t addr, boost::uint16_t value){
- //load the data struct
- usrp_e_ctl16 data;
- data.offset = addr;
- data.count = 1;
- data.buf[0] = value;
-
- //call the ioctl
- this->ioctl(USRP_E_WRITE_CTL16, &data);
-}
-
-boost::uint32_t usrp_e_impl::peek32(boost::uint32_t addr){
- //load the data struct
- usrp_e_ctl32 data;
- data.offset = addr;
- data.count = 1;
-
- //call the ioctl
- this->ioctl(USRP_E_READ_CTL32, &data);
-
- return data.buf[0];
-}
-
-boost::uint16_t usrp_e_impl::peek16(boost::uint32_t addr){
- //load the data struct
- usrp_e_ctl16 data;
- data.offset = addr;
- data.count = 1;
-
- //call the ioctl
- this->ioctl(USRP_E_READ_CTL16, &data);
-
- return data.buf[0];
-}
-
-/***********************************************************************
* Device Get
**********************************************************************/
void usrp_e_impl::get(const wax::obj &key_, wax::obj &val){
diff --git a/host/lib/usrp/usrp_e/usrp_e_impl.hpp b/host/lib/usrp/usrp_e/usrp_e_impl.hpp
index 21023ae55..08ace2ffb 100644
--- a/host/lib/usrp/usrp_e/usrp_e_impl.hpp
+++ b/host/lib/usrp/usrp_e/usrp_e_impl.hpp
@@ -15,21 +15,20 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#include <uhd/types/clock_config.hpp>
+#include "usrp_e_iface.hpp"
#include <uhd/usrp/usrp_e.hpp>
+#include <uhd/types/clock_config.hpp>
#include <uhd/usrp/dboard_manager.hpp>
#ifndef INCLUDED_USRP_E_IMPL_HPP
#define INCLUDED_USRP_E_IMPL_HPP
-class usrp_e_impl; // dummy class declaration
-
/*!
- * Make a usrp_e dboard interface.
- * \param impl a pointer to the usrp_e impl object
+ * Make a usrp-e dboard interface.
+ * \param iface the usrp-e interface object
* \return a sptr to a new dboard interface
*/
-uhd::usrp::dboard_interface::sptr make_usrp_e_dboard_interface(usrp_e_impl *impl);
+uhd::usrp::dboard_iface::sptr make_usrp_e_dboard_iface(usrp_e_iface::sptr iface);
/*!
* Simple wax obj proxy class:
@@ -84,22 +83,9 @@ public:
size_t send(const boost::asio::const_buffer &, const uhd::tx_metadata_t &, const uhd::io_type_t &);
size_t recv(const boost::asio::mutable_buffer &, uhd::rx_metadata_t &, const uhd::io_type_t &);
- /*!
- * Perform an ioctl call on the device node file descriptor.
- * This will throw when the internal ioctl call fails.
- * \param request the control word
- * \param mem pointer to some memory
- */
- void ioctl(int request, void *mem);
-
- //peekers and pokers
- void poke32(boost::uint32_t addr, boost::uint32_t value);
- void poke16(boost::uint32_t addr, boost::uint16_t value);
- boost::uint32_t peek32(boost::uint32_t addr);
- boost::uint16_t peek16(boost::uint32_t addr);
-
private:
static const size_t _max_num_samples = 2048/sizeof(boost::uint32_t);
+ usrp_e_iface::sptr _iface;
int _node_fd;
uhd::clock_config_t _clock_config;