3 * Copyright 2003,2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
24 * Low level primitives for directly messing with USRP hardware.
26 * If you're trying to use the USRP, you'll probably want to take a
27 * look at the usrp_standard_rx and usrp_standard_tx classes. They
28 * hide a bunch of low level details and provide high performance
31 * This interface is built on top of libusb, which allegedly works under
32 * Linux, *BSD and Mac OS/X. http://libusb.sourceforge.net
35 %include <stl.i> // pick up string stuff
39 #include <usrp_prims.h>
43 enum usrp_load_status_t { ULS_ERROR = 0, ULS_OK, ULS_ALREADY_LOADED };
45 struct usb_dev_handle;
49 * \brief initialize libusb; probe busses and devices.
50 * Safe to call more than once.
52 void usrp_one_time_init ();
57 * \brief locate Nth (zero based) USRP device in system.
58 * Return pointer or 0 if not found.
60 * The following kinds of devices are considered USRPs:
62 * unconfigured USRP (no firwmare loaded)
63 * configured USRP (firmware loaded)
64 * unconfigured Cypress FX2 (only if fx2_ok_p is true)
66 struct usb_device *usrp_find_device (int nth, bool fx2_ok_p = false);
68 bool usrp_usrp_p (struct usb_device *q); //< is this a USRP
69 bool usrp_usrp0_p (struct usb_device *q); //< is this a USRP Rev 0
70 bool usrp_usrp1_p (struct usb_device *q); //< is this a USRP Rev 1
71 bool usrp_usrp2_p (struct usb_device *q); //< is this a USRP Rev 2
72 int usrp_hw_rev (struct usb_device *q); //< return h/w rev code
73 bool usrp_fx2_p (struct usb_device *q); //< is this an unconfigured Cypress FX2
75 bool usrp_unconfigured_usrp_p (struct usb_device *q); //< some kind of unconfigured USRP
76 bool usrp_configured_usrp_p (struct usb_device *q); //< some kind of configured USRP
79 * \brief given a usb_device return an instance of the appropriate usb_dev_handle
81 * These routines claim the specified interface and select the
82 * correct alternate interface. (USB nomenclature is totally screwed!)
84 * If interface can't be opened, or is already claimed by some other
85 * process, 0 is returned.
87 struct usb_dev_handle *usrp_open_cmd_interface (struct usb_device *dev);
88 struct usb_dev_handle *usrp_open_rx_interface (struct usb_device *dev);
89 struct usb_dev_handle *usrp_open_tx_interface (struct usb_device *dev);
92 * \brief close interface.
94 bool usrp_close_interface (struct usb_dev_handle *udh);
97 * \brief load intel hex format file into USRP/Cypress FX2 (8051).
99 * The filename extension is typically *.ihx
101 * Note that loading firmware may cause the device to renumerate. I.e.,
102 * change its configuration, invalidating the current device handle.
106 usrp_load_firmware (struct usb_dev_handle *udh, const char *filename, bool force);
109 * \brief load intel hex format file into USRP FX2 (8051).
111 * The filename extension is typically *.ihx
113 * Note that loading firmware may cause the device to renumerate. I.e.,
114 * change its configuration, invalidating the current device handle.
115 * If the result is ULS_OK, usrp_load_firmware_nth delays 1 second
116 * then rescans the busses and devices.
119 usrp_load_firmware_nth (int nth, const char *filename, bool force);
122 * \brief load fpga configuration bitstream
125 usrp_load_fpga (struct usb_dev_handle *udh, const char *filename, bool force);
128 * \brief load the regular firmware and fpga bitstream in the Nth USRP.
130 * This is the normal starting point...
132 bool usrp_load_standard_bits (int nth, bool force);
135 %include <fpga_regs_common.h>
136 %include <fpga_regs_standard.h>
139 bool usrp_write_fpga_reg (struct usb_dev_handle *udh, int reg, int value);
144 usrp_read_fpga_reg (struct usb_dev_handle *udh, int reg)
147 bool ok = usrp_read_fpga_reg (udh, reg, &value);
156 bool usrp_set_fpga_reset (struct usb_dev_handle *udh, bool on);
157 bool usrp_set_fpga_tx_enable (struct usb_dev_handle *udh, bool on);
158 bool usrp_set_fpga_rx_enable (struct usb_dev_handle *udh, bool on);
159 bool usrp_set_fpga_tx_reset (struct usb_dev_handle *udh, bool on);
160 bool usrp_set_fpga_rx_reset (struct usb_dev_handle *udh, bool on);
161 bool usrp_set_led (struct usb_dev_handle *udh, int which, bool on);
163 bool usrp_check_rx_overrun (struct usb_dev_handle *udh, bool *overrun_p);
164 bool usrp_check_tx_underrun (struct usb_dev_handle *udh, bool *underrun_p);
166 // i2c_read and i2c_write are limited to a maximum len of 64 bytes.
168 bool usrp_i2c_write (struct usb_dev_handle *udh, int i2c_addr,
171 bool usrp_i2c_read (struct usb_dev_handle *udh, int i2c_addr,
174 // spi_read and spi_write are limited to a maximum of 64 bytes
175 // See usrp_spi_defs.h for more info
177 bool usrp_spi_write (struct usb_dev_handle *udh,
178 int optional_header, int enables, int format,
179 unsigned char *buf, int len);
181 bool usrp_spi_read (struct usb_dev_handle *udh,
182 int optional_header, int enables, int format,
183 unsigned char *buf, int len);
186 bool usrp_9862_write (struct usb_dev_handle *udh,
187 int which_codec, // [0, 1]
188 int regno, // [0, 63]
189 int value); // [0, 255]
194 usrp_9862_read (struct usb_dev_handle *udh, int which_codec, int reg)
197 bool ok = usrp_9862_read (udh, which_codec, reg, &value);
209 usrp_eeprom_write (struct usb_dev_handle *udh, int i2c_addr,
210 int eeprom_offset, const std::string buf)
212 return usrp_eeprom_write (udh, i2c_addr, eeprom_offset,
213 buf.data (), buf.size ());
217 usrp_eeprom_read (struct usb_dev_handle *udh, int i2c_addr,
218 int eeprom_offset, int len)
225 if (!usrp_eeprom_read (udh, i2c_addr, eeprom_offset, buf, len))
228 return std::string (buf, len);
233 bool usrp_write_aux_dac (struct usb_dev_handle *uhd, int slot,
234 int which_dac, int value);
238 int usrp_read_aux_adc (struct usb_dev_handle *udh, int slot, int which_adc)
241 bool ok = usrp_read_aux_adc (udh, slot, which_adc, &value);
251 * \brief return a usrp's serial number.
253 * Note that this only works on a configured usrp.
254 * \returns non-zero length string iff successful.
256 std::string usrp_serial_number(struct usb_dev_handle *udh);
259 * \brief usrp daughterboard id to name mapping
261 const std::string usrp_dbid_to_string (int dbid);
264 #include "../../firmware/include/fpga_regs_common.h"
265 #include "../../firmware/include/fpga_regs_standard.h"