diff options
Diffstat (limited to 'host/lib')
| -rw-r--r-- | host/lib/include/uhd/utils/system_time.hpp | 18 | ||||
| -rw-r--r-- | host/lib/types/CMakeLists.txt | 61 | ||||
| -rw-r--r-- | host/lib/types/time_spec.cpp | 48 | ||||
| -rw-r--r-- | host/lib/usrp/common/recv_packet_demuxer_3000.hpp | 6 | ||||
| -rw-r--r-- | host/lib/usrp/e300/e300_fifo_config.cpp | 5 | ||||
| -rw-r--r-- | host/lib/usrp/usrp1/soft_time_ctrl.cpp | 5 | ||||
| -rw-r--r-- | host/lib/usrp/x300/x300_dac_ctrl.cpp | 9 | ||||
| -rw-r--r-- | host/lib/utils/CMakeLists.txt | 63 | ||||
| -rw-r--r-- | host/lib/utils/system_time.cpp | 54 | 
9 files changed, 150 insertions, 119 deletions
diff --git a/host/lib/include/uhd/utils/system_time.hpp b/host/lib/include/uhd/utils/system_time.hpp new file mode 100644 index 000000000..30cd5a673 --- /dev/null +++ b/host/lib/include/uhd/utils/system_time.hpp @@ -0,0 +1,18 @@ +// +// Copyright 2017 Ettus Research (National Instruments Corp.) +// +// SPDX-License-Identifier: GPL-3.0+ +// + +#include <uhd/types/time_spec.hpp> + +namespace uhd { + +    /*! +     * Get the system time in time_spec_t format. +     * Uses the highest precision clock available. +     * \return the system time as a time_spec_t +     */ +    time_spec_t get_system_time(void); + +}; /* namespace uhd */ diff --git a/host/lib/types/CMakeLists.txt b/host/lib/types/CMakeLists.txt index 2156160cd..7f8c80c95 100644 --- a/host/lib/types/CMakeLists.txt +++ b/host/lib/types/CMakeLists.txt @@ -6,67 +6,6 @@  #  ######################################################################## -# Setup defines for high resolution timing -######################################################################## -MESSAGE(STATUS "") -MESSAGE(STATUS "Configuring high resolution timing...") -INCLUDE(CheckCXXSourceCompiles) - -SET(CMAKE_REQUIRED_LIBRARIES -lrt) -CHECK_CXX_SOURCE_COMPILES(" -    #include <ctime> -    int main(){ -        timespec ts; -        return clock_gettime(CLOCK_MONOTONIC, &ts); -    } -    " HAVE_CLOCK_GETTIME -) -SET(CMAKE_REQUIRED_LIBRARIES) - -INCLUDE(CheckCXXSourceCompiles) -CHECK_CXX_SOURCE_COMPILES(" -    #include <mach/mach_time.h> -    int main(){ -        mach_timebase_info_data_t info; -        mach_timebase_info(&info); -        mach_absolute_time(); -        return 0; -    } -    " HAVE_MACH_ABSOLUTE_TIME -) - -CHECK_CXX_SOURCE_COMPILES(" -    #include <Windows.h> -    int main(){ -        LARGE_INTEGER value; -        QueryPerformanceCounter(&value); -        QueryPerformanceFrequency(&value); -        return 0; -    } -    " HAVE_QUERY_PERFORMANCE_COUNTER -) - -IF(HAVE_CLOCK_GETTIME) -    MESSAGE(STATUS "  High resolution timing supported through clock_gettime.") -    SET(TIME_SPEC_DEFS HAVE_CLOCK_GETTIME) -    LIBUHD_APPEND_LIBS("-lrt") -ELSEIF(HAVE_MACH_ABSOLUTE_TIME) -    MESSAGE(STATUS "  High resolution timing supported through mach_absolute_time.") -    SET(TIME_SPEC_DEFS HAVE_MACH_ABSOLUTE_TIME) -ELSEIF(HAVE_QUERY_PERFORMANCE_COUNTER) -    MESSAGE(STATUS "  High resolution timing supported through QueryPerformanceCounter.") -    SET(TIME_SPEC_DEFS HAVE_QUERY_PERFORMANCE_COUNTER) -ELSE() -    MESSAGE(STATUS "  High resolution timing supported though microsec_clock.") -    SET(TIME_SPEC_DEFS HAVE_MICROSEC_CLOCK) -ENDIF() - -SET_SOURCE_FILES_PROPERTIES( -    ${CMAKE_CURRENT_SOURCE_DIR}/time_spec.cpp -    PROPERTIES COMPILE_DEFINITIONS "${TIME_SPEC_DEFS}" -) - -########################################################################  # This file included, use CMake directory variables  ########################################################################  LIBUHD_APPEND_SOURCES( diff --git a/host/lib/types/time_spec.cpp b/host/lib/types/time_spec.cpp index 40df87611..aae6a6121 100644 --- a/host/lib/types/time_spec.cpp +++ b/host/lib/types/time_spec.cpp @@ -10,54 +10,6 @@  using namespace uhd;  /*********************************************************************** - * Time spec system time - **********************************************************************/ - -#ifdef HAVE_CLOCK_GETTIME -#include <time.h> -time_spec_t time_spec_t::get_system_time(void){ -    timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); -    return time_spec_t(ts.tv_sec, ts.tv_nsec, 1e9); -} -#endif /* HAVE_CLOCK_GETTIME */ - - -#ifdef HAVE_MACH_ABSOLUTE_TIME -#include <mach/mach_time.h> -time_spec_t time_spec_t::get_system_time(void){ -    mach_timebase_info_data_t info; mach_timebase_info(&info); -    intmax_t nanosecs = mach_absolute_time()*info.numer/info.denom; -    return time_spec_t::from_ticks(nanosecs, 1e9); -} -#endif /* HAVE_MACH_ABSOLUTE_TIME */ - - -#ifdef HAVE_QUERY_PERFORMANCE_COUNTER -#include <Windows.h> -time_spec_t time_spec_t::get_system_time(void){ -    LARGE_INTEGER counts, freq; -    QueryPerformanceCounter(&counts); -    QueryPerformanceFrequency(&freq); -    return time_spec_t::from_ticks(counts.QuadPart, double(freq.QuadPart)); -} -#endif /* HAVE_QUERY_PERFORMANCE_COUNTER */ - - -#ifdef HAVE_MICROSEC_CLOCK -#include <boost/date_time/posix_time/posix_time.hpp> -namespace pt = boost::posix_time; -time_spec_t time_spec_t::get_system_time(void){ -    pt::ptime time_now = pt::microsec_clock::universal_time(); -    pt::time_duration time_dur = time_now - pt::from_time_t(0); -    return time_spec_t( -        time_t(time_dur.total_seconds()), -        long(time_dur.fractional_seconds()), -        double(pt::time_duration::ticks_per_second()) -    ); -} -#endif /* HAVE_MICROSEC_CLOCK */ - -/***********************************************************************   * Time spec constructors   **********************************************************************/  #define time_spec_init(full, frac) { \ diff --git a/host/lib/usrp/common/recv_packet_demuxer_3000.hpp b/host/lib/usrp/common/recv_packet_demuxer_3000.hpp index 8b0aa9ee0..74807741f 100644 --- a/host/lib/usrp/common/recv_packet_demuxer_3000.hpp +++ b/host/lib/usrp/common/recv_packet_demuxer_3000.hpp @@ -8,6 +8,7 @@  #ifndef INCLUDED_LIBUHD_USRP_COMMON_RECV_PACKET_DEMUXER_3000_HPP  #define INCLUDED_LIBUHD_USRP_COMMON_RECV_PACKET_DEMUXER_3000_HPP +#include <uhd/utils/system_time.hpp>  #include <uhd/config.hpp>  #include <uhd/transport/zero_copy.hpp>  #include <uhd/utils/log.hpp> @@ -35,12 +36,13 @@ namespace uhd{ namespace usrp{          transport::managed_recv_buffer::sptr get_recv_buff(const uint32_t sid, const double timeout)          { -            const time_spec_t exit_time = time_spec_t(timeout) + time_spec_t::get_system_time(); +            const time_spec_t exit_time = +                time_spec_t(timeout) + uhd::get_system_time();              transport::managed_recv_buffer::sptr buff;              buff = _internal_get_recv_buff(sid, timeout);              while (not buff) //loop until timeout              { -                const time_spec_t delta = exit_time - time_spec_t::get_system_time(); +                const time_spec_t delta = exit_time - uhd::get_system_time();                  const double new_timeout = delta.get_real_secs();                  if (new_timeout < 0.0) break;                  buff = _internal_get_recv_buff(sid, new_timeout); diff --git a/host/lib/usrp/e300/e300_fifo_config.cpp b/host/lib/usrp/e300/e300_fifo_config.cpp index 7d4834040..c02c943dd 100644 --- a/host/lib/usrp/e300/e300_fifo_config.cpp +++ b/host/lib/usrp/e300/e300_fifo_config.cpp @@ -7,6 +7,7 @@  #ifdef E300_NATIVE +#include <uhd/utils/system_time.hpp>  #include <uhd/config.hpp>  #include <stdint.h>  #include <atomic> @@ -238,7 +239,7 @@ public:      template <typename T>      UHD_INLINE typename T::sptr get_buff(const double timeout)      { -        const time_spec_t exit_time = time_spec_t::get_system_time() + time_spec_t(timeout); +        const time_spec_t exit_time = uhd::get_system_time() + time_spec_t(timeout);          while (1)          {              if (zf_peek32(_addrs.ctrl + ARBITER_RB_STATUS_OCC)) @@ -251,7 +252,7 @@ public:                      _index = 0;                  return _buffs[_index++]->get_new<T>();              } -            if (time_spec_t::get_system_time() > exit_time) { +            if (uhd::get_system_time() > exit_time) {                  break;              }              _waiter->wait(timeout); diff --git a/host/lib/usrp/usrp1/soft_time_ctrl.cpp b/host/lib/usrp/usrp1/soft_time_ctrl.cpp index 626f973e1..061075e32 100644 --- a/host/lib/usrp/usrp1/soft_time_ctrl.cpp +++ b/host/lib/usrp/usrp1/soft_time_ctrl.cpp @@ -6,6 +6,7 @@  //  #include "soft_time_ctrl.hpp" +#include <uhd/utils/system_time.hpp>  #include <uhd/utils/tasks.hpp>  #include <boost/make_shared.hpp>  #include <boost/thread/condition_variable.hpp> @@ -49,7 +50,7 @@ public:       ******************************************************************/      void set_time(const time_spec_t &time){          boost::mutex::scoped_lock lock(_update_mutex); -        _time_offset = time_spec_t::get_system_time() - time; +        _time_offset = uhd::get_system_time() - time;      }      time_spec_t get_time(void){ @@ -59,7 +60,7 @@ public:      UHD_INLINE time_spec_t time_now(void){          //internal get time without scoped lock -        return time_spec_t::get_system_time() - _time_offset; +        return uhd::get_system_time() - _time_offset;      }      UHD_INLINE void sleep_until_time( diff --git a/host/lib/usrp/x300/x300_dac_ctrl.cpp b/host/lib/usrp/x300/x300_dac_ctrl.cpp index 5648a5fb7..400e48282 100644 --- a/host/lib/usrp/x300/x300_dac_ctrl.cpp +++ b/host/lib/usrp/x300/x300_dac_ctrl.cpp @@ -7,6 +7,7 @@  #include "x300_dac_ctrl.hpp"  #include "x300_regs.hpp" +#include <uhd/utils/system_time.hpp>  #include <uhd/types/time_spec.hpp>  #include <uhd/utils/log.hpp>  #include <uhd/utils/safe_call.hpp> @@ -207,14 +208,14 @@ public:          // Verify PLL is Locked. 1 sec timeout.          // NOTE: Data sheet inconsistent about which pins give PLL lock status. FIXME! -        const time_spec_t exit_time = time_spec_t::get_system_time() + time_spec_t(1.0); +        const time_spec_t exit_time = uhd::get_system_time() + time_spec_t(1.0);          while (true)          {              const size_t reg_e = read_ad9146_reg(0x0E); // PLL Status (Expect bit 7 = 1)              const size_t reg_6 = read_ad9146_reg(0x06); // Event Flags (Expect bit 7 = 0 and bit 6 = 1)              if ((((reg_e >> 7) & 0x1) == 0x1) && (((reg_6 >> 6) & 0x3) == 0x1))                  break; -            if (time_spec_t::get_system_time() > exit_time) +            if (exit_time < uhd::get_system_time())                  throw uhd::runtime_error("x300_dac_ctrl: timeout waiting for DAC PLL to lock");              if (reg_6 & (1 << 7))               // Lock lost?                  write_ad9146_reg(0x06, 0xC0);   // Clear PLL event flags @@ -231,7 +232,7 @@ public:          write_ad9146_reg(0x06, 0x30);          write_ad9146_reg(0x12, 0x00); -        const time_spec_t exit_time = time_spec_t::get_system_time() + time_spec_t(1.0); +        const time_spec_t exit_time = uhd::get_system_time() + time_spec_t(1.0);          while (true)          {              boost::this_thread::sleep(boost::posix_time::milliseconds(1));  // wait for sync to complete @@ -239,7 +240,7 @@ public:              const size_t reg_6 = read_ad9146_reg(0x06);     // Event Flags (Expect bit 5 = 0 and bit 4 = 1)              if ((((reg_12 >> 6) & 0x3) == 0x1) && (((reg_6 >> 4) & 0x3) == 0x1))                  break; -            if (time_spec_t::get_system_time() > exit_time) +            if (exit_time < uhd::get_system_time())                  throw uhd::runtime_error("x300_dac_ctrl: timeout waiting for backend synchronization");              if (reg_6 & (1 << 5))                  write_ad9146_reg(0x06, 0x30);   // Clear Sync event flags diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index 659c855a1..ea59df081 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -91,6 +91,68 @@ SET_SOURCE_FILES_PROPERTIES(  )  ######################################################################## +# Setup defines for high resolution timing +######################################################################## +MESSAGE(STATUS "") +MESSAGE(STATUS "Configuring high resolution timing...") +INCLUDE(CheckCXXSourceCompiles) + +SET(CMAKE_REQUIRED_LIBRARIES -lrt) +CHECK_CXX_SOURCE_COMPILES(" +    #include <ctime> +    int main(){ +        timespec ts; +        return clock_gettime(CLOCK_MONOTONIC, &ts); +    } +    " HAVE_CLOCK_GETTIME +) +SET(CMAKE_REQUIRED_LIBRARIES) + +INCLUDE(CheckCXXSourceCompiles) +CHECK_CXX_SOURCE_COMPILES(" +    #include <mach/mach_time.h> +    int main(){ +        mach_timebase_info_data_t info; +        mach_timebase_info(&info); +        mach_absolute_time(); +        return 0; +    } +    " HAVE_MACH_ABSOLUTE_TIME +) + +CHECK_CXX_SOURCE_COMPILES(" +    #include <Windows.h> +    int main(){ +        LARGE_INTEGER value; +        QueryPerformanceCounter(&value); +        QueryPerformanceFrequency(&value); +        return 0; +    } +    " HAVE_QUERY_PERFORMANCE_COUNTER +) + + +IF(HAVE_CLOCK_GETTIME) +    MESSAGE(STATUS "  High resolution timing supported through clock_gettime.") +    SET(SYSTEM_TIME_DEFS HAVE_CLOCK_GETTIME) +    LIBUHD_APPEND_LIBS("-lrt") +ELSEIF(HAVE_MACH_ABSOLUTE_TIME) +    MESSAGE(STATUS "  High resolution timing supported through mach_absolute_time.") +    SET(SYSTEM_TIME_DEFS HAVE_MACH_ABSOLUTE_TIME) +ELSEIF(HAVE_QUERY_PERFORMANCE_COUNTER) +    MESSAGE(STATUS "  High resolution timing supported through QueryPerformanceCounter.") +    SET(SYSTEM_TIME_DEFS HAVE_QUERY_PERFORMANCE_COUNTER) +ELSE() +    MESSAGE(STATUS "  High resolution timing supported though microsec_clock.") +    SET(SYSTEM_TIME_DEFS HAVE_MICROSEC_CLOCK) +ENDIF() + +SET_SOURCE_FILES_PROPERTIES( +    ${CMAKE_CURRENT_SOURCE_DIR}/system_time.cpp +    PROPERTIES COMPILE_DEFINITIONS "${SYSTEM_TIME_DEFS}" +) + +########################################################################  # Setup defines for module loading  ########################################################################  MESSAGE(STATUS "") @@ -178,6 +240,7 @@ LIBUHD_APPEND_SOURCES(      ${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/prefs.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/static.cpp +    ${CMAKE_CURRENT_SOURCE_DIR}/system_time.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/tasks.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/thread.cpp  ) diff --git a/host/lib/utils/system_time.cpp b/host/lib/utils/system_time.cpp new file mode 100644 index 000000000..d371756bc --- /dev/null +++ b/host/lib/utils/system_time.cpp @@ -0,0 +1,54 @@ +// +// Copyright 2017 Ettus Research (National Instruments Corp.) +// +// SPDX-License-Identifier: GPL-3.0+ +// + +#include <uhd/utils/system_time.hpp> + +using namespace uhd; + +#ifdef HAVE_CLOCK_GETTIME +#include <time.h> +time_spec_t uhd::get_system_time(void){ +    timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); +    return time_spec_t(ts.tv_sec, ts.tv_nsec, 1e9); +} +#endif /* HAVE_CLOCK_GETTIME */ + + +#ifdef HAVE_MACH_ABSOLUTE_TIME +#include <mach/mach_time.h> +time_spec_t uhd::get_system_time(void){ +    mach_timebase_info_data_t info; mach_timebase_info(&info); +    intmax_t nanosecs = mach_absolute_time()*info.numer/info.denom; +    return time_spec_t::from_ticks(nanosecs, 1e9); +} +#endif /* HAVE_MACH_ABSOLUTE_TIME */ + + +#ifdef HAVE_QUERY_PERFORMANCE_COUNTER +#include <Windows.h> +time_spec_t uhd::get_system_time(void){ +    LARGE_INTEGER counts, freq; +    QueryPerformanceCounter(&counts); +    QueryPerformanceFrequency(&freq); +    return time_spec_t::from_ticks(counts.QuadPart, double(freq.QuadPart)); +} +#endif /* HAVE_QUERY_PERFORMANCE_COUNTER */ + + +#ifdef HAVE_MICROSEC_CLOCK +#include <boost/date_time/posix_time/posix_time.hpp> +namespace pt = boost::posix_time; +time_spec_t uhd::get_system_time(void){ +    pt::ptime time_now = pt::microsec_clock::universal_time(); +    pt::time_duration time_dur = time_now - pt::from_time_t(0); +    return time_spec_t( +        time_t(time_dur.total_seconds()), +        long(time_dur.fractional_seconds()), +        double(pt::time_duration::ticks_per_second()) +    ); +} +#endif /* HAVE_MICROSEC_CLOCK */ +  | 
