aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/rfnoc/mb_controller.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-05-31 22:11:42 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-26 11:49:23 -0800
commitfaa4786e025e787c196eec99f213da0d51a1f87e (patch)
tree17e39f93b0251e6e87e25d37775f10e55c0119fe /host/lib/rfnoc/mb_controller.cpp
parent0200aedf4497d5bc4ddf9f3a071ed5395e605f2d (diff)
downloaduhd-faa4786e025e787c196eec99f213da0d51a1f87e.tar.gz
uhd-faa4786e025e787c196eec99f213da0d51a1f87e.tar.bz2
uhd-faa4786e025e787c196eec99f213da0d51a1f87e.zip
rfnoc: Add mb_controller API
The mb_controller is an interface to hardware-specific functions of the motherboard. The API works in two ways: - The user can request access to it, and thus interact directly with the motherboard - RFNoC blocks can request access to it, if they need to interact with the motherboard themselves.
Diffstat (limited to 'host/lib/rfnoc/mb_controller.cpp')
-rw-r--r--host/lib/rfnoc/mb_controller.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/host/lib/rfnoc/mb_controller.cpp b/host/lib/rfnoc/mb_controller.cpp
new file mode 100644
index 000000000..10d5ebe47
--- /dev/null
+++ b/host/lib/rfnoc/mb_controller.cpp
@@ -0,0 +1,73 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <uhd/rfnoc/mb_controller.hpp>
+#include <uhd/exception.hpp>
+#include <atomic>
+
+using namespace uhd::rfnoc;
+
+
+/******************************************************************************
+ * Timekeeper API
+ *****************************************************************************/
+mb_controller::timekeeper::timekeeper()
+{
+ // nop
+}
+
+uhd::time_spec_t mb_controller::timekeeper::get_time_now()
+{
+ return time_spec_t::from_ticks(get_ticks_now(), _tick_rate);
+}
+
+uhd::time_spec_t mb_controller::timekeeper::get_time_last_pps()
+{
+ return time_spec_t::from_ticks(get_ticks_last_pps(), _tick_rate);
+}
+
+void mb_controller::timekeeper::set_time_now(const uhd::time_spec_t &time)
+{
+ set_ticks_now(time.to_ticks(_tick_rate));
+}
+
+void mb_controller::timekeeper::set_time_next_pps(const uhd::time_spec_t &time)
+{
+ set_ticks_next_pps(time.to_ticks(_tick_rate));
+}
+
+void mb_controller::timekeeper::set_tick_rate(const double tick_rate)
+{
+ if (_tick_rate == tick_rate) {
+ return;
+ }
+ _tick_rate = tick_rate;
+
+ // The period is the inverse of the tick rate, normalized by nanoseconds,
+ // and represented as Q32 (e.g., period == 1ns means period_ns == 1<<32)
+ const uint64_t period_ns = static_cast<uint64_t>(1e9 / tick_rate * (uint64_t(1) << 32));
+ set_period(period_ns);
+}
+
+size_t mb_controller::get_num_timekeepers() const
+{
+ return _timekeepers.size();
+}
+
+mb_controller::timekeeper::sptr mb_controller::get_timekeeper(const size_t tk_idx) const
+{
+ if (!_timekeepers.count(tk_idx)) {
+ throw uhd::index_error(
+ std::string("No timekeeper with index ") + std::to_string(tk_idx));
+ }
+
+ return _timekeepers.at(tk_idx);
+}
+
+void mb_controller::register_timekeeper(const size_t idx, timekeeper::sptr tk)
+{
+ _timekeepers.emplace(idx, std::move(tk));
+}