aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/include
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-03-23 15:40:28 -0700
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:03:44 -0800
commit6d332e5ca4a7311406ac285f827c31c9e5b94280 (patch)
tree77098d97db8e8884124d66617721724821a80ced /mpm/include
parentef6326a174e6880be5e2eaeac26a2c5de0768807 (diff)
downloaduhd-6d332e5ca4a7311406ac285f827c31c9e5b94280.tar.gz
uhd-6d332e5ca4a7311406ac285f827c31c9e5b94280.tar.bz2
uhd-6d332e5ca4a7311406ac285f827c31c9e5b94280.zip
mpm: move public includes into include/
Diffstat (limited to 'mpm/include')
-rw-r--r--mpm/include/mpm/CMakeLists.txt5
-rw-r--r--mpm/include/mpm/dboards/magnesium_manager.hpp60
-rw-r--r--mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp (renamed from mpm/include/lmk/lmk04828_spi_iface.hpp)0
-rw-r--r--mpm/include/mpm/mykonos/ad937x_ctrl.hpp99
-rw-r--r--mpm/include/mpm/net_helper.hpp69
-rw-r--r--mpm/include/mpm/print_foo.hpp5
-rw-r--r--mpm/include/mpm/spi/mock_spi.h10
-rw-r--r--mpm/include/mpm/spi/spi_iface.hpp (renamed from mpm/include/mpm/spi_iface.hpp)0
-rw-r--r--mpm/include/mpm/spi/spi_lock.hpp25
-rw-r--r--mpm/include/mpm/udev_helper.hpp62
-rw-r--r--mpm/include/mpm/xbar_iface.hpp69
11 files changed, 398 insertions, 6 deletions
diff --git a/mpm/include/mpm/CMakeLists.txt b/mpm/include/mpm/CMakeLists.txt
index d8ffe1416..348073920 100644
--- a/mpm/include/mpm/CMakeLists.txt
+++ b/mpm/include/mpm/CMakeLists.txt
@@ -15,6 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
INSTALL(FILES
- print_foo.hpp
+ net_helper.hpp
+ spi_iface.hpp
+ udev_helper.hpp
+ xbar_iface.hpp
DESTINATION ${INCLUDE_DIR}/mpm
)
diff --git a/mpm/include/mpm/dboards/magnesium_manager.hpp b/mpm/include/mpm/dboards/magnesium_manager.hpp
new file mode 100644
index 000000000..356727618
--- /dev/null
+++ b/mpm/include/mpm/dboards/magnesium_manager.hpp
@@ -0,0 +1,60 @@
+//
+// Copyright 2017 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/>.
+//
+
+#pragma once
+
+#include "mpm/spi/spi_lock.hpp"
+#include "mpm/spi/spidev_iface.hpp"
+#include "mpm/lmk04828/lmk04828_spi_iface.hpp"
+#include "mpm/mykonos/ad937x_ctrl.hpp"
+#include <memory>
+
+namespace mpm { namespace dboards {
+ class magnesium_periph_manager// : public dboard_periph_manager
+ {
+ public:
+ magnesium_periph_manager(std::string lmk_spidev, std::string mykonos_spidev);
+
+ /*! Return a reference to the clock chip
+ */
+ lmk04828_iface::sptr get_clock_ctrl(){return _clock_ctrl;};
+
+ /*! Return a reference to the radio chip
+ */
+ ad937x_ctrl::sptr get_radio_ctrl(){return _mykonos_ctrl;};
+
+ private:
+ //cpld control
+ spi_lock::sptr _spi_lock;
+ lmk04828_spi_iface::sptr _clock_spi;
+ lmk04828_iface::sptr _clock_ctrl;
+ mpm::spi::spidev_iface::sptr _mykonos_spi;
+ ad937x_ctrl::sptr _mykonos_ctrl;
+ };
+
+}};
+
+
+#ifdef LIBMPM_PYTHON
+void export_dboards(){
+ LIBMPM_BOOST_PREAMBLE("dboards")
+ bp::class_<mpm::dboards::magnesium_periph_manager>("magnesium_periph_manager", bp::init<std::string, std::string>())
+ .def("get_clock_ctrl", &mpm::dboards::magnesium_periph_manager::get_clock_ctrl)
+ .def("get_radio_ctrl", &mpm::dboards::magnesium_periph_manager::get_radio_ctrl)
+ ;
+}
+#endif
diff --git a/mpm/include/lmk/lmk04828_spi_iface.hpp b/mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp
index fa11029a8..fa11029a8 100644
--- a/mpm/include/lmk/lmk04828_spi_iface.hpp
+++ b/mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp
diff --git a/mpm/include/mpm/mykonos/ad937x_ctrl.hpp b/mpm/include/mpm/mykonos/ad937x_ctrl.hpp
new file mode 100644
index 000000000..663424b06
--- /dev/null
+++ b/mpm/include/mpm/mykonos/ad937x_ctrl.hpp
@@ -0,0 +1,99 @@
+//
+// Copyright 2017 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/>.
+//
+
+#pragma once
+
+#include "mpm/spi/spi_lock.hpp"
+
+// TODO: fix path of UHD includes
+#include <uhd/types/direction.hpp>
+#include <uhd/types/ranges.hpp>
+#include <uhd/exception.hpp>
+#include <uhd/types/serial.hpp>
+
+#include <boost/noncopyable.hpp>
+#include <memory>
+#include <functional>
+#include <set>
+class ad937x_device;
+
+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);
+ virtual ~ad937x_ctrl(void) {}
+
+ static uhd::meta_range_t get_rf_freq_range(void);
+ static uhd::meta_range_t get_bw_filter_range(void);
+ static std::vector<double> get_clock_rates(void);
+ static uhd::meta_range_t get_gain_range(const std::string &which);
+
+ virtual uint8_t get_product_id() = 0;
+ virtual uint8_t get_device_rev() = 0;
+ virtual std::string get_api_version() = 0;
+ virtual std::string get_arm_version() = 0;
+
+ virtual double set_bw_filter(const std::string &which, double value) = 0;
+ virtual double set_gain(const std::string &which, double value) = 0;
+
+ virtual void set_agc_mode(const std::string &which, const std::string &mode) = 0;
+
+ virtual double set_clock_rate(double value) = 0;
+ virtual void enable_channel(const std::string &which, bool enable) = 0;
+
+ virtual double set_freq(const std::string &which, double value) = 0;
+ virtual double get_freq(const std::string &which) = 0;
+
+ virtual void set_fir(const std::string &which, int8_t gain, const std::vector<int16_t> & fir) = 0;
+ virtual std::vector<int16_t> get_fir(const std::string &which, int8_t &gain) = 0;
+
+ virtual int16_t get_temperature() = 0;
+
+protected:
+ static uhd::direction_t _get_direction_from_antenna(const std::string& antenna);
+ static std::set<size_t> _get_valid_fir_lengths(const std::string& which);
+};
+
+#ifdef LIBMPM_PYTHON
+void export_mykonos(){
+ LIBMPM_BOOST_PREAMBLE("ad937x")
+
+ bp::class_<ad937x_ctrl, boost::noncopyable, std::shared_ptr<ad937x_ctrl> >("ad937x_ctrl", bp::no_init)
+ .def("make", &ad937x_ctrl::make)
+ .def("get_rf_freq_range", &ad937x_ctrl::get_rf_freq_range)
+ .def("get_bw_filter_range", &ad937x_ctrl::get_bw_filter_range)
+ .def("get_clock_rates", &ad937x_ctrl::get_clock_rates)
+ .def("get_gain_range", &ad937x_ctrl::get_gain_range)
+ .def("get_product_id", &ad937x_ctrl::get_product_id)
+ .def("get_device_rev", &ad937x_ctrl::get_device_rev)
+ .def("get_api_version", &ad937x_ctrl::get_api_version)
+ .def("get_arm_version", &ad937x_ctrl::get_arm_version)
+ .def("set_bw_filter", &ad937x_ctrl::set_bw_filter)
+ .def("set_gain", &ad937x_ctrl::set_gain)
+ .def("set_agc_mode", &ad937x_ctrl::set_agc_mode)
+ .def("set_clock_rate", &ad937x_ctrl::set_clock_rate)
+ .def("enable_channel", &ad937x_ctrl::enable_channel)
+ .def("set_freq", &ad937x_ctrl::set_freq)
+ .def("get_freq", &ad937x_ctrl::get_freq)
+ .def("set_fir", &ad937x_ctrl::set_fir)
+ .def("get_fir", &ad937x_ctrl::get_fir)
+ .def("get_temperature", &ad937x_ctrl::get_temperature)
+ ;
+}
+#endif
+
diff --git a/mpm/include/mpm/net_helper.hpp b/mpm/include/mpm/net_helper.hpp
new file mode 100644
index 000000000..b07e43ccc
--- /dev/null
+++ b/mpm/include/mpm/net_helper.hpp
@@ -0,0 +1,69 @@
+//
+// Copyright 2017 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 <map>
+#include <vector>
+#include <string>
+
+namespace mpm {
+namespace network {
+
+/*!
+ * A struct describing a single network interface
+ */
+using net_iface = struct net_iface {
+ /*! MAC address of the interface in the form AABBCCDDEEFF */
+ std::string mac_addr;
+ /*! vector of associated IP addresses, contains both IPv4 and IPv6 */
+ std::vector<std::string> ip_addr;
+};
+
+/*!
+ * net_ifaces contains a <interfaces name, net_iface> pair
+ * describing mac address and associated ip addresses for
+ * each interface
+ */
+using net_ifaces = std::map<std::string, net_iface>;
+
+/*!
+ * Convenience function to get all ip addresses of one MAC address
+ * \param MAC address in the form AABBCCDDEEFF
+ * \return vector of strings containing all IP addresses with this MAC address
+ */
+std::vector<std::string> get_if_addrs(const std::string& mac_addr);
+
+/*!
+ * Get information about all interfaces on this system
+ * \return a map with interface names as keys and the interfaces information as value
+ */
+net_ifaces get_net_map();
+
+/*!
+ * Pretty print net_ifaces in the style of `ip addr`
+ * \param interface map net_ifaces to print
+ */
+void print_net_ifaces(net_ifaces my_ifaces);
+}
+}
+
+#ifdef LIBMPM_PYTHON
+void export_net_iface(){
+ LIBMPM_BOOST_PREAMBLE("network")
+ bp::def("get_if_addrs", &mpm::network::get_if_addrs);
+}
+#endif
+
diff --git a/mpm/include/mpm/print_foo.hpp b/mpm/include/mpm/print_foo.hpp
deleted file mode 100644
index d85ac5727..000000000
--- a/mpm/include/mpm/print_foo.hpp
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <iostream>
-
-namespace mpm{
- void print_foo();
-}
diff --git a/mpm/include/mpm/spi/mock_spi.h b/mpm/include/mpm/spi/mock_spi.h
new file mode 100644
index 000000000..c289faa16
--- /dev/null
+++ b/mpm/include/mpm/spi/mock_spi.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#include <uhd/types/serial.hpp>
+
+class mock_spi : public virtual uhd::spi_iface
+{
+public:
+ typedef boost::shared_ptr<spi> sptr;
+ static sptr make(const std::string &device);
+};
diff --git a/mpm/include/mpm/spi_iface.hpp b/mpm/include/mpm/spi/spi_iface.hpp
index 3142fd661..3142fd661 100644
--- a/mpm/include/mpm/spi_iface.hpp
+++ b/mpm/include/mpm/spi/spi_iface.hpp
diff --git a/mpm/include/mpm/spi/spi_lock.hpp b/mpm/include/mpm/spi/spi_lock.hpp
new file mode 100644
index 000000000..9ad4e20fe
--- /dev/null
+++ b/mpm/include/mpm/spi/spi_lock.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <boost/noncopyable.hpp>
+#include <mutex>
+#include <memory>
+
+class spi_lock : public boost::noncopyable
+{
+public:
+ using sptr = std::shared_ptr<spi_lock>;
+ static sptr make(uint8_t spidev_index);
+
+ spi_lock(uint8_t spidev_index);
+
+ uint8_t get_spidev() const;
+
+private:
+ const uint8_t spidev_index;
+
+ // BasicLockable implementation for lock_guard
+ mutable std::mutex spi_mutex;
+ friend class std::lock_guard<spi_lock>;
+ void lock();
+ void unlock();
+};
diff --git a/mpm/include/mpm/udev_helper.hpp b/mpm/include/mpm/udev_helper.hpp
new file mode 100644
index 000000000..055a93cee
--- /dev/null
+++ b/mpm/include/mpm/udev_helper.hpp
@@ -0,0 +1,62 @@
+//
+// Copyright 2017 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 <libudev.h>
+#include <string>
+#include <vector>
+
+namespace mpm {
+ /*!
+ * The udev_helper class:
+ *
+ * talks to libudev and holds a udev context. Device enumeration is done
+ * once during initialization.
+ * On destruction the udev context is unreferenced again.
+ */
+ class udev_helper{
+ public:
+ udev_helper();
+ ~udev_helper();
+ /*!
+ * Return the nvmem device associated with the parent address
+ * \param address of the parent platform driver
+ * \return a string containing the name of file of the device in /sys
+ */
+ std::string get_eeprom(const std::string &address);
+ /*!
+ * Find spidevices associated with the spi_master
+ * \param address of the parent platform driver
+ * \return a vector of string containing the device paths is /dev
+ */
+ std::vector<std::string> get_spidev_nodes(const std::string &spi_master);
+
+ private:
+ udev *_udev;
+ udev_enumerate *_enumerate;
+ };
+}
+
+#ifdef LIBMPM_PYTHON
+void export_udev_helper(){
+ LIBMPM_BOOST_PREAMBLE("udev")
+ bp::class_<mpm::udev_helper>("udev_helper", bp::init<>())
+ .def("get_eeprom", &mpm::udev_helper::get_eeprom)
+ .def("get_spidev_nodes", &mpm::udev_helper::get_spidev_nodes)
+ ;
+}
+#endif
+
diff --git a/mpm/include/mpm/xbar_iface.hpp b/mpm/include/mpm/xbar_iface.hpp
new file mode 100644
index 000000000..9b17ed97b
--- /dev/null
+++ b/mpm/include/mpm/xbar_iface.hpp
@@ -0,0 +1,69 @@
+//
+// Copyright 2017 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/>.
+//
+#pragma once
+#include <boost/noncopyable.hpp>
+#include <memory>
+#include <mutex>
+#include <cstdint>
+
+namespace mpm{
+
+/*!
+ * Crossbar route command
+ */
+using rfnoc_crossbar_cmd = struct rfnoc_crossbar_cmd {
+ /*! destination address */
+ uint8_t dest_addr;
+ /*! destination port */
+ uint8_t dest_port;
+};
+
+#define RFNCBWROUTIOC _IOW('R', 1, struct rfnoc_crossbar_cmd)
+#define RFNCDELROUTIOC _IOW('D', 1, struct rfnoc_crossbar_cmd)
+
+/*!
+ * Crossbar interface class holding a crossbar context
+ */
+class xbar_iface: boost::noncopyable{
+public:
+ // use static mutex! lock_guard
+ using sptr = std::shared_ptr<xbar_iface>;
+ static sptr make(const std::string &device);
+ void set_route(uint8_t dst_addr, uint8_t dst_port);
+ void del_route(uint8_t dst_addr, uint8_t dst_port);
+ ~xbar_iface();
+ xbar_iface(const std::string &device);
+
+private:
+ static std::mutex _lock;
+ int _fd;
+};
+}
+
+
+#ifdef LIBMPM_PYTHON
+void export_xbar(){
+ LIBMPM_BOOST_PREAMBLE("xbar")
+ bp::class_<mpm::xbar_iface, boost::noncopyable, std::shared_ptr<mpm::xbar_iface> >("xbar", bp::no_init)
+ .def("make", &mpm::xbar_iface::make)
+ .staticmethod("make")
+ .def("set_route", &mpm::xbar_iface::set_route)
+ .def("del_route", &mpm::xbar_iface::del_route)
+ ;
+}
+#endif
+