aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/rfnoc
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-06-13 13:34:11 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-26 11:49:27 -0800
commit3da938f1242219fdf993576dcfdce7440a63c044 (patch)
tree145b8999ba2c72ebc8e1115ceedd6a8a3a0d2210 /host/lib/rfnoc
parentde246ea6174e3a6d5fe0dd554d5208f24c2932bb (diff)
downloaduhd-3da938f1242219fdf993576dcfdce7440a63c044.tar.gz
uhd-3da938f1242219fdf993576dcfdce7440a63c044.tar.bz2
uhd-3da938f1242219fdf993576dcfdce7440a63c044.zip
rfnoc: Add clock selection to blocks
During registration, blocks must now specify which clock they are using for the timebase (i.e., for timed commands) and for the ctrlport (this is used to determine the length of sleeps and polls). For example, the X300 provides bus_clk and radio_clk; typically, the former is used for the control port, and the latter for the timebase clock. Another virtual clock is called "__graph__", and it means the clock is derived from property propagation via the graph. The actual clocks are provided by the mb_iface. It has two new API calls: get_timebase_clock() and get_ctrlport_clock(), which take an argument as to which clock exactly is requested. On block initialization, those clock_iface objects are copied into the block controller. The get_tick_rate() API call for blocks now exclusively checks the timebase clock_iface, and will no longer cache the current tick rate in a separate _tick_rate member variable. Block controllers can't manually modify the clock_iface, unless they also have access to the mb_controller (like the radio block), and that mb_controller has provided said access. This commit also adds the clock selection API changes to the DDC block, the Null block, and the default block.
Diffstat (limited to 'host/lib/rfnoc')
-rw-r--r--host/lib/rfnoc/block_control.cpp3
-rw-r--r--host/lib/rfnoc/client_zero.cpp5
-rw-r--r--host/lib/rfnoc/ddc_block_control.cpp3
-rw-r--r--host/lib/rfnoc/noc_block_base.cpp50
-rw-r--r--host/lib/rfnoc/null_block_control.cpp3
-rw-r--r--host/lib/rfnoc/registry_factory.cpp18
-rw-r--r--host/lib/rfnoc/rfnoc_graph.cpp36
7 files changed, 83 insertions, 35 deletions
diff --git a/host/lib/rfnoc/block_control.cpp b/host/lib/rfnoc/block_control.cpp
index 78c390001..e6d5cd31d 100644
--- a/host/lib/rfnoc/block_control.cpp
+++ b/host/lib/rfnoc/block_control.cpp
@@ -21,4 +21,5 @@ public:
}
};
-UHD_RFNOC_BLOCK_REGISTER_DIRECT(block_control, DEFAULT_NOC_ID, DEFAULT_BLOCK_NAME)
+UHD_RFNOC_BLOCK_REGISTER_DIRECT(
+ block_control, DEFAULT_NOC_ID, DEFAULT_BLOCK_NAME, CLOCK_KEY_GRAPH, "bus_clk")
diff --git a/host/lib/rfnoc/client_zero.cpp b/host/lib/rfnoc/client_zero.cpp
index aaecdcbf5..6d0e47203 100644
--- a/host/lib/rfnoc/client_zero.cpp
+++ b/host/lib/rfnoc/client_zero.cpp
@@ -220,9 +220,10 @@ client_zero::sptr client_zero::make(chdr_ctrl_endpoint& chdr_ctrl_ep, sep_id_t d
static constexpr uint16_t CLIENT_ZERO_PORT = 0;
static constexpr size_t CLIENT_ZERO_BUFF_CAPACITY = 32;
static constexpr size_t CLIENT_ZERO_MAX_ASYNC_MSGS = 0;
- static clock_iface client_zero_clk{"client_zero"};
+ // This clock_iface doesn't really matter because client_zero doesn't do timed
+ // commands
+ static clock_iface client_zero_clk("client_zero", 100e6, true);
client_zero_clk.set_running(true); // Client zero clock must be always-on.
- client_zero_clk.set_freq(100e6); // The freq is unused. No timed ops or sleeps.
return std::make_shared<client_zero>(chdr_ctrl_ep.get_ctrlport_ep(dst_epid,
CLIENT_ZERO_PORT,
diff --git a/host/lib/rfnoc/ddc_block_control.cpp b/host/lib/rfnoc/ddc_block_control.cpp
index 0b6fd7d89..56bb8cc5a 100644
--- a/host/lib/rfnoc/ddc_block_control.cpp
+++ b/host/lib/rfnoc/ddc_block_control.cpp
@@ -516,4 +516,5 @@ private:
std::vector<property_t<double>> _freq;
};
-UHD_RFNOC_BLOCK_REGISTER_DIRECT(ddc_block_control, 0xDDC00000, "DDC")
+UHD_RFNOC_BLOCK_REGISTER_DIRECT(
+ ddc_block_control, 0xDDC00000, "DDC", CLOCK_KEY_GRAPH, "bus_clk")
diff --git a/host/lib/rfnoc/noc_block_base.cpp b/host/lib/rfnoc/noc_block_base.cpp
index c0d8cf2a9..68093d9b1 100644
--- a/host/lib/rfnoc/noc_block_base.cpp
+++ b/host/lib/rfnoc/noc_block_base.cpp
@@ -23,21 +23,28 @@ noc_block_base::noc_block_base(make_args_ptr make_args)
, _block_id(make_args->block_id)
, _num_input_ports(make_args->num_input_ports)
, _num_output_ports(make_args->num_output_ports)
- , _clock_iface(make_args->clk_iface)
+ , _ctrlport_clock_iface(make_args->ctrlport_clk_iface)
+ , _tb_clock_iface(make_args->tb_clk_iface)
, _mb_controller(std::move(make_args->mb_control))
, _block_args(make_args->args)
, _tree(make_args->tree)
{
+ RFNOC_LOG_TRACE(
+ "Using timebase clock: `" << _tb_clock_iface->get_name() << "'. Current frequency: "
+ << (_tb_clock_iface->get_freq() / 1e6) << " MHz");
+ RFNOC_LOG_TRACE("Using ctrlport clock: `"
+ << _ctrlport_clock_iface->get_name() << "'. Current frequency: "
+ << (_ctrlport_clock_iface->get_freq() / 1e6) << " MHz");
// First, create one tick_rate property for every port
_tick_rate_props.reserve(get_num_input_ports() + get_num_output_ports());
for (size_t input_port = 0; input_port < get_num_input_ports(); input_port++) {
_tick_rate_props.push_back(property_t<double>(PROP_KEY_TICK_RATE,
- DEFAULT_TICK_RATE,
+ _tb_clock_iface->get_freq(),
{res_source_info::INPUT_EDGE, input_port}));
}
for (size_t output_port = 0; output_port < get_num_output_ports(); output_port++) {
_tick_rate_props.push_back(property_t<double>(PROP_KEY_TICK_RATE,
- DEFAULT_TICK_RATE,
+ _tb_clock_iface->get_freq(),
{res_source_info::OUTPUT_EDGE, output_port}));
}
// Register all the tick_rate properties and create a default resolver
@@ -51,14 +58,16 @@ noc_block_base::noc_block_base(make_args_ptr make_args)
auto prop_refs_copy = prop_refs;
add_property_resolver(
{&prop}, std::move(prop_refs_copy), [this, source_prop = &prop]() {
+ // _set_tick_rate() will update _tick_rate, but only if that's
+ // a valid operation for this block
+ this->_set_tick_rate(source_prop->get());
+ // Now, _tick_rate is valid and we will pass its value to all
+ // tick_rate properties
for (property_t<double>& tick_rate_prop : _tick_rate_props) {
- tick_rate_prop = source_prop->get();
+ tick_rate_prop = get_tick_rate();
}
- this->_set_tick_rate(source_prop->get());
});
}
- // Now enable this clock iface
- _clock_iface->set_running(true);
}
noc_block_base::~noc_block_base()
@@ -89,13 +98,19 @@ void noc_block_base::set_num_output_ports(const size_t num_ports)
}
+double noc_block_base::get_tick_rate() const
+{
+ return _tb_clock_iface->get_freq();
+}
+
void noc_block_base::set_tick_rate(const double tick_rate)
{
- if (_tick_rate == tick_rate) {
+ if (tick_rate == get_tick_rate()) {
return;
}
// Update this node
- _set_tick_rate(tick_rate);
+ RFNOC_LOG_TRACE("Setting tb clock freq to " << tick_rate/1e6 << " MHz");
+ _tb_clock_iface->set_freq(tick_rate);
// Now trigger property propagation
if (!_tick_rate_props.empty()) {
auto src_info = _tick_rate_props.at(0).get_src_info();
@@ -105,12 +120,21 @@ void noc_block_base::set_tick_rate(const double tick_rate)
void noc_block_base::_set_tick_rate(const double tick_rate)
{
- if (tick_rate == _tick_rate) {
+ if (tick_rate == get_tick_rate()) {
+ return;
+ }
+ if (tick_rate <= 0) {
+ RFNOC_LOG_WARNING("Attempting to set tick rate to 0. Skipping.")
return;
}
- RFNOC_LOG_TRACE("Updating tick rate to " << (tick_rate / 1e6) << " MHz");
- _clock_iface->set_freq(tick_rate);
- _tick_rate = tick_rate;
+ if (_tb_clock_iface->get_name() == CLOCK_KEY_GRAPH) {
+ RFNOC_LOG_TRACE("Updating tick rate to " << (tick_rate / 1e6) << " MHz");
+ _tb_clock_iface->set_freq(tick_rate);
+ } else {
+ RFNOC_LOG_WARNING("Cannot change tick rate to "
+ << (tick_rate / 1e6)
+ << " MHz, this clock is not configurable by the graph!");
+ }
}
void noc_block_base::shutdown()
diff --git a/host/lib/rfnoc/null_block_control.cpp b/host/lib/rfnoc/null_block_control.cpp
index 21042453d..443c2f3d7 100644
--- a/host/lib/rfnoc/null_block_control.cpp
+++ b/host/lib/rfnoc/null_block_control.cpp
@@ -181,4 +181,5 @@ private:
uint32_t _item_width;
};
-UHD_RFNOC_BLOCK_REGISTER_DIRECT(null_block_control, 0x00000001, "NullSrcSink")
+UHD_RFNOC_BLOCK_REGISTER_DIRECT(
+ null_block_control, 0x00000001, "NullSrcSink", CLOCK_KEY_GRAPH, "bus_clk")
diff --git a/host/lib/rfnoc/registry_factory.cpp b/host/lib/rfnoc/registry_factory.cpp
index d03cb183a..117b60e96 100644
--- a/host/lib/rfnoc/registry_factory.cpp
+++ b/host/lib/rfnoc/registry_factory.cpp
@@ -24,9 +24,8 @@ using namespace uhd::rfnoc;
// descriptor file
//
// This is the direct registry:
-using block_direct_reg_t = std::unordered_map<noc_block_base::noc_id_t,
- std::tuple<std::string /* block_name */,
- registry::factory_t>>;
+using block_direct_reg_t =
+ std::unordered_map<noc_block_base::noc_id_t, block_factory_info_t>;
UHD_SINGLETON_FCN(block_direct_reg_t, get_direct_block_registry);
//
// This is the descriptor registry:
@@ -54,6 +53,8 @@ UHD_SINGLETON_FCN(
*****************************************************************************/
void registry::register_block_direct(noc_block_base::noc_id_t noc_id,
const std::string& block_name,
+ const std::string& timebase_clock,
+ const std::string& ctrlport_clock,
factory_t factory_fn)
{
if (get_direct_block_registry().count(noc_id)) {
@@ -63,8 +64,9 @@ void registry::register_block_direct(noc_block_base::noc_id_t noc_id,
<< std::hex << noc_id << std::dec << std::endl;
return;
}
- get_direct_block_registry().emplace(
- noc_id, std::make_tuple(block_name, std::move(factory_fn)));
+ get_direct_block_registry().emplace(noc_id,
+ block_factory_info_t{
+ block_name, timebase_clock, ctrlport_clock, std::move(factory_fn)});
}
void registry::register_block_descriptor(
@@ -96,8 +98,7 @@ void registry::request_mb_access(const std::string& block_key)
/******************************************************************************
* Factory functions
*****************************************************************************/
-std::pair<registry::factory_t, std::string> factory::get_block_factory(
- noc_block_base::noc_id_t noc_id)
+block_factory_info_t factory::get_block_factory(noc_block_base::noc_id_t noc_id)
{
// First, check the descriptor registry
// FIXME TODO
@@ -109,8 +110,7 @@ std::pair<registry::factory_t, std::string> factory::get_block_factory(
<< std::hex << std::setw(sizeof(noc_block_base::noc_id_t) * 2) << noc_id);
noc_id = DEFAULT_NOC_ID;
}
- auto& block_info = get_direct_block_registry().at(noc_id);
- return {std::get<1>(block_info), std::get<0>(block_info)};
+ return get_direct_block_registry().at(noc_id);
}
bool factory::has_requested_mb_access(noc_block_base::noc_id_t noc_id)
diff --git a/host/lib/rfnoc/rfnoc_graph.cpp b/host/lib/rfnoc/rfnoc_graph.cpp
index 5b2277284..04b13a374 100644
--- a/host/lib/rfnoc/rfnoc_graph.cpp
+++ b/host/lib/rfnoc/rfnoc_graph.cpp
@@ -184,27 +184,47 @@ private:
// Iterate through and register each of the blocks in this mboard
for (size_t portno = 0; portno < num_blocks; ++portno) {
auto noc_id = mb_cz->get_noc_id(portno + first_block_port);
- auto block_factory_pair = factory::get_block_factory(noc_id);
+ auto block_factory_info = factory::get_block_factory(noc_id);
auto block_info = mb_cz->get_block_info(portno + first_block_port);
block_id_t block_id(mb_idx,
- block_factory_pair.second,
- block_count_map[block_factory_pair.second]++);
- auto clk_iface = std::make_shared<clock_iface>(block_id.to_string() + "_clock");
+ block_factory_info.block_name,
+ block_count_map[block_factory_info.block_name]++);
+ // Get access to the clock interface objects. We have some rules
+ // here:
+ // - The ctrlport clock must always be provided through the
+ // BSP via mb_iface
+ // - The timebase clock can be set to "graph", which means the
+ // block takes care of the timebase itself (via property
+ // propagation). In that case, we generate a clock iface
+ // object on the fly here.
+ // - In all other cases, the BSP must provide us that clock
+ // iface object through the mb_iface
+ auto ctrlport_clk_iface =
+ mb.get_clock_iface(block_factory_info.ctrlport_clk);
+ auto tb_clk_iface = (block_factory_info.timebase_clk == CLOCK_KEY_GRAPH) ?
+ std::make_shared<clock_iface>(CLOCK_KEY_GRAPH) :
+ mb.get_clock_iface(block_factory_info.timebase_clk);
+ // A "graph" clock is always "running"
+ if (block_factory_info.timebase_clk == CLOCK_KEY_GRAPH) {
+ tb_clk_iface->set_running(true);
+ }
auto block_reg_iface = _gsm->get_block_register_iface(ctrl_sep_addr,
portno,
- *clk_iface.get(),
- *clk_iface.get());
+ *ctrlport_clk_iface.get(),
+ *tb_clk_iface.get());
auto make_args_uptr = std::make_unique<noc_block_base::make_args_t>();
make_args_uptr->noc_id = noc_id;
make_args_uptr->block_id = block_id;
make_args_uptr->num_input_ports = block_info.num_inputs;
make_args_uptr->num_output_ports = block_info.num_outputs;
make_args_uptr->reg_iface = block_reg_iface;
- make_args_uptr->clk_iface = clk_iface;
+ make_args_uptr->tb_clk_iface = tb_clk_iface;
+ make_args_uptr->ctrlport_clk_iface = ctrlport_clk_iface;
make_args_uptr->mb_control = (factory::has_requested_mb_access(noc_id) ? _mb_controllers.at(mb_idx) : nullptr);
make_args_uptr->tree = _tree->subtree("/mboards/0"); /* FIXME Get the block's subtree */
make_args_uptr->args = dev_addr; // TODO filter the device args
- _block_registry->register_block(block_factory_pair.first(std::move(make_args_uptr)));
+ _block_registry->register_block(
+ block_factory_info.factory_fn(std::move(make_args_uptr)));
_xbar_block_config[block_id.to_string()] = {
portno, noc_id, block_id.get_block_count()};
}