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/block_ctrl_base_factory.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/block_ctrl_base_factory.cpp')
| -rw-r--r-- | host/lib/rfnoc/block_ctrl_base_factory.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/host/lib/rfnoc/block_ctrl_base_factory.cpp b/host/lib/rfnoc/block_ctrl_base_factory.cpp new file mode 100644 index 000000000..aab2ed475 --- /dev/null +++ b/host/lib/rfnoc/block_ctrl_base_factory.cpp @@ -0,0 +1,96 @@ +// +// Copyright 2014 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 <boost/format.hpp> +#include <uhd/utils/msg.hpp> +#include <uhd/utils/log.hpp> +#include <uhd/rfnoc/blockdef.hpp> +#include <uhd/rfnoc/block_ctrl_base.hpp> + +#define UHD_FACTORY_LOG() UHD_LOGV(never) + +using namespace uhd; +using namespace uhd::rfnoc; + +typedef uhd::dict<std::string, block_ctrl_base::make_t> block_fcn_reg_t; +// Instantiate the block function registry container +UHD_SINGLETON_FCN(block_fcn_reg_t, get_block_fcn_regs); + +void block_ctrl_base::register_block( + const make_t &make, + const std::string &key +) { + if (get_block_fcn_regs().has_key(key)) { + throw uhd::runtime_error( + str(boost::format("Attempting to register an RFNoC block with key %s for the second time.") % key) + ); + } + + get_block_fcn_regs().set(key, make); +} + +/*! Look up names for blocks in XML files using NoC ID. + */ +static void lookup_block_key(boost::uint64_t noc_id, make_args_t &make_args) +{ + try { + blockdef::sptr bd = blockdef::make_from_noc_id(noc_id); + if (not bd) { + make_args.block_key = DEFAULT_BLOCK_NAME; + make_args.block_name = DEFAULT_BLOCK_NAME; + return; + } + UHD_ASSERT_THROW(bd->is_block()); + make_args.block_key = bd->get_key(); + make_args.block_name = bd->get_name(); + return; + } catch (std::exception &e) { + UHD_MSG(warning) << str(boost::format("Error while looking up name for NoC-ID %016X.\n%s") % noc_id % e.what()) << std::endl; + } + + make_args.block_key = DEFAULT_BLOCK_NAME; + make_args.block_name = DEFAULT_BLOCK_NAME; +} + + +block_ctrl_base::sptr block_ctrl_base::make( + const make_args_t &make_args_, + boost::uint64_t noc_id +) { + UHD_FACTORY_LOG() << "[RFNoC Factory] block_ctrl_base::make() " << std::endl; + make_args_t make_args = make_args_; + + // Check if a block key was specified, in this case, we *must* either + // create a specialized block controller class or throw + if (make_args.block_key.empty()) { + lookup_block_key(noc_id, make_args); + } else if (not get_block_fcn_regs().has_key(make_args.block_key)) { + throw uhd::runtime_error( + str(boost::format("No block controller class registered for key '%s'.") % make_args.block_key) + ); + } + if (not get_block_fcn_regs().has_key(make_args.block_key)) { + make_args.block_key = DEFAULT_BLOCK_NAME; + } + if (make_args.block_name.empty()) { + make_args.block_name = make_args.block_key; + } + + UHD_FACTORY_LOG() << "[RFNoC Factory] Using controller key '" << make_args.block_key << "' and block name '" << make_args.block_name << "'" << std::endl; + return get_block_fcn_regs()[make_args.block_key](make_args); +} + |
