From 158caeaa92df7ffdf363236985f4b8e7825f3950 Mon Sep 17 00:00:00 2001 From: ttsou Date: Wed, 9 Sep 2009 11:02:41 -0400 Subject: [PATCH] Added autotools header generation and build time version checking --- config/usrp_fusb_tech.m4 | 5 +- config/usrp_libusb.m4 | 79 ++++++++++++++---- usrp/host/Makefile.am | 2 +- usrp/host/include/usrp/Makefile.am | 10 +++ .../usrp/{usrp_basic.h => usrp_basic.h.in} | 54 ++---------- .../usrp/{usrp_prims.h => usrp_prims.h.in} | 82 ++++++++----------- usrp/host/lib/fusb.h | 9 +- usrp/host/lib/usrp_basic_common.cc | 8 +- usrp/host/lib/usrp_basic_libusb.cc | 1 - usrp/host/lib/usrp_prims_common.cc | 18 +--- usrp/host/lib/usrp_prims_libusb.cc | 25 +----- usrp/host/lib/usrp_prims_libusb1.cc | 20 +---- 12 files changed, 134 insertions(+), 179 deletions(-) rename usrp/host/include/usrp/{usrp_basic.h => usrp_basic.h.in} (96%) rename usrp/host/include/usrp/{usrp_prims.h => usrp_prims.h.in} (84%) diff --git a/config/usrp_fusb_tech.m4 b/config/usrp_fusb_tech.m4 index 196799e3..0be6a0ec 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 cb3130c8..1d9cf0cb 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 ' >> $tmpfile + echo '#include ' >> $tmpfile + echo >> $tmpfile ;; - *) ;; - esac + usrp_basic*) + echo '#include ' >> $tmpfile + echo '#include ' >> $tmpfile + echo '#include ' >> $tmpfile + echo '#include ' >> $tmpfile + echo '#include ' >> $tmpfile + echo '#include ' >> $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 aa94fbd6..cc4ba91a 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 d580d8a7..1e36b105 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 similarity index 96% rename from usrp/host/include/usrp/usrp_basic.h rename to usrp/host/include/usrp/usrp_basic.h.in index 3ec73411..3faa5304 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 -#include -#include -#include -#include -#include - -#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 similarity index 84% rename from usrp/host/include/usrp/usrp_prims.h rename to usrp/host/include/usrp/usrp_prims.h.in index bd7779b6..5e3df338 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 -#include +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 24d2bee6..dbfda5a6 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 2579827e..79e5b07e 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 +#include "usrp/usrp_basic.h" #include "usrp/usrp_prims.h" #include "usrp_interfaces.h" #include "fpga_regs_common.h" @@ -38,10 +38,10 @@ #include #include -#if 1 -#include -#else +#ifdef HAVE_LIBUSB_1 #include +#else +#include #endif using namespace ad9862; diff --git a/usrp/host/lib/usrp_basic_libusb.cc b/usrp/host/lib/usrp_basic_libusb.cc index 296890b6..c788cc05 100644 --- a/usrp/host/lib/usrp_basic_libusb.cc +++ b/usrp/host/lib/usrp_basic_libusb.cc @@ -39,7 +39,6 @@ #include #include - 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 4b695bec..5ef6503d 100644 --- a/usrp/host/lib/usrp_prims_common.cc +++ b/usrp/host/lib/usrp_prims_common.cc @@ -41,10 +41,10 @@ #include #include -#if 1 -#include -#else +#ifdef HAVE_LIBUSB_1 #include +#else +#include #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 diff --git a/usrp/host/lib/usrp_prims_libusb.cc b/usrp/host/lib/usrp_prims_libusb.cc index 841d447a..716e9fd7 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 3f0763bf..a99adafb 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; -- 2.30.2