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
This commit is contained in:
Eric Wild 2021-05-28 21:20:19 +02:00 committed by Hoernchen
parent b6f238c0f2
commit 5e6b10cd9e
1 changed files with 14 additions and 0 deletions

View File

@ -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<std::string> 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) {