diff options
author | michael-west <michael.west@ettus.com> | 2021-10-19 12:20:33 -0700 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-11-10 13:43:48 -0800 |
commit | 91a4f628828358267f5c0b0719da65dd34234196 (patch) | |
tree | 9c1c036fff0091510106608e1bbc151d0ea9fb05 /host/lib/usrp/b200/b200_impl.cpp | |
parent | 7f8e7f97c82923b2011c905e8a1374a8718b1230 (diff) | |
download | uhd-91a4f628828358267f5c0b0719da65dd34234196.tar.gz uhd-91a4f628828358267f5c0b0719da65dd34234196.tar.bz2 uhd-91a4f628828358267f5c0b0719da65dd34234196.zip |
B200: Re-sync times
The times on the device can glitch if either the tick rate changes or
the number of active chains changes. This throws off the time if the
user gets streamers, changes the sample rate, or changes the tick rate
after synchronizing the time. This change re-synchronizes the times
automatically in those cases.
Signed-off-by: michael-west <michael.west@ettus.com>
Diffstat (limited to 'host/lib/usrp/b200/b200_impl.cpp')
-rw-r--r-- | host/lib/usrp/b200/b200_impl.cpp | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/host/lib/usrp/b200/b200_impl.cpp b/host/lib/usrp/b200/b200_impl.cpp index ed685d536..6de161e87 100644 --- a/host/lib/usrp/b200/b200_impl.cpp +++ b/host/lib/usrp/b200/b200_impl.cpp @@ -301,6 +301,7 @@ b200_impl::b200_impl( _revision(0) , _enable_user_regs(device_addr.has_key("enable_user_regs")) , _time_source(UNKNOWN) + , _time_set_with_pps(false) , _tick_rate(0.0) // Forces a clock initialization at startup { _tree = property_tree::make(); @@ -715,11 +716,9 @@ b200_impl::b200_impl( _tree->create<time_spec_t>(mb_path / "time" / "pps") .set_publisher( std::bind(&time_core_3000::get_time_last_pps, _radio_perifs[0].time64)); - for (radio_perifs_t& perif : _radio_perifs) { - _tree->access<time_spec_t>(mb_path / "time" / "pps") - .add_coerced_subscriber(std::bind( - &time_core_3000::set_time_next_pps, perif.time64, std::placeholders::_1)); - } + _tree->access<time_spec_t>(mb_path / "time" / "pps") + .add_coerced_subscriber(std::bind( + &b200_impl::set_time_next_pps, this, std::placeholders::_1)); // setup time source props const std::vector<std::string> time_sources = @@ -1305,11 +1304,28 @@ void b200_impl::set_time(const uhd::time_spec_t& t) perif.time64->set_time_sync(t); _local_ctrl->poke32(TOREG(SR_CORE_SYNC), 1 << 2 | uint32_t(_time_source)); _local_ctrl->poke32(TOREG(SR_CORE_SYNC), _time_source); + _time_set_with_pps = false; +} + +void b200_impl::set_time_next_pps(const uhd::time_spec_t& t) +{ + for (radio_perifs_t& perif : _radio_perifs) + perif.time64->set_time_next_pps(t); + _time_set_with_pps = true; } void b200_impl::sync_times() { - set_time(_radio_perifs[0].time64->get_time_now()); + if (_time_set_with_pps) { + UHD_LOG_DEBUG("B200", "Re-synchronizing time using PPS"); + uhd::time_spec_t time_last_pps = _radio_perifs[0].time64->get_time_last_pps(); + while (_radio_perifs[0].time64->get_time_last_pps() == time_last_pps) { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + set_time_next_pps(time_last_pps + 2.0); + } else { + set_time(_radio_perifs[0].time64->get_time_now()); + } } /*********************************************************************** @@ -1443,7 +1459,7 @@ void b200_impl::update_enables(void) and bool(_radio_perifs[_fe2].rx_streamer.lock()); const size_t num_rx = (enb_rx1 ? 1 : 0) + (enb_rx2 ? 1 : 0); const size_t num_tx = (enb_tx1 ? 1 : 0) + (enb_tx2 ? 1 : 0); - const bool mimo = num_rx == 2 or num_tx == 2; + const uint32_t mimo = (num_rx == 2 or num_tx == 2) ? 1 : 0; if ((num_rx + num_tx) == 3) { throw uhd::runtime_error( @@ -1455,9 +1471,12 @@ void b200_impl::update_enables(void) if ((num_rx + num_tx) == 0) _codec_ctrl->set_active_chains(true, false, true, false); // enable something - // figure out if mimo is enabled based on new state - _gpio_state.mimo = (mimo) ? 1 : 0; - update_gpio_state(); + // update MIMO state and re-sync times if necessary + if (_gpio_state.mimo != mimo) { + _gpio_state.mimo = mimo; + update_gpio_state(); + sync_times(); + } // atrs change based on enables this->update_atrs(); |