diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-07-30 10:31:28 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 11:49:33 -0800 |
commit | 867cd4a23b28ad469b61cb822980fecd798f108b (patch) | |
tree | aae4e906b7e693a4cc06a30a71f0d3ba6e51a90b | |
parent | 9b8e4e652c168e76f7cf2ca0a699640961b8e6ce (diff) | |
download | uhd-867cd4a23b28ad469b61cb822980fecd798f108b.tar.gz uhd-867cd4a23b28ad469b61cb822980fecd798f108b.tar.bz2 uhd-867cd4a23b28ad469b61cb822980fecd798f108b.zip |
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.
-rw-r--r-- | host/include/uhd/rfnoc_graph.hpp | 13 | ||||
-rw-r--r-- | host/lib/rfnoc/rfnoc_graph.cpp | 73 |
2 files changed, 86 insertions, 0 deletions
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, |