From 09ac6991c3e7afed6bf75dadb16363965fbf54ce Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 20 Aug 2018 18:03:12 -0700 Subject: utils: Factor wait_for_lo_lock() out of cal utils --- host/utils/uhd_cal_rx_iq_balance.cpp | 9 +-------- host/utils/uhd_cal_tx_dc_offset.cpp | 9 +-------- host/utils/uhd_cal_tx_iq_balance.cpp | 9 +-------- host/utils/usrp_cal_utils.hpp | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/host/utils/uhd_cal_rx_iq_balance.cpp b/host/utils/uhd_cal_rx_iq_balance.cpp index 470a66f9c..81a04b6f9 100644 --- a/host/utils/uhd_cal_rx_iq_balance.cpp +++ b/host/utils/uhd_cal_rx_iq_balance.cpp @@ -74,14 +74,7 @@ static double tune_rx_and_tx(uhd::usrp::multi_usrp::sptr usrp, const double rx_l tx_tune_req.dsp_freq = tx_freq - max_fe_tx_freq; usrp->set_tx_freq(tx_tune_req); - //wait for the LOs to become locked - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - boost::system_time start = boost::get_system_time(); - while (not usrp->get_tx_sensor("lo_locked").to_bool() or not usrp->get_rx_sensor("lo_locked").to_bool()) - { - if (boost::get_system_time() > start + boost::posix_time::milliseconds(100)) - throw std::runtime_error("timed out waiting for TX and/or RX LO to lock"); - } + wait_for_lo_lock(usrp); return usrp->get_rx_freq(); } diff --git a/host/utils/uhd_cal_tx_dc_offset.cpp b/host/utils/uhd_cal_tx_dc_offset.cpp index ecd676e07..6c35f017f 100644 --- a/host/utils/uhd_cal_tx_dc_offset.cpp +++ b/host/utils/uhd_cal_tx_dc_offset.cpp @@ -81,14 +81,7 @@ static double tune_rx_and_tx(uhd::usrp::multi_usrp::sptr usrp, const double tx_l rx_tune_req.dsp_freq = rx_freq - max_fe_rx_freq; usrp->set_rx_freq(rx_tune_req); - //wait for the LOs to become locked - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - boost::system_time start = boost::get_system_time(); - while (not usrp->get_tx_sensor("lo_locked").to_bool() or not usrp->get_rx_sensor("lo_locked").to_bool()) - { - if (boost::get_system_time() > start + boost::posix_time::milliseconds(100)) - throw std::runtime_error("timed out waiting for TX and/or RX LO to lock"); - } + wait_for_lo_lock(usrp); return usrp->get_tx_freq(); } diff --git a/host/utils/uhd_cal_tx_iq_balance.cpp b/host/utils/uhd_cal_tx_iq_balance.cpp index da8807479..d5079431b 100644 --- a/host/utils/uhd_cal_tx_iq_balance.cpp +++ b/host/utils/uhd_cal_tx_iq_balance.cpp @@ -78,14 +78,7 @@ static double tune_rx_and_tx(uhd::usrp::multi_usrp::sptr usrp, const double tx_l rx_tune_req.dsp_freq = rx_freq - max_fe_rx_freq; usrp->set_rx_freq(rx_tune_req); - //wait for the LOs to become locked - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - boost::system_time start = boost::get_system_time(); - while (not usrp->get_tx_sensor("lo_locked").to_bool() or not usrp->get_rx_sensor("lo_locked").to_bool()) - { - if (boost::get_system_time() > start + boost::posix_time::milliseconds(100)) - throw std::runtime_error("timed out waiting for TX and/or RX LO to lock"); - } + wait_for_lo_lock(usrp); return usrp->get_tx_freq(); } diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp index 88fedcbd4..8fde78e1f 100644 --- a/host/utils/usrp_cal_utils.hpp +++ b/host/utils/usrp_cal_utils.hpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include namespace fs = boost::filesystem; @@ -395,3 +397,17 @@ bool has_tx_error(uhd::tx_streamer::sptr tx_stream) | uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST ); } + +void wait_for_lo_lock(uhd::usrp::multi_usrp::sptr usrp) +{ + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + const auto timeout = + std::chrono::steady_clock::now() + std::chrono::milliseconds(100); + while (not usrp->get_tx_sensor("lo_locked").to_bool() + or not usrp->get_rx_sensor("lo_locked").to_bool()) { + if (std::chrono::steady_clock::now() > timeout) { + throw std::runtime_error( + "timed out waiting for TX and/or RX LO to lock"); + } + } +} -- cgit v1.2.3