summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-04-12 16:10:29 -0700
committerJosh Blum <josh@joshknows.com>2010-04-12 16:10:29 -0700
commit40c231937e1ab4fb70ffb241a5ddb2455db0e907 (patch)
treee0537029f17c532797534239e13df4b2875f33fc
parentb87d9afe82e962718f5f5d514abf9d79b9603b98 (diff)
downloaduhd-40c231937e1ab4fb70ffb241a5ddb2455db0e907.tar.gz
uhd-40c231937e1ab4fb70ffb241a5ddb2455db0e907.tar.bz2
uhd-40c231937e1ab4fb70ffb241a5ddb2455db0e907.zip
moved spi transact to usrp2 impl, and removed spi read
-rw-r--r--host/include/uhd/usrp/dboard_interface.hpp68
-rw-r--r--host/lib/usrp/dboard/db_rfx.cpp2
-rw-r--r--host/lib/usrp/usrp2/dboard_interface.cpp60
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp32
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp9
5 files changed, 80 insertions, 91 deletions
diff --git a/host/include/uhd/usrp/dboard_interface.hpp b/host/include/uhd/usrp/dboard_interface.hpp
index dab5a2281..43fd1f143 100644
--- a/host/include/uhd/usrp/dboard_interface.hpp
+++ b/host/include/uhd/usrp/dboard_interface.hpp
@@ -25,6 +25,33 @@
namespace uhd{ namespace usrp{
+//spi configuration struct
+struct UHD_API spi_config_t{
+ /*!
+ * The edge type specifies when data is valid
+ * relative to the edge of the serial clock.
+ */
+ enum edge_t{
+ EDGE_RISE = 'r',
+ EDGE_FALL = 'f'
+ };
+
+ //! on what edge is the mosi data valid?
+ edge_t mosi_edge;
+
+ //! on what edge is the miso data valid?
+ edge_t miso_edge;
+
+ /*!
+ * Create a new spi config.
+ * \param edge the default edge for mosi and miso
+ */
+ spi_config_t(edge_t edge = EDGE_RISE){
+ mosi_edge = edge;
+ miso_edge = edge;
+ }
+};
+
/*!
* The daughter board dboard_interface to be subclassed.
* A dboard instance dboard_interfaces with the mboard though this api.
@@ -42,33 +69,6 @@ public:
UNIT_TYPE_TX = 't'
};
- //spi configuration struct
- struct UHD_API spi_config_t{
- /*!
- * The edge type specifies when data is valid
- * relative to the edge of the serial clock.
- */
- enum edge_t{
- EDGE_RISE = 'r',
- EDGE_FALL = 'f'
- };
-
- //! on what edge is the mosi data valid?
- edge_t mosi_edge;
-
- //! on what edge is the miso data valid?
- edge_t miso_edge;
-
- /*!
- * Create a new spi config.
- * \param edge the default edge for mosi and miso
- */
- spi_config_t(edge_t edge = EDGE_RISE){
- mosi_edge = edge;
- miso_edge = edge;
- }
- };
-
//tell the host which gpio bank
enum gpio_bank_t{
GPIO_BANK_RX = 'r',
@@ -155,20 +155,6 @@ public:
) = 0;
/*!
- * \brief Read data to SPI bus peripheral.
- *
- * \param unit which unit, rx or tx
- * \param config configuration settings
- * \param num_bits the number of bits
- * \return the data that was read
- */
- virtual boost::uint32_t read_spi(
- unit_type_t unit,
- const spi_config_t &config,
- size_t num_bits
- ) = 0;
-
- /*!
* \brief Read and write data to SPI bus peripheral.
* The data read back will be the same length as the input buffer.
*
diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp
index 68fa51144..4bf931660 100644
--- a/host/lib/usrp/dboard/db_rfx.cpp
+++ b/host/lib/usrp/dboard/db_rfx.cpp
@@ -138,7 +138,7 @@ void rfx_xcvr::reload_adf4360_regs(void){
BOOST_FOREACH(adf4360_regs_t::addr_t addr, addrs){
this->get_interface()->write_spi(
dboard_interface::UNIT_TYPE_TX,
- dboard_interface::spi_config_t::EDGE_RISE,
+ spi_config_t::EDGE_RISE,
_adf4360_regs.get_reg(addr), 24
);
}
diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp
index eee7c087a..d10cfa37e 100644
--- a/host/lib/usrp/usrp2/dboard_interface.cpp
+++ b/host/lib/usrp/usrp2/dboard_interface.cpp
@@ -47,32 +47,16 @@ public:
const spi_config_t &config,
boost::uint32_t data,
size_t num_bits
- ){
- transact_spi(unit, config, data, num_bits, false /*no rb*/);
- }
-
- boost::uint32_t read_spi(
- unit_type_t unit,
- const spi_config_t &config,
- size_t num_bits
- ){
- return transact_spi(unit, config, 0, num_bits, true /*rb*/);
- }
+ );
boost::uint32_t read_write_spi(
unit_type_t unit,
const spi_config_t &config,
boost::uint32_t data,
size_t num_bits
- ){
- return transact_spi(unit, config, data, num_bits, true /*rb*/);
- }
-
-private:
- boost::uint32_t transact_spi(
- unit_type_t, const spi_config_t &, boost::uint32_t, size_t, bool
);
+private:
usrp2_impl *_impl;
boost::uint32_t _ddr_shadow;
};
@@ -175,42 +159,22 @@ static boost::uint8_t unit_to_otw_dev(dboard_interface::unit_type_t unit){
throw std::invalid_argument("unknown unit type type");
}
-/*!
- * Static function to convert a spi edge enum
- * to an over-the-wire value for the usrp2 control.
- * \param edge the dboard interface spi edge enum
- * \return an over the wire representation
- */
-static boost::uint8_t spi_edge_to_otw(dboard_interface::spi_config_t::edge_t edge){
- switch(edge){
- case dboard_interface::spi_config_t::EDGE_RISE: return USRP2_CLK_EDGE_RISE;
- case dboard_interface::spi_config_t::EDGE_FALL: return USRP2_CLK_EDGE_FALL;
- }
- throw std::invalid_argument("unknown spi edge type");
+void usrp2_dboard_interface::write_spi(
+ unit_type_t unit,
+ const spi_config_t &config,
+ boost::uint32_t data,
+ size_t num_bits
+){
+ _impl->transact_spi(unit_to_otw_dev(unit), config, data, num_bits, false /*no rb*/);
}
-boost::uint32_t usrp2_dboard_interface::transact_spi(
+boost::uint32_t usrp2_dboard_interface::read_write_spi(
unit_type_t unit,
const spi_config_t &config,
boost::uint32_t data,
- size_t num_bits,
- bool readback
+ size_t num_bits
){
- //setup the out data
- usrp2_ctrl_data_t out_data;
- out_data.id = htonl(USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO);
- out_data.data.spi_args.dev = unit_to_otw_dev(unit);
- out_data.data.spi_args.miso_edge = spi_edge_to_otw(config.miso_edge);
- out_data.data.spi_args.mosi_edge = spi_edge_to_otw(config.mosi_edge);
- out_data.data.spi_args.readback = (readback)? 1 : 0;
- out_data.data.spi_args.num_bits = num_bits;
- out_data.data.spi_args.data = htonl(data);
-
- //send and recv
- usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data);
- ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE);
-
- return ntohl(out_data.data.spi_args.data);
+ return _impl->transact_spi(unit_to_otw_dev(unit), config, data, num_bits, true /*rb*/);
}
/***********************************************************************
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index a7be2da8c..6d8c1a86c 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -15,15 +15,16 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
+#include "usrp2_impl.hpp"
#include <uhd/transport/if_addrs.hpp>
#include <uhd/usrp/device_props.hpp>
#include <uhd/utils/assert.hpp>
#include <uhd/utils/static.hpp>
+#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
#include <iostream>
-#include "usrp2_impl.hpp"
using namespace uhd;
using namespace uhd::usrp;
@@ -217,6 +218,35 @@ boost::uint16_t usrp2_impl::peek16(boost::uint32_t addr){
return impl_peek<boost::uint16_t>(this, addr);
}
+boost::uint32_t usrp2_impl::transact_spi(
+ int which_slave,
+ const spi_config_t &config,
+ boost::uint32_t data,
+ size_t num_bits,
+ bool readback
+){
+ static const uhd::dict<spi_config_t::edge_t, int> spi_edge_to_otw = boost::assign::map_list_of
+ (spi_config_t::EDGE_RISE, USRP2_CLK_EDGE_RISE)
+ (spi_config_t::EDGE_FALL, USRP2_CLK_EDGE_FALL)
+ ;
+
+ //setup the out data
+ usrp2_ctrl_data_t out_data;
+ out_data.id = htonl(USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO);
+ out_data.data.spi_args.dev = which_slave;
+ out_data.data.spi_args.miso_edge = spi_edge_to_otw[config.miso_edge];
+ out_data.data.spi_args.mosi_edge = spi_edge_to_otw[config.mosi_edge];
+ out_data.data.spi_args.readback = (readback)? 1 : 0;
+ out_data.data.spi_args.num_bits = num_bits;
+ out_data.data.spi_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_TRANSACTED_SPI_DUDE);
+
+ return ntohl(out_data.data.spi_args.data);
+}
+
/***********************************************************************
* Control Send/Recv
**********************************************************************/
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index 4e7154afa..5a02b33dc 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -110,6 +110,15 @@ public:
void poke16(boost::uint32_t addr, boost::uint16_t data);
boost::uint16_t peek16(boost::uint32_t addr);
+ //spi read and write
+ 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
+ );
+
//misc access methods
double get_master_clock_freq(void);