From b14bc217e9598578bef89707ca4febc11e0f4290 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 6 Jun 2017 11:27:07 -0700 Subject: mpm/mpmd: Dboard info is now stored in mboard info; refactored initialization --- host/lib/usrp/mpmd/mpmd_impl.hpp | 25 ++++++-- host/lib/usrp/mpmd/mpmd_mboard_impl.cpp | 108 +++++++++++++++++++++----------- 2 files changed, 90 insertions(+), 43 deletions(-) (limited to 'host/lib') diff --git a/host/lib/usrp/mpmd/mpmd_impl.hpp b/host/lib/usrp/mpmd/mpmd_impl.hpp index 3051ada71..b6b02904c 100644 --- a/host/lib/usrp/mpmd/mpmd_impl.hpp +++ b/host/lib/usrp/mpmd/mpmd_impl.hpp @@ -79,6 +79,11 @@ class mpmd_mboard_impl //! Device information is read back via MPM and stored here. uhd::device_addr_t device_info; + //! Dboard info is read back via MPM and stored here. There will be one + // dictionary per dboard; but there's no requirement for the dictionary + // to be populated at all. + std::vector dboard_info; + //! Number of RFNoC crossbars on this device size_t num_xbars = 0; @@ -110,19 +115,27 @@ class mpmd_mboard_impl private: /************************************************************************* - * Private attributes + * Private methods ************************************************************************/ - //! Stores a list of local addresses of the crossbars. The local address is - // what we use when addressing a crossbar in a CHDR header. - std::vector xbar_local_addrs; - - /*! Renew the claim onto the device. * * This is meant to be called repeatedly, e.g., using a UHD task. */ bool claim(); + uhd::task::sptr claim_device_and_make_task( + uhd::rpc_client::sptr rpc, + const uhd::device_addr_t mb_args + ); + + /************************************************************************* + * Private attributes + ************************************************************************/ + //! Stores a list of local addresses of the crossbars. The local address is + // what we use when addressing a crossbar in a CHDR header. + std::vector xbar_local_addrs; + + /*! Continuously reclaims the device. */ uhd::task::sptr _claimer_task; diff --git a/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp b/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp index 0584813df..0c8e5911a 100644 --- a/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp +++ b/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp @@ -34,6 +34,36 @@ namespace { const std::string MPMD_DEFAULT_SESSION_ID = "UHD"; + + /************************************************************************* + * Helper functions + ************************************************************************/ + + void init_device( + uhd::rpc_client::sptr rpc, + const uhd::device_addr_t mb_args + ) { + // TODO maybe put this somewhere else? + const std::set key_blacklist{ + "serial", "claimed", "type", "rev", "addr" + }; + std::map mpm_device_args; + for (const auto &key : mb_args.keys()) { + if (not key_blacklist.count(key)) { + mpm_device_args[key] = mb_args[key]; + } + } + rpc->set_timeout(mb_args.cast( + "init_timeout", MPMD_DEFAULT_INIT_TIMEOUT + )); + if (not rpc->request_with_token("init", mpm_device_args)) { + throw uhd::runtime_error("Failed to initialize device."); + } + rpc->set_timeout(mb_args.cast( + "rpc_timeout", MPMD_DEFAULT_RPC_TIMEOUT + )); + } + } using namespace uhd; @@ -53,53 +83,34 @@ mpmd_mboard_impl::mpmd_mboard_impl( << " mboard args: " << mb_args.to_string() ; - // Claim logic - auto rpc_token = rpc->request("claim", - mb_args.get("session_id", MPMD_DEFAULT_SESSION_ID) - ); - if (rpc_token.empty()) { - throw uhd::value_error("mpmd device claiming failed!"); - } - UHD_LOG_TRACE("MPMD", "Received claim token " << rpc_token); - rpc->set_token(rpc_token); - _claimer_task = task::make([this] { - if (not this->claim()) { - throw uhd::value_error("mpmd device reclaiming loop failed!"); - }; - std::this_thread::sleep_for( - std::chrono::milliseconds(MPMD_RECLAIM_INTERVAL_MS) - ); - }); + _claimer_task = claim_device_and_make_task(rpc, mb_args); + // No one else can now claim the device. + init_device(rpc, mb_args); + // RFNoC block clocks are now on. Noc-IDs can be read back. + - // Init and query info - std::map mpm_device_args; - const std::set key_blacklist{ // TODO put this somewhere else - "serial", "claimed", "type", "rev", "addr" - }; - for (const auto &key : mb_args.keys()) { - if (not key_blacklist.count(key)) { - mpm_device_args[key] = mb_args[key]; - } - } - rpc->set_timeout(mb_args.cast( - "init_timeout", MPMD_DEFAULT_INIT_TIMEOUT - )); - if (not rpc->request_with_token("init", mpm_device_args)) { - throw uhd::runtime_error("Failed to initialize device."); - } auto device_info_dict = rpc->request("get_device_info"); for (const auto &info_pair : device_info_dict) { device_info[info_pair.first] = info_pair.second; } UHD_LOGGER_TRACE("MPMD") << "MPM reports device info: " << device_info.to_string(); - rpc->set_timeout(mb_args.cast( - "rpc_timeout", MPMD_DEFAULT_RPC_TIMEOUT - )); + auto dboards_info = rpc->request>("get_dboard_info"); + UHD_ASSERT_THROW(this->dboard_info.size() == 0); + for (const auto &dboard_info_dict : dboards_info) { + uhd::device_addr_t this_db_info; + for (const auto &info_pair : dboard_info_dict) { + this_db_info[info_pair.first] = info_pair.second; + } + UHD_LOGGER_TRACE("MPMD") + << "MPM reports dboard info for slot " << this->dboard_info.size() + << ": " << this_db_info.to_string(); + this->dboard_info.push_back(this_db_info); + } // Initialize properties this->num_xbars = rpc->request("get_num_xbars"); - // Local addresses are not yet valid after this! + // xbar_local_addrs is not yet valid after this! this->xbar_local_addrs.resize(this->num_xbars, 0xFF); // std::vector data_ifaces = @@ -164,6 +175,29 @@ bool mpmd_mboard_impl::claim() return rpc->request_with_token("reclaim"); } +uhd::task::sptr mpmd_mboard_impl::claim_device_and_make_task( + uhd::rpc_client::sptr rpc, + const uhd::device_addr_t mb_args +) { + auto rpc_token = rpc->request("claim", + mb_args.get("session_id", MPMD_DEFAULT_SESSION_ID) + ); + if (rpc_token.empty()) { + throw uhd::value_error("mpmd device claiming failed!"); + } + UHD_LOG_TRACE("MPMD", "Received claim token " << rpc_token); + rpc->set_token(rpc_token); + return uhd::task::make([this] { + if (not this->claim()) { + throw uhd::value_error("mpmd device reclaiming loop failed!"); + }; + std::this_thread::sleep_for( + std::chrono::milliseconds(MPMD_RECLAIM_INTERVAL_MS) + ); + }); +} + + /***************************************************************************** * Factory ****************************************************************************/ -- cgit v1.2.3