From c5d7e88a9ec0c2c720993977a67cfb6263ec8d20 Mon Sep 17 00:00:00 2001 From: Michael West Date: Wed, 20 Jan 2021 12:51:27 -0800 Subject: dboard_iface: Modify sleep() function The algorithm for the sleep() function is changed to first increment the command time if the command time is set. If the command time is not set, it just performs a sleep on the host. The intention is to make a best effort to create the requested delay on the device. Signed-off-by: Michael West --- host/lib/usrp/dboard_iface.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'host/lib/usrp') diff --git a/host/lib/usrp/dboard_iface.cpp b/host/lib/usrp/dboard_iface.cpp index b2ff23ab9..4a3836151 100644 --- a/host/lib/usrp/dboard_iface.cpp +++ b/host/lib/usrp/dboard_iface.cpp @@ -13,11 +13,20 @@ using namespace uhd::usrp; void dboard_iface::sleep(const boost::chrono::nanoseconds& time) { - // nanosleep is not really accurate in userland and it is also not very - // cross-platform. So just sleep for the minimum amount of time in us. - if (time < boost::chrono::microseconds(1)) { - std::this_thread::sleep_for(std::chrono::microseconds(1)); + // This sleep function is intended to create a delay on the + // device. If a command time is set, just increment that time. + // If not, the best we can do is just do a sleep on the host. + // FIXME: Create a delay in the FPGA on the device. + auto cmd_time = get_command_time(); + if (cmd_time.get_real_secs() != 0.0) { + set_command_time(cmd_time + uhd::time_spec_t(time.count())); } else { - std::this_thread::sleep_for(std::chrono::microseconds(time.count())); + // nanosleep is not really accurate in userland and it is also not very + // cross-platform. So just sleep for the minimum amount of time in us. + if (time < boost::chrono::microseconds(1)) { + std::this_thread::sleep_for(std::chrono::microseconds(1)); + } else { + std::this_thread::sleep_for(std::chrono::microseconds(time.count())); + } } } -- cgit v1.2.3