aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/rfnoc/rfnoc_graph.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-04-30 18:26:52 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-26 11:49:17 -0800
commitfb0175a89ff85456f0efa59e726cf3abe1a87967 (patch)
tree251c585f38d984d37bbe0c6d82ffb063bb527350 /host/lib/rfnoc/rfnoc_graph.cpp
parent636dad30696b68fc26bb91f370873fb3f938b020 (diff)
downloaduhd-fb0175a89ff85456f0efa59e726cf3abe1a87967.tar.gz
uhd-fb0175a89ff85456f0efa59e726cf3abe1a87967.tar.bz2
uhd-fb0175a89ff85456f0efa59e726cf3abe1a87967.zip
rfnoc: Add rfnoc_graph class
This replaces device3() for RFNoC applications.
Diffstat (limited to 'host/lib/rfnoc/rfnoc_graph.cpp')
-rw-r--r--host/lib/rfnoc/rfnoc_graph.cpp160
1 files changed, 160 insertions, 0 deletions
diff --git a/host/lib/rfnoc/rfnoc_graph.cpp b/host/lib/rfnoc/rfnoc_graph.cpp
new file mode 100644
index 000000000..fef2ccccb
--- /dev/null
+++ b/host/lib/rfnoc/rfnoc_graph.cpp
@@ -0,0 +1,160 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <uhd/rfnoc/node.hpp>
+#include <uhd/rfnoc_graph.hpp>
+#include <uhdlib/rfnoc/block_container.hpp>
+#include <uhdlib/rfnoc/graph.hpp>
+#include <uhdlib/rfnoc/rfnoc_device.hpp>
+#include <boost/shared_ptr.hpp> // FIXME remove when rfnoc_device is ready
+
+using namespace uhd::rfnoc;
+
+
+class rfnoc_graph_impl : public rfnoc_graph
+{
+public:
+ /**************************************************************************
+ * Structors
+ *************************************************************************/
+ rfnoc_graph_impl(const uhd::device_addr_t& dev_addr)
+ {
+ setup_graph(dev_addr);
+ }
+
+ ~rfnoc_graph_impl()
+ {
+ _graph.reset();
+ }
+
+ /**************************************************************************
+ * Block Discovery/Retrieval
+ *************************************************************************/
+ std::vector<block_id_t> find_blocks(const std::string& block_id_hint) const
+ {
+ return _block_registry->find_blocks(block_id_hint);
+ }
+
+ bool has_block(const block_id_t& block_id) const
+ {
+ return _block_registry->has_block(block_id);
+ }
+
+ noc_block_base::sptr get_block(const block_id_t& block_id) const
+ {
+ return _block_registry->get_block(block_id);
+ }
+
+ /**************************************************************************
+ * Graph Connections
+ *************************************************************************/
+ void connect(const block_id_t& src_blk,
+ size_t src_port,
+ const block_id_t& dst_blk,
+ size_t dst_port,
+ bool skip_property_propagation)
+ {
+ if (!has_block(src_blk)) {
+ throw uhd::lookup_error(
+ std::string("Cannot connect blocks, source block not found: ")
+ + src_blk.to_string());
+ }
+ if (!has_block(dst_blk)) {
+ throw uhd::lookup_error(
+ std::string("Cannot connect blocks, source block not found: ")
+ + src_blk.to_string());
+ }
+ _connect(get_block(src_blk),
+ src_port,
+ get_block(dst_blk),
+ dst_port,
+ skip_property_propagation);
+ }
+
+ void connect(uhd::tx_streamer& /*streamer*/,
+ size_t /*strm_port*/,
+ const block_id_t& /*dst_blk*/,
+ size_t /*dst_port*/)
+ {
+ throw uhd::not_implemented_error("");
+ }
+
+ void connect(const block_id_t& /*src_blk*/,
+ size_t /*src_port*/,
+ uhd::rx_streamer& /*streamer*/,
+ size_t /*strm_port*/)
+ {
+ throw uhd::not_implemented_error("");
+ }
+
+private:
+ /**************************************************************************
+ * Device Setup
+ *************************************************************************/
+ void setup_graph(const uhd::device_addr_t& dev_addr)
+ {
+ // Phase I: Initialize the motherboards
+ auto dev = uhd::device::make(dev_addr);
+ _device = boost::dynamic_pointer_cast<detail::rfnoc_device>(dev);
+ if (!_device) {
+ throw uhd::key_error(std::string("Found no RFNoC devices for ----->\n")
+ + dev_addr.to_pp_string());
+ }
+
+ // Configure endpoint_manager, make sure all routes are established
+ // FIXME
+
+ // Enumerate blocks, load them into the block registry
+ // FIXME
+
+ // Create graph, connect all static routes
+ // FIXME
+ }
+
+
+ /**************************************************************************
+ * Helpers
+ *************************************************************************/
+ /*! Internal connection helper
+ *
+ * Prerequisite: \p src_blk and \p dst_blk need to point to valid nodes
+ */
+ void _connect(std::shared_ptr<node_t> src_blk,
+ size_t src_port,
+ std::shared_ptr<node_t> dst_blk,
+ size_t dst_port,
+ bool skip_property_propagation)
+ {
+ graph_edge_t edge_info(
+ src_port, dst_port, graph_edge_t::DYNAMIC, not skip_property_propagation);
+ edge_info.src_blockid = src_blk->get_unique_id();
+ edge_info.dst_blockid = dst_blk->get_unique_id();
+ _graph->connect(src_blk.get(), dst_blk.get(), edge_info);
+ }
+
+
+ /**************************************************************************
+ * Attributes
+ *************************************************************************/
+ //! Reference to the underlying device implementation
+ detail::rfnoc_device::sptr _device;
+
+ //! Registry for the blocks (it's a separate class)
+ std::unique_ptr<detail::block_container_t> _block_registry;
+
+ //! Reference to the graph
+ std::unique_ptr<detail::graph_t> _graph;
+
+}; /* class rfnoc_graph_impl */
+
+
+/******************************************************************************
+ * Factory
+ *****************************************************************************/
+rfnoc_graph::sptr rfnoc_graph::make(const uhd::device_addr_t& device_addr)
+{
+ return std::make_shared<rfnoc_graph_impl>(device_addr);
+}