From 546aa04355ff34924ce1d00fd003cb0ee63c8cf9 Mon Sep 17 00:00:00 2001 From: Trung N Tran Date: Fri, 27 Apr 2018 15:27:13 -0700 Subject: mpm: replace long execution function with async call - Replace mykonos finish_initialization with async version - Replace myknonos setup_cal with async version - Remove disable_timeout on rpc_server init() --- mpm/include/mpm/ad937x/ad937x_ctrl.hpp | 47 ++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'mpm/include') diff --git a/mpm/include/mpm/ad937x/ad937x_ctrl.hpp b/mpm/include/mpm/ad937x/ad937x_ctrl.hpp index c7a31e92a..762bd2e0e 100644 --- a/mpm/include/mpm/ad937x/ad937x_ctrl.hpp +++ b/mpm/include/mpm/ad937x/ad937x_ctrl.hpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace mpm { namespace chips { @@ -84,6 +85,10 @@ public: static const uint32_t DEFAULT_TRACKING_CALS_MASKS; static const uint32_t DEFAULT_INIT_CALS_TIMEOUT; + // Async call handles + std::future handle_finish_initialization; + std::future handle_setup_cal; + /*! \brief make a new AD9371 ctrl object using the specified SPI iface * * \param spi_mutex a mutex that will be locked whenever the SPI iface is to be used @@ -299,10 +304,48 @@ void export_mykonos(){ bp::class_>("ad937x_ctrl", bp::no_init) .def("set_master_clock_rate", &ad937x_ctrl::set_master_clock_rate) .def("begin_initialization", &ad937x_ctrl::begin_initialization) - .def("finish_initialization", &ad937x_ctrl::finish_initialization) + .def("async__finish_initialization", +[]( + ad937x_ctrl& self + ){ + self.handle_finish_initialization = std::async(std::launch::async, + &ad937x_ctrl::finish_initialization, + &self + ); + }) + .def("await__finish_initialization", +[]( + ad937x_ctrl& self + )->bool{ + if (self.handle_finish_initialization.wait_for(std::chrono::seconds(0)) == std::future_status::ready){ + self.handle_finish_initialization.get(); + return true; + } + return false; + }) .def("set_lo_source", &ad937x_ctrl::set_lo_source) .def("get_lo_source", &ad937x_ctrl::get_lo_source) - .def("setup_cal", &ad937x_ctrl::setup_cal) + .def("async__setup_cal", +[]( + ad937x_ctrl& self, + const uint32_t init_cals_mask, + const uint32_t timeout, + const uint32_t tracking_cals_mask + ){ + self.handle_setup_cal = std::async(std::launch::async, + &ad937x_ctrl::setup_cal, + &self, + init_cals_mask, + timeout, + tracking_cals_mask + ); + }) + .def("await__setup_cal", +[]( + ad937x_ctrl& self + )->bool{ + if (self.handle_setup_cal.wait_for(std::chrono::seconds(0)) == std::future_status::ready){ + self.handle_setup_cal.get(); + return true; + } + return false; + }) .def("start_jesd_rx", &ad937x_ctrl::start_jesd_rx) .def("start_jesd_tx", &ad937x_ctrl::start_jesd_tx) .def("start_radio", &ad937x_ctrl::start_radio) -- cgit v1.2.3