diff options
-rw-r--r-- | config/usrp_fusb_tech.m4 | 5 | ||||
-rw-r--r-- | config/usrp_libusb.m4 | 79 | ||||
-rw-r--r-- | usrp/host/Makefile.am | 2 | ||||
-rw-r--r-- | usrp/host/include/usrp/Makefile.am | 10 | ||||
-rw-r--r-- | usrp/host/include/usrp/usrp_basic.h.in (renamed from usrp/host/include/usrp/usrp_basic.h) | 54 | ||||
-rw-r--r-- | usrp/host/include/usrp/usrp_prims.h.in (renamed from usrp/host/include/usrp/usrp_prims.h) | 82 | ||||
-rw-r--r-- | usrp/host/lib/fusb.h | 9 | ||||
-rw-r--r-- | usrp/host/lib/usrp_basic_common.cc | 8 | ||||
-rw-r--r-- | usrp/host/lib/usrp_basic_libusb.cc | 1 | ||||
-rw-r--r-- | usrp/host/lib/usrp_prims_common.cc | 18 | ||||
-rw-r--r-- | usrp/host/lib/usrp_prims_libusb.cc | 25 | ||||
-rw-r--r-- | usrp/host/lib/usrp_prims_libusb1.cc | 20 |
12 files changed, 134 insertions, 179 deletions
diff --git a/config/usrp_fusb_tech.m4 b/config/usrp_fusb_tech.m4 index 196799e34..0be6a0ec5 100644 --- a/config/usrp_fusb_tech.m4 +++ b/config/usrp_fusb_tech.m4 @@ -29,9 +29,12 @@ AC_DEFUN([USRP_SET_FUSB_TECHNIQUE],[ AC_HELP_STRING([--with-fusb-tech=OS], [Set fast USB technique (default=auto)]), [cf_with_fusb_tech="$withval"], - [cf_with_fusb_tech="$host_os"]) + [cf_with_fusb_tech="libusb1"]) if test [x]$1 != xno; then case "$cf_with_fusb_tech" in + libusb1*) + FUSB_TECH=libusb1 + ;; linux*) AC_CHECK_HEADER([linux/usbdevice_fs.h], [x_have_usbdevice_fs_h=yes], diff --git a/config/usrp_libusb.m4 b/config/usrp_libusb.m4 index cb3130c87..1d9cf0cbc 100644 --- a/config/usrp_libusb.m4 +++ b/config/usrp_libusb.m4 @@ -19,27 +19,78 @@ dnl Boston, MA 02110-1301, USA. AC_DEFUN([USRP_LIBUSB], [ libusbok=yes - PKG_CHECK_MODULES(USB, libusb, [], [ - AC_LANG_PUSH(C) + PKG_CHECK_MODULES(USB, libusb-1.0, [have_libusb1=yes; libusbok=yes], [ + PKG_CHECK_MODULES(USB, libusb, [have_libusb1=no; libusbok=yes], [libusbok=no]) + ]) - AC_CHECK_HEADERS([usb.h], [], [libusbok=no; AC_MSG_RESULT([USRP requires libusb. usb.h not found. See http://libusb.sf.net])]) + if test x$libusbok = xyes; then + if test x$have_libusb1 = xyes; then + AC_DEFINE(HAVE_LIBUSB_1, [1], [Define if libusb-1.0 found]) + fi + AC_OUTPUT_COMMANDS([ + case "$CONFIG_OTHER" in + usrp*) + outfile=usrp/host/include/usrp/$CONFIG_OTHER + tmpfile=${outfile}T + dirname="sed s,^.*/,,g" + + echo creating $outfile + cat > $tmpfile << _EOF_ +/* -*- Mode: C++ -*- +* -------------------------------------------------------------------- +* DO NOT EDIT THIS FILE! It has been automatically generated +* from: configure.in and `echo $outfile|$dirname`.in +* on host: `(hostname || uname -n) 2>/dev/null | sed 1q` +* -------------------------------------------------------------------- +*/ - save_LIBS="$LIBS" - case "$host_os" in - darwin*) - LIBS="$LIBS -lIOKit" +_EOF_ + echo "#ifndef _`echo $outfile | $dirname | tr a-z. A-Z_`_" >> $tmpfile + echo "#define _`echo $outfile | $dirname | tr a-z. A-Z_`_" >> $tmpfile + echo >> $tmpfile + + case "$CONFIG_OTHER" in + usrp_prims*) + echo '#include <usrp/usrp_slots.h>' >> $tmpfile + echo '#include <string>' >> $tmpfile + echo >> $tmpfile ;; - *) ;; - esac + usrp_basic*) + echo '#include <usrp/db_base.h>' >> $tmpfile + echo '#include <usrp/usrp_slots.h>' >> $tmpfile + echo '#include <string>' >> $tmpfile + echo '#include <vector>' >> $tmpfile + echo '#include <boost/utility.hpp>' >> $tmpfile + echo '#include <usrp/usrp_subdev_spec.h>' >> $tmpfile + echo >> $tmpfile + ;; + esac + + if test x$have_libusb1 = xno; then + echo 'struct usb_device;'>> $tmpfile + echo 'struct usb_dev_handle;'>> $tmpfile + echo 'typedef struct usb_device libusb_device;' >> $tmpfile + echo 'typedef struct usb_dev_handle libusb_device_handle;' >> $tmpfile + echo >> $tmpfile + fi - AC_SEARCH_LIBS(usb_bulk_write, [usb], [USB_LIBS="$LIBS"], [libusbok=no; AC_MSG_RESULT([USRP requires libusb. usb_bulk_write not found. See http://libusb.sf.net])]) + if test x$have_libusb1 = xyes; then + echo 'struct libusb_device;' >> $tmpfile + echo 'struct libusb_device_handle;' >> $tmpfile + echo >> $tmpfile + fi - LIBS="$save_LIBS" + # The ugly but portable cpp stuff comes from here + infile=usrp/host/include/usrp/`echo $outfile | sed 's,.*/,,g;s,\..*$,,g'`.h.in + sed '/^##.*$/d' $infile >> $tmpfile + mv ${tmpfile} ${outfile} + ;; + esac - AC_LANG_POP - ]) + ],[ + have_libusb1=$have_libusb1 + ]) - if test x$libusbok = xyes; then AC_SUBST(USB_LIBS) ifelse([$1], , :, [$1]) else diff --git a/usrp/host/Makefile.am b/usrp/host/Makefile.am index aa94fbd6e..cc4ba91aa 100644 --- a/usrp/host/Makefile.am +++ b/usrp/host/Makefile.am @@ -19,7 +19,7 @@ # Boston, MA 02110-1301, USA. # -SUBDIRS = misc lib include apps +SUBDIRS = misc include lib apps if PYTHON SUBDIRS += swig diff --git a/usrp/host/include/usrp/Makefile.am b/usrp/host/include/usrp/Makefile.am index d580d8a75..1e36b105a 100644 --- a/usrp/host/include/usrp/Makefile.am +++ b/usrp/host/include/usrp/Makefile.am @@ -23,6 +23,16 @@ include $(top_srcdir)/Makefile.common usrpincludedir = $(includedir)/usrp +usrp_prims.h: usrp_prims.h.in $(top_srcdir)/config.status + cd $(top_srcdir) \ + && CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=usrp_prims.h \ + $(SHELL) ./config.status + +usrp_basic.h: usrp_basic.h.in $(top_srcdir)/config.status + cd $(top_srcdir) \ + && CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=usrp_basic.h \ + $(SHELL) ./config.status + usrpinclude_HEADERS = \ db_base.h \ db_basic.h \ diff --git a/usrp/host/include/usrp/usrp_basic.h b/usrp/host/include/usrp/usrp_basic.h.in index 3ec734113..3faa5304f 100644 --- a/usrp/host/include/usrp/usrp_basic.h +++ b/usrp/host/include/usrp/usrp_basic.h.in @@ -1,24 +1,10 @@ -/* -*- c++ -*- */ -/* - * Copyright 2003,2004,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ +class fusb_devhandle; +class fusb_ephandle; + +enum txrx_t { + C_RX = 0, + C_TX = 1 +}; /* * ---------------------------------------------------------------------- @@ -36,32 +22,6 @@ * ---------------------------------------------------------------------- */ -#ifndef INCLUDED_USRP_BASIC_H -#define INCLUDED_USRP_BASIC_H - -#include <usrp/db_base.h> -#include <usrp/usrp_slots.h> -#include <string> -#include <vector> -#include <boost/utility.hpp> -#include <usrp/usrp_subdev_spec.h> - -#if 1 -struct usb_dev_handle; -struct usb_device; -typedef struct usb_dev_handle libusb_device_handle; -typedef struct usb_device libusb_device; -#else -struct libusb_device_handle; -#endif - -class fusb_devhandle; -class fusb_ephandle; - -enum txrx_t { - C_RX = 0, - C_TX = 1 -}; /*! * \brief abstract base class for usrp operations diff --git a/usrp/host/include/usrp/usrp_prims.h b/usrp/host/include/usrp/usrp_prims.h.in index bd7779b64..5e3df3389 100644 --- a/usrp/host/include/usrp/usrp_prims.h +++ b/usrp/host/include/usrp/usrp_prims.h.in @@ -1,58 +1,9 @@ -/* -*- c++ -*- */ -/* - * Copyright 2003,2004,2006,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -/* - * Low level primitives for directly messing with USRP hardware. - * - * If you're trying to use the USRP, you'll probably want to take a look - * at the usrp_rx and usrp_tx classes. They hide a bunch of low level details - * and provide high performance streaming i/o. - * - * This interface is built on top of libusb, which allegedly works under - * Linux, *BSD and Mac OS/X. http://libusb.sourceforge.net - */ - -#ifndef _USRP_PRIMS_H_ -#define _USRP_PRIMS_H_ - -#include <usrp/usrp_slots.h> -#include <string> +struct libusb_context; static const int USRP_HASH_SIZE = 16; enum usrp_load_status_t { ULS_ERROR = 0, ULS_OK, ULS_ALREADY_LOADED }; -#if 1 -struct usb_dev_handle; -struct usb_device; -typedef struct usb_dev_handle libusb_device_handle; -typedef struct usb_device libusb_device; -#else -struct libusb_device_handle; -struct libusb_device; -#endif - -struct libusb_context; - /*! * \brief initialize libusb; probe busses and devices. * If new_context is set to true, initiate and returns new libusb_context. @@ -306,4 +257,35 @@ bool usrp_write_dboard_offsets (libusb_device_handle *udh, int slot_id, */ std::string usrp_serial_number(libusb_device_handle *udh); +/* + * Static helper functions + */ + +bool _usrp_configured_p (libusb_device *q); +libusb_device_handle *usrp_open_interface(libusb_device *dev, + int interface, + int altinterface); +bool write_internal_ram (libusb_device_handle *udh, unsigned char *buf, + int start_addr, size_t len); +int write_cmd (libusb_device_handle *udh, int request, int value, + int index, unsigned char *bytes, int len); +bool usrp_usrp_p (libusb_device *q); +int usrp_hw_rev (libusb_device *q); +bool our_nanosleep (const struct timespec *delay); +const char *get_proto_filename (const std::string user_filename, + const char *env_var, + const char *def); +char *find_file (const char *filename, int hw_rev); +void load_status_msg (usrp_load_status_t s, const char *type, + const char *filename); +bool usrp1_fpga_write (libusb_device_handle *udh, int regno, int value); +bool usrp1_fpga_read (libusb_device_handle *udh, int regno, int *value); +bool usrp_set_switch (libusb_device_handle *udh, int cmd_byte, bool on); + +bool usrp_set_fpga_reset (libusb_device_handle *udh, bool on); +bool usrp_set_fpga_tx_enable (libusb_device_handle *udh, bool on); +bool usrp_set_fpga_rx_enable (libusb_device_handle *udh, bool on); +bool usrp_set_fpga_tx_reset (libusb_device_handle *udh, bool on); +bool usrp_set_fpga_rx_reset (libusb_device_handle *udh, bool on); + #endif /* _USRP_PRIMS_H_ */ diff --git a/usrp/host/lib/fusb.h b/usrp/host/lib/fusb.h index 24d2bee6e..dbfda5a61 100644 --- a/usrp/host/lib/fusb.h +++ b/usrp/host/lib/fusb.h @@ -25,12 +25,15 @@ #ifndef _FUSB_H_ #define _FUSB_H_ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -#if 1 +#ifdef HAVE_LIBUSB_1 +struct libusb_device_handle; +#else struct usb_dev_handle; typedef struct usb_dev_handle libusb_device_handle; -#else -struct libusb_device_handle; #endif struct libusb_context; diff --git a/usrp/host/lib/usrp_basic_common.cc b/usrp/host/lib/usrp_basic_common.cc index 2579827e9..79e5b07ec 100644 --- a/usrp/host/lib/usrp_basic_common.cc +++ b/usrp/host/lib/usrp_basic_common.cc @@ -24,7 +24,7 @@ #include "config.h" #endif -#include <usrp/usrp_basic.h> +#include "usrp/usrp_basic.h" #include "usrp/usrp_prims.h" #include "usrp_interfaces.h" #include "fpga_regs_common.h" @@ -38,10 +38,10 @@ #include <string.h> #include <cstdio> -#if 1 -#include <usb.h> -#else +#ifdef HAVE_LIBUSB_1 #include <libusb-1.0/libusb.h> +#else +#include <usb.h> #endif using namespace ad9862; diff --git a/usrp/host/lib/usrp_basic_libusb.cc b/usrp/host/lib/usrp_basic_libusb.cc index 296890b6c..c788cc054 100644 --- a/usrp/host/lib/usrp_basic_libusb.cc +++ b/usrp/host/lib/usrp_basic_libusb.cc @@ -39,7 +39,6 @@ #include <string.h> #include <cstdio> - using namespace ad9862; #define NELEM(x) (sizeof (x) / sizeof (x[0])) diff --git a/usrp/host/lib/usrp_prims_common.cc b/usrp/host/lib/usrp_prims_common.cc index 4b695bec5..5ef6503d5 100644 --- a/usrp/host/lib/usrp_prims_common.cc +++ b/usrp/host/lib/usrp_prims_common.cc @@ -41,10 +41,10 @@ #include <ad9862.h> #include <assert.h> -#if 1 -#include <usb.h> -#else +#ifdef HAVE_LIBUSB_1 #include <libusb-1.0/libusb.h> +#else +#include <usb.h> #endif extern "C" { @@ -66,18 +66,6 @@ static const int hash_slot_addr[2] = { static const char *default_firmware_filename = "std.ihx"; static const char *default_fpga_filename = "std_2rxhb_2tx.rbf"; -/* - * Forward Declarations - */ - -bool _usrp_configured_p (libusb_device *q); -libusb_device_handle *usrp_open_interface(libusb_device *dev, - int interface, - int altinterface); -bool write_internal_ram (libusb_device_handle *udh, unsigned char *buf, - int start_addr, size_t len); -int write_cmd (libusb_device_handle *udh, int request, int value, - int index, unsigned char *bytes, int len); #include "std_paths.h" #include <stdio.h> diff --git a/usrp/host/lib/usrp_prims_libusb.cc b/usrp/host/lib/usrp_prims_libusb.cc index 841d447ae..716e9fd70 100644 --- a/usrp/host/lib/usrp_prims_libusb.cc +++ b/usrp/host/lib/usrp_prims_libusb.cc @@ -50,29 +50,6 @@ extern "C" { using namespace ad9862; -/* - * Forward Declarations - */ - -bool our_nanosleep (const struct timespec *delay); -const char *get_proto_filename (const std::string user_filename, - const char *env_var, - const char *def); -char *find_file (const char *filename, int hw_rev); -void load_status_msg (usrp_load_status_t s, const char *type, - const char *filename); -bool usrp1_fpga_write (libusb_device_handle *udh, int regno, int value); -bool usrp1_fpga_read (libusb_device_handle *udh, int regno, int *value); -bool usrp_set_switch (libusb_device_handle *udh, int cmd_byte, bool on); - -bool usrp_set_fpga_reset (struct usb_dev_handle *udh, bool on); -bool usrp_set_fpga_tx_enable (struct usb_dev_handle *udh, bool on); -bool usrp_set_fpga_rx_enable (struct usb_dev_handle *udh, bool on); -bool usrp_set_fpga_tx_reset (struct usb_dev_handle *udh, bool on); -bool usrp_set_fpga_rx_reset (struct usb_dev_handle *udh, bool on); - - - static const int FIRMWARE_HASH_SLOT = 0; static const int FPGA_HASH_SLOT = 1; @@ -121,7 +98,7 @@ usrp_hw_rev (struct usb_device *q) /* * q must be a real USRP, not an FX2. Return true if it's configured. */ -static bool +bool _usrp_configured_p (struct usb_device *q) { return (q->descriptor.bcdDevice & 0xFF00) != 0; diff --git a/usrp/host/lib/usrp_prims_libusb1.cc b/usrp/host/lib/usrp_prims_libusb1.cc index 3f0763bf9..a99adafb3 100644 --- a/usrp/host/lib/usrp_prims_libusb1.cc +++ b/usrp/host/lib/usrp_prims_libusb1.cc @@ -50,24 +50,6 @@ extern "C" { using namespace ad9862; -bool our_nanosleep (const struct timespec *delay); -const char *get_proto_filename (const std::string user_filename, - const char *env_var, - const char *def); -char *find_file (const char *filename, int hw_rev); -void load_status_msg (usrp_load_status_t s, const char *type, - const char *filename); -bool usrp1_fpga_write (libusb_device_handle *udh, int regno, int value); -bool usrp1_fpga_read (libusb_device_handle *udh, int regno, int *value); -bool usrp_set_switch (libusb_device_handle *udh, int cmd_byte, bool on); - -bool usrp_set_fpga_reset (struct usb_dev_handle *udh, bool on); -bool usrp_set_fpga_tx_enable (struct usb_dev_handle *udh, bool on); -bool usrp_set_fpga_rx_enable (struct usb_dev_handle *udh, bool on); -bool usrp_set_fpga_tx_reset (struct usb_dev_handle *udh, bool on); -bool usrp_set_fpga_rx_reset (struct usb_dev_handle *udh, bool on); - - static const int FIRMWARE_HASH_SLOT = 0; static const int FPGA_HASH_SLOT = 1; @@ -132,7 +114,7 @@ usrp_hw_rev (struct libusb_device *q) /* * q must be a real USRP, not an FX2. Return true if it's configured. */ -static bool +bool _usrp_configured_p (struct libusb_device *q) { struct libusb_device_descriptor desc; |