summaryrefslogtreecommitdiff
path: root/usrp/host/include
diff options
context:
space:
mode:
Diffstat (limited to 'usrp/host/include')
-rw-r--r--usrp/host/include/usrp/.gitignore3
-rw-r--r--usrp/host/include/usrp/Makefile.am4
-rw-r--r--usrp/host/include/usrp/libusb_types.h.in38
-rw-r--r--usrp/host/include/usrp/usrp_basic.h70
-rw-r--r--usrp/host/include/usrp/usrp_prims.h144
5 files changed, 155 insertions, 104 deletions
diff --git a/usrp/host/include/usrp/.gitignore b/usrp/host/include/usrp/.gitignore
index 25b2cae79..0f068a1f3 100644
--- a/usrp/host/include/usrp/.gitignore
+++ b/usrp/host/include/usrp/.gitignore
@@ -1,3 +1,6 @@
/Makefile
/Makefile.in
+
+# Generated files
+/libusb_types.h
/usrp_dbid.h
diff --git a/usrp/host/include/usrp/Makefile.am b/usrp/host/include/usrp/Makefile.am
index d580d8a75..769acc774 100644
--- a/usrp/host/include/usrp/Makefile.am
+++ b/usrp/host/include/usrp/Makefile.am
@@ -34,6 +34,7 @@ usrpinclude_HEADERS = \
db_tv_rx.h \
db_tv_rx_mimo.h \
db_xcvr2450.h \
+ libusb_types.h \
usrp_basic.h \
usrp_bytesex.h \
usrp_dbid.h \
@@ -44,6 +45,9 @@ usrpinclude_HEADERS = \
usrp_subdev_spec.h \
usrp_tune_result.h
+EXTRA_DIST = \
+ libusb_types.h.in
+
if PYTHON
swiginclude_HEADERS = \
db_base.i
diff --git a/usrp/host/include/usrp/libusb_types.h.in b/usrp/host/include/usrp/libusb_types.h.in
new file mode 100644
index 000000000..cf10e33cc
--- /dev/null
+++ b/usrp/host/include/usrp/libusb_types.h.in
@@ -0,0 +1,38 @@
+/* -*- Mode: C++ -*- */
+/*
+ * Copyright 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.
+ */
+
+#ifndef _LIBUSB_TYPES_H_
+#define _LIBUSB_TYPES_H_
+
+#if @USE_LIBUSB1@
+#include <libusb-1.0/libusb.h>
+struct libusb_device;
+struct libusb_device_handle;
+struct libusb_device_descriptor;
+#else
+#include <usb.h>
+typedef struct usb_device libusb_device;
+typedef struct usb_dev_handle libusb_device_handle;
+typedef struct usb_device_descriptor libusb_device_descriptor;
+#endif
+
+#endif /* _LIBUSB_TYPES_H_ */
diff --git a/usrp/host/include/usrp/usrp_basic.h b/usrp/host/include/usrp/usrp_basic.h
index fbbf49d57..c24630eb6 100644
--- a/usrp/host/include/usrp/usrp_basic.h
+++ b/usrp/host/include/usrp/usrp_basic.h
@@ -1,52 +1,36 @@
-/* -*- c++ -*- */
+/* -*- c++ -*- */
/*
- * Copyright 2003,2004,2008,2009 Free Software Foundation, Inc.
- *
+ * Copyright 2005,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.
*/
-/*
- * ----------------------------------------------------------------------
- * Mid level interface to the Universal Software Radio Peripheral (Rev 1)
- *
- * These classes implement the basic functionality for talking to the
- * USRP. They try to be as independent of the signal processing code
- * in FPGA as possible. They implement access to the low level
- * peripherals on the board, provide a common way for reading and
- * writing registers in the FPGA, and provide the high speed interface
- * to streaming data across the USB.
- *
- * It is expected that subclasses will be derived that provide
- * access to the functionality to a particular FPGA configuration.
- * ----------------------------------------------------------------------
- */
-
#ifndef INCLUDED_USRP_BASIC_H
#define INCLUDED_USRP_BASIC_H
#include <usrp/db_base.h>
#include <usrp/usrp_slots.h>
+#include <usrp/usrp_subdev_spec.h>
+#include <usrp/libusb_types.h>
#include <string>
#include <vector>
#include <boost/utility.hpp>
-#include <usrp/usrp_subdev_spec.h>
-struct usb_dev_handle;
class fusb_devhandle;
class fusb_ephandle;
@@ -55,6 +39,23 @@ enum txrx_t {
C_TX = 1
};
+/*
+ * ----------------------------------------------------------------------
+ * Mid level interface to the Universal Software Radio Peripheral (Rev 1)
+ *
+ * These classes implement the basic functionality for talking to the
+ * USRP. They try to be as independent of the signal processing code
+ * in FPGA as possible. They implement access to the low level
+ * peripherals on the board, provide a common way for reading and
+ * writing registers in the FPGA, and provide the high speed interface
+ * to streaming data across the USB.
+ *
+ * It is expected that subclasses will be derived that provide
+ * access to the functionality to a particular FPGA configuration.
+ * ----------------------------------------------------------------------
+ */
+
+
/*!
* \brief abstract base class for usrp operations
* \ingroup usrp
@@ -65,16 +66,17 @@ protected:
void shutdown_daughterboards();
protected:
- struct usb_dev_handle *d_udh;
- int d_usb_data_rate; // bytes/sec
- int d_bytes_per_poll; // how often to poll for overruns
- bool d_verbose;
- long d_fpga_master_clock_freq;
+ libusb_device_handle *d_udh;
+ struct libusb_context *d_ctx;
+ int d_usb_data_rate; // bytes/sec
+ int d_bytes_per_poll; // how often to poll for overruns
+ bool d_verbose;
+ long d_fpga_master_clock_freq;
- static const int MAX_REGS = 128;
- unsigned int d_fpga_shadows[MAX_REGS];
+ static const int MAX_REGS = 128;
+ unsigned int d_fpga_shadows[MAX_REGS];
- int d_dbid[2]; // daughterboard ID's (side A, side B)
+ int d_dbid[2]; // daughterboard ID's (side A, side B)
/*!
* Shared pointers to subclasses of db_base.
@@ -91,7 +93,7 @@ protected:
usrp_basic (int which_board,
- struct usb_dev_handle *open_interface (struct usb_device *dev),
+ libusb_device_handle *open_interface (libusb_device *dev),
const std::string fpga_filename = "",
const std::string firmware_filename = "");
@@ -988,4 +990,4 @@ public:
bool stop ();
};
-#endif
+#endif /* INCLUDED_USRP_BASIC_H */
diff --git a/usrp/host/include/usrp/usrp_prims.h b/usrp/host/include/usrp/usrp_prims.h
index aa0887050..323287d02 100644
--- a/usrp/host/include/usrp/usrp_prims.h
+++ b/usrp/host/include/usrp/usrp_prims.h
@@ -1,54 +1,57 @@
-/* -*- c++ -*- */
+/* -*- c++ -*- */
/*
- * Copyright 2003,2004,2006,2009 Free Software Foundation, Inc.
- *
+ * Copyright 2005,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_
+#ifndef INCLUDED_USRP_PRIMS_H
+#define INCLUDED_USRP_PRIMS_H
#include <usrp/usrp_slots.h>
+#include <usrp/libusb_types.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 };
-struct usb_dev_handle;
-struct usb_device;
-
/*!
- * \brief initialize libusb; probe busses and devices.
+ * \brief initialize libusb; Behavior differs depending on libusb version
+ *
+ * libusb-0.12
+ *
+ * Probe busses and devices. The argument is ignored and defaults to NULL.
* Safe to call more than once.
+ *
+ * libusb-1.0
+ *
+ * If an location to a libusb_context is passed in, create and write in the new
+ * context. If no argument is provided, initialize libusb with the default
+ * (NULL) context.
+ *
+ * Generally _not_ safe to call more than once with non-NULL argument since a
+ * new context will be created each time.
*/
-void usrp_one_time_init ();
+
+void usrp_one_time_init (libusb_context **ctx = NULL);
/*
* force a rescan of the buses and devices
@@ -65,21 +68,21 @@ void usrp_rescan ();
* configured USRP (firmware loaded)
* unconfigured Cypress FX2 (only if fx2_ok_p is true)
*/
-struct usb_device *usrp_find_device (int nth, bool fx2_ok_p = false);
+libusb_device *usrp_find_device (int nth, bool fx2_ok_p = false, libusb_context *ctx = NULL);
-bool usrp_usrp_p (struct usb_device *q); //< is this a USRP
-bool usrp_usrp0_p (struct usb_device *q); //< is this a USRP Rev 0
-bool usrp_usrp1_p (struct usb_device *q); //< is this a USRP Rev 1
-bool usrp_usrp2_p (struct usb_device *q); //< is this a USRP Rev 2
-int usrp_hw_rev (struct usb_device *q); //< return h/w rev code
+bool usrp_usrp_p (libusb_device *q); //< is this a USRP
+bool usrp_usrp0_p (libusb_device *q); //< is this a USRP Rev 0
+bool usrp_usrp1_p (libusb_device *q); //< is this a USRP Rev 1
+bool usrp_usrp2_p (libusb_device *q); //< is this a USRP Rev 2
+int usrp_hw_rev (libusb_device *q); //< return h/w rev code
-bool usrp_fx2_p (struct usb_device *q); //< is this an unconfigured Cypress FX2
+bool usrp_fx2_p (libusb_device *q); //< is this an unconfigured Cypress FX2
-bool usrp_unconfigured_usrp_p (struct usb_device *q); //< some kind of unconfigured USRP
-bool usrp_configured_usrp_p (struct usb_device *q); //< some kind of configured USRP
+bool usrp_unconfigured_usrp_p (libusb_device *q); //< some kind of unconfigured USRP
+bool usrp_configured_usrp_p (libusb_device *q); //< some kind of configured USRP
/*!
- * \brief given a usb_device return an instance of the appropriate usb_dev_handle
+ * \brief given a libusb_device return an instance of the appropriate libusb_device_handle
*
* These routines claim the specified interface and select the
* correct alternate interface. (USB nomenclature is totally screwed!)
@@ -87,14 +90,14 @@ bool usrp_configured_usrp_p (struct usb_device *q); //< some kind of configured
* If interface can't be opened, or is already claimed by some other
* process, 0 is returned.
*/
-struct usb_dev_handle *usrp_open_cmd_interface (struct usb_device *dev);
-struct usb_dev_handle *usrp_open_rx_interface (struct usb_device *dev);
-struct usb_dev_handle *usrp_open_tx_interface (struct usb_device *dev);
+libusb_device_handle *usrp_open_cmd_interface (libusb_device *dev);
+libusb_device_handle *usrp_open_rx_interface (libusb_device *dev);
+libusb_device_handle *usrp_open_tx_interface (libusb_device *dev);
/*!
* \brief close interface.
*/
-bool usrp_close_interface (struct usb_dev_handle *udh);
+bool usrp_close_interface (libusb_device_handle *udh);
/*!
* \brief load intel hex format file into USRP/Cypress FX2 (8051).
@@ -106,7 +109,7 @@ bool usrp_close_interface (struct usb_dev_handle *udh);
*/
usrp_load_status_t
-usrp_load_firmware (struct usb_dev_handle *udh, const char *filename, bool force);
+usrp_load_firmware (libusb_device_handle *udh, const char *filename, bool force);
/*!
* \brief load intel hex format file into USRP FX2 (8051).
@@ -119,13 +122,13 @@ usrp_load_firmware (struct usb_dev_handle *udh, const char *filename, bool force
* then rescans the busses and devices.
*/
usrp_load_status_t
-usrp_load_firmware_nth (int nth, const char *filename, bool force);
+usrp_load_firmware_nth (int nth, const char *filename, bool force, libusb_context *ctx = NULL);
/*!
* \brief load fpga configuration bitstream
*/
usrp_load_status_t
-usrp_load_fpga (struct usb_dev_handle *udh, const char *filename, bool force);
+usrp_load_fpga (libusb_device_handle *udh, const char *filename, bool force);
/*!
* \brief load the regular firmware and fpga bitstream in the Nth USRP.
@@ -134,60 +137,61 @@ usrp_load_fpga (struct usb_dev_handle *udh, const char *filename, bool force);
*/
bool usrp_load_standard_bits (int nth, bool force,
const std::string fpga_filename = "",
- const std::string firmware_filename = "");
+ const std::string firmware_filename = "",
+ libusb_context *ctx = NULL);
/*!
* \brief copy the given \p hash into the USRP hash slot \p which.
* The usrp implements two hash slots, 0 and 1.
*/
-bool usrp_set_hash (struct usb_dev_handle *udh, int which,
+bool usrp_set_hash (libusb_device_handle *udh, int which,
const unsigned char hash[USRP_HASH_SIZE]);
/*!
* \brief retrieve the \p hash from the USRP hash slot \p which.
* The usrp implements two hash slots, 0 and 1.
*/
-bool usrp_get_hash (struct usb_dev_handle *udh, int which,
+bool usrp_get_hash (libusb_device_handle *udh, int which,
unsigned char hash[USRP_HASH_SIZE]);
-bool usrp_write_fpga_reg (struct usb_dev_handle *udh, int reg, int value);
-bool usrp_read_fpga_reg (struct usb_dev_handle *udh, int reg, int *value);
-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);
-bool usrp_set_led (struct usb_dev_handle *udh, int which, bool on);
+bool usrp_write_fpga_reg (libusb_device_handle *udh, int reg, int value);
+bool usrp_read_fpga_reg (libusb_device_handle *udh, int reg, int *value);
+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);
+bool usrp_set_led (libusb_device_handle *udh, int which, bool on);
-bool usrp_check_rx_overrun (struct usb_dev_handle *udh, bool *overrun_p);
-bool usrp_check_tx_underrun (struct usb_dev_handle *udh, bool *underrun_p);
+bool usrp_check_rx_overrun (libusb_device_handle *udh, bool *overrun_p);
+bool usrp_check_tx_underrun (libusb_device_handle *udh, bool *underrun_p);
// i2c_read and i2c_write are limited to a maximum len of 64 bytes.
-bool usrp_i2c_write (struct usb_dev_handle *udh, int i2c_addr,
+bool usrp_i2c_write (libusb_device_handle *udh, int i2c_addr,
const void *buf, int len);
-bool usrp_i2c_read (struct usb_dev_handle *udh, int i2c_addr,
+bool usrp_i2c_read (libusb_device_handle *udh, int i2c_addr,
void *buf, int len);
// spi_read and spi_write are limited to a maximum of 64 bytes
// See usrp_spi_defs.h for more info
-bool usrp_spi_write (struct usb_dev_handle *udh,
+bool usrp_spi_write (libusb_device_handle *udh,
int optional_header, int enables, int format,
const void *buf, int len);
-bool usrp_spi_read (struct usb_dev_handle *udh,
+bool usrp_spi_read (libusb_device_handle *udh,
int optional_header, int enables, int format,
void *buf, int len);
-bool usrp_9862_write (struct usb_dev_handle *udh,
+bool usrp_9862_write (libusb_device_handle *udh,
int which_codec, // [0, 1]
int regno, // [0, 63]
int value); // [0, 255]
-bool usrp_9862_read (struct usb_dev_handle *udh,
+bool usrp_9862_read (libusb_device_handle *udh,
int which_codec, // [0, 1]
int regno, // [0, 63]
unsigned char *value); // [0, 255]
@@ -198,28 +202,28 @@ bool usrp_9862_read (struct usb_dev_handle *udh,
* \p buf contains alternating register_number, register_value pairs.
* \p len must be even and is the length of buf in bytes.
*/
-bool usrp_9862_write_many (struct usb_dev_handle *udh, int which_codec,
+bool usrp_9862_write_many (libusb_device_handle *udh, int which_codec,
const unsigned char *buf, int len);
/*!
* \brief write specified regs to all 9862's in the system
*/
-bool usrp_9862_write_many_all (struct usb_dev_handle *udh,
+bool usrp_9862_write_many_all (libusb_device_handle *udh,
const unsigned char *buf, int len);
// Write 24LC024 / 24LC025 EEPROM on motherboard or daughterboard.
// Which EEPROM is determined by i2c_addr. See i2c_addr.h
-bool usrp_eeprom_write (struct usb_dev_handle *udh, int i2c_addr,
+bool usrp_eeprom_write (libusb_device_handle *udh, int i2c_addr,
int eeprom_offset, const void *buf, int len);
// Read 24LC024 / 24LC025 EEPROM on motherboard or daughterboard.
// Which EEPROM is determined by i2c_addr. See i2c_addr.h
-bool usrp_eeprom_read (struct usb_dev_handle *udh, int i2c_addr,
+bool usrp_eeprom_read (libusb_device_handle *udh, int i2c_addr,
int eeprom_offset, void *buf, int len);
@@ -241,7 +245,7 @@ bool usrp_eeprom_read (struct usb_dev_handle *udh, int i2c_addr,
* binary values. Although dacs 0, 1 and 2 are 8-bit and dac 3 is 12-bit,
* the interface is in terms of 12-bit values [0,4095]
*/
-bool usrp_write_aux_dac (struct usb_dev_handle *uhd, int slot,
+bool usrp_write_aux_dac (libusb_device_handle *uhd, int slot,
int which_dac, int value);
/*!
@@ -251,7 +255,7 @@ bool usrp_write_aux_dac (struct usb_dev_handle *uhd, int slot,
* \p which_adc: [0,1] which of the two adcs to read
* \p *value: return value, 12-bit straight binary.
*/
-bool usrp_read_aux_adc (struct usb_dev_handle *udh, int slot,
+bool usrp_read_aux_adc (libusb_device_handle *udh, int slot,
int which_adc, int *value);
@@ -274,13 +278,13 @@ struct usrp_dboard_eeprom {
* \brief Read and return parsed daughterboard eeprom
*/
usrp_dbeeprom_status_t
-usrp_read_dboard_eeprom (struct usb_dev_handle *udh,
+usrp_read_dboard_eeprom (libusb_device_handle *udh,
int slot_id, usrp_dboard_eeprom *eeprom);
/*!
* \brief write ADC/DAC offset calibration constants to d'board eeprom
*/
-bool usrp_write_dboard_offsets (struct usb_dev_handle *udh, int slot_id,
+bool usrp_write_dboard_offsets (libusb_device_handle *udh, int slot_id,
short offset0, short offset1);
/*!
@@ -289,6 +293,6 @@ bool usrp_write_dboard_offsets (struct usb_dev_handle *udh, int slot_id,
* Note that this only works on a configured usrp.
* \returns non-zero length string iff successful.
*/
-std::string usrp_serial_number(struct usb_dev_handle *udh);
+std::string usrp_serial_number(libusb_device_handle *udh);
-#endif /* _USRP_PRIMS_H_ */
+#endif /* INCLUDED_USRP_PRIMS_H */