From 227fe34217e5430f78c6b679ba215b68a6a5c1a0 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 8 May 2019 13:13:32 -0700 Subject: n3xx: mg: Make set_freq() call asynchronous This does not change the MPM/UHD API, but it makes the set_freq() call asynchronous on the MPM side. The upside is that it will release the GIL if the set_freq() call takes too long, e.g., because of MPM calibrations. --- mpm/include/mpm/ad937x/ad937x_ctrl.hpp | 25 +++++++++++++++++++++++++ mpm/python/usrp_mpm/dboard_manager/magnesium.py | 14 ++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'mpm') diff --git a/mpm/include/mpm/ad937x/ad937x_ctrl.hpp b/mpm/include/mpm/ad937x/ad937x_ctrl.hpp index 6d28eccd1..cb4d0e060 100644 --- a/mpm/include/mpm/ad937x/ad937x_ctrl.hpp +++ b/mpm/include/mpm/ad937x/ad937x_ctrl.hpp @@ -85,6 +85,7 @@ public: // Async call handles std::future handle_finish_initialization; std::future handle_setup_cal; + std::future handle_set_freq; /*! \brief make a new AD9371 ctrl object using the specified SPI iface * @@ -344,6 +345,30 @@ void export_mykonos(py::module& top_module) .def("set_clock_rate", &ad937x_ctrl::set_clock_rate) .def("enable_channel", &ad937x_ctrl::enable_channel) .def("set_freq", &ad937x_ctrl::set_freq) + .def("async__set_freq", +[]( + ad937x_ctrl& self, + const std::string &which, + const double value, + const bool wait_for_lock + ){ + self.handle_set_freq = std::async(std::launch::async, + &ad937x_ctrl::set_freq, + &self, + which, + value, + wait_for_lock + ); + }) + .def("await__set_freq", +[]( + ad937x_ctrl& self + )->bool{ + if (self.handle_set_freq.wait_for(std::chrono::seconds(0)) + == std::future_status::ready){ + self.handle_set_freq.get(); + return true; + } + return false; + }) .def("get_freq", &ad937x_ctrl::get_freq) .def("get_lo_locked", &ad937x_ctrl::get_lo_locked) .def("set_fir", &ad937x_ctrl::set_fir) diff --git a/mpm/python/usrp_mpm/dboard_manager/magnesium.py b/mpm/python/usrp_mpm/dboard_manager/magnesium.py index 13e621414..c4e2f4131 100644 --- a/mpm/python/usrp_mpm/dboard_manager/magnesium.py +++ b/mpm/python/usrp_mpm/dboard_manager/magnesium.py @@ -18,6 +18,7 @@ from usrp_mpm.cores import nijesdcore from usrp_mpm.mpmlog import get_logger from usrp_mpm.sys_utils.uio import open_uio from usrp_mpm.user_eeprom import BfrfsEEPROM +from usrp_mpm.mpmutils import async_exec ############################################################################### # SPI Helpers @@ -328,6 +329,19 @@ class Magnesium(BfrfsEEPROM, DboardManagerBase): # The reference clock is handled elsewhere since it is a motherboard- # level clock. + def set_freq(self, which, freq, wait_for_lock): + """ + Perform asynchronous tuning. This will, under the hood, call set_freq() + on the AD937X object, but will spin it out into an asynchronous + execution. We do this because under some circumstances, the set_freq() + call can take a long time to execute, and we want to release the GIL + during that time. + + Note: This overrides the set_freq() call provided from self.mykonos. + """ + self.log.trace("Tuning {} {} {}".format(which, freq, wait_for_lock)) + async_exec(self.mykonos, "set_freq", which, freq, wait_for_lock) + return self.mykonos.get_freq(which) def _reinit(self, master_clock_rate): """ -- cgit v1.2.3