3 * Copyright 2003,2004,2009 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/usrp_prims.h>
43 enum usrp_load_status_t { ULS_ERROR = 0, ULS_OK, ULS_ALREADY_LOADED };
47 * \brief initialize libusb; probe busses and devices.
48 * Safe to call more than once.
50 void usrp_one_time_init (libusb_context **ctx = NULL);
55 * \brief locate Nth (zero based) USRP device in system.
56 * Return pointer or 0 if not found.
58 * The following kinds of devices are considered USRPs:
60 * unconfigured USRP (no firwmare loaded)
61 * configured USRP (firmware loaded)
62 * unconfigured Cypress FX2 (only if fx2_ok_p is true)
64 libusb_device *usrp_find_device (int nth, bool fx2_ok_p = false, libusb_context *ctx);
66 bool usrp_usrp_p (libusb_device *q); //< is this a USRP
67 bool usrp_usrp0_p (libusb_device *q); //< is this a USRP Rev 0
68 bool usrp_usrp1_p (libusb_device *q); //< is this a USRP Rev 1
69 bool usrp_usrp2_p (libusb_device *q); //< is this a USRP Rev 2
70 int usrp_hw_rev (libusb_device *q); //< return h/w rev code
71 bool usrp_fx2_p (libusb_device *q); //< is this an unconfigured Cypress FX2
73 bool usrp_unconfigured_usrp_p (libusb_device *q); //< some kind of unconfigured USRP
74 bool usrp_configured_usrp_p (libusb_device *q); //< some kind of configured USRP
77 * \brief given a libusb_device return an instance of the appropriate libusb_device_handle
79 * These routines claim the specified interface and select the
80 * correct alternate interface. (USB nomenclature is totally screwed!)
82 * If interface can't be opened, or is already claimed by some other
83 * process, 0 is returned.
85 libusb_device_handle *usrp_open_cmd_interface (libusb_device *dev);
86 libusb_device_handle *usrp_open_rx_interface (libusb_device *dev);
87 libusb_device_handle *usrp_open_tx_interface (libusb_device *dev);
90 * \brief close interface.
92 bool usrp_close_interface (libusb_device_handle *udh);
95 * \brief load intel hex format file into USRP/Cypress FX2 (8051).
97 * The filename extension is typically *.ihx
99 * Note that loading firmware may cause the device to renumerate. I.e.,
100 * change its configuration, invalidating the current device handle.
104 usrp_load_firmware (libusb_device_handle *udh, const char *filename, bool force);
107 * \brief load intel hex format file into USRP FX2 (8051).
109 * The filename extension is typically *.ihx
111 * Note that loading firmware may cause the device to renumerate. I.e.,
112 * change its configuration, invalidating the current device handle.
113 * If the result is ULS_OK, usrp_load_firmware_nth delays 1 second
114 * then rescans the busses and devices.
117 usrp_load_firmware_nth (int nth, const char *filename, bool force, libusb_context *ctx);
120 * \brief load fpga configuration bitstream
123 usrp_load_fpga (libusb_device_handle *udh, const char *filename, bool force);
126 * \brief load the regular firmware and fpga bitstream in the Nth USRP.
128 * This is the normal starting point...
130 bool usrp_load_standard_bits (int nth, bool force);
133 %include <fpga_regs_common.h>
134 %include <fpga_regs_standard.h>
137 bool usrp_write_fpga_reg (libusb_device_handle *udh, int reg, int value);
142 usrp_read_fpga_reg (libusb_device_handle *udh, int reg)
145 bool ok = usrp_read_fpga_reg (udh, reg, &value);
154 bool usrp_set_fpga_reset (libusb_device_handle *udh, bool on);
155 bool usrp_set_fpga_tx_enable (libusb_device_handle *udh, bool on);
156 bool usrp_set_fpga_rx_enable (libusb_device_handle *udh, bool on);
157 bool usrp_set_fpga_tx_reset (libusb_device_handle *udh, bool on);
158 bool usrp_set_fpga_rx_reset (libusb_device_handle *udh, bool on);
159 bool usrp_set_led (libusb_device_handle *udh, int which, bool on);
161 bool usrp_check_rx_overrun (libusb_device_handle *udh, bool *overrun_p);
162 bool usrp_check_tx_underrun (libusb_device_handle *udh, bool *underrun_p);
164 // i2c_read and i2c_write are limited to a maximum len of 64 bytes.
166 bool usrp_i2c_write (libusb_device_handle *udh, int i2c_addr,
169 bool usrp_i2c_read (libusb_device_handle *udh, int i2c_addr,
172 // spi_read and spi_write are limited to a maximum of 64 bytes
173 // See usrp_spi_defs.h for more info
175 bool usrp_spi_write (libusb_device_handle *udh,
176 int optional_header, int enables, int format,
177 unsigned char *buf, int len);
179 bool usrp_spi_read (libusb_device_handle *udh,
180 int optional_header, int enables, int format,
181 unsigned char *buf, int len);
184 bool usrp_9862_write (libusb_device_handle *udh,
185 int which_codec, // [0, 1]
186 int regno, // [0, 63]
187 int value); // [0, 255]
192 usrp_9862_read (libusb_device_handle *udh, int which_codec, int reg)
195 bool ok = usrp_9862_read (udh, which_codec, reg, &value);
207 usrp_eeprom_write (libusb_device_handle *udh, int i2c_addr,
208 int eeprom_offset, const std::string buf)
210 return usrp_eeprom_write (udh, i2c_addr, eeprom_offset,
211 buf.data (), buf.size ());
215 usrp_eeprom_read (libusb_device_handle *udh, int i2c_addr,
216 int eeprom_offset, int len)
223 if (!usrp_eeprom_read (udh, i2c_addr, eeprom_offset, buf, len))
226 return std::string (buf, len);
231 bool usrp_write_aux_dac (libusb_device_handle *uhd, int slot,
232 int which_dac, int value);
236 int usrp_read_aux_adc (libusb_device_handle *udh, int slot, int which_adc)
239 bool ok = usrp_read_aux_adc (udh, slot, which_adc, &value);
249 * \brief return a usrp's serial number.
251 * Note that this only works on a configured usrp.
252 * \returns non-zero length string iff successful.
254 std::string usrp_serial_number(libusb_device_handle *udh);
257 * \brief usrp daughterboard id to name mapping
259 const std::string usrp_dbid_to_string (int dbid);
262 #include "../../firmware/include/fpga_regs_common.h"
263 #include "../../firmware/include/fpga_regs_standard.h"