From 5e6b10cd9e08da52f57b1f746659d020cf278eb4 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 28 May 2021 21:20:19 +0200 Subject: uhd: ensure configured clock source is actually used We wouldn't want to get caught running with unlocked external clock sources, right?! Change-Id: Ie38d85617f46eb5ab7d9527ddf6aaab4d3edf6bf --- Transceiver52M/device/uhd/UHDDevice.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Transceiver52M/device/uhd/UHDDevice.cpp b/Transceiver52M/device/uhd/UHDDevice.cpp index 010fa8c..5486822 100644 --- a/Transceiver52M/device/uhd/UHDDevice.cpp +++ b/Transceiver52M/device/uhd/UHDDevice.cpp @@ -548,6 +548,7 @@ void uhd_device::set_channels(bool swap) int uhd_device::open(const std::string &args, int ref, bool swap_channels) { const char *refstr; + int clock_lock_attempts = 15; /* Register msg handler. Different APIs depending on UHD version */ #ifdef USE_UHD_3_11 @@ -620,6 +621,19 @@ int uhd_device::open(const std::string &args, int ref, bool swap_channels) usrp_dev->set_clock_source(refstr); + std::vector sensor_names = usrp_dev->get_mboard_sensor_names(); + if (std::find(sensor_names.begin(), sensor_names.end(), "ref_locked") != sensor_names.end()) { + LOGC(DDEV, INFO) << "Waiting for clock reference lock (max " << clock_lock_attempts << "s)..." << std::flush; + while (!usrp_dev->get_mboard_sensor("ref_locked", 0).to_bool() && clock_lock_attempts--) + sleep(1); + + if (!clock_lock_attempts) { + LOGC(DDEV, ALERT) << "Locking to external 10Mhz failed!"; + return -1; + } + } + LOGC(DDEV, INFO) << "Selected clock source is " << usrp_dev->get_clock_source(0); + try { set_rates(); } catch (const std::exception &e) { -- cgit v1.2.3