diff options
author | Grant Meyerhoff <grant.meyerhoff@ni.com> | 2021-06-14 11:25:58 -0500 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-06-17 12:35:32 -0500 |
commit | 86a1c47ee1a1d1d2aa9b7904ecf5486bb3bf3eac (patch) | |
tree | eba0358aec899fdaf3c85bb78ebb3c94c053fd7f /host | |
parent | c0a44be527e65aa83f1a00ab59785906a5411612 (diff) | |
download | uhd-86a1c47ee1a1d1d2aa9b7904ecf5486bb3bf3eac.tar.gz uhd-86a1c47ee1a1d1d2aa9b7904ecf5486bb3bf3eac.tar.bz2 uhd-86a1c47ee1a1d1d2aa9b7904ecf5486bb3bf3eac.zip |
uhd: Add callback for setting sync_sources
Diffstat (limited to 'host')
-rw-r--r-- | host/include/uhd/rfnoc/mb_controller.hpp | 18 | ||||
-rw-r--r-- | host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp | 4 | ||||
-rw-r--r-- | host/lib/rfnoc/mb_controller.cpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/mpmd/mpmd_mb_controller.cpp | 25 |
4 files changed, 53 insertions, 0 deletions
diff --git a/host/include/uhd/rfnoc/mb_controller.hpp b/host/include/uhd/rfnoc/mb_controller.hpp index 5ca0ce52a..259b107ab 100644 --- a/host/include/uhd/rfnoc/mb_controller.hpp +++ b/host/include/uhd/rfnoc/mb_controller.hpp @@ -27,6 +27,14 @@ class UHD_API mb_controller : public uhd::noncopyable, { public: using sptr = std::shared_ptr<mb_controller>; + using sync_source_t = device_addr_t; + + /*! Callback function for changing sync sources + * + * When a sync source is changed, the sync source callback function is called + * to notify any registrants of the update + */ + using sync_source_updater_t = std::function<void(const sync_source_t& sync_source)>; virtual ~mb_controller() {} @@ -387,6 +395,16 @@ public: virtual void set_gpio_src( const std::string& bank, const std::vector<std::string>& src); + /*! Register a callback function to update sync sources + * + * This callback alerts those registered that a change has + * occurred to a sync source, whether that be the clock_source, + * time_source, or both via sync_source. + * + * \param callback_f The function to call when a sync source is updated + */ + virtual void register_sync_source_updater(sync_source_updater_t callback_f); + protected: /*! Stash away a timekeeper. This needs to be called by the implementer of * mb_controller. diff --git a/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp b/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp index a40398991..e7498b9f5 100644 --- a/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp +++ b/host/lib/include/uhdlib/usrp/common/mpmd_mb_controller.hpp @@ -101,6 +101,8 @@ public: std::vector<std::string> get_gpio_src(const std::string& bank) override; void set_gpio_src( const std::string& bank, const std::vector<std::string>& src) override; + void register_sync_source_updater( + mb_controller::sync_source_updater_t callback_f) override; private: /************************************************************************** @@ -118,6 +120,8 @@ private: std::vector<std::string> _gpio_banks; std::unordered_map<std::string, std::vector<std::string>> _gpio_srcs; + std::vector<mb_controller::sync_source_updater_t> _sync_source_updaters; + public: /*! When the FPGA is reloaded, pass the notification to every Radio block * Public to allow other classes to register for notifications. diff --git a/host/lib/rfnoc/mb_controller.cpp b/host/lib/rfnoc/mb_controller.cpp index 356224f83..c7034fd5f 100644 --- a/host/lib/rfnoc/mb_controller.cpp +++ b/host/lib/rfnoc/mb_controller.cpp @@ -191,3 +191,9 @@ void mb_controller::set_gpio_src(const std::string&, const std::vector<std::stri { throw uhd::not_implemented_error("set_gpio_src() not supported on this motherboard!"); } + +void mb_controller::register_sync_source_updater(mb_controller::sync_source_updater_t) +{ + throw uhd::not_implemented_error( + "register_sync_source_updater() not supported on this motherboard!"); +} diff --git a/host/lib/usrp/mpmd/mpmd_mb_controller.cpp b/host/lib/usrp/mpmd/mpmd_mb_controller.cpp index 9bbd324b0..665a38152 100644 --- a/host/lib/usrp/mpmd/mpmd_mb_controller.cpp +++ b/host/lib/usrp/mpmd/mpmd_mb_controller.cpp @@ -125,6 +125,13 @@ std::string mpmd_mb_controller::get_mboard_name() const void mpmd_mb_controller::set_time_source(const std::string& source) { _rpc->get_raw_rpc_client()->notify_with_token(MPMD_DEFAULT_LONG_TIMEOUT, "set_time_source", source); + if (!_sync_source_updaters.empty()) { + mb_controller::sync_source_t sync_source; + sync_source["time_source"] = source; + for (const auto& updater : _sync_source_updaters) { + updater(sync_source); + } + } } std::string mpmd_mb_controller::get_time_source() const @@ -140,6 +147,13 @@ std::vector<std::string> mpmd_mb_controller::get_time_sources() const void mpmd_mb_controller::set_clock_source(const std::string& source) { _rpc->get_raw_rpc_client()->notify_with_token(MPMD_DEFAULT_LONG_TIMEOUT, "set_clock_source", source); + if (!_sync_source_updaters.empty()) { + mb_controller::sync_source_t sync_source; + sync_source["clock_source"] = source; + for (const auto& updater : _sync_source_updaters) { + updater(sync_source); + } + } } std::string mpmd_mb_controller::get_clock_source() const @@ -169,6 +183,11 @@ void mpmd_mb_controller::set_sync_source(const device_addr_t& sync_source) } _rpc->get_raw_rpc_client()->notify_with_token( MPMD_DEFAULT_LONG_TIMEOUT, "set_sync_source", sync_source_map); + if (!_sync_source_updaters.empty()) { + for (const auto& updater : _sync_source_updaters) { + updater(sync_source); + } + } } device_addr_t mpmd_mb_controller::get_sync_source() const @@ -259,3 +278,9 @@ void mpmd_mb_controller::set_gpio_src( } _rpc->set_gpio_src(bank, src); } + +void mpmd_mb_controller::register_sync_source_updater( + mb_controller::sync_source_updater_t callback_f) +{ + _sync_source_updaters.push_back(callback_f); +} |