diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-05-11 16:18:24 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:53 -0800 |
commit | 8ebd4d8e5fbfdc612ad5dd8ec212c76bd8cf4ed6 (patch) | |
tree | 2f87c6dd3e27aa454c0bbeb45a0da7e0de08ef74 | |
parent | b39dafa1eebf327a8bbd3959a3c54e85707b56aa (diff) | |
download | uhd-8ebd4d8e5fbfdc612ad5dd8ec212c76bd8cf4ed6.tar.gz uhd-8ebd4d8e5fbfdc612ad5dd8ec212c76bd8cf4ed6.tar.bz2 uhd-8ebd4d8e5fbfdc612ad5dd8ec212c76bd8cf4ed6.zip |
mpm: spi: Added 16-bit access to SPI regs
-rw-r--r-- | mpm/include/mpm/types/regs_iface.hpp | 13 | ||||
-rw-r--r-- | mpm/include/mpm/types/types_python.hpp | 2 | ||||
-rw-r--r-- | mpm/lib/spi/spi_regs_iface.cpp | 31 |
3 files changed, 45 insertions, 1 deletions
diff --git a/mpm/include/mpm/types/regs_iface.hpp b/mpm/include/mpm/types/regs_iface.hpp index 78e590b23..80005a4b0 100644 --- a/mpm/include/mpm/types/regs_iface.hpp +++ b/mpm/include/mpm/types/regs_iface.hpp @@ -41,6 +41,19 @@ namespace mpm { namespace types { const uint32_t addr, const uint8_t data ) = 0; + + /*! Return a 16-bit value from a given address + */ + virtual uint16_t peek16( + const uint32_t addr + ) = 0; + + /*! Write a 16-bit value to a given address + */ + virtual void poke16( + const uint32_t addr, + const uint16_t data + ) = 0; }; }}; /* namespace mpm::regs */ diff --git a/mpm/include/mpm/types/types_python.hpp b/mpm/include/mpm/types/types_python.hpp index a0a00aa48..ef31408e7 100644 --- a/mpm/include/mpm/types/types_python.hpp +++ b/mpm/include/mpm/types/types_python.hpp @@ -31,6 +31,8 @@ void export_types() { bp::class_<regs_iface, boost::noncopyable, std::shared_ptr<regs_iface> >("regs_iface", bp::no_init) .def("peek8", ®s_iface::peek8) .def("poke8", ®s_iface::poke8) + .def("peek16", ®s_iface::peek16) + .def("poke16", ®s_iface::poke16) ; } diff --git a/mpm/lib/spi/spi_regs_iface.cpp b/mpm/lib/spi/spi_regs_iface.cpp index ab9e089f8..40b376ee1 100644 --- a/mpm/lib/spi/spi_regs_iface.cpp +++ b/mpm/lib/spi/spi_regs_iface.cpp @@ -58,7 +58,7 @@ public: throw mpm::runtime_error("SPI read returned too much data"); } - return uint8_t(data & 0xFF); + return data; } void poke8( @@ -74,6 +74,35 @@ public: _spi_iface->transfer24_8(transaction); } + uint16_t peek16( + const uint32_t addr + ) { + uint32_t transaction = 0 + | (addr << _addr_shift) + | _read_flags + ; + + uint32_t data = _spi_iface->transfer24_8(transaction); + if ((data & 0xFFFF0000) != 0) { + throw mpm::runtime_error("SPI read returned too much data"); + } + + return data; + } + + void poke16( + const uint32_t addr, + const uint16_t data + ) { + uint32_t transaction = 0 + | _write_flags + | (addr << _addr_shift) + | (data << _data_shift) + ; + + _spi_iface->transfer24_8(transaction); + } + private: mpm::spi::spi_iface::sptr _spi_iface; |