aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-05-07 14:39:26 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-26 11:49:14 -0800
commitf0371292a43c3e4e3c68d8631c57d64ab10faf4c (patch)
tree4ce350cf0671d3cccc2a0e02a602375af9dc4b12
parent752fdd269215a606212fb97e909b08707bf54507 (diff)
downloaduhd-f0371292a43c3e4e3c68d8631c57d64ab10faf4c.tar.gz
uhd-f0371292a43c3e4e3c68d8631c57d64ab10faf4c.tar.bz2
uhd-f0371292a43c3e4e3c68d8631c57d64ab10faf4c.zip
rfnoc: Add detail::block_container_t class
This is a storage for the noc_block_base derivatives. It supports finding blocks.
-rw-r--r--host/lib/include/uhdlib/rfnoc/block_container.hpp57
-rw-r--r--host/lib/rfnoc/CMakeLists.txt1
-rw-r--r--host/lib/rfnoc/block_container.cpp74
3 files changed, 132 insertions, 0 deletions
diff --git a/host/lib/include/uhdlib/rfnoc/block_container.hpp b/host/lib/include/uhdlib/rfnoc/block_container.hpp
new file mode 100644
index 000000000..e32feed52
--- /dev/null
+++ b/host/lib/include/uhdlib/rfnoc/block_container.hpp
@@ -0,0 +1,57 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#ifndef INCLUDED_LIBUHD_BLOCK_CONTAINER_HPP
+#define INCLUDED_LIBUHD_BLOCK_CONTAINER_HPP
+
+#include <uhd/rfnoc/noc_block_base.hpp>
+#include <uhd/rfnoc/block_id.hpp>
+#include <boost/units/detail/utility.hpp>
+#include <unordered_set>
+#include <mutex>
+#include <vector>
+
+namespace uhd { namespace rfnoc { namespace detail {
+
+/*! Storage container for RFNoC block controllers
+ */
+class block_container_t
+{
+public:
+ block_container_t();
+
+ void register_block(noc_block_base::sptr block);
+
+ /*! Returns the block ids of all blocks that match the specified hint
+ *
+ * See uhd::rfnoc::rfnoc_graph::find_blocks() for details.
+ */
+ std::vector<block_id_t> find_blocks(const std::string& block_id_hint) const;
+
+ /*! Checks if a specific NoC block exists on the device.
+ *
+ * See uhd::rfnoc::rfnoc_graph::has_block() for details.
+ */
+ bool has_block(const block_id_t& block_id) const;
+
+ /*! \brief Returns a block controller class for an NoC block.
+ *
+ * See uhd::rfnoc::rfnoc_graph::get_block() for details.
+ */
+ noc_block_base::sptr get_block(const block_id_t& block_id) const;
+
+private:
+ //! Lock access to the storage
+ mutable std::mutex _mutex;
+
+ //! The actual block registry
+ std::unordered_set<noc_block_base::sptr> _blocks;
+};
+
+}}} /* namespace uhd::rfnoc::detail */
+
+#endif /* INCLUDED_LIBUHD_BLOCK_CONTAINER_HPP */
+
diff --git a/host/lib/rfnoc/CMakeLists.txt b/host/lib/rfnoc/CMakeLists.txt
index 9d691ac5e..bc3e7309f 100644
--- a/host/lib/rfnoc/CMakeLists.txt
+++ b/host/lib/rfnoc/CMakeLists.txt
@@ -12,6 +12,7 @@
LIBUHD_APPEND_SOURCES(
# Infrastructure:
${CMAKE_CURRENT_SOURCE_DIR}/async_msg_handler.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/block_container.cpp
${CMAKE_CURRENT_SOURCE_DIR}/block_ctrl_base.cpp
${CMAKE_CURRENT_SOURCE_DIR}/block_ctrl_base_factory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/block_ctrl_impl.cpp
diff --git a/host/lib/rfnoc/block_container.cpp b/host/lib/rfnoc/block_container.cpp
new file mode 100644
index 000000000..0151b228b
--- /dev/null
+++ b/host/lib/rfnoc/block_container.cpp
@@ -0,0 +1,74 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <uhd/utils/log.hpp>
+#include <uhdlib/rfnoc/block_container.hpp>
+#include <boost/format.hpp>
+#include <algorithm>
+
+
+using namespace uhd::rfnoc::detail;
+
+using uhd::rfnoc::block_id_t;
+using uhd::rfnoc::noc_block_base;
+
+/******************************************************************************
+ * Structors
+ *****************************************************************************/
+block_container_t::block_container_t()
+{
+ // nop
+}
+
+
+/******************************************************************************
+ * API
+ *****************************************************************************/
+void block_container_t::register_block(noc_block_base::sptr block)
+{
+ std::lock_guard<std::mutex> lock(_mutex);
+ UHD_LOGGER_DEBUG("RFNOC::BLOCK_CONTAINER")
+ << boost::format("Registering block: %s (NOC ID=%08x)") % block->get_unique_id()
+ % block->get_noc_id();
+ _blocks.insert(block);
+}
+
+std::vector<block_id_t> block_container_t::find_blocks(
+ const std::string& block_id_hint) const
+{
+ std::lock_guard<std::mutex> lock(_mutex);
+ std::vector<block_id_t> block_ids;
+ for (auto it = _blocks.cbegin(); it != _blocks.cend(); ++it) {
+ auto id = (*it)->get_block_id();
+ if (id.match(block_id_hint) || block_id_hint.empty()) {
+ block_ids.push_back(id);
+ }
+ }
+ return block_ids;
+}
+
+bool block_container_t::has_block(const block_id_t& block_id) const
+{
+ std::lock_guard<std::mutex> lock(_mutex);
+ return std::any_of(
+ _blocks.cbegin(), _blocks.cend(), [block_id](noc_block_base::sptr block) {
+ return block->get_block_id() == block_id;
+ });
+}
+
+noc_block_base::sptr block_container_t::get_block(const block_id_t& block_id) const
+{
+ auto block_itr = std::find_if(
+ _blocks.cbegin(), _blocks.cend(), [block_id](noc_block_base::sptr block) {
+ return block->get_block_id() == block_id;
+ });
+ if (block_itr == _blocks.cend()) {
+ throw uhd::lookup_error(std::string("This device does not have a block with ID: ")
+ + block_id.to_string());
+ }
+ return *block_itr;
+}
+