From 91347ea2cbf7618d4439548210eec940c582cbb8 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 8 Oct 2014 14:44:49 +0200 Subject: uhd: Added sid_t This is a data type to represent SIDs (stream IDs). It includes setters and getters for all components of the SID, converters to and from string and uint32 as well as C++ streams. --- host/include/uhd/types/CMakeLists.txt | 1 + host/include/uhd/types/sid.hpp | 238 ++++++++++++++++++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100644 host/include/uhd/types/sid.hpp (limited to 'host/include') diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt index 334f1b41b..66b8662a1 100644 --- a/host/include/uhd/types/CMakeLists.txt +++ b/host/include/uhd/types/CMakeLists.txt @@ -29,6 +29,7 @@ UHD_INSTALL(FILES ref_vector.hpp sensors.hpp serial.hpp + sid.hpp stream_cmd.hpp time_spec.hpp tune_request.hpp diff --git a/host/include/uhd/types/sid.hpp b/host/include/uhd/types/sid.hpp new file mode 100644 index 000000000..12f98ff97 --- /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 . +// + +#ifndef INCLUDED_UHD_TYPES_SID_HPP +#define INCLUDED_UHD_TYPES_SID_HPP + +#include +#include +#include +#include + +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 + * + * 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 + * + * 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: -- cgit v1.2.3 From 27aa985f450a7d2312f8731991d4e4e9ec122e8d Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 23 Oct 2014 18:07:07 +0200 Subject: math: Added a portable log2() --- host/include/uhd/utils/math.hpp | 12 +++++++++++- host/tests/CMakeLists.txt | 1 + host/tests/math_test.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 host/tests/math_test.cpp (limited to 'host/include') diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp index 21825c3dc..a41a35d67 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 #include #include #include - namespace uhd { /*! @@ -237,6 +237,16 @@ namespace fp_compare { == fp_compare::fp_compare_delta(rhs, FREQ_COMPARISON_DELTA_HZ)); } + //! Portable log2() + template 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(2); + } + + } // namespace math } // namespace uhd diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index ea0b30cb8..579fd46ca 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -34,6 +34,7 @@ SET(test_sources fp_compare_delta_test.cpp fp_compare_epsilon_test.cpp gain_group_test.cpp + math_test.cpp msg_test.cpp property_test.cpp ranges_test.cpp diff --git a/host/tests/math_test.cpp b/host/tests/math_test.cpp new file mode 100644 index 000000000..6c890c484 --- /dev/null +++ b/host/tests/math_test.cpp @@ -0,0 +1,29 @@ +// +// 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 . +// + +#include +#include +#include + +// NOTE: This is not the only math test case, see e.g. special tests +// for fp comparison. + +BOOST_AUTO_TEST_CASE(test_log2){ + double y = uhd::math::log2(16.0); + BOOST_CHECK_EQUAL(y, 4.0); +} + -- cgit v1.2.3 From beabf3d302a98a0a1e28ae8cc4d338f0bd13db6e Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Mon, 3 Nov 2014 17:05:26 -0800 Subject: uhd: replaced the `images_error` with a generic utility error - Deleted images.*, moved functionality to paths.* - Applies for all devices that check FPGA or FW compat numbers - Adds generic utility search tool --- host/include/uhd/utils/CMakeLists.txt | 1 - host/include/uhd/utils/images.hpp | 53 ----------------------- host/include/uhd/utils/paths.hpp | 25 +++++++++++ host/lib/usrp/b100/b100_impl.cpp | 10 ++--- host/lib/usrp/b100/b100_impl.hpp | 2 +- host/lib/usrp/b200/b200_impl.cpp | 15 +++---- host/lib/usrp/b200/b200_impl.hpp | 6 +-- host/lib/usrp/e100/e100_impl.cpp | 4 +- host/lib/usrp/e300/e300_impl.cpp | 4 +- host/lib/usrp/e300/e300_network.cpp | 2 +- host/lib/usrp/usrp1/usrp1_impl.cpp | 4 +- host/lib/usrp/usrp2/usrp2_iface.cpp | 8 ++-- host/lib/usrp/x300/x300_impl.cpp | 14 +++--- host/lib/usrp_clock/octoclock/octoclock_impl.cpp | 6 +-- host/lib/utils/CMakeLists.txt | 1 - host/lib/utils/images.cpp | 54 ------------------------ host/lib/utils/paths.cpp | 37 ++++++++++++++-- host/utils/b2xx_fx3_utils.cpp | 2 +- host/utils/octoclock_firmware_burner.cpp | 2 +- host/utils/usrp_n2xx_simple_net_burner.cpp | 2 +- host/utils/usrp_x3xx_fpga_burner.cpp | 2 +- 21 files changed, 99 insertions(+), 155 deletions(-) delete mode 100644 host/include/uhd/utils/images.hpp delete mode 100644 host/lib/utils/images.cpp (limited to 'host/include') diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index c308c9cde..05f6892d2 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -25,7 +25,6 @@ UHD_INSTALL(FILES cast.hpp csv.hpp gain_group.hpp - images.hpp log.hpp math.hpp msg.hpp diff --git a/host/include/uhd/utils/images.hpp b/host/include/uhd/utils/images.hpp deleted file mode 100644 index a0934fb08..000000000 --- a/host/include/uhd/utils/images.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// 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 . -// - -#ifndef INCLUDED_UHD_UTILS_IMAGES_HPP -#define INCLUDED_UHD_UTILS_IMAGES_HPP - -#include -#include - -namespace uhd{ - - /*! - * Search for an image in the system image paths: - * Search compiled-in paths and environment variable paths - * for a specific image file with the provided file name. - * \param image_name the name of the file - * \return the full system path to the file - * \throw exception if the image was not found - */ - UHD_API std::string find_image_path(const std::string &image_name); - - /*! - * Search for the location of the UHD Images Downloader script. - * \return the full system path to uhd_images_downloader.py - */ - - UHD_API std::string find_images_downloader(void); - - /*! - * Return the error string for recommending using the UHD Images Downloader. - * String depends on OS. - * \return the message suggesting the use of uhd_images_downloader.py - */ - - UHD_API std::string print_images_error(void); - -} //namespace uhd - -#endif /* INCLUDED_UHD_UTILS_IMAGES_HPP */ diff --git a/host/include/uhd/utils/paths.hpp b/host/include/uhd/utils/paths.hpp index e0f455e92..c1f32ba61 100644 --- a/host/include/uhd/utils/paths.hpp +++ b/host/include/uhd/utils/paths.hpp @@ -32,6 +32,31 @@ namespace uhd{ //! Get a string representing the system's pkg directory UHD_API std::string get_pkg_path(void); + /*! + * Search for an image in the system image paths: + * Search compiled-in paths and environment variable paths + * for a specific image file with the provided file name. + * \param image_name the name of the file + * \return the full system path to the file + * \throw exception if the image was not found + */ + UHD_API std::string find_image_path(const std::string &image_name); + + /*! + * Search for the location of a particular UHD utility. + * The utility must be installed in the `uhd/utils` directory. + * \param the name of the utility to search for + * \return the full system path to @param + */ + UHD_API std::string find_utility(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); + } //namespace uhd #endif /* INCLUDED_UHD_UTILS_PATHS_HPP */ diff --git a/host/lib/usrp/b100/b100_impl.cpp b/host/lib/usrp/b100/b100_impl.cpp index 24a87a3c8..c4279913c 100644 --- a/host/lib/usrp/b100/b100_impl.cpp +++ b/host/lib/usrp/b100/b100_impl.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -82,7 +82,7 @@ static device_addrs_t b100_find(const device_addr_t &hint) b100_fw_image = find_image_path(hint.get("fw", B100_FW_FILE_NAME)); } catch(...){ - UHD_MSG(warning) << boost::format("Could not locate B100 firmware. %s\n") % print_images_error(); + UHD_MSG(warning) << boost::format("Could not locate B100 firmware. %s\n") % print_utility_error("uhd_images_downloader.py"); return b100_addrs; } UHD_LOG << "the firmware image: " << b100_fw_image << std::endl; @@ -532,10 +532,10 @@ void b100_impl::check_fw_compat(void){ ); if (fw_compat_num != B100_FW_COMPAT_NUM){ throw uhd::runtime_error(str(boost::format( - "Expected firmware compatibility number 0x%x, but got 0x%x:\n" + "Expected firmware compatibility number %d, but got %d:\n" "The firmware build is not compatible with the host code build.\n" "%s" - ) % B100_FW_COMPAT_NUM % fw_compat_num % print_images_error())); + ) % int(B100_FW_COMPAT_NUM) % fw_compat_num % print_utility_error("uhd_images_downloader.py"))); } _tree->create("/mboards/0/fw_version").set(str(boost::format("%u.0") % fw_compat_num)); } @@ -552,7 +552,7 @@ void b100_impl::check_fpga_compat(void){ "Expected FPGA compatibility number %d, but got %d:\n" "The FPGA build is not compatible with the host code build." "%s" - ) % int(B100_FPGA_COMPAT_NUM) % fpga_major % print_images_error())); + ) % int(B100_FPGA_COMPAT_NUM) % fpga_major % print_utility_error("uhd_images_downloader.py"))); } _tree->create("/mboards/0/fpga_version").set(str(boost::format("%u.%u") % fpga_major % fpga_minor)); } diff --git a/host/lib/usrp/b100/b100_impl.hpp b/host/lib/usrp/b100/b100_impl.hpp index 59ea2202e..dbca543be 100644 --- a/host/lib/usrp/b100/b100_impl.hpp +++ b/host/lib/usrp/b100/b100_impl.hpp @@ -46,7 +46,7 @@ static const double B100_LINK_RATE_BPS = 256e6/5; //pratical link rate (< 480 Mbps) static const std::string B100_FW_FILE_NAME = "usrp_b100_fw.ihx"; static const std::string B100_FPGA_FILE_NAME = "usrp_b100_fpga.bin"; -static const boost::uint16_t B100_FW_COMPAT_NUM = 0x04; +static const boost::uint16_t B100_FW_COMPAT_NUM = 4; static const boost::uint16_t B100_FPGA_COMPAT_NUM = 11; static const boost::uint32_t B100_RX_SID_BASE = 30; static const boost::uint32_t B100_TX_ASYNC_SID = 10; diff --git a/host/lib/usrp/b200/b200_impl.cpp b/host/lib/usrp/b200/b200_impl.cpp index 6d1172c98..b3c190c50 100644 --- a/host/lib/usrp/b200/b200_impl.cpp +++ b/host/lib/usrp/b200/b200_impl.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -115,7 +115,7 @@ static device_addrs_t b200_find(const device_addr_t &hint) UHD_MSG(warning) << boost::format( "Could not locate B200 firmware.\n" "Please install the images package. %s\n" - ) % print_images_error(); + ) % print_utility_error("uhd_images_downloader.py"); return b200_addrs; } UHD_LOG << "the firmware image: " << b200_fw_image << std::endl; @@ -791,11 +791,11 @@ void b200_impl::check_fw_compat(void) if (compat_major != B200_FW_COMPAT_NUM_MAJOR){ throw uhd::runtime_error(str(boost::format( - "Expected firmware compatibility number 0x%x, but got 0x%x.%x:\n" + "Expected firmware compatibility number %d.%d, but got %d.%d:\n" "The firmware build is not compatible with the host code build.\n" "%s" - ) % int(B200_FW_COMPAT_NUM_MAJOR) % compat_major % compat_minor - % print_images_error())); + ) % int(B200_FW_COMPAT_NUM_MAJOR) % int(B200_FW_COMPAT_NUM_MINOR) + % compat_major % compat_minor % print_utility_error("uhd_images_downloader.py"))); } _tree->create("/mboards/0/fw_version").set(str(boost::format("%u.%u") % compat_major % compat_minor)); @@ -812,11 +812,10 @@ void b200_impl::check_fpga_compat(void) if (compat_major != B200_FPGA_COMPAT_NUM){ throw uhd::runtime_error(str(boost::format( - "Expected FPGA compatibility number 0x%x, but got 0x%x.%x:\n" + "Expected FPGA compatibility number %d, but got %d:\n" "The FPGA build is not compatible with the host code build.\n" "%s" - ) % int(B200_FPGA_COMPAT_NUM) % compat_major % compat_minor - % print_images_error())); + ) % int(B200_FPGA_COMPAT_NUM) % compat_major % print_utility_error("uhd_images_downloader.py"))); } _tree->create("/mboards/0/fpga_version").set(str(boost::format("%u.%u") % compat_major % compat_minor)); diff --git a/host/lib/usrp/b200/b200_impl.hpp b/host/lib/usrp/b200/b200_impl.hpp index 22e962bd5..71592f60b 100644 --- a/host/lib/usrp/b200/b200_impl.hpp +++ b/host/lib/usrp/b200/b200_impl.hpp @@ -45,9 +45,9 @@ #include #include #include "recv_packet_demuxer_3000.hpp" -static const boost::uint8_t B200_FW_COMPAT_NUM_MAJOR = 0x07; -static const boost::uint8_t B200_FW_COMPAT_NUM_MINOR = 0x00; -static const boost::uint16_t B200_FPGA_COMPAT_NUM = 0x04; +static const boost::uint8_t B200_FW_COMPAT_NUM_MAJOR = 7; +static const boost::uint8_t B200_FW_COMPAT_NUM_MINOR = 0; +static const boost::uint16_t B200_FPGA_COMPAT_NUM = 4; static const double B200_BUS_CLOCK_RATE = 100e6; static const double B200_DEFAULT_TICK_RATE = 32e6; static const double B200_DEFAULT_FREQ = 100e6; // Hz diff --git a/host/lib/usrp/e100/e100_impl.cpp b/host/lib/usrp/e100/e100_impl.cpp index 8b4f2316c..ac419e0e0 100644 --- a/host/lib/usrp/e100/e100_impl.cpp +++ b/host/lib/usrp/e100/e100_impl.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -132,7 +132,7 @@ e100_impl::e100_impl(const uhd::device_addr_t &device_addr){ e100_fpga_image = find_image_path(device_addr.get("fpga", default_fpga_file_name)); } catch(...){ - UHD_MSG(error) << boost::format("Could not find FPGA image. %s\n") % print_images_error(); + UHD_MSG(error) << boost::format("Could not find FPGA image. %s\n") % print_utility_error("uhd_images_downloader.py"); throw; } e100_load_fpga(e100_fpga_image); diff --git a/host/lib/usrp/e300/e300_impl.cpp b/host/lib/usrp/e300/e300_impl.cpp index e42ac390e..8807a56e4 100644 --- a/host/lib/usrp/e300/e300_impl.cpp +++ b/host/lib/usrp/e300/e300_impl.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -397,7 +397,7 @@ e300_impl::e300_impl(const uhd::device_addr_t &device_addr) "%s" ) % fpga::COMPAT_MAJOR % _get_version(FPGA_MAJOR) % _get_version(FPGA_MINOR) - % print_images_error())); + % print_utility_error("uhd_images_downloader.py"))); } //////////////////////////////////////////////////////////////////// diff --git a/host/lib/usrp/e300/e300_network.cpp b/host/lib/usrp/e300/e300_network.cpp index 883ff0c4f..59e1eec86 100644 --- a/host/lib/usrp/e300/e300_network.cpp +++ b/host/lib/usrp/e300/e300_network.cpp @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 709092e42..dbd5408e8 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -85,7 +85,7 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) usrp1_fw_image = find_image_path(hint.get("fw", "usrp1_fw.ihx")); } catch(...){ - UHD_MSG(warning) << boost::format("Could not locate USRP1 firmware. %s") % print_images_error(); + UHD_MSG(warning) << boost::format("Could not locate USRP1 firmware. %s") % print_utility_error("uhd_images_downloader.py"); } UHD_LOG << "USRP1 firmware image: " << usrp1_fw_image << std::endl; diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index b2085807f..65cf90a17 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -375,7 +375,7 @@ public: fpga_image_path = uhd::find_image_path(fpga_image); } catch(const std::exception &){ - return str(boost::format("Could not find %s and %s in your images path!\n%s") % fw_image % fpga_image % print_images_error()); + return str(boost::format("Could not find %s and %s in your images path!\n%s") % fw_image % fpga_image % print_utility_error("uhd_images_downloader.py")); } //escape char for multi-line cmd + newline + indent? @@ -389,13 +389,13 @@ public: if (this->get_rev() == USRP2_REV3 or this->get_rev() == USRP2_REV4){ const std::string card_burner = (fs::path(uhd::get_pkg_path()) / UHD_LIB_DIR / "uhd" / "utils" / "usrp2_card_burner.py").string(); const std::string card_burner_cmd = str(boost::format("\"%s%s\" %s--fpga=\"%s\" %s--fw=\"%s\"") % sudo % card_burner % ml % fpga_image_path % ml % fw_image_path); - return str(boost::format("%s\n%s") % print_images_error() % card_burner_cmd); + return str(boost::format("%s\n%s") % print_utility_error("uhd_images_downloader.py") % card_burner_cmd); } else{ const std::string addr = _ctrl_transport->get_recv_addr(); const std::string net_burner_path = (fs::path(uhd::get_pkg_path()) / UHD_LIB_DIR / "uhd" / "utils" / "usrp_n2xx_simple_net_burner").string(); const std::string net_burner_cmd = str(boost::format("\"%s\" %s--addr=\"%s\"") % net_burner_path % ml % addr); - return str(boost::format("%s\n%s") % print_images_error() % net_burner_cmd); + return str(boost::format("%s\n%s") % print_utility_error("uhd_images_downloader.py") % net_burner_cmd); } } diff --git a/host/lib/usrp/x300/x300_impl.cpp b/host/lib/usrp/x300/x300_impl.cpp index a879ae02d..8d255097d 100644 --- a/host/lib/usrp/x300/x300_impl.cpp +++ b/host/lib/usrp/x300/x300_impl.cpp @@ -24,7 +24,7 @@ #include "apply_corrections.hpp" #include #include -#include +#include #include #include #include @@ -171,7 +171,7 @@ static device_addrs_t x300_find_pcie(const device_addr_t &hint, bool explicit_qu default: continue; } - + niriok_proxy::sptr kernel_proxy = niriok_proxy::make_and_open(dev_info.interface_path); //Attempt to read the name from the EEPROM and perform filtering. @@ -1670,11 +1670,11 @@ void x300_impl::check_fw_compat(const fs_path &mb_path, wb_iface::sptr iface) if (compat_major != X300_FW_COMPAT_MAJOR) { throw uhd::runtime_error(str(boost::format( - "Expected firmware compatibility number 0x%x, but got 0x%x.%x:\n" + "Expected firmware compatibility number %d.%d, but got %d.%d:\n" "The firmware build is not compatible with the host code build.\n" "%s" - ) % int(X300_FW_COMPAT_MAJOR) % compat_major % compat_minor - % print_images_error())); + ) % int(X300_FW_COMPAT_MAJOR) % int(X300_FW_COMPAT_MINOR) + % compat_major % compat_minor % print_utility_error("uhd_images_downloader.py"))); } _tree->create(mb_path / "fw_version").set(str(boost::format("%u.%u") % compat_major % compat_minor)); @@ -1694,11 +1694,11 @@ void x300_impl::check_fpga_compat(const fs_path &mb_path, wb_iface::sptr iface) "Download the appropriate FPGA images for this version of UHD.\n" "%s\n\n" "Then burn a new image to the on-board flash storage of your\n" - "USRP X3xx device using the burner utility. \n\n" + "USRP X3xx device using the burner utility. %s\n\n" "For more information, refer to the UHD manual:\n\n" " http://files.ettus.com/manual/page_usrp_x3x0.html#x3x0_flash" ) % int(X300_FPGA_COMPAT_MAJOR) % compat_major - % print_images_error())); + % print_utility_error("uhd_images_downloader.py") % print_utility_error("usrp_x3xx_fpga_burner"))); } _tree->create(mb_path / "fpga_version").set(str(boost::format("%u.%u") % compat_major % compat_minor)); diff --git a/host/lib/usrp_clock/octoclock/octoclock_impl.cpp b/host/lib/usrp_clock/octoclock/octoclock_impl.cpp index 8c207dd9f..d55fab10e 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_impl.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_impl.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -420,7 +420,7 @@ std::string octoclock_impl::_get_images_help_message(const std::string &addr){ catch(const std::exception &e){ return str(boost::format("Could not find %s in your images path.\n%s") % image_name - % uhd::print_images_error()); + % uhd::print_utility_error("uhd_images_downloader.py")); } //Get escape character @@ -433,5 +433,5 @@ std::string octoclock_impl::_get_images_help_message(const std::string &addr){ //Get burner command const std::string burner_path = (fs::path(uhd::get_pkg_path()) / "bin" / "octoclock_firmware_burner").string(); const std::string burner_cmd = str(boost::format("%s %s--addr=\"%s\"") % burner_path % ml % addr); - return str(boost::format("%s\n%s") % uhd::print_images_error() % burner_cmd); + return str(boost::format("%s\n%s") % uhd::print_utility_error("uhd_images_downloader.py") % burner_cmd); } diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index 106e2b650..369920ac1 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -132,7 +132,6 @@ SET_SOURCE_FILES_PROPERTIES( LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/csv.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gain_group.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/images.cpp ${CMAKE_CURRENT_SOURCE_DIR}/load_modules.cpp ${CMAKE_CURRENT_SOURCE_DIR}/log.cpp ${CMAKE_CURRENT_SOURCE_DIR}/msg.cpp diff --git a/host/lib/utils/images.cpp b/host/lib/utils/images.cpp deleted file mode 100644 index 1ba2f81e6..000000000 --- a/host/lib/utils/images.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// -// 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 . -// - -#include -#include -#include -#include -#include -#include -#include - -namespace fs = boost::filesystem; - -std::vector get_image_paths(void); //defined in paths.cpp - -/*********************************************************************** - * Find an image in the image paths - **********************************************************************/ -std::string uhd::find_image_path(const std::string &image_name){ - if (fs::exists(image_name)){ - return fs::system_complete(image_name).string(); - } - BOOST_FOREACH(const fs::path &path, get_image_paths()){ - fs::path image_path = path / image_name; - if (fs::exists(image_path)) return image_path.string(); - } - throw uhd::io_error("Could not find path for image: " + image_name + "\n\n" + uhd::print_images_error()); -} - -std::string uhd::find_images_downloader(void){ - return fs::path(fs::path(uhd::get_pkg_path()) / UHD_LIB_DIR / "uhd" / "utils" / "uhd_images_downloader.py").string(); -} - -std::string uhd::print_images_error(void){ - #ifdef UHD_PLATFORM_WIN32 - return "As an Administrator, please run:\n\n\"" + find_images_downloader() + "\""; - #else - return "Please run:\n\nsudo \"" + find_images_downloader() + "\""; - #endif -} diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 3e2bea1c6..282ebb566 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -17,15 +17,19 @@ #include #include -#include + +#include +#include #include #include -#include +#include + +#include //P_tmpdir #include +#include #include #include -#include //getenv -#include //P_tmpdir + #ifdef BOOST_MSVC #define USE_GET_TEMP_PATH #include //GetTempPath @@ -136,3 +140,28 @@ std::string uhd::get_app_path(void){ return uhd::get_tmp_path(); } + +std::string uhd::find_image_path(const std::string &image_name){ + if (fs::exists(image_name)){ + return fs::system_complete(image_name).string(); + } + BOOST_FOREACH(const fs::path &path, get_image_paths()){ + fs::path image_path = path / image_name; + if (fs::exists(image_path)) return image_path.string(); + } + throw uhd::io_error("Could not find path for image: " + image_name + + "\n\n" + uhd::print_utility_error("uhd_images_downloader.py")); +} + +std::string uhd::find_utility(std::string name) { + return fs::path(fs::path(uhd::get_pkg_path()) / UHD_LIB_DIR / "uhd" / "utils" / name) + .string(); +} + +std::string uhd::print_utility_error(std::string name){ + #ifdef UHD_PLATFORM_WIN32 + return "As an Administrator, please run:\n\n\"" + find_utility(name) + "\""; + #else + return "Please run:\n\n \"" + find_utility(name) + "\""; + #endif +} diff --git a/host/utils/b2xx_fx3_utils.cpp b/host/utils/b2xx_fx3_utils.cpp index 0cab6618d..8b64be63e 100644 --- a/host/utils/b2xx_fx3_utils.cpp +++ b/host/utils/b2xx_fx3_utils.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include namespace po = boost::program_options; namespace fs = boost::filesystem; diff --git a/host/utils/octoclock_firmware_burner.cpp b/host/utils/octoclock_firmware_burner.cpp index 9551ddd20..0a48caabd 100644 --- a/host/utils/octoclock_firmware_burner.cpp +++ b/host/utils/octoclock_firmware_burner.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include diff --git a/host/utils/usrp_n2xx_simple_net_burner.cpp b/host/utils/usrp_n2xx_simple_net_burner.cpp index dc83b6fdf..b06e67bb2 100644 --- a/host/utils/usrp_n2xx_simple_net_burner.cpp +++ b/host/utils/usrp_n2xx_simple_net_burner.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include diff --git a/host/utils/usrp_x3xx_fpga_burner.cpp b/host/utils/usrp_x3xx_fpga_burner.cpp index b849cfb92..abd5815e8 100644 --- a/host/utils/usrp_x3xx_fpga_burner.cpp +++ b/host/utils/usrp_x3xx_fpga_burner.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include -- cgit v1.2.3 From 7866b66587c7570890a24a7ebc89330976a8d81b Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 21 Nov 2014 15:27:36 +0100 Subject: docs: Added notes on auto_tick_rate (B200) --- host/docs/usrp_b200.dox | 31 ++++++++++++++++++++++++++++--- host/include/uhd/usrp/multi_usrp.hpp | 5 +++++ 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'host/include') diff --git a/host/docs/usrp_b200.dox b/host/docs/usrp_b200.dox index 6ee2f3445..9d3550b98 100644 --- a/host/docs/usrp_b200.dox +++ b/host/docs/usrp_b200.dox @@ -36,15 +36,40 @@ images: The master clock rate feeds the RF frontends and the DSP chains. Users may select non-default clock rates to acheive integer decimations or -interpolations in the DSP chains. The default master clock rate defaults -to 32 MHz, but can be set to any rate between 5 MHz and 61.44 MHz. +interpolations in the DSP chains. The clock rate can be set to any value +between 5 MHz and 61.44 MHz (or 30.72 MHz for dual-channel mode). +Note that rates above 56 MHz are possible, but not recommended. The user can set the master clock rate through the usrp API call uhd::usrp::multi_usrp::set_master_clock_rate(), or the clock rate can be set through the -device arguments, which many applications take: : +device arguments, which many applications take: uhd_usrp_probe --args="master_clock_rate=52e6" +The property to control the master clock rate is a double value, called `tick_rate`. + +\subsection b200_auto_mcr Automatic Clock Rate Setting + +The default clock rate setting is to automatically set a clock rate +depending on the requested sampling rate. The automatic clock rate selection +is disabled when either `master_clock_rate` is given in the device initialization +arguments, or when uhd::usrp::multi_usrp::set_master_clock_rate() is called. + +Note that the master clock rate must be an integer multiple of the sampling +rate. If a master clock rate is chosen for which this condition does not +hold, a warning will be displayed and a different sampling rate is used internally. + +Nevertheless, there are multiple valid values for the master clock rate +for most sampling rates. The auto clock rate selection attempts to use +the largest possible clock rate as to enable as many half-band filters +as possible. Expert users might have cases where a more fine-grained +control over the resampling stages is required, in which case manually +selecting a master clock rate might be more suitable than the automatic +rate. + +The property to dis- or enable the auto tick rate is a boolean value, +`auto_tick_rate`. + \section b200_fe RF Frontend Notes The B200 features an integrated RF frontend. diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index 6fd22ff23..2362ebcd7 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -155,6 +155,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 */ -- cgit v1.2.3 From d47d1805c4b679c1f6975e00b714efd28d7ba1c4 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 24 Nov 2014 13:47:50 +0100 Subject: docs: Fixed sid_t doxygen --- host/include/uhd/types/sid.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/types/sid.hpp b/host/include/uhd/types/sid.hpp index 12f98ff97..95034c7a5 100644 --- a/host/include/uhd/types/sid.hpp +++ b/host/include/uhd/types/sid.hpp @@ -40,7 +40,7 @@ namespace uhd { * is required, we use the combination of the 8-bit address and the 8-bit * endpoint. * - * \section sid_str_repr + * \section sid_str_repr String Representation * * The string representation of a SID is of the form * @@ -60,7 +60,7 @@ namespace uhd { * SRC_ADDRESS.SRC_ENDPOINT>DST_ADDRESS.DST_ENDPOINT * * - * \section sid_block_ports + * \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 -- cgit v1.2.3 From 0da9251e68606dc9cbb3e1d36914cfb95f890ada Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 3 Nov 2014 16:27:08 +0100 Subject: transport: Made CHDR-related routines separate from VRT Our VRT routines have the option to switch, on the fly, between VRLP and CHDR. This adds new CHDR-specific (un-)packers, which can only work with CHDR. --- host/docs/uhd.dox | 1 + host/docs/vrt_chdr.dox | 83 ++++++++++++ host/include/uhd/transport/CMakeLists.txt | 4 +- host/include/uhd/transport/chdr.hpp | 113 +++++++++++++++++ host/include/uhd/transport/vrt_if_packet.hpp | 74 ++++++++++- host/lib/transport/CMakeLists.txt | 1 + host/lib/transport/chdr.cpp | 182 +++++++++++++++++++++++++++ host/tests/CMakeLists.txt | 3 +- host/tests/chdr_test.cpp | 141 +++++++++++++++++++++ 9 files changed, 598 insertions(+), 4 deletions(-) create mode 100644 host/docs/vrt_chdr.dox create mode 100644 host/include/uhd/transport/chdr.hpp create mode 100644 host/lib/transport/chdr.cpp create mode 100644 host/tests/chdr_test.cpp (limited to 'host/include') diff --git a/host/docs/uhd.dox b/host/docs/uhd.dox index 5b0738969..5cbe51a90 100644 --- a/host/docs/uhd.dox +++ b/host/docs/uhd.dox @@ -11,6 +11,7 @@ Some additional pages on developing UHD are also available here: \li \subpage page_coding \li \subpage page_stream +\li \subpage page_rtp */ // vim:ft=doxygen: diff --git a/host/docs/vrt_chdr.dox b/host/docs/vrt_chdr.dox new file mode 100644 index 000000000..8ab177b21 --- /dev/null +++ b/host/docs/vrt_chdr.dox @@ -0,0 +1,83 @@ +/*! \page page_rtp Radio Transport Protocols + +\tableofcontents + +Radio transport protocols are used to exchange samples (or other items) between host and devices. +If one were to sniff Ethernet traffic between a USRP and a PC, the packets would conform to a +radio transport protocol. + +For USRP devices, two radio transport protocols are relevent: VRT (the VITA Radio Transport protocol) +and CVITA (compressed VITA), also known as CHDR. Generation-3 devices and the B200 use CHDR, the rest +use VRT. + +\section rtp_vrt VRT + +VRT is an open protocol defined by the VITA-49 standard. It was designed for interoperability, +and to allow different device types to work with different software stacks. + +VRT is a very verbose standard, and only a subset is implemented in UHD/USRPs. +The full standard is available from the VITA website: http://www.vita.com . + + +\section rtp_chdr CVITA (CHDR) + +For the third generation of Ettus devices, a new type transport protocol was designed. +It reduces the complexity of the original standard and uses a fixed-length 64-Bit header +for everything except the timestamp. Because this is a "compressed" form of VITA, it +was dubbed "Compressed VITA" (CVITA). The compressed header is called CHDR, which is why +the protocol is often called CHDR itself (pronounced like the cheese "cheddar"). + +By compressing all information into a 64-bit line, the header can efficiently be parsed +in newer FPGAs, where the common streaming protocol is 64-Bit AXI. The first line in a +packet already provides all necessary information to proceed. + +Some CHDR-specific functions can be found in: uhd::transport::vrt::chdr. + +The form of a CVITA packet is the following: + +Address (Bytes) | Length (Bytes) | Payload +----------------|----------------|---------------------------- +0 | 8 | Compressed Header (CHDR) +8 | 8 | Fractional Time (Optional!) +8/16 | - | Data + +If there is no timestamp present, the data starts at address 8, otherwise, it starts at 16. + +The 64 Bits in the compressed header have the following meaning: + +Bits | Meaning +-------|-------------------------------------------------- +63:62 | Packet Type +61 | Has fractional time stamp (1: Yes) +60 | End-of-burst or error flag +59:48 | 12-bit sequence number +47:32 | Total packet length in Bytes +31:0 | Stream ID (SID) + + +The packet type is determined mainly by the first two bits, although +the EOB or error flag are also taken into consideration: + +Bit 63 | Bit 62 | Bit 60 | Packet Type +-------|--------|--------|-------------- +0 | 0 | 0 | Data +0 | 0 | 1 | Data (End-of-burst) +0 | 1 | 0 | Flow Control +1 | 0 | 0 | Command Packet +1 | 1 | 0 | Command Response +1 | 1 | 1 | Command Response (Error) + +\section vrt_tools Tools + +For CHDR, we provide a Wireshark dissector under tools/chdr_dissector. It can be used +for Ethernet links as well as USB (e.g., for the B210). + +\section vrt_code Code + +Relevent code sections for the radio transport layer are: +* uhd::transport::vrt - Namespace for radio transport protocol related functions and definitions +* uhd::transport::vrt::chdr - Sub-namespace specifically for CVITA/CHDR +* uhd::sid_t - Datatype to represent SIDs + +*/ +// vim:ft=doxygen: 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 . # - 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 . +// + +#ifndef INCLUDED_UHD_TRANSPORT_CHDR_HPP +#define INCLUDED_UHD_TRANSPORT_CHDR_HPP + +#include + +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/vrt_if_packet.hpp b/host/include/uhd/transport/vrt_if_packet.hpp index d16892281..8bc65cdf1 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 + + // 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/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index 5920f3d78..9ec8a5c0b 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -129,6 +129,7 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/if_addrs.cpp ${CMAKE_CURRENT_SOURCE_DIR}/udp_simple.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nirio_zero_copy.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/chdr.cpp ) # Verbose Debug output for send/recv diff --git a/host/lib/transport/chdr.cpp b/host/lib/transport/chdr.cpp new file mode 100644 index 000000000..47ac961b9 --- /dev/null +++ b/host/lib/transport/chdr.cpp @@ -0,0 +1,182 @@ +// +// 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 . +// + +#include +#include +#include + +//define the endian macros to convert integers +#ifdef BOOST_BIG_ENDIAN + #define BE_MACRO(x) (x) + #define LE_MACRO(x) uhd::byteswap(x) +#else + #define BE_MACRO(x) uhd::byteswap(x) + #define LE_MACRO(x) (x) +#endif + +using namespace uhd::transport::vrt; + +static const boost::uint32_t HDR_FLAG_TSF = (1 << 29); +static const boost::uint32_t HDR_FLAG_EOB = (1 << 28); +static const boost::uint32_t HDR_FLAG_ERROR = (1 << 28); + +/***************************************************************************/ +/* Packing */ +/***************************************************************************/ +/*! Translate the contents of \p if_packet_info into a 32-Bit word and return it. + */ +UHD_INLINE boost::uint32_t _hdr_pack_chdr( + if_packet_info_t &if_packet_info +) { + // Set fields in if_packet_info + if_packet_info.num_header_words32 = 2 + (if_packet_info.has_tsf ? 2 : 0); + if_packet_info.num_packet_words32 = + if_packet_info.num_header_words32 + + if_packet_info.num_payload_words32; + + boost::uint16_t pkt_length = + if_packet_info.num_payload_bytes + (4 * if_packet_info.num_header_words32); + boost::uint32_t chdr = 0 + // 2 Bits: Packet type + | (if_packet_info.packet_type << 30) + // 1 Bit: Has time + | (if_packet_info.has_tsf ? HDR_FLAG_TSF : 0) + // 1 Bit: EOB or Error + | ((if_packet_info.eob or if_packet_info.error) ? HDR_FLAG_EOB : 0) + // 12 Bits: Sequence number + | ((if_packet_info.packet_count & 0xFFF) << 16) + // 16 Bits: Total packet length + | pkt_length; + return chdr; +} + +void chdr::if_hdr_pack_be( + boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info +) { + // Write header and update if_packet_info + packet_buff[0] = BE_MACRO(_hdr_pack_chdr(if_packet_info)); + + // Write SID + packet_buff[1] = BE_MACRO(if_packet_info.sid); + + // Write time + if (if_packet_info.has_tsf) { + packet_buff[2] = BE_MACRO(boost::uint32_t(if_packet_info.tsf >> 32)); + packet_buff[3] = BE_MACRO(boost::uint32_t(if_packet_info.tsf >> 0)); + } +} + +void chdr::if_hdr_pack_le( + boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info +) { + // Write header and update if_packet_info + packet_buff[0] = LE_MACRO(_hdr_pack_chdr(if_packet_info)); + + // Write SID + packet_buff[1] = LE_MACRO(if_packet_info.sid); + + // Write time + if (if_packet_info.has_tsf) { + packet_buff[2] = LE_MACRO(boost::uint32_t(if_packet_info.tsf >> 32)); + packet_buff[3] = LE_MACRO(boost::uint32_t(if_packet_info.tsf >> 0)); + } +} + + +/***************************************************************************/ +/* Unpacking */ +/***************************************************************************/ +UHD_INLINE void _hdr_unpack_chdr( + const boost::uint32_t chdr, + if_packet_info_t &if_packet_info +) { + // Set constant members + if_packet_info.link_type = if_packet_info_t::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; + if_packet_info.sob = false; + + // Set configurable members + if_packet_info.has_tsf = bool(chdr & HDR_FLAG_TSF); + if_packet_info.packet_type = if_packet_info_t::packet_type_t((chdr >> 30) & 0x3); + if_packet_info.eob = (if_packet_info.packet_type == if_packet_info_t::PACKET_TYPE_DATA) + && bool(chdr & HDR_FLAG_EOB); + if_packet_info.error = (if_packet_info.packet_type == if_packet_info_t::PACKET_TYPE_RESP) + && bool(chdr & HDR_FLAG_ERROR); + if_packet_info.packet_count = (chdr >> 16) & 0xFFF; + + // Set packet length variables + if (if_packet_info.has_tsf) { + if_packet_info.num_header_words32 = 4; + } else { + if_packet_info.num_header_words32 = 2; + } + size_t pkt_size_bytes = (chdr & 0xFFFF); + size_t pkt_size_word32 = (pkt_size_bytes / 4) + ((pkt_size_bytes % 4) ? 1 : 0); + // Check lengths match: + if (pkt_size_word32 < if_packet_info.num_header_words32) { + throw uhd::value_error("Bad CHDR or invalid packet length"); + } + if (if_packet_info.num_packet_words32 < pkt_size_word32) { + throw uhd::value_error("Bad CHDR or packet fragment"); + } + if_packet_info.num_payload_bytes = pkt_size_bytes - (4 * if_packet_info.num_header_words32); + if_packet_info.num_payload_words32 = pkt_size_word32 - if_packet_info.num_header_words32; +} + +void chdr::if_hdr_unpack_be( + const boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info +) { + // Read header and update if_packet_info + boost::uint32_t chdr = BE_MACRO(packet_buff[0]); + _hdr_unpack_chdr(chdr, if_packet_info); + + // Read SID + if_packet_info.sid = BE_MACRO(packet_buff[1]); + + // Read time (has_tsf was updated earlier) + if (if_packet_info.has_tsf) { + if_packet_info.tsf = 0 + | boost::uint64_t(BE_MACRO(packet_buff[2])) << 32 + | BE_MACRO(packet_buff[3]); + } +} + +void chdr::if_hdr_unpack_le( + const boost::uint32_t *packet_buff, + if_packet_info_t &if_packet_info +) { + // Read header and update if_packet_info + boost::uint32_t chdr = LE_MACRO(packet_buff[0]); + _hdr_unpack_chdr(chdr, if_packet_info); + + // Read SID + if_packet_info.sid = LE_MACRO(packet_buff[1]); + + // Read time (has_tsf was updated earlier) + if (if_packet_info.has_tsf) { + if_packet_info.tsf = 0 + | boost::uint64_t(LE_MACRO(packet_buff[2])) << 32 + | LE_MACRO(packet_buff[3]); + } +} + diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 579fd46ca..829fb8e94 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -27,8 +27,9 @@ SET(test_sources addr_test.cpp buffer_test.cpp byteswap_test.cpp - convert_test.cpp cast_test.cpp + chdr_test.cpp + convert_test.cpp dict_test.cpp error_test.cpp fp_compare_delta_test.cpp diff --git a/host/tests/chdr_test.cpp b/host/tests/chdr_test.cpp new file mode 100644 index 000000000..8893e12e5 --- /dev/null +++ b/host/tests/chdr_test.cpp @@ -0,0 +1,141 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include + +using namespace uhd::transport::vrt; + +static void pack_and_unpack( + if_packet_info_t &if_packet_info_in +){ + // Temp buffer for packed packet + boost::uint32_t packet_buff[2048] = {0}; + + // Check input (must not be lazy) + BOOST_REQUIRE( + (if_packet_info_in.num_payload_words32 == 0 and if_packet_info_in.num_payload_bytes == 0) + or + (if_packet_info_in.num_payload_words32 != 0 and if_packet_info_in.num_payload_bytes != 0) + ); + if (if_packet_info_in.num_payload_words32) { + BOOST_REQUIRE(if_packet_info_in.num_payload_bytes <= 4 * if_packet_info_in.num_payload_words32); + BOOST_REQUIRE(if_packet_info_in.num_payload_bytes > 4*(if_packet_info_in.num_payload_words32-1)); + } + + //pack metadata into a vrt header + chdr::if_hdr_pack_be( + packet_buff, if_packet_info_in + ); + std::cout << std::endl; + boost::uint32_t header_bits = (uhd::ntohx(packet_buff[0]) >> 28); + std::cout << boost::format("header bits = 0b%d%d%d%d") % bool(header_bits & 8) % bool(header_bits & 4) % bool(header_bits & 2) % bool(header_bits & 1) << std::endl; + for (size_t i = 0; i < 5; i++) + { + std::cout << boost::format("packet_buff[%u] = 0x%08x") % i % uhd::ntohx(packet_buff[i]) << std::endl; + } + + if_packet_info_t if_packet_info_out; + // Must be set a-priori as per contract + if_packet_info_out.num_packet_words32 = if_packet_info_in.num_packet_words32; + + //unpack the vrt header back into metadata + chdr::if_hdr_unpack_be( + packet_buff, if_packet_info_out + ); + + //check the the unpacked metadata is the same + BOOST_CHECK_EQUAL(if_packet_info_in.packet_count, if_packet_info_out.packet_count); + BOOST_CHECK_EQUAL(if_packet_info_in.num_header_words32, if_packet_info_out.num_header_words32); + BOOST_CHECK_EQUAL(if_packet_info_in.num_payload_words32, if_packet_info_out.num_payload_words32); + BOOST_CHECK(if_packet_info_out.has_sid); + BOOST_CHECK_EQUAL(if_packet_info_in.sid, if_packet_info_out.sid); + BOOST_CHECK(if_packet_info_out.has_sid); + BOOST_CHECK_EQUAL(if_packet_info_in.has_tsf, if_packet_info_out.has_tsf); + if (if_packet_info_in.has_tsf and if_packet_info_out.has_tsf){ + BOOST_CHECK_EQUAL(if_packet_info_in.tsf, if_packet_info_out.tsf); + } +} + +BOOST_AUTO_TEST_CASE(test_with_chdr){ + if_packet_info_t if_packet_info; + if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_DATA; + if_packet_info.eob = false; + if_packet_info.packet_count = 7; + if_packet_info.has_tsf = true; + if_packet_info.tsf = 0x1234567890ABCDEF; + if_packet_info.sid = 0xAABBCCDD; + if_packet_info.num_payload_words32 = 24; + if_packet_info.num_payload_bytes = 95; + pack_and_unpack(if_packet_info); +} + +BOOST_AUTO_TEST_CASE(test_with_chdr_fc){ + if_packet_info_t if_packet_info; + if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_FC; + if_packet_info.eob = false; + if_packet_info.packet_count = 19; + if_packet_info.has_tsf = false; + if_packet_info.tsf = 0x1234567890ABCDEF; + if_packet_info.sid = 0xAABBCCDD; + if_packet_info.num_payload_words32 = 4; + if_packet_info.num_payload_bytes = 16; + pack_and_unpack(if_packet_info); +} + +BOOST_AUTO_TEST_CASE(test_with_chdr_cmd){ + if_packet_info_t if_packet_info; + if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_CMD; + if_packet_info.packet_count = 19; + if_packet_info.has_tsf = true; + if_packet_info.tsf = 0x1234567890ABCDEF; + if_packet_info.sid = 0xAABBCCDD; + if_packet_info.num_payload_words32 = 4; + if_packet_info.num_payload_bytes = 16; + pack_and_unpack(if_packet_info); +} + +BOOST_AUTO_TEST_CASE(test_with_chdr_resp){ + if_packet_info_t if_packet_info; + if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_RESP; + if_packet_info.packet_count = 123; + if_packet_info.has_tsf = false; + if_packet_info.tsf = 0x1234567890ABCDEF; + if_packet_info.sid = 0xAABBCCDD; + if_packet_info.num_payload_words32 = 4; + if_packet_info.num_payload_bytes = 16; + pack_and_unpack(if_packet_info); +} + +BOOST_AUTO_TEST_CASE(test_with_chdr_err){ + if_packet_info_t if_packet_info; + if_packet_info.packet_type = if_packet_info_t::PACKET_TYPE_ERROR; + if_packet_info.packet_count = 1928; + if_packet_info.eob = false; + if_packet_info.error = false; // Needs to be set explicitly + if_packet_info.has_tsf = false; + if_packet_info.tsf = 0x1234567890ABCDEF; + if_packet_info.sid = 0xAABBCCDD; + if_packet_info.num_payload_words32 = 4; + if_packet_info.num_payload_bytes = 16; + pack_and_unpack(if_packet_info); +} + -- cgit v1.2.3 From c7796ea9714d1781df3acb4cf2283c0266babf13 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 12 Dec 2014 18:19:02 +0100 Subject: uhd: Added direction_t for RX & TX --- host/include/uhd/types/CMakeLists.txt | 1 + host/include/uhd/types/direction.hpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 host/include/uhd/types/direction.hpp (limited to 'host/include') diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt index 66b8662a1..444ff71ae 100644 --- a/host/include/uhd/types/CMakeLists.txt +++ b/host/include/uhd/types/CMakeLists.txt @@ -21,6 +21,7 @@ UHD_INSTALL(FILES device_addr.hpp dict.ipp dict.hpp + direction.hpp io_type.hpp mac_addr.hpp metadata.hpp diff --git a/host/include/uhd/types/direction.hpp b/host/include/uhd/types/direction.hpp new file mode 100644 index 000000000..400e7e0d4 --- /dev/null +++ b/host/include/uhd/types/direction.hpp @@ -0,0 +1,27 @@ +// +// 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 . +// + +#ifndef INCLUDED_UHD_TYPES_DIRECTION_HPP +#define INCLUDED_UHD_TYPES_DIRECTION_HPP + +namespace uhd { + + enum direction_t { RX, TX }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_DIRECTION_HPP */ -- cgit v1.2.3 From bb10b51c21ed7e116e4be5b11a256eefb60d7903 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 15 Dec 2014 17:25:43 +0100 Subject: uhd: Renamed direction_t names to avoid namespace clashes --- host/include/uhd/types/direction.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'host/include') diff --git a/host/include/uhd/types/direction.hpp b/host/include/uhd/types/direction.hpp index 400e7e0d4..62fbde3f0 100644 --- a/host/include/uhd/types/direction.hpp +++ b/host/include/uhd/types/direction.hpp @@ -20,7 +20,14 @@ namespace uhd { - enum direction_t { RX, TX }; + enum direction_t { + //! Receive + RX_DIRECTION, + //! Transmit + TX_DIRECTION, + //! Duplex + DX_DIRECTION + }; } //namespace uhd -- cgit v1.2.3 From 3c5fe0a201d78a8732aad31a71bf806e00c89db1 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Thu, 18 Dec 2014 15:37:20 -0800 Subject: Adding support for NI VID + PIDs for USRP B2xx devices. --- host/include/uhd/transport/usb_device_handle.hpp | 3 + host/lib/transport/libusb1_base.cpp | 20 +++--- host/lib/usrp/b200/b200_iface.hpp | 3 + host/lib/usrp/b200/b200_impl.cpp | 72 +++++++++++++++++---- host/utils/b2xx_fx3_utils.cpp | 80 ++++++++++++++++-------- 5 files changed, 134 insertions(+), 44 deletions(-) (limited to 'host/include') 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 sptr; + typedef std::pair 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 get_device_list(boost::uint16_t vid, boost::uint16_t pid); + static std::vector get_device_list(const std::vector& vid_pid_pair_list); + }; //namespace usb diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp index ee4e20adb..18acb1fdc 100644 --- a/host/lib/transport/libusb1_base.cpp +++ b/host/lib/transport/libusb1_base.cpp @@ -343,15 +343,21 @@ libusb::special_handle::sptr libusb::special_handle::make(device::sptr dev){ std::vector usb_device_handle::get_device_list( boost::uint16_t vid, boost::uint16_t pid ){ - std::vector handles; + return usb_device_handle::get_device_list(std::vector(1,usb_device_handle::vid_pid_pair_t(vid,pid))); +} +std::vector usb_device_handle::get_device_list(const std::vector& vid_pid_pair_list) +{ + std::vector handles; libusb::device_list::sptr dev_list = libusb::device_list::make(); - for (size_t i = 0; i < dev_list->size(); i++){ - usb_device_handle::sptr handle = libusb::special_handle::make(dev_list->at(i)); - if (handle->get_vendor_id() == vid and handle->get_product_id() == pid){ - handles.push_back(handle); - } + for(size_t iter = 0; iter < vid_pid_pair_list.size(); ++iter) + { + for (size_t i = 0; i < dev_list->size(); i++){ + usb_device_handle::sptr handle = libusb::special_handle::make(dev_list->at(i)); + if (handle->get_vendor_id() == vid_pid_pair_list[iter].first and handle->get_product_id() == vid_pid_pair_list[iter].second){ + handles.push_back(handle); + } + } } - return handles; } diff --git a/host/lib/usrp/b200/b200_iface.hpp b/host/lib/usrp/b200/b200_iface.hpp index 83adfdd64..1821865d3 100644 --- a/host/lib/usrp/b200/b200_iface.hpp +++ b/host/lib/usrp/b200/b200_iface.hpp @@ -26,7 +26,10 @@ #include "ad9361_ctrl.hpp" const static boost::uint16_t B200_VENDOR_ID = 0x2500; +const static boost::uint16_t B200_VENDOR_NI_ID = 0x3923; const static boost::uint16_t B200_PRODUCT_ID = 0x0020; +const static boost::uint16_t B200_PRODUCT_NI_ID = 0x7813; +const static boost::uint16_t B210_PRODUCT_NI_ID = 0x7814; const static boost::uint16_t FX3_VID = 0x04b4; const static boost::uint16_t FX3_DEFAULT_PID = 0x00f3; const static boost::uint16_t FX3_REENUM_PID = 0x00f0; diff --git a/host/lib/usrp/b200/b200_impl.cpp b/host/lib/usrp/b200/b200_impl.cpp index b2f0d8d3e..9b323cb13 100644 --- a/host/lib/usrp/b200/b200_impl.cpp +++ b/host/lib/usrp/b200/b200_impl.cpp @@ -87,14 +87,16 @@ static device_addrs_t b200_find(const device_addr_t &hint) //since an address and resource is intended for a different, non-USB, device. if (hint.has_key("addr") || hint.has_key("resource")) return b200_addrs; - boost::uint16_t vid, pid; + size_t found = 0; + std::vector vid_pid_pair_list;//vid pid pair search list for devices. if(hint.has_key("vid") && hint.has_key("pid") && hint.has_key("type") && hint["type"] == "b200") { - vid = uhd::cast::hexstr_cast(hint.get("vid")); - pid = uhd::cast::hexstr_cast(hint.get("pid")); + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(uhd::cast::hexstr_cast(hint.get("vid")), + uhd::cast::hexstr_cast(hint.get("pid")))); } else { - vid = B200_VENDOR_ID; - pid = B200_PRODUCT_ID; + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID, B200_PRODUCT_ID)); + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B200_PRODUCT_NI_ID)); + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID, B210_PRODUCT_NI_ID)); } // Important note: @@ -104,8 +106,9 @@ static device_addrs_t b200_find(const device_addr_t &hint) // This requirement is a courtesy of libusb1.0 on windows. //find the usrps and load firmware - size_t found = 0; - BOOST_FOREACH(usb_device_handle::sptr handle, usb_device_handle::get_device_list(vid, pid)) { + std::vector uhd_usb_device_vector = usb_device_handle::get_device_list(vid_pid_pair_list); + + BOOST_FOREACH(usb_device_handle::sptr handle, uhd_usb_device_vector) { //extract the firmware path for the b200 std::string b200_fw_image; try{ @@ -138,7 +141,7 @@ static device_addrs_t b200_find(const device_addr_t &hint) //search for the device until found or timeout while (boost::get_system_time() < timeout_time and b200_addrs.empty() and found != 0) { - BOOST_FOREACH(usb_device_handle::sptr handle, usb_device_handle::get_device_list(vid, pid)) + BOOST_FOREACH(usb_device_handle::sptr handle, usb_device_handle::get_device_list(vid_pid_pair_list)) { usb_control::sptr control; try{control = usb_control::make(handle, 0);} @@ -155,12 +158,16 @@ static device_addrs_t b200_find(const device_addr_t &hint) { switch (boost::lexical_cast(mb_eeprom["product"])) { + //0x0001 and 0x7737 are Ettus B200 product Ids. case 0x0001: case 0x7737: + case B200_PRODUCT_NI_ID: new_addr["product"] = "B200"; break; - case 0x7738: + //0x0002 and 0x7738 are Ettus B210 product Ids. case 0x0002: + case 0x7738: + case B210_PRODUCT_NI_ID: new_addr["product"] = "B210"; break; default: UHD_MSG(error) << "B200 unknown product code: " << mb_eeprom["product"] << std::endl; @@ -204,13 +211,50 @@ b200_impl::b200_impl(const device_addr_t &device_addr) //try to match the given device address with something on the USB bus boost::uint16_t vid = B200_VENDOR_ID; boost::uint16_t pid = B200_PRODUCT_ID; + bool specified_vid = false; + bool specified_pid = false; + if (device_addr.has_key("vid")) + { vid = uhd::cast::hexstr_cast(device_addr.get("vid")); + specified_vid = true; + } + if (device_addr.has_key("pid")) + { pid = uhd::cast::hexstr_cast(device_addr.get("pid")); + specified_pid = true; + } + + std::vector vid_pid_pair_list;//search list for devices. - std::vector device_list = - usb_device_handle::get_device_list(vid, pid); + // Search only for specified VID and PID if both specified + if (specified_vid && specified_pid) + { + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid,pid)); + } + // Search for all supported PIDs limited to specified VID if only VID specified + else if (specified_vid) + { + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid,B200_PRODUCT_ID)); + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid,B200_PRODUCT_NI_ID)); + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(vid,B210_PRODUCT_NI_ID)); + } + // Search for all supported VIDs limited to specified PID if only PID specified + else if (specified_pid) + { + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID,pid)); + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID,pid)); + } + // Search for all supported devices if neither VID nor PID specified + else + { + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_ID,B200_PRODUCT_ID)); + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID,B200_PRODUCT_NI_ID)); + vid_pid_pair_list.push_back(usb_device_handle::vid_pid_pair_t(B200_VENDOR_NI_ID,B210_PRODUCT_NI_ID)); + } + + std::vector device_list = usb_device_handle::get_device_list(vid_pid_pair_list); //locate the matching handle in the device list usb_device_handle::sptr handle; @@ -244,13 +288,17 @@ b200_impl::b200_impl(const device_addr_t &device_addr) { switch (boost::lexical_cast(mb_eeprom["product"])) { + //0x0001 and 0x7737 are Ettus B200 product Ids. case 0x0001: case 0x7737: + case B200_PRODUCT_NI_ID: product_name = "B200"; default_file_name = B200_FPGA_FILE_NAME; break; - case 0x7738: + //0x0002 and 0x7738 are Ettus B210 product Ids. case 0x0002: + case 0x7738: + case B210_PRODUCT_NI_ID: product_name = "B210"; default_file_name = B210_FPGA_FILE_NAME; break; diff --git a/host/utils/b2xx_fx3_utils.cpp b/host/utils/b2xx_fx3_utils.cpp index 8b64be63e..78449a8a4 100644 --- a/host/utils/b2xx_fx3_utils.cpp +++ b/host/utils/b2xx_fx3_utils.cpp @@ -54,17 +54,21 @@ const static vid_pid_t known_vid_pids[] = { {B200_VENDOR_ID, B200_PRODUCT_ID} }; const static std::vector known_vid_pid_vector(known_vid_pids, known_vid_pids + (sizeof(known_vid_pids) / sizeof(known_vid_pids[0]))); -const static boost::uint8_t eeprom_init_values[] = { - 0x43, - 0x59, - 0x14, - 0xB2, - (B200_PRODUCT_ID & 0xff), - (B200_PRODUCT_ID >> 8), - (B200_VENDOR_ID & 0xff), - (B200_VENDOR_ID >> 8) - }; -const static uhd::byte_vector_t eeprom_init_value_vector(eeprom_init_values, eeprom_init_values + (sizeof(eeprom_init_values) / sizeof(eeprom_init_values[0]))); + +static const size_t EEPROM_INIT_VALUE_VECTOR_SIZE = 8; +static uhd::byte_vector_t construct_eeprom_init_value_vector(boost::uint16_t vid, boost::uint16_t pid) +{ + uhd::byte_vector_t init_values(EEPROM_INIT_VALUE_VECTOR_SIZE); + init_values.push_back(0x43); + init_values.push_back(0x59); + init_values.push_back(0x14); + init_values.push_back(0xB2); + init_values.push_back(static_cast(pid & 0xff)); + init_values.push_back(static_cast(pid >> 8)); + init_values.push_back(static_cast(vid & 0xff)); + init_values.push_back(static_cast(vid >> 8)); + return init_values; +} //!used with lexical cast to parse a hex string template struct to_hex{ @@ -153,15 +157,22 @@ uhd::transport::usb_device_handle::sptr open_device(const boost::uint16_t vid, c try { // try caller's VID/PID first - handles = uhd::transport::usb_device_handle::get_device_list(vp.vid,vp.pid); - if (user_supplied && handles.size() == 0) - std::cerr << (boost::format("Failed to open device with VID 0x%04x and PID 0x%04x - trying other known VID/PIDs") % vid % pid).str() << std::endl; - - // try known VID/PIDs next - for (size_t i = 0; handles.size() == 0 && i < known_vid_pid_vector.size(); i++) + std::vector vid_pid_pair_list(1,uhd::transport::usb_device_handle::vid_pid_pair_t(vid,pid)); + handles = uhd::transport::usb_device_handle::get_device_list(vid_pid_pair_list); + if (handles.size() == 0) { - vp = known_vid_pid_vector[i]; - handles = uhd::transport::usb_device_handle::get_device_list(vp.vid,vp.pid); + if (user_supplied) + { + std::cerr << (boost::format("Failed to open device with VID 0x%04x and PID 0x%04x - trying other known VID/PIDs") % vid % pid).str() << std::endl; + } + + // try known VID/PIDs next + for (size_t i = 0; handles.size() == 0 && i < known_vid_pid_vector.size(); i++) + { + vp = known_vid_pid_vector[i]; + handles = uhd::transport::usb_device_handle::get_device_list(vp.vid, vp.pid); + } + } if (handles.size() > 0) @@ -281,7 +292,7 @@ int erase_eeprom(b200_iface::sptr& b200) boost::int32_t main(boost::int32_t argc, char *argv[]) { boost::uint16_t vid, pid; - std::string pid_str, vid_str, fw_file, fpga_file; + std::string pid_str, vid_str, fw_file, fpga_file, writevid_str, writepid_str; bool user_supplied_vid_pid = false; po::options_description visible("Allowed options"); @@ -295,7 +306,6 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { ("reset-device,D", "Reset the B2xx Device.") ("reset-fpga,F", "Reset the FPGA (does not require re-programming.") ("reset-usb,U", "Reset the USB subsystem on your host computer.") - ("init-device,I", "Initialize a B2xx device.") ("load-fw,W", po::value(&fw_file), "Load a firmware (hex) file into the FX3.") ("load-fpga,L", po::value(&fpga_file), @@ -305,9 +315,14 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { // Hidden options provided for testing - use at your own risk! po::options_description hidden("Hidden options"); hidden.add_options() - ("uninit-device,U", "Uninitialize a B2xx device.") + ("init-device,I", "Initialize a B2xx device.") + ("uninit-device", "Uninitialize a B2xx device.") ("read-eeprom,R", "Read first 8 bytes of EEPROM") - ("erase-eeprom,E", "Erase first 8 bytes of EEPROM"); + ("erase-eeprom,E", "Erase first 8 bytes of EEPROM") + ("write-vid", po::value(&writevid_str), + "Write VID field of EEPROM") + ("write-pid", po::value(&writepid_str), + "Write PID field of EEPROM"); po::options_description desc; desc.add(visible); @@ -486,9 +501,24 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { * Cypress VID/PID for the initial FW load, but we can initialize from any state. */ if (vm.count("init-device")) { + uint16_t writevid = B200_VENDOR_ID; + uint16_t writepid = B200_PRODUCT_ID; + /* Now, initialize the device. */ - if (write_and_verify_eeprom(b200, eeprom_init_value_vector)) - return -1; + // Added for testing purposes - not exposed + if (vm.count("write-vid") && vm.count("write-pid")) + { + try { + writevid = atoh(writevid_str); + writepid = atoh(writepid_str); + } catch (std::exception &e) { + std::cerr << "Exception while parsing write VID and PID: " << e.what() << std:: endl; + return ~0; + } + } + + std::cout << "Writing VID and PID to EEPROM..." << std::endl << std::endl; + if (write_and_verify_eeprom(b200, construct_eeprom_init_value_vector(writevid, writepid))) return -1; std::cout << "EEPROM initialized, resetting device..." << std::endl << std::endl; -- cgit v1.2.3 From 2d3f3c6c0fde4eb8d4f9b19a1e15f253d361c38d Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Mon, 22 Dec 2014 09:21:58 -0800 Subject: math: fixed MSVC error regarding ambiguous std::log call --- host/include/uhd/utils/math.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/include') diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp index a41a35d67..275a94f72 100644 --- a/host/include/uhd/utils/math.hpp +++ b/host/include/uhd/utils/math.hpp @@ -243,7 +243,7 @@ namespace fp_compare { { // C++11 defines std::log2(), when that's universally supported // we can switch over. - return std::log(x) / std::log(2); + return std::log(x) / std::log(float_t(2)); } -- cgit v1.2.3 From 3f9ef46bc51acc5933721974e191d2a9659f6566 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Fri, 19 Dec 2014 14:52:57 -0800 Subject: Added support for MinGW cross-compile * Added CMake toolchain file, compatible with different versions * No dependency on MinGW runtime, all statically linked * Misc coding tweaks to allow MinGW to compile --- host/CMakeLists.txt | 16 +++++ host/cmake/Toolchains/mingw_cross.cmake | 69 ++++++++++++++++++++++ host/include/uhd/config.hpp | 9 ++- .../uhd/transport/nirio/nirio_driver_iface.h | 4 +- host/lib/transport/nirio/nifpga_lvbitx.cpp | 2 +- host/lib/utils/platform.cpp | 4 +- host/tests/CMakeLists.txt | 8 ++- 7 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 host/cmake/Toolchains/mingw_cross.cmake (limited to 'host/include') diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 856f1ec70..6d87bf95d 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -137,6 +137,22 @@ IF(MSVC) ADD_DEFINITIONS(/MP) #multi-threaded build ENDIF(MSVC) +IF(MINGW) + #Avoid depending on MinGW runtime DLLs + CHECK_CXX_COMPILER_FLAG(-static-libgcc HAVE_STATIC_LIBGCC_FLAG) + IF(HAVE_STATIC_LIBGCC_FLAG) + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc") + SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc") + ENDIF() + CHECK_CXX_COMPILER_FLAG(-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG) + IF(HAVE_STATIC_LIBSTDCXX_FLAG) + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++") + SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++") + ENDIF() +ENDIF() + IF(CYGWIN) ADD_DEFINITIONS(-D__USE_W32_SOCKETS) #boost asio says we need this ENDIF(CYGWIN) diff --git a/host/cmake/Toolchains/mingw_cross.cmake b/host/cmake/Toolchains/mingw_cross.cmake new file mode 100644 index 000000000..7c5adb002 --- /dev/null +++ b/host/cmake/Toolchains/mingw_cross.cmake @@ -0,0 +1,69 @@ +# Use this command: +# +# cmake -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchain-mingw.cmake . +# +# or for out of source: +# +# cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw.cmake .. +# +# You will need at least CMake 2.6.0. +# +# Adjust the following paths to suit your environment. +# +# This file was based on http://www.cmake.org/Wiki/CmakeMingw + +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Windows) + +# Assume the target architecture. +# XXX for some reason the value set here gets cleared before we reach the +# main CMakeLists.txt; see that file for a workaround. +# set(CMAKE_SYSTEM_PROCESSOR i686) + +# Which compilers to use for C and C++, and location of target +# environment. +if(EXISTS /usr/i586-mingw32msvc) + # First look in standard location as used by Debian/Ubuntu/etc. + set(CMAKE_C_COMPILER i586-mingw32msvc-gcc) + set(CMAKE_CXX_COMPILER i586-mingw32msvc-g++) + set(CMAKE_RC_COMPILER i586-mingw32msvc-windres) + set(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc) +elseif(EXISTS /usr/i686-w64-mingw32) + # First look in standard location as used by Debian/Ubuntu/etc. + set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) + set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) + set(CMAKE_RC_COMPILER i686-w64-mingw32-windres) + set(CMAKE_AR:FILEPATH /usr/bin/i686-w64-mingw32-ar) +elseif(EXISTS /opt/mingw) + # You can get a MinGW environment using the script at . + # It downloads and builds MinGW and most of the dependencies for you. + # You can use the toolchain file generated by MXE called `mxe-conf.cmake' + # or you can use this file by adjusting the above and following paths. + set(CMAKE_C_COMPILER /opt/mingw/usr/bin/i686-pc-mingw32-gcc) + set(CMAKE_CXX_COMPILER /opt/mingw/usr/bin/i686-pc-mingw32-g++) + set(CMAKE_RC_COMPILER /opt/mingw/usr/bin/i686-pc-mingw32-windres) + set(CMAKE_FIND_ROOT_PATH /opt/mingw/usr/i686-pc-mingw32) +else() + # Else fill in local path which the user will likely adjust. + # This is the location assumed by + set(CMAKE_C_COMPILER /usr/local/cross-tools/bin/i386-mingw32-gcc) + set(CMAKE_CXX_COMPILER /usr/local/cross-tools/bin/i386-mingw32-g++) + set(CMAKE_RC_COMPILER /usr/local/cross-tools/bin/i386-mingw32-windres) + set(CMAKE_FIND_ROOT_PATH /usr/local/cross-tools) +endif() + +# Adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# Tell pkg-config not to look at the target environment's .pc files. +# Setting PKG_CONFIG_LIBDIR sets the default search directory, but we have to +# set PKG_CONFIG_PATH as well to prevent pkg-config falling back to the host's +# path. +set(ENV{PKG_CONFIG_LIBDIR} ${CMAKE_FIND_ROOT_PATH}/lib/pkgconfig) +set(ENV{PKG_CONFIG_PATH} ${CMAKE_FIND_ROOT_PATH}/lib/pkgconfig) + +set(ENV{MINGDIR} ${CMAKE_FIND_ROOT_PATH}) diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index 619bd0787..173845fea 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 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 #elif defined(__GNUG__) && __GNUG__ >= 4 #define UHD_EXPORT __attribute__((visibility("default"))) #define UHD_IMPORT __attribute__((visibility("default"))) diff --git a/host/include/uhd/transport/nirio/nirio_driver_iface.h b/host/include/uhd/transport/nirio/nirio_driver_iface.h index 83afd816a..3e0e56a7f 100644 --- a/host/include/uhd/transport/nirio/nirio_driver_iface.h +++ b/host/include/uhd/transport/nirio/nirio_driver_iface.h @@ -24,9 +24,9 @@ #include #include #if defined(UHD_PLATFORM_WIN32) - #include + #include #pragma warning(disable:4201) // nonstandard extension used : nameless struct/union - #include + #include #pragma warning(default:4201) #elif !defined(UHD_PLATFORM_LINUX) #include diff --git a/host/lib/transport/nirio/nifpga_lvbitx.cpp b/host/lib/transport/nirio/nifpga_lvbitx.cpp index b87d87a8d..189037163 100644 --- a/host/lib/transport/nirio/nifpga_lvbitx.cpp +++ b/host/lib/transport/nirio/nifpga_lvbitx.cpp @@ -115,7 +115,7 @@ std::string nifpga_lvbitx::_get_fpga_images_dir(const std::string search_paths) // directories searched for a LVBITX image. // char* uhd_images_dir; -#ifdef UHD_PLATFORM_WIN32 +#if defined(UHD_PLATFORM_WIN32) && !defined(__MINGW32__) // Some versions of MinGW don't expose _dupenv_s size_t len; errno_t err = _dupenv_s(&uhd_images_dir, &len, "UHD_IMAGES_DIR"); if(not err and uhd_images_dir != NULL) search_path_vtr.push_back(std::string(uhd_images_dir)); diff --git a/host/lib/utils/platform.cpp b/host/lib/utils/platform.cpp index e2f92039e..a9cef663b 100644 --- a/host/lib/utils/platform.cpp +++ b/host/lib/utils/platform.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010-2012 Ettus Research LLC +// Copyright 2010-2012,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 @@ -19,7 +19,7 @@ #include #include #ifdef UHD_PLATFORM_WIN32 -#include +#include #else #include #endif diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 829fb8e94..596ab1017 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -48,7 +48,11 @@ SET(test_sources ) #turn each test cpp file into an executable with an int main() function -ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN) +IF(MINGW) + ADD_DEFINITIONS(-DBOOST_TEST_MAIN) +ELSE() + ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN) +ENDIF() SET(UHD_TEST_TARGET_DEPS uhd) SET(UHD_TEST_LIBRARY_DIRS ${Boost_LIBRARY_DIRS}) @@ -57,7 +61,7 @@ SET(UHD_TEST_LIBRARY_DIRS ${Boost_LIBRARY_DIRS}) FOREACH(test_source ${test_sources}) GET_FILENAME_COMPONENT(test_name ${test_source} NAME_WE) ADD_EXECUTABLE(${test_name} ${test_source}) - TARGET_LINK_LIBRARIES(${test_name} uhd) + TARGET_LINK_LIBRARIES(${test_name} uhd ${Boost_LIBRARIES}) UHD_ADD_TEST(${test_name} ${test_name}) UHD_INSTALL(TARGETS ${test_name} RUNTIME DESTINATION ${PKG_LIB_DIR}/tests COMPONENT tests) ENDFOREACH(test_source) -- cgit v1.2.3 From befbaf97d09f1c36437bb285d7a1dc70a34ef6ab Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Sat, 24 Jan 2015 01:46:22 +0100 Subject: uhd: Added an update() method for dicts Very similar to Python's dict.update(). --- host/include/uhd/types/dict.hpp | 19 ++++++++++++++++++- host/include/uhd/types/dict.ipp | 14 ++++++++++++++ host/tests/addr_test.cpp | 7 +++++++ host/tests/dict_test.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) (limited to 'host/include') diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index 97fa8f09c..51e3e1814 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_args The arguments to copy. + * \param fail_on_conflict If true, throws. + * \throws uhd::value_error + */ + void update(const dict &new_dict, bool fail_on_conflict=true); + private: typedef std::pair pair_t; std::list _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); } + template + void dict::update(const dict &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/tests/addr_test.cpp b/host/tests/addr_test.cpp index cea2f224c..61bb6d049 100644 --- a/host/tests/addr_test.cpp +++ b/host/tests/addr_test.cpp @@ -66,6 +66,13 @@ BOOST_AUTO_TEST_CASE(test_device_addr){ old_dev_addr_vals.begin(), old_dev_addr_vals.end(), new_dev_addr_vals.begin(), new_dev_addr_vals.end() ); + + uhd::device_addr_t dev_addr_lhs1("key1=val1,key2=val2"); + dev_addr_lhs1.update(uhd::device_addr_t("key2=val2x,key3=val3"), false); + BOOST_CHECK_EQUAL(dev_addr_lhs1["key1"], "val1"); + BOOST_CHECK_EQUAL(dev_addr_lhs1["key2"], "val2x"); + BOOST_CHECK_EQUAL(dev_addr_lhs1["key3"], "val3"); + std::cout << "Merged: " << dev_addr_lhs1.to_string() << std::endl; } BOOST_AUTO_TEST_CASE(test_dboard_id){ diff --git a/host/tests/dict_test.cpp b/host/tests/dict_test.cpp index 7b388d090..333aadbba 100644 --- a/host/tests/dict_test.cpp +++ b/host/tests/dict_test.cpp @@ -70,3 +70,28 @@ BOOST_AUTO_TEST_CASE(test_dict_pop){ BOOST_CHECK(d.keys()[0] == -1); BOOST_CHECK(d.keys()[1] == 1); } + +BOOST_AUTO_TEST_CASE(test_dict_update) +{ + uhd::dict d1 = boost::assign::map_list_of + ("key1", "val1") + ("key2", "val2") + ; + uhd::dict d2 = boost::assign::map_list_of + ("key2", "val2x") + ("key3", "val3") + ; + + d1.update(d2, false /* don't throw cause of conflict */); + BOOST_CHECK_EQUAL(d1["key1"], "val1"); + BOOST_CHECK_EQUAL(d1["key2"], "val2x"); + BOOST_CHECK_EQUAL(d1["key3"], "val3"); + + uhd::dict d3 = boost::assign::map_list_of + ("key1", "val1") + ("key2", "val2") + ; + BOOST_CHECK_THROW(d3.update(d2), uhd::value_error); +} + + -- cgit v1.2.3 From bee57ee03fd4b9dac476da7e375ddd8dcc749b1b Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 15 Jan 2015 14:37:47 +0100 Subject: convert: Modifications to id_type - Converter ID symbols are exported - to_string() function for lighter feedback --- host/include/uhd/convert.hpp | 3 ++- host/lib/convert/convert_impl.cpp | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'host/include') 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{ + struct UHD_API id_type : boost::equality_comparable{ 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/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp index 329e94a4d..48eb1f8d6 100644 --- a/host/lib/convert/convert_impl.cpp +++ b/host/lib/convert/convert_impl.cpp @@ -43,10 +43,10 @@ bool convert::operator==(const convert::id_type &lhs, const convert::id_type &rh std::string convert::id_type::to_pp_string(void) const{ return str(boost::format( "conversion ID\n" - " Input format: %s\n" - " Num inputs: %d\n" + " Input format: %s\n" + " Num inputs: %d\n" " Output format: %s\n" - " Num outputs: %d\n" + " Num outputs: %d\n" ) % this->input_format % this->num_inputs @@ -55,6 +55,15 @@ std::string convert::id_type::to_pp_string(void) const{ ); } +std::string convert::id_type::to_string(void) const{ + return str(boost::format("%s (%d) -> %s (%d)") + % this->input_format + % this->num_inputs + % this->output_format + % this->num_outputs + ); +} + /*********************************************************************** * Setup the table registry **********************************************************************/ -- cgit v1.2.3 From 7d97ab60012b99ed92fb122a3a68d68515a404fa Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 3 Feb 2015 17:20:09 +0100 Subject: multi_usrp: Added a normalized gain setting Adds more methods: {set,get}_normalized_{tx,rx}_gain() which allow changing and reading back the gain within [0, 1]. --- host/include/uhd/usrp/multi_usrp.hpp | 57 ++++++++++++++++++++++++++++++++++++ host/lib/usrp/multi_usrp.cpp | 51 ++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) (limited to 'host/include') diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index 2362ebcd7..cebfda5a2 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -26,6 +26,7 @@ #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 #include #include @@ -494,6 +495,24 @@ public: return this->set_rx_gain(gain, ALL_GAINS, chan); } + /*! + * 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; + /*! * Get the RX gain value for the specified gain element. * For an empty name, sum across all gain elements. @@ -508,6 +527,19 @@ public: return this->get_rx_gain(ALL_GAINS, chan); } + /*! + * Return the normalized RX gain value. + * + * See set_normalized_rx_gain() for a discussion of normalized + * gains. + * + * \param gain the normalized gain value + * \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. @@ -732,6 +764,18 @@ public: return this->set_tx_gain(gain, ALL_GAINS, chan); } + /*! + * 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. @@ -746,6 +790,19 @@ public: return this->get_tx_gain(ALL_GAINS, chan); } + /*! + * Return the normalized TX gain value. + * + * See set_normalized_rx_gain() for a discussion of normalized + * gains. + * + * \param gain the normalized gain value + * \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. diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index e97787785..eab8c5283 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -831,6 +831,16 @@ public: } } + void set_normalized_rx_gain(double gain, size_t chan = 0) + { + if (gain > 1.0 || gain < 0.0) { + throw uhd::runtime_error("Normalized gain out of range, must be in [0, 1]."); + } + gain_range_t gain_range = get_rx_gain_range(ALL_GAINS, chan); + double abs_gain = (gain * (gain_range.stop() - gain_range.start())) + gain_range.start(); + set_rx_gain(abs_gain, ALL_GAINS, chan); + } + double get_rx_gain(const std::string &name, size_t chan){ try { return rx_gain_group(chan)->get_value(name); @@ -839,6 +849,21 @@ public: } } + double get_normalized_rx_gain(size_t chan) + { + gain_range_t gain_range = get_rx_gain_range(ALL_GAINS, chan); + double gain_range_width = gain_range.stop() - gain_range.start(); + // In case we have a device without a range of gains: + if (gain_range_width == 0.0) { + return 0; + } + double norm_gain = (get_rx_gain(ALL_GAINS, chan) - gain_range.start()) / gain_range_width; + // Avoid rounding errors: + if (norm_gain > 1.0) return 1.0; + if (norm_gain < 0.0) return 0.0; + return norm_gain; + } + gain_range_t get_rx_gain_range(const std::string &name, size_t chan){ try { return rx_gain_group(chan)->get_range(name); @@ -1032,6 +1057,17 @@ public: } } + void set_normalized_tx_gain(double gain, size_t chan = 0) + { + if (gain > 1.0 || gain < 0.0) { + throw uhd::runtime_error("Normalized gain out of range, must be in [0, 1]."); + } + gain_range_t gain_range = get_tx_gain_range(ALL_GAINS, chan); + double abs_gain = (gain * (gain_range.stop() - gain_range.start())) + gain_range.start(); + set_tx_gain(abs_gain, ALL_GAINS, chan); + } + + double get_tx_gain(const std::string &name, size_t chan){ try { return tx_gain_group(chan)->get_value(name); @@ -1040,6 +1076,21 @@ public: } } + double get_normalized_tx_gain(size_t chan) + { + gain_range_t gain_range = get_tx_gain_range(ALL_GAINS, chan); + double gain_range_width = gain_range.stop() - gain_range.start(); + // In case we have a device without a range of gains: + if (gain_range_width == 0.0) { + return 0.0; + } + double norm_gain = (get_rx_gain(ALL_GAINS, chan) - gain_range.start()) / gain_range_width; + // Avoid rounding errors: + if (norm_gain > 1.0) return 1.0; + if (norm_gain < 0.0) return 0.0; + return norm_gain; + } + gain_range_t get_tx_gain_range(const std::string &name, size_t chan){ try { return tx_gain_group(chan)->get_range(name); -- cgit v1.2.3 From 4602ea9148e5e36fefca6402b7dcc5a1104e7410 Mon Sep 17 00:00:00 2001 From: Julian Arnold Date: Fri, 20 Feb 2015 10:49:53 -0800 Subject: uhd: iq imbalance correction api --- host/include/uhd/usrp/multi_usrp.hpp | 8 ++++++++ host/lib/usrp/multi_usrp.cpp | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'host/include') diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index cebfda5a2..8357b9ffb 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -651,6 +651,14 @@ public: */ virtual void set_rx_dc_offset(const std::complex &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. diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index eab8c5283..e7d39b244 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -916,6 +916,9 @@ public: if (chan != ALL_CHANS){ if (_tree->exists(rx_fe_root(chan) / "dc_offset" / "enable")) { _tree->access(rx_fe_root(chan) / "dc_offset" / "enable").set(enb); + } else if (_tree->exists(rx_rf_fe_root(chan) / "dc_offset" / "enable")) { + /*For B2xx devices the dc-offset correction is implemented in the rf front-end*/ + _tree->access(rx_rf_fe_root(chan) / "dc_offset" / "enable").set(enb); } else { UHD_MSG(warning) << "Setting DC offset compensation is not possible on this device." << std::endl; } @@ -940,6 +943,20 @@ public: } } + void set_rx_iq_balance(const bool enb, size_t chan){ + if (chan != ALL_CHANS){ + if (_tree->exists(rx_rf_fe_root(chan) / "iq_balance" / "enable")) { + _tree->access(rx_rf_fe_root(chan) / "iq_balance" / "enable").set(enb); + } else { + UHD_MSG(warning) << "Setting IQ imbalance compensation is not possible on this device." << std::endl; + } + return; + } + for (size_t c = 0; c < get_rx_num_channels(); c++){ + this->set_rx_iq_balance(enb, c); + } + } + void set_rx_iq_balance(const std::complex &offset, size_t chan){ if (chan != ALL_CHANS){ if (_tree->exists(rx_fe_root(chan) / "iq_balance" / "value")) { -- cgit v1.2.3 From 499bcc0238315a2e1f01625d725a67b168acb99f Mon Sep 17 00:00:00 2001 From: Marcus Müller Date: Fri, 27 Feb 2015 19:44:26 +0100 Subject: uhd: Fixed: Exception during detection kills device::make On systems with libusb but not USB, device detection for USB devices fails (lsusb itself dies with "error -99"). This crashes the device detection process itself. Also made the documentation for ::make match what it actually does. --- host/include/uhd/device.hpp | 4 +++- host/lib/device.cpp | 23 ++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index 1e88a4138..5ca48f8e9 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -77,7 +77,9 @@ public: /*! * \brief Create a new device from the device address hint. * - * The make routine will call find and pick one of the results. + * The method will go through the registered device types and pick one of + * the discovered devices. + * * By default, the first result will be used to create a new device. * Use the which parameter as an index into the list of results. * diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 006ea6ec8..3e84d5bea 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010-2011,2014 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 @@ -90,9 +90,9 @@ device_addrs_t device::find(const device_addr_t &hint, device_filter_t filter){ device_addrs_t device_addrs; - BOOST_FOREACH(const dev_fcn_reg_t &fcn, get_dev_fcn_regs()){ - try{ - if(filter == ANY or fcn.get<2>() == filter){ + BOOST_FOREACH(const dev_fcn_reg_t &fcn, get_dev_fcn_regs()) { + try { + if (filter == ANY or fcn.get<2>() == filter) { device_addrs_t discovered_addrs = fcn.get<0>()(hint); device_addrs.insert( device_addrs.begin(), @@ -101,7 +101,7 @@ device_addrs_t device::find(const device_addr_t &hint, device_filter_t filter){ ); } } - catch(const std::exception &e){ + catch (const std::exception &e) { UHD_MSG(error) << "Device discovery error: " << e.what() << std::endl; } } @@ -119,12 +119,17 @@ device::sptr device::make(const device_addr_t &hint, device_filter_t filter, siz std::vector dev_addr_makers; BOOST_FOREACH(const dev_fcn_reg_t &fcn, get_dev_fcn_regs()){ - if(filter == ANY or fcn.get<2>() == filter){ - BOOST_FOREACH(device_addr_t dev_addr, fcn.get<0>()(hint)){ - //append the discovered address and its factory function - dev_addr_makers.push_back(dev_addr_make_t(dev_addr, fcn.get<1>())); + try{ + if(filter == ANY or fcn.get<2>() == filter){ + BOOST_FOREACH(device_addr_t dev_addr, fcn.get<0>()(hint)){ + //append the discovered address and its factory function + dev_addr_makers.push_back(dev_addr_make_t(dev_addr, fcn.get<1>())); + } } } + catch(const std::exception &e){ + UHD_MSG(error) << "Device discovery error: " << e.what() << std::endl; + } } //check that we found any devices -- cgit v1.2.3 From 33edac343488fdd87337e308b277adca69f16819 Mon Sep 17 00:00:00 2001 From: Julian Arnold Date: Thu, 5 Mar 2015 15:24:46 -0800 Subject: uhd: AGC support --- host/include/uhd/usrp/multi_usrp.hpp | 10 ++++++++++ host/lib/usrp/multi_usrp.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) (limited to 'host/include') diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index 8357b9ffb..e8fcdb4b6 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -513,6 +513,16 @@ public: */ 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 on 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. diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index e7d39b244..bc6e121d0 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -824,6 +824,26 @@ public: } void set_rx_gain(double gain, const std::string &name, size_t chan){ + /* Check if any AGC mode is enable and if so warn the user */ + if (chan != ALL_CHANS) { + if (_tree->exists(rx_rf_fe_root(chan) / "gain" / "agc")) { + bool agc = _tree->access(rx_rf_fe_root(chan) / "gain" / "agc" / "enable").get(); + if(agc) { + UHD_MSG(warning) << "AGC enabled for this channel. Setting will be ignored." << std::endl; + } + } + } else { + for (size_t c = 0; c < get_rx_num_channels(); c++){ + if (_tree->exists(rx_rf_fe_root(c) / "gain" / "agc")) { + bool agc = _tree->access(rx_rf_fe_root(chan) / "gain" / "agc" / "enable").get(); + if(agc) { + UHD_MSG(warning) << "AGC enabled for this channel. Setting will be ignored." << std::endl; + } + } + } + } + /* Apply gain setting. + * If device is in AGC mode it will ignore the setting. */ try { return rx_gain_group(chan)->set_value(gain, name); } catch (uhd::key_error &e) { @@ -841,6 +861,22 @@ public: set_rx_gain(abs_gain, ALL_GAINS, chan); } + void set_rx_agc(bool enable, size_t chan = 0) + { + if (chan != ALL_CHANS){ + if (_tree->exists(rx_rf_fe_root(chan) / "gain" / "agc" / "enable")) { + _tree->access(rx_rf_fe_root(chan) / "gain" / "agc" / "enable").set(enable); + } else { + UHD_MSG(warning) << "AGC is not available on this device." << std::endl; + } + return; + } + for (size_t c = 0; c < get_rx_num_channels(); c++){ + this->set_rx_agc(enable, c); + } + + } + double get_rx_gain(const std::string &name, size_t chan){ try { return rx_gain_group(chan)->get_value(name); -- cgit v1.2.3 From a55b5a097da01606f23209713bf1ce754be5b7d3 Mon Sep 17 00:00:00 2001 From: Julian Arnold Date: Fri, 30 Jan 2015 15:11:15 -0800 Subject: uhd: Introduced filter API. This is a unified API to access filters on USRP devices. Filters can be accessed through the property tree, or multi_usrp. --- host/include/uhd/types/CMakeLists.txt | 1 + host/include/uhd/types/filters.hpp | 286 ++++++++++++++++++++++++++++++++++ host/include/uhd/usrp/multi_usrp.hpp | 33 ++++ host/lib/types/CMakeLists.txt | 1 + host/lib/types/filters.cpp | 74 +++++++++ host/lib/usrp/multi_usrp.cpp | 83 ++++++++++ 6 files changed, 478 insertions(+) create mode 100644 host/include/uhd/types/filters.hpp create mode 100644 host/lib/types/filters.cpp (limited to 'host/include') diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt index f5a92a805..b82c2b7f2 100644 --- a/host/include/uhd/types/CMakeLists.txt +++ b/host/include/uhd/types/CMakeLists.txt @@ -37,6 +37,7 @@ UHD_INSTALL(FILES tune_request.hpp tune_result.hpp wb_iface.hpp + filters.hpp DESTINATION ${INCLUDE_DIR}/uhd/types COMPONENT headers ) diff --git a/host/include/uhd/types/filters.hpp b/host/include/uhd/types/filters.hpp new file mode 100644 index 000000000..0cb23b294 --- /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 . +// + +#ifndef INCLUDED_UHD_TYPES_FILTERS_HPP +#define INCLUDED_UHD_TYPES_FILTERS_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace uhd{ + + class UHD_API filter_info_base + { + public: + typedef boost::shared_ptr 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 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 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 + 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 _taps; + + public: + typedef boost::shared_ptr 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& 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& get_taps() + { + return _taps; + } + + virtual std::string to_pp_string() + { + std::ostringstream os; + os< + class UHD_API digital_filter_fir : public digital_filter_base + { + public: + typedef boost::shared_ptr > 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& taps + ): + digital_filter_base(type, bypass, position_index, rate, interpolation, decimation, tap_bit_width, max_num_taps, taps) + { + //NOP + } + + void set_taps(const std::vector& 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 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/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index e8fcdb4b6..1c408d56e 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -973,6 +974,38 @@ public: */ virtual boost::uint32_t get_gpio_attr(const std::string &bank, const std::string &attr, 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 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/lib/types/CMakeLists.txt b/host/lib/types/CMakeLists.txt index 853da3fe2..821754386 100644 --- a/host/lib/types/CMakeLists.txt +++ b/host/lib/types/CMakeLists.txt @@ -91,4 +91,5 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/tune.cpp ${CMAKE_CURRENT_SOURCE_DIR}/types.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wb_iface.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/filters.cpp ) diff --git a/host/lib/types/filters.cpp b/host/lib/types/filters.cpp new file mode 100644 index 000000000..4ee06491f --- /dev/null +++ b/host/lib/types/filters.cpp @@ -0,0 +1,74 @@ +// +// 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 . +// + +#include + +using namespace uhd; + +std::ostream& uhd::operator<<(std::ostream& os, filter_info_base& f) +{ + return os << f.to_pp_string(); +} + +std::string filter_info_base::to_pp_string() +{ + std::ostringstream os; + os << "[filter_info_base]" << std::endl; + switch(_type){ + case ANALOG_LOW_PASS: + os << "type: " << "Analog Low-pass" << std::endl; + break; + case ANALOG_BAND_PASS: + os << "type: " << "Analog Band-pass" << std::endl; + break; + case DIGITAL_I16: + os << "type: " << "Digital (i16)" << std::endl; + break; + case DIGITAL_FIR_I16: + os << "type: " << "Digital FIR (i16)" << std::endl; + break; + default: + os << "type: " << "Unknown type!" << std::endl; + break; + } + + os << "bypass enable: " << _bypass << std::endl + <<"position index: " << _position_index << std::endl; + + std::string str = os.str(); + return str; +} + +std::string analog_filter_base::to_pp_string() +{ + std::ostringstream os; + os << filter_info_base::to_pp_string() << + "\t[analog_filter_base]" << std::endl << + "\tdesc: " << _analog_type << std::endl; + return std::string(os.str()); + +} + +std::string analog_filter_lp::to_pp_string() +{ + std::ostringstream os; + os << analog_filter_base::to_pp_string() << + "\t\t[analog_filter_lp]" << std::endl << + "\t\tcutoff: " << _cutoff << std::endl << + "\t\trolloff: " << _rolloff << std::endl; + return std::string(os.str()); +} diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index bc6e121d0..570c67875 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include using namespace uhd; @@ -1007,6 +1009,87 @@ public: } } + std::vector get_filter_names(const std::string &search_mask) + { + std::vector ret; + + for (size_t chan = 0; chan < get_rx_num_channels(); chan++){ + + if (_tree->exists(rx_rf_fe_root(chan) / "filters")) { + std::vector names = _tree->list(rx_rf_fe_root(chan) / "filters"); + for(size_t i = 0; i < names.size(); i++) + { + std::string name = rx_rf_fe_root(chan) / "filters" / names[i]; + if((search_mask.empty()) or boost::contains(name, search_mask)) { + ret.push_back(name); + } + } + } + if (_tree->exists(rx_dsp_root(chan) / "filters")) { + std::vector names = _tree->list(rx_dsp_root(chan) / "filters"); + for(size_t i = 0; i < names.size(); i++) + { + std::string name = rx_dsp_root(chan) / "filters" / names[i]; + if((search_mask.empty()) or (boost::contains(name, search_mask))) { + ret.push_back(name); + } + } + } + + } + + for (size_t chan = 0; chan < get_tx_num_channels(); chan++){ + + if (_tree->exists(tx_rf_fe_root(chan) / "filters")) { + std::vector names = _tree->list(tx_rf_fe_root(chan) / "filters"); + for(size_t i = 0; i < names.size(); i++) + { + std::string name = tx_rf_fe_root(chan) / "filters" / names[i]; + if((search_mask.empty()) or (boost::contains(name, search_mask))) { + ret.push_back(name); + } + } + } + if (_tree->exists(rx_dsp_root(chan) / "filters")) { + std::vector names = _tree->list(tx_dsp_root(chan) / "filters"); + for(size_t i = 0; i < names.size(); i++) + { + std::string name = tx_dsp_root(chan) / "filters" / names[i]; + if((search_mask.empty()) or (boost::contains(name, search_mask))) { + ret.push_back(name); + } + } + } + + } + + return ret; + } + + filter_info_base::sptr get_filter(const std::string &path) + { + std::vector possible_names = get_filter_names(""); + std::vector::iterator it; + it = find(possible_names.begin(), possible_names.end(), path); + if (it == possible_names.end()) { + throw uhd::runtime_error("Attempting to get non-existing filter: "+path); + } + + return _tree->access(path / "value").get(); + } + + void set_filter(const std::string &path, filter_info_base::sptr filter) + { + std::vector possible_names = get_filter_names(""); + std::vector::iterator it; + it = find(possible_names.begin(), possible_names.end(), path); + if (it == possible_names.end()) { + throw uhd::runtime_error("Attempting to set non-existing filter: "+path); + } + + _tree->access(path / "value").set(filter); + } + /******************************************************************* * TX methods ******************************************************************/ -- cgit v1.2.3 From cc1bb014033b531e5cff1523eb3c3f925aa576f6 Mon Sep 17 00:00:00 2001 From: Michael Dickens Date: Sat, 7 Mar 2015 11:11:05 -0500 Subject: nirio: have get_direction() and get_scalar_type() return their actual types. --- host/include/uhd/transport/nirio/nirio_fifo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/transport/nirio/nirio_fifo.h b/host/include/uhd/transport/nirio/nirio_fifo.h index c424275fc..5a2e29631 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(); -- cgit v1.2.3 From a4eee83b82a5f57b22c092e5f9dc825baf8fe6dd Mon Sep 17 00:00:00 2001 From: Michael Dickens Date: Sat, 7 Mar 2015 11:15:10 -0500 Subject: nirio: hopefully fix #pragma declarations; "push" and "pop" introduced in GCC 4.6; works with all clang. --- host/include/uhd/transport/nirio/nirio_fifo.ipp | 10 ++++++---- host/lib/transport/nirio/nirio_resource_manager.cpp | 11 ++++++----- host/lib/transport/nirio/niriok_proxy.cpp | 10 ++++++---- host/lib/transport/nirio/niriok_proxy_impl_v1.cpp | 11 ++++++----- host/lib/transport/nirio/niriok_proxy_impl_v2.cpp | 10 ++++++---- 5 files changed, 30 insertions(+), 22 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/transport/nirio/nirio_fifo.ipp b/host/include/uhd/transport/nirio/nirio_fifo.ipp index ca6486e30..49ce43888 100644 --- a/host/include/uhd/transport/nirio/nirio_fifo.ipp +++ b/host/include/uhd/transport/nirio/nirio_fifo.ipp @@ -15,9 +15,11 @@ // along with this program. If not, see . // -#ifdef __clang__ - #pragma GCC diagnostic push ignored "-Wmissing-field-initializers" -#elif defined(__GNUC__) +// "push" and "pop" introduced in GCC 4.6; works with all clang +#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) + #pragma GCC diagnostic push +#endif +#if defined(__clang__) || defined(__GNUC__) #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif @@ -375,6 +377,6 @@ inline datatype_info_t nirio_fifo::_get_datatype_info() return datatype_info_t(RIO_SCALAR_TYPE_UQ, 8); } -#ifdef __GNUC__ +#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) #pragma GCC diagnostic pop #endif diff --git a/host/lib/transport/nirio/nirio_resource_manager.cpp b/host/lib/transport/nirio/nirio_resource_manager.cpp index e56670de0..d62f5c40d 100644 --- a/host/lib/transport/nirio/nirio_resource_manager.cpp +++ b/host/lib/transport/nirio/nirio_resource_manager.cpp @@ -15,12 +15,13 @@ // along with this program. If not, see . // - #include -#ifdef __clang__ - #pragma GCC diagnostic push ignored "-Wmissing-field-initializers" -#elif defined(__GNUC__) +// "push" and "pop" introduced in GCC 4.6; works with all clang +#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) + #pragma GCC diagnostic push +#endif +#if defined(__clang__) || defined(__GNUC__) #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif @@ -100,6 +101,6 @@ nirio_fifo_info_t* nirio_resource_manager::_lookup_fifo_info(const char* fifo_na }} -#ifdef __GNUC__ +#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) #pragma GCC diagnostic pop #endif diff --git a/host/lib/transport/nirio/niriok_proxy.cpp b/host/lib/transport/nirio/niriok_proxy.cpp index cc2daba22..0cc13efb8 100644 --- a/host/lib/transport/nirio/niriok_proxy.cpp +++ b/host/lib/transport/nirio/niriok_proxy.cpp @@ -20,9 +20,11 @@ #include #include -#ifdef __clang__ - #pragma GCC diagnostic push ignored "-Wmissing-field-initializers" -#elif defined(__GNUC__) +// "push" and "pop" introduced in GCC 4.6; works with all clang +#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) + #pragma GCC diagnostic push +#endif +#if defined(__clang__) || defined(__GNUC__) #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif @@ -73,6 +75,6 @@ namespace uhd { namespace niusrprio } }} -#ifdef __GNUC__ +#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) #pragma GCC diagnostic pop #endif diff --git a/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp b/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp index f4a8e4ff5..f0ffe2ffc 100644 --- a/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp +++ b/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp @@ -15,13 +15,14 @@ // along with this program. If not, see . // - #include #include -#ifdef __clang__ - #pragma GCC diagnostic push ignored "-Wmissing-field-initializers" -#elif defined(__GNUC__) +// "push" and "pop" introduced in GCC 4.6; works with all clang +#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) + #pragma GCC diagnostic push +#endif +#if defined(__clang__) || defined(__GNUC__) #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif @@ -490,6 +491,6 @@ namespace uhd { namespace niusrprio }} -#ifdef __GNUC__ +#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) #pragma GCC diagnostic pop #endif diff --git a/host/lib/transport/nirio/niriok_proxy_impl_v2.cpp b/host/lib/transport/nirio/niriok_proxy_impl_v2.cpp index 8fb82708e..748db5cf8 100644 --- a/host/lib/transport/nirio/niriok_proxy_impl_v2.cpp +++ b/host/lib/transport/nirio/niriok_proxy_impl_v2.cpp @@ -19,9 +19,11 @@ #include #include -#ifdef __clang__ - #pragma GCC diagnostic push ignored "-Wmissing-field-initializers" -#elif defined(__GNUC__) +// "push" and "pop" introduced in GCC 4.6; works with all clang +#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) + #pragma GCC diagnostic push +#endif +#if defined(__clang__) || defined(__GNUC__) #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif @@ -642,6 +644,6 @@ namespace uhd { namespace niusrprio }} -#ifdef __GNUC__ +#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) #pragma GCC diagnostic pop #endif -- cgit v1.2.3 From eed305afee7c5c34a48efd75dfb49ba20072f518 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 11 Mar 2015 16:48:55 -0700 Subject: uhd: Fixed some punctuation-related compiler warnings --- host/include/uhd/transport/vrt_if_packet.hpp | 4 ++-- host/include/uhd/types/clock_config.hpp | 4 ++-- host/include/uhd/utils/log.hpp | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/transport/vrt_if_packet.hpp b/host/include/uhd/transport/vrt_if_packet.hpp index d16892281..362531567 100644 --- a/host/include/uhd/transport/vrt_if_packet.hpp +++ b/host/include/uhd/transport/vrt_if_packet.hpp @@ -46,7 +46,7 @@ namespace vrt{ { LINK_TYPE_NONE = 0x0, LINK_TYPE_CHDR = 0x1, - LINK_TYPE_VRLP = 0x2, + LINK_TYPE_VRLP = 0x2 } link_type; //packet type @@ -54,7 +54,7 @@ namespace vrt{ { 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 } packet_type; //size fields diff --git a/host/include/uhd/types/clock_config.hpp b/host/include/uhd/types/clock_config.hpp index 27b312245..6d5d01ec2 100644 --- a/host/include/uhd/types/clock_config.hpp +++ b/host/include/uhd/types/clock_config.hpp @@ -47,12 +47,12 @@ namespace uhd{ REF_AUTO = int('a'), //automatic (device specific) REF_INT = int('i'), //internal reference REF_SMA = int('s'), //external sma port - REF_MIMO = int('m'), //reference from mimo cable + REF_MIMO = int('m') //reference from mimo cable } ref_source; enum pps_source_t { PPS_INT = int('i'), //there is no internal PPS_SMA = int('s'), //external sma port - PPS_MIMO = int('m'), //time sync from mimo cable + PPS_MIMO = int('m') //time sync from mimo cable } pps_source; enum pps_polarity_t { PPS_NEG = int('n'), //negative edge diff --git a/host/include/uhd/utils/log.hpp b/host/include/uhd/utils/log.hpp index 5baa00108..106c0d9d5 100644 --- a/host/include/uhd/utils/log.hpp +++ b/host/include/uhd/utils/log.hpp @@ -76,7 +76,7 @@ namespace uhd{ namespace _log{ regularly = 3, rarely = 4, very_rarely = 5, - never = 6, + never = 6 }; //! Internal logging object (called by UHD_LOG macros) @@ -101,12 +101,12 @@ namespace uhd{ namespace _log{ // General insertion overload template - INSERTION_OVERLOAD(T val); + INSERTION_OVERLOAD(T val) // Insertion overloads for std::ostream manipulators - INSERTION_OVERLOAD(std::ostream& (*val)(std::ostream&)); - INSERTION_OVERLOAD(std::ios& (*val)(std::ios&)); - INSERTION_OVERLOAD(std::ios_base& (*val)(std::ios_base&)); + INSERTION_OVERLOAD(std::ostream& (*val)(std::ostream&)) + INSERTION_OVERLOAD(std::ios& (*val)(std::ios&)) + INSERTION_OVERLOAD(std::ios_base& (*val)(std::ios_base&)) private: std::ostringstream _ss; -- cgit v1.2.3 From fae746179cbb1d8ac146dcae9b5d6cb58b366a56 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 11 Mar 2015 16:14:00 -0700 Subject: uhd: Fixed multiple compiler warnings (unused variables, missing literal f) --- host/include/uhd/utils/math.hpp | 2 +- host/lib/usrp/b200/b200_impl.cpp | 2 +- host/lib/usrp/dboard/db_ubx.cpp | 2 +- host/lib/usrp/multi_usrp.cpp | 12 ++++++------ host/lib/usrp_clock/octoclock/octoclock_impl.cpp | 2 +- host/utils/b2xx_fx3_utils.cpp | 4 ++-- host/utils/query_gpsdo_sensors.cpp | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp index 21825c3dc..e6ac4d3dc 100644 --- a/host/include/uhd/utils/math.hpp +++ b/host/include/uhd/utils/math.hpp @@ -60,7 +60,7 @@ namespace math { * values, a custom epsilon should be defined for those computations. This * use-case is provided for in the `fp_compare_epsilon` class constructor. */ - static const float SINGLE_PRECISION_EPSILON = 1.19e-7; + static const float SINGLE_PRECISION_EPSILON = 1.19e-7f; static const double DOUBLE_PRECISION_EPSILON = 2.22e-16; namespace fp_compare { diff --git a/host/lib/usrp/b200/b200_impl.cpp b/host/lib/usrp/b200/b200_impl.cpp index e30853762..304a3fc48 100644 --- a/host/lib/usrp/b200/b200_impl.cpp +++ b/host/lib/usrp/b200/b200_impl.cpp @@ -1007,6 +1007,6 @@ sensor_value_t b200_impl::get_ref_locked(void) sensor_value_t b200_impl::get_fe_pll_locked(const bool is_tx) { const boost::uint32_t st = _local_ctrl->peek32(RB32_CORE_PLL); - const bool locked = is_tx ? st & 0x1 : st & 0x2; + const bool locked = is_tx ? bool(st & 0x1) : bool(st & 0x2); return sensor_value_t("LO", locked, "locked", "unlocked"); } diff --git a/host/lib/usrp/dboard/db_ubx.cpp b/host/lib/usrp/dboard/db_ubx.cpp index b6cc1421c..5184d2ecb 100644 --- a/host/lib/usrp/dboard/db_ubx.cpp +++ b/host/lib/usrp/dboard/db_ubx.cpp @@ -84,7 +84,7 @@ protected: // Get only regs with changes try { changed_regs = get_changed_addrs(); - } catch (uhd::runtime_error& e) { + } catch (uhd::runtime_error&) { // No saved state - write all regs for (int addr = 5; addr >= 0; addr--) changed_regs.insert(boost::uint32_t(addr)); diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 175633c4c..45e736757 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -823,7 +823,7 @@ public: void set_rx_gain(double gain, const std::string &name, size_t chan){ try { return rx_gain_group(chan)->set_value(gain, name); - } catch (uhd::key_error &e) { + } catch (uhd::key_error &) { THROW_GAIN_NAME_ERROR(name,chan,rx); } } @@ -831,7 +831,7 @@ public: double get_rx_gain(const std::string &name, size_t chan){ try { return rx_gain_group(chan)->get_value(name); - } catch (uhd::key_error &e) { + } catch (uhd::key_error &) { THROW_GAIN_NAME_ERROR(name,chan,rx); } } @@ -839,7 +839,7 @@ public: gain_range_t get_rx_gain_range(const std::string &name, size_t chan){ try { return rx_gain_group(chan)->get_range(name); - } catch (uhd::key_error &e) { + } catch (uhd::key_error &) { THROW_GAIN_NAME_ERROR(name,chan,rx); } } @@ -1024,7 +1024,7 @@ public: void set_tx_gain(double gain, const std::string &name, size_t chan){ try { return tx_gain_group(chan)->set_value(gain, name); - } catch (uhd::key_error &e) { + } catch (uhd::key_error &) { THROW_GAIN_NAME_ERROR(name,chan,tx); } } @@ -1032,7 +1032,7 @@ public: double get_tx_gain(const std::string &name, size_t chan){ try { return tx_gain_group(chan)->get_value(name); - } catch (uhd::key_error &e) { + } catch (uhd::key_error &) { THROW_GAIN_NAME_ERROR(name,chan,tx); } } @@ -1040,7 +1040,7 @@ public: gain_range_t get_tx_gain_range(const std::string &name, size_t chan){ try { return tx_gain_group(chan)->get_range(name); - } catch (uhd::key_error &e) { + } catch (uhd::key_error &) { THROW_GAIN_NAME_ERROR(name,chan,tx); } } diff --git a/host/lib/usrp_clock/octoclock/octoclock_impl.cpp b/host/lib/usrp_clock/octoclock/octoclock_impl.cpp index d55fab10e..b98d95725 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_impl.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_impl.cpp @@ -417,7 +417,7 @@ std::string octoclock_impl::_get_images_help_message(const std::string &addr){ try{ image_location = uhd::find_image_path(image_name); } - catch(const std::exception &e){ + catch(const std::exception &){ return str(boost::format("Could not find %s in your images path.\n%s") % image_name % uhd::print_utility_error("uhd_images_downloader.py")); diff --git a/host/utils/b2xx_fx3_utils.cpp b/host/utils/b2xx_fx3_utils.cpp index 8b64be63e..572daef70 100644 --- a/host/utils/b2xx_fx3_utils.cpp +++ b/host/utils/b2xx_fx3_utils.cpp @@ -173,7 +173,7 @@ uhd::transport::usb_device_handle::sptr open_device(const boost::uint16_t vid, c if (!handle) std::cerr << "Cannot open device" << std::endl; } - catch(const std::exception &e) { + catch(const std::exception &) { std::cerr << "Failed to communicate with the device!" << std::endl; #ifdef UHD_PLATFORM_WIN32 std::cerr << "The necessary drivers are not installed. Read the UHD Transport Application Notes for details:\nhttp://files.ettus.com/manual/page_transport.html" << std::endl; @@ -195,7 +195,7 @@ b200_iface::sptr make_b200_iface(const uhd::transport::usb_device_handle::sptr & if (!b200) std::cerr << "Cannot create device interface" << std::endl; } - catch(const std::exception &e) { + catch(const std::exception &) { std::cerr << "Failed to communicate with the device!" << std::endl; #ifdef UHD_PLATFORM_WIN32 std::cerr << "The necessary drivers are not installed. Read the UHD Transport Application Notes for details:\nhttp://files.ettus.com/manual/page_transport.html" << std::endl; diff --git a/host/utils/query_gpsdo_sensors.cpp b/host/utils/query_gpsdo_sensors.cpp index 05f918eb4..9a40d2b42 100644 --- a/host/utils/query_gpsdo_sensors.cpp +++ b/host/utils/query_gpsdo_sensors.cpp @@ -118,7 +118,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::sensor_value_t rmc_string = usrp->get_mboard_sensor("gps_gprmc"); std::cout << boost::format("Printing available NMEA strings:\n"); std::cout << boost::format("%s\n%s\n%s\n") % gga_string.to_pp_string() % rmc_string.to_pp_string() % gps_time.to_pp_string(); - } catch (std::exception &e) { + } catch (std::exception &) { std::cout << "NMEA strings not implemented for this device." << std::endl; } std::cout << boost::format("UHD Device time: %.0f seconds\n") % (last_pps_time.get_real_secs()); -- cgit v1.2.3 From cc7d37f114d5a14b4e45372f38324bf95115b6b9 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 11 Mar 2015 16:45:19 -0700 Subject: uhd: Fixed several type-cast related warnings for naggy compilers --- host/examples/txrx_loopback_to_file.cpp | 4 ++-- host/include/uhd/utils/fp_compare_delta.ipp | 20 +++++++++--------- host/include/uhd/utils/math.hpp | 2 +- host/lib/usrp/cores/rx_dsp_core_3000.cpp | 2 +- host/lib/usrp/cores/time_core_3000.cpp | 6 +++--- host/lib/usrp/dboard/db_cbx.cpp | 2 +- host/lib/usrp/multi_usrp.cpp | 2 +- host/tests/fp_compare_delta_test.cpp | 26 +++++++++++------------ host/tests/fp_compare_epsilon_test.cpp | 32 ++++++++++++++--------------- host/utils/usrp_cal_utils.hpp | 2 +- 10 files changed, 49 insertions(+), 49 deletions(-) (limited to 'host/include') diff --git a/host/examples/txrx_loopback_to_file.cpp b/host/examples/txrx_loopback_to_file.cpp index 4eb6daa6c..efa23c410 100644 --- a/host/examples/txrx_loopback_to_file.cpp +++ b/host/examples/txrx_loopback_to_file.cpp @@ -182,7 +182,7 @@ template void recv_to_file( UHD_ASSERT_THROW(outfiles.size() == buffs.size()); UHD_ASSERT_THROW(buffs.size() == rx_channel_nums.size()); bool overflow_message = true; - float timeout = settling_time + 0.1; //expected settling time + padding for first recv + float timeout = settling_time + 0.1f; //expected settling time + padding for first recv //setup streaming uhd::stream_cmd_t stream_cmd((num_requested_samples == 0)? @@ -196,7 +196,7 @@ template void recv_to_file( while(not stop_signal_called and (num_requested_samples != num_total_samps or num_requested_samples == 0)){ size_t num_rx_samps = rx_stream->recv(buff_ptrs, samps_per_buff, md, timeout); - timeout = 0.1; //small timeout for subsequent recv + timeout = 0.1f; //small timeout for subsequent recv if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) { std::cout << boost::format("Timeout while streaming") << std::endl; diff --git a/host/include/uhd/utils/fp_compare_delta.ipp b/host/include/uhd/utils/fp_compare_delta.ipp index 092ade6e9..49cbc281b 100644 --- a/host/include/uhd/utils/fp_compare_delta.ipp +++ b/host/include/uhd/utils/fp_compare_delta.ipp @@ -100,8 +100,8 @@ namespace uhd { namespace math { namespace fp_compare { template UHD_INLINE bool operator==(fp_compare_delta lhs, double rhs) { - float_t delta = fp_compare_select_delta(double(lhs._delta), - DOUBLE_PRECISION_DELTA); + float_t delta = float_t(fp_compare_select_delta(double(lhs._delta), + DOUBLE_PRECISION_DELTA)); return (std::fabs(lhs._value - rhs) < delta); } @@ -112,8 +112,8 @@ namespace uhd { namespace math { namespace fp_compare { template UHD_INLINE bool operator<(fp_compare_delta lhs, double rhs) { - float_t delta = fp_compare_select_delta(double(lhs._delta), - DOUBLE_PRECISION_DELTA); + float_t delta = float_t(fp_compare_select_delta(double(lhs._delta), + DOUBLE_PRECISION_DELTA)); return ((rhs - lhs._value) > delta); } @@ -124,8 +124,8 @@ namespace uhd { namespace math { namespace fp_compare { template UHD_INLINE bool operator>(fp_compare_delta lhs, double rhs) { - float_t delta = fp_compare_select_delta(double(lhs._delta), - DOUBLE_PRECISION_DELTA); + float_t delta = float_t(fp_compare_select_delta(double(lhs._delta), + DOUBLE_PRECISION_DELTA)); return ((lhs._value - rhs) > delta); } @@ -148,8 +148,8 @@ namespace uhd { namespace math { namespace fp_compare { template UHD_INLINE bool operator<(double lhs, fp_compare_delta rhs) { - float_t delta = fp_compare_select_delta(DOUBLE_PRECISION_DELTA, - double(rhs._delta)); + float_t delta = float_t(fp_compare_select_delta(DOUBLE_PRECISION_DELTA, + double(rhs._delta))); return ((rhs._value - lhs) > delta); } @@ -160,8 +160,8 @@ namespace uhd { namespace math { namespace fp_compare { template UHD_INLINE bool operator>(double lhs, fp_compare_delta rhs) { - float_t delta = fp_compare_select_delta(DOUBLE_PRECISION_DELTA, - double(rhs._delta)); + float_t delta = float_t(fp_compare_select_delta(DOUBLE_PRECISION_DELTA, + double(rhs._delta))); return ((lhs - rhs._value) > delta); } diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp index e6ac4d3dc..4f88494d6 100644 --- a/host/include/uhd/utils/math.hpp +++ b/host/include/uhd/utils/math.hpp @@ -155,7 +155,7 @@ namespace fp_compare { * These are the default deltas used by the 'fp_compare_delta' class for * single and double-precision floating point comparisons. */ - static const float SINGLE_PRECISION_DELTA = 1e-3; + static const float SINGLE_PRECISION_DELTA = 1e-3f; static const double DOUBLE_PRECISION_DELTA = 1e-5; /*! Floating-point delta to use for frequency comparisons. */ diff --git a/host/lib/usrp/cores/rx_dsp_core_3000.cpp b/host/lib/usrp/cores/rx_dsp_core_3000.cpp index 13d69920a..8a131ffb4 100644 --- a/host/lib/usrp/cores/rx_dsp_core_3000.cpp +++ b/host/lib/usrp/cores/rx_dsp_core_3000.cpp @@ -72,7 +72,7 @@ public: { UHD_SAFE_CALL ( - //NOP + ;//NOP ) } diff --git a/host/lib/usrp/cores/time_core_3000.cpp b/host/lib/usrp/cores/time_core_3000.cpp index aa5d5593d..ffae5dc0d 100644 --- a/host/lib/usrp/cores/time_core_3000.cpp +++ b/host/lib/usrp/cores/time_core_3000.cpp @@ -50,7 +50,7 @@ struct time_core_3000_impl : time_core_3000 { UHD_SAFE_CALL ( - //NOP + ;//NOP ) } @@ -71,8 +71,8 @@ struct time_core_3000_impl : time_core_3000 UHD_MSG(status) << ((test_fail)? " fail" : "pass") << std::endl; //useful warning for debugging actual rate - const size_t ticks_elapsed = _tick_rate*approx_secs; - const size_t appox_rate = ticks_elapsed/(sleep_millis/1e3); + const size_t ticks_elapsed = size_t(_tick_rate*approx_secs); + const size_t appox_rate = size_t(ticks_elapsed/(sleep_millis/1e3)); if (test_fail) UHD_MSG(warning) << "Expecting clock rate: " << (_tick_rate/1e6) << " MHz\n" << "Appoximate clock rate: " << (appox_rate/1e6) << " MHz\n" diff --git a/host/lib/usrp/dboard/db_cbx.cpp b/host/lib/usrp/dboard/db_cbx.cpp index db7f84932..ad255460e 100644 --- a/host/lib/usrp/dboard/db_cbx.cpp +++ b/host/lib/usrp/dboard/db_cbx.cpp @@ -142,7 +142,7 @@ double sbx_xcvr::cbx::set_lo_freq(dboard_iface::unit_t unit, double target_freq) } //keep pfd freq low enough to achieve 50kHz BS clock - BS = std::ceil(pfd_freq / 50e3); + BS = int(std::ceil(pfd_freq / 50e3)); if(BS <= 1023) break; } diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 45e736757..794438b90 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -1162,7 +1162,7 @@ public: { if (_tree->exists(mb_root(mboard) / "gpio" / bank)) { - return _tree->access(mb_root(mboard) / "gpio" / bank / attr).get(); + return boost::uint32_t(_tree->access(mb_root(mboard) / "gpio" / bank / attr).get()); } if (bank.size() > 2 and bank[1] == 'X') { diff --git a/host/tests/fp_compare_delta_test.cpp b/host/tests/fp_compare_delta_test.cpp index 9b009a79d..0ac4e257d 100644 --- a/host/tests/fp_compare_delta_test.cpp +++ b/host/tests/fp_compare_delta_test.cpp @@ -101,8 +101,8 @@ BOOST_AUTO_TEST_CASE(double_equality_operators) { BOOST_AUTO_TEST_CASE(float_inequality_operators) { // Test inequality operator, which is based on equality operator - fp_compare_delta alpha = fp_compare_delta(127.0); - fp_compare_delta beta = fp_compare_delta(alpha._value + 1.19e-3); + fp_compare_delta alpha = fp_compare_delta(127.0f); + fp_compare_delta beta = fp_compare_delta(alpha._value + 1.19e-3f); BOOST_CHECK(alpha != beta); BOOST_CHECK(alpha != float(alpha._value + 1.19e-3)); @@ -119,17 +119,17 @@ BOOST_AUTO_TEST_CASE(double_inequality_operators) { BOOST_AUTO_TEST_CASE(float_lessthan_operators) { // Test less-than operator - fp_compare_delta alpha = fp_compare_delta(274192.7); - fp_compare_delta beta = fp_compare_delta(alpha._value - 0.2); + fp_compare_delta alpha = fp_compare_delta(274192.7f); + fp_compare_delta beta = fp_compare_delta(alpha._value - 0.2f); BOOST_CHECK(beta < alpha); BOOST_CHECK(float(alpha._value - 0.2) < alpha); // Confirm false less-than case - fp_compare_delta charlie = fp_compare_delta(alpha._value - 1.2); + fp_compare_delta charlie = fp_compare_delta(alpha._value - 1.2f); BOOST_CHECK(not (alpha < charlie)); - BOOST_CHECK(not (alpha < float(alpha._value - 1.2))); + BOOST_CHECK(not (alpha < float(alpha._value - 1.2f))); } BOOST_AUTO_TEST_CASE(double_lessthan_operators) { @@ -149,14 +149,14 @@ BOOST_AUTO_TEST_CASE(double_lessthan_operators) { BOOST_AUTO_TEST_CASE(float_lessthanequals_operators) { // Test that <= correctly reports for equal values - fp_compare_delta alpha = fp_compare_delta(827.3); + fp_compare_delta alpha = fp_compare_delta(827.3f); fp_compare_delta beta = fp_compare_delta(alpha._value); BOOST_CHECK(alpha <= beta); BOOST_CHECK(alpha <= float(alpha._value)); // Test that <= correctly reports for less-than values - fp_compare_delta charlie = fp_compare_delta(alpha._value - 1.2); + fp_compare_delta charlie = fp_compare_delta(alpha._value - 1.2f); BOOST_CHECK(charlie <= alpha); BOOST_CHECK(float(alpha._value - 1.2) <= alpha); @@ -179,14 +179,14 @@ BOOST_AUTO_TEST_CASE(double_lessthanequals_operators) { BOOST_AUTO_TEST_CASE(float_greaterthan_operators) { // Test basic greater-than functionality - fp_compare_delta alpha = fp_compare_delta(98325.4); - fp_compare_delta beta = fp_compare_delta(alpha._value + 0.15); + fp_compare_delta alpha = fp_compare_delta(98325.4f); + fp_compare_delta beta = fp_compare_delta(alpha._value + 0.15f); BOOST_CHECK(beta > alpha); BOOST_CHECK(float(alpha._value + 0.15) > alpha); // Test false greater-than case - fp_compare_delta charlie = fp_compare_delta(alpha._value + 1.2); + fp_compare_delta charlie = fp_compare_delta(alpha._value + 1.2f); BOOST_CHECK(not (alpha > charlie)); BOOST_CHECK(not (alpha > float(alpha._value + 1.2))); @@ -209,14 +209,14 @@ BOOST_AUTO_TEST_CASE(double_greaterthan_operators) { BOOST_AUTO_TEST_CASE(float_greaterthanequals_operators) { // Test that >= correctly reports for equal values - fp_compare_delta alpha = fp_compare_delta(7834.89); + fp_compare_delta alpha = fp_compare_delta(7834.89f); fp_compare_delta beta = fp_compare_delta(alpha._value); BOOST_CHECK(alpha >= beta); BOOST_CHECK(alpha >= float(alpha._value)); // Test that >= correctly reports for greater-than values - fp_compare_delta charlie = fp_compare_delta(alpha._value + 4.8); + fp_compare_delta charlie = fp_compare_delta(alpha._value + 4.8f); BOOST_CHECK(charlie >= alpha); BOOST_CHECK(float(alpha._value + 4.8) >= alpha); diff --git a/host/tests/fp_compare_epsilon_test.cpp b/host/tests/fp_compare_epsilon_test.cpp index 5790318c2..45687ad26 100644 --- a/host/tests/fp_compare_epsilon_test.cpp +++ b/host/tests/fp_compare_epsilon_test.cpp @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(fp_compare_epsilon_constructors) { // Test constructor with specified epsilon fp_compare_epsilon foxtrot = fp_compare_epsilon(alpha._value, uhd::math::SINGLE_PRECISION_EPSILON); - fp_compare_epsilon gamma = fp_compare_epsilon(alpha._value, 2.0e-1); + fp_compare_epsilon gamma = fp_compare_epsilon(alpha._value, 2.0e-1f); BOOST_CHECK_EQUAL(alpha._epsilon, foxtrot._epsilon); BOOST_CHECK(not (alpha._epsilon == gamma._epsilon)); @@ -102,10 +102,10 @@ BOOST_AUTO_TEST_CASE(double_equality_operators) { BOOST_AUTO_TEST_CASE(float_inequality_operators) { // Test inequality operator, which is based on equality operator fp_compare_epsilon alpha = fp_compare_epsilon(127.0); - fp_compare_epsilon beta = fp_compare_epsilon(alpha._value + 1.19e-5); + fp_compare_epsilon beta = fp_compare_epsilon(alpha._value + 1.19e-5f); BOOST_CHECK(alpha != beta); - BOOST_CHECK(alpha != float(alpha._value + 1.19e-5)); + BOOST_CHECK(alpha != float(alpha._value + 1.19e-5f)); } BOOST_AUTO_TEST_CASE(double_inequality_operators) { @@ -119,17 +119,17 @@ BOOST_AUTO_TEST_CASE(double_inequality_operators) { BOOST_AUTO_TEST_CASE(float_lessthan_operators) { // Test less-than operator - fp_compare_epsilon alpha = fp_compare_epsilon(274192.7); - fp_compare_epsilon beta = fp_compare_epsilon(alpha._value - 0.15); + fp_compare_epsilon alpha = fp_compare_epsilon(274192.7f); + fp_compare_epsilon beta = fp_compare_epsilon(alpha._value - 0.15f); BOOST_CHECK(beta < alpha); BOOST_CHECK(float(alpha._value - 0.15) < alpha); // Confirm false less-than case - fp_compare_epsilon charlie = fp_compare_epsilon(alpha._value - 1.2); + fp_compare_epsilon charlie = fp_compare_epsilon(alpha._value - 1.2f); BOOST_CHECK(not (alpha < charlie)); - BOOST_CHECK(not (alpha < float(alpha._value - 1.2))); + BOOST_CHECK(not (alpha < float(alpha._value - 1.2f))); } BOOST_AUTO_TEST_CASE(double_lessthan_operators) { @@ -149,14 +149,14 @@ BOOST_AUTO_TEST_CASE(double_lessthan_operators) { BOOST_AUTO_TEST_CASE(float_lessthanequals_operators) { // Test that <= correctly reports for equal values - fp_compare_epsilon alpha = fp_compare_epsilon(827.3); + fp_compare_epsilon alpha = fp_compare_epsilon(827.3f); fp_compare_epsilon beta = fp_compare_epsilon(alpha._value); BOOST_CHECK(alpha <= beta); BOOST_CHECK(alpha <= float(alpha._value)); // Test that <= correctly reports for less-than values - fp_compare_epsilon charlie = fp_compare_epsilon(alpha._value - 1.2); + fp_compare_epsilon charlie = fp_compare_epsilon(alpha._value - 1.2f); BOOST_CHECK(charlie <= alpha); BOOST_CHECK(float(alpha._value - 1.2) <= alpha); @@ -179,17 +179,17 @@ BOOST_AUTO_TEST_CASE(double_lessthanequals_operators) { BOOST_AUTO_TEST_CASE(float_greaterthan_operators) { // Test basic greater-than functionality - fp_compare_epsilon alpha = fp_compare_epsilon(98325.4); - fp_compare_epsilon beta = fp_compare_epsilon(alpha._value + 0.15); + fp_compare_epsilon alpha = fp_compare_epsilon(98325.4f); + fp_compare_epsilon beta = fp_compare_epsilon(alpha._value + 0.15f); BOOST_CHECK(beta > alpha); BOOST_CHECK(float(alpha._value + 0.15) > alpha); // Test false greater-than case - fp_compare_epsilon charlie = fp_compare_epsilon(alpha._value + 1.2); + fp_compare_epsilon charlie = fp_compare_epsilon(alpha._value + 1.2f); BOOST_CHECK(not (alpha > charlie)); - BOOST_CHECK(not (alpha > float(alpha._value + 1.2))); + BOOST_CHECK(not (alpha > float(alpha._value + 1.2f))); } BOOST_AUTO_TEST_CASE(double_greaterthan_operators) { @@ -209,17 +209,17 @@ BOOST_AUTO_TEST_CASE(double_greaterthan_operators) { BOOST_AUTO_TEST_CASE(float_greaterthanequals_operators) { // Test that >= correctly reports for equal values - fp_compare_epsilon alpha = fp_compare_epsilon(7834.89); + fp_compare_epsilon alpha = fp_compare_epsilon(7834.89f); fp_compare_epsilon beta = fp_compare_epsilon(alpha._value); BOOST_CHECK(alpha >= beta); BOOST_CHECK(alpha >= float(alpha._value)); // Test that >= correctly reports for greater-than values - fp_compare_epsilon charlie = fp_compare_epsilon(alpha._value + 4.8); + fp_compare_epsilon charlie = fp_compare_epsilon(alpha._value + 4.8f); BOOST_CHECK(charlie >= alpha); - BOOST_CHECK(float(alpha._value + 4.8) >= alpha); + BOOST_CHECK(float(alpha._value + 4.8f) >= alpha); } BOOST_AUTO_TEST_CASE(double_greaterthanequals_operators) { diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp index c027a4785..ccdb0a61d 100644 --- a/host/utils/usrp_cal_utils.hpp +++ b/host/utils/usrp_cal_utils.hpp @@ -249,7 +249,7 @@ static void capture_samples( // Right after the stream is started, there will be transient data. // That transient data is discarded and only "good" samples are returned. - size_t nsamps_to_discard = usrp->get_rx_rate() * 0.001; // 1ms to be discarded + size_t nsamps_to_discard = size_t(usrp->get_rx_rate() * 0.001); // 1ms to be discarded std::vector discard_buff(nsamps_to_discard); uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); -- cgit v1.2.3