aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorKevin Gilbert <kevin.gilbert@ni.com>2016-08-04 12:02:10 -0700
committerMartin Braun <martin.braun@ettus.com>2016-08-05 08:38:26 -0700
commit63253ed7b2399b67d99878c7becc3926dfe17177 (patch)
tree326f92444200f1ead56231d1f5d2261730561c89 /host/lib
parentd21a7163ed2de9799064bf1ef980c3dac51c7b86 (diff)
downloaduhd-63253ed7b2399b67d99878c7becc3926dfe17177.tar.gz
uhd-63253ed7b2399b67d99878c7becc3926dfe17177.tar.bz2
uhd-63253ed7b2399b67d99878c7becc3926dfe17177.zip
Add sleep function to dboard_iface
Having this function allows a dboard_iface implementation to be aware of the timing of various calls such as SPI and register writes.
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/usrp/CMakeLists.txt1
-rw-r--r--host/lib/usrp/dboard/twinrx/twinrx_io.hpp7
-rw-r--r--host/lib/usrp/dboard_iface.cpp31
3 files changed, 35 insertions, 4 deletions
diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt
index dde4f02c3..d20cc966b 100644
--- a/host/lib/usrp/CMakeLists.txt
+++ b/host/lib/usrp/CMakeLists.txt
@@ -24,6 +24,7 @@ LIBUHD_APPEND_SOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/dboard_base.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dboard_eeprom.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dboard_id.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/dboard_iface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dboard_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gps_ctrl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mboard_eeprom.cpp
diff --git a/host/lib/usrp/dboard/twinrx/twinrx_io.hpp b/host/lib/usrp/dboard/twinrx/twinrx_io.hpp
index 8b504b549..5d099e361 100644
--- a/host/lib/usrp/dboard/twinrx/twinrx_io.hpp
+++ b/host/lib/usrp/dboard/twinrx/twinrx_io.hpp
@@ -108,10 +108,9 @@ public:
_db_iface->set_gpio_out(dboard_iface::UNIT_BOTH,
(cpld::get_reg(addr) << shift(CPLD_FULL_ADDR)) | (data << shift(CPLD_DATA)),
mask<boost::uint32_t>(CPLD_FULL_ADDR)|mask<boost::uint32_t>(CPLD_DATA));
- //Sleep for 166ns to ensure that we don't toggle the enables to quickly
- //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.
- boost::this_thread::sleep(boost::posix_time::microseconds(0));
+ //Sleep for 166ns to ensure that we don't toggle the enables too quickly
+ //The underlying sleep function rounds to microsecond precision.
+ _db_iface->sleep(boost::chrono::nanoseconds(166));
//Step 2: Write the reg offset and data, and assert the necessary enable
_db_iface->set_gpio_out(dboard_iface::UNIT_BOTH,
(static_cast<boost::uint32_t>(addr) << shift(CPLD_FULL_ADDR)) | (data << shift(CPLD_DATA)),
diff --git a/host/lib/usrp/dboard_iface.cpp b/host/lib/usrp/dboard_iface.cpp
new file mode 100644
index 000000000..2a04095e8
--- /dev/null
+++ b/host/lib/usrp/dboard_iface.cpp
@@ -0,0 +1,31 @@
+//
+// Copyright 2016 Ettus Research
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#include <uhd/usrp/dboard_iface.hpp>
+
+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)) {
+ boost::this_thread::sleep_for(boost::chrono::microseconds(1));
+ } else {
+ boost::this_thread::sleep_for(time);
+ }
+}