GNU Radio Manual and C++ API Reference 3.10.3.0
The Free & Open Software Radio Ecosystem
rfnoc_block.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2020 Free Software Foundation, Inc.
4 *
5 * SPDX-License-Identifier: GPL-3.0-or-later
6 */
7
8#ifndef INCLUDED_UHD_RFNOC_BLOCK_H
9#define INCLUDED_UHD_RFNOC_BLOCK_H
10
11#include <gnuradio/block.h>
13#include <uhd/rfnoc/noc_block_base.hpp>
14#include <string>
15
16namespace gr {
17namespace uhd {
18
19/*! Base class for RFNoC blocks controlled by GNU Radio
20 *
21 * Any GNU Radio block that is meant to control an RFNoC block
22 * should be derived from this class.
23 */
25{
26protected:
27 // \param block_ref A reference to the underlying block controller
28 rfnoc_block(::uhd::rfnoc::noc_block_base::sptr block_ref);
29
30 rfnoc_block() {} // For virtual subclassing
31
32public:
33 using sptr = std::shared_ptr<rfnoc_block>;
34
35 //! Factory function to create a UHD block controller reference
36 //
37 // \param graph Reference to the flowgraph's RFNoC graph
38 // \param block_args Block args
39 // \param block_name Block name (e.g. "DDC")
40 // \param device_select Device index (motherboard index)
41 // \param block_select Block index
42 // \param max_ref_count Maximum number of references this block can have in
43 // the GNU Radio flow graph
44 static ::uhd::rfnoc::noc_block_base::sptr
46 const ::uhd::device_addr_t& block_args,
47 const std::string& block_name,
48 const int device_select = -1,
49 const int block_select = -1,
50 const size_t max_ref_count = 1);
51
52 //! Return a type-cast block reference, or throw if the cast failed.
53 //
54 // \throws std::runtime_error if there is no valid block reference
55 template <typename block_type>
56 std::shared_ptr<block_type> get_block_ref()
57 {
58 auto cast_block_ref = std::dynamic_pointer_cast<block_type>(d_block_ref);
59 if (!cast_block_ref) {
60 throw std::runtime_error(
61 std::string(
62 "Unable to cast the following block into its desired type: ") +
63 d_block_ref->get_unique_id());
64 }
65 return cast_block_ref;
66 }
67
68 /*! Return the unique ID of the underlying block
69 */
70 std::string get_unique_id() const;
71
72 // GNU Radio-specific overrides
73
74 //! This method should never be called by RFNoC blocks, they do the work
75 // in the FPGA.
76 int general_work(int noutput_items,
77 gr_vector_int& ninput_items,
78 gr_vector_const_void_star& input_items,
79 gr_vector_void_star& output_items);
80
81private:
82 //! Reference to the underlying RFNoC block
83 ::uhd::rfnoc::noc_block_base::sptr d_block_ref;
84};
85
86} // namespace uhd
87} // namespace gr
88
89#endif /* INCLUDED_UHD_RFNOC_BLOCK_H */
The abstract base class for all 'terminal' processing blocks.
Definition: gnuradio-runtime/include/gnuradio/block.h:63
Definition: rfnoc_block.h:25
std::shared_ptr< block_type > get_block_ref()
Return a type-cast block reference, or throw if the cast failed.
Definition: rfnoc_block.h:56
::uhd::rfnoc::noc_block_base::sptr make_block_ref(rfnoc_graph::sptr graph, const ::uhd::device_addr_t &block_args, const std::string &block_name, const int device_select=-1, const int block_select=-1, const size_t max_ref_count=1)
Factory function to create a UHD block controller reference.
rfnoc_block(::uhd::rfnoc::noc_block_base::sptr block_ref)
std::string get_unique_id() const
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
This method should never be called by RFNoC blocks, they do the work.
std::shared_ptr< rfnoc_block > sptr
Definition: rfnoc_block.h:33
rfnoc_block()
Definition: rfnoc_block.h:30
std::shared_ptr< rfnoc_graph > sptr
Definition: rfnoc_graph.h:31
#define GR_UHD_API
Definition: gr-uhd/include/gnuradio/uhd/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::vector< const void * > gr_vector_const_void_star
Definition: types.h:28
std::vector< void * > gr_vector_void_star
Definition: types.h:27
std::vector< int > gr_vector_int
Definition: types.h:23