From 6d332e5ca4a7311406ac285f827c31c9e5b94280 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 23 Mar 2017 15:40:28 -0700 Subject: mpm: move public includes into include/ --- mpm/include/lmk/lmk04828_spi_iface.hpp | 40 ---------- mpm/include/mpm/CMakeLists.txt | 5 +- mpm/include/mpm/dboards/magnesium_manager.hpp | 60 +++++++++++++++ mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp | 40 ++++++++++ mpm/include/mpm/mykonos/ad937x_ctrl.hpp | 99 +++++++++++++++++++++++++ mpm/include/mpm/net_helper.hpp | 69 +++++++++++++++++ mpm/include/mpm/print_foo.hpp | 5 -- mpm/include/mpm/spi/mock_spi.h | 10 +++ mpm/include/mpm/spi/spi_iface.hpp | 75 +++++++++++++++++++ mpm/include/mpm/spi/spi_lock.hpp | 25 +++++++ mpm/include/mpm/spi_iface.hpp | 75 ------------------- mpm/include/mpm/udev_helper.hpp | 62 ++++++++++++++++ mpm/include/mpm/xbar_iface.hpp | 69 +++++++++++++++++ 13 files changed, 513 insertions(+), 121 deletions(-) delete mode 100644 mpm/include/lmk/lmk04828_spi_iface.hpp create mode 100644 mpm/include/mpm/dboards/magnesium_manager.hpp create mode 100644 mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp create mode 100644 mpm/include/mpm/mykonos/ad937x_ctrl.hpp create mode 100644 mpm/include/mpm/net_helper.hpp delete mode 100644 mpm/include/mpm/print_foo.hpp create mode 100644 mpm/include/mpm/spi/mock_spi.h create mode 100644 mpm/include/mpm/spi/spi_iface.hpp create mode 100644 mpm/include/mpm/spi/spi_lock.hpp delete mode 100644 mpm/include/mpm/spi_iface.hpp create mode 100644 mpm/include/mpm/udev_helper.hpp create mode 100644 mpm/include/mpm/xbar_iface.hpp (limited to 'mpm/include') diff --git a/mpm/include/lmk/lmk04828_spi_iface.hpp b/mpm/include/lmk/lmk04828_spi_iface.hpp deleted file mode 100644 index fa11029a8..000000000 --- a/mpm/include/lmk/lmk04828_spi_iface.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "lmk04828.hpp" -#include "uhd/types/serial.hpp" -#include - -class lmk04828_spi_iface -{ -public: - using sptr = boost::shared_ptr; - lmk04828_spi_iface(uhd::spi_iface::sptr iface); - lmk04828_iface::write_fn_t get_write_fn(); - lmk04828_iface::read_fn_t get_read_fn(); - static sptr make(uhd::spi_iface::sptr iface); - -private: - const int LMK_SPI_NUM_BITS = 24; - const int LMK_SPI_READ_FLAG = 1; - const int LMK_SPI_READ_FLAG_OFFSET = 23; - const int LMK_SPI_READ_ADDR_OFFSET = 8; - const int LMK_SPI_RESERVED_FIELD_MASK = ~(0x3 << 21); - const int DEFAULT_SLAVE = 1; - - uhd::spi_iface::sptr _spi_iface; - uhd::spi_config_t config; - - void spi_write(std::vector writes); - uint8_t spi_read(uint32_t addr); -}; - -#ifdef LIBMPM_PYTHON -void export_lmk(){ - LIBMPM_BOOST_PREAMBLE("lmk04828") - bp::class_, boost::noncopyable >("lmk04828_iface", bp::no_init) - .def("make", &lmk04828_iface::make) - .def("verify_chip_id", &lmk04828_iface::verify_chip_id) - .def("get_chip_id", &lmk04828_iface::get_chip_id) - .def("init", &lmk04828_iface::init) - .def("send_sysref_pulse", &lmk04828_iface::send_sysref_pulse) - ; -} -#endif 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 . # 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 . +// + +#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 + +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_("magnesium_periph_manager", bp::init()) + .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/mpm/lmk04828/lmk04828_spi_iface.hpp b/mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp new file mode 100644 index 000000000..fa11029a8 --- /dev/null +++ b/mpm/include/mpm/lmk04828/lmk04828_spi_iface.hpp @@ -0,0 +1,40 @@ +#include "lmk04828.hpp" +#include "uhd/types/serial.hpp" +#include + +class lmk04828_spi_iface +{ +public: + using sptr = boost::shared_ptr; + lmk04828_spi_iface(uhd::spi_iface::sptr iface); + lmk04828_iface::write_fn_t get_write_fn(); + lmk04828_iface::read_fn_t get_read_fn(); + static sptr make(uhd::spi_iface::sptr iface); + +private: + const int LMK_SPI_NUM_BITS = 24; + const int LMK_SPI_READ_FLAG = 1; + const int LMK_SPI_READ_FLAG_OFFSET = 23; + const int LMK_SPI_READ_ADDR_OFFSET = 8; + const int LMK_SPI_RESERVED_FIELD_MASK = ~(0x3 << 21); + const int DEFAULT_SLAVE = 1; + + uhd::spi_iface::sptr _spi_iface; + uhd::spi_config_t config; + + void spi_write(std::vector writes); + uint8_t spi_read(uint32_t addr); +}; + +#ifdef LIBMPM_PYTHON +void export_lmk(){ + LIBMPM_BOOST_PREAMBLE("lmk04828") + bp::class_, boost::noncopyable >("lmk04828_iface", bp::no_init) + .def("make", &lmk04828_iface::make) + .def("verify_chip_id", &lmk04828_iface::verify_chip_id) + .def("get_chip_id", &lmk04828_iface::get_chip_id) + .def("init", &lmk04828_iface::init) + .def("send_sysref_pulse", &lmk04828_iface::send_sysref_pulse) + ; +} +#endif 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 . +// + +#pragma once + +#include "mpm/spi/spi_lock.hpp" + +// TODO: fix path of UHD includes +#include +#include +#include +#include + +#include +#include +#include +#include +class ad937x_device; + +class ad937x_ctrl : public boost::noncopyable +{ +public: + typedef std::shared_ptr 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 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 & fir) = 0; + virtual std::vector 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 _get_valid_fir_lengths(const std::string& which); +}; + +#ifdef LIBMPM_PYTHON +void export_mykonos(){ + LIBMPM_BOOST_PREAMBLE("ad937x") + + bp::class_ >("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 . +// + +#include +#include +#include + +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 ip_addr; +}; + +/*! + * net_ifaces contains a pair + * describing mac address and associated ip addresses for + * each interface + */ +using net_ifaces = std::map; + +/*! + * 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 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 - -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 + +class mock_spi : public virtual uhd::spi_iface +{ +public: + typedef boost::shared_ptr sptr; + static sptr make(const std::string &device); +}; diff --git a/mpm/include/mpm/spi/spi_iface.hpp b/mpm/include/mpm/spi/spi_iface.hpp new file mode 100644 index 000000000..3142fd661 --- /dev/null +++ b/mpm/include/mpm/spi/spi_iface.hpp @@ -0,0 +1,75 @@ +// +// 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 . +// + +#pragma once + +#include + +namespace mpm { + + /*! \brief Intermediate object to SPI + * + */ + class spi_iface + { + public: + typedef std::shared_ptr sptr; + + enum class spi_wire_mode_t { + THREE_WIRE_MODE = 0, + FOUR_WIRE_MODE = 1 + }; + + enum class spi_endianness_t { + LSB_FIRST = 0, + MSB_FIRST = 1 + }; + + virtual void write_byte( + const uint16_t addr, + const uint8_t data + ) = 0; + + virtual void write_bytes( + const uint16_t *addr, + const uint8_t *data, + const uint32_t count + ) = 0; + + virtual uint8_t read_byte(const uint16_t addr) = 0; + + virtual void write_field( + const uint16_t addr, + const uint8_t field_val, + const uint8_t mask, + const uint8_t start_bit + ) = 0; + + virtual uint8_t read_field( + const uint16_t addr, + const uint8_t mask, + const uint8_t start_bit + ) = 0; + + virtual spi_wire_mode_t get_wire_mode() const = 0; + virtual spi_endianness_t get_endianness() const = 0; + + virtual size_t get_chip_select() const = 0; + }; + +} /* namespace mpm */ + 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 +#include +#include + +class spi_lock : public boost::noncopyable +{ +public: + using sptr = std::shared_ptr; + 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; + void lock(); + void unlock(); +}; diff --git a/mpm/include/mpm/spi_iface.hpp b/mpm/include/mpm/spi_iface.hpp deleted file mode 100644 index 3142fd661..000000000 --- a/mpm/include/mpm/spi_iface.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// -// 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 . -// - -#pragma once - -#include - -namespace mpm { - - /*! \brief Intermediate object to SPI - * - */ - class spi_iface - { - public: - typedef std::shared_ptr sptr; - - enum class spi_wire_mode_t { - THREE_WIRE_MODE = 0, - FOUR_WIRE_MODE = 1 - }; - - enum class spi_endianness_t { - LSB_FIRST = 0, - MSB_FIRST = 1 - }; - - virtual void write_byte( - const uint16_t addr, - const uint8_t data - ) = 0; - - virtual void write_bytes( - const uint16_t *addr, - const uint8_t *data, - const uint32_t count - ) = 0; - - virtual uint8_t read_byte(const uint16_t addr) = 0; - - virtual void write_field( - const uint16_t addr, - const uint8_t field_val, - const uint8_t mask, - const uint8_t start_bit - ) = 0; - - virtual uint8_t read_field( - const uint16_t addr, - const uint8_t mask, - const uint8_t start_bit - ) = 0; - - virtual spi_wire_mode_t get_wire_mode() const = 0; - virtual spi_endianness_t get_endianness() const = 0; - - virtual size_t get_chip_select() const = 0; - }; - -} /* namespace mpm */ - 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 . +// + +#include +#include +#include + +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 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_("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 . +// +#pragma once +#include +#include +#include +#include + +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; + 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_ >("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 + -- cgit v1.2.3