diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-03-08 09:28:55 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:44 -0800 |
commit | 1a4348038d0eb57d53475074dca49e8192aeb2d7 (patch) | |
tree | 04c8e87fa9c95d2702aac410f6fb271461acb9bb /mpm/include | |
parent | fc8cd827f6b16b9c8c354a216889e6a9d7f37456 (diff) | |
download | uhd-1a4348038d0eb57d53475074dca49e8192aeb2d7.tar.gz uhd-1a4348038d0eb57d53475074dca49e8192aeb2d7.tar.bz2 uhd-1a4348038d0eb57d53475074dca49e8192aeb2d7.zip |
Initial commit for N3xx development.
- Creates mpm/ subdirectory
- First pass at hardware daemon/MPM
- New code for LMK04828, AD9371
- spidev integration
Contributions by:
Martin Braun <martin.braun@ettus.com>
Derek Kozel <derek.kozel@ettus.com>
Mark Meserve <mark.meserve@ni.com>
Andrej Rode <andrej.rode@ettus.com>
Diffstat (limited to 'mpm/include')
-rw-r--r-- | mpm/include/CMakeLists.txt | 18 | ||||
-rw-r--r-- | mpm/include/lmk/lmk04828_spi_iface.hpp | 24 | ||||
-rw-r--r-- | mpm/include/mpm/CMakeLists.txt | 20 | ||||
-rw-r--r-- | mpm/include/mpm/print_foo.hpp | 5 | ||||
-rw-r--r-- | mpm/include/mpm/spi/adi_ctrl.hpp | 31 | ||||
-rw-r--r-- | mpm/include/mpm/spi/spidev_iface.hpp | 59 | ||||
-rw-r--r-- | mpm/include/mpm/spi_iface.hpp | 75 | ||||
-rw-r--r-- | mpm/include/mpm/tests/tests_spi_iface.hpp | 69 |
8 files changed, 301 insertions, 0 deletions
diff --git a/mpm/include/CMakeLists.txt b/mpm/include/CMakeLists.txt new file mode 100644 index 000000000..d7f06105b --- /dev/null +++ b/mpm/include/CMakeLists.txt @@ -0,0 +1,18 @@ +# +# 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/>. +# + +ADD_SUBDIRECTORY(mpm) diff --git a/mpm/include/lmk/lmk04828_spi_iface.hpp b/mpm/include/lmk/lmk04828_spi_iface.hpp new file mode 100644 index 000000000..3338bd6d1 --- /dev/null +++ b/mpm/include/lmk/lmk04828_spi_iface.hpp @@ -0,0 +1,24 @@ +#include "lmk04828.hpp" +#include "uhd/types/serial.hpp" + +class lmk04828_spi_iface +{ +public: + lmk04828_spi_iface(uhd::spi_iface::sptr iface); + lmk04828_iface::write_fn_t get_write_fn(); + lmk04828_iface::read_fn_t get_read_fn(); + +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<uint32_t> writes); + uint8_t spi_read(uint32_t addr); +}; diff --git a/mpm/include/mpm/CMakeLists.txt b/mpm/include/mpm/CMakeLists.txt new file mode 100644 index 000000000..d8ffe1416 --- /dev/null +++ b/mpm/include/mpm/CMakeLists.txt @@ -0,0 +1,20 @@ +# +# 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/>. +# +INSTALL(FILES + print_foo.hpp + DESTINATION ${INCLUDE_DIR}/mpm +) diff --git a/mpm/include/mpm/print_foo.hpp b/mpm/include/mpm/print_foo.hpp new file mode 100644 index 000000000..d85ac5727 --- /dev/null +++ b/mpm/include/mpm/print_foo.hpp @@ -0,0 +1,5 @@ +#include <iostream> + +namespace mpm{ + void print_foo(); +} diff --git a/mpm/include/mpm/spi/adi_ctrl.hpp b/mpm/include/mpm/spi/adi_ctrl.hpp new file mode 100644 index 000000000..d3269cecc --- /dev/null +++ b/mpm/include/mpm/spi/adi_ctrl.hpp @@ -0,0 +1,31 @@ +// +// 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_iface.hpp> + +struct mpm_spiSettings_t +{ + static mpm_spiSettings_t* make(spiSettings_t *sps) { + return reinterpret_cast<mpm_spiSettings_t *>(sps); + } + + spiSettings_t spi_settings; + mpm::spi_iface *spi_iface; +}; + diff --git a/mpm/include/mpm/spi/spidev_iface.hpp b/mpm/include/mpm/spi/spidev_iface.hpp new file mode 100644 index 000000000..fb82ffade --- /dev/null +++ b/mpm/include/mpm/spi/spidev_iface.hpp @@ -0,0 +1,59 @@ +// +// 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 "uhd/types/serial.hpp" +#include <boost/shared_ptr.hpp> + +namespace mpm { namespace spi { + + /*! Implementation of a uhd::spi_iface that uses Linux' spidev underneath. + */ + class spidev_iface : public uhd::spi_iface + { + public: + typedef boost::shared_ptr<spidev_iface> sptr; + virtual uint32_t read_spi( + int which_slave, + const uhd::spi_config_t &config, + uint32_t data, + size_t num_bits + ) = 0; + + virtual void write_spi( + int which_slave, + const uhd::spi_config_t &config, + uint32_t data, + size_t num_bits + ) = 0; + + virtual uint32_t transact_spi( + int /* which_slave */, + const uhd::spi_config_t & /* config */, + uint32_t data, + size_t num_bits, + bool readback + ) = 0; + /*! + * \param device The path to the spidev used. + */ + static sptr make(const std::string &device); + }; + +}}; /* namespace mpm */ + diff --git a/mpm/include/mpm/spi_iface.hpp b/mpm/include/mpm/spi_iface.hpp new file mode 100644 index 000000000..3142fd661 --- /dev/null +++ b/mpm/include/mpm/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 <http://www.gnu.org/licenses/>. +// + +#pragma once + +#include <memory> + +namespace mpm { + + /*! \brief Intermediate object to SPI + * + */ + class spi_iface + { + public: + typedef std::shared_ptr<spi_iface> 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/tests/tests_spi_iface.hpp b/mpm/include/mpm/tests/tests_spi_iface.hpp new file mode 100644 index 000000000..6dde42612 --- /dev/null +++ b/mpm/include/mpm/tests/tests_spi_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 <mpm/spi_iface.hpp> +#include <unordered_map> +#include <memory> +namespace mpm { + class tests_spi_iface : public virtual spi_iface + { + public: + + /************************************************************************** + * spi_iface API calls + *************************************************************************/ + + typedef std::shared_ptr<tests_spi_iface> sptr; + static sptr make(){ + return std::make_shared<tests_spi_iface>(); + }; + + void write_byte( + const uint16_t addr, + const uint8_t data + ); + + void write_bytes( + const uint16_t *addr, + const uint8_t *data, + const uint32_t count + ); + + uint8_t read_byte(const uint16_t addr); + + void write_field( + const uint16_t addr, + const uint8_t field_val, + const uint8_t mask, + const uint8_t start_bit + ); + + uint8_t read_field( + const uint16_t addr, + const uint8_t mask, + const uint8_t start_bit + ); + spi_wire_mode_t get_wire_mode() const; + spi_endianness_t get_endianness() const; + size_t get_chip_select() const; + + private: + std::unordered_map<uint16_t, uint8_t> _regs; + uint8_t _default_val = 0; + }; +} |