diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-05-24 14:46:39 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 11:49:16 -0800 |
commit | 1ed37cdfda93e430037ee4028ec5ac70ab223b1b (patch) | |
tree | 16c20409cf18b0747b107092ed64c3beab4f6e89 /host/include | |
parent | de6dfccc835ad46b5f4362caae66a37651716ab2 (diff) | |
download | uhd-1ed37cdfda93e430037ee4028ec5ac70ab223b1b.tar.gz uhd-1ed37cdfda93e430037ee4028ec5ac70ab223b1b.tar.bz2 uhd-1ed37cdfda93e430037ee4028ec5ac70ab223b1b.zip |
rfnoc: Add block registry/factory and make_args
- noc_block_base now has a ctor defined
- The registry stores factory functions to the individual Noc-Block
implementations
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/rfnoc/CMakeLists.txt | 2 | ||||
-rw-r--r-- | host/include/uhd/rfnoc/noc_block_base.hpp | 21 | ||||
-rw-r--r-- | host/include/uhd/rfnoc/noc_block_make_args.hpp | 44 | ||||
-rw-r--r-- | host/include/uhd/rfnoc/registry.hpp | 78 |
4 files changed, 143 insertions, 2 deletions
diff --git a/host/include/uhd/rfnoc/CMakeLists.txt b/host/include/uhd/rfnoc/CMakeLists.txt index 319240578..41826a9cb 100644 --- a/host/include/uhd/rfnoc/CMakeLists.txt +++ b/host/include/uhd/rfnoc/CMakeLists.txt @@ -16,11 +16,13 @@ if(ENABLE_RFNOC) defaults.hpp dirtifier.hpp graph.hpp + noc_block_make_args.hpp node_ctrl_base.hpp node_ctrl_base.ipp node.hpp node.ipp rate_node_ctrl.hpp + registry.hpp scalar_node_ctrl.hpp sink_block_ctrl_base.hpp sink_node_ctrl.hpp diff --git a/host/include/uhd/rfnoc/noc_block_base.hpp b/host/include/uhd/rfnoc/noc_block_base.hpp index 0adcfdafb..b671e6525 100644 --- a/host/include/uhd/rfnoc/noc_block_base.hpp +++ b/host/include/uhd/rfnoc/noc_block_base.hpp @@ -13,8 +13,12 @@ #include <uhd/rfnoc/register_iface_holder.hpp> //! Shorthand for block constructor -#define UHD_RFNOC_BLOCK_CONSTRUCTOR(CLASS_NAME) \ - CLASS_NAME##_impl(make_args_ptr make_args) : noc_block_base(std::move(make_args)) +#define RFNOC_BLOCK_CONSTRUCTOR(CLASS_NAME) \ + CLASS_NAME##_impl(make_args_ptr make_args) : CLASS_NAME(std::move(make_args)) + +#define RFNOC_DECLARE_BLOCK(CLASS_NAME) \ + using sptr = std::shared_ptr<CLASS_NAME>;\ + CLASS_NAME(make_args_ptr make_args) : noc_block_base(std::move(make_args)) {} namespace uhd { namespace rfnoc { @@ -42,6 +46,14 @@ public: */ using noc_id_t = uint32_t; + //! Forward declaration for the constructor arguments + struct make_args_t; + + //! Opaque pointer to the constructor arguments + using make_args_ptr = std::unique_ptr<make_args_t>; + + virtual ~noc_block_base(); + /************************************************************************** * node_t API calls *************************************************************************/ @@ -71,6 +83,9 @@ public: */ const block_id_t& get_block_id() const { return _block_id; } +protected: + noc_block_base(make_args_ptr make_args); + private: //! This block's Noc-ID noc_id_t _noc_id; @@ -89,4 +104,6 @@ private: }} /* namespace uhd::rfnoc */ +#include <uhd/rfnoc/noc_block_make_args.hpp> + #endif /* INCLUDED_LIBUHD_NOC_BLOCK_BASE_HPP */ diff --git a/host/include/uhd/rfnoc/noc_block_make_args.hpp b/host/include/uhd/rfnoc/noc_block_make_args.hpp new file mode 100644 index 000000000..8a4b1f5ad --- /dev/null +++ b/host/include/uhd/rfnoc/noc_block_make_args.hpp @@ -0,0 +1,44 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_LIBUHD_NOC_BLOCK_MAKE_ARGS_HPP +#define INCLUDED_LIBUHD_NOC_BLOCK_MAKE_ARGS_HPP + +#include <uhd/rfnoc/noc_block_base.hpp> +#include <uhd/rfnoc/register_iface.hpp> +#include <uhd/property_tree.hpp> + +namespace uhd { namespace rfnoc { + +/*! Data structure to hold the arguments passed into the noc_block_base ctor + * + * We want to hide these from the user, so she can't futz around with them. + * Hence the opaque pointer, and non-UHD_API implementation. + */ +struct noc_block_base::make_args_t +{ + //! Noc-ID + noc_id_t noc_id; + + //! Block ID (e.g. 0/Radio#0) + block_id_t block_id; + + //! Number of input ports (gets reported from the FPGA) + size_t num_input_ports; + + //! Number of output ports (gets reported from the FPGA) + size_t num_output_ports; + + //! Register interface to this block's register space + register_iface::sptr reg_iface; + + //! The subtree for this block + uhd::property_tree::sptr tree; +}; + +}} /* namespace uhd::rfnoc */ + +#endif /* INCLUDED_LIBUHD_NOC_BLOCK_MAKE_ARGS_HPP */ diff --git a/host/include/uhd/rfnoc/registry.hpp b/host/include/uhd/rfnoc/registry.hpp new file mode 100644 index 000000000..18d896205 --- /dev/null +++ b/host/include/uhd/rfnoc/registry.hpp @@ -0,0 +1,78 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_LIBUHD_RFNOC_REGISTRY_HPP +#define INCLUDED_LIBUHD_RFNOC_REGISTRY_HPP + +#include <uhd/config.hpp> +#include <uhd/rfnoc/noc_block_base.hpp> +#include <uhd/utils/static.hpp> +#include <functional> +#include <string> + +//! This macro must be placed inside a block implementation file +// after the class definition +#define UHD_RFNOC_BLOCK_REGISTER_DIRECT(CLASS_NAME, NOC_ID, BLOCK_NAME) \ + uhd::rfnoc::noc_block_base::sptr CLASS_NAME##_make( \ + uhd::rfnoc::noc_block_base::make_args_ptr make_args) \ + { \ + return std::make_shared<CLASS_NAME##_impl>(std::move(make_args)); \ + } \ + UHD_STATIC_BLOCK(register_rfnoc_##CLASS_NAME) \ + { \ + uhd::rfnoc::registry::register_block_direct( \ + NOC_ID, BLOCK_NAME, &CLASS_NAME##_make); \ + } + +namespace uhd { namespace rfnoc { + +/*! RFNoC Block Registry + * + * A container for various functions to register blocks + */ +class UHD_API registry +{ +public: + using factory_t = std::function<noc_block_base::sptr(noc_block_base::make_args_ptr)>; + + /*! Register a block that does not use a block descriptor file + * + * Note: It is highly recommended to use the UHD_RFNOC_BLOCK_REGISTER_DIRECT() + * macro instead of calling this function. + * + * Use this registry function for blocks that do not read from a textual + * description (block descriptor file). + * + * If the Noc-ID is already registered, it will print an error to stderr and + * ignore the new block. + * + * \param noc_id The 32-bit Noc-ID for this block (e.g. 0xDDC00000) + * \param block_name The name used for the block ID (e.g. "Radio") + * \param factory_fn A factory function that returns a reference to the + * block + */ + static void register_block_direct(noc_block_base::noc_id_t noc_id, + const std::string& block_name, + factory_t factory_fn); + + /*! Register a block that does use a block descriptor file + * + * Use this registry function for blocks that also have a textual + * description (block descriptor file). + * + * For these blocks, the framework will first look up the Noc-ID from the + * blocks on the FPGA, and then find the corresponding block key by + * searching all the availble block descriptor files. When such a key is + * found, it will be used to find a block that was previously registered + * here. + */ + static void register_block_descriptor(const std::string& block_key, + factory_t factory_fn); +}; + +}} /* namespace uhd::rfnoc */ + +#endif /* INCLUDED_LIBUHD_RFNOC_REGISTRY_HPP */ |