summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.common1
-rw-r--r--config/ax_cxx_check_flag.m484
-rw-r--r--configure.ac24
-rw-r--r--include/usrp_uhd/usrp/dboard/base.hpp27
-rw-r--r--include/usrp_uhd/usrp/dboard/manager.hpp28
-rw-r--r--lib/usrp/dboard/base.cpp27
-rw-r--r--lib/usrp/dboard/dboards.hpp8
-rw-r--r--lib/usrp/dboard/manager.cpp98
8 files changed, 202 insertions, 95 deletions
diff --git a/Makefile.common b/Makefile.common
index 0afe43c7b..8972e4f42 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -7,7 +7,6 @@ USRP_UHD_LA = $(abs_top_builddir)/lib/libusrp_uhd.la
USRP_UHD_USRP_DBOARD_LA = $(abs_top_builddir)/lib/usrp/dboard/lib.la
GENERAL_CPPFLAGS = \
- -W -Wall -Werror -ansi -pedantic \
-I$(top_srcdir)/include \
$(BOOST_CPPFLAGS)
diff --git a/config/ax_cxx_check_flag.m4 b/config/ax_cxx_check_flag.m4
new file mode 100644
index 000000000..2de9f273f
--- /dev/null
+++ b/config/ax_cxx_check_flag.m4
@@ -0,0 +1,84 @@
+# ===========================================================================
+# http://www.nongnu.org/autoconf-archive/ax_cxx_check_flag.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CXX_CHECK_FLAG(FLAG-TO-CHECK,[PROLOGUE],[BODY],[ACTION-IF-SUCCESS],[ACTION-IF-FAILURE])
+#
+# DESCRIPTION
+#
+# This macro tests if the C++ compiler supports the flag FLAG-TO-CHECK. If
+# successfull execute ACTION-IF-SUCCESS otherwise ACTION-IF-FAILURE.
+# PROLOGUE and BODY are optional and should be used as in AC_LANG_PROGRAM
+# macro.
+#
+# This code is inspired from KDE_CHECK_COMPILER_FLAG macro. Thanks to
+# Bogdan Drozdowski <bogdandr@op.pl> for testing and bug fixes.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Francesco Salvestrini <salvestrini@users.sourceforge.net>
+#
+# 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 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+AC_DEFUN([AX_CXX_CHECK_FLAG],[
+ AC_PREREQ([2.61])
+ AC_REQUIRE([AC_PROG_CXX])
+ AC_REQUIRE([AC_PROG_SED])
+
+ flag=`echo "$1" | $SED 'y% .=/+-(){}<>:*,%_______________%'`
+
+ AC_CACHE_CHECK([whether the C++ compiler accepts the $1 flag],
+ [ax_cv_cxx_check_flag_$flag],[
+
+ AC_LANG_PUSH([C++])
+
+ save_CXXFLAGS="$CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS $1"
+ AC_COMPILE_IFELSE([
+ AC_LANG_PROGRAM([$2],[$3])
+ ],[
+ eval "ax_cv_cxx_check_flag_$flag=yes"
+ ],[
+ eval "ax_cv_cxx_check_flag_$flag=no"
+ ])
+
+ CXXFLAGS="$save_CXXFLAGS"
+
+ AC_LANG_POP
+
+ ])
+
+ AS_IF([eval "test \"`echo '$ax_cv_cxx_check_flag_'$flag`\" = yes"],[
+ :
+ $4
+ ],[
+ :
+ $5
+ ])
+])
diff --git a/configure.ac b/configure.ac
index e36fce8ef..acb77f90c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,10 +14,32 @@ AM_INIT_AUTOMAKE(usrp_uhd, 0)
##################################################
AC_PROG_CXX
LT_INIT
-AX_BOOST_BASE([1.36])
+AX_BOOST_BASE([1.36], [], AC_MSG_ERROR("cannot find boost"))
AX_BOOST_THREAD
##################################################
+## Check Headers
+##################################################
+AC_DEFUN([UHD_CHECK_HEADER],[
+ AC_CHECK_HEADER([$1], [], AC_MSG_ERROR("cannot find header $1"))
+])
+UHD_CHECK_HEADER([sys/uio.h])
+UHD_CHECK_HEADER([arpa/inet.h])
+UHD_CHECK_HEADER([netinet/ether.h])
+
+##################################################
+## Check Flags
+##################################################
+AC_DEFUN([UHD_OPTIONAL_CXXFLAG],[
+ AX_CXX_CHECK_FLAG([$1], [], [], [CXXFLAGS="${CXXFLAGS} $1"])
+])
+UHD_OPTIONAL_CXXFLAG([-Wall])
+UHD_OPTIONAL_CXXFLAG([-Wextra])
+UHD_OPTIONAL_CXXFLAG([-Werror])
+UHD_OPTIONAL_CXXFLAG([-pedantic])
+UHD_OPTIONAL_CXXFLAG([-ansi])
+
+##################################################
## Check Programs
##################################################
AC_PATH_PROG(SED, sed)
diff --git a/include/usrp_uhd/usrp/dboard/base.hpp b/include/usrp_uhd/usrp/dboard/base.hpp
index 09cc9b324..82895ed59 100644
--- a/include/usrp_uhd/usrp/dboard/base.hpp
+++ b/include/usrp_uhd/usrp/dboard/base.hpp
@@ -15,19 +15,19 @@ namespace usrp_uhd{ namespace usrp{ namespace dboard{
/*!
* A daughter board base class for all dboards.
- * Sub classes for xcvr boards should inherit this.
+ * Only other dboard base classes should inherit this.
*/
-class xcvr_base : boost::noncopyable{
+class base : boost::noncopyable{
public:
- typedef boost::shared_ptr<xcvr_base> sptr;
+ typedef boost::shared_ptr<base> sptr;
//the constructor args consist of a subdev index and an interface
//derived classes should pass the args into the base class ctor
//but should not have to deal with the internals of the args
typedef boost::tuple<size_t, interface::sptr> ctor_args_t;
//structors
- xcvr_base(ctor_args_t const&);
- ~xcvr_base(void);
+ base(ctor_args_t const&);
+ ~base(void);
//interface
virtual void rx_get(const wax::type &key, wax::type &val) = 0;
@@ -45,10 +45,23 @@ private:
};
/*!
+ * A xcvr daughter board implements rx and tx methods
+ * Sub classes for xcvr boards should inherit this.
+ */
+class xcvr_base : public base{
+public:
+ /*!
+ * Create a new xcvr dboard object, override in subclasses.
+ */
+ xcvr_base(ctor_args_t const&);
+ ~xcvr_base(void);
+};
+
+/*!
* A rx daughter board only implements rx methods.
* Sub classes for rx-only boards should inherit this.
*/
-class rx_base : public xcvr_base{
+class rx_base : public base{
public:
/*!
* Create a new rx dboard object, override in subclasses.
@@ -66,7 +79,7 @@ public:
* A tx daughter board only implements tx methods.
* Sub classes for rx-only boards should inherit this.
*/
-class tx_base : public xcvr_base{
+class tx_base : public base{
public:
/*!
* Create a new rx dboard object, override in subclasses.
diff --git a/include/usrp_uhd/usrp/dboard/manager.hpp b/include/usrp_uhd/usrp/dboard/manager.hpp
index 788b8a6eb..d977fa527 100644
--- a/include/usrp_uhd/usrp/dboard/manager.hpp
+++ b/include/usrp_uhd/usrp/dboard/manager.hpp
@@ -8,7 +8,6 @@
#include <vector>
#include <usrp_uhd/wax.hpp>
#include <boost/utility.hpp>
-#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <usrp_uhd/usrp/dboard/base.hpp>
@@ -26,29 +25,16 @@ public:
typedef uint16_t dboard_id_t;
//dboard constructor (each dboard should have a ::make with this signature)
- typedef boost::function<xcvr_base::sptr(xcvr_base::ctor_args_t)> dboard_ctor_t;
+ typedef base::sptr(*dboard_ctor_t)(base::ctor_args_t const&);
/*!
- * Register rx subdevices for a given dboard id.
+ * Register subdevices for a given dboard id.
*
- * \param dboard_id the rx dboard id
+ * \param dboard_id the dboard id (rx or tx)
* \param dboard_ctor the dboard constructor function pointer
- * \param num_subdevs the number of rx subdevs in this dboard
+ * \param num_subdevs the number of subdevs in this dboard
*/
- static void register_rx_subdev(
- dboard_id_t dboard_id,
- dboard_ctor_t dboard_ctor,
- size_t num_subdevs
- );
-
- /*!
- * Register tx subdevices for a given dboard id.
- *
- * \param dboard_id the tx dboard id
- * \param dboard_ctor the dboard constructor function pointer
- * \param num_subdevs the number of tx subdevs in this dboard
- */
- static void register_tx_subdev(
+ static void register_subdevs(
dboard_id_t dboard_id,
dboard_ctor_t dboard_ctor,
size_t num_subdevs
@@ -73,8 +59,8 @@ public:
private:
//list of rx and tx dboards in this manager
//each dboard here is actually a subdevice
- std::vector<xcvr_base::sptr> _rx_dboards;
- std::vector<xcvr_base::sptr> _tx_dboards;
+ std::vector<base::sptr> _rx_dboards;
+ std::vector<base::sptr> _tx_dboards;
};
}}} //namespace
diff --git a/lib/usrp/dboard/base.cpp b/lib/usrp/dboard/base.cpp
index 4fbe4df8c..d8a6e66c2 100644
--- a/lib/usrp/dboard/base.cpp
+++ b/lib/usrp/dboard/base.cpp
@@ -7,30 +7,40 @@
using namespace usrp_uhd::usrp::dboard;
/***********************************************************************
- * xcvr dboard base class
+ * base dboard base class
**********************************************************************/
-xcvr_base::xcvr_base(ctor_args_t const& args)
+base::base(ctor_args_t const& args)
: _subdev_index(args.get<0>()), _dboard_interface(args.get<1>()){
/* NOP */
}
-xcvr_base::~xcvr_base(void){
+base::~base(void){
/* NOP */
}
-size_t xcvr_base::get_subdev_index(void){
+size_t base::get_subdev_index(void){
return _subdev_index;
}
-interface::sptr xcvr_base::get_interface(void){
+interface::sptr base::get_interface(void){
return _dboard_interface;
}
/***********************************************************************
+ * xcvr dboard base class
+ **********************************************************************/
+xcvr_base::xcvr_base(ctor_args_t const& args) : base(args){
+ /* NOP */
+}
+
+xcvr_base::~xcvr_base(void){
+ /* NOP */
+}
+
+/***********************************************************************
* rx dboard base class
**********************************************************************/
-rx_base::rx_base(ctor_args_t const& args)
-: xcvr_base(args){
+rx_base::rx_base(ctor_args_t const& args) : base(args){
/* NOP */
}
@@ -49,8 +59,7 @@ void rx_base::tx_set(const wax::type &, const wax::type &){
/***********************************************************************
* tx dboard base class
**********************************************************************/
-tx_base::tx_base(ctor_args_t const& args)
-: xcvr_base(args){
+tx_base::tx_base(ctor_args_t const& args) : base(args){
/* NOP */
}
diff --git a/lib/usrp/dboard/dboards.hpp b/lib/usrp/dboard/dboards.hpp
index b46b5f590..7a93286ae 100644
--- a/lib/usrp/dboard/dboards.hpp
+++ b/lib/usrp/dboard/dboards.hpp
@@ -14,8 +14,8 @@ using namespace usrp_uhd::usrp::dboard;
**********************************************************************/
class basic_rx : public rx_base{
public:
- static xcvr_base::sptr make(ctor_args_t const& args){
- return xcvr_base::sptr(new basic_rx(args));
+ static base::sptr make(ctor_args_t const& args){
+ return base::sptr(new basic_rx(args));
}
basic_rx(ctor_args_t const& args);
~basic_rx(void);
@@ -26,8 +26,8 @@ public:
class basic_tx : public tx_base{
public:
- static xcvr_base::sptr make(ctor_args_t const& args){
- return xcvr_base::sptr(new basic_tx(args));
+ static base::sptr make(ctor_args_t const& args){
+ return base::sptr(new basic_tx(args));
}
basic_tx(ctor_args_t const& args);
~basic_tx(void);
diff --git a/lib/usrp/dboard/manager.cpp b/lib/usrp/dboard/manager.cpp
index 897b6e304..6486fadf2 100644
--- a/lib/usrp/dboard/manager.cpp
+++ b/lib/usrp/dboard/manager.cpp
@@ -3,7 +3,6 @@
//
#include <usrp_uhd/usrp/dboard/manager.hpp>
-#include <boost/tuple/tuple.hpp>
#include <boost/format.hpp>
#include <map>
#include "dboards.hpp"
@@ -27,48 +26,27 @@ static void register_internal_dboards(void){
static bool called = false;
if (called) return; called = true;
//register the known dboards (dboard id, constructor, num subdevs)
- manager::register_tx_subdev(0x0000, &basic_tx::make, 1);
- manager::register_rx_subdev(0x0001, &basic_rx::make, 3);
+ manager::register_subdevs(0x0000, &basic_tx::make, 1);
+ manager::register_subdevs(0x0001, &basic_rx::make, 3);
}
/***********************************************************************
* storage and registering for dboards
**********************************************************************/
-//hold a dboard constructor and the number of subdevs
-typedef boost::tuple<manager::dboard_ctor_t, size_t> dboard_reg_val_t;
+//map a dboard id to a dboard constructor
+static std::map<manager::dboard_id_t, manager::dboard_ctor_t> id_to_ctor_map;
-//map a dboard id to a registered value tuple
-typedef std::map<manager::dboard_id_t, dboard_reg_val_t> dboard_reg_map_t;
+//map a dboard constructor to number of subdevices
+static std::map<manager::dboard_ctor_t, size_t> ctor_to_num_map;
-//static instances of registered dboard ids
-static dboard_reg_map_t dboard_rx_regs, dboard_tx_regs;
-
-/*!
- * Helper function to register a dboard contructor to its id.
- * This should be called by the api calls to register subdevs.
- */
-static void register_xx_subdev(
- manager::dboard_id_t dboard_id,
- manager::dboard_ctor_t dboard_ctor,
- size_t num_subdevs,
- dboard_reg_map_t &dboard_reg_map
+void manager::register_subdevs(
+ dboard_id_t dboard_id,
+ dboard_ctor_t dboard_ctor,
+ size_t num_subdevs
){
register_internal_dboards(); //always call first
- dboard_reg_map.insert(std::pair<manager::dboard_id_t, dboard_reg_val_t>(
- dboard_id, dboard_reg_val_t(dboard_ctor, num_subdevs)
- ));
-}
-
-void manager::register_rx_subdev(
- dboard_id_t dboard_id, dboard_ctor_t dboard_ctor, size_t num_subdevs
-){
- register_xx_subdev(dboard_id, dboard_ctor, num_subdevs, dboard_rx_regs);
-}
-
-void manager::register_tx_subdev(
- dboard_id_t dboard_id, dboard_ctor_t dboard_ctor, size_t num_subdevs
-){
- register_xx_subdev(dboard_id, dboard_ctor, num_subdevs, dboard_tx_regs);
+ id_to_ctor_map[dboard_id] = dboard_ctor;
+ ctor_to_num_map[dboard_ctor] = num_subdevs;
}
/***********************************************************************
@@ -84,7 +62,7 @@ public:
enum type_t{RX_TYPE, TX_TYPE};
//structors
- subdev_proxy(xcvr_base::sptr subdev, type_t type)
+ subdev_proxy(base::sptr subdev, type_t type)
: _subdev(subdev), _type(type){
/* NOP */
}
@@ -94,8 +72,8 @@ public:
}
private:
- xcvr_base::sptr _subdev;
- type_t _type;
+ base::sptr _subdev;
+ type_t _type;
//forward the get calls to the rx or tx
void get(const wax::type &key, wax::type &val){
@@ -117,27 +95,18 @@ private:
/***********************************************************************
* dboard manager methods
**********************************************************************/
-static void create_subdevs(
- dboard_reg_map_t &dboard_reg_map,
+static manager::dboard_ctor_t const& get_dboard_ctor(
manager::dboard_id_t dboard_id,
- interface::sptr dboard_interface,
- std::vector<xcvr_base::sptr> &subdevs,
std::string const& xx_type
){
//verify that there is a registered constructor for this id
- if (dboard_reg_map.count(dboard_id) == 0){
+ if (id_to_ctor_map.count(dboard_id) == 0){
throw std::runtime_error(str(
boost::format("Unknown %s dboard id: 0x%04x") % xx_type % dboard_id
));
}
- //create new subdevices for the dboard ids
- for (size_t i = 0; i < dboard_reg_map[dboard_id].get<1>(); i++){
- subdevs.push_back(
- dboard_reg_map[dboard_id].get<0>()(
- xcvr_base::ctor_args_t(i, dboard_interface)
- )
- );
- }
+ //return the dboard constructor for this id
+ return id_to_ctor_map[dboard_id];
}
manager::manager(
@@ -146,8 +115,33 @@ manager::manager(
interface::sptr dboard_interface
){
register_internal_dboards(); //always call first
- create_subdevs(dboard_rx_regs, rx_dboard_id, dboard_interface, _rx_dboards, "rx");
- create_subdevs(dboard_tx_regs, tx_dboard_id, dboard_interface, _tx_dboards, "tx");
+ const dboard_ctor_t rx_dboard_ctor = get_dboard_ctor(rx_dboard_id, "rx");
+ const dboard_ctor_t tx_dboard_ctor = get_dboard_ctor(tx_dboard_id, "tx");
+ //make xcvr subdevs (make one subdev for both rx and tx dboards)
+ if (rx_dboard_ctor == tx_dboard_ctor){
+ for (size_t i = 0; i < ctor_to_num_map[rx_dboard_ctor]; i++){
+ base::sptr xcvr_dboard = rx_dboard_ctor(
+ base::ctor_args_t(i, dboard_interface)
+ );
+ _rx_dboards.push_back(xcvr_dboard);
+ _tx_dboards.push_back(xcvr_dboard);
+ }
+ }
+ //make tx and rx subdevs (separate subdevs for rx and tx dboards)
+ else{
+ //make the rx subdevs
+ for (size_t i = 0; i < ctor_to_num_map[rx_dboard_ctor]; i++){
+ _rx_dboards.push_back(rx_dboard_ctor(
+ base::ctor_args_t(i, dboard_interface)
+ ));
+ }
+ //make the tx subdevs
+ for (size_t i = 0; i < ctor_to_num_map[tx_dboard_ctor]; i++){
+ _tx_dboards.push_back(tx_dboard_ctor(
+ base::ctor_args_t(i, dboard_interface)
+ ));
+ }
+ }
}
manager::~manager(void){