From 867cd4a23b28ad469b61cb822980fecd798f108b Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 30 Jul 2019 10:31:28 -0700 Subject: rfnoc: rfnoc_graph: Add is_connectable() API rfnoc_graph::is_connectable() allows to check if is possible to call connect() on blocks. If blocks are attached to other blocks statically, or if they are on unconnected devices, they are not connectable. --- host/include/uhd/rfnoc_graph.hpp | 13 +++++++ host/lib/rfnoc/rfnoc_graph.cpp | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/host/include/uhd/rfnoc_graph.hpp b/host/include/uhd/rfnoc_graph.hpp index ff7e46aa8..09e95d667 100644 --- a/host/include/uhd/rfnoc_graph.hpp +++ b/host/include/uhd/rfnoc_graph.hpp @@ -156,6 +156,19 @@ public: /************************************************************************** * Connection APIs *************************************************************************/ + /*! Verify if two blocks/ports are connectable. + * + * If this call returns true, then connect() can be called with the same + * arguments. It does not, however, check if the block was already + * connnected. + * + * \returns true if the two blocks are connectable + */ + virtual bool is_connectable(const block_id_t& src_blk, + size_t src_port, + const block_id_t& dst_blk, + size_t dst_port) = 0; + /*! Connect a RFNOC block with block ID \p src_block to another with block ID \p * dst_block. * diff --git a/host/lib/rfnoc/rfnoc_graph.cpp b/host/lib/rfnoc/rfnoc_graph.cpp index 511e61f05..86211af6c 100644 --- a/host/lib/rfnoc/rfnoc_graph.cpp +++ b/host/lib/rfnoc/rfnoc_graph.cpp @@ -91,6 +91,79 @@ public: /************************************************************************** * Graph Connections *************************************************************************/ + bool is_connectable(const block_id_t& src_blk, + size_t src_port, + const block_id_t& dst_blk, + size_t dst_port) + { + try { + const std::string src_blk_info = + src_blk.to_string() + ":" + std::to_string(src_port); + const std::string dst_blk_info = + dst_blk.to_string() + ":" + std::to_string(dst_port); + + // Find the static edge for src_blk:src_port + auto src_static_edge_o = _get_static_edge( + [src_blk_id = src_blk.to_string(), src_port](const graph_edge_t& edge) { + return edge.src_blockid == src_blk_id && edge.src_port == src_port; + }); + // If the edge doesn't exist, then it's not even connected in the + // FPGA. + if (!src_static_edge_o) { + return false; + } + graph_edge_t src_static_edge = src_static_edge_o.get(); + + // Now see if it's already connected to the destination + if (src_static_edge.dst_blockid == dst_blk.to_string() + && src_static_edge.dst_port == dst_port) { + return true; + } + + // If they're not statically connected, the source *must* be connected + // to an SEP, or this route is impossible + if (block_id_t(src_static_edge.dst_blockid).get_block_name() != NODE_ID_SEP) { + return false; + } + + // OK, now we know which source SEP we have + const std::string src_sep_info = src_static_edge.dst_blockid; + // const sep_addr_t src_sep_addr = _sep_map.at(src_sep_info); + + // Now find the static edge for the destination SEP + auto dst_static_edge_o = _get_static_edge( + [dst_blk_id = dst_blk.to_string(), dst_port](const graph_edge_t& edge) { + return edge.dst_blockid == dst_blk_id && edge.dst_port == dst_port; + }); + // If the edge doesn't exist, then it's not even connected in the + // FPGA. + if (!dst_static_edge_o) { + return false; + } + graph_edge_t dst_static_edge = dst_static_edge_o.get(); + + // If they're not statically connected, the source *must* be connected + // to an SEP, or this route is impossible + if (block_id_t(dst_static_edge.src_blockid).get_block_name() != NODE_ID_SEP) { + return false; + } + + // OK, now we know which destination SEP we have + const std::string dst_sep_info = dst_static_edge.src_blockid; + // const sep_addr_t dst_sep_addr = _sep_map.at(dst_sep_info); + + UHD_LOG_WARNING(LOG_ID, + "is_connectable() currently assuming that SEPs" + << dst_sep_info << " and " << src_sep_info + << " are connectable. " + "Please implement a better check."); + } catch (...) { + return false; + } + return true; + } + + void connect(const block_id_t& src_blk, size_t src_port, const block_id_t& dst_blk, -- cgit v1.2.3