diff options
author | Johannes Demel <demel@ant.uni-bremen.de> | 2020-06-11 17:33:34 +0200 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2021-01-16 13:57:48 +0100 |
commit | a7f0a6f2274305f9973110db71fc2d33d901828d (patch) | |
tree | 175ac3795898c4f8b84fce5b970f1ac5813810cd /gr-uhd/lib/usrp_block_impl.cc | |
parent | ea0f1c66b23fa602c6b60181e1dd0941e224279d (diff) |
uhd: Add PC clock resync command
USRPs may be synchronized to a host clock. Over time USRP and host clock
deviate. This is an issue for timed commands. With this commit it is
possible to resync both devices.
The new command key is `pc_clock_resync`. The command does not expect
any argument.
It may be possible that USRP time is not strictly monotonic anymore. If
that is a requirement, other options should be explored.
e.g. connect a 'Message Strobe' block to a USRP command port and send a
message with `pmt.dict_add(pmt.make_dict(), pmt.intern('pc_clock_resync'), pmt.PMT_T)`
periodically. It is sufficient to send such a message every couple of
seconds.
Diffstat (limited to 'gr-uhd/lib/usrp_block_impl.cc')
-rw-r--r-- | gr-uhd/lib/usrp_block_impl.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/gr-uhd/lib/usrp_block_impl.cc b/gr-uhd/lib/usrp_block_impl.cc index c117b8651e..c603a8dd47 100644 --- a/gr-uhd/lib/usrp_block_impl.cc +++ b/gr-uhd/lib/usrp_block_impl.cc @@ -101,6 +101,11 @@ const pmt::pmt_t gr::uhd::cmd_tag_key() static const pmt::pmt_t val = pmt::mp("tag"); return val; } +const pmt::pmt_t gr::uhd::cmd_pc_clock_resync_key() +{ + static const pmt::pmt_t val = pmt::mp("pc_clock_resync"); + return val; +} const pmt::pmt_t gr::uhd::cmd_gpio_key() { @@ -157,6 +162,7 @@ usrp_block_impl::usrp_block_impl(const ::uhd::device_addr_t& device_addr, REGISTER_CMD_HANDLER(cmd_bandwidth_key(), _cmd_handler_bw); REGISTER_CMD_HANDLER(cmd_antenna_key(), _cmd_handler_antenna); REGISTER_CMD_HANDLER(cmd_gpio_key(), _cmd_handler_gpio); + REGISTER_CMD_HANDLER(cmd_pc_clock_resync_key(), _cmd_handler_pc_clock_resync); } usrp_block_impl::~usrp_block_impl() @@ -742,6 +748,18 @@ void usrp_block_impl::_cmd_handler_rate(const pmt::pmt_t& rate_, int, const pmt: set_samp_rate(rate); } +void usrp_block_impl::_cmd_handler_pc_clock_resync(const pmt::pmt_t&, + int, + const pmt::pmt_t&) +{ + const uint64_t ticks = + std::chrono::duration_cast<std::chrono::nanoseconds>( + std::chrono::high_resolution_clock::now().time_since_epoch()) + .count(); + const ::uhd::time_spec_t& time_spec = ::uhd::time_spec_t::from_ticks(ticks, 1.0e9); + set_time_now(time_spec, ::uhd::usrp::multi_usrp::ALL_MBOARDS); +} + void usrp_block_impl::_cmd_handler_tune(const pmt::pmt_t& tune, int chan, const pmt::pmt_t& msg) |