aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/lib/lmk04828
diff options
context:
space:
mode:
Diffstat (limited to 'mpm/lib/lmk04828')
-rw-r--r--mpm/lib/lmk04828/CMakeLists.txt47
-rw-r--r--mpm/lib/lmk04828/lmk04828_spi_iface.cpp43
2 files changed, 90 insertions, 0 deletions
diff --git a/mpm/lib/lmk04828/CMakeLists.txt b/mpm/lib/lmk04828/CMakeLists.txt
new file mode 100644
index 000000000..4235cb34a
--- /dev/null
+++ b/mpm/lib/lmk04828/CMakeLists.txt
@@ -0,0 +1,47 @@
+MACRO(ETTUS_PYTHON_GEN_SOURCE pyfile outfile)
+ #ensure that the directory exists for outfile
+ GET_FILENAME_COMPONENT(outfile_dir ${outfile} PATH)
+ FILE(MAKE_DIRECTORY ${outfile_dir})
+
+ #make the outfile depend on the python script
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${outfile} DEPENDS ${pyfile} ${ETTUS_PYTHON_GEN_SOURCE_DEPS}
+ COMMAND ${PYTHON_EXECUTABLE} -B ${pyfile} ${outfile}
+ COMMENT "Generating ${outfile}"
+ )
+
+ #make lmk04828 depend on the outfile
+ LIST(APPEND lmk04828_srcs ${ARGV})
+ENDMACRO(ETTUS_PYTHON_GEN_SOURCE)
+
+####################################################
+# LMK04828
+####################################################
+
+# Register definitions need to be generated
+SET(UHD_HOST_ROOT ${CMAKE_SOURCE_DIR}/../host)
+MESSAGE("uhd host root: ${UHD_HOST_ROOT}")
+SET(UHD_IC_REG_MAP_PATH ${UHD_HOST_ROOT}/lib/ic_reg_maps)
+
+SET(ETTUS_PYTHON_GEN_SOURCE_DEPS ${UHD_IC_REG_MAP_PATH}/common.py)
+ETTUS_PYTHON_GEN_SOURCE(
+ ${UHD_IC_REG_MAP_PATH}/gen_lmk04828_regs.py
+ ${CMAKE_CURRENT_BINARY_DIR}/lmk04828_regs.hpp
+)
+SET(LIBUHD_PYTHON_GEN_SOURCE_DEPS)
+
+
+# LMK04828 driver files
+LIST(APPEND lmk04828_srcs
+ ${UHD_HOST_ROOT}/lib/usrp/common/lmk04828.cpp
+ ${UHD_HOST_ROOT}/lib/types/serial.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/lmk04828_spi_iface.cpp
+ )
+
+# Extra files needed
+LIST(APPEND lmk04828_srcs ${UHD_HOST_ROOT}/lib/exception.cpp)
+
+# For include/uhd/exception.hpp and include/uhd/config.h
+
+USRP_PERIPHS_ADD_OBJECT(lmk04828 ${lmk04828_srcs})
+TARGET_INCLUDE_DIRECTORIES(lmk04828 PUBLIC ${UHD_HOST_ROOT}/include ${CMAKE_CURRENT_BINARY_DIR} ${UHD_HOST_ROOT}/lib/usrp/common)
diff --git a/mpm/lib/lmk04828/lmk04828_spi_iface.cpp b/mpm/lib/lmk04828/lmk04828_spi_iface.cpp
new file mode 100644
index 000000000..e281467e1
--- /dev/null
+++ b/mpm/lib/lmk04828/lmk04828_spi_iface.cpp
@@ -0,0 +1,43 @@
+#include "lmk/lmk04828_spi_iface.hpp"
+#include "uhd/exception.hpp"
+#include <boost/bind.hpp>
+
+lmk04828_spi_iface::lmk04828_spi_iface(uhd::spi_iface::sptr iface) : _spi_iface(iface)
+ {
+ // Use default SPI Config options
+ config = uhd::spi_config_t(uhd::spi_config_t::EDGE_RISE);
+ }
+
+lmk04828_iface::write_fn_t lmk04828_spi_iface::get_write_fn()
+ {
+ return boost::bind(&lmk04828_spi_iface::spi_write, this, _1);
+ }
+
+lmk04828_iface::read_fn_t lmk04828_spi_iface::get_read_fn()
+ {
+ return boost::bind(&lmk04828_spi_iface::spi_read, this, _1);
+ }
+
+void lmk04828_spi_iface::spi_write(std::vector<uint32_t> writes) {
+ for (uint32_t write : writes) {
+ _spi_iface->write_spi(DEFAULT_SLAVE, config, write, LMK_SPI_NUM_BITS);
+ }
+ }
+
+uint8_t lmk04828_spi_iface::spi_read(uint32_t addr) {
+ // Format LMK SPI read transaction
+ // r/w[23] 0[22:21] addr[20:8] data[7:0] = 24 bits
+ uint32_t transaction = 0;
+ transaction |= LMK_SPI_READ_FLAG << LMK_SPI_READ_FLAG_OFFSET;
+ transaction &= LMK_SPI_RESERVED_FIELD_MASK;
+ transaction |= addr << LMK_SPI_READ_ADDR_OFFSET;
+
+ uint32_t data = _spi_iface->read_spi(DEFAULT_SLAVE, config, transaction, LMK_SPI_NUM_BITS);
+
+ if ((data & 0xFFFFFF00) != 0) {
+ // There's more than 8 bits of data!
+ throw uhd::runtime_error("LMK SPI read returned too much data");
+ }
+
+ return data & 0xFF;
+ }