mirror of https://gerrit.osmocom.org/libusrp
Commonized more usrp_prims code and renamed libusb-0.12 files to libusb0
This commit is contained in:
parent
a3e0f0219d
commit
58d67dd106
|
@ -260,20 +260,26 @@ std::string usrp_serial_number(libusb_device_handle *udh);
|
|||
* Internal functions
|
||||
*/
|
||||
|
||||
libusb_device_handle *usrp_open_interface(libusb_device *dev,
|
||||
int interface,
|
||||
int altinterface);
|
||||
libusb_device_handle *
|
||||
usrp_open_interface(libusb_device *dev, int interface, int altinterface);
|
||||
|
||||
int write_cmd (libusb_device_handle *udh, int request, int value,
|
||||
int index, unsigned char *bytes, int len);
|
||||
int write_cmd (libusb_device_handle *udh, int request, int value, int index,
|
||||
unsigned char *bytes, int len);
|
||||
|
||||
libusb_device_descriptor get_usb_device_descriptor (libusb_device *q);
|
||||
/*
|
||||
* Compatibility functions
|
||||
*/
|
||||
|
||||
libusb_device *get_usb_device (libusb_device_handle *udh);
|
||||
libusb_device *_get_usb_device (libusb_device_handle *udh);
|
||||
|
||||
int usb_control_transfer (struct usb_dev_handle *udh, int request_type,
|
||||
int request, int value, int index,
|
||||
unsigned char *data, int length,
|
||||
unsigned int timeout);
|
||||
libusb_device_descriptor _get_usb_device_descriptor (libusb_device *q);
|
||||
|
||||
int _get_usb_string_descriptor (libusb_device_handle *udh, int index,
|
||||
unsigned char* data, int length);
|
||||
|
||||
int _usb_control_transfer (struct usb_dev_handle *udh, int request_type,
|
||||
int request, int value, int index,
|
||||
unsigned char *data, int length,
|
||||
unsigned int timeout);
|
||||
|
||||
#endif /* _USRP_PRIMS_H_ */
|
||||
|
|
|
@ -75,15 +75,15 @@ darwin_CODE = \
|
|||
win32_CODE = \
|
||||
fusb_win32.cc \
|
||||
fusb_sysconfig_win32.cc \
|
||||
usrp_prims_libusb.cc \
|
||||
usrp_basic_libusb.cc
|
||||
usrp_prims_libusb0.cc \
|
||||
usrp_basic_libusb0.cc
|
||||
|
||||
|
||||
linux_CODE = \
|
||||
fusb_linux.cc \
|
||||
fusb_sysconfig_linux.cc \
|
||||
usrp_prims_libusb.cc \
|
||||
usrp_basic_libusb.cc
|
||||
usrp_prims_libusb0.cc \
|
||||
usrp_basic_libusb0.cc
|
||||
|
||||
ra_wb_CODE = \
|
||||
fusb_ra_wb.cc \
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
#ifndef _FUSB_H_
|
||||
#define _FUSB_H_
|
||||
|
||||
/*
|
||||
* This is bad, but it works for now. The fusb header files are not installed.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
@ -33,7 +37,7 @@
|
|||
struct libusb_device_handle;
|
||||
#else
|
||||
struct usb_dev_handle;
|
||||
typedef struct usb_dev_handle libusb_device_handle;
|
||||
typedef usb_dev_handle libusb_device_handle;
|
||||
#endif
|
||||
|
||||
struct libusb_context;
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
//#ifdef HAVE_CONFIG_H
|
||||
//#include "config.h"
|
||||
//#endif
|
||||
|
||||
#include <fusb_libusb1.h>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
//#ifdef HAVE_CONFIG_H
|
||||
//#include "config.h"
|
||||
//#endif
|
||||
|
||||
#include <fusb_linux.h>
|
||||
#include <usb.h> // libusb header
|
||||
|
|
|
@ -67,7 +67,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";
|
||||
|
||||
|
||||
static char *
|
||||
find_file (const char *filename, int hw_rev)
|
||||
{
|
||||
|
@ -117,7 +116,7 @@ static void power_down_9862s (libusb_device_handle *udh);
|
|||
int
|
||||
usrp_hw_rev (libusb_device *q)
|
||||
{
|
||||
libusb_device_descriptor desc = get_usb_device_descriptor(q);
|
||||
libusb_device_descriptor desc = _get_usb_device_descriptor(q);
|
||||
return desc.bcdDevice & 0x00FF;
|
||||
}
|
||||
|
||||
|
@ -127,14 +126,14 @@ usrp_hw_rev (libusb_device *q)
|
|||
static bool
|
||||
_usrp_configured_p (libusb_device *q)
|
||||
{
|
||||
libusb_device_descriptor desc = get_usb_device_descriptor(q);
|
||||
libusb_device_descriptor desc = _get_usb_device_descriptor(q);
|
||||
return (desc.bcdDevice & 0xFF00) != 0;
|
||||
}
|
||||
|
||||
bool
|
||||
usrp_usrp_p (libusb_device *q)
|
||||
{
|
||||
libusb_device_descriptor desc = get_usb_device_descriptor(q);
|
||||
libusb_device_descriptor desc = _get_usb_device_descriptor(q);
|
||||
return (desc.idVendor == USB_VID_FSF
|
||||
&& desc.idProduct == USB_PID_FSF_USRP);
|
||||
}
|
||||
|
@ -142,7 +141,7 @@ usrp_usrp_p (libusb_device *q)
|
|||
bool
|
||||
usrp_fx2_p (libusb_device *q)
|
||||
{
|
||||
libusb_device_descriptor desc = get_usb_device_descriptor(q);
|
||||
libusb_device_descriptor desc = _get_usb_device_descriptor(q);
|
||||
return (desc.idVendor == USB_VID_CYPRESS
|
||||
&& desc.idProduct == USB_PID_CYPRESS_FX2);
|
||||
}
|
||||
|
@ -218,7 +217,7 @@ write_internal_ram (libusb_device_handle *udh, unsigned char *buf,
|
|||
if (n > quanta)
|
||||
n = quanta;
|
||||
|
||||
a = usb_control_transfer (udh, 0x40, 0xA0, addr, 0,
|
||||
a = _usb_control_transfer (udh, 0x40, 0xA0, addr, 0,
|
||||
(unsigned char*)(buf + (addr - start_addr)), n, 1000);
|
||||
|
||||
if (a < 0){
|
||||
|
@ -424,7 +423,7 @@ usrp_set_hash (libusb_device_handle *udh, int which,
|
|||
which &= 1;
|
||||
|
||||
// we use the Cypress firmware down load command to jam it in.
|
||||
int r = usb_control_transfer (udh, 0x40, 0xa0, hash_slot_addr[which], 0,
|
||||
int r = _usb_control_transfer (udh, 0x40, 0xa0, hash_slot_addr[which], 0,
|
||||
(unsigned char *) hash, USRP_HASH_SIZE, 1000);
|
||||
return r == USRP_HASH_SIZE;
|
||||
}
|
||||
|
@ -436,7 +435,7 @@ usrp_get_hash (libusb_device_handle *udh, int which,
|
|||
which &= 1;
|
||||
|
||||
// we use the Cypress firmware upload command to fetch it.
|
||||
int r = usb_control_transfer (udh, 0xc0, 0xa0, hash_slot_addr[which], 0,
|
||||
int r = _usb_control_transfer (udh, 0xc0, 0xa0, hash_slot_addr[which], 0,
|
||||
(unsigned char *) hash, USRP_HASH_SIZE, 1000);
|
||||
return r == USRP_HASH_SIZE;
|
||||
}
|
||||
|
@ -489,7 +488,7 @@ usrp1_fpga_read (libusb_device_handle *udh,
|
|||
bool
|
||||
usrp_write_fpga_reg (libusb_device_handle *udh, int reg, int value)
|
||||
{
|
||||
switch (usrp_hw_rev (get_usb_device (udh))){
|
||||
switch (usrp_hw_rev (_get_usb_device (udh))){
|
||||
case 0: // not supported ;)
|
||||
abort();
|
||||
|
||||
|
@ -501,7 +500,7 @@ 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)
|
||||
{
|
||||
switch (usrp_hw_rev (get_usb_device (udh))){
|
||||
switch (usrp_hw_rev (_get_usb_device (udh))){
|
||||
case 0: // not supported ;)
|
||||
abort();
|
||||
|
||||
|
@ -935,12 +934,12 @@ static void
|
|||
power_down_9862s (libusb_device_handle *udh)
|
||||
{
|
||||
static const unsigned char regs[] = {
|
||||
REG_RX_PWR_DN, 0x01, // everything
|
||||
REG_TX_PWR_DN, 0x0f, // pwr dn digital and analog_both
|
||||
REG_TX_MODULATOR, 0x00 // coarse & fine modulators disabled
|
||||
REG_RX_PWR_DN, 0x01, // everything
|
||||
REG_TX_PWR_DN, 0x0f, // pwr dn digital and analog_both
|
||||
REG_TX_MODULATOR, 0x00 // coarse & fine modulators disabled
|
||||
};
|
||||
|
||||
switch (usrp_hw_rev (get_usb_device (udh))){
|
||||
switch (usrp_hw_rev (_get_usb_device (udh))){
|
||||
case 0:
|
||||
break;
|
||||
|
||||
|
@ -1214,6 +1213,24 @@ usrp_write_dboard_offsets (libusb_device_handle *udh, int slot_id,
|
|||
0, buf, sizeof (buf));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
std::string
|
||||
usrp_serial_number(libusb_device_handle *udh)
|
||||
{
|
||||
libusb_device_descriptor desc =
|
||||
_get_usb_device_descriptor (_get_usb_device (udh));
|
||||
|
||||
unsigned char iserial = desc.iSerialNumber;
|
||||
if (iserial == 0)
|
||||
return "";
|
||||
|
||||
unsigned char buf[1024];
|
||||
if (_get_usb_string_descriptor (udh, iserial, buf, sizeof(buf)) < 0)
|
||||
return "";
|
||||
|
||||
return (char*) buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -42,27 +42,35 @@ extern "C" {
|
|||
|
||||
using namespace ad9862;
|
||||
|
||||
struct usb_device_descriptor
|
||||
get_usb_device_descriptor (struct usb_device *q)
|
||||
{
|
||||
return q->descriptor;
|
||||
}
|
||||
/*
|
||||
* libusb 0.12 / 1.0 compatibility
|
||||
*/
|
||||
|
||||
struct usb_device *
|
||||
get_usb_device (struct usb_dev_handle *udh)
|
||||
_get_usb_device (struct usb_dev_handle *udh)
|
||||
{
|
||||
return usb_device (udh);
|
||||
}
|
||||
|
||||
struct usb_device_descriptor
|
||||
_get_usb_device_descriptor (struct usb_device *q)
|
||||
{
|
||||
return q->descriptor;
|
||||
}
|
||||
int
|
||||
usb_control_transfer (struct usb_dev_handle *udh, int request_type,
|
||||
_get_usb_string_descriptor (struct usb_dev_handle *udh, int index,
|
||||
unsigned char* data, int length)
|
||||
{
|
||||
return usb_get_string_simple (udh, index, (char*) data, length);
|
||||
}
|
||||
|
||||
int
|
||||
_usb_control_transfer (struct usb_dev_handle *udh, int request_type,
|
||||
int request, int value, int index,
|
||||
unsigned char *data, int length, unsigned int timeout)
|
||||
{
|
||||
return usb_control_msg (udh, request_type,
|
||||
request, value, index,
|
||||
return usb_control_msg (udh, request_type,request, value, index,
|
||||
(char*) data, length, (int) timeout);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -197,20 +205,3 @@ write_cmd (struct usb_dev_handle *udh,
|
|||
return r;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
|
||||
std::string
|
||||
usrp_serial_number(struct usb_dev_handle *udh)
|
||||
{
|
||||
unsigned char iserial = usb_device(udh)->descriptor.iSerialNumber;
|
||||
if (iserial == 0)
|
||||
return "";
|
||||
|
||||
char buf[1024];
|
||||
if (usb_get_string_simple(udh, iserial, buf, sizeof(buf)) < 0)
|
||||
return "";
|
||||
|
||||
return buf;
|
||||
}
|
|
@ -49,9 +49,18 @@ extern "C" {
|
|||
|
||||
using namespace ad9862;
|
||||
|
||||
/*
|
||||
* libusb 0.12 / 1.0 compatibility
|
||||
*/
|
||||
|
||||
struct libusb_device *
|
||||
_get_usb_device (struct libusb_device_handle *udh)
|
||||
{
|
||||
return libusb_get_device (udh);
|
||||
}
|
||||
|
||||
struct libusb_device_descriptor
|
||||
get_usb_device_descriptor(struct libusb_device *q)
|
||||
_get_usb_device_descriptor(struct libusb_device *q)
|
||||
{
|
||||
int ret;
|
||||
struct libusb_device_descriptor desc;
|
||||
|
@ -62,21 +71,20 @@ get_usb_device_descriptor(struct libusb_device *q)
|
|||
return desc;
|
||||
}
|
||||
|
||||
struct libusb_device *
|
||||
get_usb_device (struct libusb_device_handle *udh)
|
||||
int
|
||||
_get_usb_string_descriptor (struct libusb_device_handle *udh, int index,
|
||||
unsigned char* data, int length)
|
||||
{
|
||||
return libusb_get_device (udh);
|
||||
return libusb_get_string_descriptor_ascii (udh, (uint8_t) index, data, length);
|
||||
}
|
||||
|
||||
int
|
||||
usb_control_transfer (struct usb_dev_handle *udh, uint8_t request_type,
|
||||
uint8_t request, uint16_t value, uint16_t index,
|
||||
unsigned char *data, uint16_t length,
|
||||
unsigned int timeout)
|
||||
_usb_control_transfer (struct libusb_dev_handle *udh, int request_type,
|
||||
int request, int value, int index,
|
||||
unsigned char *data, int length, unsigned int timeout)
|
||||
{
|
||||
return libusb_control_transfer (udh, request_type, request, value, index,
|
||||
*data, length, timeout);
|
||||
|
||||
data, length, timeout);
|
||||
}
|
||||
|
||||
|
||||
|
@ -199,23 +207,3 @@ write_cmd (struct libusb_device_handle *udh,
|
|||
return r;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
std::string
|
||||
usrp_serial_number(struct libusb_device_handle *udh)
|
||||
{
|
||||
struct libusb_device_descriptor desc;
|
||||
if (libusb_get_device_descriptor(libusb_get_device(udh), &desc) < 0)
|
||||
fprintf (stderr, "usrp: libusb_get_device_descriptor failed\n");
|
||||
|
||||
unsigned char iserial = desc.iSerialNumber;
|
||||
if (iserial == 0)
|
||||
return "";
|
||||
|
||||
unsigned char buf[1024];
|
||||
if (libusb_get_string_descriptor_ascii(udh, iserial, buf, sizeof(buf)) < 0)
|
||||
return "";
|
||||
|
||||
return (char*) buf;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue