From 4ac4f25aba479a21e73539eb29b56951247c2e8a Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Thu, 30 Dec 2010 18:09:54 -0800 Subject: USRP1: Fix ATR for TX/full duplex --- host/lib/usrp/usrp1/dboard_iface.cpp | 46 ++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'host') diff --git a/host/lib/usrp/usrp1/dboard_iface.cpp b/host/lib/usrp/usrp1/dboard_iface.cpp index 70ce3da76..c2c971269 100644 --- a/host/lib/usrp/usrp1/dboard_iface.cpp +++ b/host/lib/usrp/usrp1/dboard_iface.cpp @@ -267,22 +267,38 @@ void usrp1_dboard_iface::_set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value) { // Ignore unsupported states - if ((atr == ATR_REG_IDLE) || (atr == ATR_REG_FULL_DUPLEX)) + if ((atr == ATR_REG_IDLE)) return; - - switch(unit) { - case UNIT_RX: - if (_dboard_slot == usrp1_impl::DBOARD_SLOT_A) - _iface->poke32(FR_ATR_RXVAL_1, value); - else if (_dboard_slot == usrp1_impl::DBOARD_SLOT_B) - _iface->poke32(FR_ATR_RXVAL_3, value); - break; - case UNIT_TX: - if (_dboard_slot == usrp1_impl::DBOARD_SLOT_A) - _iface->poke32(FR_ATR_TXVAL_0, value); - else if (_dboard_slot == usrp1_impl::DBOARD_SLOT_B) - _iface->poke32(FR_ATR_TXVAL_2, value); - break; + if(atr == ATR_REG_RX_ONLY) { + switch(unit) { + case UNIT_RX: + if (_dboard_slot == usrp1_impl::DBOARD_SLOT_A) + _iface->poke32(FR_ATR_RXVAL_1, value); + else if (_dboard_slot == usrp1_impl::DBOARD_SLOT_B) + _iface->poke32(FR_ATR_RXVAL_3, value); + break; + case UNIT_TX: + if (_dboard_slot == usrp1_impl::DBOARD_SLOT_A) + _iface->poke32(FR_ATR_RXVAL_0, value); + else if (_dboard_slot == usrp1_impl::DBOARD_SLOT_B) + _iface->poke32(FR_ATR_RXVAL_2, value); + break; + } + } else if (atr == ATR_REG_TX_ONLY && atr == ATR_REG_FULL_DUPLEX) { + switch(unit) { + case UNIT_RX: + if (_dboard_slot == usrp1_impl::DBOARD_SLOT_A) + _iface->poke32(FR_ATR_TXVAL_1, value); + else if (_dboard_slot == usrp1_impl::DBOARD_SLOT_B) + _iface->poke32(FR_ATR_TXVAL_3, value); + break; + case UNIT_TX: + if (_dboard_slot == usrp1_impl::DBOARD_SLOT_A) + _iface->poke32(FR_ATR_TXVAL_0, value); + else if (_dboard_slot == usrp1_impl::DBOARD_SLOT_B) + _iface->poke32(FR_ATR_TXVAL_2, value); + break; + } } } /*********************************************************************** -- cgit v1.2.3 From ee59a7af6b117da60b7128e3bb91860b18f1d19d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 31 Dec 2010 10:21:39 -0800 Subject: usrp: xcvr dboards should also register their default subdev name as 0 --- host/include/uhd/usrp/dboard_manager.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host') diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp index c68f069f0..3c41c65a8 100644 --- a/host/include/uhd/usrp/dboard_manager.hpp +++ b/host/include/uhd/usrp/dboard_manager.hpp @@ -68,7 +68,7 @@ public: const dboard_id_t &tx_dboard_id, dboard_ctor_t dboard_ctor, const std::string &name, - const prop_names_t &subdev_names = prop_names_t(1, "") + const prop_names_t &subdev_names = prop_names_t(1, "0") ); /*! -- cgit v1.2.3 From 3f30734fbace70c952c2939ed0cd9fff7b6e4914 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 31 Dec 2010 11:27:53 -0800 Subject: xcvr2450: update comment for full duplex case --- host/lib/usrp/dboard/db_xcvr2450.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'host') diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index a3a1e6242..e76727bec 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -245,7 +245,8 @@ void xcvr2450::update_atr(void){ int band_sel = (xcvr2450::is_highband(_lo_freq))? HB_PA_TXIO : LB_PA_TXIO; int tx_ant_sel = (_tx_ant == "J1")? ANTSEL_TX1_RX2_TXIO : ANTSEL_TX2_RX1_TXIO; int rx_ant_sel = (_rx_ant == "J2")? ANTSEL_TX1_RX2_TXIO : ANTSEL_TX2_RX1_TXIO; - int xx_ant_sel = tx_ant_sel; //prefer the tx antenna selection for full duplex (rx will get the other antenna) + int xx_ant_sel = tx_ant_sel; //Prefer the tx antenna selection for full duplex, + //due to the issue that USRP1 will take the value of full duplex for its TXATR. int ad9515div = (_ad9515div == 3)? AD9515DIV_3_TXIO : AD9515DIV_2_TXIO; //set the tx registers -- cgit v1.2.3 From b4d58f3501596fdddf240d576d0b1b2cb5862892 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Fri, 31 Dec 2010 10:31:42 -0800 Subject: USRP1: REALLY fix the full-duplex case. --- host/lib/usrp/usrp1/dboard_iface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'host') diff --git a/host/lib/usrp/usrp1/dboard_iface.cpp b/host/lib/usrp/usrp1/dboard_iface.cpp index c2c971269..4e47d6bf6 100644 --- a/host/lib/usrp/usrp1/dboard_iface.cpp +++ b/host/lib/usrp/usrp1/dboard_iface.cpp @@ -267,7 +267,7 @@ void usrp1_dboard_iface::_set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value) { // Ignore unsupported states - if ((atr == ATR_REG_IDLE)) + if ((atr == ATR_REG_IDLE) || (atr == ATR_REG_TX_ONLY)) return; if(atr == ATR_REG_RX_ONLY) { switch(unit) { @@ -284,7 +284,7 @@ void usrp1_dboard_iface::_set_atr_reg(unit_t unit, _iface->poke32(FR_ATR_RXVAL_2, value); break; } - } else if (atr == ATR_REG_TX_ONLY && atr == ATR_REG_FULL_DUPLEX) { + } else if (atr == ATR_REG_FULL_DUPLEX) { switch(unit) { case UNIT_RX: if (_dboard_slot == usrp1_impl::DBOARD_SLOT_A) -- cgit v1.2.3 From ea20cc274cdd7ea15df2347e9d1a3539bd819bed Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 2 Jan 2011 01:58:06 -0800 Subject: uhd: create a find packages module for docutils, cleaned up some of the other find package stuff --- host/Modules/FindDocutils.cmake | 21 +++++++++++++++++++++ host/Modules/UHDVersion.cmake | 16 +++++----------- host/docs/CMakeLists.txt | 21 ++++----------------- host/lib/transport/CMakeLists.txt | 3 ++- 4 files changed, 32 insertions(+), 29 deletions(-) create mode 100644 host/Modules/FindDocutils.cmake (limited to 'host') diff --git a/host/Modules/FindDocutils.cmake b/host/Modules/FindDocutils.cmake new file mode 100644 index 000000000..b9996f3f1 --- /dev/null +++ b/host/Modules/FindDocutils.cmake @@ -0,0 +1,21 @@ +# +# Copyright 2010 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 . +# + +######################################################################## +FIND_PROGRAM(RST2HTML_EXECUTABLE rst2html) +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Docutils DEFAULT_MSG RST2HTML_EXECUTABLE) diff --git a/host/Modules/UHDVersion.cmake b/host/Modules/UHDVersion.cmake index fc2e2bbbd..4bd740185 100644 --- a/host/Modules/UHDVersion.cmake +++ b/host/Modules/UHDVersion.cmake @@ -28,16 +28,13 @@ SET(UHD_VERSION_PATCH 0) #Short hash of git commit ######################################################################## # Find GIT to get repo information ######################################################################## -MESSAGE(STATUS "") -MESSAGE(STATUS "Checking for git") -FIND_PROGRAM(GIT git) -IF(GIT) - MESSAGE(STATUS "Checking for git - found") +FIND_PACKAGE(Git QUIET) +IF(GIT_FOUND) #grab the git log entry for the current head EXECUTE_PROCESS( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - COMMAND ${GIT} log HEAD~..HEAD --date=raw + COMMAND ${GIT_EXECUTABLE} log HEAD~..HEAD --date=raw OUTPUT_VARIABLE _git_log OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -58,11 +55,8 @@ IF(GIT) #grab the git ref id for the current head EXECUTE_PROCESS( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - COMMAND ${GIT} rev-parse --short HEAD + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD OUTPUT_VARIABLE _git_rev OUTPUT_STRIP_TRAILING_WHITESPACE ) SET(UHD_VERSION_PATCH ${_git_rev}) - -ELSE(GIT) - MESSAGE(STATUS "Checking for git - not found") -ENDIF(GIT) +ENDIF(GIT_FOUND) diff --git a/host/docs/CMakeLists.txt b/host/docs/CMakeLists.txt index 54e0d589c..592d66526 100644 --- a/host/docs/CMakeLists.txt +++ b/host/docs/CMakeLists.txt @@ -36,17 +36,9 @@ SET(manual_sources # Setup Manual ######################################################################## MESSAGE(STATUS "") -MESSAGE(STATUS "Checking for rst2html (docutils)") -FIND_PROGRAM(RST2HTML rst2html) -IF(RST2HTML) - MESSAGE(STATUS "Checking for rst2html (docutils) - found") - MESSAGE(STATUS " Enabled generation of HTML manual.") -ELSE(RST2HTML) - MESSAGE(STATUS "Checking for rst2html (docutils) - not found") - MESSAGE(STATUS " Disabled generation of HTML manual.") -ENDIF(RST2HTML) +FIND_PACKAGE(Docutils REQUIRED) -LIBUHD_REGISTER_COMPONENT("Manual" ENABLE_MANUAL ON "RST2HTML" OFF) +LIBUHD_REGISTER_COMPONENT("Manual" ENABLE_MANUAL ON "DOCUTILS_FOUND" OFF) IF(ENABLE_MANUAL) #setup rst2html options @@ -66,7 +58,7 @@ IF(ENABLE_MANUAL) #make the html file depend on the rst file ADD_CUSTOM_COMMAND( OUTPUT ${htmlfile} DEPENDS ${rstfile} ${stylesheet} - COMMAND ${RST2HTML} ${rstfile} ${htmlfile} ${rst2html_options} + COMMAND ${RST2HTML_EXECUTABLE} ${rstfile} ${htmlfile} ${rst2html_options} COMMENT "Generating ${htmlfile}" ) @@ -85,14 +77,11 @@ INSTALL(FILES ${manual_sources} DESTINATION ${PKG_DOC_DIR}/manual/rst) # Setup Doxygen ######################################################################## MESSAGE(STATUS "") -MESSAGE(STATUS "Checking for doxygen") -INCLUDE(FindDoxygen) +FIND_PACKAGE(Doxygen) LIBUHD_REGISTER_COMPONENT("Doxygen" ENABLE_DOXYGEN ON "DOXYGEN_FOUND" OFF) IF(ENABLE_DOXYGEN) - MESSAGE(STATUS " Enabled generation of Doxygen documentation.") - #generate the doxygen configuration file SET(CMAKE_CURRENT_BINARY_DIR_DOXYGEN ${CMAKE_CURRENT_BINARY_DIR}/doxygen) CONFIGURE_FILE( @@ -111,6 +100,4 @@ IF(ENABLE_DOXYGEN) #make the doxygen generation a built-time dependency ADD_CUSTOM_TARGET(doxygen_docs ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR_DOXYGEN}) INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR_DOXYGEN} DESTINATION ${PKG_DOC_DIR}) -ELSE(ENABLE_DOXYGEN) - MESSAGE(STATUS " Disabled generation of Doxygen documentation.") ENDIF(ENABLE_DOXYGEN) diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index 5602e47a7..0d6226e4c 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -22,7 +22,8 @@ ######################################################################## # Setup libusb ######################################################################## -FIND_PACKAGE(USB1) +MESSAGE(STATUS "") +FIND_PACKAGE(USB1 REQUIRED) LIBUHD_REGISTER_COMPONENT("USB" ENABLE_USB ON "ENABLE_LIBUHD;LIBUSB_FOUND" OFF) -- cgit v1.2.3 From e2487eb7311d6bbeec5e6aaeab0a3857d8cada1b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 2 Jan 2011 13:10:27 -0800 Subject: uhd: potential fix for explicit template + llvm --- host/include/uhd/config.hpp | 16 ++++++++++------ host/lib/types.cpp | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'host') diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index 9a29fb246..6200e6339 100644 --- a/host/include/uhd/config.hpp +++ b/host/include/uhd/config.hpp @@ -56,17 +56,14 @@ #define UHD_HELPER_DLL_IMPORT __declspec(dllimport) #define UHD_HELPER_DLL_EXPORT __declspec(dllexport) #define UHD_HELPER_DLL_LOCAL - #define UHD_HELPER_EXIM_TMPL #elif defined(__GNUG__) && __GNUG__ >= 4 #define UHD_HELPER_DLL_IMPORT __attribute__ ((visibility("default"))) #define UHD_HELPER_DLL_EXPORT __attribute__ ((visibility("default"))) #define UHD_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden"))) - #define UHD_HELPER_EXIM_TMPL extern #else #define UHD_HELPER_DLL_IMPORT #define UHD_HELPER_DLL_EXPORT #define UHD_HELPER_DLL_LOCAL - #define UHD_HELPER_EXIM_TMPL extern #endif // Now we use the generic helper definitions above to define UHD_API and UHD_LOCAL. @@ -78,16 +75,13 @@ #ifdef UHD_DLL // defined if UHD is compiled as a DLL #ifdef UHD_DLL_EXPORTS // defined if we are building the UHD DLL (instead of using it) #define UHD_API UHD_HELPER_DLL_EXPORT - #define UHD_EXIM_TMPL UHD_HELPER_EXIM_TMPL #else #define UHD_API UHD_HELPER_DLL_IMPORT - #define UHD_EXIM_TMPL UHD_HELPER_EXIM_TMPL #endif // UHD_DLL_EXPORTS #define UHD_LOCAL UHD_HELPER_DLL_LOCAL #else // UHD_DLL is not defined: this means UHD is a static lib. #define UHD_API #define UHD_LOCAL - #define UHD_EXIM_TMPL #endif // UHD_DLL // Define force inline macro @@ -119,4 +113,14 @@ #define UHD_PLATFORM_MACOS #endif +//On macos platform, explicit templates must be: +// - defined with extern in the header file +// - defined as a symbol in the source file +#ifdef UHD_PLATFORM_MACOS + #define UHD_EXIM_TMPL extern + #define UHD_USE_EXIM_TMPL +#else + #define UHD_EXIM_TMPL +#endif + #endif /* INCLUDED_UHD_CONFIG_HPP */ diff --git a/host/lib/types.cpp b/host/lib/types.cpp index bea20a4aa..9e4a26c23 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -43,8 +43,10 @@ using namespace uhd; /*********************************************************************** * ranges template instantiation **********************************************************************/ +#ifdef UHD_USE_EXIM_TMPL template struct uhd::meta_range_t; template struct uhd::meta_range_t; +#endif /*********************************************************************** * tune request -- cgit v1.2.3 From 6b3ab5f712c099005fd7bb423ac9d53dc2c5a167 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Sun, 2 Jan 2011 21:28:39 -0800 Subject: fu_ranges: dict's keys()/vals() now return non-const to make BOOST_FOREACH happy on Clang --- host/include/uhd/types/dict.hpp | 4 ++-- host/include/uhd/types/dict.ipp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'host') diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index 6166140a0..a117efa6b 100644 --- a/host/include/uhd/types/dict.hpp +++ b/host/include/uhd/types/dict.hpp @@ -54,14 +54,14 @@ namespace uhd{ * Key order depends on insertion precedence. * \return vector of keys */ - const std::vector keys(void) const; + std::vector keys(void) const; /*! * Get a list of the values in this dict. * Value order depends on insertion precedence. * \return vector of values */ - const std::vector vals(void) const; + std::vector vals(void) const; /*! * Does the dictionary contain this key? diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp index f037d7988..efff9e955 100644 --- a/host/include/uhd/types/dict.ipp +++ b/host/include/uhd/types/dict.ipp @@ -59,7 +59,7 @@ namespace uhd{ } template - const std::vector dict::keys(void) const{ + std::vector dict::keys(void) const{ std::vector keys; BOOST_FOREACH(const pair_t &p, _map){ keys.push_back(p.first); @@ -68,7 +68,7 @@ namespace uhd{ } template - const std::vector dict::vals(void) const{ + std::vector dict::vals(void) const{ std::vector vals; BOOST_FOREACH(const pair_t &p, _map){ vals.push_back(p.second); -- cgit v1.2.3 From 2d1f96d834baf7cb92305e9ecdadbe0ad13a8d04 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 2 Jan 2011 21:46:47 -0800 Subject: uhd: try to neaten up the attribute macros in config.hpp --- host/include/uhd/config.hpp | 86 ++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 55 deletions(-) (limited to 'host') diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index 6200e6339..62c2504e1 100644 --- a/host/include/uhd/config.hpp +++ b/host/include/uhd/config.hpp @@ -18,9 +18,10 @@ #ifndef INCLUDED_UHD_CONFIG_HPP #define INCLUDED_UHD_CONFIG_HPP -// suppress warnings #include + #ifdef BOOST_MSVC +// suppress warnings //# pragma warning(push) //# pragma warning(disable: 4511) // copy constructor can't not be generated //# pragma warning(disable: 4512) // assignment operator can't not be generated @@ -37,70 +38,43 @@ //# pragma warning(disable: 4511) // 'class' : copy constructor could not be generated //# pragma warning(disable: 4250) // 'class' : inherits 'method' via dominance # pragma warning(disable: 4200) // nonstandard extension used : zero-sized array in struct/union -#endif // define logical operators -#ifdef BOOST_MSVC - #include -#endif +#include // define ssize_t -#ifdef BOOST_MSVC - #include - typedef ptrdiff_t ssize_t; -#endif - -// http://gcc.gnu.org/wiki/Visibility -// Generic helper definitions for shared library support -#if defined(BOOST_HAS_DECLSPEC) - #define UHD_HELPER_DLL_IMPORT __declspec(dllimport) - #define UHD_HELPER_DLL_EXPORT __declspec(dllexport) - #define UHD_HELPER_DLL_LOCAL -#elif defined(__GNUG__) && __GNUG__ >= 4 - #define UHD_HELPER_DLL_IMPORT __attribute__ ((visibility("default"))) - #define UHD_HELPER_DLL_EXPORT __attribute__ ((visibility("default"))) - #define UHD_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden"))) -#else - #define UHD_HELPER_DLL_IMPORT - #define UHD_HELPER_DLL_EXPORT - #define UHD_HELPER_DLL_LOCAL -#endif - -// Now we use the generic helper definitions above to define UHD_API and UHD_LOCAL. -// UHD_API is used for the public API symbols. It either DLL imports or DLL exports (or does nothing for static build) -// UHD_LOCAL is used for non-api symbols. - -#define UHD_DLL // defined here, put into configuration if we need to make static libs +#include +typedef ptrdiff_t ssize_t; -#ifdef UHD_DLL // defined if UHD is compiled as a DLL - #ifdef UHD_DLL_EXPORTS // defined if we are building the UHD DLL (instead of using it) - #define UHD_API UHD_HELPER_DLL_EXPORT - #else - #define UHD_API UHD_HELPER_DLL_IMPORT - #endif // UHD_DLL_EXPORTS - #define UHD_LOCAL UHD_HELPER_DLL_LOCAL -#else // UHD_DLL is not defined: this means UHD is a static lib. - #define UHD_API - #define UHD_LOCAL -#endif // UHD_DLL +#endif //BOOST_MSVC -// Define force inline macro -#if defined(BOOST_MSVC) - #define UHD_INLINE __forceinline +//define cross platform attribute macros +#if defined(BOOST_MSVC) || defined(BOOST_HAS_DECLSPEC) + #define UHD_EXPORT __declspec(dllexport) + #define UHD_IMPORT __declspec(dllimport) + #define UHD_INLINE __forceinline + #define UHD_DEPRECATED __declspec(deprecated) + #define UHD_ALIGNED(x) __declspec(align(x)) #elif defined(__GNUG__) && __GNUG__ >= 4 - #define UHD_INLINE inline __attribute__((always_inline)) + #define UHD_EXPORT __attribute__((visibility("default"))) + #define UHD_IMPORT __attribute__((visibility("default"))) + #define UHD_INLINE inline __attribute__((always_inline)) + #define UHD_DEPRECATED __attribute__((deprecated)) + #define UHD_ALIGNED(x) __attribute__((aligned(x))) #else - #define UHD_INLINE inline + #define UHD_EXPORT + #define UHD_IMPORT + #define UHD_INLINE inline + #define UHD_DEPRECATED + #define UHD_ALIGNED(x) #endif -// Define deprecated attribute macro -#if defined(BOOST_MSVC) - #define UHD_DEPRECATED __declspec(deprecated) -#elif defined(__GNUG__) && __GNUG__ >= 4 - #define UHD_DEPRECATED __attribute__ ((deprecated)) +// Define API declaration macro +#ifdef UHD_DLL_EXPORTS + #define UHD_API UHD_EXPORT #else - #define UHD_DEPRECATED -#endif + #define UHD_API UHD_IMPORT +#endif // UHD_DLL_EXPORTS // Platform defines for conditional parts of headers: // Taken from boost/config/select_platform_config.hpp, @@ -111,12 +85,14 @@ #define UHD_PLATFORM_WIN32 #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) #define UHD_PLATFORM_MACOS +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) + #define UHD_PLATFORM_BSD #endif //On macos platform, explicit templates must be: // - defined with extern in the header file // - defined as a symbol in the source file -#ifdef UHD_PLATFORM_MACOS +#if defined(UHD_PLATFORM_MACOS) || defined(UHD_PLATFORM_BSD) #define UHD_EXIM_TMPL extern #define UHD_USE_EXIM_TMPL #else -- cgit v1.2.3 From ed6a2941f8e144e5f02a7a34c9d4764c65174617 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 3 Jan 2011 01:43:48 -0800 Subject: uhd: created buffer pool to allocate aligned memory, and implemented in transports --- host/include/uhd/transport/CMakeLists.txt | 1 + host/include/uhd/transport/buffer_pool.hpp | 59 ++++++++++++++++++++++ host/include/uhd/transport/if_addrs.hpp | 6 +-- host/lib/transport/CMakeLists.txt | 1 + host/lib/transport/buffer_pool.cpp | 80 ++++++++++++++++++++++++++++++ host/lib/transport/libusb1_zero_copy.cpp | 10 ++-- host/lib/transport/udp_zero_copy_asio.cpp | 12 ++--- 7 files changed, 155 insertions(+), 14 deletions(-) create mode 100644 host/include/uhd/transport/buffer_pool.hpp create mode 100644 host/lib/transport/buffer_pool.cpp (limited to 'host') diff --git a/host/include/uhd/transport/CMakeLists.txt b/host/include/uhd/transport/CMakeLists.txt index 2c84c0724..adcfc7598 100644 --- a/host/include/uhd/transport/CMakeLists.txt +++ b/host/include/uhd/transport/CMakeLists.txt @@ -21,6 +21,7 @@ INSTALL(FILES alignment_buffer.ipp bounded_buffer.hpp bounded_buffer.ipp + buffer_pool.hpp convert_types.hpp convert_types.ipp if_addrs.hpp diff --git a/host/include/uhd/transport/buffer_pool.hpp b/host/include/uhd/transport/buffer_pool.hpp new file mode 100644 index 000000000..b6c683948 --- /dev/null +++ b/host/include/uhd/transport/buffer_pool.hpp @@ -0,0 +1,59 @@ +// +// Copyright 2010 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_BUFFER_POOL_HPP +#define INCLUDED_UHD_TRANSPORT_BUFFER_POOL_HPP + +#include +#include +#include + +namespace uhd{ namespace transport{ + + /*! + * A buffer pool manages memory for a homogeneous set of buffers. + * Each buffer is the pool start at a 16-byte alignment boundary. + */ + class UHD_API buffer_pool : boost::noncopyable{ + public: + typedef boost::shared_ptr sptr; + typedef void * ptr_type; + + /*! + * Make a new buffer pool. + * \param num_buffs the number of buffers to allocate + * \param buff_size the size of each buffer in bytes + * \param alignment the alignment boundary in bytes + * \return a new buffer pool buff_size X num_buffs + */ + static sptr make( + const size_t num_buffs, + const size_t buff_size, + const size_t alignment = 16 + ); + + //! Get a pointer to the buffer start at the specified index + virtual ptr_type at(const size_t index) const = 0; + + //! Get the number of buffers in this pool + virtual size_t size(void) const = 0; + }; + +}} //namespace + + +#endif /* INCLUDED_UHD_TRANSPORT_BUFFER_POOL_HPP */ diff --git a/host/include/uhd/transport/if_addrs.hpp b/host/include/uhd/transport/if_addrs.hpp index fbbb35e1d..84f24cb5a 100644 --- a/host/include/uhd/transport/if_addrs.hpp +++ b/host/include/uhd/transport/if_addrs.hpp @@ -15,8 +15,8 @@ // along with this program. If not, see . // -#ifndef INCLUDED_UHD_IFADDRS_HPP -#define INCLUDED_UHD_IFADDRS_HPP +#ifndef INCLUDED_UHD_TRANSPORT_IF_ADDRS_HPP +#define INCLUDED_UHD_TRANSPORT_IF_ADDRS_HPP #include #include @@ -44,4 +44,4 @@ namespace uhd{ namespace transport{ }} //namespace -#endif /* INCLUDED_UHD_IFADDRS_HPP */ +#endif /* INCLUDED_UHD_TRANSPORT_IF_ADDRS_HPP */ diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index 0d6226e4c..4bfe03b10 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -109,6 +109,7 @@ SET_SOURCE_FILES_PROPERTIES( ) LIBUHD_APPEND_SOURCES( + ${CMAKE_CURRENT_SOURCE_DIR}/buffer_pool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/if_addrs.cpp ${CMAKE_CURRENT_SOURCE_DIR}/udp_simple.cpp ${CMAKE_CURRENT_SOURCE_DIR}/udp_zero_copy_asio.cpp diff --git a/host/lib/transport/buffer_pool.cpp b/host/lib/transport/buffer_pool.cpp new file mode 100644 index 000000000..9a9ddfedf --- /dev/null +++ b/host/lib/transport/buffer_pool.cpp @@ -0,0 +1,80 @@ +// +// Copyright 2010 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 + +using namespace uhd::transport; + +//! pad the byte count to a multiple of alignment +static size_t pad_to_boundary(const size_t bytes, const size_t alignment){ + return bytes + (alignment - bytes)%alignment; +} + +/*********************************************************************** + * Buffer pool implementation + **********************************************************************/ +class buffer_pool_impl : public buffer_pool{ +public: + buffer_pool_impl( + const std::vector &ptrs, + boost::shared_array mem + ): _ptrs(ptrs), _mem(mem){ + /* NOP */ + } + + ptr_type at(const size_t index) const{ + return _ptrs.at(index); + } + + size_t size(void) const{ + return _ptrs.size(); + } + +private: + std::vector _ptrs; + boost::shared_array _mem; +}; + +/*********************************************************************** + * Buffer pool factor function + **********************************************************************/ +buffer_pool::sptr buffer_pool::make( + const size_t num_buffs, + const size_t buff_size, + const size_t alignment +){ + //1) pad the buffer size to be a multiple of alignment + //2) pad the overall memory size for room after alignment + //3) allocate the memory in one block of sufficient size + const size_t padded_buff_size = pad_to_boundary(buff_size, alignment); + boost::shared_array mem(new char[padded_buff_size*num_buffs + alignment]); + + //Fill a vector with boundary-aligned points in the memory + const size_t mem_start = pad_to_boundary(size_t(mem.get()), alignment); + std::vector ptrs(num_buffs); + for (size_t i = 0; i < num_buffs; i++){ + ptrs[i] = ptr_type(mem_start + padded_buff_size*i); + } + + //Create a new buffer pool implementation with: + // - the pre-computed pointers, and + // - the reference to allocated memory. + return sptr(new buffer_pool_impl(ptrs, mem)); +} + diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index f589d7c77..5dc230527 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -18,9 +18,9 @@ #include "libusb1_base.hpp" #include #include +#include #include #include -#include #include #include #include @@ -105,8 +105,8 @@ private: //! a list of all transfer structs we allocated std::vector _all_luts; - //! a block of memory for the transfer buffers - boost::shared_array _buffer; + //! memory allocated for the transfer buffers + buffer_pool::sptr _buffer_pool; // Calls for processing asynchronous I/O libusb_transfer *allocate_transfer(void *mem, size_t len); @@ -157,9 +157,9 @@ usb_endpoint::usb_endpoint( _input(input) { _completed_list = lut_buff_type::make(num_transfers); - _buffer = boost::shared_array(new char[num_transfers*transfer_size]); + _buffer_pool = buffer_pool::make(num_transfers, transfer_size); for (size_t i = 0; i < num_transfers; i++){ - _all_luts.push_back(allocate_transfer(_buffer.get() + i*transfer_size, transfer_size)); + _all_luts.push_back(allocate_transfer(_buffer_pool->at(i), transfer_size)); //input luts are immediately submitted to be filled //output luts go into the completed list as free buffers diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index c758fa894..d979f4377 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -18,10 +18,10 @@ #include #include //mtu #include +#include #include #include #include -#include #include #include #include @@ -123,16 +123,16 @@ public: void init(void){ //allocate all recv frames and release them to begin xfers _pending_recv_buffs = pending_buffs_type::make(_num_recv_frames); - _recv_buffer = boost::shared_array(new char[_num_recv_frames*_recv_frame_size]); + _recv_buffer_pool = buffer_pool::make(_num_recv_frames, _recv_frame_size); for (size_t i = 0; i < _num_recv_frames; i++){ - release(_recv_buffer.get() + i*_recv_frame_size); + release(_recv_buffer_pool->at(i)); } //allocate all send frames and push them into the fifo _pending_send_buffs = pending_buffs_type::make(_num_send_frames); - _send_buffer = boost::shared_array(new char[_num_send_frames*_send_frame_size]); + _send_buffer_pool = buffer_pool::make(_num_send_frames, _send_frame_size); for (size_t i = 0; i < _num_send_frames; i++){ - handle_send(_send_buffer.get() + i*_send_frame_size); + handle_send(_send_buffer_pool->at(i)); } //spawn the service threads that will run the io service @@ -302,7 +302,7 @@ public: private: //memory management -> buffers and fifos boost::thread_group _thread_group; - boost::shared_array _send_buffer, _recv_buffer; + buffer_pool::sptr _send_buffer_pool, _recv_buffer_pool; typedef bounded_buffer pending_buffs_type; pending_buffs_type::sptr _pending_recv_buffs, _pending_send_buffs; const size_t _recv_frame_size, _num_recv_frames; -- cgit v1.2.3 From df11c4d378ebe11ba4864d5a28559b8cb4af98c4 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 3 Jan 2011 14:19:01 -0800 Subject: uhd: some tweaks to buffer pool --- host/lib/transport/buffer_pool.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'host') diff --git a/host/lib/transport/buffer_pool.cpp b/host/lib/transport/buffer_pool.cpp index 9a9ddfedf..88ecedd2f 100644 --- a/host/lib/transport/buffer_pool.cpp +++ b/host/lib/transport/buffer_pool.cpp @@ -32,7 +32,7 @@ static size_t pad_to_boundary(const size_t bytes, const size_t alignment){ class buffer_pool_impl : public buffer_pool{ public: buffer_pool_impl( - const std::vector &ptrs, + const std::vector &ptrs, boost::shared_array mem ): _ptrs(ptrs), _mem(mem){ /* NOP */ @@ -47,7 +47,7 @@ public: } private: - std::vector _ptrs; + std::vector _ptrs; boost::shared_array _mem; }; @@ -63,7 +63,7 @@ buffer_pool::sptr buffer_pool::make( //2) pad the overall memory size for room after alignment //3) allocate the memory in one block of sufficient size const size_t padded_buff_size = pad_to_boundary(buff_size, alignment); - boost::shared_array mem(new char[padded_buff_size*num_buffs + alignment]); + boost::shared_array mem(new char[padded_buff_size*num_buffs + alignment-1]); //Fill a vector with boundary-aligned points in the memory const size_t mem_start = pad_to_boundary(size_t(mem.get()), alignment); -- cgit v1.2.3