summaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorNick Foster <nick@nerdnetworks.org>2011-03-03 10:50:45 -0800
committerNick Foster <nick@nerdnetworks.org>2011-03-03 10:50:45 -0800
commit1b63cd2560886d851f3e2ba98bfddf772c44df34 (patch)
tree126e1bedf44c3e9159c8ab7b2dd1ad52452ea6a0 /host/include
parent77319389b09c663170284ed64961ab27cf77488e (diff)
downloaduhd-1b63cd2560886d851f3e2ba98bfddf772c44df34.tar.gz
uhd-1b63cd2560886d851f3e2ba98bfddf772c44df34.tar.bz2
uhd-1b63cd2560886d851f3e2ba98bfddf772c44df34.zip
Generalized mboard_iface and added a SPI convenience class a la I2C
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/types/serial.hpp59
-rw-r--r--host/include/uhd/usrp/CMakeLists.txt1
-rw-r--r--host/include/uhd/usrp/mboard_iface.hpp20
-rw-r--r--host/include/uhd/usrp/mboard_props.hpp3
-rw-r--r--host/include/uhd/usrp/multi_usrp.hpp7
5 files changed, 71 insertions, 19 deletions
diff --git a/host/include/uhd/types/serial.hpp b/host/include/uhd/types/serial.hpp
index c134725f5..9b203324b 100644
--- a/host/include/uhd/types/serial.hpp
+++ b/host/include/uhd/types/serial.hpp
@@ -116,6 +116,65 @@ namespace uhd{
*/
spi_config_t(edge_t edge = EDGE_RISE);
};
+
+ /*!
+ * The SPI interface class.
+ * Provides routines to transact SPI and do other useful things which haven't been defined yet.
+ */
+ class UHD_API spi_iface{
+ public:
+ /*!
+ * Perform a 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::spi_config_t &config,
+ boost::uint32_t data,
+ size_t num_bits,
+ bool readback
+ ) = 0;
+
+ /*!
+ * Read from the SPI bus.
+ * \param which_slave the slave device number
+ * \param config spi config args
+ * \param data the bits to write out (be sure to set write bit)
+ * \param num_bits how many bits in data
+ * \return spi data
+ */
+ boost::uint32_t read_spi(
+ int which_slave,
+ const uhd::spi_config_t &config,
+ boost::uint16_t data,
+ size_t num_bits) {
+ return transact_spi(
+ which_slave, config, data, num_bits, true
+ );
+ }
+
+ /*!
+ * Write to the SPI bus.
+ * \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
+ */
+ void write_spi(
+ int which_slave,
+ const uhd::spi_config_t &config,
+ boost::uint16_t data,
+ size_t num_bits) {
+ transact_spi(
+ which_slave, config, data, num_bits, false
+ );
+ }
+ };
} //namespace uhd
diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt
index f60b35e59..59a1302af 100644
--- a/host/include/uhd/usrp/CMakeLists.txt
+++ b/host/include/uhd/usrp/CMakeLists.txt
@@ -43,6 +43,7 @@ INSTALL(FILES
### interfaces ###
single_usrp.hpp
multi_usrp.hpp
+ mboard_iface.hpp
DESTINATION ${INCLUDE_DIR}/uhd/usrp
)
diff --git a/host/include/uhd/usrp/mboard_iface.hpp b/host/include/uhd/usrp/mboard_iface.hpp
index 4924bc99b..cfd273232 100644
--- a/host/include/uhd/usrp/mboard_iface.hpp
+++ b/host/include/uhd/usrp/mboard_iface.hpp
@@ -33,8 +33,9 @@ namespace uhd{ namespace usrp{
* Provides a set of functions to implementation layer.
* Including spi, peek, poke, control...
*/
-class mboard_iface : public uhd::i2c_iface {
+class mboard_iface : public uhd::i2c_iface, public uhd::spi_iface {
public:
+ typedef boost::shared_ptr<mboard_iface> sptr;
/*!
* Write a register (32 bits)
* \param addr the address
@@ -64,23 +65,6 @@ public:
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::spi_config_t &config,
- boost::uint32_t data,
- size_t num_bits,
- bool readback
- ) = 0;
-
- /*!
* Write to a serial port.
* \param dev which UART to write to
* \param buf the data to write
diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp
index 180c4eeb3..a2580954e 100644
--- a/host/include/uhd/usrp/mboard_props.hpp
+++ b/host/include/uhd/usrp/mboard_props.hpp
@@ -47,7 +47,8 @@ namespace uhd{ namespace usrp{
MBOARD_PROP_CLOCK_CONFIG, //rw, clock_config_t
MBOARD_PROP_TIME_NOW, //rw, time_spec_t
MBOARD_PROP_TIME_PPS, //wo, time_spec_t
- MBOARD_PROP_EEPROM_MAP //wr, mboard_eeprom_t
+ MBOARD_PROP_EEPROM_MAP, //wr, mboard_eeprom_t
+ MBOARD_PROP_IFACE, //ro, mboard_iface::sptr
};
}} //namespace
diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp
index b06975b6c..b161d1278 100644
--- a/host/include/uhd/usrp/multi_usrp.hpp
+++ b/host/include/uhd/usrp/multi_usrp.hpp
@@ -28,6 +28,7 @@
#include <uhd/types/sensors.hpp>
#include <uhd/usrp/subdev_spec.hpp>
#include <uhd/usrp/dboard_iface.hpp>
+#include <uhd/usrp/mboard_iface.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <vector>
@@ -250,6 +251,12 @@ public:
* \return a vector of sensor names
*/
virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0;
+
+ /*!
+ * Get a handle to the mboard_iface object which controls peripheral access.
+ * \return a mboard_iface::sptr object
+ */
+ virtual mboard_iface::sptr get_mboard_iface(size_t mboard) = 0;
/*******************************************************************
* RX methods