aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/include
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-06-13 08:13:57 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-26 11:49:27 -0800
commitde246ea6174e3a6d5fe0dd554d5208f24c2932bb (patch)
treece7d42a8f8c97c1ea2360bed90b73091db2e35c2 /host/lib/include
parent6bd43946a71173cbf0f1d318843ba34d6849dc30 (diff)
downloaduhd-de246ea6174e3a6d5fe0dd554d5208f24c2932bb.tar.gz
uhd-de246ea6174e3a6d5fe0dd554d5208f24c2932bb.tar.bz2
uhd-de246ea6174e3a6d5fe0dd554d5208f24c2932bb.zip
rfnoc: clock_iface: Add flag for clock to be (im-)mutable
An immutable clock means it has a locked frequency, and attempts to change the frequency will cause an exception to be thrown.
Diffstat (limited to 'host/lib/include')
-rw-r--r--host/lib/include/uhdlib/rfnoc/clock_iface.hpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/host/lib/include/uhdlib/rfnoc/clock_iface.hpp b/host/lib/include/uhdlib/rfnoc/clock_iface.hpp
index 807382f13..ae61a645e 100644
--- a/host/lib/include/uhdlib/rfnoc/clock_iface.hpp
+++ b/host/lib/include/uhdlib/rfnoc/clock_iface.hpp
@@ -8,6 +8,8 @@
#define INCLUDED_UHD_RFNOC_CLOCK_IFACE_HPP
#include <uhd/config.hpp>
+#include <uhd/exception.hpp>
+#include <uhd/utils/log.hpp>
#include <atomic>
#include <string>
@@ -16,12 +18,18 @@ namespace uhd { namespace rfnoc {
class clock_iface
{
public:
- clock_iface(const std::string& name) : _name(name)
+ clock_iface(const std::string& name) : _name(name), _is_mutable(true)
{
_is_running = false;
_freq = 0.0;
}
+ clock_iface(const std::string& name, const double freq, const bool is_mutable = true)
+ : _name(name), _freq(freq), _is_mutable(is_mutable)
+ {
+ _is_running = false;
+ }
+
clock_iface() = delete;
clock_iface(const clock_iface& rhs) = delete;
clock_iface(clock_iface&& rhs) = delete;
@@ -38,6 +46,11 @@ public:
return _is_running;
}
+ inline bool is_mutable() const
+ {
+ return _is_mutable;
+ }
+
inline void set_running(bool is_running)
{
_is_running = is_running;
@@ -48,8 +61,14 @@ public:
return _freq;
}
+ //! If the clock is immutable, this will throw if freq is different from the
+ // current frequency.
inline void set_freq(double freq)
{
+ if (!_is_mutable && freq != _freq.load()) {
+ UHD_LOG_ERROR(_name, "Trying to change an immutable clock!");
+ throw uhd::runtime_error("Trying to change an immutable clock!");
+ }
_freq = freq;
}
@@ -57,6 +76,7 @@ private:
const std::string _name;
std::atomic<bool> _is_running;
std::atomic<double> _freq;
+ const bool _is_mutable;
};
}} // namespace uhd::rfnoc