diff options
| author | Martin Braun <martin.braun@ettus.com> | 2016-08-01 18:17:41 -0700 | 
|---|---|---|
| committer | Martin Braun <martin.braun@ettus.com> | 2016-08-09 12:42:52 -0700 | 
| commit | 3bf4b000f7d9a7f4af82c21753556ede7e8df6e3 (patch) | |
| tree | 2228d7eb58c4d83d91192cb9b6a908e4e49f6317 /host/lib/rfnoc/graph_impl.cpp | |
| parent | c5b076173e2d866f3ee99c113a37183c5ec20f0b (diff) | |
| download | uhd-3bf4b000f7d9a7f4af82c21753556ede7e8df6e3.tar.gz uhd-3bf4b000f7d9a7f4af82c21753556ede7e8df6e3.tar.bz2 uhd-3bf4b000f7d9a7f4af82c21753556ede7e8df6e3.zip | |
Merging RFNoC support for X310
Diffstat (limited to 'host/lib/rfnoc/graph_impl.cpp')
| -rw-r--r-- | host/lib/rfnoc/graph_impl.cpp | 164 | 
1 files changed, 164 insertions, 0 deletions
| diff --git a/host/lib/rfnoc/graph_impl.cpp b/host/lib/rfnoc/graph_impl.cpp new file mode 100644 index 000000000..fdf4fdc78 --- /dev/null +++ b/host/lib/rfnoc/graph_impl.cpp @@ -0,0 +1,164 @@ +// +// Copyright 2016 Ettus Research LLC +// +// 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/>. +// + +#include "graph_impl.hpp" +#include <uhd/rfnoc/source_block_ctrl_base.hpp> +#include <uhd/rfnoc/sink_block_ctrl_base.hpp> +#include <uhd/utils/msg.hpp> + +using namespace uhd::rfnoc; + +/**************************************************************************** + * Structors + ***************************************************************************/ +graph_impl::graph_impl( +            const std::string &name, +            boost::weak_ptr<uhd::device3> device_ptr +            //async_msg_handler::sptr msg_handler +) : _name(name) +  , _device_ptr(device_ptr) +{ + +} + + +/**************************************************************************** + * Connection API + ***************************************************************************/ +void graph_impl::connect( +        const block_id_t &src_block, +        size_t src_block_port, +        const block_id_t &dst_block, +        size_t dst_block_port, +        const size_t pkt_size_ +) { +    device3::sptr device_ptr = _device_ptr.lock(); +    if (not device_ptr) { +        throw uhd::runtime_error("Invalid device"); +    } + +    uhd::rfnoc::source_block_ctrl_base::sptr src = device_ptr->get_block_ctrl<rfnoc::source_block_ctrl_base>(src_block); +    uhd::rfnoc::sink_block_ctrl_base::sptr dst = device_ptr->get_block_ctrl<rfnoc::sink_block_ctrl_base>(dst_block); + +    /******************************************************************** +     * 1. Draw the edges (logically connect the nodes) +     ********************************************************************/ +    size_t actual_src_block_port = src->connect_downstream( +            boost::dynamic_pointer_cast<uhd::rfnoc::node_ctrl_base>(dst), +            src_block_port +    ); +    if (src_block_port == uhd::rfnoc::ANY_PORT) { +        src_block_port = actual_src_block_port; +    } else if (src_block_port != actual_src_block_port) { +        throw uhd::runtime_error(str( +            boost::format("Can't connect to port %d on block %s.") +            % src_block_port % src->unique_id() +        )); +    } +    size_t actual_dst_block_port = dst->connect_upstream( +            boost::dynamic_pointer_cast<uhd::rfnoc::node_ctrl_base>(src), +            dst_block_port +    ); +    if (dst_block_port == uhd::rfnoc::ANY_PORT) { +        dst_block_port = actual_dst_block_port; +    } else if (dst_block_port != actual_dst_block_port) { +        throw uhd::runtime_error(str( +            boost::format("Can't connect to port %d on block %s.") +            % dst_block_port % dst->unique_id() +        )); +    } +    src->set_downstream_port(actual_src_block_port, actual_dst_block_port); +    dst->set_upstream_port(actual_dst_block_port, actual_src_block_port); +    // At this point, ports are locked and no one else can simply connect +    // into them. +    UHD_MSG(status) +        << "[" << _name << "] Connecting " +        << src_block << ":" << actual_src_block_port << " --> " +        << dst_block << ":" << actual_dst_block_port << std::endl; + +    /******************************************************************** +     * 2. Check IO signatures match +     ********************************************************************/ +    if (not rfnoc::stream_sig_t::is_compatible( +                src->get_output_signature(actual_src_block_port), +                dst->get_input_signature(actual_dst_block_port) +        )) { +        throw uhd::runtime_error(str( +            boost::format("Can't connect block %s to %s: IO signature mismatch\n(%s is incompatible with %s).") +            % src->get_block_id().get() % dst->get_block_id().get() +            % src->get_output_signature(actual_src_block_port) +            % dst->get_input_signature(actual_dst_block_port) +        )); +    } + +    /******************************************************************** +     * 3. Configure the source block's destination +     ********************************************************************/ +    // Calculate SID +    sid_t sid = dst->get_address(dst_block_port); +    sid.set_src(src->get_address(src_block_port)); + +    // Set SID on source block +    src->set_destination(sid.get(), src_block_port); + +    /******************************************************************** +     * 4. Configure flow control +     ********************************************************************/ +    size_t pkt_size = (pkt_size_ != 0) ? pkt_size_ : src->get_output_signature(src_block_port).packet_size; +    if (pkt_size == 0) { // Unspecified packet rate. Assume max packet size. +        UHD_MSG(status) << "Assuming max packet size for " << src->get_block_id() << std::endl; +        pkt_size = uhd::rfnoc::MAX_PACKET_SIZE; +    } +    // FC window (in packets) depends on FIFO size...          ...and packet size. +    size_t buf_size_pkts = dst->get_fifo_size(dst_block_port) / pkt_size; +    if (buf_size_pkts == 0) { +        throw uhd::runtime_error(str( +            boost::format("Input FIFO for block %s is too small (%d kiB) for packets of size %d kiB\n" +                          "coming from block %s.") +            % dst->get_block_id().get() % (dst->get_fifo_size(dst_block_port) / 1024) +            % (pkt_size / 1024) % src->get_block_id().get() +        )); +    } +    src->configure_flow_control_out(buf_size_pkts, src_block_port); +    // On the same crossbar, use lots of FC packets +    size_t pkts_per_ack = std::min( +            uhd::rfnoc::DEFAULT_FC_XBAR_PKTS_PER_ACK, +            buf_size_pkts - 1 +    ); +    // Over the network, use less or we'd flood the transport +    if (sid.get_src_addr() != sid.get_dst_addr()) { +        pkts_per_ack = std::max<size_t>(buf_size_pkts / uhd::rfnoc::DEFAULT_FC_TX_RESPONSE_FREQ, 1); +    } +    dst->configure_flow_control_in( +            0, // Default to not use cycles +            pkts_per_ack, +            dst_block_port +    ); + +    /******************************************************************** +     * 5. Configure error policy +     ********************************************************************/ +    dst->set_error_policy("next_burst"); +} + +void graph_impl::connect( +        const block_id_t &src_block, +        const block_id_t &dst_block +) { +    connect(src_block, ANY_PORT, dst_block, ANY_PORT); +} + | 
