aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mpm/dboards/magnesium_manager.cpp4
-rw-r--r--mpm/include/mpm/ad937x/ad937x_ctrl.hpp2
-rw-r--r--mpm/include/mpm/ad937x/adi_ctrl.hpp1
-rw-r--r--mpm/include/mpm/dboards/magnesium_manager.hpp2
-rw-r--r--mpm/lib/mykonos/ad937x_ctrl.cpp36
-rw-r--r--mpm/lib/spi/CMakeLists.txt3
-rw-r--r--mpm/lib/spi/mock_spi.cpp117
-rw-r--r--mpm/lib/spi/spi_config.cpp37
-rw-r--r--mpm/lib/spi/spi_config.h44
-rw-r--r--mpm/lib/spi/spi_lock.cpp26
10 files changed, 22 insertions, 250 deletions
diff --git a/mpm/dboards/magnesium_manager.cpp b/mpm/dboards/magnesium_manager.cpp
index 92f196a9f..d5e07d1e0 100644
--- a/mpm/dboards/magnesium_manager.cpp
+++ b/mpm/dboards/magnesium_manager.cpp
@@ -23,10 +23,10 @@ using namespace mpm::dboards;
magnesium_periph_manager::magnesium_periph_manager(
std::string lmk_spidev, std::string mykonos_spidev
- ): _spi_lock(spi_lock::make(std::rand()))
+ ): _spi_mutex(std::make_shared<std::mutex>())
{
_clock_spi = lmk04828_spi_iface::make(mpm::spi::spidev_iface::make(lmk_spidev));
_clock_ctrl = lmk04828_iface::make(_clock_spi->get_write_fn(), _clock_spi->get_read_fn());
_mykonos_spi = mpm::spi::spidev_iface::make(mykonos_spidev);
- _mykonos_ctrl = ad937x_ctrl::make(_spi_lock, _mykonos_spi);
+ _mykonos_ctrl = ad937x_ctrl::make(_spi_mutex, _mykonos_spi);
};
diff --git a/mpm/include/mpm/ad937x/ad937x_ctrl.hpp b/mpm/include/mpm/ad937x/ad937x_ctrl.hpp
index 10cbb0717..43ed37a94 100644
--- a/mpm/include/mpm/ad937x/ad937x_ctrl.hpp
+++ b/mpm/include/mpm/ad937x/ad937x_ctrl.hpp
@@ -33,7 +33,7 @@ class ad937x_ctrl : public boost::noncopyable
{
public:
typedef std::shared_ptr<ad937x_ctrl> sptr;
- static sptr make(spi_lock::sptr spi_l, uhd::spi_iface::sptr iface);
+ static sptr make(std::shared_ptr<std::mutex> spi_mutex, uhd::spi_iface::sptr iface);
virtual ~ad937x_ctrl(void) {}
static uhd::meta_range_t get_rf_freq_range(void);
diff --git a/mpm/include/mpm/ad937x/adi_ctrl.hpp b/mpm/include/mpm/ad937x/adi_ctrl.hpp
index d2514a321..616f59ea4 100644
--- a/mpm/include/mpm/ad937x/adi_ctrl.hpp
+++ b/mpm/include/mpm/ad937x/adi_ctrl.hpp
@@ -17,7 +17,6 @@
#pragma once
-// TODO: fix path of UHD include
#include <uhd/types/serial.hpp>
#include <chrono>
diff --git a/mpm/include/mpm/dboards/magnesium_manager.hpp b/mpm/include/mpm/dboards/magnesium_manager.hpp
index 356727618..be8f9f8e8 100644
--- a/mpm/include/mpm/dboards/magnesium_manager.hpp
+++ b/mpm/include/mpm/dboards/magnesium_manager.hpp
@@ -39,7 +39,7 @@ namespace mpm { namespace dboards {
private:
//cpld control
- spi_lock::sptr _spi_lock;
+ std::shared_ptr<std::mutex> _spi_mutex;
lmk04828_spi_iface::sptr _clock_spi;
lmk04828_iface::sptr _clock_ctrl;
mpm::spi::spidev_iface::sptr _mykonos_spi;
diff --git a/mpm/lib/mykonos/ad937x_ctrl.cpp b/mpm/lib/mykonos/ad937x_ctrl.cpp
index 047c8ba46..b0777091f 100644
--- a/mpm/lib/mykonos/ad937x_ctrl.cpp
+++ b/mpm/lib/mykonos/ad937x_ctrl.cpp
@@ -105,8 +105,8 @@ uhd::meta_range_t ad937x_ctrl::get_gain_range(const std::string &which)
class ad937x_ctrl_impl : public ad937x_ctrl
{
public:
- ad937x_ctrl_impl(spi_lock::sptr spi_l, uhd::spi_iface::sptr iface) :
- spi_l(spi_l),
+ ad937x_ctrl_impl(std::shared_ptr<std::mutex> spi_mutex, uhd::spi_iface::sptr iface) :
+ spi_mutex(spi_mutex),
device(iface)
{
@@ -114,18 +114,18 @@ public:
virtual uint8_t get_product_id()
{
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
return device.get_product_id();
}
virtual uint8_t get_device_rev()
{
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
return device.get_device_rev();
}
virtual std::string get_api_version()
{
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
auto api = device.get_api_version();
std::ostringstream ss;
ss << api.silicon_ver << "."
@@ -137,7 +137,7 @@ public:
virtual std::string get_arm_version()
{
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
auto arm = device.get_arm_version();
std::ostringstream ss;
ss << arm.major_ver << "."
@@ -157,7 +157,7 @@ public:
auto dir = _get_direction_from_antenna(which);
auto chain = _get_chain_from_antenna(which);
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
return device.set_gain(dir, chain, value);
}
@@ -184,7 +184,7 @@ public:
throw uhd::runtime_error("invalid agc mode");
}
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
device.set_agc_mode(dir, gain_mode);
}
@@ -196,7 +196,7 @@ public:
value = *(rates.cbegin());
}
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
return device.set_clock_rate(value);
}
@@ -205,7 +205,7 @@ public:
auto dir = _get_direction_from_antenna(which);
auto chain = _get_chain_from_antenna(which);
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
return device.enable_channel(dir, chain, enable);
}
@@ -214,7 +214,7 @@ public:
auto dir = _get_direction_from_antenna(which);
auto clipped_value = get_rf_freq_range().clip(value);
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
return device.tune(dir, clipped_value);
}
@@ -222,7 +222,7 @@ public:
{
auto dir = _get_direction_from_antenna(which);
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
return device.get_freq(dir);
}
@@ -237,7 +237,7 @@ public:
throw uhd::value_error("invalid filter length");
}
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
device.set_fir(dir, chain, gain, fir);
}
@@ -246,24 +246,24 @@ public:
auto dir = _get_direction_from_antenna(which);
auto chain = _get_chain_from_antenna(which);
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
return device.get_fir(dir, chain, gain);
}
virtual int16_t get_temperature()
{
- std::lock_guard<spi_lock> lock(*spi_l);
+ std::lock_guard<std::mutex> lock(*spi_mutex);
return device.get_temperature();
}
private:
ad937x_device device;
- spi_lock::sptr spi_l;
+ std::shared_ptr<std::mutex> spi_mutex;
};
-ad937x_ctrl::sptr ad937x_ctrl::make(spi_lock::sptr spi_l, uhd::spi_iface::sptr iface)
+ad937x_ctrl::sptr ad937x_ctrl::make(std::shared_ptr<std::mutex> spi_mutex, uhd::spi_iface::sptr iface)
{
- return std::make_shared<ad937x_ctrl_impl>(spi_l, iface);
+ return std::make_shared<ad937x_ctrl_impl>(spi_mutex, iface);
}
diff --git a/mpm/lib/spi/CMakeLists.txt b/mpm/lib/spi/CMakeLists.txt
index b84c0de73..517e88561 100644
--- a/mpm/lib/spi/CMakeLists.txt
+++ b/mpm/lib/spi/CMakeLists.txt
@@ -1,7 +1,4 @@
SET(SPI_SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/spi_lock.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/spi_config.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/mock_spi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spidev_iface.cpp
)
diff --git a/mpm/lib/spi/mock_spi.cpp b/mpm/lib/spi/mock_spi.cpp
deleted file mode 100644
index 28518d7a8..000000000
--- a/mpm/lib/spi/mock_spi.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-//
-// Copyright 2014 Ettus Research (National Instruments)
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-/*
-#include <uhd/config.hpp>
-#include <uhd/exception.hpp>
-#include "n310_spi.h"
-
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <linux/types.h>
-#include <linux/spi/spidev.h>
-
-
-class spidev_impl : public spi
-{
-public:
-
- spidev_impl(const std::string &device)
- : _mode(SPI_CPHA),
- _speed(2000000),
- _bits(8),
- _delay(0)
- {
- int ret;
- _fd = open(device.c_str(), O_RDWR);
- if (_fd < 0)
- throw uhd::runtime_error(str(boost::format("Could not open spidev device %s") % device));
-
- ret = ioctl(_fd, SPI_IOC_WR_MODE, &_mode);
- if (ret == -1)
- throw uhd::runtime_error("Could not set spidev mode");
-
- ret = ioctl(_fd, SPI_IOC_RD_MODE, &_mode);
- if (ret == -1)
- throw uhd::runtime_error("Could not get spidev mode");
-
- ret = ioctl(_fd, SPI_IOC_WR_BITS_PER_WORD, &_bits);
- if (ret == -1)
- throw uhd::runtime_error("Could not set spidev bits per word");
-
- ret = ioctl(_fd, SPI_IOC_RD_BITS_PER_WORD, &_bits);
- if (ret == -1)
- throw uhd::runtime_error("Could not get spidev bits per word");
-
- ret = ioctl(_fd, SPI_IOC_WR_MAX_SPEED_HZ, &_speed);
- if (ret == -1)
- throw uhd::runtime_error("Could not set spidev max speed");
-
- ret = ioctl(_fd, SPI_IOC_RD_MAX_SPEED_HZ, &_speed);
- if (ret == -1)
- throw uhd::runtime_error("Could not get spidev max speed");
- }
-
- virtual ~spidev_impl()
- {
- close(_fd);
- }
-
- uint32_t transact_spi(int, const uhd::spi_config_t &,
- uint32_t data, size_t num_bits,
- bool)
- {
- int ret(0);
- struct spi_ioc_transfer tr;
-
- uint8_t *tx_data = reinterpret_cast<uint8_t *>(&data);
-
-
- UHD_ASSERT_THROW(num_bits == 24);
- uint8_t tx[] = { tx_data[2], tx_data[1], tx_data[0] };
-
- uint8_t rx[3];
- tr.tx_buf = (unsigned long)&tx[0];
- tr.rx_buf = (unsigned long)&rx[0];
- tr.len = num_bits >> 3;
- tr.bits_per_word = _bits;
- tr.tx_nbits = 1;
- tr.rx_nbits = 1;
- tr.speed_hz = _speed;
- tr.delay_usecs = _delay;
-
- ret = ioctl(_fd, SPI_IOC_MESSAGE(1), &tr);
- if (ret < 1)
- throw uhd::runtime_error("Could not send spidev message");
-
- return rx[2];
- }
-
-private:
- int _fd;
- uint8_t _mode;
- uint32_t _speed;
- uint8_t _bits;
- uint16_t _delay;
-
-};
-
-spi::sptr spi::make(const std::string &device)
-{
- return spi::sptr(new spidev_impl(device));
-}
-*/ \ No newline at end of file
diff --git a/mpm/lib/spi/spi_config.cpp b/mpm/lib/spi/spi_config.cpp
deleted file mode 100644
index 69d6d9c2a..000000000
--- a/mpm/lib/spi/spi_config.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "spi_config.h"
-
-
-spi_config_t::spi_config_t(const spi_hwd_settings_t hwd_settings, const spi_device_settings_t device_settings) :
- full_settings({
- _convert_to_adi_settings(hwd_settings.chip_select_index, device_settings),
- hwd_settings })
-{
-
-}
-
-spiSettings_t spi_config_t::_convert_to_adi_settings(const uint8_t chip_select_index, const spi_device_settings_t device_settings)
-{
- return {
- chip_select_index,
- device_settings.writeBitPolarity,
- device_settings.longInstructionWord,
- device_settings.MSBFirst,
- device_settings.CPHA,
- device_settings.CPOL,
- device_settings.enSpiStreaming,
- device_settings.autoIncAddrUp,
- device_settings.fourWireMode,
- device_settings.spiClkFreq_Hz,
- };
-}
-
-const spiSettings_t* spi_config_t::get_spi_settings() const
-{
- return &(full_settings.adi_settings);
-}
-
-const spi_full_settings_t* spi_config_t::recover_full_spi_settings(const spiSettings_t* settings)
-{
- // TODO: make this better
- return reinterpret_cast<const spi_full_settings_t*>(settings);
-}
diff --git a/mpm/lib/spi/spi_config.h b/mpm/lib/spi/spi_config.h
deleted file mode 100644
index a29a9bc64..000000000
--- a/mpm/lib/spi/spi_config.h
+++ /dev/null
@@ -1,44 +0,0 @@
-#pragma once
-
-#include "../mykonos/adi/common.h"
-
-// contains information about the spi configuration
-
-struct spi_device_settings_t
-{
- uint8_t writeBitPolarity;
- uint8_t longInstructionWord; ///< 1 = 16bit instruction word, 0 = 8bit instruction word
- uint8_t MSBFirst; ///< 1 = MSBFirst, 0 = LSBFirst
- uint8_t CPHA; ///< clock phase, sets which clock edge the data updates (valid 0 or 1)
- uint8_t CPOL; ///< clock polarity 0 = clock starts low, 1 = clock starts high
- uint8_t enSpiStreaming; ///< Not implemented. SW feature to improve SPI throughput.
- uint8_t autoIncAddrUp; ///< Not implemented. For SPI Streaming, set address increment direction. 1= next addr = addr+1, 0:addr = addr-1
- uint8_t fourWireMode; ///< 1: Use 4-wire SPI, 0: 3-wire SPI (SDIO pin is bidirectional). NOTE: ADI's FPGA platform always uses 4-wire mode.
- uint32_t spiClkFreq_Hz;
-};
-
-struct spi_hwd_settings_t
-{
- uint8_t spidev_index;
- uint8_t chip_select_index;
-};
-
-struct spi_full_settings_t
-{
- spiSettings_t adi_settings;
- spi_hwd_settings_t hwd_settings;
-};
-
-class spi_config_t
-{
-public:
- spi_config_t(spi_hwd_settings_t hwd_settings, spi_device_settings_t device_settings);
-
-private:
- const spi_full_settings_t full_settings;
- static spiSettings_t _convert_to_adi_settings(uint8_t chip_select_index, spi_device_settings_t device_settings);
-
-public:
- const spiSettings_t* get_spi_settings() const;
- static const spi_full_settings_t* recover_full_spi_settings(const spiSettings_t* settings);
-};
diff --git a/mpm/lib/spi/spi_lock.cpp b/mpm/lib/spi/spi_lock.cpp
deleted file mode 100644
index b37daa738..000000000
--- a/mpm/lib/spi/spi_lock.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "mpm/spi/spi_lock.hpp"
-
-spi_lock::spi_lock(uint8_t spidev_index) :
- spidev_index(spidev_index)
-{
-
-}
-
-uint8_t spi_lock::get_spidev() const
-{
- return spidev_index;
-}
-
-void spi_lock::lock()
-{
- spi_mutex.lock();
-}
-void spi_lock::unlock()
-{
- spi_mutex.unlock();
-}
-
-spi_lock::sptr spi_lock::make(uint8_t spidev_index)
-{
- return std::make_shared<spi_lock>(spidev_index);
-}