From 9b78da222fb5e51c1ad9ccd6887d1cf85c4c7926 Mon Sep 17 00:00:00 2001 From: michael-west Date: Thu, 4 Nov 2021 13:53:20 -0700 Subject: host: Add ability to get time from Radio block Add API calls to Radio control to get ticks and time. Signed-off-by: michael-west --- host/include/uhd/rfnoc/radio_control.hpp | 14 ++++++++++++++ host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp | 10 ++++++++++ host/lib/rfnoc/radio_control_impl.cpp | 20 +++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) (limited to 'host') diff --git a/host/include/uhd/rfnoc/radio_control.hpp b/host/include/uhd/rfnoc/radio_control.hpp index ffa9b64fe..ab30be02c 100644 --- a/host/include/uhd/rfnoc/radio_control.hpp +++ b/host/include/uhd/rfnoc/radio_control.hpp @@ -64,6 +64,20 @@ public: // Ultimately, the exact impact of SPC is device-dependent. virtual size_t get_spc() const = 0; + /************************************************************************** + * Time-Related API Calls + *************************************************************************/ + /*! Get tick count + * \returns tick count + * \throws uhd::not_implemented_error if not implemented + */ + virtual uint64_t get_ticks_now() = 0; + /*! Get the time + * \returns time now + * \throws uhd::not_implemented_error if not implemented + */ + virtual uhd::time_spec_t get_time_now() = 0; + /************************************************************************** * RF-Related API Calls *************************************************************************/ diff --git a/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp b/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp index 0ff0e9b12..b60b0f2a2 100644 --- a/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp +++ b/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp @@ -58,6 +58,12 @@ public: meta_range_t get_rate_range() const override; size_t get_spc() const override; + /************************************************************************** + * Time-Related API Calls + *************************************************************************/ + uint64_t get_ticks_now() override; + uhd::time_spec_t get_time_now() override; + /************************************************************************** * RF-specific API calls *************************************************************************/ @@ -209,6 +215,10 @@ public: { static const uint32_t REG_COMPAT_NUM = 0x00; // Compatibility number register offset + static const uint32_t REG_TIME_LO = + 0x04; // Time lower bits + static const uint32_t REG_TIME_HI = + 0x08; // Time upper bits static const uint32_t REG_RADIO_WIDTH = 0x1000 + 0x04; // Upper 16 bits is sample width, lower 16 bits is NSPC diff --git a/host/lib/rfnoc/radio_control_impl.cpp b/host/lib/rfnoc/radio_control_impl.cpp index c9b9b6bfe..53117176b 100644 --- a/host/lib/rfnoc/radio_control_impl.cpp +++ b/host/lib/rfnoc/radio_control_impl.cpp @@ -26,7 +26,7 @@ const std::string radio_control::ALL_LOS = "all"; const std::string radio_control::ALL_GAINS = ""; const uint16_t radio_control_impl::MAJOR_COMPAT = 0; -const uint16_t radio_control_impl::MINOR_COMPAT = 0; +const uint16_t radio_control_impl::MINOR_COMPAT = 1; const uint32_t radio_control_impl::regmap::REG_COMPAT_NUM; const uint32_t radio_control_impl::regmap::REG_RADIO_WIDTH; @@ -294,6 +294,24 @@ size_t radio_control_impl::get_spc() const return _spc; } + +/****************************************************************************** + * Time-Related API Calls + *****************************************************************************/ +uint64_t radio_control_impl::get_ticks_now() +{ + // Time registers added in 0.1 + if (_fpga_compat < 1) { + throw uhd::not_implemented_error("Radio does not support time readback"); + } + return regs().peek64(regmap::REG_TIME_LO); +} + +uhd::time_spec_t radio_control_impl::get_time_now() +{ + return uhd::time_spec_t::from_ticks(get_ticks_now(), get_rate()); +} + /**************************************************************************** * RF API ***************************************************************************/ -- cgit v1.2.3