Universal Software Radio Peripheral
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2005,2009 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef INCLUDED_USRP_PRIMS_H 00024 #define INCLUDED_USRP_PRIMS_H 00025 00026 #include <usrp/usrp_slots.h> 00027 #include <usrp/libusb_types.h> 00028 #include <string> 00029 00030 struct libusb_context; 00031 00032 static const int USRP_HASH_SIZE = 16; 00033 00034 enum usrp_load_status_t { ULS_ERROR = 0, ULS_OK, ULS_ALREADY_LOADED }; 00035 00054 void usrp_one_time_init (libusb_context **ctx = NULL); 00055 00063 void usrp_deinit (libusb_context *ctx); 00064 00065 /* 00066 * force a rescan of the buses and devices 00067 */ 00068 void usrp_rescan (); 00069 00080 libusb_device *usrp_find_device (int nth, bool fx2_ok_p = false, libusb_context *ctx = NULL); 00081 00082 bool usrp_usrp_p (libusb_device *q); //< is this a USRP 00083 bool usrp_usrp0_p (libusb_device *q); //< is this a USRP Rev 0 00084 bool usrp_usrp1_p (libusb_device *q); //< is this a USRP Rev 1 00085 bool usrp_usrp2_p (libusb_device *q); //< is this a USRP Rev 2 00086 int usrp_hw_rev (libusb_device *q); //< return h/w rev code 00087 00088 bool usrp_fx2_p (libusb_device *q); //< is this an unconfigured Cypress FX2 00089 00090 bool usrp_unconfigured_usrp_p (libusb_device *q); //< some kind of unconfigured USRP 00091 bool usrp_configured_usrp_p (libusb_device *q); //< some kind of configured USRP 00092 00102 libusb_device_handle *usrp_open_cmd_interface (libusb_device *dev); 00103 libusb_device_handle *usrp_open_rx_interface (libusb_device *dev); 00104 libusb_device_handle *usrp_open_tx_interface (libusb_device *dev); 00105 00109 bool usrp_close_interface (libusb_device_handle *udh); 00110 00120 usrp_load_status_t 00121 usrp_load_firmware (libusb_device_handle *udh, const char *filename, bool force); 00122 00133 usrp_load_status_t 00134 usrp_load_firmware_nth (int nth, const char *filename, bool force, libusb_context *ctx = NULL); 00135 00139 usrp_load_status_t 00140 usrp_load_fpga (libusb_device_handle *udh, const char *filename, bool force); 00141 00147 bool usrp_load_standard_bits (int nth, bool force, 00148 const std::string fpga_filename = "", 00149 const std::string firmware_filename = "", 00150 libusb_context *ctx = NULL); 00151 00156 bool usrp_set_hash (libusb_device_handle *udh, int which, 00157 const unsigned char hash[USRP_HASH_SIZE]); 00158 00163 bool usrp_get_hash (libusb_device_handle *udh, int which, 00164 unsigned char hash[USRP_HASH_SIZE]); 00165 00166 bool usrp_write_fpga_reg (libusb_device_handle *udh, int reg, int value); 00167 bool usrp_read_fpga_reg (libusb_device_handle *udh, int reg, int *value); 00168 bool usrp_set_fpga_reset (libusb_device_handle *udh, bool on); 00169 bool usrp_set_fpga_tx_enable (libusb_device_handle *udh, bool on); 00170 bool usrp_set_fpga_rx_enable (libusb_device_handle *udh, bool on); 00171 bool usrp_set_fpga_tx_reset (libusb_device_handle *udh, bool on); 00172 bool usrp_set_fpga_rx_reset (libusb_device_handle *udh, bool on); 00173 bool usrp_set_led (libusb_device_handle *udh, int which, bool on); 00174 00175 bool usrp_check_rx_overrun (libusb_device_handle *udh, bool *overrun_p); 00176 bool usrp_check_tx_underrun (libusb_device_handle *udh, bool *underrun_p); 00177 00178 // i2c_read and i2c_write are limited to a maximum len of 64 bytes. 00179 00180 bool usrp_i2c_write (libusb_device_handle *udh, int i2c_addr, 00181 const void *buf, int len); 00182 00183 bool usrp_i2c_read (libusb_device_handle *udh, int i2c_addr, 00184 void *buf, int len); 00185 00186 // spi_read and spi_write are limited to a maximum of 64 bytes 00187 // See usrp_spi_defs.h for more info 00188 00189 bool usrp_spi_write (libusb_device_handle *udh, 00190 int optional_header, int enables, int format, 00191 const void *buf, int len); 00192 00193 bool usrp_spi_read (libusb_device_handle *udh, 00194 int optional_header, int enables, int format, 00195 void *buf, int len); 00196 00197 00198 bool usrp_9862_write (libusb_device_handle *udh, 00199 int which_codec, // [0, 1] 00200 int regno, // [0, 63] 00201 int value); // [0, 255] 00202 00203 bool usrp_9862_read (libusb_device_handle *udh, 00204 int which_codec, // [0, 1] 00205 int regno, // [0, 63] 00206 unsigned char *value); // [0, 255] 00207 00214 bool usrp_9862_write_many (libusb_device_handle *udh, int which_codec, 00215 const unsigned char *buf, int len); 00216 00217 00221 bool usrp_9862_write_many_all (libusb_device_handle *udh, 00222 const unsigned char *buf, int len); 00223 00224 00225 // Write 24LC024 / 24LC025 EEPROM on motherboard or daughterboard. 00226 // Which EEPROM is determined by i2c_addr. See i2c_addr.h 00227 00228 bool usrp_eeprom_write (libusb_device_handle *udh, int i2c_addr, 00229 int eeprom_offset, const void *buf, int len); 00230 00231 00232 // Read 24LC024 / 24LC025 EEPROM on motherboard or daughterboard. 00233 // Which EEPROM is determined by i2c_addr. See i2c_addr.h 00234 00235 bool usrp_eeprom_read (libusb_device_handle *udh, int i2c_addr, 00236 int eeprom_offset, void *buf, int len); 00237 00238 00239 // Slot specific i/o routines 00240 00257 bool usrp_write_aux_dac (libusb_device_handle *uhd, int slot, 00258 int which_dac, int value); 00259 00267 bool usrp_read_aux_adc (libusb_device_handle *udh, int slot, 00268 int which_adc, int *value); 00269 00270 00274 const std::string usrp_dbid_to_string (int dbid); 00275 00276 00277 enum usrp_dbeeprom_status_t { UDBE_OK, UDBE_BAD_SLOT, UDBE_NO_EEPROM, UDBE_INVALID_EEPROM }; 00278 00279 struct usrp_dboard_eeprom { 00280 unsigned short id; // d'board identifier code 00281 unsigned short oe; // fpga output enables: 00282 // If bit set, i/o pin is an output from FPGA. 00283 short offset[2]; // ADC/DAC offset correction 00284 }; 00285 00289 usrp_dbeeprom_status_t 00290 usrp_read_dboard_eeprom (libusb_device_handle *udh, 00291 int slot_id, usrp_dboard_eeprom *eeprom); 00292 00296 bool usrp_write_dboard_offsets (libusb_device_handle *udh, int slot_id, 00297 short offset0, short offset1); 00298 00305 std::string usrp_serial_number(libusb_device_handle *udh); 00306 00307 #endif /* INCLUDED_USRP_PRIMS_H */