diff options
Diffstat (limited to 'host/lib/usrp/usrp_e')
-rw-r--r-- | host/lib/usrp/usrp_e/dboard_iface.cpp | 42 | ||||
-rw-r--r-- | host/lib/usrp/usrp_e/dboard_impl.cpp | 8 | ||||
-rw-r--r-- | host/lib/usrp/usrp_e/dsp_impl.cpp | 8 | ||||
-rw-r--r-- | host/lib/usrp/usrp_e/mboard_impl.cpp | 15 | ||||
-rw-r--r-- | host/lib/usrp/usrp_e/usrp_e_iface.cpp | 49 | ||||
-rw-r--r-- | host/lib/usrp/usrp_e/usrp_e_iface.hpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/usrp_e/usrp_e_impl.cpp | 5 |
7 files changed, 73 insertions, 60 deletions
diff --git a/host/lib/usrp/usrp_e/dboard_iface.cpp b/host/lib/usrp/usrp_e/dboard_iface.cpp index 12e8fe206..f69cdd2b4 100644 --- a/host/lib/usrp/usrp_e/dboard_iface.cpp +++ b/host/lib/usrp/usrp_e/dboard_iface.cpp @@ -23,6 +23,7 @@ #include <boost/assign/list_of.hpp> #include <linux/usrp_e.h> //i2c and spi constants +using namespace uhd; using namespace uhd::usrp; class usrp_e_dboard_iface : public dboard_iface{ @@ -37,8 +38,8 @@ public: void set_gpio_ddr(unit_t, boost::uint16_t); boost::uint16_t read_gpio(unit_t); - void write_i2c(int, const byte_vector_t &); - byte_vector_t read_i2c(int, size_t); + void write_i2c(boost::uint8_t, const byte_vector_t &); + byte_vector_t read_i2c(boost::uint8_t, size_t); void write_spi( unit_t unit, @@ -169,41 +170,12 @@ boost::uint32_t usrp_e_dboard_iface::read_write_spi( /*********************************************************************** * I2C **********************************************************************/ -static const size_t max_i2c_data_bytes = 10; - -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]; - - //load the data struct - usrp_e_i2c &data = reinterpret_cast<usrp_e_i2c&>(mem); - data.addr = i2c_addr; - data.len = buf.size(); - std::copy(buf.begin(), buf.end(), data.data); - - //call the spi ioctl - _iface->ioctl(USRP_E_I2C_WRITE, &data); +void usrp_e_dboard_iface::write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){ + return _iface->write_i2c(addr, 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]; - - //load the data struct - usrp_e_i2c &data = reinterpret_cast<usrp_e_i2c&>(mem); - data.addr = i2c_addr; - data.len = num_bytes; - - //call the spi ioctl - _iface->ioctl(USRP_E_I2C_READ, &data); - - //unload the data - byte_vector_t ret(data.len); - ASSERT_THROW(ret.size() == num_bytes); - std::copy(data.data, data.data+ret.size(), ret.begin()); - return ret; +byte_vector_t usrp_e_dboard_iface::read_i2c(boost::uint8_t addr, size_t num_bytes){ + return _iface->read_i2c(addr, num_bytes); } /*********************************************************************** diff --git a/host/lib/usrp/usrp_e/dboard_impl.cpp b/host/lib/usrp/usrp_e/dboard_impl.cpp index df0f1d9a9..e87a2c0a5 100644 --- a/host/lib/usrp/usrp_e/dboard_impl.cpp +++ b/host/lib/usrp/usrp_e/dboard_impl.cpp @@ -50,26 +50,26 @@ void usrp_e_impl::dboard_init(void){ * RX Dboard Get **********************************************************************/ void usrp_e_impl::rx_dboard_get(const wax::obj &, wax::obj &){ - + UHD_THROW_PROP_GET_ERROR(); } /*********************************************************************** * RX Dboard Set **********************************************************************/ void usrp_e_impl::rx_dboard_set(const wax::obj &, const wax::obj &){ - + UHD_THROW_PROP_SET_ERROR(); } /*********************************************************************** * TX Dboard Get **********************************************************************/ void usrp_e_impl::tx_dboard_get(const wax::obj &, wax::obj &){ - + UHD_THROW_PROP_GET_ERROR(); } /*********************************************************************** * TX Dboard Set **********************************************************************/ void usrp_e_impl::tx_dboard_set(const wax::obj &, const wax::obj &){ - + UHD_THROW_PROP_SET_ERROR(); } diff --git a/host/lib/usrp/usrp_e/dsp_impl.cpp b/host/lib/usrp/usrp_e/dsp_impl.cpp index e32c76a3d..272ac71b3 100644 --- a/host/lib/usrp/usrp_e/dsp_impl.cpp +++ b/host/lib/usrp/usrp_e/dsp_impl.cpp @@ -34,14 +34,14 @@ void usrp_e_impl::rx_ddc_init(void){ * RX DDC Get **********************************************************************/ void usrp_e_impl::rx_ddc_get(const wax::obj &, wax::obj &){ - + UHD_THROW_PROP_GET_ERROR(); } /*********************************************************************** * RX DDC Set **********************************************************************/ void usrp_e_impl::rx_ddc_set(const wax::obj &, const wax::obj &){ - + UHD_THROW_PROP_SET_ERROR(); } /*********************************************************************** @@ -58,12 +58,12 @@ void usrp_e_impl::tx_duc_init(void){ * TX DUC Get **********************************************************************/ void usrp_e_impl::tx_duc_get(const wax::obj &, wax::obj &){ - + UHD_THROW_PROP_GET_ERROR(); } /*********************************************************************** * TX DUC Set **********************************************************************/ void usrp_e_impl::tx_duc_set(const wax::obj &, const wax::obj &){ - + UHD_THROW_PROP_SET_ERROR(); } diff --git a/host/lib/usrp/usrp_e/mboard_impl.cpp b/host/lib/usrp/usrp_e/mboard_impl.cpp index 2d225c6ea..00ce4b782 100644 --- a/host/lib/usrp/usrp_e/mboard_impl.cpp +++ b/host/lib/usrp/usrp_e/mboard_impl.cpp @@ -58,7 +58,7 @@ void usrp_e_impl::mboard_get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_RX_DBOARD: - ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(name == ""); val = _rx_dboard_proxy->get_link(); return; @@ -67,7 +67,7 @@ void usrp_e_impl::mboard_get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_TX_DBOARD: - ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(name == ""); val = _tx_dboard_proxy->get_link(); return; @@ -80,7 +80,7 @@ void usrp_e_impl::mboard_get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_RX_DSP: - ASSERT_THROW(name == "ddc0"); + UHD_ASSERT_THROW(name == "ddc0"); val = _rx_ddc_proxy->get_link(); return; @@ -89,7 +89,7 @@ void usrp_e_impl::mboard_get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_TX_DSP: - ASSERT_THROW(name == "duc0"); + UHD_ASSERT_THROW(name == "duc0"); val = _tx_duc_proxy->get_link(); return; @@ -101,10 +101,7 @@ void usrp_e_impl::mboard_get(const wax::obj &key_, wax::obj &val){ val = _clock_config; return; - case MBOARD_PROP_TIME_NOW: - case MBOARD_PROP_TIME_NEXT_PPS: - throw std::runtime_error("Error: trying to get write-only property on usrp-e mboard"); - + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -112,5 +109,5 @@ void usrp_e_impl::mboard_get(const wax::obj &key_, wax::obj &val){ * Mboard Set **********************************************************************/ void usrp_e_impl::mboard_set(const wax::obj &, const wax::obj &){ - + UHD_THROW_PROP_SET_ERROR(); } diff --git a/host/lib/usrp/usrp_e/usrp_e_iface.cpp b/host/lib/usrp/usrp_e/usrp_e_iface.cpp index d4c988211..41737a716 100644 --- a/host/lib/usrp/usrp_e/usrp_e_iface.cpp +++ b/host/lib/usrp/usrp_e/usrp_e_iface.cpp @@ -16,11 +16,14 @@ // #include "usrp_e_iface.hpp" +#include <uhd/utils/assert.hpp> #include <sys/ioctl.h> //ioctl #include <linux/usrp_e.h> //ioctl structures and constants #include <boost/format.hpp> #include <stdexcept> +using namespace uhd; + class usrp_e_iface_impl : public usrp_e_iface{ public: @@ -96,11 +99,51 @@ public: } /******************************************************************* + * I2C + ******************************************************************/ + static const size_t max_i2c_data_bytes = 10; + + void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){ + //allocate some memory for this transaction + UHD_ASSERT_THROW(bytes.size() <= max_i2c_data_bytes); + boost::uint8_t mem[sizeof(usrp_e_i2c) + max_i2c_data_bytes]; + + //load the data struct + usrp_e_i2c &data = reinterpret_cast<usrp_e_i2c&>(mem); + data.addr = addr; + data.len = bytes.size(); + std::copy(bytes.begin(), bytes.end(), data.data); + + //call the spi ioctl + this->ioctl(USRP_E_I2C_WRITE, &data); + } + + byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes){ + //allocate some memory for this transaction + UHD_ASSERT_THROW(num_bytes <= max_i2c_data_bytes); + boost::uint8_t mem[sizeof(usrp_e_i2c) + max_i2c_data_bytes]; + + //load the data struct + usrp_e_i2c &data = reinterpret_cast<usrp_e_i2c&>(mem); + data.addr = addr; + data.len = num_bytes; + + //call the spi ioctl + this->ioctl(USRP_E_I2C_READ, &data); + + //unload the data + byte_vector_t bytes(data.len); + UHD_ASSERT_THROW(bytes.size() == num_bytes); + std::copy(data.data, data.data+bytes.size(), bytes.begin()); + return bytes; + } + + /******************************************************************* * SPI ******************************************************************/ boost::uint32_t transact_spi( int which_slave, - const uhd::usrp::spi_config_t &config, + const spi_config_t &config, boost::uint32_t bits, size_t num_bits, bool readback @@ -114,8 +157,8 @@ public: //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; + data.flags |= (config.miso_edge == spi_config_t::EDGE_RISE)? UE_SPI_LATCH_RISE : UE_SPI_LATCH_FALL; + data.flags |= (config.mosi_edge == spi_config_t::EDGE_RISE)? UE_SPI_PUSH_FALL : UE_SPI_PUSH_RISE; //call the spi ioctl this->ioctl(USRP_E_SPI, &data); diff --git a/host/lib/usrp/usrp_e/usrp_e_iface.hpp b/host/lib/usrp/usrp_e/usrp_e_iface.hpp index 4fc3bb33d..763d19581 100644 --- a/host/lib/usrp/usrp_e/usrp_e_iface.hpp +++ b/host/lib/usrp/usrp_e/usrp_e_iface.hpp @@ -19,7 +19,7 @@ #define INCLUDED_USRP_E_IFACE_HPP #include <uhd/transport/udp_simple.hpp> -#include <uhd/usrp/dboard_iface.hpp> //spi config +#include <uhd/types/serial.hpp> #include <boost/shared_ptr.hpp> #include <boost/utility.hpp> #include <boost/cstdint.hpp> @@ -29,7 +29,7 @@ * Provides a set of functions to implementation layer. * Including spi, peek, poke, control... */ -class usrp_e_iface : boost::noncopyable{ +class usrp_e_iface : boost::noncopyable, public uhd::i2c_iface{ public: typedef boost::shared_ptr<usrp_e_iface> sptr; @@ -87,7 +87,7 @@ public: */ virtual boost::uint32_t transact_spi( int which_slave, - const uhd::usrp::spi_config_t &config, + const uhd::spi_config_t &config, boost::uint32_t data, size_t num_bits, bool readback diff --git a/host/lib/usrp/usrp_e/usrp_e_impl.cpp b/host/lib/usrp/usrp_e/usrp_e_impl.cpp index 4d08210e2..211b939ee 100644 --- a/host/lib/usrp/usrp_e/usrp_e_impl.cpp +++ b/host/lib/usrp/usrp_e/usrp_e_impl.cpp @@ -112,7 +112,7 @@ void usrp_e_impl::get(const wax::obj &key_, wax::obj &val){ return; case DEVICE_PROP_MBOARD: - ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(name == ""); val = _mboard_proxy->get_link(); return; @@ -128,6 +128,7 @@ void usrp_e_impl::get(const wax::obj &key_, wax::obj &val){ val = size_t(_max_num_samples); return; + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -135,7 +136,7 @@ void usrp_e_impl::get(const wax::obj &key_, wax::obj &val){ * Device Set **********************************************************************/ void usrp_e_impl::set(const wax::obj &, const wax::obj &){ - throw std::runtime_error("Cannot set in usrp-e device"); + UHD_THROW_PROP_SET_ERROR(); } /*********************************************************************** |