aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
Diffstat (limited to 'host/include')
-rw-r--r--host/include/CMakeLists.txt7
-rw-r--r--host/include/uhd.h41
-rw-r--r--host/include/uhd/CMakeLists.txt11
-rw-r--r--host/include/uhd/config.h82
-rw-r--r--host/include/uhd/config.hpp9
-rw-r--r--host/include/uhd/convert.hpp3
-rw-r--r--host/include/uhd/error.h169
-rw-r--r--host/include/uhd/exception.hpp8
-rw-r--r--host/include/uhd/image_loader.hpp90
-rw-r--r--host/include/uhd/transport/CMakeLists.txt4
-rw-r--r--host/include/uhd/transport/chdr.hpp113
-rw-r--r--host/include/uhd/transport/nirio/nirio_driver_iface.h115
-rw-r--r--host/include/uhd/transport/nirio/nirio_fifo.h4
-rw-r--r--host/include/uhd/transport/nirio/nirio_quirks.h4
-rw-r--r--host/include/uhd/transport/nirio/niriok_proxy.h29
-rw-r--r--host/include/uhd/transport/nirio/niriok_proxy_impl_v1.h339
-rw-r--r--host/include/uhd/transport/nirio/niriok_proxy_impl_v2.h269
-rw-r--r--host/include/uhd/transport/tcp_zero_copy.hpp4
-rw-r--r--host/include/uhd/transport/usb_device_handle.hpp3
-rw-r--r--host/include/uhd/transport/vrt_if_packet.hpp76
-rw-r--r--host/include/uhd/transport/zero_copy.hpp2
-rw-r--r--host/include/uhd/types/CMakeLists.txt17
-rw-r--r--host/include/uhd/types/byte_vector.hpp48
-rw-r--r--host/include/uhd/types/dict.hpp19
-rw-r--r--host/include/uhd/types/dict.ipp14
-rw-r--r--host/include/uhd/types/direction.hpp2
-rw-r--r--host/include/uhd/types/filters.hpp286
-rw-r--r--host/include/uhd/types/metadata.h364
-rw-r--r--host/include/uhd/types/ranges.h154
-rw-r--r--host/include/uhd/types/sensors.h231
-rw-r--r--host/include/uhd/types/sid.hpp238
-rw-r--r--host/include/uhd/types/stream_cmd.hpp34
-rw-r--r--host/include/uhd/types/string_vector.h86
-rw-r--r--host/include/uhd/types/tune_request.h61
-rw-r--r--host/include/uhd/types/tune_result.h60
-rw-r--r--host/include/uhd/types/usrp_info.h94
-rw-r--r--host/include/uhd/usrp/CMakeLists.txt14
-rw-r--r--host/include/uhd/usrp/dboard_eeprom.h110
-rw-r--r--host/include/uhd/usrp/mboard_eeprom.h87
-rw-r--r--host/include/uhd/usrp/multi_usrp.hpp157
-rw-r--r--host/include/uhd/usrp/subdev_spec.h137
-rw-r--r--host/include/uhd/usrp/usrp.h1152
-rw-r--r--host/include/uhd/usrp_clock/CMakeLists.txt10
-rw-r--r--host/include/uhd/usrp_clock/usrp_clock.h125
-rw-r--r--host/include/uhd/utils/CMakeLists.txt8
-rw-r--r--host/include/uhd/utils/dirty_tracked.hpp132
-rw-r--r--host/include/uhd/utils/math.hpp12
-rw-r--r--host/include/uhd/utils/paths.hpp10
-rw-r--r--host/include/uhd/utils/soft_register.hpp688
-rw-r--r--host/include/uhd/utils/thread_priority.h53
-rw-r--r--host/include/uhd/version.hpp.in2
51 files changed, 5065 insertions, 722 deletions
diff --git a/host/include/CMakeLists.txt b/host/include/CMakeLists.txt
index 780213918..8b1e6bc05 100644
--- a/host/include/CMakeLists.txt
+++ b/host/include/CMakeLists.txt
@@ -20,4 +20,11 @@ CONFIGURE_FILE(
${CMAKE_CURRENT_BINARY_DIR}/config.h
)
+IF(ENABLE_C_API)
+ UHD_INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/uhd.h
+ DESTINATION ${INCLUDE_DIR}
+ COMPONENT headers
+ )
+ENDIF(ENABLE_C_API)
+
ADD_SUBDIRECTORY(uhd)
diff --git a/host/include/uhd.h b/host/include/uhd.h
new file mode 100644
index 000000000..8647e25e4
--- /dev/null
+++ b/host/include/uhd.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 Ettus Research LLC
+ *
+ * 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/>.
+ */
+
+#ifndef INCLUDED_UHD_H
+#define INCLUDED_UHD_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+#include <uhd/types/metadata.h>
+#include <uhd/types/ranges.h>
+#include <uhd/types/sensors.h>
+#include <uhd/types/string_vector.h>
+#include <uhd/types/tune_request.h>
+#include <uhd/types/tune_result.h>
+#include <uhd/types/usrp_info.h>
+
+#include <uhd/usrp/dboard_eeprom.h>
+#include <uhd/usrp/mboard_eeprom.h>
+#include <uhd/usrp/subdev_spec.h>
+#include <uhd/usrp/usrp.h>
+
+#include <uhd/usrp_clock/usrp_clock.h>
+
+#include <uhd/utils/thread_priority.h>
+
+#endif /* INCLUDED_UHD_H */
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt
index f6123aa90..083ec4951 100644
--- a/host/include/uhd/CMakeLists.txt
+++ b/host/include/uhd/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2010-2011,2013-2014 Ettus Research LLC
+# Copyright 2010-2011,2013-2015 Ettus Research LLC
#
# 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
@@ -40,3 +40,12 @@ UHD_INSTALL(FILES
DESTINATION ${INCLUDE_DIR}/uhd
COMPONENT headers
)
+
+IF(ENABLE_C_API)
+ UHD_INSTALL(FILES
+ config.h
+ error.h
+ DESTINATION ${INCLUDE_DIR}/uhd
+ COMPONENT headers
+ )
+ENDIF(ENABLE_C_API)
diff --git a/host/include/uhd/config.h b/host/include/uhd/config.h
new file mode 100644
index 000000000..1d6cefcc0
--- /dev/null
+++ b/host/include/uhd/config.h
@@ -0,0 +1,82 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_CONFIG_H
+#define INCLUDED_UHD_CONFIG_H
+
+#ifdef _MSC_VER
+// Bring in "and", "or", and "not"
+#include <iso646.h>
+
+// Define ssize_t
+#include <stddef.h>
+typedef ptrdiff_t ssize_t;
+
+#endif /* _MSC_VER */
+
+// Define cross-platform macros
+#if defined(_MSC_VER)
+ #define UHD_EXPORT __declspec(dllexport)
+ #define UHD_IMPORT __declspec(dllimport)
+ #define UHD_INLINE __forceinline
+ #define UHD_DEPRECATED __declspec(deprecated)
+ #define UHD_ALIGNED(x) __declspec(align(x))
+ #define UHD_UNUSED(x) x
+#elif defined(__MINGW32__)
+ #define UHD_EXPORT __declspec(dllexport)
+ #define UHD_IMPORT __declspec(dllimport)
+ #define UHD_INLINE inline
+ #define UHD_DEPRECATED __declspec(deprecated)
+ #define UHD_ALIGNED(x) __declspec(align(x))
+ #define UHD_UNUSED(x) x __attribute__((unused))
+#elif defined(__GNUG__) && __GNUG__ >= 4
+ #define UHD_EXPORT __attribute__((visibility("default")))
+ #define UHD_IMPORT __attribute__((visibility("default")))
+ #define UHD_INLINE inline __attribute__((always_inline))
+ #define UHD_DEPRECATED __attribute__((deprecated))
+ #define UHD_ALIGNED(x) __attribute__((aligned(x)))
+ #define UHD_UNUSED(x) x __attribute__((unused))
+#else
+ #define UHD_EXPORT
+ #define UHD_IMPORT
+ #define UHD_INLINE inline
+ #define UHD_DEPRECATED
+ #define UHD_ALIGNED(x)
+ #define UHD_UNUSED(x) x
+#endif
+
+// API declaration macro
+#ifdef UHD_DLL_EXPORTS
+ #define UHD_API UHD_EXPORT
+#else
+ #define UHD_API UHD_IMPORT
+#endif // UHD_DLL_EXPORTS
+
+// Platform defines for conditional code:
+// Taken from boost/config/select_platform_config.hpp,
+// However, we define macros, not strings, for platforms.
+#if defined(linux) || defined(__linux) || defined(__linux__)
+ #define UHD_PLATFORM_LINUX
+#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+ #define UHD_PLATFORM_WIN32
+#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
+ #define UHD_PLATFORM_MACOS
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ #define UHD_PLATFORM_BSD
+#endif
+
+#endif /* INCLUDED_UHD_CONFIG_H */
diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp
index 7ecc4924a..8939cd773 100644
--- a/host/include/uhd/config.hpp
+++ b/host/include/uhd/config.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2011 Ettus Research LLC
+// Copyright 2010-2011,2014-2015 Ettus Research LLC
//
// 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
@@ -56,6 +56,13 @@ typedef ptrdiff_t ssize_t;
#define UHD_DEPRECATED __declspec(deprecated)
#define UHD_ALIGNED(x) __declspec(align(x))
#define UHD_UNUSED(x) x
+#elif defined(__MINGW32__)
+ #define UHD_EXPORT __declspec(dllexport)
+ #define UHD_IMPORT __declspec(dllimport)
+ #define UHD_INLINE inline
+ #define UHD_DEPRECATED __declspec(deprecated)
+ #define UHD_ALIGNED(x) __declspec(align(x))
+ #define UHD_UNUSED(x) x __attribute__((unused))
#elif defined(__GNUG__) && __GNUG__ >= 4
#define UHD_EXPORT __attribute__((visibility("default")))
#define UHD_IMPORT __attribute__((visibility("default")))
diff --git a/host/include/uhd/convert.hpp b/host/include/uhd/convert.hpp
index d740d80fb..e42123b20 100644
--- a/host/include/uhd/convert.hpp
+++ b/host/include/uhd/convert.hpp
@@ -63,12 +63,13 @@ namespace uhd{ namespace convert{
typedef int priority_type;
//! Identify a conversion routine in the registry
- struct id_type : boost::equality_comparable<id_type>{
+ struct UHD_API id_type : boost::equality_comparable<id_type>{
std::string input_format;
size_t num_inputs;
std::string output_format;
size_t num_outputs;
std::string to_pp_string(void) const;
+ std::string to_string(void) const;
};
//! Implement equality_comparable interface
diff --git a/host/include/uhd/error.h b/host/include/uhd/error.h
new file mode 100644
index 000000000..f0ac41d1f
--- /dev/null
+++ b/host/include/uhd/error.h
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2015 Ettus Research LLC
+ *
+ * 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/>.
+ */
+
+#ifndef INCLUDED_UHD_ERROR_H
+#define INCLUDED_UHD_ERROR_H
+
+#include <stdlib.h>
+
+//! UHD error codes
+/*!
+ * Each error code corresponds to a specific uhd::exception, with
+ * extra codes corresponding to a boost::exception, std::exception,
+ * and a catch-all for everything else. When an internal C++ function
+ * throws an exception, UHD converts it to one of these error codes
+ * to return on the C level.
+ */
+typedef enum {
+
+ //! No error thrown.
+ UHD_ERROR_NONE = 0,
+ //! Invalid device arguments.
+ UHD_ERROR_INVALID_DEVICE = 1,
+
+ //! See uhd::index_error.
+ UHD_ERROR_INDEX = 10,
+ //! See uhd::key_error.
+ UHD_ERROR_KEY = 11,
+
+ //! See uhd::not_implemented_error.
+ UHD_ERROR_NOT_IMPLEMENTED = 20,
+ //! See uhd::usb_error.
+ UHD_ERROR_USB = 21,
+
+ //! See uhd::io_error.
+ UHD_ERROR_IO = 30,
+ //! See uhd::os_error.
+ UHD_ERROR_OS = 31,
+
+ //! See uhd::assertion_error.
+ UHD_ERROR_ASSERTION = 40,
+ //! See uhd::lookup_error.
+ UHD_ERROR_LOOKUP = 41,
+ //! See uhd::type_error.
+ UHD_ERROR_TYPE = 42,
+ //! See uhd::value_error.
+ UHD_ERROR_VALUE = 43,
+ //! See uhd::runtime_error.
+ UHD_ERROR_RUNTIME = 44,
+ //! See uhd::environment_error.
+ UHD_ERROR_ENVIRONMENT = 45,
+ //! See uhd::system_error.
+ UHD_ERROR_SYSTEM = 46,
+ //! See uhd::exception.
+ UHD_ERROR_EXCEPT = 47,
+
+ //! A boost::exception was thrown.
+ UHD_ERROR_BOOSTEXCEPT = 60,
+
+ //! A std::exception was thrown.
+ UHD_ERROR_STDEXCEPT = 70,
+
+ //! An unknown error was thrown.
+ UHD_ERROR_UNKNOWN = 100
+} uhd_error;
+
+#ifdef __cplusplus
+#include <uhd/config.hpp>
+#include <uhd/exception.hpp>
+
+#include <boost/exception/diagnostic_information.hpp>
+
+#include <string>
+
+UHD_API uhd_error error_from_uhd_exception(const uhd::exception* e);
+
+UHD_API const std::string& get_c_global_error_string();
+
+UHD_API void set_c_global_error_string(const std::string &msg);
+
+/*!
+ * This macro runs the given C++ code, and if there are any exceptions
+ * thrown, they are caught and converted to the corresponding UHD error
+ * code.
+ */
+#define UHD_SAFE_C(...) \
+ try{ __VA_ARGS__ } \
+ catch (const uhd::exception &e) { \
+ set_c_global_error_string(e.what()); \
+ return error_from_uhd_exception(&e); \
+ } \
+ catch (const boost::exception &e) { \
+ set_c_global_error_string(boost::diagnostic_information(e)); \
+ return UHD_ERROR_BOOSTEXCEPT; \
+ } \
+ catch (const std::exception &e) { \
+ set_c_global_error_string(e.what()); \
+ return UHD_ERROR_STDEXCEPT; \
+ } \
+ catch (...) { \
+ set_c_global_error_string("Unrecognized exception caught."); \
+ return UHD_ERROR_UNKNOWN; \
+ } \
+ set_c_global_error_string("None"); \
+ return UHD_ERROR_NONE;
+
+/*!
+ * This macro runs the given C++ code, and if there are any exceptions
+ * thrown, they are caught and converted to the corresponding UHD error
+ * code. The error message is also saved into the given handle.
+ */
+#define UHD_SAFE_C_SAVE_ERROR(h, ...) \
+ h->last_error.clear(); \
+ try{ __VA_ARGS__ } \
+ catch (const uhd::exception &e) { \
+ set_c_global_error_string(e.what()); \
+ h->last_error = e.what(); \
+ return error_from_uhd_exception(&e); \
+ } \
+ catch (const boost::exception &e) { \
+ set_c_global_error_string(boost::diagnostic_information(e)); \
+ h->last_error = boost::diagnostic_information(e); \
+ return UHD_ERROR_BOOSTEXCEPT; \
+ } \
+ catch (const std::exception &e) { \
+ set_c_global_error_string(e.what()); \
+ h->last_error = e.what(); \
+ return UHD_ERROR_STDEXCEPT; \
+ } \
+ catch (...) { \
+ set_c_global_error_string("Unrecognized exception caught."); \
+ h->last_error = "Unrecognized exception caught."; \
+ return UHD_ERROR_UNKNOWN; \
+ } \
+ h->last_error = "None"; \
+ set_c_global_error_string("None"); \
+ return UHD_ERROR_NONE;
+
+extern "C" {
+#endif
+
+//! Return the last error string reported by UHD
+/*!
+ * Functions that do not take in UHD structs/handles will place any error
+ * strings into a buffer that can be queried with this function. Functions that
+ * do take in UHD structs/handles will place their error strings in both locations.
+ */
+uhd_error uhd_get_last_error(
+ char* error_out,
+ size_t strbuffer_len
+);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_ERROR_H */
diff --git a/host/include/uhd/exception.hpp b/host/include/uhd/exception.hpp
index 69e902fd5..a21106166 100644
--- a/host/include/uhd/exception.hpp
+++ b/host/include/uhd/exception.hpp
@@ -98,6 +98,14 @@ namespace uhd{
virtual void dynamic_throw(void) const;
};
+ struct UHD_API usb_error : runtime_error{
+ int _code;
+ usb_error(int code, const std::string &what);
+ virtual unsigned code(void) const { return _code; };
+ virtual usb_error *dynamic_clone(void) const;
+ virtual void dynamic_throw(void) const;
+ };
+
struct UHD_API not_implemented_error : runtime_error{
not_implemented_error(const std::string &what);
virtual unsigned code(void) const;
diff --git a/host/include/uhd/image_loader.hpp b/host/include/uhd/image_loader.hpp
new file mode 100644
index 000000000..5963c862f
--- /dev/null
+++ b/host/include/uhd/image_loader.hpp
@@ -0,0 +1,90 @@
+//
+// Copyright 2014-2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_IMAGE_LOADER_HPP
+#define INCLUDED_UHD_IMAGE_LOADER_HPP
+
+#include <string>
+
+#include <boost/function.hpp>
+
+#include <uhd/config.hpp>
+#include <uhd/types/device_addr.hpp>
+
+namespace uhd{
+
+class UHD_API image_loader : boost::noncopyable{
+
+public:
+
+ typedef struct{
+ uhd::device_addr_t args;
+ bool load_firmware;
+ bool load_fpga;
+ std::string firmware_path;
+ std::string fpga_path;
+ } image_loader_args_t;
+
+ //! Signature of an image loading function
+ /*!
+ * This is the function signature for an image loading function.
+ * See the declaration of load() for the meaning of these arguments.
+ *
+ * This function must return true upon the end of a successful image load
+ * or false if no applicable device was found. It may only throw a runtime
+ * error under one of three conditions:
+ *
+ * * The function finds multiple devices that fit the user's arguments.
+ * * The function has already engaged with a specific device and
+ * something goes wrong.
+ * * The user gives arguments that unambiguously lead to a specific
+ * device and expect the default image(s) to be loaded, but the specific
+ * model of the device cannot be determined beyond a category.
+ */
+ typedef boost::function<bool(const image_loader_args_t &)> loader_fcn_t;
+
+ //! Register an image loader
+ /*!
+ * \param device_type the "type=foo" value given in an --args option
+ * \param loader_fcn the loader function for the given device
+ * \param recovery_instructions instructions on how to restore a device
+ */
+ static void register_image_loader(
+ const std::string &device_type,
+ const loader_fcn_t &loader_fcn,
+ const std::string &recovery_instructions
+ );
+
+ //! Load firmware and/or FPGA onto a device
+ /*!
+ * \param image_loader_args arguments to pass into image loading function
+ */
+ static bool load(const image_loader_args_t &image_loader_args);
+
+ //! Get the instructions on how to recovery a particular device
+ /*!
+ * These instructions should be queried if the user interrupts an image loading
+ * session, as this will likely leave the device in an unstable state.
+ * \param device_type the "type=foo" value given in an --args option
+ * \return recoverying instructions
+ */
+ static std::string get_recovery_instructions(const std::string &device_type);
+};
+
+}
+
+#endif /* INCLUDED_UHD_IMAGE_LOADER_HPP */
diff --git a/host/include/uhd/transport/CMakeLists.txt b/host/include/uhd/transport/CMakeLists.txt
index 2118674c6..623c179e9 100644
--- a/host/include/uhd/transport/CMakeLists.txt
+++ b/host/include/uhd/transport/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2010-2013 Ettus Research LLC
+# Copyright 2010-2014 Ettus Research LLC
#
# 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
@@ -15,11 +15,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
UHD_INSTALL(FILES
bounded_buffer.hpp
bounded_buffer.ipp
buffer_pool.hpp
+ chdr.hpp
if_addrs.hpp
udp_constants.hpp
udp_simple.hpp
diff --git a/host/include/uhd/transport/chdr.hpp b/host/include/uhd/transport/chdr.hpp
new file mode 100644
index 000000000..5e8cd58a9
--- /dev/null
+++ b/host/include/uhd/transport/chdr.hpp
@@ -0,0 +1,113 @@
+//
+// Copyright 2014 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_TRANSPORT_CHDR_HPP
+#define INCLUDED_UHD_TRANSPORT_CHDR_HPP
+
+#include <uhd/transport/vrt_if_packet.hpp>
+
+namespace uhd{ namespace transport{ namespace vrt{
+
+/*! \brief CVITA/CHDR related function
+ *
+ * See \ref rtp_chdr for details on the CVITA/CHDR protocol.
+ *
+ * All packers take the host format into account. Choose the _le functions
+ * if the transport uses little endian format (e.g. PCIe) and the _be
+ * functions if the transport uses big endian format (e.g. Ethernet).
+ *
+ * Note 1: All packers assume there to be enough space at the address
+ * provided by \p packet_buff. See also \ref vrt_pack_contract.
+ *
+ * Note 2: All these packers assume the following options without checking them:
+ * - `if_packet_info.link_type == LINK_TYPE_CHDR`
+ * - `if_packet_info.has_cid == false`
+ * - `if_packet_info.has_sid == true`
+ * - `if_packet_info.has_tsi == false`
+ * - `if_packet_info.has_tlr == false`
+ * This relaxes some of \ref vrt_pack_contract, but adds the additional
+ * constraint that the input data must be CHDR.
+ *
+ * In the unpacker, these values will be set accordingly.
+ */
+namespace chdr{
+
+ //! The maximum number of 64-bit words in a CVITA header
+ static const size_t max_if_hdr_words64 = 2; // CHDR + tsf (fractional timestamp)
+
+ /*!
+ * Pack a CHDR header from metadata (big endian format).
+ *
+ * See \ref vrt_pack_contract, but `link_type` is assumed to be
+ * `LINK_TYPE_CHDR`.
+ *
+ * \param packet_buff memory to write the packed vrt header
+ * \param if_packet_info the if packet info (read/write)
+ */
+ UHD_API void if_hdr_pack_be(
+ boost::uint32_t *packet_buff,
+ if_packet_info_t &if_packet_info
+ );
+
+ /*!
+ * Unpack a CHDR header to metadata (big endian format).
+ *
+ * See \ref vrt_unpack_contract, but `link_type` is assumed to be
+ * `LINK_TYPE_CHDR`.
+ *
+ * \param packet_buff memory to read the packed vrt header
+ * \param if_packet_info the if packet info (read/write)
+ */
+ UHD_API void if_hdr_unpack_be(
+ const boost::uint32_t *packet_buff,
+ if_packet_info_t &if_packet_info
+ );
+
+ /*!
+ * Pack a CHDR header from metadata (little endian format).
+ *
+ * See \ref vrt_pack_contract, but `link_type` is assumed to be
+ * `LINK_TYPE_CHDR`.
+ *
+ * \param packet_buff memory to write the packed vrt header
+ * \param if_packet_info the if packet info (read/write)
+ */
+ UHD_API void if_hdr_pack_le(
+ boost::uint32_t *packet_buff,
+ if_packet_info_t &if_packet_info
+ );
+
+ /*!
+ * Unpack a CHDR header to metadata (little endian format).
+ *
+ * See \ref vrt_unpack_contract, but `link_type` is assumed to be
+ * `LINK_TYPE_CHDR`.
+ *
+ * \param packet_buff memory to read the packed vrt header
+ * \param if_packet_info the if packet info (read/write)
+ */
+ UHD_API void if_hdr_unpack_le(
+ const boost::uint32_t *packet_buff,
+ if_packet_info_t &if_packet_info
+ );
+
+} //namespace chdr
+
+}}} //namespace uhd::transport::vrt
+
+#endif /* INCLUDED_UHD_TRANSPORT_CHDR_HPP */
+
diff --git a/host/include/uhd/transport/nirio/nirio_driver_iface.h b/host/include/uhd/transport/nirio/nirio_driver_iface.h
index 10df8e04e..6804f6171 100644
--- a/host/include/uhd/transport/nirio/nirio_driver_iface.h
+++ b/host/include/uhd/transport/nirio/nirio_driver_iface.h
@@ -24,57 +24,84 @@
#include <uhd/transport/nirio/status.h>
#include <uhd/config.hpp>
#if defined(UHD_PLATFORM_WIN32)
- #include <Windows.h>
- #pragma warning(disable:4201) // nonstandard extension used : nameless struct/union
- #include <WinIoCtl.h>
- #pragma warning(default:4201)
+ #include <windows.h>
+ #ifdef _MSC_VER
+ #pragma warning(disable:4201) // nonstandard extension used : nameless struct/union
+ #endif
+ #include <winioctl.h>
+ #ifdef _MSC_VER
+ #pragma warning(default:4201)
+ #endif
#elif defined(UHD_PLATFORM_MACOS)
#include <IOKit/IOKitLib.h>
+#elif defined(UHD_PLATFORM_LINUX)
+ #include <linux/ioctl.h>
#endif
-// CTL_CODE macro for non-win OSes
-#ifndef UHD_PLATFORM_WIN32
- #define CTL_CODE(a,controlCode,b,c) (controlCode)
+#if __GNUC__
+ typedef uint64_t aligned_uint64_t __attribute__ ((aligned(8)));
+#else
+ typedef uint64_t aligned_uint64_t;
#endif
-namespace nirio_driver_iface {
+//IOCTL Definitions
+
+#if defined(UHD_PLATFORM_WIN32)
+
+ #define IOCTL_ACCESS_ANY (FILE_ANY_ACCESS)
+ #define IOCTL_ACCESS_READ (FILE_READ_ACCESS)
+ #define IOCTL_ACCESS_WRITE (FILE_WRITE_ACCESS)
+ #define IOCTL_ACCESS_RW (FILE_READ_ACCESS | FILE_WRITE_ACCESS)
+
+ #define IOCTL(type, function, access) \
+ CTL_CODE((0x8000+type), (0x800+function), METHOD_BUFFERED, access)
+
+#elif defined(UHD_PLATFORM_MACOS)
+
+ #define IOCTL_ACCESS_ANY (0U)
+ #define IOCTL_ACCESS_READ (1U)
+ #define IOCTL_ACCESS_WRITE (2U)
+ #define IOCTL_ACCESS_RW (3U)
+
+ #define IOCTL(type, function, access) \
+ (((access & 0x0003) << 30) | \
+ ((type & 0x00FF) << 16) | \
+ ((function & 0xFFFF) << 0))
+
+#elif defined(UHD_PLATFORM_LINUX)
+
+ #define IOCTL_ACCESS_ANY (_IOC_NONE)
+ #define IOCTL_ACCESS_READ (_IOC_READ)
+ #define IOCTL_ACCESS_WRITE (_IOC_WRITE)
+ #define IOCTL_ACCESS_RW (_IOC_READ | _IOC_WRITE)
+
+ struct nirio_ioctl_block_t {
+ aligned_uint64_t in_buf;
+ aligned_uint64_t out_buf;
+ uint32_t in_buf_len;
+ uint32_t out_buf_len;
+ uint32_t bytes_returned;
+ uint32_t padding;
+ };
+
+ #define IOCTL(type, function, access) \
+ _IOC(access, type, function, sizeof(nirio_ioctl_block_t))
-const uint32_t NIRIO_IOCTL_BASE = 0x800;
-
-const uint32_t NIRIO_IOCTL_SYNCOP =
- CTL_CODE(FILE_DEVICE_UNKNOWN,
- NIRIO_IOCTL_BASE + 4,
- METHOD_OUT_DIRECT,
- FILE_READ_DATA | FILE_WRITE_DATA);
- ///< The synchronous operation code. Note: We
- /// must use METHOD_OUT_DIRECT on the syncOp()
- /// IOCTL to ensure the contents of the output
- /// block are available in the kernel.
-
-const uint32_t NIRIO_IOCTL_GET_IFACE_NUM =
- CTL_CODE(FILE_DEVICE_UNKNOWN,
- NIRIO_IOCTL_BASE + 6,
- METHOD_BUFFERED,
- FILE_READ_DATA); ///< Get the interface number for a device
-
-const uint32_t NIRIO_IOCTL_GET_SESSION =
- CTL_CODE(FILE_DEVICE_UNKNOWN,
- NIRIO_IOCTL_BASE + 8,
- METHOD_BUFFERED,
- FILE_READ_ACCESS); ///< Gets a previously opened session to a device
-
-const uint32_t NIRIO_IOCTL_POST_OPEN =
- CTL_CODE(FILE_DEVICE_UNKNOWN,
- NIRIO_IOCTL_BASE + 9,
- METHOD_BUFFERED,
- FILE_READ_ACCESS); ///< Called after opening a session
-
-const uint32_t NIRIO_IOCTL_PRE_CLOSE =
- CTL_CODE(FILE_DEVICE_UNKNOWN,
- NIRIO_IOCTL_BASE + 10,
- METHOD_BUFFERED,
- FILE_READ_ACCESS); ///< Called before closing a session
+#else
+ #define IOCTL_ACCESS_ANY (0U)
+ #define IOCTL_ACCESS_READ (1U)
+ #define IOCTL_ACCESS_WRITE (2U)
+ #define IOCTL_ACCESS_RW (3U)
+
+ #define IOCTL(type, function, access) \
+ (((access & 0x0003) << 30) | \
+ ((type & 0x00FF) << 16) | \
+ ((function & 0xFFFF) << 0))
+
+#endif
+
+namespace nirio_driver_iface {
//Device handle definition
#if defined(UHD_PLATFORM_LINUX)
@@ -83,7 +110,7 @@ const uint32_t NIRIO_IOCTL_PRE_CLOSE =
typedef HANDLE rio_dev_handle_t;
#elif defined(UHD_PLATFORM_MACOS)
typedef io_connect_t rio_dev_handle_t;
-#else //Unsupported platforms
+#else
typedef int rio_dev_handle_t;
#endif
static const rio_dev_handle_t INVALID_RIO_HANDLE = ((rio_dev_handle_t)-1);
diff --git a/host/include/uhd/transport/nirio/nirio_fifo.h b/host/include/uhd/transport/nirio/nirio_fifo.h
index cd471474d..a0cd7149f 100644
--- a/host/include/uhd/transport/nirio/nirio_fifo.h
+++ b/host/include/uhd/transport/nirio/nirio_fifo.h
@@ -59,8 +59,8 @@ public:
inline const std::string& get_name() const { return _name; }
inline uint32_t get_channel() const { return _fifo_channel; }
- inline uint32_t get_direction() const { return _fifo_direction; }
- inline uint32_t get_scalar_type() const { return _datatype_info.scalar_type; }
+ inline fifo_direction_t get_direction() const { return _fifo_direction; }
+ inline nirio_scalar_type_t get_scalar_type() const { return _datatype_info.scalar_type; }
nirio_status start();
diff --git a/host/include/uhd/transport/nirio/nirio_quirks.h b/host/include/uhd/transport/nirio/nirio_quirks.h
index 8e58f80f1..45ef40394 100644
--- a/host/include/uhd/transport/nirio/nirio_quirks.h
+++ b/host/include/uhd/transport/nirio/nirio_quirks.h
@@ -35,8 +35,8 @@ public:
nirio_quirks() : _tx_stream_count(0) {
}
- UHD_INLINE void register_tx_streams(const uint32_t tx_stream_indices[]) {
- for (size_t i = 0; i < sizeof(tx_stream_indices)/sizeof(*tx_stream_indices); i++) {
+ UHD_INLINE void register_tx_streams(const uint32_t tx_stream_indices[], size_t size) {
+ for (size_t i = 0; i < size; i++) {
_tx_stream_fifo_indices.insert(tx_stream_indices[i]);
}
}
diff --git a/host/include/uhd/transport/nirio/niriok_proxy.h b/host/include/uhd/transport/nirio/niriok_proxy.h
index 07bcb59b6..bb112dd8a 100644
--- a/host/include/uhd/transport/nirio/niriok_proxy.h
+++ b/host/include/uhd/transport/nirio/niriok_proxy.h
@@ -145,29 +145,9 @@ namespace uhd { namespace niusrprio
class UHD_API niriok_proxy : public boost::noncopyable {
public:
- struct nirio_ioctl_packet_t {
- nirio_ioctl_packet_t(
- void* const _outBuf,
- const uint32_t _outSize,
- const int32_t _statusCode)
- {
- outBuf._64BitField = 0;
- outBuf.pointer = _outBuf;
- outSize = _outSize;
- statusCode = _statusCode;
- };
-
- union {
- void* pointer;
- uint64_t _64BitField;
- } outBuf;
-
- uint32_t outSize;
- int32_t statusCode;
- };
- typedef boost::shared_ptr<niriok_proxy> sptr;
-
- static sptr make_and_open(const std::string& interface_path);
+ typedef boost::shared_ptr<niriok_proxy> sptr;
+
+ static sptr make_and_open(const std::string& interface_path);
niriok_proxy();
virtual ~niriok_proxy();
@@ -180,9 +160,6 @@ namespace uhd { namespace niusrprio
uint32_t get_interface_num() { return _interface_num; }
- virtual nirio_status get_cached_session(
- uint32_t& session) = 0;
-
virtual nirio_status get_version(
nirio_version_t type,
uint32_t& major,
diff --git a/host/include/uhd/transport/nirio/niriok_proxy_impl_v1.h b/host/include/uhd/transport/nirio/niriok_proxy_impl_v1.h
index 173d43ed6..a10d1aaff 100644
--- a/host/include/uhd/transport/nirio/niriok_proxy_impl_v1.h
+++ b/host/include/uhd/transport/nirio/niriok_proxy_impl_v1.h
@@ -33,341 +33,8 @@ namespace uhd { namespace niusrprio
are not compatible with NI-RIO 14.0 and later.
*/
- class UHD_API niriok_proxy_impl_v1 : virtual public niriok_proxy {
+ class UHD_API niriok_proxy_impl_v1 : virtual public niriok_proxy {
public:
-
- // -------------------------------
- // Function Codes: defined as integers rather than enums because they
- // are going to be carried accross boundaries so size matters
-
- struct NIRIO_FUNC
- {
- static const uint32_t GET32 = 0x00000001;
- static const uint32_t SET32 = 0x00000002;
- static const uint32_t SET_DRIVER_CONFIG = 0x00000007;
- static const uint32_t FIFO = 0x00000008;
- static const uint32_t IO = 0x0000000A;
- static const uint32_t FIFO_STOP_ALL = 0x0000000C;
- static const uint32_t ADD_RESOURCE = 0x0000000D;
- static const uint32_t GET_STRING = 0x0000000E;
- static const uint32_t SET_STRING = 0x0000000F;
- static const uint32_t DOWNLOAD = 0x00000013;
- static const uint32_t RESET = 0x00000014;
- };
-
- struct NIRIO_RESOURCE
- {
- static const uint32_t INPUT_FIFO = 0xD0000001;
- static const uint32_t OUTPUT_FIFO = 0xD0000002;
- };
-
- struct NIRIO_FIFO
- {
- static const uint32_t CONFIGURE = 0x80000001;
- static const uint32_t START = 0x80000002;
- static const uint32_t STOP = 0x80000003;
- static const uint32_t READ = 0x80000004;
- static const uint32_t WRITE = 0x80000005;
- static const uint32_t WAIT = 0x80000006;
- static const uint32_t GRANT = 0x80000007;
- };
-
- struct NIRIO_IO
- {
- static const uint32_t POKE64 = 0xA0000005;
- static const uint32_t POKE32 = 0xA0000006;
- static const uint32_t POKE16 = 0xA0000007;
- static const uint32_t POKE8 = 0xA0000008;
- static const uint32_t PEEK64 = 0xA0000009;
- static const uint32_t PEEK32 = 0xA000000A;
- static const uint32_t PEEK16 = 0xA000000B;
- static const uint32_t PEEK8 = 0xA000000C;
- static const uint32_t READ_BLOCK = 0xA000000D;
- static const uint32_t WRITE_BLOCK = 0xA000000E;
- static const uint32_t GET_IO_WINDOW = 0xA000000F;
- static const uint32_t GET_IO_WINDOW_SIZE = 0xA0000010;
- };
-
- struct nirio_syncop_in_params_t
- {
- uint32_t function;
- uint32_t subfunction;
-
- union
- {
- struct
- {
- uint32_t attribute;
- uint32_t value;
- } attribute32;
-
- struct
- {
- uint32_t attribute;
- uint64_t value;
- } attribute64;
-
- struct
- {
- uint32_t attribute;
- } attributeStr;
-
- struct
- {
- uint32_t attribute;
- } download;
-
- union
- {
- struct
- {
- uint32_t reserved_field_0_0_0;
- } reserved_field_0_0;
- struct
- {
- uint32_t reserved_field_0_1_0;
- uint32_t reserved_field_0_1_1;
- } reserved_field_0_1;
- struct
- {
- uint32_t reserved_field_0_2_0;
- } reserved_field_0_2;
- } reserved_field_0;
-
- union
- {
- struct
- {
- uint32_t channel;
- uint32_t baseAddress;
- uint32_t depthInSamples;
- uint32_t version;
- } fifo;
- struct
- {
- uint32_t channel;
- uint32_t baseAddress;
- uint32_t depthInSamples;
- uint32_t version;
- uint32_t scalarType;
- uint32_t bitWidth;
- } fifoWithDataType;
- struct
- {
- uint64_t rangeBaseAddress;
- uint32_t rangeSizeInBytes;
- uint32_t rangeAttribute;
- } atomic; // obsolete
- } add;
-
- struct
- {
- uint32_t channel;
-
- union
- {
- struct
- {
- uint32_t requestedDepth;
- uint8_t requiresActuals;
- } config;
- struct
- {
- uint32_t timeout;
- } read;
- struct
- {
- uint32_t timeout;
- uint32_t scalarType;
- uint32_t bitWidth;
- } readWithDataType;
- struct
- {
- uint32_t timeout;
- } write;
- struct
- {
- uint32_t timeout;
- uint32_t scalarType;
- uint32_t bitWidth;
- } writeWithDataType;
- struct
- {
- uint32_t elementsRequested;
- uint32_t scalarType;
- uint32_t bitWidth;
- uint32_t timeout;
- uint8_t output;
- } wait;
- struct
- {
- uint32_t elements;
- } grant;
- } op;
- } fifo;
-
- struct
- {
- uint64_t reserved_field_1_0;
- uint32_t reserved_field_1_1;
- uint32_t reserved_field_1_2;
- } reserved_field_1; // Obsolete
-
- struct
- {
- uint32_t offset;
- union
- {
- uint64_t value64;
- uint32_t value32;
- uint16_t value16;
- uint8_t value8;
- } value;
- union
- {
- uint32_t sizeToMap;
- } memoryMappedIoWindow;
- } io;
-
- struct
- {
- uint32_t reserved_field_2_0;
- uint32_t reserved_field_2_1;
- } reserved_field_2;
-
- struct
- {
- uint32_t reserved_field_3_0;
- } reserved_field_3;
-
- union
- {
- struct
- {
- uint32_t reserved_field_4_0;
- int32_t reserved_field_4_1;
- } wait;
- } reserved_field_4;
-
- } params;
-
- uint32_t inbufByteLen;
-
- union
- {
- const void* pointer;
- uint64_t _64BitField;
- } inbuf;
- };
-
- static inline void init_syncop_in_params(nirio_syncop_in_params_t& param, const void* const buf, const uint32_t len)
- {
- param.inbuf._64BitField = 0;
- param.inbuf.pointer = buf;
- param.inbufByteLen = len;
- }
-
-
- struct nirio_syncop_out_params_t
- {
- union
- {
- struct
- {
- uint32_t value;
- } attribute32;
-
- struct
- {
- uint64_t value;
- } attribute64;
-
- union
- {
- struct
- {
- uint32_t reserved_field_0_0;
- } enable;
- } reserved_field_0;
-
- struct
- {
- union
- {
- struct
- {
- uint32_t actualDepth;
- uint32_t actualSize;
- } config;
- struct
- {
- uint32_t numberRead;
- uint32_t numberRemaining;
- } read;
- struct
- {
- uint32_t numberRemaining;
- } write;
- struct
- {
- union
- {
- void* pointer;
- uint64_t _64BitField;
- } elements;
- } wait;
- } op;
- } fifo;
-
- struct
- {
- union
- {
- union
- {
- uint64_t value64;
- uint32_t value32;
- uint16_t value16;
- uint8_t value8;
- } value;
- union
- {
- void* memoryMappedAddress;
- uint64_t _64BitField;
- } memoryMappedIoWindow;
- union
- {
- uint32_t size;
- } memoryMappedIoWindowSize;
- };
- } io;
-
- uint32_t stringLength;
-
- struct
- {
- uint32_t reserved_field_1_0;
- } reserved_field_1;
-
- } params;
-
- uint32_t outbufByteLen;
-
- union
- {
- void* pointer;
- uint64_t _64BitField;
- } outbuf;
- };
-
-
- static inline void init_syncop_out_params(nirio_syncop_out_params_t& param, void* buf, uint32_t len)
- {
- param.outbuf._64BitField = 0;
- param.outbuf.pointer = buf;
- param.outbufByteLen = len;
- }
-
niriok_proxy_impl_v1();
virtual ~niriok_proxy_impl_v1();
@@ -377,9 +44,6 @@ namespace uhd { namespace niusrprio
virtual nirio_status reset();
- virtual nirio_status get_cached_session(
- uint32_t& session);
-
virtual nirio_status get_version(
nirio_version_t type,
uint32_t& major,
@@ -477,7 +141,6 @@ namespace uhd { namespace niusrprio
size_t writeBufferLength,
void *readBuffer,
size_t readBufferLength);
-
};
}}
diff --git a/host/include/uhd/transport/nirio/niriok_proxy_impl_v2.h b/host/include/uhd/transport/nirio/niriok_proxy_impl_v2.h
index 333ab4348..c0183502a 100644
--- a/host/include/uhd/transport/nirio/niriok_proxy_impl_v2.h
+++ b/host/include/uhd/transport/nirio/niriok_proxy_impl_v2.h
@@ -24,12 +24,6 @@
#include <uhd/transport/nirio/nirio_quirks.h>
#include <uhd/transport/nirio/niriok_proxy.h>
-#if __GNUC__
- typedef uint64_t tAlignedU64 __attribute__ ((aligned(8)));
-#else
- typedef uint64_t tAlignedU64;
-#endif
-
namespace uhd { namespace niusrprio
{
/*
@@ -39,267 +33,8 @@ namespace uhd { namespace niusrprio
are not compatible with NI-RIO versions older than 14.0.
*/
- #define IOCTL(type, function, access) \
- CTL_CODE((0x8000+type), (0x800+function), METHOD_BUFFERED, access)
-
- #define IOCTL_ACCESS_ANY (FILE_ANY_ACCESS)
- #define IOCTL_ACCESS_READ (FILE_READ_ACCESS)
- #define IOCTL_ACCESS_WRITE (FILE_WRITE_ACCESS)
- #define IOCTL_ACCESS_RW (FILE_READ_ACCESS | FILE_WRITE_ACCESS)
-
- #define IOCTL_TRANSPORT_GET32 IOCTL(0, 0, IOCTL_ACCESS_READ)
- #define IOCTL_TRANSPORT_SET32 IOCTL(0, 1, IOCTL_ACCESS_WRITE)
- #define IOCTL_TRANSPORT_GET_STRING IOCTL(0, 2, IOCTL_ACCESS_READ)
- #define IOCTL_TRANSPORT_SET_STRING IOCTL(0, 3, IOCTL_ACCESS_WRITE)
- #define IOCTL_TRANSPORT_RESET IOCTL(1, 1, IOCTL_ACCESS_WRITE)
- #define IOCTL_TRANSPORT_ADD_INPUT_FIFO_RESOURCE IOCTL(2, 0, IOCTL_ACCESS_ANY)
- #define IOCTL_TRANSPORT_ADD_OUTPUT_FIFO_RESOURCE IOCTL(2, 1, IOCTL_ACCESS_ANY)
- #define IOCTL_TRANSPORT_SET_DEVICE_CONFIG IOCTL(2, 3, IOCTL_ACCESS_WRITE)
- #define IOCTL_TRANSPORT_FIFO_CONFIG IOCTL(4, 0, IOCTL_ACCESS_ANY)
- #define IOCTL_TRANSPORT_FIFO_START IOCTL(4, 1, IOCTL_ACCESS_ANY)
- #define IOCTL_TRANSPORT_FIFO_STOP IOCTL(4, 2, IOCTL_ACCESS_ANY)
- #define IOCTL_TRANSPORT_FIFO_READ IOCTL(4, 3, IOCTL_ACCESS_READ)
- #define IOCTL_TRANSPORT_FIFO_WRITE IOCTL(4, 4, IOCTL_ACCESS_WRITE)
- #define IOCTL_TRANSPORT_FIFO_WAIT IOCTL(4, 5, IOCTL_ACCESS_ANY)
- #define IOCTL_TRANSPORT_FIFO_GRANT IOCTL(4, 6, IOCTL_ACCESS_ANY)
- #define IOCTL_TRANSPORT_FIFO_STOP_ALL IOCTL(4, 7, IOCTL_ACCESS_ANY)
- #define IOCTL_TRANSPORT_PEEK64 IOCTL(5, 2, IOCTL_ACCESS_READ)
- #define IOCTL_TRANSPORT_PEEK32 IOCTL(5, 3, IOCTL_ACCESS_READ)
- #define IOCTL_TRANSPORT_POKE64 IOCTL(5, 6, IOCTL_ACCESS_WRITE)
- #define IOCTL_TRANSPORT_POKE32 IOCTL(5, 7, IOCTL_ACCESS_WRITE)
- #define IOCTL_TRANSPORT_POST_OPEN IOCTL(8, 0, IOCTL_ACCESS_ANY)
- #define IOCTL_TRANSPORT_PRE_CLOSE IOCTL(8, 1, IOCTL_ACCESS_ANY)
-
- typedef struct {
- nirio_scalar_type_t scalarType;
- nirio_u32_t bitWidth;
- nirio_i32_t integerWordLength;
- } nirio_fifo_data_type_t;
-
class UHD_API niriok_proxy_impl_v2 : virtual public niriok_proxy {
public:
- typedef struct in_transport_get32
- {
- nirio_device_attribute32_t attribute;
- int32_t status;
- } in_transport_get32_t;
- typedef struct out_transport_get32
- {
- uint32_t retVal__;
- int32_t status;
- } out_transport_get32_t;
- typedef struct in_transport_set32
- {
- nirio_device_attribute32_t attribute;
- uint32_t value;
- int32_t status;
- } in_transport_set32_t;
- typedef struct out_transport_set32
- {
- int32_t status;
- } out_transport_set32_t;
- typedef struct out_transport_get_string
- {
- uint32_t stringLen;
- int32_t status;
- } out_transport_get_string_t;
- typedef struct out_transport_set_string
- {
- int32_t status;
- } out_transport_set_string_t;
- typedef struct in_transport_reset
- {
- int32_t status;
- } in_transport_reset_t;
- typedef struct out_transport_reset
- {
- int32_t status;
- } out_transport_reset_t;
- typedef struct in_transport_add_input_fifo_resource
- {
- uint32_t channel;
- uint32_t baseAddress;
- uint32_t depthInSamples;
- nirio_fifo_data_type_t dataType;
- uint32_t version;
- int32_t status;
- } in_transport_add_input_fifo_resource_t;
- typedef struct out_transport_addInputFifo_resource
- {
- int32_t status;
- } out_transport_add_input_fifo_resource_t;
- typedef struct in_transport_addOutputFifo_resource
- {
- uint32_t channel;
- uint32_t baseAddress;
- uint32_t depthInSamples;
- nirio_fifo_data_type_t dataType;
- uint32_t version;
- int32_t status;
- } in_transport_add_output_fifo_resource_t;
- typedef struct out_transport_addOutputFifo_resource
- {
- int32_t status;
- } out_transport_add_output_fifo_resource_t;
- typedef struct in_transport_setDevice_config
- {
- uint32_t attribute;
- int32_t status;
- } in_transport_set_device_config_t;
- typedef struct out_transport_setDevice_config
- {
- int32_t status;
- } out_transport_set_device_config_t;
- typedef struct in_transport_fifo_config
- {
- uint32_t channel;
- tAlignedU64 requestedDepth;
- int32_t status;
- } in_transport_fifo_config_t;
- typedef struct out_transport_fifo_config
- {
- tAlignedU64 actualDepth;
- tAlignedU64 actualSize;
- int32_t status;
- } out_transport_fifo_config_t;
- typedef struct in_transport_fifo_start
- {
- uint32_t channel;
- int32_t status;
- } in_transport_fifo_start_t;
- typedef struct out_transport_fifo_start
- {
- int32_t status;
- } out_transport_fifo_start_t;
- typedef struct in_transport_fifo_stop
- {
- uint32_t channel;
- int32_t status;
- } in_transport_fifo_stop_t;
- typedef struct out_transport_fifo_stop
- {
- int32_t status;
- } out_transport_fifo_stop_t;
- typedef struct in_transport_fifo_read
- {
- uint32_t channel;
- tAlignedU64 buf;
- uint32_t numberElements;
- nirio_fifo_data_type_t dataType;
- uint32_t timeout;
- int32_t status;
- } in_transport_fifo_read_t;
- typedef struct out_transport_fifo_read
- {
- uint32_t read;
- uint32_t remaining;
- int32_t status;
- } out_transport_fifo_read_t;
- typedef struct in_transport_fifo_write
- {
- uint32_t channel;
- tAlignedU64 buf;
- uint32_t numberElements;
- nirio_fifo_data_type_t dataType;
- uint32_t timeout;
- int32_t status;
- } in_transport_fifo_write_t;
- typedef struct out_transport_fifo_write
- {
- uint32_t remaining;
- int32_t status;
- } out_transport_fifo_write_t;
- typedef struct in_transport_fifo_wait
- {
- uint32_t channel;
- tAlignedU64 elementsRequested;
- nirio_fifo_data_type_t dataType;
- bool output;
- uint32_t timeout;
- int32_t status;
- } in_transport_fifo_wait_t;
- typedef struct out_transport_fifo_wait
- {
- tAlignedU64 elements;
- tAlignedU64 elementsAcquired;
- tAlignedU64 elementsRemaining;
- int32_t status;
- } out_transport_fifo_wait_t;
- typedef struct in_transport_fifo_grant
- {
- uint32_t channel;
- tAlignedU64 elements;
- int32_t status;
- } in_transport_fifo_grant_t;
- typedef struct out_transport_fifo_grant
- {
- int32_t status;
- } out_transport_fifo_grant_t;
- typedef struct in_transport_fifoStop_all
- {
- int32_t status;
- } in_transport_fifo_stop_all_t;
- typedef struct out_transport_fifoStop_all
- {
- int32_t status;
- } out_transport_fifo_stop_all_t;
- typedef struct in_transport_peek64
- {
- uint32_t offset;
- int32_t status;
- } in_transport_peek64_t;
- typedef struct out_transport_peek64
- {
- tAlignedU64 retVal__;
- int32_t status;
- } out_transport_peek64_t;
- typedef struct in_transport_peek32
- {
- uint32_t offset;
- int32_t status;
- } in_transport_peek32_t;
- typedef struct out_transport_peek32
- {
- uint32_t retVal__;
- int32_t status;
- } out_transport_peek32_t;
- typedef struct in_transport_poke64
- {
- uint32_t offset;
- tAlignedU64 value;
- int32_t status;
- } in_transport_poke64_t;
- typedef struct out_transport_poke64
- {
- int32_t status;
- } out_transport_poke64_t;
- typedef struct in_transport_poke32
- {
- uint32_t offset;
- uint32_t value;
- int32_t status;
- } in_transport_poke32_t;
- typedef struct out_transport_poke32
- {
- int32_t status;
- } out_transport_poke32_t;
- typedef struct in_transport_post_open
- {
- int32_t status;
- } in_transport_post_open_t;
- typedef struct out_transport_post_open
- {
- int32_t status;
- } out_transport_post_open_t;
- typedef struct in_transport_pre_close
- {
- int32_t status;
- } in_transport_pre_close_t;
- typedef struct out_transport_pre_close
- {
- int32_t status;
- } out_transport_pre_close_t;
-
niriok_proxy_impl_v2();
virtual ~niriok_proxy_impl_v2();
@@ -309,9 +44,6 @@ namespace uhd { namespace niusrprio
virtual nirio_status reset();
- virtual nirio_status get_cached_session(
- uint32_t& session);
-
virtual nirio_status get_version(
nirio_version_t type,
uint32_t& major,
@@ -402,7 +134,6 @@ namespace uhd { namespace niusrprio
protected:
// protected close function that doesn't acquire synchronization lock
virtual void _close();
-
};
}}
diff --git a/host/include/uhd/transport/tcp_zero_copy.hpp b/host/include/uhd/transport/tcp_zero_copy.hpp
index 52e94fab9..ac282d8a2 100644
--- a/host/include/uhd/transport/tcp_zero_copy.hpp
+++ b/host/include/uhd/transport/tcp_zero_copy.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2014 Ettus Research LLC
+// Copyright 2010-2015 Ettus Research LLC
//
// 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
@@ -32,7 +32,7 @@ namespace uhd{ namespace transport{
*/
struct UHD_API tcp_zero_copy : public virtual zero_copy_if
{
- virtual ~tcp_zero_copy(void) = 0;
+ virtual ~tcp_zero_copy(void);
/*!
* Make a new zero copy TCP transport:
diff --git a/host/include/uhd/transport/usb_device_handle.hpp b/host/include/uhd/transport/usb_device_handle.hpp
index fdea9e2be..bf122f549 100644
--- a/host/include/uhd/transport/usb_device_handle.hpp
+++ b/host/include/uhd/transport/usb_device_handle.hpp
@@ -41,6 +41,7 @@ namespace uhd { namespace transport {
class UHD_API usb_device_handle : boost::noncopyable {
public:
typedef boost::shared_ptr<usb_device_handle> sptr;
+ typedef std::pair<boost::uint16_t, boost::uint16_t> vid_pid_pair_t;
/*!
* Return the device's serial number
@@ -83,6 +84,8 @@ public:
* \return a vector of USB device handles that match vid and pid
*/
static std::vector<usb_device_handle::sptr> get_device_list(boost::uint16_t vid, boost::uint16_t pid);
+ static std::vector<usb_device_handle::sptr> get_device_list(const std::vector<usb_device_handle::vid_pid_pair_t>& vid_pid_pair_list);
+
}; //namespace usb
diff --git a/host/include/uhd/transport/vrt_if_packet.hpp b/host/include/uhd/transport/vrt_if_packet.hpp
index 362531567..1e54607c1 100644
--- a/host/include/uhd/transport/vrt_if_packet.hpp
+++ b/host/include/uhd/transport/vrt_if_packet.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2013 Ettus Research LLC
+// Copyright 2010-2014 Ettus Research LLC
//
// 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
@@ -52,9 +52,18 @@ namespace vrt{
//packet type
enum packet_type_t
{
+ // VRT language:
PACKET_TYPE_DATA = 0x0,
PACKET_TYPE_IF_EXT = 0x1,
- PACKET_TYPE_CONTEXT = 0x2 //extension context: has_sid = true
+ PACKET_TYPE_CONTEXT = 0x2, //extension context: has_sid = true
+
+ // CVITA language:
+ //PACKET_TYPE_DATA = 0x0, // Data
+ PACKET_TYPE_FC = 0x1, // Flow control
+ PACKET_TYPE_ACK = 0x1, // Flow control (ack)
+ PACKET_TYPE_CMD = 0x2, // Command
+ PACKET_TYPE_RESP = 0x3, // Command response
+ PACKET_TYPE_ERROR = 0x3 // Command response: Error (the EOB bit is raised in this case)
} packet_type;
//size fields
@@ -65,18 +74,46 @@ namespace vrt{
//header fields
size_t packet_count;
+ //! Asserted for start- or end-of-burst
bool sob, eob;
+ //! This is asserted for command responses that are errors (CHDR only)
+ bool error;
//optional fields
+ //! Stream ID (SID). See uhd::sid_t
bool has_sid; boost::uint32_t sid;
+ //! Class ID.
bool has_cid; boost::uint64_t cid;
+ //! Integer timestamp
bool has_tsi; boost::uint32_t tsi;
+ //! Fractional timestamp
bool has_tsf; boost::uint64_t tsf;
+ //! Trailer
bool has_tlr; boost::uint32_t tlr;
};
/*!
* Pack a vrt header from metadata (big endian format).
+ *
+ * \section vrt_pack_contract Packing contract
+ *
+ * \subsection Requirements:
+ * - packet_buff points to a valid address space with enough space to write
+ * the entire buffer, regardless of its length. At the very least, it must
+ * be able to hold an entire header.
+ * - `if_packet_info` has the following members set to correct values:
+ * - `has_*` members all set accordingly
+ * - For every true `has_*` member, the corresponding variable holds a valid
+ * value (e.g. if `has_sid` is true, `sid` contains a valid SID)
+ * - `num_payload_bytes` and `num_payload_words32` are both set to the correct values
+ *
+ * \subsection Result:
+ * - `packet_buff` now points to a valid header that can be sent over the transport
+ * without further modification
+ * - The following members on `if_packet_info` are set:
+ * - `num_header_words32`
+ * - `num_packet_words32`
+ *
* \param packet_buff memory to write the packed vrt header
* \param if_packet_info the if packet info (read/write)
*/
@@ -87,6 +124,34 @@ namespace vrt{
/*!
* Unpack a vrt header to metadata (big endian format).
+ *
+ * \section vrt_unpack_contract Unpacking contract
+ *
+ * \subsection Requirements
+ * - `packet_buff` points to a readable address space with a
+ * CHDR packet, starting at the header. `packet_buff[0]` *must* always
+ * point to a valid first word of the header. This implies that num_packet_words32
+ * must be at least 1.
+ * - `if_packet_info` has the following members set to correct values:
+ * - `num_packet_words32`. This means all values `packet_buff[0]`
+ * through `packet_buff[if_packet_info.num_packet_words32-1]` are
+ * readable words from this packet.
+ * - `link_type`
+ *
+ * \subsection Result
+ * - `if_packet_info` now has the following values set to correct values:
+ * - `packet_type`
+ * - `num_payload_bytes`
+ * - `num_payload_words32`
+ * - `num_header_words32`
+ * - `has_*`
+ * - `sob`, `eob`, `error`, `cid`, `sid` (if applicable)
+ * - `tsf`, `tsi` (if applicable)
+ *
+ * \subsection Exceptions
+ * - If the header is invalid, but the requirements are still met,
+ * will throw a uhd::value_error.
+ *
* \param packet_buff memory to read the packed vrt header
* \param if_packet_info the if packet info (read/write)
*/
@@ -97,6 +162,9 @@ namespace vrt{
/*!
* Pack a vrt header from metadata (little endian format).
+ *
+ * See \ref vrt_pack_contract.
+ *
* \param packet_buff memory to write the packed vrt header
* \param if_packet_info the if packet info (read/write)
*/
@@ -107,6 +175,9 @@ namespace vrt{
/*!
* Unpack a vrt header to metadata (little endian format).
+ *
+ * See \ref vrt_unpack_contract.
+ *
* \param packet_buff memory to read the packed vrt header
* \param if_packet_info the if packet info (read/write)
*/
@@ -124,6 +195,7 @@ namespace vrt{
num_packet_words32(0),
packet_count(0),
sob(false), eob(false),
+ error(false),
has_sid(false), sid(0),
has_cid(false), cid(0),
has_tsi(false), tsi(0),
diff --git a/host/include/uhd/transport/zero_copy.hpp b/host/include/uhd/transport/zero_copy.hpp
index 9ff3042aa..de1b17e1a 100644
--- a/host/include/uhd/transport/zero_copy.hpp
+++ b/host/include/uhd/transport/zero_copy.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2012 Ettus Research LLC
+// Copyright 2010-2012,2015 Ettus Research LLC
//
// 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
diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt
index 8bb1de381..3f34782e2 100644
--- a/host/include/uhd/types/CMakeLists.txt
+++ b/host/include/uhd/types/CMakeLists.txt
@@ -17,6 +17,7 @@
UHD_INSTALL(FILES
+ byte_vector.hpp
clock_config.hpp
device_addr.hpp
dict.ipp
@@ -31,11 +32,27 @@ UHD_INSTALL(FILES
ref_vector.hpp
sensors.hpp
serial.hpp
+ sid.hpp
stream_cmd.hpp
time_spec.hpp
tune_request.hpp
tune_result.hpp
wb_iface.hpp
+ filters.hpp
DESTINATION ${INCLUDE_DIR}/uhd/types
COMPONENT headers
)
+
+IF(ENABLE_C_API)
+ UHD_INSTALL(FILES
+ metadata.h
+ ranges.h
+ sensors.h
+ string_vector.h
+ tune_request.h
+ tune_result.h
+ usrp_info.h
+ DESTINATION ${INCLUDE_DIR}/uhd/types
+ COMPONENT headers
+ )
+ENDIF(ENABLE_C_API)
diff --git a/host/include/uhd/types/byte_vector.hpp b/host/include/uhd/types/byte_vector.hpp
new file mode 100644
index 000000000..b7637fb5d
--- /dev/null
+++ b/host/include/uhd/types/byte_vector.hpp
@@ -0,0 +1,48 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_TYPES_BYTE_VECTOR_HPP
+#define INCLUDED_UHD_TYPES_BYTE_VECTOR_HPP
+
+#include <algorithm>
+#include <string>
+#include <vector>
+
+#include <boost/assign.hpp>
+#include <boost/cstdint.hpp>
+
+#include <uhd/config.hpp>
+
+namespace uhd{
+
+ //! Byte vector used for I2C data passing and EEPROM parsing.
+ typedef std::vector<boost::uint8_t> byte_vector_t;
+
+ template<typename RangeSrc, typename RangeDst> UHD_INLINE
+ void byte_copy(const RangeSrc &src, RangeDst &dst){
+ std::copy(boost::begin(src), boost::end(src), boost::begin(dst));
+ }
+
+ //! Create a string from a byte vector, terminate when invalid ASCII encountered
+ UHD_API std::string bytes_to_string(const byte_vector_t &bytes);
+
+ //! Create a byte vector from a string, end at null terminator or max length
+ UHD_API byte_vector_t string_to_bytes(const std::string &str, size_t max_length);
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_TYPES_BYTE_VECTOR_HPP */
diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp
index 97fa8f09c..90559ff5f 100644
--- a/host/include/uhd/types/dict.hpp
+++ b/host/include/uhd/types/dict.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2011 Ettus Research LLC
+// Copyright 2010-2011,2015 Ettus Research LLC
//
// 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
@@ -117,6 +117,23 @@ namespace uhd{
*/
Val pop(const Key &key);
+ /*! Update this dictionary with values from another.
+ *
+ * Basically, this copies all the key/value pairs from \p new_dict
+ * into this dict. When the key is already present in the current
+ * dict, it either overwrites the current value (if \p fail_on_conflict
+ * is false) or it throws (if \p fail_on_conflict is true *and* the
+ * values differ).
+ *
+ * With the exception of \p fail_on_conflict, this behaves analogously
+ * to Python's dict.update() method.
+ *
+ * \param new_dict The arguments to copy.
+ * \param fail_on_conflict If true, throws.
+ * \throws uhd::value_error
+ */
+ void update(const dict<Key, Val> &new_dict, bool fail_on_conflict=true);
+
private:
typedef std::pair<Key, Val> pair_t;
std::list<pair_t> _map; //private container
diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp
index 5e9cf97ad..5fd4b536e 100644
--- a/host/include/uhd/types/dict.ipp
+++ b/host/include/uhd/types/dict.ipp
@@ -135,6 +135,20 @@ namespace uhd{
throw key_not_found<Key, Val>(key);
}
+ template <typename Key, typename Val>
+ void dict<Key, Val>::update(const dict<Key, Val> &new_dict, bool fail_on_conflict)
+ {
+ BOOST_FOREACH(const Key &key, new_dict.keys()) {
+ if (fail_on_conflict and has_key(key) and get(key) != new_dict[key]) {
+ throw uhd::value_error(str(
+ boost::format("Option merge conflict: %s:%s != %s:%s")
+ % key % get(key) % key % new_dict[key]
+ ));
+ }
+ set(key, new_dict[key]);
+ }
+ }
+
} //namespace uhd
#endif /* INCLUDED_UHD_TYPES_DICT_IPP */
diff --git a/host/include/uhd/types/direction.hpp b/host/include/uhd/types/direction.hpp
index 0f257de44..59ee9b55f 100644
--- a/host/include/uhd/types/direction.hpp
+++ b/host/include/uhd/types/direction.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2015 Ettus Research LLC
+// Copyright 2014-2015 Ettus Research LLC
//
// 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
diff --git a/host/include/uhd/types/filters.hpp b/host/include/uhd/types/filters.hpp
new file mode 100644
index 000000000..976ae233d
--- /dev/null
+++ b/host/include/uhd/types/filters.hpp
@@ -0,0 +1,286 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_TYPES_FILTERS_HPP
+#define INCLUDED_UHD_TYPES_FILTERS_HPP
+
+#include <uhd/config.hpp>
+#include <uhd/utils/log.hpp>
+#include <uhd/utils/msg.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/scoped_array.hpp>
+#include <string>
+#include <vector>
+#include <iostream>
+#include <ostream>
+#include <sstream>
+
+namespace uhd{
+
+ class UHD_API filter_info_base
+ {
+ public:
+ typedef boost::shared_ptr<filter_info_base> sptr;
+ enum filter_type
+ {
+ ANALOG_LOW_PASS,
+ ANALOG_BAND_PASS,
+ DIGITAL_I16,
+ DIGITAL_FIR_I16
+ };
+
+ filter_info_base(
+ filter_type type,
+ bool bypass,
+ size_t position_index
+ ):
+ _type(type), _bypass(bypass),
+ _position_index(position_index)
+ {
+ //NOP
+ }
+
+ inline virtual bool is_bypassed()
+ {
+ return _bypass;
+ }
+
+ inline filter_type get_type()
+ {
+ return _type;
+ }
+
+ virtual ~filter_info_base()
+ {
+ //NOP
+ }
+
+ virtual std::string to_pp_string();
+
+ protected:
+ filter_type _type;
+ bool _bypass;
+ size_t _position_index;
+
+ };
+
+ UHD_API std::ostream& operator<<(std::ostream& os, filter_info_base& f);
+
+ class UHD_API analog_filter_base : public filter_info_base
+ {
+ std::string _analog_type;
+ public:
+ typedef boost::shared_ptr<analog_filter_base> sptr;
+ analog_filter_base(
+ filter_type type,
+ bool bypass,
+ size_t position_index,
+ const std::string& analog_type
+ ):
+ filter_info_base(type, bypass, position_index),
+ _analog_type(analog_type)
+ {
+ //NOP
+ }
+
+ inline const std::string& get_analog_type()
+ {
+ return _analog_type;
+ }
+
+ virtual std::string to_pp_string();
+ };
+
+ class UHD_API analog_filter_lp : public analog_filter_base
+ {
+ double _cutoff;
+ double _rolloff;
+
+ public:
+ typedef boost::shared_ptr<analog_filter_lp> sptr;
+ analog_filter_lp(
+ filter_type type,
+ bool bypass,
+ size_t position_index,
+ const std::string& analog_type,
+ double cutoff,
+ double rolloff
+ ):
+ analog_filter_base(type, bypass, position_index, analog_type),
+ _cutoff(cutoff),
+ _rolloff(rolloff)
+ {
+ //NOP
+ }
+
+ inline double get_cutoff()
+ {
+ return _cutoff;
+ }
+
+ inline double get_rolloff()
+ {
+ return _cutoff;
+ }
+
+ inline void set_cutoff(const double cutoff)
+ {
+ _cutoff = cutoff;
+ }
+
+ virtual std::string to_pp_string();
+ };
+
+ template<typename tap_t>
+ class UHD_API digital_filter_base : public filter_info_base
+ {
+ protected:
+ double _rate;
+ boost::uint32_t _interpolation;
+ boost::uint32_t _decimation;
+ tap_t _tap_full_scale;
+ boost::uint32_t _max_num_taps;
+ std::vector<tap_t> _taps;
+
+ public:
+ typedef boost::shared_ptr<digital_filter_base> sptr;
+ digital_filter_base(
+ filter_type type,
+ bool bypass,
+ size_t position_index,
+ double rate,
+ size_t interpolation,
+ size_t decimation,
+ double tap_full_scale,
+ size_t max_num_taps,
+ const std::vector<tap_t>& taps
+ ):
+ filter_info_base(type, bypass, position_index),
+ _rate(rate),
+ _interpolation(interpolation),
+ _decimation(decimation),
+ _tap_full_scale(tap_full_scale),
+ _max_num_taps(max_num_taps),
+ _taps(taps)
+ {
+ //NOP
+ }
+
+ inline double get_output_rate()
+ {
+ return (_bypass ? _rate : (_rate / _decimation * _interpolation));
+ }
+
+ inline double get_input_rate()
+ {
+ return _rate;
+ }
+
+ inline double get_interpolation()
+ {
+ return _interpolation;
+ }
+
+ inline double get_decimation()
+ {
+ return _decimation;
+ }
+
+ inline double get_tap_full_scale()
+ {
+ return _tap_full_scale;
+ }
+
+ inline std::vector<tap_t>& get_taps()
+ {
+ return _taps;
+ }
+
+ virtual std::string to_pp_string()
+ {
+ std::ostringstream os;
+ os<<filter_info_base::to_pp_string()<<
+ "\t[digital_filter_base]"<<std::endl<<
+ "\tinput rate: "<<_rate<<std::endl<<
+ "\tinterpolation: "<<_interpolation<<std::endl<<
+ "\tdecimation: "<<_decimation<<std::endl<<
+ "\tfull-scale: "<<_tap_full_scale<<std::endl<<
+ "\tmax num taps: "<<_max_num_taps<<std::endl<<
+ "\ttaps: "<<std::endl;
+
+ os<<"\t\t";
+ for(size_t i = 0; i < _taps.size(); i++)
+ {
+ os<<"(tap "<<i<<": "<<_taps[i]<<")";
+ if( ((i%10) == 0) && (i != 0))
+ {
+ os<<std::endl<<"\t\t";
+ }
+ }
+ os<<std::endl;
+ return std::string(os.str());
+ }
+
+ };
+
+ template<typename tap_t>
+ class UHD_API digital_filter_fir : public digital_filter_base<tap_t>
+ {
+ public:
+ typedef boost::shared_ptr<digital_filter_fir<tap_t> > sptr;
+
+ digital_filter_fir(
+ filter_info_base::filter_type type,
+ bool bypass, size_t position_index,
+ double rate,
+ size_t interpolation,
+ size_t decimation,
+ size_t tap_bit_width,
+ size_t max_num_taps,
+ const std::vector<tap_t>& taps
+ ):
+ digital_filter_base<tap_t>(type, bypass, position_index, rate, interpolation, decimation, tap_bit_width, max_num_taps, taps)
+ {
+ //NOP
+ }
+
+ void set_taps(const std::vector<tap_t>& taps)
+ {
+ std::size_t num_taps = taps.size();
+ if(num_taps < this->_max_num_taps){
+ UHD_MSG(warning) << "digital_filter_fir::set_taps not enough coefficients. Appending zeros";
+ std::vector<tap_t> coeffs;
+ for (size_t i = 0; i < this->_max_num_taps; i++)
+ {
+ if(i < num_taps)
+ {
+ coeffs.push_back(taps[i]);
+ } else {
+ coeffs.push_back(0);
+ }
+ }
+ this->_taps = coeffs;
+ } else {
+ this->_taps = taps;
+ }
+ }
+ };
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_TYPES_FILTERS_HPP */
diff --git a/host/include/uhd/types/metadata.h b/host/include/uhd/types/metadata.h
new file mode 100644
index 000000000..0cdbc6a72
--- /dev/null
+++ b/host/include/uhd/types/metadata.h
@@ -0,0 +1,364 @@
+/*
+ * Copyright 2015 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/>.
+ */
+
+#ifndef INCLUDED_UHD_TYPES_METADATA_H
+#define INCLUDED_UHD_TYPES_METADATA_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <time.h>
+
+#ifdef __cplusplus
+#include <uhd/types/metadata.hpp>
+#include <string>
+
+struct uhd_rx_metadata_t {
+ uhd::rx_metadata_t rx_metadata_cpp;
+ std::string last_error;
+};
+
+struct uhd_tx_metadata_t {
+ uhd::tx_metadata_t tx_metadata_cpp;
+ std::string last_error;
+};
+
+struct uhd_async_metadata_t {
+ uhd::async_metadata_t async_metadata_cpp;
+ std::string last_error;
+};
+
+extern "C" {
+#else
+struct uhd_rx_metadata_t;
+struct uhd_tx_metadata_t;
+struct uhd_async_metadata_t;
+#endif
+
+//! RX metadata interface for describing sent IF data.
+/*!
+ * See uhd::rx_metadata_t for details.
+ *
+ * NOTE: Using this handle before calling uhd_rx_metadata_make() will
+ * result in undefined behavior.
+ */
+typedef struct uhd_rx_metadata_t* uhd_rx_metadata_handle;
+
+//! TX metadata interface for describing received IF data.
+/*!
+ * See uhd::tx_metadata_t for details.
+ *
+ * NOTE: Using this handle before calling uhd_tx_metadata_make() will
+ * result in undefined behavior.
+ */
+typedef struct uhd_tx_metadata_t* uhd_tx_metadata_handle;
+
+//! Interface for describing transmit-related events.
+/*!
+ * See uhd::async_metadata_t for details.
+ *
+ * NOTE: Using this handle before calling uhd_async_metadata_make() will
+ * result in undefined behavior.
+ */
+typedef struct uhd_async_metadata_t* uhd_async_metadata_handle;
+
+//! Error condition on a receive call
+/*!
+ * See uhd::rx_metadata_t::error_code_t for more details.
+ */
+typedef enum {
+ //! No error code associated with this metadata
+ UHD_RX_METADATA_ERROR_CODE_NONE = 0x0,
+ //! No packet received, implementation timed out
+ UHD_RX_METADATA_ERROR_CODE_TIMEOUT = 0x1,
+ //! A stream command was issued in the past
+ UHD_RX_METADATA_ERROR_CODE_LATE_COMMAND = 0x2,
+ //! Expected another stream command
+ UHD_RX_METADATA_ERROR_CODE_BROKEN_CHAIN = 0x4,
+ //! Overflow or sequence error
+ UHD_RX_METADATA_ERROR_CODE_OVERFLOW = 0x8,
+ //! Multi-channel alignment failed
+ UHD_RX_METADATA_ERROR_CODE_ALIGNMENT = 0xC,
+ //! The packet could not be parsed
+ UHD_RX_METADATA_ERROR_CODE_BAD_PACKET = 0xF
+} uhd_rx_metadata_error_code_t;
+
+
+//! Create a new RX metadata handle
+UHD_API uhd_error uhd_rx_metadata_make(
+ uhd_rx_metadata_handle* handle
+);
+
+//! Free an RX metadata handle
+/*!
+ * Using a handle after freeing it here will result in a segmentation fault.
+ */
+UHD_API uhd_error uhd_rx_metadata_free(
+ uhd_rx_metadata_handle* handle
+);
+
+//! Has time specification?
+UHD_API uhd_error uhd_rx_metadata_has_time_spec(
+ uhd_rx_metadata_handle h,
+ bool *result_out
+);
+
+//! Time of first sample
+UHD_API uhd_error uhd_rx_metadata_time_spec(
+ uhd_rx_metadata_handle h,
+ time_t *full_secs_out,
+ double *frac_secs_out
+);
+
+//! Fragmentation flag
+UHD_API uhd_error uhd_rx_metadata_more_fragments(
+ uhd_rx_metadata_handle h,
+ bool *result_out
+);
+
+//! Fragmentation offset
+UHD_API uhd_error uhd_rx_metadata_fragment_offset(
+ uhd_rx_metadata_handle h,
+ size_t *fragment_offset_out
+);
+
+//! Start of burst?
+UHD_API uhd_error uhd_rx_metadata_start_of_burst(
+ uhd_rx_metadata_handle h,
+ bool *result_out
+);
+
+//! End of burst?
+UHD_API uhd_error uhd_rx_metadata_end_of_burst(
+ uhd_rx_metadata_handle h,
+ bool *result_out
+);
+
+//! Result out of sequence?
+UHD_API uhd_error uhd_rx_metadata_out_of_sequence(
+ uhd_rx_metadata_handle h,
+ bool *result_out
+);
+
+//! Return a pretty-print representation of this metadata.
+/*!
+ * NOTE: This function will overwrite any string in the given buffer
+ * before inserting the pp_string.
+ *
+ * \param h metadata handle
+ * \param pp_string_out string buffer for pp_string
+ * \param buffer length
+ */
+UHD_API uhd_error uhd_rx_metadata_to_pp_string(
+ uhd_rx_metadata_handle h,
+ char* pp_string_out,
+ size_t strbuffer_len
+);
+
+//! Get the last error state of the RX metadata object.
+UHD_API uhd_error uhd_rx_metadata_error_code(
+ uhd_rx_metadata_handle h,
+ uhd_rx_metadata_error_code_t *error_code_out
+);
+
+//! Get a string representation of the last error state of the RX metadata object.
+/*!
+ * NOTES:
+ * <ul>
+ * <li>This is different from the error that can be retrieved with
+ * uhd_rx_metadata_last_error. See uhd::rx_metadata_t::strerror() for details.</li>
+ * <li>This function will overwrite any string in the given buffer before
+ * inserting the error string.</li>
+ * </ul>
+ *
+ * \param h metadata handle
+ * \param strerror_out string buffer for strerror
+ * \param buffer length
+ */
+UHD_API uhd_error uhd_rx_metadata_strerror(
+ uhd_rx_metadata_handle h,
+ char* strerror_out,
+ size_t strbuffer_len
+);
+
+//! Get the last error logged by the RX metadata object.
+/*!
+ * NOTES:
+ * <ul>
+ * <li>This is different from the error that can be retrieved with
+ * uhd_rx_metadata_strerror(). See <uhd/error.h> for details.</li>
+ * <li>This function will overwrite any string in the given buffer before
+ * inserting the error string.</li>
+ * </ul>
+ *
+ * \param h metadata handle
+ * \param error_out string buffer for error
+ * \param buffer length
+ */
+UHD_API uhd_error uhd_rx_metadata_last_error(
+ uhd_rx_metadata_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+//! Create a new TX metadata handle
+UHD_API uhd_error uhd_tx_metadata_make(
+ uhd_tx_metadata_handle* handle,
+ bool has_time_spec,
+ time_t full_secs,
+ double frac_secs,
+ bool start_of_burst,
+ bool end_of_burst
+);
+
+
+//! Free an TX metadata handle
+/*!
+ * Using a handle after freeing it here will result in a segmentation fault.
+ */
+UHD_API uhd_error uhd_tx_metadata_free(
+ uhd_tx_metadata_handle* handle
+);
+
+//! Has time specification?
+UHD_API uhd_error uhd_tx_metadata_has_time_spec(
+ uhd_tx_metadata_handle h,
+ bool *result_out
+);
+
+//! Get time specification
+UHD_API uhd_error uhd_tx_metadata_time_spec(
+ uhd_tx_metadata_handle h,
+ time_t *full_secs_out,
+ double *frac_secs_out
+);
+
+//! Start of burst?
+UHD_API uhd_error uhd_tx_metadata_start_of_burst(
+ uhd_tx_metadata_handle h,
+ bool *result_out
+);
+
+//! End of burst?
+UHD_API uhd_error uhd_tx_metadata_end_of_burst(
+ uhd_tx_metadata_handle h,
+ bool *result_out
+);
+
+//! Get the last error logged by the TX metadata object.
+/*!
+ * NOTE: This function will overwrite any string in the given buffer before
+ * inserting the error string.
+ *
+ * \param h metadata handle
+ * \param error_out string buffer for error
+ * \param buffer length
+ */
+UHD_API uhd_error uhd_tx_metadata_last_error(
+ uhd_tx_metadata_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+//! The type of event for a receive async message call.
+/*!
+ * See uhd::async_metadata_t::event_code_t for more details.
+ */
+typedef enum {
+ //! A burst was successfully transmitted.
+ UHD_ASYNC_METADATA_EVENT_CODE_BURST_ACK = 0x1,
+ //! An internal send buffer has emptied.
+ UHD_ASYNC_METADATA_EVENT_CODE_UNDERFLOW = 0x2,
+ //! Packet loss error between host and device.
+ UHD_ASYNC_METADATA_EVENT_CODE_SEQ_ERROR = 0x4,
+ //! Packet had time that was late.
+ UHD_ASYNC_METADATA_EVENT_CODE_TIME_ERROR = 0x8,
+ //! Underflow occurred inside a packet.
+ UHD_ASYNC_METADATA_EVENT_CODE_UNDERFLOW_IN_PACKET = 0x10,
+ //! Packet loss within a burst.
+ UHD_ASYNC_METADATA_EVENT_CODE_SEQ_ERROR_IN_BURST = 0x20,
+ //! Some kind of custom user payload.
+ UHD_ASYNC_METADATA_EVENT_CODE_USER_PAYLOAD = 0x40
+} uhd_async_metadata_event_code_t;
+
+//! Create a new async metadata handle
+UHD_API uhd_error uhd_async_metadata_make(
+ uhd_async_metadata_handle* handle
+);
+
+//! Free an async metadata handle
+/*!
+ * Using a handle after freeing it will result in a segmentation fault.
+ */
+UHD_API uhd_error uhd_async_metadata_free(
+ uhd_async_metadata_handle* handle
+);
+
+//! Channel number in a MIMO configuration
+UHD_API uhd_error uhd_async_metadata_channel(
+ uhd_async_metadata_handle h,
+ size_t *channel_out
+);
+
+//! Has time specification?
+UHD_API uhd_error uhd_async_metadata_has_time_spec(
+ uhd_async_metadata_handle h,
+ bool *result_out
+);
+
+//! Get time specification
+UHD_API uhd_error uhd_async_metadata_time_spec(
+ uhd_async_metadata_handle h,
+ time_t *full_secs_out,
+ double *frac_secs_out
+);
+
+//! Get last event code
+UHD_API uhd_error uhd_async_metadata_event_code(
+ uhd_async_metadata_handle h,
+ uhd_async_metadata_event_code_t *event_code_out
+);
+
+//! Get payload from custom FPGA fabric
+UHD_API uhd_error uhd_async_metadata_user_payload(
+ uhd_async_metadata_handle h,
+ uint32_t user_payload_out[4]
+);
+
+//! Get the last error logged by the async metadata object.
+/*!
+ * NOTE: This function will overwrite any string in the given buffer before
+ * inserting the error string.
+ *
+ * \param h metadata handle
+ * \param error_out string buffer for error
+ * \param buffer length
+ */
+UHD_API uhd_error uhd_async_metadata_last_error(
+ uhd_async_metadata_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_TYPES_METADATA_H */
diff --git a/host/include/uhd/types/ranges.h b/host/include/uhd/types/ranges.h
new file mode 100644
index 000000000..ca80c9141
--- /dev/null
+++ b/host/include/uhd/types/ranges.h
@@ -0,0 +1,154 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_TYPES_RANGES_H
+#define INCLUDED_UHD_TYPES_RANGES_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+#include <stdbool.h>
+#include <stdlib.h>
+
+//! Range of floating-point values
+typedef struct {
+ //! First value
+ double start;
+ //! Last value
+ double stop;
+ //! Granularity
+ double step;
+} uhd_range_t;
+
+#ifdef __cplusplus
+#include <uhd/types/ranges.hpp>
+#include <string>
+
+struct uhd_meta_range_t {
+ uhd::meta_range_t meta_range_cpp;
+ std::string last_error;
+};
+
+extern "C" {
+#else
+struct uhd_meta_range_t;
+#endif
+
+//! C-level interface for dealing with a list of ranges
+/*!
+ * See uhd::meta_range_t for more details.
+ */
+typedef struct uhd_meta_range_t* uhd_meta_range_handle;
+
+//! Get a string representation of the given range
+UHD_API uhd_error uhd_range_to_pp_string(
+ const uhd_range_t *range,
+ char* pp_string_out,
+ size_t strbuffer_len
+);
+
+//! Create a meta range handle
+/*!
+ * NOTE: Using a uhd_meta_range_handle before passing it into this function will
+ * result in undefined behavior.
+ */
+UHD_API uhd_error uhd_meta_range_make(
+ uhd_meta_range_handle* h
+);
+
+//! Destroy a meta range handle
+/*!
+ * NOTE: Using a uhd_meta_range_handle after passing it into this function will
+ * result in a segmentation fault.
+ */
+UHD_API uhd_error uhd_meta_range_free(
+ uhd_meta_range_handle* h
+);
+
+//! Get the overall start value for the given meta range
+UHD_API uhd_error uhd_meta_range_start(
+ uhd_meta_range_handle h,
+ double *start_out
+);
+
+//! Get the overall stop value for the given meta range
+UHD_API uhd_error uhd_meta_range_stop(
+ uhd_meta_range_handle h,
+ double *stop_out
+);
+
+//! Get the overall step value for the given meta range
+UHD_API uhd_error uhd_meta_range_step(
+ uhd_meta_range_handle h,
+ double *step_out
+);
+
+//! Clip the given value to a possible value in the given range
+UHD_API uhd_error uhd_meta_range_clip(
+ uhd_meta_range_handle h,
+ double value,
+ bool clip_step,
+ double *result_out
+);
+
+//! Get the number of ranges in the given meta range
+UHD_API uhd_error uhd_meta_range_size(
+ uhd_meta_range_handle h,
+ size_t *size_out
+);
+
+//! Add a range to the given meta range
+UHD_API uhd_error uhd_meta_range_push_back(
+ uhd_meta_range_handle h,
+ const uhd_range_t *range
+);
+
+//! Get the range at the given index
+UHD_API uhd_error uhd_meta_range_at(
+ uhd_meta_range_handle h,
+ size_t num,
+ uhd_range_t *range_out
+);
+
+//! Get a string representation of the given meta range
+UHD_API uhd_error uhd_meta_range_to_pp_string(
+ uhd_meta_range_handle h,
+ char* pp_string_out,
+ size_t strbuffer_len
+);
+
+//! Get the last error recorded by the underlying meta range
+UHD_API uhd_error uhd_meta_range_last_error(
+ uhd_meta_range_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+#ifdef __cplusplus
+}
+
+UHD_API uhd::range_t uhd_range_c_to_cpp(
+ const uhd_range_t *range_c
+);
+
+UHD_API void uhd_range_cpp_to_c(
+ const uhd::range_t &range_cpp,
+ uhd_range_t *range_c
+);
+#endif
+
+#endif /* INCLUDED_UHD_TYPES_RANGES_H */
diff --git a/host/include/uhd/types/sensors.h b/host/include/uhd/types/sensors.h
new file mode 100644
index 000000000..c0037c9f6
--- /dev/null
+++ b/host/include/uhd/types/sensors.h
@@ -0,0 +1,231 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_TYPES_SENSORS_H
+#define INCLUDED_UHD_TYPES_SENSORS_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+#ifdef __cplusplus
+#include <uhd/types/sensors.hpp>
+#include <string>
+
+struct uhd_sensor_value_t {
+ // No default constructor, so we need a pointer
+ uhd::sensor_value_t* sensor_value_cpp;
+ std::string last_error;
+};
+extern "C" {
+#else
+struct uhd_sensor_value_t;
+#endif
+
+//! C-level interface for a UHD sensor
+/*!
+ * See uhd::sensor_value_t for more details.
+ *
+ * NOTE: Using a handle before calling a make function will result in undefined behavior.
+ */
+typedef struct uhd_sensor_value_t* uhd_sensor_value_handle;
+
+//! Sensor value types
+typedef enum {
+ UHD_SENSOR_VALUE_BOOLEAN = 98,
+ UHD_SENSOR_VALUE_INTEGER = 105,
+ UHD_SENSOR_VALUE_REALNUM = 114,
+ UHD_SENSOR_VALUE_STRING = 115
+} uhd_sensor_value_data_type_t;
+
+//! Make a UHD sensor from a boolean.
+/*!
+ * \param h the sensor handle in which to place sensor
+ * \param name sensor name
+ * \param value sensor value
+ * \param utrue string representing "true"
+ * \param ufalse string representing "false"
+ * \returns UHD error code
+ */
+UHD_API uhd_error uhd_sensor_value_make_from_bool(
+ uhd_sensor_value_handle* h,
+ const char* name,
+ bool value,
+ const char* utrue,
+ const char* ufalse
+);
+
+//! Make a UHD sensor from an integer.
+/*!
+ * \param h the sensor value in which to place sensor
+ * \param name sensor name
+ * \param value sensor value
+ * \param unit sensor unit
+ * \param formatter printf-style format string for value string
+ * \returns UHD error code
+ */
+UHD_API uhd_error uhd_sensor_value_make_from_int(
+ uhd_sensor_value_handle* h,
+ const char* name,
+ int value,
+ const char* unit,
+ const char* formatter
+);
+
+//! Make a UHD sensor from a real number.
+/*!
+ * \param h the sensor value in which to place sensor
+ * \param name sensor name
+ * \param value sensor value
+ * \param unit sensor unit
+ * \param formatter printf-style format string for value string
+ * \returns UHD error code
+ */
+UHD_API uhd_error uhd_sensor_value_make_from_realnum(
+ uhd_sensor_value_handle* h,
+ const char* name,
+ double value,
+ const char* unit,
+ const char* formatter
+);
+
+//! Make a UHD sensor from a string.
+/*!
+ * \param h the sensor value in which to place sensor
+ * \param name sensor name
+ * \param value sensor value
+ * \param unit sensor unit
+ * \returns UHD error code
+ */
+UHD_API uhd_error uhd_sensor_value_make_from_string(
+ uhd_sensor_value_handle* h,
+ const char* name,
+ const char* value,
+ const char* unit
+);
+
+//! Free the given sensor handle.
+/*!
+ * Attempting to use the handle after calling this handle will
+ * result in a segmentation fault.
+ */
+UHD_API uhd_error uhd_sensor_value_free(
+ uhd_sensor_value_handle* h
+);
+
+//! Get the sensor's value as a boolean.
+UHD_API uhd_error uhd_sensor_value_to_bool(
+ uhd_sensor_value_handle h,
+ bool *value_out
+);
+
+//! Get the sensor's value as an integer.
+UHD_API uhd_error uhd_sensor_value_to_int(
+ uhd_sensor_value_handle h,
+ int *value_out
+);
+
+//! Get the sensor's value as a real number.
+UHD_API uhd_error uhd_sensor_value_to_realnum(
+ uhd_sensor_value_handle h,
+ double *value_out
+);
+
+//! Get the sensor's name.
+/*!
+ * NOTE: This function will overwrite any string in the given
+ * buffer before inserting the sensor name.
+ *
+ * \param h sensor handle
+ * \param name_out string buffer in which to place name
+ * \param strbuffer_len buffer length
+ */
+UHD_API uhd_error uhd_sensor_value_name(
+ uhd_sensor_value_handle h,
+ char* name_out,
+ size_t strbuffer_len
+);
+
+//! Get the sensor's value.
+/*!
+ * NOTE: This function will overwrite any string in the given
+ * buffer before inserting the sensor value.
+ *
+ * \param h sensor handle
+ * \param value_out string buffer in which to place value
+ * \param strbuffer_len buffer length
+ */
+UHD_API uhd_error uhd_sensor_value_value(
+ uhd_sensor_value_handle h,
+ char* value_out,
+ size_t strbuffer_len
+);
+
+//! Get the sensor's unit.
+/*!
+ * NOTE: This function will overwrite any string in the given
+ * buffer before inserting the sensor unit.
+ *
+ * \param h sensor handle
+ * \param unit_out string buffer in which to place unit
+ * \param strbuffer_len buffer length
+ */
+UHD_API uhd_error uhd_sensor_value_unit(
+ uhd_sensor_value_handle h,
+ char* unit_out,
+ size_t strbuffer_len
+);
+
+UHD_API uhd_error uhd_sensor_value_data_type(
+ uhd_sensor_value_handle h,
+ uhd_sensor_value_data_type_t *data_type_out
+);
+
+//! Get a pretty-print representation of the given sensor.
+/*!
+ * NOTE: This function will overwrite any string in the given
+ * buffer before inserting the string.
+ *
+ * \param h sensor handle
+ * \param pp_string_out string buffer in which to place pp_string
+ * \param strbuffer_len buffer length
+ */
+UHD_API uhd_error uhd_sensor_value_to_pp_string(
+ uhd_sensor_value_handle h,
+ char* pp_string_out,
+ size_t strbuffer_len
+);
+
+//! Get the last error logged by the sensor handle.
+/*!
+ * NOTE: This function will overwrite any string in the given
+ * buffer before inserting the error string.
+ *
+ * \param h sensor handle
+ * \param error_out string buffer in which to place error
+ * \param strbuffer_len buffer length
+ */
+UHD_API uhd_error uhd_sensor_value_last_error(
+ uhd_sensor_value_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_TYPES_SENSORS_H */
diff --git a/host/include/uhd/types/sid.hpp b/host/include/uhd/types/sid.hpp
new file mode 100644
index 000000000..95034c7a5
--- /dev/null
+++ b/host/include/uhd/types/sid.hpp
@@ -0,0 +1,238 @@
+//
+// Copyright 2014 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_TYPES_SID_HPP
+#define INCLUDED_UHD_TYPES_SID_HPP
+
+#include <uhd/config.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/shared_ptr.hpp>
+#include <iostream>
+
+namespace uhd {
+ /*!
+ * \brief Represents a stream ID (SID).
+ *
+ * A stream ID (SID) is an identifier for data.
+ * It is a 32-Bit value which consistst of 16 Bits
+ * for the source address and 16 Bits for the destination
+ * address.
+ * Every address is split into two parts: The _address_, which
+ * identifies the device used, and the _endpoint_, which identifies
+ * a specific object inside the given device (e.g., a block).
+ * *Note:* In the case where there are several crossbars on a single
+ * device, each crossbar gets its own address.
+ * Both address and endpoint are 8 bits in length. If a 16-bit address
+ * is required, we use the combination of the 8-bit address and the 8-bit
+ * endpoint.
+ *
+ * \section sid_str_repr String Representation
+ *
+ * The string representation of a SID is of the form
+ *
+ * 2.3>0.6
+ *
+ * The '>' symbol shows the direction, so in this case,
+ * data is flowing from address 2.3 to 0.6.
+ *
+ * As a convention, ':' is used instead of '.' when giving the
+ * SID in hexadecimal numbers, and two characters are used for each
+ * address part. As an example, the following two SIDs are identical:
+ *
+ * 2.3>0.16 (decimal)
+ * 02:03>00:10 (hexadecimal)
+ *
+ * The format is:
+ * SRC_ADDRESS.SRC_ENDPOINT>DST_ADDRESS.DST_ENDPOINT
+ *
+ *
+ * \section sid_block_ports Block Ports
+ *
+ * In the special case where a block on a crossbar is addressed, the
+ * endpoint is further split up into two parts of four bits each: The
+ * first four bits specify the port number on the crossbar, whereas the
+ * lower four bits represent the *block port*. As an example, consider
+ * the following SID, given in hexadecimal:
+ *
+ * 00:10>02:A1
+ *
+ * In this example, assume data is flowing from the host computer to an
+ * X300. The crossbar address is 02. The endpoint is A1, which means we
+ * are accessing a block on crossbar port A (the tenth port), and are addressing
+ * block port 1.
+ *
+ */
+ class UHD_API sid_t
+ {
+ public:
+ //! Create an unset SID
+ sid_t();
+ //! Create a sid_t object from a 32-Bit SID value
+ sid_t(boost::uint32_t sid);
+ //! Create a sid_t object from its four components
+ sid_t(boost::uint8_t src_addr, boost::uint8_t src_ep, boost::uint8_t dst_addr, boost::uint8_t dst_ep);
+ //! Convert a string representation of a SID into its numerical representation
+ sid_t(const std::string &);
+
+ //! Return a decimal string representation of the SID.
+ std::string to_pp_string() const;
+ //! Return a hexadecimal string representation of the SID.
+ std::string to_pp_string_hex() const;
+
+ //! Returns true if this actually holds a valid SID
+ bool is_set() const { return _set; };
+
+ // Getters
+ //
+ //! Alias for get_sid()
+ UHD_INLINE boost::uint32_t get() const { return get_sid(); };
+ //! Returns a 32-Bit representation of the SID if set, or zero otherwise.
+ UHD_INLINE boost::uint32_t get_sid() const { return _set ? _sid : 0; };
+ //! Return the 16-bit source address of this SID
+ UHD_INLINE boost::uint32_t get_src() const {
+ return (_sid >> 16) & 0xFFFF;
+ }
+ //! Return the 16-bit destination address of this SID
+ UHD_INLINE boost::uint32_t get_dst() const {
+ return _sid & 0xFFFF;
+ }
+ //! Return 8-bit address of the source
+ UHD_INLINE boost::uint32_t get_src_addr() const {
+ return (get_src() >> 8) & 0xFF;
+ }
+ //! Return endpoint of the source
+ UHD_INLINE boost::uint32_t get_src_endpoint() const {
+ return get_src() & 0xFF;
+ }
+ //! Return crossbar port of the source
+ UHD_INLINE boost::uint32_t get_src_xbarport() const {
+ return (get_src_endpoint() >> 4) & 0xF;
+ }
+ //! Return block port of the source
+ UHD_INLINE boost::uint32_t get_src_blockport() const {
+ return (get_src_endpoint()) & 0xF;
+ }
+ //! Return 8-bit address of the destination
+ UHD_INLINE boost::uint32_t get_dst_addr() const {
+ return (get_dst() >> 8) & 0xFF;
+ }
+ //! Return endpoint of the destination
+ UHD_INLINE boost::uint32_t get_dst_endpoint() const {
+ return get_dst() & 0xFF;
+ }
+ //! Return crossbar port of the source
+ UHD_INLINE boost::uint32_t get_dst_xbarport() const {
+ return (get_dst_endpoint() >> 4) & 0xF;
+ }
+ //! Return block port of the source
+ UHD_INLINE boost::uint32_t get_dst_blockport() const {
+ return (get_dst_endpoint()) & 0xF;
+ }
+
+ // Setters
+
+ //! Alias for set_sid()
+ void set(boost::uint32_t new_sid) { set_sid(new_sid); };
+ //! Convert a string representation of a SID into a numerical one
+ // Throws uhd::value_error if the string is not a valid SID
+ // representation.
+ void set_from_str(const std::string &);
+ void set_sid(boost::uint32_t new_sid);
+ //! Set the source address of this SID
+ // (the first 16 Bits)
+ void set_src(boost::uint32_t new_addr);
+ //! Set the destination address of this SID
+ // (the last 16 Bits)
+ void set_dst(boost::uint32_t new_addr);
+ void set_src_addr(boost::uint32_t new_addr);
+ void set_src_endpoint(boost::uint32_t new_addr);
+ void set_dst_addr(boost::uint32_t new_addr);
+ void set_dst_endpoint(boost::uint32_t new_addr);
+ void set_dst_xbarport(boost::uint32_t new_xbarport);
+ void set_dst_blockport(boost::uint32_t new_blockport);
+
+ // Manipulators
+
+ //! Swaps dst and src address and returns the new SID.
+ sid_t reversed();
+
+ //! Swaps dst and src in-place.
+ void reverse();
+
+ // Overloaded operators
+
+ sid_t operator = (boost::uint32_t new_sid) {
+ set_sid(new_sid);
+ return *this;
+ }
+
+ sid_t operator = (sid_t &sid) {
+ set_sid(sid.get_sid());
+ return *this;
+ }
+
+ sid_t operator = (const std::string &sid_str) {
+ set_from_str(sid_str);
+ return *this;
+ }
+
+ bool operator == (const sid_t &sid) const {
+ return (not _set and not sid.is_set()) or (_sid == sid.get_sid());
+ }
+
+ bool operator == (boost::uint32_t sid) const {
+ return _set and _sid == sid;
+ }
+
+ bool operator == (const std::string &sid_str) const {
+ sid_t rhs(sid_str);
+ return *this == rhs;
+ }
+
+ // overloaded type casts are tricky, but for now we'll need them
+ // for backward compatibility. consider them deprecated.
+
+ //! If the SID is not set, always returns zero.
+ // Use is_set() to check if the return value is valid.
+ operator boost::uint32_t() const {
+ return get();
+ }
+
+ operator bool() const {
+ return _set;
+ }
+
+ private:
+ boost::uint32_t _sid;
+ bool _set;
+ };
+
+ //! Stream output operator. Honors std::ios::hex.
+ UHD_INLINE std::ostream& operator<< (std::ostream& out, const sid_t &sid) {
+ std::ios_base::fmtflags ff = out.flags();
+ if (ff & std::ios::hex) {
+ out << sid.to_pp_string_hex();
+ } else {
+ out << sid.to_pp_string();
+ }
+ return out;
+ }
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_TYPES_SID_HPP */
+// vim: sw=4 et:
diff --git a/host/include/uhd/types/stream_cmd.hpp b/host/include/uhd/types/stream_cmd.hpp
index 3c34c9656..c24296bd6 100644
--- a/host/include/uhd/types/stream_cmd.hpp
+++ b/host/include/uhd/types/stream_cmd.hpp
@@ -1,19 +1,19 @@
-//
-// Copyright 2010-2012 Ettus Research LLC
-//
-// 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/>.
-//
+/*
+ * Copyright 2010-2012,2015 Ettus Research LLC
+ *
+ * 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/>.
+ */
#ifndef INCLUDED_UHD_TYPES_STREAM_CMD_HPP
#define INCLUDED_UHD_TYPES_STREAM_CMD_HPP
@@ -59,6 +59,6 @@ namespace uhd{
stream_cmd_t(const stream_mode_t &stream_mode);
};
-} //namespace uhd
+} /* namespace uhd */
#endif /* INCLUDED_UHD_TYPES_STREAM_CMD_HPP */
diff --git a/host/include/uhd/types/string_vector.h b/host/include/uhd/types/string_vector.h
new file mode 100644
index 000000000..685b05f3f
--- /dev/null
+++ b/host/include/uhd/types/string_vector.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2015 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/>.
+ */
+
+#ifndef INCLUDED_UHD_TYPES_STRING_VECTOR_H
+#define INCLUDED_UHD_TYPES_STRING_VECTOR_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+#include <stdlib.h>
+
+#ifdef __cplusplus
+#include <string>
+#include <vector>
+
+struct uhd_string_vector_t {
+ std::vector<std::string> string_vector_cpp;
+ std::string last_error;
+};
+
+extern "C" {
+#else
+//! C-level read-only interface for interacting with a string vector
+struct uhd_string_vector_t;
+#endif
+
+typedef struct uhd_string_vector_t uhd_string_vector_t;
+
+typedef uhd_string_vector_t* uhd_string_vector_handle;
+
+//! Instantiate a string_vector handle.
+UHD_API uhd_error uhd_string_vector_make(
+ uhd_string_vector_handle *h
+);
+
+//! Safely destroy a string_vector handle.
+UHD_API uhd_error uhd_string_vector_free(
+ uhd_string_vector_handle *h
+);
+
+//! Add a string to the list
+UHD_API uhd_error uhd_string_vector_push_back(
+ uhd_string_vector_handle *h,
+ const char* value
+);
+
+//! Get the string at the given index
+UHD_API uhd_error uhd_string_vector_at(
+ uhd_string_vector_handle h,
+ size_t index,
+ char* value_out,
+ size_t strbuffer_len
+);
+
+//! Get the number of strings in this list
+UHD_API uhd_error uhd_string_vector_size(
+ uhd_string_vector_handle h,
+ size_t *size_out
+);
+
+//! Get the last error reported by the underlying object
+UHD_API uhd_error uhd_string_vector_last_error(
+ uhd_string_vector_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_TYPES_STRING_VECTOR_H */
diff --git a/host/include/uhd/types/tune_request.h b/host/include/uhd/types/tune_request.h
new file mode 100644
index 000000000..046350643
--- /dev/null
+++ b/host/include/uhd/types/tune_request.h
@@ -0,0 +1,61 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_TYPES_TUNE_REQUEST_H
+#define INCLUDED_UHD_TYPES_TUNE_REQUEST_H
+
+#include <uhd/config.h>
+
+#include <stdlib.h>
+
+//! Policy options for tunable elements in the RF chain.
+typedef enum {
+ //! Do not set this argument, use current setting.
+ UHD_TUNE_REQUEST_POLICY_NONE = 78,
+ //! Automatically determine the argument's value.
+ UHD_TUNE_REQUEST_POLICY_AUTO = 65,
+ //! Use the argument's value for the setting.
+ UHD_TUNE_REQUEST_POLICY_MANUAL = 77
+} uhd_tune_request_policy_t;
+
+//! Instructs implementation how to tune the RF chain
+/*!
+ * See uhd::tune_request_t for more details.
+ */
+typedef struct {
+ //! Target frequency for RF chain in Hz
+ double target_freq;
+ //! RF frequency policy
+ uhd_tune_request_policy_t rf_freq_policy;
+ //! RF frequency in Hz
+ double rf_freq;
+ //! DSP frequency policy
+ uhd_tune_request_policy_t dsp_freq_policy;
+ //! DSP frequency in Hz
+ double dsp_freq;
+ //! Key-value pairs delimited by commas
+ char* args;
+} uhd_tune_request_t;
+
+#ifdef __cplusplus
+#include <uhd/types/tune_request.hpp>
+
+UHD_API uhd::tune_request_t uhd_tune_request_c_to_cpp(uhd_tune_request_t *tune_request_c);
+
+#endif
+
+#endif /* INCLUDED_UHD_TYPES_TUNE_REQUEST_H */
diff --git a/host/include/uhd/types/tune_result.h b/host/include/uhd/types/tune_result.h
new file mode 100644
index 000000000..e0d00cd2e
--- /dev/null
+++ b/host/include/uhd/types/tune_result.h
@@ -0,0 +1,60 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_TYPES_TUNE_RESULT_H
+#define INCLUDED_UHD_TYPES_TUNE_RESULT_H
+
+#include <uhd/config.h>
+
+#include <stdlib.h>
+
+//! Stores RF and DSP tuned frequencies.
+/*!
+ * See uhd::tune_result_t for more details.
+ */
+typedef struct {
+ //! Target RF frequency, clipped to be within system range
+ double clipped_rf_freq;
+ //! Target RF frequency, including RF FE offset
+ double target_rf_freq;
+ //! Frequency to which RF LO is actually tuned
+ double actual_rf_freq;
+ //! Frequency the CORDIC must adjust the RF
+ double target_dsp_freq;
+ //! Frequency to which the CORDIC in the DSP actually tuned
+ double actual_dsp_freq;
+} uhd_tune_result_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//! Create a pretty print representation of this tune result.
+UHD_API void uhd_tune_result_to_pp_string(uhd_tune_result_t *tune_result,
+ char* pp_string_out, size_t strbuffer_len);
+
+#ifdef __cplusplus
+}
+#include <uhd/types/tune_result.hpp>
+
+UHD_API uhd::tune_result_t uhd_tune_result_c_to_cpp(uhd_tune_result_t *tune_result_c);
+
+UHD_API void uhd_tune_result_cpp_to_c(const uhd::tune_result_t &tune_result_cpp,
+ uhd_tune_result_t *tune_result_c);
+#endif
+
+#endif /* INCLUDED_UHD_TYPES_TUNE_RESULT_H */
diff --git a/host/include/uhd/types/usrp_info.h b/host/include/uhd/types/usrp_info.h
new file mode 100644
index 000000000..c118963da
--- /dev/null
+++ b/host/include/uhd/types/usrp_info.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2015 Ettus Research LLC
+ *
+ * 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/>.
+ */
+
+#ifndef INCLUDED_UHD_TYPES_USRP_INFO_H
+#define INCLUDED_UHD_TYPES_USRP_INFO_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+//! USRP RX info
+/*!
+ * This struct is populated by uhd_usrp_get_rx_info().
+ */
+typedef struct {
+ //! Motherboard ID
+ char* mboard_id;
+ //! Motherboard name
+ char* mboard_name;
+ //! Motherboard serial
+ char* mboard_serial;
+ //! RX daughterboard ID
+ char* rx_id;
+ //! RX subdev name
+ char* rx_subdev_name;
+ //! RX subdev spec
+ char* rx_subdev_spec;
+ //! RX daughterboard serial
+ char* rx_serial;
+ //! RX daughterboard antenna
+ char* rx_antenna;
+} uhd_usrp_rx_info_t;
+
+//! USRP TX info
+/*!
+ * This struct is populated by uhd_usrp_get_tx_info().
+ */
+typedef struct {
+ //! Motherboard ID
+ char* mboard_id;
+ //! Motherboard name
+ char* mboard_name;
+ //! Motherboard serial
+ char* mboard_serial;
+ //! TX daughterboard ID
+ char* tx_id;
+ //! TX subdev name
+ char* tx_subdev_name;
+ //! TX subdev spec
+ char* tx_subdev_spec;
+ //! TX daughterboard serial
+ char* tx_serial;
+ //! TX daughterboard antenna
+ char* tx_antenna;
+} uhd_usrp_tx_info_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//! Clean up a uhd_usrp_rx_info_t populated by uhd_usrp_get_rx_info().
+/*!
+ * NOTE: If this function is passed a uhd_usrp_rx_info_t that has not
+ * been populated by uhd_usrp_get_rx_info(), it will produce a double-free
+ * error.
+ */
+UHD_API uhd_error uhd_usrp_rx_info_free(uhd_usrp_rx_info_t *rx_info);
+
+//! Clean up a uhd_usrp_tx_info_t populated by uhd_usrp_get_tx_info().
+/*!
+ * NOTE: If this function is passed a uhd_usrp_tx_info_t that has not
+ * been populated by uhd_usrp_get_tx_info(), it will produce a double-free
+ * error.
+ */
+UHD_API uhd_error uhd_usrp_tx_info_free(uhd_usrp_tx_info_t *tx_info);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_TYPES_USRP_INFO_H */
diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt
index d30a2900a..e974f808d 100644
--- a/host/include/uhd/usrp/CMakeLists.txt
+++ b/host/include/uhd/usrp/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2010-2011 Ettus Research LLC
+# Copyright 2010-2011,2015 Ettus Research LLC
#
# 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
@@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
UHD_INSTALL(FILES
#### dboard headers ###
@@ -36,3 +35,14 @@ UHD_INSTALL(FILES
DESTINATION ${INCLUDE_DIR}/uhd/usrp
COMPONENT headers
)
+
+IF(ENABLE_C_API)
+ UHD_INSTALL(FILES
+ dboard_eeprom.h
+ mboard_eeprom.h
+ subdev_spec.h
+ usrp.h
+ DESTINATION ${INCLUDE_DIR}/uhd/usrp
+ COMPONENT headers
+ )
+ENDIF(ENABLE_C_API)
diff --git a/host/include/uhd/usrp/dboard_eeprom.h b/host/include/uhd/usrp/dboard_eeprom.h
new file mode 100644
index 000000000..6980de0ce
--- /dev/null
+++ b/host/include/uhd/usrp/dboard_eeprom.h
@@ -0,0 +1,110 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_DBOARD_EEPROM_H
+#define INCLUDED_UHD_USRP_DBOARD_EEPROM_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+#ifdef __cplusplus
+#include <uhd/usrp/dboard_eeprom.hpp>
+#include <string>
+
+struct uhd_dboard_eeprom_t {
+ uhd::usrp::dboard_eeprom_t dboard_eeprom_cpp;
+ std::string last_error;
+};
+
+extern "C" {
+#else
+struct uhd_dboard_eeprom_t;
+#endif
+
+//! A C-level interface for interacting with a daughterboard EEPROM
+/*!
+ * See uhd::usrp::dboard_eeprom_t for more details.
+ *
+ * NOTE: Using a handle before passing it into uhd_dboard_eeprom_make() will
+ * result in undefined behavior.
+ */
+typedef struct uhd_dboard_eeprom_t* uhd_dboard_eeprom_handle;
+
+//! Create handle for a USRP daughterboard EEPROM
+UHD_API uhd_error uhd_dboard_eeprom_make(
+ uhd_dboard_eeprom_handle* h
+);
+
+//! Safely destroy the given handle
+/*!
+ * NOTE: Using a handle after passing it into this function will result in
+ * a segmentation fault.
+ */
+UHD_API uhd_error uhd_dboard_eeprom_free(
+ uhd_dboard_eeprom_handle* h
+);
+
+//! Get the ID associated with the given daughterboard as a string hex representation
+UHD_API uhd_error uhd_dboard_eeprom_get_id(
+ uhd_dboard_eeprom_handle h,
+ char* id_out,
+ size_t strbuffer_len
+);
+
+//! Set the daughterboard ID using a string hex representation
+UHD_API uhd_error uhd_dboard_eeprom_set_id(
+ uhd_dboard_eeprom_handle h,
+ const char* id
+);
+
+//! Get the daughterboard's serial
+UHD_API uhd_error uhd_dboard_eeprom_get_serial(
+ uhd_dboard_eeprom_handle h,
+ char* serial_out,
+ size_t strbuffer_len
+);
+
+//! Set the daughterboard's serial
+UHD_API uhd_error uhd_dboard_eeprom_set_serial(
+ uhd_dboard_eeprom_handle h,
+ const char* serial
+);
+
+//! Get the daughterboard's revision (not always present)
+UHD_API uhd_error uhd_dboard_eeprom_get_revision(
+ uhd_dboard_eeprom_handle h,
+ int* revision_out
+);
+
+//! Set the daughterboard's revision
+UHD_API uhd_error uhd_dboard_eeprom_set_revision(
+ uhd_dboard_eeprom_handle h,
+ int revision
+);
+
+//! Get the last error reported by the handle
+UHD_API uhd_error uhd_dboard_eeprom_last_error(
+ uhd_dboard_eeprom_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_USRP_DBOARD_EEPROM_H */
diff --git a/host/include/uhd/usrp/mboard_eeprom.h b/host/include/uhd/usrp/mboard_eeprom.h
new file mode 100644
index 000000000..b4474a26d
--- /dev/null
+++ b/host/include/uhd/usrp/mboard_eeprom.h
@@ -0,0 +1,87 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_MBOARD_EEPROM_H
+#define INCLUDED_UHD_USRP_MBOARD_EEPROM_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+#ifdef __cplusplus
+#include <uhd/usrp/mboard_eeprom.hpp>
+#include <string>
+
+struct uhd_mboard_eeprom_t {
+ uhd::usrp::mboard_eeprom_t mboard_eeprom_cpp;
+ std::string last_error;
+};
+
+extern "C" {
+#else
+struct uhd_mboard_eeprom_t;
+#endif
+
+//! A C-level interface for interacting with a USRP motherboard's EEPROM
+/*!
+ * See uhd::usrp::mboard_eeprom_t for more details.
+ *
+ * NOTE: Using a handle before passing it into uhd_mboard_eeprom_make() will
+ * result in undefined behavior.
+ */
+typedef struct uhd_mboard_eeprom_t* uhd_mboard_eeprom_handle;
+
+//! Create a handle for working with a USRP motherboard EEPROM
+UHD_API uhd_error uhd_mboard_eeprom_make(
+ uhd_mboard_eeprom_handle* h
+);
+
+//! Free a USRP motherboard EEPROM handle
+/*!
+ * NOTE: Using a handle after passing it into this function will result in
+ * a segmentation fault.
+ */
+UHD_API uhd_error uhd_mboard_eeprom_free(
+ uhd_mboard_eeprom_handle* h
+);
+
+//! Get the value associated with the given EEPROM key
+UHD_API uhd_error uhd_mboard_eeprom_get_value(
+ uhd_mboard_eeprom_handle h,
+ const char* key,
+ char* value_out,
+ size_t strbuffer_len
+);
+
+//! Set the value for the given EEPROM key
+UHD_API uhd_error uhd_mboard_eeprom_set_value(
+ uhd_mboard_eeprom_handle h,
+ const char* key,
+ const char* value
+);
+
+//! Get the last error recorded by the handle
+UHD_API uhd_error uhd_mboard_eeprom_last_error(
+ uhd_mboard_eeprom_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_USRP_MBOARD_EEPROM_H */
diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp
index 7ac38f84b..cc392542f 100644
--- a/host/include/uhd/usrp/multi_usrp.hpp
+++ b/host/include/uhd/usrp/multi_usrp.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2012,2014 Ettus Research LLC
+// Copyright 2010-2012,2014-2015 Ettus Research LLC
//
// 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
@@ -22,12 +22,15 @@
#define UHD_USRP_MULTI_USRP_REF_SOURCES_API
#define UHD_USRP_MULTI_USRP_GET_RATES_API
#define UHD_USRP_MULTI_USRP_FRONTEND_CAL_API
+#define UHD_USRP_MULTI_USRP_FRONTEND_IQ_AUTO_API
#define UHD_USRP_MULTI_USRP_COMMAND_TIME_API
#define UHD_USRP_MULTI_USRP_BW_RANGE_API
#define UHD_USRP_MULTI_USRP_USER_REGS_API
#define UHD_USRP_MULTI_USRP_GET_USRP_INFO_API
#define UHD_USRP_MULTI_USRP_NORMALIZED_GAIN
#define UHD_USRP_MULTI_USRP_GPIO_API
+#define UHD_USRP_MULTI_USRP_REGISTER_API
+#define UHD_USRP_MULTI_USRP_FILTER_API
#include <uhd/config.hpp>
#include <uhd/device.hpp>
@@ -37,6 +40,7 @@
#include <uhd/types/tune_request.hpp>
#include <uhd/types/tune_result.hpp>
#include <uhd/types/sensors.hpp>
+#include <uhd/types/filters.hpp>
#include <uhd/usrp/subdev_spec.hpp>
#include <uhd/usrp/dboard_iface.hpp>
#include <boost/shared_ptr.hpp>
@@ -157,6 +161,11 @@ public:
* If the specified rate is not available, this method will throw.
* On other devices, this method notifies the software of the rate,
* but requires the the user has made the necessary hardware change.
+ *
+ * If the device has an 'auto clock rate' setting (e.g. B200, see also
+ * \ref b200_auto_mcr), this will get disabled and the clock rate will be
+ * fixed to \p rate.
+ *
* \param rate the new master clock rate in Hz
* \param mboard the motherboard index 0 to M-1
*/
@@ -492,6 +501,34 @@ public:
}
/*!
+ * Set the normalized RX gain value.
+ *
+ * The normalized gain is a value in [0, 1], where 0 is the
+ * smallest gain value available, and 1 is the largest, independent
+ * of the device. In between, gains are linearly interpolated.
+ *
+ * Check the individual device manual for notes on the gain range.
+ *
+ * Note that it is not possible to specify a gain name for
+ * this function, it will always set the overall gain.
+ *
+ * \param gain the normalized gain value
+ * \param chan the channel index 0 to N-1
+ * \throws A uhd::runtime_error if the gain value is outside [0, 1].
+ */
+ virtual void set_normalized_rx_gain(double gain, size_t chan = 0) = 0;
+
+ /*!
+ * Enable or disable the RX AGC module.
+ * Once this module is enabled manual gain settings will be ignored.
+ * The AGC will start in a default configuration which should be good for most use cases.
+ * Device specific configuration parameters can be found in the property tree.
+ * \param enable Enable or Disable the AGC
+ * \param chan the channel index 0 to N-1
+ */
+ virtual void set_rx_agc(bool enable, size_t chan = 0) = 0;
+
+ /*!
* Get the RX gain value for the specified gain element.
* For an empty name, sum across all gain elements.
* \param name the name of the gain element
@@ -506,6 +543,18 @@ public:
}
/*!
+ * Return the normalized RX gain value.
+ *
+ * See set_normalized_rx_gain() for a discussion of normalized
+ * gains.
+ *
+ * \param chan the channel index 0 to N-1
+ * \returns The normalized gain (in [0, 1])
+ * \throws A uhd::runtime_error if the gain value is outside [0, 1].
+ */
+ virtual double get_normalized_rx_gain(size_t chan = 0) = 0;
+
+ /*!
* Get the RX gain range for the specified gain element.
* For an empty name, calculate the overall gain range.
* \param name the name of the gain element
@@ -617,6 +666,14 @@ public:
virtual void set_rx_dc_offset(const std::complex<double> &offset, size_t chan = ALL_CHANS) = 0;
/*!
+ * Enable/disable the automatic IQ imbalance correction.
+ *
+ * \param enb true to enable automatic IQ balance correction
+ * \param chan the channel index 0 to N-1
+ */
+ virtual void set_rx_iq_balance(const bool enb, size_t chan) = 0;
+
+ /*!
* Set the RX frontend IQ imbalance correction.
* Use this to adjust the magnitude and phase of I and Q.
*
@@ -730,6 +787,18 @@ public:
}
/*!
+ * Set the normalized TX gain value.
+ *
+ * See set_normalized_rx_gain() for a discussion on normalized
+ * gains.
+ *
+ * \param gain the normalized gain value
+ * \param chan the channel index 0 to N-1
+ * \throws A uhd::runtime_error if the gain value is outside [0, 1].
+ */
+ virtual void set_normalized_tx_gain(double gain, size_t chan = 0) = 0;
+
+ /*!
* Get the TX gain value for the specified gain element.
* For an empty name, sum across all gain elements.
* \param name the name of the gain element
@@ -744,6 +813,18 @@ public:
}
/*!
+ * Return the normalized TX gain value.
+ *
+ * See set_normalized_rx_gain() for a discussion of normalized
+ * gains.
+ *
+ * \param chan the channel index 0 to N-1
+ * \returns The normalized gain (in [0, 1])
+ * \throws A uhd::runtime_error if the gain value is outside [0, 1].
+ */
+ virtual double get_normalized_tx_gain(size_t chan = 0) = 0;
+
+ /*!
* Get the TX gain range for the specified gain element.
* For an empty name, calculate the overall gain range.
* \param name the name of the gain element
@@ -895,6 +976,80 @@ public:
*/
virtual boost::uint32_t get_gpio_attr(const std::string &bank, const std::string &attr, const size_t mboard = 0) = 0;
+ /*******************************************************************
+ * Register IO methods
+ ******************************************************************/
+ struct register_info_t {
+ size_t bitwidth;
+ bool readable;
+ bool writable;
+ };
+
+ /*!
+ * Enumerate the full paths of all low-level USRP registers accessible to read/write
+ * \param mboard the motherboard index 0 to M-1
+ * \return a vector of register paths
+ */
+ virtual std::vector<std::string> enumerate_registers(const size_t mboard = 0) = 0;
+
+ /*!
+ * Get more information about a low-level device register
+ * \param path the full path to the register
+ * \param mboard the motherboard index 0 to M-1
+ * \return the info struct which contains the bitwidth and read-write access information
+ */
+ virtual register_info_t get_register_info(const std::string &path, const size_t mboard = 0) = 0;
+
+ /*!
+ * Write a low-level register field for a register in the USRP hardware
+ * \param path the full path to the register
+ * \param field the identifier of bitfield to be written (all other bits remain unchanged)
+ * \param value the value to write to the register field
+ * \param mboard the motherboard index 0 to M-1
+ */
+ virtual void write_register(const std::string &path, const boost::uint32_t field, const boost::uint64_t value, const size_t mboard = 0) = 0;
+
+ /*!
+ * Read a low-level register field from a register in the USRP hardware
+ * \param path the full path to the register
+ * \param field the identifier of bitfield to be read
+ * \param mboard the motherboard index 0 to M-1
+ * \return the value of the register field
+ */
+ virtual boost::uint64_t read_register(const std::string &path, const boost::uint32_t field, const size_t mboard = 0) = 0;
+
+ /*******************************************************************
+ * Filter API methods
+ ******************************************************************/
+
+ /*!
+ * Enumerate the available filters in the signal path.
+ * \param search_mask
+ * \parblock
+ * Select only certain filter names by specifying this search mask.
+ *
+ * E.g. if search mask is set to "rx_frontends/A" only filter names including that string will be returned.
+ * \endparblock
+ * \return a vector of strings representing the selected filter names.
+ */
+ virtual std::vector<std::string> get_filter_names(const std::string &search_mask = "") = 0;
+
+ /*!
+ * Return the filter object for the given name.
+ * \param path the name of the filter as returned from get_filter_names().
+ * \return a filter_info_base::sptr.
+ */
+ virtual filter_info_base::sptr get_filter(const std::string &path) = 0;
+
+ /*!
+ * Write back a filter obtained by get_filter() to the signal path.
+ * This filter can be a modified version of the originally returned one.
+ * The information about Rx or Tx is contained in the path parameter.
+ * \param path the name of the filter as returned from get_filter_names().
+ * \param filter the filter_info_base::sptr of the filter object to be written
+ */
+ virtual void set_filter(const std::string &path, filter_info_base::sptr filter) = 0;
+
};
}}
diff --git a/host/include/uhd/usrp/subdev_spec.h b/host/include/uhd/usrp/subdev_spec.h
new file mode 100644
index 000000000..f847181b7
--- /dev/null
+++ b/host/include/uhd/usrp/subdev_spec.h
@@ -0,0 +1,137 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_SUBDEV_SPEC_H
+#define INCLUDED_UHD_USRP_SUBDEV_SPEC_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+#include <stdbool.h>
+
+//! Subdevice specification
+typedef struct {
+ // Daughterboard slot name
+ char* db_name;
+ //! Subdevice name
+ char* sd_name;
+} uhd_subdev_spec_pair_t;
+
+#ifdef __cplusplus
+#include <uhd/usrp/subdev_spec.hpp>
+#include <string>
+
+struct uhd_subdev_spec_t {
+ uhd::usrp::subdev_spec_t subdev_spec_cpp;
+ std::string last_error;
+};
+
+extern "C" {
+#else
+struct uhd_subdev_spec_t;
+#endif
+
+//! A C-level interface for working with a list of subdevice specifications
+/*!
+ * See uhd::usrp::subdev_spec_t for more details.
+ *
+ * NOTE: Using a handle before passing it into uhd_subdev_spec_make() will result in
+ * undefined behavior.
+ */
+typedef struct uhd_subdev_spec_t* uhd_subdev_spec_handle;
+
+//! Safely destroy any memory created in the generation of a uhd_subdev_spec_pair_t
+UHD_API uhd_error uhd_subdev_spec_pair_free(
+ uhd_subdev_spec_pair_t *subdev_spec_pair
+);
+
+//! Check to see if two subdevice specifications are equal
+UHD_API uhd_error uhd_subdev_spec_pairs_equal(
+ const uhd_subdev_spec_pair_t* first,
+ const uhd_subdev_spec_pair_t* second,
+ bool *result_out
+);
+
+//! Create a handle for a list of subdevice specifications
+UHD_API uhd_error uhd_subdev_spec_make(
+ uhd_subdev_spec_handle* h,
+ const char* markup
+);
+
+//! Safely destroy a subdevice specification handle
+/*!
+ * NOTE: Using a handle after passing it into this function will result in
+ * a segmentation fault.
+ */
+UHD_API uhd_error uhd_subdev_spec_free(
+ uhd_subdev_spec_handle* h
+);
+
+//! Check how many subdevice specifications are in this list
+UHD_API uhd_error uhd_subdev_spec_size(
+ uhd_subdev_spec_handle h,
+ size_t *size_out
+);
+
+//! Add a subdevice specification to this list
+UHD_API uhd_error uhd_subdev_spec_push_back(
+ uhd_subdev_spec_handle h,
+ const char* markup
+);
+
+//! Get the subdevice specification at the given index
+UHD_API uhd_error uhd_subdev_spec_at(
+ uhd_subdev_spec_handle h,
+ size_t num,
+ uhd_subdev_spec_pair_t *subdev_spec_pair_out
+);
+
+//! Get a string representation of the given list
+UHD_API uhd_error uhd_subdev_spec_to_pp_string(
+ uhd_subdev_spec_handle h,
+ char* pp_string_out,
+ size_t strbuffer_len
+);
+
+//! Get a markup string representation of the given list
+UHD_API uhd_error uhd_subdev_spec_to_string(
+ uhd_subdev_spec_handle h,
+ char* string_out,
+ size_t strbuffer_len
+);
+
+//! Get the last error recorded by the given handle
+UHD_API uhd_error uhd_subdev_spec_last_error(
+ uhd_subdev_spec_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+#ifdef __cplusplus
+}
+
+UHD_API uhd::usrp::subdev_spec_pair_t uhd_subdev_spec_pair_c_to_cpp(
+ const uhd_subdev_spec_pair_t* subdev_spec_pair_c
+);
+
+UHD_API void uhd_subdev_spec_pair_cpp_to_c(
+ const uhd::usrp::subdev_spec_pair_t &subdev_spec_pair_cpp,
+ uhd_subdev_spec_pair_t *subdev_spec_pair_c
+);
+#endif
+
+#endif /* INCLUDED_UHD_USRP_SUBDEV_SPEC_H */
diff --git a/host/include/uhd/usrp/usrp.h b/host/include/uhd/usrp/usrp.h
new file mode 100644
index 000000000..1bde694b4
--- /dev/null
+++ b/host/include/uhd/usrp/usrp.h
@@ -0,0 +1,1152 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_H
+#define INCLUDED_UHD_USRP_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+#include <uhd/types/metadata.h>
+#include <uhd/types/ranges.h>
+#include <uhd/types/sensors.h>
+#include <uhd/types/string_vector.h>
+#include <uhd/types/tune_request.h>
+#include <uhd/types/tune_result.h>
+#include <uhd/types/usrp_info.h>
+#include <uhd/usrp/mboard_eeprom.h>
+#include <uhd/usrp/dboard_eeprom.h>
+#include <uhd/usrp/subdev_spec.h>
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <time.h>
+
+//! Register info
+typedef struct {
+ size_t bitwidth;
+ bool readable;
+ bool writable;
+} uhd_usrp_register_info_t;
+
+/*
+ * Streamers
+ */
+
+//! A struct of parameters to construct a stream.
+/*!
+ * See uhd::stream_args_t for more details.
+ */
+typedef struct {
+ //! Format of host memory
+ char* cpu_format;
+ //! Over-the-wire format
+ char* otw_format;
+ //! Other stream args
+ char* args;
+ //! Array that lists channels
+ size_t* channel_list;
+ //! Number of channels
+ int n_channels;
+} uhd_stream_args_t;
+
+//! How streaming is issued to the device
+/*!
+ * See uhd::stream_cmd_t for more details.
+ */
+typedef enum {
+ //! Stream samples indefinitely
+ UHD_STREAM_MODE_START_CONTINUOUS = 97,
+ //! End continuous streaming
+ UHD_STREAM_MODE_STOP_CONTINUOUS = 111,
+ //! Stream some number of samples and finish
+ UHD_STREAM_MODE_NUM_SAMPS_AND_DONE = 100,
+ //! Stream some number of samples but expect more
+ UHD_STREAM_MODE_NUM_SAMPS_AND_MORE = 109
+} uhd_stream_mode_t;
+
+//! Define how device streams to host
+/*!
+ * See uhd::stream_cmd_t for more details.
+ */
+typedef struct {
+ //! How streaming is issued to the device
+ uhd_stream_mode_t stream_mode;
+ //! Number of samples
+ size_t num_samps;
+ //! Stream now?
+ bool stream_now;
+ //! If not now, then full seconds into future to stream
+ time_t time_spec_full_secs;
+ //! If not now, then fractional seconds into future to stream
+ double time_spec_frac_secs;
+} uhd_stream_cmd_t;
+
+struct uhd_rx_streamer;
+struct uhd_tx_streamer;
+
+//! C-level interface for working with an RX streamer
+/*!
+ * See uhd::rx_streamer for more details.
+ */
+typedef struct uhd_rx_streamer* uhd_rx_streamer_handle;
+
+//! C-level interface for working with a TX streamer
+/*!
+ * See uhd::tx_streamer for more details.
+ */
+typedef struct uhd_tx_streamer* uhd_tx_streamer_handle;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * RX Streamer
+ */
+
+//! Create an RX streamer handle.
+/*!
+ * NOTE: Using this streamer before passing it into uhd_usrp_get_rx_stream()
+ * will result in undefined behavior.
+ */
+UHD_API uhd_error uhd_rx_streamer_make(
+ uhd_rx_streamer_handle *h
+);
+
+//! Free an RX streamer handle.
+/*!
+ * NOTE: Using a streamer after passing it into this function will result
+ * in a segmentation fault.
+ */
+UHD_API uhd_error uhd_rx_streamer_free(
+ uhd_rx_streamer_handle *h
+);
+
+//! Get the number of channels associated with this streamer
+UHD_API uhd_error uhd_rx_streamer_num_channels(
+ uhd_rx_streamer_handle h,
+ size_t *num_channels_out
+);
+
+//! Get the max number of samples per buffer per packet
+UHD_API uhd_error uhd_rx_streamer_max_num_samps(
+ uhd_rx_streamer_handle h,
+ size_t *max_num_samps_out
+);
+
+//! Receive buffers containing samples into the given RX streamer
+/*!
+ * See uhd::rx_streamer::recv() for more details.
+ *
+ * \param h RX streamer handle
+ * \param buffs pointer to buffers in which to receive samples
+ * \param samps_per_buffer max number of samples per buffer
+ * \param md handle to RX metadata in which to receive results
+ * \param timeout timeout in seconds to wait for a packet
+ * \param one_packet send a single packet
+ * \param items_recvd pointer to output variable for number of samples received
+ */
+UHD_API uhd_error uhd_rx_streamer_recv(
+ uhd_rx_streamer_handle h,
+ void** buffs,
+ size_t samps_per_buff,
+ uhd_rx_metadata_handle *md,
+ double timeout,
+ bool one_packet,
+ size_t *items_recvd
+);
+
+//! Issue the given stream command
+/*!
+ * See uhd::rx_streamer::issue_stream_cmd() for more details.
+ */
+UHD_API uhd_error uhd_rx_streamer_issue_stream_cmd(
+ uhd_rx_streamer_handle h,
+ const uhd_stream_cmd_t *stream_cmd
+);
+
+//! Get the last error reported by the RX streamer
+/*!
+ * NOTE: This will overwrite the string currently in error_out before
+ * using it to return its error.
+ *
+ * \param h RX streamer handle
+ * \param error_out string buffer in which to place error
+ * \param strbuffer_len buffer size
+ */
+UHD_API uhd_error uhd_rx_streamer_last_error(
+ uhd_rx_streamer_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+/*
+ * TX Streamer
+ */
+
+//! Create an TX streamer handle.
+/*!
+ * NOTE: Using this streamer before passing it into uhd_usrp_get_tx_stream()
+ * will result in undefined behavior.
+ */
+UHD_API uhd_error uhd_tx_streamer_make(
+ uhd_tx_streamer_handle *h
+);
+
+//! Free an TX streamer handle.
+/*!
+ * NOTE: Using a streamer after passing it into this function will result
+ * in a segmentation fault.
+ */
+UHD_API uhd_error uhd_tx_streamer_free(
+ uhd_tx_streamer_handle *h
+);
+
+//! Get the number of channels associated with this streamer
+UHD_API uhd_error uhd_tx_streamer_num_channels(
+ uhd_tx_streamer_handle h,
+ size_t *num_channels_out
+);
+
+//! Get the max number of samples per buffer per packet
+UHD_API uhd_error uhd_tx_streamer_max_num_samps(
+ uhd_tx_streamer_handle h,
+ size_t *max_num_samps_out
+);
+
+//! Send buffers containing samples described by the metadata
+/*!
+ * See uhd::tx_streamer::send() for more details.
+ *
+ * \param h TX streamer handle
+ * \param buffs pointer to buffers containing samples to send
+ * \param samps_per_buffer max number of samples per buffer
+ * \param md handle to TX metadata
+ * \param timeout timeout in seconds to wait for a packet
+ * \param items_sent pointer to output variable for number of samples send
+ */
+UHD_API uhd_error uhd_tx_streamer_send(
+ uhd_tx_streamer_handle h,
+ const void **buffs,
+ size_t samps_per_buff,
+ uhd_tx_metadata_handle *md,
+ double timeout,
+ size_t *items_sent
+);
+
+//! Receive an asynchronous message from this streamer
+/*!
+ * See uhd::tx_streamer::recv_async_msg() for more details.
+ */
+UHD_API uhd_error uhd_tx_streamer_recv_async_msg(
+ uhd_tx_streamer_handle h,
+ uhd_async_metadata_handle *md,
+ double timeout,
+ bool *valid
+);
+
+//! Get the last error reported by the TX streamer
+/*!
+ * NOTE: This will overwrite the string currently in error_out before
+ * using it to return its error.
+ *
+ * \param h TX streamer handle
+ * \param error_out string buffer in which to place error
+ * \param strbuffer_len buffer size
+ */
+UHD_API uhd_error uhd_tx_streamer_last_error(
+ uhd_tx_streamer_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+/****************************************************************************
+ * Public Datatypes for USRP / streamer handling.
+ ***************************************************************************/
+struct uhd_usrp;
+
+//! C-level interface for working with a USRP device
+/*
+ * See uhd::usrp::multi_usrp for more details.
+ *
+ * NOTE: You must pass this handle into uhd_usrp_make before using it.
+ */
+typedef struct uhd_usrp* uhd_usrp_handle;
+
+/****************************************************************************
+ * USRP Make / Free API calls
+ ***************************************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//! Find all connected USRP devices.
+/*!
+ * See uhd::device::find() for more details.
+ */
+UHD_API uhd_error uhd_usrp_find(
+ const char* args,
+ uhd_string_vector_handle *strings_out
+);
+
+//! Create a USRP handle.
+/*!
+ * \param h the handle
+ * \param args device args (e.g. "type=x300")
+ */
+UHD_API uhd_error uhd_usrp_make(
+ uhd_usrp_handle *h,
+ const char *args
+);
+
+//! Safely destroy the USRP object underlying the handle.
+/*!
+ * NOTE: Attempting to use a USRP handle after passing it into this function
+ * will result in a segmentation fault.
+ */
+UHD_API uhd_error uhd_usrp_free(
+ uhd_usrp_handle *h
+);
+
+//! Get the last error reported by the USRP handle
+UHD_API uhd_error uhd_usrp_last_error(
+ uhd_usrp_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+//! Create RX streamer from a USRP handle and given stream args
+UHD_API uhd_error uhd_usrp_get_rx_stream(
+ uhd_usrp_handle h,
+ uhd_stream_args_t *stream_args,
+ uhd_rx_streamer_handle h_out
+);
+
+//! Create TX streamer from a USRP handle and given stream args
+UHD_API uhd_error uhd_usrp_get_tx_stream(
+ uhd_usrp_handle h,
+ uhd_stream_args_t *stream_args,
+ uhd_tx_streamer_handle h_out
+);
+
+/****************************************************************************
+ * multi_usrp API calls
+ ***************************************************************************/
+
+//! Get RX info from the USRP device
+/*!
+ * NOTE: After calling this function, uhd_usrp_rx_info_free() must be called on info_out.
+ */
+UHD_API uhd_error uhd_usrp_get_rx_info(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_usrp_rx_info_t *info_out
+);
+
+//! Get TX info from the USRP device
+/*!
+ * NOTE: After calling this function, uhd_usrp_tx_info_free() must be called on info_out.
+ */
+UHD_API uhd_error uhd_usrp_get_tx_info(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_usrp_tx_info_t *info_out
+);
+
+/****************************************************************************
+ * Motherboard methods
+ ***************************************************************************/
+
+//! Set the master clock rate.
+/*!
+ * See uhd::usrp::multi_usrp::set_master_clock_rate() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_master_clock_rate(
+ uhd_usrp_handle h,
+ double rate,
+ size_t mboard
+);
+
+//! Get the master clock rate.
+/*!
+ * See uhd::usrp::multi_usrp::get_master_clock_rate() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_master_clock_rate(
+ uhd_usrp_handle h,
+ size_t mboard,
+ double *clock_rate_out
+);
+
+//! Get a pretty-print representation of the USRP device.
+/*!
+ * See uhd::usrp::multi_usrp::get_pp_string() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_pp_string(
+ uhd_usrp_handle h,
+ char* pp_string_out,
+ size_t strbuffer_len
+);
+
+//! Get the motherboard name for the given device
+/*!
+ * See uhd::usrp::multi_usrp::get_mboard_name() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_mboard_name(
+ uhd_usrp_handle h,
+ size_t mboard,
+ char* mboard_name_out,
+ size_t strbuffer_len
+);
+
+//! Get the USRP device's current internal time
+/*!
+ * See uhd::usrp::multi_usrp::get_time_now() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_time_now(
+ uhd_usrp_handle h,
+ size_t mboard,
+ time_t *full_secs_out,
+ double *frac_secs_out
+);
+
+//! Get the time when this device's last PPS pulse occurred
+/*!
+ * See uhd::usrp::multi_usrp::get_time_last_pps() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_time_last_pps(
+ uhd_usrp_handle h,
+ size_t mboard,
+ time_t *full_secs_out,
+ double *frac_secs_out
+);
+
+//! Set the USRP device's time
+/*!
+ * See uhd::usrp::multi_usrp::set_time_now() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_time_now(
+ uhd_usrp_handle h,
+ time_t full_secs,
+ double frac_secs,
+ size_t mboard
+);
+
+//! Set the USRP device's time to the given value upon the next PPS detection
+/*!
+ * See uhd::usrp::multi_usrp::set_time_next_pps() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_time_next_pps(
+ uhd_usrp_handle h,
+ time_t full_secs,
+ double frac_secs,
+ size_t mboard
+);
+
+//! Synchronize the time across all motherboards
+/*!
+ * See uhd::usrp::multi_usrp::set_time_unknown_pps() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_time_unknown_pps(
+ uhd_usrp_handle h,
+ time_t full_secs,
+ double frac_secs
+);
+
+//! Are all motherboard times synchronized?
+UHD_API uhd_error uhd_usrp_get_time_synchronized(
+ uhd_usrp_handle h,
+ bool *result_out
+);
+
+//! Set the time at which timed commands will take place
+/*!
+ * See uhd::usrp::multi_usrp::set_command_time() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_command_time(
+ uhd_usrp_handle h,
+ time_t full_secs,
+ double frac_secs,
+ size_t mboard
+);
+
+//! Clear the command time so that commands are sent ASAP
+UHD_API uhd_error uhd_usrp_clear_command_time(
+ uhd_usrp_handle h,
+ size_t mboard
+);
+
+//! Set the time source for the given device
+/*!
+ * See uhd::usrp::multi_usrp::set_time_source() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_time_source(
+ uhd_usrp_handle h,
+ const char* time_source,
+ size_t mboard
+);
+
+//! Get the time source for the given device
+/*!
+ * See uhd::usrp::multi_usrp::get_time_source() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_time_source(
+ uhd_usrp_handle h,
+ size_t mboard,
+ char* time_source_out,
+ size_t strbuffer_len
+);
+
+//! Get a list of time sources for the given device
+UHD_API uhd_error uhd_usrp_get_time_sources(
+ uhd_usrp_handle h,
+ size_t mboard,
+ uhd_string_vector_handle *time_sources_out
+);
+
+//! Set the given device's clock source
+/*!
+ * See uhd::usrp::multi_usrp::set_clock_source() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_clock_source(
+ uhd_usrp_handle h,
+ const char* clock_source,
+ size_t mboard
+);
+
+//! Get the given device's clock source
+/*!
+ * See uhd::usrp::multi_usrp::get_clock_source() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_clock_source(
+ uhd_usrp_handle h,
+ size_t mboard,
+ char* clock_source_out,
+ size_t strbuffer_len
+);
+
+//! Get a list of clock sources for the given device
+UHD_API uhd_error uhd_usrp_get_clock_sources(
+ uhd_usrp_handle h,
+ size_t mboard,
+ uhd_string_vector_handle *clock_sources_out
+);
+
+//! Enable or disable sending the clock source to an output connector
+/*!
+ * See uhd::usrp::set_clock_source_out() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_clock_source_out(
+ uhd_usrp_handle h,
+ bool enb,
+ size_t mboard
+);
+
+//! Enable or disable sending the time source to an output connector
+/*!
+ * See uhd::usrp::set_time_source_out() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_time_source_out(
+ uhd_usrp_handle h,
+ bool enb,
+ size_t mboard
+);
+
+//! Get the number of devices associated with the given USRP handle
+UHD_API uhd_error uhd_usrp_get_num_mboards(
+ uhd_usrp_handle h,
+ size_t *num_mboards_out
+);
+
+//! Get the value associated with the given sensor name
+UHD_API uhd_error uhd_usrp_get_mboard_sensor(
+ uhd_usrp_handle h,
+ const char* name,
+ size_t mboard,
+ uhd_sensor_value_handle *sensor_value_out
+);
+
+//! Get a list of motherboard sensors for the given device
+UHD_API uhd_error uhd_usrp_get_mboard_sensor_names(
+ uhd_usrp_handle h,
+ size_t mboard,
+ uhd_string_vector_handle *mboard_sensor_names_out
+);
+
+//! Perform a write on a user configuration register bus
+/*!
+ * See uhd::usrp::multi_usrp::set_user_register() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_user_register(
+ uhd_usrp_handle h,
+ uint8_t addr,
+ uint32_t data,
+ size_t mboard
+);
+
+/****************************************************************************
+ * EEPROM access methods
+ ***************************************************************************/
+
+//! Get a handle for the given motherboard's EEPROM
+UHD_API uhd_error uhd_usrp_get_mboard_eeprom(
+ uhd_usrp_handle h,
+ uhd_mboard_eeprom_handle mb_eeprom,
+ size_t mboard
+);
+
+//! Set values in the given motherboard's EEPROM
+UHD_API uhd_error uhd_usrp_set_mboard_eeprom(
+ uhd_usrp_handle h,
+ uhd_mboard_eeprom_handle mb_eeprom,
+ size_t mboard
+);
+
+//! Get a handle for the given device's daughterboard EEPROM
+UHD_API uhd_error uhd_usrp_get_dboard_eeprom(
+ uhd_usrp_handle h,
+ uhd_dboard_eeprom_handle db_eeprom,
+ const char* unit,
+ const char* slot,
+ size_t mboard
+);
+
+//! Set values in the given daughterboard's EEPROM
+UHD_API uhd_error uhd_usrp_set_dboard_eeprom(
+ uhd_usrp_handle h,
+ uhd_dboard_eeprom_handle db_eeprom,
+ const char* unit,
+ const char* slot,
+ size_t mboard
+);
+
+/****************************************************************************
+ * RX methods
+ ***************************************************************************/
+
+//! Map the given device's RX frontend to a channel
+/*!
+ * See uhd::usrp::multi_usrp::set_rx_subdev_spec() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_rx_subdev_spec(
+ uhd_usrp_handle h,
+ uhd_subdev_spec_handle subdev_spec,
+ size_t mboard
+);
+
+//! Get the RX frontend specfication for the given device
+UHD_API uhd_error uhd_usrp_get_rx_subdev_spec(
+ uhd_usrp_handle h,
+ size_t mboard,
+ uhd_subdev_spec_handle subdev_spec_out
+);
+
+//! Get the number of RX channels for the given handle
+UHD_API uhd_error uhd_usrp_get_rx_num_channels(
+ uhd_usrp_handle h,
+ size_t *num_channels_out
+);
+
+//! Get the name for the RX frontend
+UHD_API uhd_error uhd_usrp_get_rx_subdev_name(
+ uhd_usrp_handle h,
+ size_t chan,
+ char* rx_subdev_name_out,
+ size_t strbuffer_len
+);
+
+//! Set the given RX channel's sample rate (in Sps)
+UHD_API uhd_error uhd_usrp_set_rx_rate(
+ uhd_usrp_handle h,
+ double rate,
+ size_t chan
+);
+
+//! Get the given RX channel's sample rate (in Sps)
+UHD_API uhd_error uhd_usrp_get_rx_rate(
+ uhd_usrp_handle h,
+ size_t chan,
+ double *rate_out
+);
+
+//! Get a range of possible RX rates for the given channel
+UHD_API uhd_error uhd_usrp_get_rx_rates(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_meta_range_handle rates_out
+);
+
+//! Set the given channel's center RX frequency
+UHD_API uhd_error uhd_usrp_set_rx_freq(
+ uhd_usrp_handle h,
+ uhd_tune_request_t *tune_request,
+ size_t chan,
+ uhd_tune_result_t *tune_result
+);
+
+//! Get the given channel's center RX frequency
+UHD_API uhd_error uhd_usrp_get_rx_freq(
+ uhd_usrp_handle h,
+ size_t chan,
+ double *freq_out
+);
+
+//! Get all possible center frequency ranges for the given channel
+/*!
+ * See uhd::usrp::multi_usrp::get_rx_freq_range() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_rx_freq_range(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_meta_range_handle freq_range_out
+);
+
+//! Get all possible RF frequency ranges for the given channel's RX RF frontend
+UHD_API uhd_error uhd_usrp_get_fe_rx_freq_range(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_meta_range_handle freq_range_out
+);
+
+//! Set the RX gain for the given channel and name
+UHD_API uhd_error uhd_usrp_set_rx_gain(
+ uhd_usrp_handle h,
+ double gain,
+ size_t chan,
+ const char *gain_name
+);
+
+//! Set the normalized RX gain [0.0, 1.0] for the given channel
+/*!
+ * See uhd::usrp::multi_usrp::set_normalized_rx_gain() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_normalized_rx_gain(
+ uhd_usrp_handle h,
+ double gain,
+ size_t chan
+);
+
+//! Enable or disable the given channel's RX AGC module
+/*!
+ * See uhd::usrp::multi_usrp::set_rx_agc() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_rx_agc(
+ uhd_usrp_handle h,
+ bool enable,
+ size_t chan
+);
+
+//! Get the given channel's RX gain
+UHD_API uhd_error uhd_usrp_get_rx_gain(
+ uhd_usrp_handle h,
+ size_t chan,
+ const char *gain_name,
+ double *gain_out
+);
+
+//! Get the given channel's normalized RX gain [0.0, 1.0]
+/*!
+ * See uhd::usrp::multi_usrp::get_normalized_rx_gain() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_normalized_rx_gain(
+ uhd_usrp_handle h,
+ size_t chan,
+ double *gain_out
+);
+
+//! Get all possible gain ranges for the given channel and name
+UHD_API uhd_error uhd_usrp_get_rx_gain_range(
+ uhd_usrp_handle h,
+ const char* name,
+ size_t chan,
+ uhd_meta_range_handle gain_range_out
+);
+
+//! Get a list of RX gain names for the given channel
+UHD_API uhd_error uhd_usrp_get_rx_gain_names(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_string_vector_handle *gain_names_out
+);
+
+//! Set the RX antenna for the given channel
+UHD_API uhd_error uhd_usrp_set_rx_antenna(
+ uhd_usrp_handle h,
+ const char* ant,
+ size_t chan
+);
+
+//! Get the RX antenna for the given channel
+UHD_API uhd_error uhd_usrp_get_rx_antenna(
+ uhd_usrp_handle h,
+ size_t chan,
+ char* ant_out,
+ size_t strbuffer_len
+);
+
+//! Get a list of RX antennas associated with the given channels
+UHD_API uhd_error uhd_usrp_get_rx_antennas(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_string_vector_handle *antennas_out
+);
+
+//! Get a list of RX sensors associated with the given channels
+UHD_API uhd_error uhd_usrp_get_rx_sensor_names(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_string_vector_handle *sensor_names_out
+);
+
+//! Set the bandwidth for the given channel's RX frontend
+UHD_API uhd_error uhd_usrp_set_rx_bandwidth(
+ uhd_usrp_handle h,
+ double bandwidth,
+ size_t chan
+);
+
+//! Get the bandwidth for the given channel's RX frontend
+UHD_API uhd_error uhd_usrp_get_rx_bandwidth(
+ uhd_usrp_handle h,
+ size_t chan,
+ double *bandwidth_out
+);
+
+//! Get all possible bandwidth ranges for the given channel's RX frontend
+UHD_API uhd_error uhd_usrp_get_rx_bandwidth_range(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_meta_range_handle bandwidth_range_out
+);
+
+//! Get the value for the given RX sensor
+UHD_API uhd_error uhd_usrp_get_rx_sensor(
+ uhd_usrp_handle h,
+ const char* name,
+ size_t chan,
+ uhd_sensor_value_handle *sensor_value_out
+);
+
+//! Enable or disable RX DC offset correction for the given channel
+/*!
+ * See uhd::usrp::multi_usrp::set_rx_dc_offset() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_rx_dc_offset_enabled(
+ uhd_usrp_handle h,
+ bool enb,
+ size_t chan
+);
+
+//! Enable or disable RX IQ imbalance correction for the given channel
+UHD_API uhd_error uhd_usrp_set_rx_iq_balance_enabled(
+ uhd_usrp_handle h,
+ bool enb,
+ size_t chan
+);
+
+/****************************************************************************
+ * TX methods
+ ***************************************************************************/
+
+//! Map the given device's TX frontend to a channel
+/*!
+ * See uhd::usrp::multi_usrp::set_tx_subdev_spec() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_tx_subdev_spec(
+ uhd_usrp_handle h,
+ uhd_subdev_spec_handle subdev_spec,
+ size_t mboard
+);
+
+//! Get the TX frontend specfication for the given device
+UHD_API uhd_error uhd_usrp_get_tx_subdev_spec(
+ uhd_usrp_handle h,
+ size_t mboard,
+ uhd_subdev_spec_handle subdev_spec_out
+);
+
+//! Get the number of TX channels for the given handle
+UHD_API uhd_error uhd_usrp_get_tx_num_channels(
+ uhd_usrp_handle h,
+ size_t *num_channels_out
+);
+
+//! Get the name for the RX frontend
+UHD_API uhd_error uhd_usrp_get_tx_subdev_name(
+ uhd_usrp_handle h,
+ size_t chan,
+ char* tx_subdev_name_out,
+ size_t strbuffer_len
+);
+
+//! Set the given RX channel's sample rate (in Sps)
+UHD_API uhd_error uhd_usrp_set_tx_rate(
+ uhd_usrp_handle h,
+ double rate,
+ size_t chan
+);
+
+//! Get the given RX channel's sample rate (in Sps)
+UHD_API uhd_error uhd_usrp_get_tx_rate(
+ uhd_usrp_handle h,
+ size_t chan,
+ double *rate_out
+);
+
+//! Get a range of possible RX rates for the given channel
+UHD_API uhd_error uhd_usrp_get_tx_rates(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_meta_range_handle rates_out
+);
+
+//! Set the given channel's center TX frequency
+UHD_API uhd_error uhd_usrp_set_tx_freq(
+ uhd_usrp_handle h,
+ uhd_tune_request_t *tune_request,
+ size_t chan,
+ uhd_tune_result_t *tune_result
+);
+
+//! Get the given channel's center TX frequency
+UHD_API uhd_error uhd_usrp_get_tx_freq(
+ uhd_usrp_handle h,
+ size_t chan,
+ double *freq_out
+);
+
+//! Get all possible center frequency ranges for the given channel
+/*!
+ * See uhd::usrp::multi_usrp::get_rx_freq_range() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_tx_freq_range(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_meta_range_handle freq_range_out
+);
+
+//! Get all possible RF frequency ranges for the given channel's TX RF frontend
+UHD_API uhd_error uhd_usrp_get_fe_tx_freq_range(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_meta_range_handle freq_range_out
+);
+
+//! Set the TX gain for the given channel and name
+UHD_API uhd_error uhd_usrp_set_tx_gain(
+ uhd_usrp_handle h,
+ double gain,
+ size_t chan,
+ const char *gain_name
+);
+
+//! Set the normalized TX gain [0.0, 1.0] for the given channel
+/*!
+ * See uhd::usrp::multi_usrp::set_normalized_tx_gain() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_normalized_tx_gain(
+ uhd_usrp_handle h,
+ double gain,
+ size_t chan
+);
+
+//! Get all possible gain ranges for the given channel and name
+UHD_API uhd_error uhd_usrp_get_tx_gain_range(
+ uhd_usrp_handle h,
+ const char* name,
+ size_t chan,
+ uhd_meta_range_handle gain_range_out
+);
+
+//! Get the given channel's RX gain
+UHD_API uhd_error uhd_usrp_get_tx_gain(
+ uhd_usrp_handle h,
+ size_t chan,
+ const char *gain_name,
+ double *gain_out
+);
+
+//! Get the given channel's normalized TX gain [0.0, 1.0]
+/*!
+ * See uhd::usrp::multi_usrp::get_normalized_tx_gain() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_normalized_tx_gain(
+ uhd_usrp_handle h,
+ size_t chan,
+ double *gain_out
+);
+
+//! Get a list of TX gain names for the given channel
+UHD_API uhd_error uhd_usrp_get_tx_gain_names(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_string_vector_handle *gain_names_out
+);
+
+//! Set the TX antenna for the given channel
+UHD_API uhd_error uhd_usrp_set_tx_antenna(
+ uhd_usrp_handle h,
+ const char* ant,
+ size_t chan
+);
+
+//! Get the TX antenna for the given channel
+UHD_API uhd_error uhd_usrp_get_tx_antenna(
+ uhd_usrp_handle h,
+ size_t chan,
+ char* ant_out,
+ size_t strbuffer_len
+);
+
+//! Get a list of tx antennas associated with the given channels
+UHD_API uhd_error uhd_usrp_get_tx_antennas(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_string_vector_handle *antennas_out
+);
+
+//! Set the bandwidth for the given channel's TX frontend
+UHD_API uhd_error uhd_usrp_set_tx_bandwidth(
+ uhd_usrp_handle h,
+ double bandwidth,
+ size_t chan
+);
+
+//! Get the bandwidth for the given channel's TX frontend
+UHD_API uhd_error uhd_usrp_get_tx_bandwidth(
+ uhd_usrp_handle h,
+ size_t chan,
+ double *bandwidth_out
+);
+
+//! Get all possible bandwidth ranges for the given channel's TX frontend
+UHD_API uhd_error uhd_usrp_get_tx_bandwidth_range(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_meta_range_handle bandwidth_range_out
+);
+
+//! Get the value for the given TX sensor
+UHD_API uhd_error uhd_usrp_get_tx_sensor(
+ uhd_usrp_handle h,
+ const char* name,
+ size_t chan,
+ uhd_sensor_value_handle *sensor_value_out
+);
+
+//! Get a list of TX sensors associated with the given channels
+UHD_API uhd_error uhd_usrp_get_tx_sensor_names(
+ uhd_usrp_handle h,
+ size_t chan,
+ uhd_string_vector_handle *sensor_names_out
+);
+
+//! Enable or disable TX DC offset correction for the given channel
+/*!
+ * See uhd::usrp::multi_usrp::set_tx_dc_offset() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_tx_dc_offset_enabled(
+ uhd_usrp_handle h,
+ bool enb,
+ size_t chan
+);
+
+//! Enable or disable TX IQ imbalance correction for the given channel
+UHD_API uhd_error uhd_usrp_set_tx_iq_balance_enabled(
+ uhd_usrp_handle h,
+ bool enb,
+ size_t chan
+);
+
+/****************************************************************************
+ * GPIO methods
+ ***************************************************************************/
+
+//! Get a list of GPIO banks associated with the given channels
+UHD_API uhd_error uhd_usrp_get_gpio_banks(
+ uhd_usrp_handle h,
+ size_t mboard,
+ uhd_string_vector_handle *gpio_banks_out
+);
+
+//! Set a GPIO attribute for a given GPIO bank
+/*!
+ * See uhd::usrp::multi_usrp::set_gpio_attr() for more details.
+ */
+UHD_API uhd_error uhd_usrp_set_gpio_attr(
+ uhd_usrp_handle h,
+ const char* bank,
+ const char* attr,
+ uint32_t value,
+ uint32_t mask,
+ size_t mboard
+);
+
+//! Get a GPIO attribute on a particular GPIO bank
+/*!
+ * See uhd::usrp::multi_usrp::get_gpio_attr() for more details.
+ */
+UHD_API uhd_error uhd_usrp_get_gpio_attr(
+ uhd_usrp_handle h,
+ const char* bank,
+ const char* attr,
+ size_t mboard,
+ uint32_t *attr_out
+);
+
+//! Enumerate the full paths of USRP registers available for read/write
+UHD_API uhd_error uhd_usrp_enumerate_registers(
+ uhd_usrp_handle h,
+ size_t mboard,
+ uhd_string_vector_handle *registers_out
+);
+
+//! Get more information about a low-level device register
+UHD_API uhd_error uhd_usrp_get_register_info(
+ uhd_usrp_handle h,
+ const char* path,
+ size_t mboard,
+ uhd_usrp_register_info_t *register_info_out
+);
+
+//! Write a low-level register field for a device register in the USRP hardware
+UHD_API uhd_error uhd_usrp_write_register(
+ uhd_usrp_handle h,
+ const char* path,
+ uint32_t field,
+ uint64_t value,
+ size_t mboard
+);
+
+//! Read a low-level register field from a device register in the USRP hardware
+UHD_API uhd_error uhd_usrp_read_register(
+ uhd_usrp_handle h,
+ const char* path,
+ uint32_t field,
+ size_t mboard,
+ uint64_t *value_out
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_USRP_H */
diff --git a/host/include/uhd/usrp_clock/CMakeLists.txt b/host/include/uhd/usrp_clock/CMakeLists.txt
index 7cd5aa9d3..518cb7737 100644
--- a/host/include/uhd/usrp_clock/CMakeLists.txt
+++ b/host/include/uhd/usrp_clock/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# Copyright 2014 Ettus Research LLC
+# Copyright 2014-2015 Ettus Research LLC
#
# 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
@@ -18,6 +18,12 @@
UHD_INSTALL(FILES
octoclock_eeprom.hpp
multi_usrp_clock.hpp
- DESTINATION ${INCLUDE_DIR}/uhd/octoclock
+ DESTINATION ${INCLUDE_DIR}/uhd/usrp_clock
COMPONENT headers
)
+
+IF(ENABLE_C_API)
+ UHD_INSTALL(FILES
+ usrp_clock.h
+ )
+ENDIF(ENABLE_C_API)
diff --git a/host/include/uhd/usrp_clock/usrp_clock.h b/host/include/uhd/usrp_clock/usrp_clock.h
new file mode 100644
index 000000000..39ce04c8c
--- /dev/null
+++ b/host/include/uhd/usrp_clock/usrp_clock.h
@@ -0,0 +1,125 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_CLOCK_H
+#define INCLUDED_UHD_USRP_CLOCK_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+#include <uhd/types/sensors.h>
+#include <uhd/types/string_vector.h>
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <time.h>
+
+/****************************************************************************
+ * Public Datatypes for USRP clock
+ ***************************************************************************/
+struct uhd_usrp_clock;
+
+//! A C-level interface for interacting with an Ettus Research clock device
+/*!
+ * See uhd::usrp_clock::multi_usrp_clock for more details.
+ *
+ * NOTE: Attempting to use a handle before passing it into uhd_usrp_clock_make()
+ * will result in undefined behavior.
+ */
+typedef struct uhd_usrp_clock* uhd_usrp_clock_handle;
+
+/****************************************************************************
+ * Make / Free API calls
+ ***************************************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//! Find all connected clock devices.
+/*!
+ * See uhd::device::find() for more details.
+ */
+UHD_API uhd_error uhd_usrp_clock_find(
+ const char* args,
+ uhd_string_vector_t *devices_out
+);
+
+//! Create a clock handle.
+/*!
+ * \param h The handle
+ * \param args Device args (e.g. "addr=192.168.10.3")
+ */
+UHD_API uhd_error uhd_usrp_clock_make(
+ uhd_usrp_clock_handle *h,
+ const char *args
+);
+
+//! Safely destroy the clock object underlying the handle.
+/*!
+ * Note: After calling this, usage of h may cause segmentation faults.
+ * However, multiple calling of uhd_usrp_free() is safe.
+ */
+UHD_API uhd_error uhd_usrp_clock_free(
+ uhd_usrp_clock_handle *h
+);
+
+//! Get last error
+UHD_API uhd_error uhd_usrp_clock_last_error(
+ uhd_usrp_clock_handle h,
+ char* error_out,
+ size_t strbuffer_len
+);
+
+//! Get board information in a nice output
+UHD_API uhd_error uhd_usrp_clock_get_pp_string(
+ uhd_usrp_clock_handle h,
+ char* pp_string_out,
+ size_t strbuffer_len
+);
+
+//! Get number of boards
+UHD_API uhd_error uhd_usrp_clock_get_num_boards(
+ uhd_usrp_clock_handle h,
+ size_t *num_boards_out
+);
+
+//! Get time
+UHD_API uhd_error uhd_usrp_clock_get_time(
+ uhd_usrp_clock_handle h,
+ size_t board,
+ uint32_t *clock_time_out
+);
+
+//! Get sensor
+UHD_API uhd_error uhd_usrp_clock_get_sensor(
+ uhd_usrp_clock_handle h,
+ const char* name,
+ size_t board,
+ uhd_sensor_value_handle *sensor_value_out
+);
+
+//! Get sensor names
+UHD_API uhd_error uhd_usrp_clock_get_sensor_names(
+ uhd_usrp_clock_handle h,
+ size_t board,
+ uhd_string_vector_handle *sensor_names_out
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_USRP_CLOCK_H */
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt
index 6b3d5a581..af6d3ee47 100644
--- a/host/include/uhd/utils/CMakeLists.txt
+++ b/host/include/uhd/utils/CMakeLists.txt
@@ -42,3 +42,11 @@ UHD_INSTALL(FILES
DESTINATION ${INCLUDE_DIR}/uhd/utils
COMPONENT headers
)
+
+IF(ENABLE_C_API)
+ UHD_INSTALL(FILES
+ thread_priority.h
+ DESTINATION ${INCLUDE_DIR}/uhd/utils
+ COMPONENT headers
+ )
+ENDIF(ENABLE_C_API)
diff --git a/host/include/uhd/utils/dirty_tracked.hpp b/host/include/uhd/utils/dirty_tracked.hpp
new file mode 100644
index 000000000..d228a9e65
--- /dev/null
+++ b/host/include/uhd/utils/dirty_tracked.hpp
@@ -0,0 +1,132 @@
+//
+// Copyright 2010-2014 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_UTILS_DIRTY_TRACKED_HPP
+#define INCLUDED_UHD_UTILS_DIRTY_TRACKED_HPP
+
+namespace uhd{
+ /*!
+ * A class that wraps a data value with a dirty flag
+ * When the client uses the assignment operator on this object, the object
+ * automatically dirties itself if the assigned type is not equal the underlying
+ * data. Data can be cleaned using the mark_clean entry-point.
+ *
+ * Requirements for data_t
+ * - Must have a default constructor
+ * - Must have a copy constructor
+ * - Must have an assignment operator (=)
+ * - Must have an equality operator (==)
+ */
+ template<typename data_t>
+ class dirty_tracked {
+ public:
+ /*!
+ * Default ctor: Initialize to default value and dirty
+ */
+ dirty_tracked() :
+ _data(), //data_t must have a default ctor
+ _dirty(true)
+ {}
+
+ /*!
+ * Initialize to specified value and dirty
+ */
+ dirty_tracked(const data_t& value) :
+ _data(value), //data_t must have a copy ctor
+ _dirty(true)
+ {}
+
+ /*!
+ * Copy ctor: Assign source to this type
+ */
+ dirty_tracked(const dirty_tracked& source) {
+ *this = source;
+ }
+
+ /*!
+ * Get underlying data
+ */
+ inline const data_t& get() const {
+ return _data;
+ }
+
+ /*!
+ * Has the underlying data changed since the last
+ * time it was cleaned?
+ */
+ inline bool is_dirty() const {
+ return _dirty;
+ }
+
+ /*!
+ * Mark the underlying data as clean
+ */
+ inline void mark_clean() {
+ _dirty = false;
+ }
+
+ /*!
+ * Mark the underlying data as dirty
+ */
+ inline void force_dirty() {
+ _dirty = true;
+ }
+
+ /*!
+ * Assignment with data.
+ * Store the specified value and mark it as dirty
+ * if it is not equal to the underlying data.
+ */
+ inline dirty_tracked& operator=(const data_t& value)
+ {
+ if(!(_data == value)) { //data_t must have an equality operator
+ _dirty = true;
+ _data = value; //data_t must have an assignment operator
+ }
+ return *this;
+ }
+
+ /*!
+ * Assignment with dirty tracked type.
+ * Store the specified value from dirty type and mark it as dirty
+ * if it is not equal to the underlying data.
+ * This exists to optimize out an implicit cast from dirty_tracked
+ * type to data type.
+ */
+ inline dirty_tracked& operator=(const dirty_tracked& source) {
+ if (!(_data == source._data)) {
+ _dirty = true;
+ _data = source._data;
+ }
+ return *this;
+ }
+
+ /*!
+ * Explicit conversion from this type to data_t
+ */
+ inline operator const data_t&() const {
+ return get();
+ }
+
+ private:
+ data_t _data;
+ bool _dirty;
+ };
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_UTILS_DIRTY_TRACKED_HPP */
diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp
index 2937ba802..ef7bfb6b7 100644
--- a/host/include/uhd/utils/math.hpp
+++ b/host/include/uhd/utils/math.hpp
@@ -18,11 +18,11 @@
#ifndef INCLUDED_UHD_UTILS_MATH_HPP
#define INCLUDED_UHD_UTILS_MATH_HPP
+#include <cmath>
#include <uhd/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/numeric/conversion/bounds.hpp>
-
namespace uhd {
/*!
@@ -237,6 +237,16 @@ namespace fp_compare {
== fp_compare::fp_compare_delta<double>(rhs, FREQ_COMPARISON_DELTA_HZ));
}
+ //! Portable log2()
+ template <typename float_t> UHD_INLINE
+ float_t log2(float_t x)
+ {
+ // C++11 defines std::log2(), when that's universally supported
+ // we can switch over.
+ return std::log(x) / std::log(float_t(2));
+ }
+
+
} // namespace math
} // namespace uhd
diff --git a/host/include/uhd/utils/paths.hpp b/host/include/uhd/utils/paths.hpp
index 0dbee3446..b97d3a55d 100644
--- a/host/include/uhd/utils/paths.hpp
+++ b/host/include/uhd/utils/paths.hpp
@@ -39,7 +39,7 @@ namespace uhd {
UHD_API std::string get_pkg_path(void);
//! Get UHD library paths
- std::vector<fs::path> get_module_paths(void);
+ UHD_API std::vector<fs::path> get_module_paths(void);
/*! Return the UHD images directory path.
*
@@ -58,7 +58,7 @@ namespace uhd {
* \param search_paths A comma-separated list of hints for paths to include.
* \returns A path string if one is found, or an empty string on failure.
*/
- UHD_API std::string get_images_dir(const std::string search_paths);
+ UHD_API std::string get_images_dir(const std::string &search_paths);
/*! Return the full path to particular UHD binary image.
*
@@ -72,7 +72,7 @@ namespace uhd {
* \return the full system path to the file
* \throw exception uhd::io_error if the file was not found.
*/
- UHD_API std::string find_image_path(const std::string &image_name, const std::string search_paths = "");
+ UHD_API std::string find_image_path(const std::string &image_name, const std::string &search_paths = "");
/*!
* Search for the location of a particular UHD utility.
@@ -80,14 +80,14 @@ namespace uhd {
* \param name the name of the utility to search for
* \return the full system path to the given utility
*/
- UHD_API std::string find_utility(std::string name);
+ UHD_API std::string find_utility(const std::string &name);
/*!
* Return an error string recommending the user run the utility.
* The error string will include the full path to the utility to run.
* \return the message suggesting the use of the named utility.
*/
- UHD_API std::string print_utility_error(std::string name);
+ UHD_API std::string print_utility_error(const std::string &name, const std::string &args = "");
} //namespace uhd
#endif /* INCLUDED_UHD_UTILS_PATHS_HPP */
diff --git a/host/include/uhd/utils/soft_register.hpp b/host/include/uhd/utils/soft_register.hpp
new file mode 100644
index 000000000..9006ab5c7
--- /dev/null
+++ b/host/include/uhd/utils/soft_register.hpp
@@ -0,0 +1,688 @@
+//
+// Copyright 2014 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_UTILS_SOFT_REGISTER_HPP
+#define INCLUDED_UHD_UTILS_SOFT_REGISTER_HPP
+
+#include <boost/cstdint.hpp>
+#include <boost/noncopyable.hpp>
+#include <uhd/types/wb_iface.hpp>
+#include <uhd/exception.hpp>
+#include <uhd/utils/dirty_tracked.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/unordered_map.hpp>
+#include <boost/tokenizer.hpp>
+#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
+#include <list>
+
+/*! \file soft_register.hpp
+ * Utilities to access and index hardware registers.
+ *
+ * This file contains three main utilities:
+ * - A soft_register wrapper class that can manage a soft-copy,
+ * do dirty tracking and allow symbolic access to various field
+ * of a register.
+ * - A register map class that can own multiple soft registers that
+ * share the same underlying control interface.
+ * - A register map database that can be used to collect multiple
+ * register maps and other databases to create a hierarchy of
+ * registers that can be accessed using the UHD register API.
+ */
+
+//==================================================================
+// Soft Register Definition
+//==================================================================
+
+#define UHD_DEFINE_SOFT_REG_FIELD(name, width, shift) \
+ static const uhd::soft_reg_field_t name = (((shift & 0xFF) << 8) | (width & 0xFF))
+
+namespace uhd {
+
+//TODO: These hints were added to boost 1.53.
+
+/** \brief hint for the branch prediction */
+inline bool likely(bool expr)
+{
+#ifdef __GNUC__
+ return __builtin_expect(expr, true);
+#else
+ return expr;
+#endif
+ }
+
+/** \brief hint for the branch prediction */
+inline bool unlikely(bool expr)
+{
+#ifdef __GNUC__
+ return __builtin_expect(expr, false);
+#else
+ return expr;
+#endif
+}
+
+/*!
+ * A register field is defined as a tuple of the mask and the shift.
+ * It can be used to make read-modify-write operations more convenient
+ * For efficiency reasons, it is recommended to always use a constant
+ * of this type because it will get optimized out by the compiler and
+ * will result in zero memory overhead
+ */
+typedef boost::uint32_t soft_reg_field_t;
+
+namespace soft_reg_field {
+ inline size_t width(const soft_reg_field_t field) {
+ return (field & 0xFF);
+ }
+
+ inline size_t shift(const soft_reg_field_t field) {
+ return ((field >> 8) & 0xFF);
+ }
+
+ template<typename data_t>
+ inline size_t mask(const soft_reg_field_t field) {
+ static const data_t ONE = static_cast<data_t>(1);
+ //Behavior for the left shift operation is undefined in C++
+ //if the shift amount is >= bitwidth of the datatype
+ //So we treat that as a special case with a branch predicition hint
+ if (likely((sizeof(data_t)*8) != width(field)))
+ return ((ONE<<width(field))-ONE)<<shift(field);
+ else
+ return (0-ONE)<<shift(field);
+ }
+}
+
+class soft_register_base : public boost::noncopyable {
+public:
+ virtual ~soft_register_base() {}
+
+ virtual void initialize(wb_iface& iface, bool sync = false) = 0;
+ virtual void flush() = 0;
+ virtual void refresh() = 0;
+ virtual size_t get_bitwidth() = 0;
+ virtual bool is_readable() = 0;
+ virtual bool is_writable() = 0;
+
+ /*!
+ * Cast the soft_register generic reference to a more specific type
+ */
+ template <typename soft_reg_t>
+ inline static soft_reg_t& cast(soft_register_base& reg) {
+ soft_reg_t* ptr = dynamic_cast<soft_reg_t*>(&reg);
+ if (ptr) {
+ return *ptr;
+ } else {
+ throw uhd::type_error("failed to cast register to specified type");
+ }
+ }
+};
+
+enum soft_reg_flush_mode_t { OPTIMIZED_FLUSH, ALWAYS_FLUSH };
+
+/*!
+ * Soft register object that holds offset, soft-copy and the control iface.
+ * Methods give convenient field-level access to soft-copy and the ability
+ * to do read-modify-write operations.
+ */
+template<typename reg_data_t, bool readable, bool writable>
+class UHD_API soft_register_t : public soft_register_base {
+public:
+ typedef boost::shared_ptr< soft_register_t<reg_data_t, readable, writable> > sptr;
+
+ //Reserved field. Represents all bits in the register.
+ UHD_DEFINE_SOFT_REG_FIELD(REGISTER, sizeof(reg_data_t)*8, 0); //[WIDTH-1:0]
+
+ /*!
+ * Generic constructor for all soft_register types
+ */
+ explicit soft_register_t(
+ wb_iface::wb_addr_type wr_addr,
+ wb_iface::wb_addr_type rd_addr,
+ soft_reg_flush_mode_t mode = ALWAYS_FLUSH):
+ _iface(NULL), _wr_addr(wr_addr), _rd_addr(rd_addr), _soft_copy(0), _flush_mode(mode)
+ {}
+
+ /*!
+ * Constructor for read-only, write-only registers and read-write registers
+ * with rd_addr == wr_addr
+ */
+ explicit soft_register_t(
+ wb_iface::wb_addr_type addr,
+ soft_reg_flush_mode_t mode = ALWAYS_FLUSH):
+ _iface(NULL), _wr_addr(addr), _rd_addr(addr), _soft_copy(0), _flush_mode(mode)
+ {}
+
+ /*!
+ * Initialize the register when the underlying bus is usable.
+ * Can be optionally synced with hardware.
+ * NOTE: Memory management of the iface is up to the caller
+ */
+ inline void initialize(wb_iface& iface, bool sync = false)
+ {
+ _iface = &iface;
+
+ //Synchronize with hardware. For RW register, flush THEN refresh.
+ if (sync && writable) flush();
+ if (sync && readable) refresh();
+ }
+
+ /*!
+ * Update specified field in the soft-copy with the arg value.
+ * Performs a read-modify-write operation so all other field are preserved.
+ * NOTE: This does not write the value to hardware.
+ */
+ inline void set(const soft_reg_field_t field, const reg_data_t value)
+ {
+ _soft_copy = (_soft_copy & ~soft_reg_field::mask<reg_data_t>(field)) |
+ ((value << soft_reg_field::shift(field)) & soft_reg_field::mask<reg_data_t>(field));
+ }
+
+ /*!
+ * Get the value of the specified field from the soft-copy.
+ * NOTE: This does not read anything from hardware.
+ */
+ inline reg_data_t get(const soft_reg_field_t field)
+ {
+ return (_soft_copy & soft_reg_field::mask<reg_data_t>(field)) >> soft_reg_field::shift(field);
+ }
+
+ /*!
+ * Write the contents of the soft-copy to hardware.
+ */
+ inline void flush()
+ {
+ if (writable && _iface) {
+ //If optimized flush then poke only if soft copy is dirty
+ //If flush mode is ALWAYS, the dirty flag should get optimized
+ //out by the compiler because it is never read
+ if (_flush_mode == ALWAYS_FLUSH || _soft_copy.is_dirty()) {
+ if (get_bitwidth() <= 16) {
+ _iface->poke16(_wr_addr, static_cast<boost::uint16_t>(_soft_copy));
+ } else if (get_bitwidth() <= 32) {
+ _iface->poke32(_wr_addr, static_cast<boost::uint32_t>(_soft_copy));
+ } else if (get_bitwidth() <= 64) {
+ _iface->poke64(_wr_addr, static_cast<boost::uint64_t>(_soft_copy));
+ } else {
+ throw uhd::not_implemented_error("soft_register only supports up to 64 bits.");
+ }
+ _soft_copy.mark_clean();
+ }
+ } else {
+ throw uhd::not_implemented_error("soft_register is not writable.");
+ }
+ }
+
+ /*!
+ * Read the contents of the register from hardware and update the soft copy.
+ */
+ inline void refresh()
+ {
+ if (readable && _iface) {
+ if (get_bitwidth() <= 16) {
+ _soft_copy = static_cast<reg_data_t>(_iface->peek16(_rd_addr));
+ } else if (get_bitwidth() <= 32) {
+ _soft_copy = static_cast<reg_data_t>(_iface->peek32(_rd_addr));
+ } else if (get_bitwidth() <= 64) {
+ _soft_copy = static_cast<reg_data_t>(_iface->peek64(_rd_addr));
+ } else {
+ throw uhd::not_implemented_error("soft_register only supports up to 64 bits.");
+ }
+ _soft_copy.mark_clean();
+ } else {
+ throw uhd::not_implemented_error("soft_register is not readable.");
+ }
+ }
+
+ /*!
+ * Shortcut for a set and a flush.
+ */
+ inline void write(const soft_reg_field_t field, const reg_data_t value)
+ {
+ set(field, value);
+ flush();
+ }
+
+ /*!
+ * Shortcut for refresh and get
+ */
+ inline reg_data_t read(const soft_reg_field_t field)
+ {
+ refresh();
+ return get(field);
+ }
+
+ /*!
+ * Get bitwidth for this register
+ */
+ inline size_t get_bitwidth()
+ {
+ static const size_t BITS_IN_BYTE = 8;
+ return sizeof(reg_data_t) * BITS_IN_BYTE;
+ }
+
+ /*!
+ * Is the register readable?
+ */
+ inline bool is_readable()
+ {
+ return readable;
+ }
+
+ /*!
+ * Is the register writable?
+ */
+ inline bool is_writable()
+ {
+ return writable;
+ }
+
+private:
+ wb_iface* _iface;
+ const wb_iface::wb_addr_type _wr_addr;
+ const wb_iface::wb_addr_type _rd_addr;
+ dirty_tracked<reg_data_t> _soft_copy;
+ const soft_reg_flush_mode_t _flush_mode;
+};
+
+/*!
+ * A synchronized soft register object.
+ * All operations in the synchronized register are serialized.
+ */
+template<typename reg_data_t, bool readable, bool writable>
+class UHD_API soft_register_sync_t : public soft_register_t<reg_data_t, readable, writable> {
+public:
+ typedef boost::shared_ptr< soft_register_sync_t<reg_data_t, readable, writable> > sptr;
+
+ explicit soft_register_sync_t(
+ wb_iface::wb_addr_type wr_addr,
+ wb_iface::wb_addr_type rd_addr,
+ soft_reg_flush_mode_t mode = ALWAYS_FLUSH):
+ soft_register_t<reg_data_t, readable, writable>(wr_addr, rd_addr, mode), _mutex()
+ {}
+
+ explicit soft_register_sync_t(
+ wb_iface::wb_addr_type addr,
+ soft_reg_flush_mode_t mode = ALWAYS_FLUSH):
+ soft_register_t<reg_data_t, readable, writable>(addr, mode), _mutex()
+ {}
+
+ inline void initialize(wb_iface& iface, bool sync = false)
+ {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ soft_register_t<reg_data_t, readable, writable>::initialize(iface, sync);
+ }
+
+ inline void set(const soft_reg_field_t field, const reg_data_t value)
+ {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ soft_register_t<reg_data_t, readable, writable>::set(field, value);
+ }
+
+ inline reg_data_t get(const soft_reg_field_t field)
+ {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ return soft_register_t<reg_data_t, readable, writable>::get(field);
+ }
+
+ inline void flush()
+ {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ soft_register_t<reg_data_t, readable, writable>::flush();
+ }
+
+ inline void refresh()
+ {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ soft_register_t<reg_data_t, readable, writable>::refresh();
+ }
+
+ inline void write(const soft_reg_field_t field, const reg_data_t value)
+ {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ soft_register_t<reg_data_t, readable, writable>::write(field, value);
+ }
+
+ inline reg_data_t read(const soft_reg_field_t field)
+ {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ return soft_register_t<reg_data_t, readable, writable>::read(field);
+ }
+
+private:
+ boost::mutex _mutex;
+};
+
+/*
+ * Register Shortcut Formats:
+ * - soft_reg<bits>_<mode>_t: Soft register object with an unsynchronized soft-copy.
+ * Thread unsafe but lightweight. Mostly const propagated.
+ * - soft_reg<bits>_<mode>_sync_t: Soft register object with a synchronized soft-copy.
+ * Thread safe but with memory/speed overhead.
+ * where:
+ * - <bits> = {16, 32 or 64}
+ * - <mode> = {wo(write-only), rw(read-write) or ro(read-only)}
+ *
+ */
+
+//16-bit shortcuts
+typedef soft_register_t<boost::uint16_t, false, true> soft_reg16_wo_t;
+typedef soft_register_t<boost::uint16_t, true, false> soft_reg16_ro_t;
+typedef soft_register_t<boost::uint16_t, true, true> soft_reg16_rw_t;
+typedef soft_register_sync_t<boost::uint16_t, false, true> soft_reg16_wo_sync_t;
+typedef soft_register_sync_t<boost::uint16_t, true, false> soft_reg16_ro_sync_t;
+typedef soft_register_sync_t<boost::uint16_t, true, true> soft_reg16_rw_sync_t;
+//32-bit shortcuts
+typedef soft_register_t<boost::uint32_t, false, true> soft_reg32_wo_t;
+typedef soft_register_t<boost::uint32_t, true, false> soft_reg32_ro_t;
+typedef soft_register_t<boost::uint32_t, true, true> soft_reg32_rw_t;
+typedef soft_register_sync_t<boost::uint32_t, false, true> soft_reg32_wo_sync_t;
+typedef soft_register_sync_t<boost::uint32_t, true, false> soft_reg32_ro_sync_t;
+typedef soft_register_sync_t<boost::uint32_t, true, true> soft_reg32_rw_sync_t;
+//64-bit shortcuts
+typedef soft_register_t<boost::uint64_t, false, true> soft_reg64_wo_t;
+typedef soft_register_t<boost::uint64_t, true, false> soft_reg64_ro_t;
+typedef soft_register_t<boost::uint64_t, true, true> soft_reg64_rw_t;
+typedef soft_register_sync_t<boost::uint64_t, false, true> soft_reg64_wo_sync_t;
+typedef soft_register_sync_t<boost::uint64_t, true, false> soft_reg64_ro_sync_t;
+typedef soft_register_sync_t<boost::uint64_t, true, true> soft_reg64_rw_sync_t;
+
+
+/*
+ * Usage example
+ *
+ //===Define bit width, RW mode, and synchronization using base class===
+ class example_reg_t : public soft_reg32_wo_sync_t (or soft_reg32_wo_t) {
+ public:
+ //===Define all the fields===
+ UHD_DEFINE_SOFT_REG_FIELD(FIELD0, 1, 0); //[0]
+ UHD_DEFINE_SOFT_REG_FIELD(FIELD1, 15, 1); //[15:1]
+ UHD_DEFINE_SOFT_REG_FIELD(FIELD2, 16, 16); //[31:16]
+
+ example_reg_t(): //ctor with no args
+ soft_reg32_wo_t(SR_CORE_EXAMPLE_REG_OFFSET)) //===Bind to offset===
+ {
+ //===Set Initial values===
+ set(FIELD0, 0);
+ set(FIELD1, 1);
+ set(FIELD2, 0xFFFF);
+ }
+ }; //===Full register definition encapsulated in one class===
+
+ void main() {
+ example_reg_t reg_obj;
+ reg_obj.initialize(iface);
+ reg_obj.write(example_reg_t::FIELD2, 0x1234);
+
+ example_reg_t::sptr reg_sptr = boost::make_shared<example_reg_t>();
+ reg_obj->initialize(iface);
+ reg_obj->write(example_reg_t::FIELD2, 0x1234);
+ }
+*/
+}
+
+//==================================================================
+// Soft Register Map and Database Definition
+//==================================================================
+
+namespace uhd {
+
+class UHD_API soft_regmap_accessor_t {
+public:
+ typedef boost::shared_ptr<soft_regmap_accessor_t> sptr;
+
+ virtual ~soft_regmap_accessor_t() {};
+ virtual soft_register_base& lookup(const std::string& path) const = 0;
+ virtual std::vector<std::string> enumerate() const = 0;
+ virtual const std::string& get_name() const = 0;
+};
+
+/*!
+ * A regmap is a collection of registers that share the same
+ * bus (control iface). A regmap must have an identifier.
+ * A regmap must manage storage for each register.
+ * The recommended way to use a regmap is to define individual registers
+ * within the scope of the regmap and instantiate them in the ragmap.
+ * Soft register object that holds offset, soft-copy and the control iface.
+ * Methods give convenient field-level access to soft-copy and the ability
+ * to do read-modify-write operations.
+ */
+class UHD_API soft_regmap_t : public soft_regmap_accessor_t, public boost::noncopyable {
+public:
+ soft_regmap_t(const std::string& name) : _name(name) {}
+ virtual ~soft_regmap_t() {};
+
+ /*!
+ * Get the name of this register map
+ */
+ virtual inline const std::string& get_name() const { return _name; }
+
+ /*!
+ * Initialize all registers in this register map using a bus.
+ * Optionally synchronize the register with hardware.
+ * The order of initialization is the same as the order in
+ * which registers were added to the map.
+ */
+ void initialize(wb_iface& iface, bool sync = false) {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ BOOST_FOREACH(soft_register_base* reg, _reglist) {
+ reg->initialize(iface, sync);
+ }
+ }
+
+ /*!
+ * Flush all registers to hardware.
+ * The order of writing is the same as the order in
+ * which registers were added to the map.
+ */
+ void flush() {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ BOOST_FOREACH(soft_register_base* reg, _reglist) {
+ reg->flush();
+ }
+ }
+
+ /*!
+ * Refresh all register soft-copies from hardware.
+ * The order of reading is the same as the order in
+ * which registers were added to the map.
+ */
+ void refresh() {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ BOOST_FOREACH(soft_register_base* reg, _reglist) {
+ reg->refresh();
+ }
+ }
+
+ /*!
+ * Lookup a register object by name.
+ * If a register with "name" is not found, runtime_error is thrown
+ */
+ virtual soft_register_base& lookup(const std::string& name) const {
+ regmap_t::const_iterator iter = _regmap.find(name);
+ if (iter != _regmap.end()) {
+ return *(iter->second);
+ } else {
+ throw uhd::runtime_error("register not found in map: " + name);
+ }
+ }
+
+ /*!
+ * Enumerate all the registers in this map.
+ * Return fully qualified paths.
+ */
+ virtual std::vector<std::string> enumerate() const {
+ std::vector<std::string> temp;
+ BOOST_FOREACH(const regmap_t::value_type& reg, _regmap) {
+ temp.push_back(_name + "/" + reg.first);
+ }
+ return temp;
+ }
+
+protected:
+ enum visibility_t {
+ PUBLIC, //Is accessible through the soft_regmap_accessor_t interface
+ PRIVATE //Is NOT accessible through the soft_regmap_accessor_t interface
+ };
+
+ /*!
+ * Add a register to this map with an identifier "name" and visibility
+ */
+ inline void add_to_map(soft_register_base& reg, const std::string& name, const visibility_t visible = PRIVATE) {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ if (visible == PUBLIC) {
+ //Only add to the map if this register is publicly visible
+ if (not _regmap.insert(regmap_t::value_type(name, &reg)).second) {
+ throw uhd::assertion_error("cannot add two registers with the same name to regmap: " + name);
+ }
+ }
+ _reglist.push_back(&reg);
+ }
+
+private:
+ typedef boost::unordered_map<std::string, soft_register_base*> regmap_t;
+ typedef std::list<soft_register_base*> reglist_t;
+
+ const std::string _name;
+ regmap_t _regmap; //For lookups
+ reglist_t _reglist; //To maintain order
+ boost::mutex _mutex;
+};
+
+
+/*!
+ * A regmap database is a collection of regmaps or other regmap databases
+ * this allows for efficient encapsulation for multiple registers in a hierarchical
+ * fashion.
+ * A regmap_db *does not* manage storage for regmaps. It is simply a wrapper.
+ */
+class UHD_API soft_regmap_db_t : public soft_regmap_accessor_t, public boost::noncopyable {
+public:
+ typedef boost::shared_ptr<soft_regmap_db_t> sptr;
+
+ /*!
+ * Use the default constructor if this is the top-level DB
+ */
+ soft_regmap_db_t() : _name("") {}
+
+ /*!
+ * Use this constructor if this is a nested DB
+ */
+ soft_regmap_db_t(const std::string& name) : _name(name) {}
+
+ /*!
+ * Get the name of this register map
+ */
+ const std::string& get_name() const { return _name; }
+
+ /*!
+ * Add a regmap to this map with an identifier "name" and visibility
+ */
+ void add(soft_regmap_t& regmap) {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ _regmaps.push_back(&regmap);
+ }
+
+ /*!
+ * Add a level of regmap_db to this map with an identifier "name" and visibility
+ */
+ void add(soft_regmap_db_t& db) {
+ boost::lock_guard<boost::mutex> lock(_mutex);
+ if (&db == this) {
+ throw uhd::assertion_error("cannot add regmap db to itself" + _name);
+ } else {
+ _regmap_dbs.push_back(&db);
+ }
+ }
+
+ /*!
+ * Lookup a register by path.
+ * A path is defined as a string of "/" separated tokens that scope a register.
+ * The leaf (last token) is the name of the register
+ * The token immediately before the leaf is the name of the register map
+ * If a nested regmap_db is used, the token before the regmap is the db name.
+ * For every nested db, the path has an additional token.
+ * For example:
+ * radio0/spi_regmap/spi_control_reg
+ */
+ soft_register_base& lookup(const std::string& path) const
+ {
+ //Turn the slash separated path string into tokens
+ std::list<std::string> tokens;
+ BOOST_FOREACH(
+ const std::string& node,
+ boost::tokenizer< boost::char_separator<char> >(path, boost::char_separator<char>("/")))
+ {
+ tokens.push_back(node);
+ }
+ if ((tokens.size() > 2 && tokens.front() == _name) || //If this is a nested DB
+ (tokens.size() > 1 && _name == "")) { //If this is a top-level DB
+ if (_name != "") tokens.pop_front();
+ if (tokens.size() == 2) { //2 tokens => regmap/register path
+ BOOST_FOREACH(const soft_regmap_accessor_t* regmap, _regmaps) {
+ if (regmap->get_name() == tokens.front()) {
+ return regmap->lookup(tokens.back());
+ }
+ }
+ throw uhd::runtime_error("could not find register map: " + path);
+ } else if (not _regmap_dbs.empty()) { //>2 tokens => <1 or more dbs>/regmap/register
+ //Reconstruct path from tokens
+ std::string newpath;
+ BOOST_FOREACH(const std::string& node, tokens) {
+ newpath += ("/" + node);
+ }
+ //Dispatch path to hierarchical DB
+ BOOST_FOREACH(const soft_regmap_accessor_t* db, _regmap_dbs) {
+ try {
+ return db->lookup(newpath.substr(1));
+ } catch (std::exception& e) {
+ continue;
+ }
+ }
+ }
+ }
+ throw uhd::runtime_error("could not find register: " + path);
+ }
+
+ /*!
+ * Enumerate the paths of all registers that this DB can access
+ */
+ virtual std::vector<std::string> enumerate() const {
+ std::vector<std::string> paths;
+ BOOST_FOREACH(const soft_regmap_accessor_t* regmap, _regmaps) {
+ const std::vector<std::string>& regs = regmap->enumerate();
+ paths.insert(paths.end(), regs.begin(), regs.end());
+ }
+ BOOST_FOREACH(const soft_regmap_accessor_t* db, _regmap_dbs) {
+ const std::vector<std::string>& regs = db->enumerate();
+ paths.insert(paths.end(), regs.begin(), regs.end());
+ }
+ return paths;
+ }
+
+private:
+ typedef std::list<soft_regmap_accessor_t*> db_t;
+
+ const std::string _name;
+ db_t _regmaps;
+ db_t _regmap_dbs;
+ boost::mutex _mutex;
+};
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_UTILS_SOFT_REGISTER_HPP */
diff --git a/host/include/uhd/utils/thread_priority.h b/host/include/uhd/utils/thread_priority.h
new file mode 100644
index 000000000..217d7a1cc
--- /dev/null
+++ b/host/include/uhd/utils/thread_priority.h
@@ -0,0 +1,53 @@
+//
+// Copyright 2015 Ettus Research LLC
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_UTILS_THREAD_PRIORITY_H
+#define INCLUDED_UHD_UTILS_THREAD_PRIORITY_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static const float uhd_default_thread_priority = 0.5;
+
+/*!
+ * Set the scheduling priority on the current thread.
+ *
+ * A new thread or calling process should make this call
+ * with the defailts this to enable realtime scheduling.
+ *
+ * A priority of zero corresponds to normal priority.
+ * Positive priority values are higher than normal.
+ * Negative priority values are lower than normal.
+ *
+ * \param priority a value between -1 and 1
+ * \param realtime true to use realtime mode
+ * \return UHD error code
+ */
+UHD_API uhd_error uhd_set_thread_priority(
+ float priority,
+ bool realtime
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_UTILS_THREAD_PRIORITY_H */
diff --git a/host/include/uhd/version.hpp.in b/host/include/uhd/version.hpp.in
index 2d578d77e..e2c64812d 100644
--- a/host/include/uhd/version.hpp.in
+++ b/host/include/uhd/version.hpp.in
@@ -27,7 +27,7 @@
* The format is oldest API compatible release - ABI compat number.
* The compatibility number allows pre-release ABI to be versioned.
*/
-#define UHD_VERSION_ABI_STRING "3.8.2-0"
+#define UHD_VERSION_ABI_STRING "3.9.0-0"
/*!
* A macro to check UHD version at compile-time.