3 * Copyright 2005,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.
23 #ifndef INCLUDED_USRP_PRIMS_H
24 #define INCLUDED_USRP_PRIMS_H
26 #include <usrp/usrp_slots.h>
27 #include <usrp/libusb_types.h>
30 struct libusb_context;
32 static const int USRP_HASH_SIZE = 16;
34 enum usrp_load_status_t { ULS_ERROR = 0, ULS_OK, ULS_ALREADY_LOADED };
37 * \brief initialize libusb; Behavior differs depending on libusb version
41 * Probe busses and devices. The argument is ignored and defaults to NULL.
42 * Safe to call more than once.
46 * If an location to a libusb_context is passed in, create and write in the new
47 * context. If no argument is provided, initialize libusb with the default
50 * Generally _not_ safe to call more than once with non-NULL argument since a
51 * new context will be created each time.
54 void usrp_one_time_init (libusb_context **ctx = NULL);
57 * \brief deinitialize libusb
59 * libusb-0.1: No effect
61 * libusb-1.0: Deinitialize context ctx
63 void usrp_deinit (libusb_context *ctx);
66 * force a rescan of the buses and devices
71 * \brief locate Nth (zero based) USRP device in system.
72 * Return pointer or 0 if not found.
74 * The following kinds of devices are considered USRPs:
76 * unconfigured USRP (no firwmare loaded)
77 * configured USRP (firmware loaded)
78 * unconfigured Cypress FX2 (only if fx2_ok_p is true)
80 libusb_device *usrp_find_device (int nth, bool fx2_ok_p = false, libusb_context *ctx = NULL);
82 bool usrp_usrp_p (libusb_device *q); //< is this a USRP
83 bool usrp_usrp0_p (libusb_device *q); //< is this a USRP Rev 0
84 bool usrp_usrp1_p (libusb_device *q); //< is this a USRP Rev 1
85 bool usrp_usrp2_p (libusb_device *q); //< is this a USRP Rev 2
86 int usrp_hw_rev (libusb_device *q); //< return h/w rev code
88 bool usrp_fx2_p (libusb_device *q); //< is this an unconfigured Cypress FX2
90 bool usrp_unconfigured_usrp_p (libusb_device *q); //< some kind of unconfigured USRP
91 bool usrp_configured_usrp_p (libusb_device *q); //< some kind of configured USRP
94 * \brief given a libusb_device return an instance of the appropriate libusb_device_handle
96 * These routines claim the specified interface and select the
97 * correct alternate interface. (USB nomenclature is totally screwed!)
99 * If interface can't be opened, or is already claimed by some other
100 * process, 0 is returned.
102 libusb_device_handle *usrp_open_cmd_interface (libusb_device *dev);
103 libusb_device_handle *usrp_open_rx_interface (libusb_device *dev);
104 libusb_device_handle *usrp_open_tx_interface (libusb_device *dev);
107 * \brief close interface.
109 bool usrp_close_interface (libusb_device_handle *udh);
112 * \brief load intel hex format file into USRP/Cypress FX2 (8051).
114 * The filename extension is typically *.ihx
116 * Note that loading firmware may cause the device to renumerate. I.e.,
117 * change its configuration, invalidating the current device handle.
121 usrp_load_firmware (libusb_device_handle *udh, const char *filename, bool force);
124 * \brief load intel hex format file into USRP FX2 (8051).
126 * The filename extension is typically *.ihx
128 * Note that loading firmware may cause the device to renumerate. I.e.,
129 * change its configuration, invalidating the current device handle.
130 * If the result is ULS_OK, usrp_load_firmware_nth delays 1 second
131 * then rescans the busses and devices.
134 usrp_load_firmware_nth (int nth, const char *filename, bool force, libusb_context *ctx = NULL);
137 * \brief load fpga configuration bitstream
140 usrp_load_fpga (libusb_device_handle *udh, const char *filename, bool force);
143 * \brief load the regular firmware and fpga bitstream in the Nth USRP.
145 * This is the normal starting point...
147 bool usrp_load_standard_bits (int nth, bool force,
148 const std::string fpga_filename = "",
149 const std::string firmware_filename = "",
150 libusb_context *ctx = NULL);
153 * \brief copy the given \p hash into the USRP hash slot \p which.
154 * The usrp implements two hash slots, 0 and 1.
156 bool usrp_set_hash (libusb_device_handle *udh, int which,
157 const unsigned char hash[USRP_HASH_SIZE]);
160 * \brief retrieve the \p hash from the USRP hash slot \p which.
161 * The usrp implements two hash slots, 0 and 1.
163 bool usrp_get_hash (libusb_device_handle *udh, int which,
164 unsigned char hash[USRP_HASH_SIZE]);
166 bool usrp_write_fpga_reg (libusb_device_handle *udh, int reg, int value);
167 bool usrp_read_fpga_reg (libusb_device_handle *udh, int reg, int *value);
168 bool usrp_set_fpga_reset (libusb_device_handle *udh, bool on);
169 bool usrp_set_fpga_tx_enable (libusb_device_handle *udh, bool on);
170 bool usrp_set_fpga_rx_enable (libusb_device_handle *udh, bool on);
171 bool usrp_set_fpga_tx_reset (libusb_device_handle *udh, bool on);
172 bool usrp_set_fpga_rx_reset (libusb_device_handle *udh, bool on);
173 bool usrp_set_led (libusb_device_handle *udh, int which, bool on);
175 bool usrp_check_rx_overrun (libusb_device_handle *udh, bool *overrun_p);
176 bool usrp_check_tx_underrun (libusb_device_handle *udh, bool *underrun_p);
178 // i2c_read and i2c_write are limited to a maximum len of 64 bytes.
180 bool usrp_i2c_write (libusb_device_handle *udh, int i2c_addr,
181 const void *buf, int len);
183 bool usrp_i2c_read (libusb_device_handle *udh, int i2c_addr,
186 // spi_read and spi_write are limited to a maximum of 64 bytes
187 // See usrp_spi_defs.h for more info
189 bool usrp_spi_write (libusb_device_handle *udh,
190 int optional_header, int enables, int format,
191 const void *buf, int len);
193 bool usrp_spi_read (libusb_device_handle *udh,
194 int optional_header, int enables, int format,
198 bool usrp_9862_write (libusb_device_handle *udh,
199 int which_codec, // [0, 1]
200 int regno, // [0, 63]
201 int value); // [0, 255]
203 bool usrp_9862_read (libusb_device_handle *udh,
204 int which_codec, // [0, 1]
205 int regno, // [0, 63]
206 unsigned char *value); // [0, 255]
209 * \brief Write multiple 9862 regs at once.
211 * \p buf contains alternating register_number, register_value pairs.
212 * \p len must be even and is the length of buf in bytes.
214 bool usrp_9862_write_many (libusb_device_handle *udh, int which_codec,
215 const unsigned char *buf, int len);
219 * \brief write specified regs to all 9862's in the system
221 bool usrp_9862_write_many_all (libusb_device_handle *udh,
222 const unsigned char *buf, int len);
225 // Write 24LC024 / 24LC025 EEPROM on motherboard or daughterboard.
226 // Which EEPROM is determined by i2c_addr. See i2c_addr.h
228 bool usrp_eeprom_write (libusb_device_handle *udh, int i2c_addr,
229 int eeprom_offset, const void *buf, int len);
232 // Read 24LC024 / 24LC025 EEPROM on motherboard or daughterboard.
233 // Which EEPROM is determined by i2c_addr. See i2c_addr.h
235 bool usrp_eeprom_read (libusb_device_handle *udh, int i2c_addr,
236 int eeprom_offset, void *buf, int len);
239 // Slot specific i/o routines
242 * \brief write to the specified aux dac.
244 * \p slot: which Tx or Rx slot to write.
245 * N.B., SLOT_TX_A and SLOT_RX_A share the same AUX DAC's
246 * SLOT_TX_B and SLOT_RX_B share the same AUX DAC's
248 * \p which_dac: [0,3] RX slots must use only 0 and 1.
249 * TX slots must use only 2 and 3.
251 * AUX DAC 3 is really the 9862 sigma delta output.
253 * \p value to write to aux dac. All dacs take straight
254 * binary values. Although dacs 0, 1 and 2 are 8-bit and dac 3 is 12-bit,
255 * the interface is in terms of 12-bit values [0,4095]
257 bool usrp_write_aux_dac (libusb_device_handle *uhd, int slot,
258 int which_dac, int value);
261 * \brief Read the specified aux adc
263 * \p slot: which Tx or Rx slot to read aux dac
264 * \p which_adc: [0,1] which of the two adcs to read
265 * \p *value: return value, 12-bit straight binary.
267 bool usrp_read_aux_adc (libusb_device_handle *udh, int slot,
268 int which_adc, int *value);
272 * \brief usrp daughterboard id to name mapping
274 const std::string usrp_dbid_to_string (int dbid);
277 enum usrp_dbeeprom_status_t { UDBE_OK, UDBE_BAD_SLOT, UDBE_NO_EEPROM, UDBE_INVALID_EEPROM };
279 struct usrp_dboard_eeprom {
280 unsigned short id; // d'board identifier code
281 unsigned short oe; // fpga output enables:
282 // If bit set, i/o pin is an output from FPGA.
283 short offset[2]; // ADC/DAC offset correction
287 * \brief Read and return parsed daughterboard eeprom
289 usrp_dbeeprom_status_t
290 usrp_read_dboard_eeprom (libusb_device_handle *udh,
291 int slot_id, usrp_dboard_eeprom *eeprom);
294 * \brief write ADC/DAC offset calibration constants to d'board eeprom
296 bool usrp_write_dboard_offsets (libusb_device_handle *udh, int slot_id,
297 short offset0, short offset1);
300 * \brief return a usrp's serial number.
302 * Note that this only works on a configured usrp.
303 * \returns non-zero length string iff successful.
305 std::string usrp_serial_number(libusb_device_handle *udh);
307 #endif /* INCLUDED_USRP_PRIMS_H */