Changeset 9546

Show
Ignore:
Timestamp:
09/14/09 01:22:02 (4 years ago)
Author:
ttsou
Message:

win32 support, combined more usrp_prims code, bug fixes

Location:
ossiedev/branches/ttsou/gnuradio/trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/branches/ttsou/gnuradio/trunk/config/usrp_libusb.m4

    r9545 r9546  
    109109          echo 'struct usb_device;'>> $tmpfile 
    110110          echo 'struct usb_dev_handle;'>> $tmpfile 
    111           echo 'typedef struct usb_device libusb_device;' >> $tmpfile 
    112           echo 'typedef struct usb_dev_handle libusb_device_handle;' >> $tmpfile 
     111          echo 'struct usb_device_descriptor;' >> $tmpfile 
     112          echo 'typedef usb_device libusb_device;' >> $tmpfile 
     113          echo 'typedef usb_dev_handle libusb_device_handle;' >> $tmpfile 
     114          echo 'typedef usb_device_descriptor libusb_device_descriptor;' >> $tmpfile 
    113115          echo >> $tmpfile 
    114116        fi 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/fusb.cc

    r9501 r9546  
    2121 */ 
    2222 
    23 #ifdef HAVE_CONFIG_H 
    24 #include "config.h" 
    25 #endif 
     23//#ifdef HAVE_CONFIG_H 
     24//#include "config.h" 
     25//#endif 
    2626 
    2727#include <fusb.h> 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/fusb.h

    r9543 r9546  
    6666   
    6767  // ACCESSORS 
    68   libusb_device_handle *get_libusb_device_handle () const { return d_udh; } 
     68  libusb_device_handle *get_usb_dev_handle () const { return d_udh; } 
    6969}; 
    7070 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/fusb_sysconfig_linux.cc

    r9543 r9546  
    3131fusb_sysconfig::make_devhandle (usb_dev_handle *udh, libusb_context *ctx) 
    3232{ 
    33   make_devhandle (udh);  
     33  return new fusb_devhandle_linux (udh);  
    3434} 
    3535 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/fusb_sysconfig_win32.cc

    r9501 r9546  
    2828         
    2929fusb_devhandle * 
    30 fusb_sysconfig::make_devhandle (usb_dev_handle *udh) 
     30fusb_sysconfig::make_devhandle (usb_dev_handle *udh, libusb_context *ctx) 
    3131{ 
    3232  return new fusb_devhandle_win32 (udh); 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/fusb_win32.cc

    r9501 r9546  
    2121 */ 
    2222 
    23 #ifdef HAVE_CONFIG_H 
    24 #include "config.h" 
    25 #endif 
     23//#ifdef HAVE_CONFIG_H 
     24//#include "config.h" 
     25//#endif 
    2626 
    2727#include <fusb_win32.h> 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/usrp_basic_common.cc

    r9539 r9546  
    2121 */ 
    2222 
    23 #ifdef HAVE_CONFIG_H 
    24 #include "config.h" 
    25 #endif 
     23//#ifdef HAVE_CONFIG_H 
     24//#include "config.h" 
     25//#endif 
    2626 
    2727#include "usrp/usrp_basic.h" 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/usrp_basic_libusb.cc

    r9539 r9546  
    2121 */ 
    2222 
    23 #ifdef HAVE_CONFIG_H 
    24 #include "config.h" 
    25 #endif 
     23//#ifdef HAVE_CONFIG_H 
     24//#include "config.h" 
     25//#endif 
    2626 
    2727#include <usrp/usrp_basic.h> 
     
    4444#define NELEM(x) (sizeof (x) / sizeof (x[0])) 
    4545 
    46 // These set the buffer size used for each end point using the fast 
    47 // usb interface.  The kernel ends up locking down this much memory. 
    48  
    49 static const int FUSB_BUFFER_SIZE = fusb_sysconfig::default_buffer_size(); 
    50 static const int FUSB_BLOCK_SIZE = fusb_sysconfig::max_block_size(); 
    51 static const int FUSB_NBLOCKS    = FUSB_BUFFER_SIZE / FUSB_BLOCK_SIZE; 
    52  
    5346 
    5447static const double POLLING_INTERVAL = 0.1;     // seconds 
     
    6659//   CLKSEL pin = high  
    6760// 
    68 // These settings give us: 
    6961//   CLKOUT1 = CLKIN = 64 MHz 
    7062//   CLKOUT2 = CLKIN = 64 MHz 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/usrp_basic_libusb1.cc

    r9539 r9546  
    4444 
    4545#define NELEM(x) (sizeof (x) / sizeof (x[0])) 
    46  
    47 // These set the buffer size used for each end point using the fast 
    48 // usb interface.  The kernel ends up locking down this much memory. 
    49  
    50 static const int FUSB_BUFFER_SIZE = fusb_sysconfig::default_buffer_size(); 
    51 static const int FUSB_BLOCK_SIZE = fusb_sysconfig::max_block_size(); 
    52 static const int FUSB_NBLOCKS    = FUSB_BUFFER_SIZE / FUSB_BLOCK_SIZE; 
    5346 
    5447 
     
    10497  memset (d_fpga_shadows, 0, sizeof (d_fpga_shadows)); 
    10598 
    106 //  d_ctx = usrp_one_time_init(true); 
    10799  usrp_one_time_init (&d_ctx); 
    108100 
     
    145137    libusb_close (d_udh); 
    146138 
    147   // Each object should be running in it's own context. If running in default 
    148   // context then leave the instance open as it may be shared. This might 
    149   // occur in mixed libusb-0.12 and libusb-1.0 environments.   
     139  // Each object _should_ be running in its own context. If running in default 
     140  // context then leave the instance open as it may be shared. 
    150141 
    151142  if (d_ctx != NULL) 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/usrp_prims_common.cc

    r9542 r9546  
    4141#include <ad9862.h> 
    4242#include <assert.h> 
     43#include "std_paths.h" 
    4344 
    4445#ifdef HAVE_LIBUSB_1  
     
    6869 
    6970 
    70 #include "std_paths.h" 
    71 #include <stdio.h> 
    72  
    7371static char * 
    7472find_file (const char *filename, int hw_rev) 
     
    108106 
    109107 
    110 void power_down_9862s (libusb_device_handle *udh); 
     108static void power_down_9862s (libusb_device_handle *udh); 
     109 
    111110 
    112111// ---------------------------------------------------------------- 
    113112 
     113/* 
     114 * q must be a real USRP, not an FX2.  Return its hardware rev number. 
     115 */ 
     116 
     117int 
     118usrp_hw_rev (libusb_device *q) 
     119{ 
     120  libusb_device_descriptor desc = get_usb_device_descriptor(q); 
     121  return desc.bcdDevice & 0x00FF; 
     122} 
     123 
     124/* 
     125 * q must be a real USRP, not an FX2.  Return true if it's configured. 
     126 */ 
     127static bool 
     128_usrp_configured_p (libusb_device *q) 
     129{ 
     130  libusb_device_descriptor desc = get_usb_device_descriptor(q); 
     131  return (desc.bcdDevice & 0xFF00) != 0; 
     132} 
     133 
     134bool 
     135usrp_usrp_p (libusb_device *q) 
     136{ 
     137  libusb_device_descriptor desc = get_usb_device_descriptor(q); 
     138  return (desc.idVendor == USB_VID_FSF 
     139          && desc.idProduct == USB_PID_FSF_USRP); 
     140} 
     141 
     142bool 
     143usrp_fx2_p (libusb_device *q) 
     144{ 
     145  libusb_device_descriptor desc = get_usb_device_descriptor(q); 
     146  return (desc.idVendor == USB_VID_CYPRESS 
     147          && desc.idProduct == USB_PID_CYPRESS_FX2); 
     148} 
     149 
    114150bool 
    115151usrp_usrp0_p (libusb_device *q) 
     
    142178  return usrp_usrp_p (q) && _usrp_configured_p (q); 
    143179} 
     180 
     181 
     182// ---------------------------------------------------------------- 
     183 
    144184 
    145185libusb_device_handle * 
     
    159199{ 
    160200  return usrp_open_interface (dev, USRP_TX_INTERFACE, USRP_TX_ALTINTERFACE); 
     201} 
     202 
     203 
     204// ---------------------------------------------------------------- 
     205// write internal ram using Cypress vendor extension 
     206 
     207static bool 
     208write_internal_ram (libusb_device_handle *udh, unsigned char *buf, 
     209                    int start_addr, size_t len) 
     210{ 
     211  int addr; 
     212  int n; 
     213  int a; 
     214  int quanta = MAX_EP0_PKTSIZE; 
     215 
     216  for (addr = start_addr; addr < start_addr + (int) len; addr += quanta){ 
     217    n = len + start_addr - addr; 
     218    if (n > quanta) 
     219      n = quanta; 
     220 
     221    a = usb_control_transfer (udh, 0x40, 0xA0, addr, 0, 
     222                       (unsigned char*)(buf + (addr - start_addr)), n, 1000); 
     223 
     224    if (a < 0){ 
     225      fprintf(stderr,"write_internal_ram failed: %u\n", a); 
     226      return false; 
     227    } 
     228  } 
     229  return true; 
    161230} 
    162231 
     
    349418} 
    350419 
     420bool 
     421usrp_set_hash (libusb_device_handle *udh, int which, 
     422               const unsigned char hash[USRP_HASH_SIZE]) 
     423{ 
     424  which &= 1; 
     425 
     426  // we use the Cypress firmware down load command to jam it in. 
     427  int r = usb_control_transfer (udh, 0x40, 0xa0, hash_slot_addr[which], 0, 
     428                                (unsigned char *) hash, USRP_HASH_SIZE, 1000); 
     429  return r == USRP_HASH_SIZE; 
     430} 
     431   
     432bool 
     433usrp_get_hash (libusb_device_handle *udh, int which, 
     434               unsigned char hash[USRP_HASH_SIZE]) 
     435{ 
     436  which &= 1; 
     437 
     438  // we use the Cypress firmware upload command to fetch it. 
     439  int r = usb_control_transfer (udh, 0xc0, 0xa0, hash_slot_addr[which], 0, 
     440                                (unsigned char *) hash, USRP_HASH_SIZE, 1000); 
     441  return r == USRP_HASH_SIZE; 
     442} 
     443 
     444 
    351445 
    352446static bool 
     
    356450} 
    357451 
    358 bool 
     452static bool 
    359453usrp1_fpga_write (libusb_device_handle *udh, 
    360454                  int regno, int value) 
     
    375469} 
    376470 
    377 bool 
     471static bool 
    378472usrp1_fpga_read (libusb_device_handle *udh, 
    379473                 int regno, int *value) 
     
    393487} 
    394488 
     489bool 
     490usrp_write_fpga_reg (libusb_device_handle *udh, int reg, int value) 
     491{ 
     492  switch (usrp_hw_rev (get_usb_device (udh))){ 
     493  case 0:                       // not supported ;) 
     494    abort(); 
     495 
     496  default: 
     497    return usrp1_fpga_write (udh, reg, value); 
     498  } 
     499} 
     500 
     501bool 
     502usrp_read_fpga_reg (libusb_device_handle *udh, int reg, int *value) 
     503{ 
     504  switch (usrp_hw_rev (get_usb_device (udh))){ 
     505  case 0:               // not supported ;) 
     506    abort(); 
     507 
     508  default: 
     509    return usrp1_fpga_read (udh, reg, value); 
     510  } 
     511} 
    395512 
    396513bool  
     
    815932} 
    816933 
     934static void 
     935power_down_9862s (libusb_device_handle *udh) 
     936{ 
     937  static const unsigned char regs[] = { 
     938    REG_RX_PWR_DN,      0x01,                   // everything 
     939    REG_TX_PWR_DN,      0x0f,                   // pwr dn digital and analog_both 
     940    REG_TX_MODULATOR,   0x00                    // coarse & fine modulators disabled 
     941  }; 
     942 
     943  switch (usrp_hw_rev (get_usb_device (udh))){ 
     944  case 0: 
     945    break; 
     946 
     947  default: 
     948    usrp_9862_write_many_all (udh, regs, sizeof (regs)); 
     949    break; 
     950  } 
     951} 
     952 
    817953 
    818954static const int EEPROM_PAGESIZE = 16; 
     
    10781214                            0, buf, sizeof (buf)); 
    10791215} 
     1216 
     1217 
     1218 
     1219 
     1220 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/usrp_prims_libusb.cc

    r9542 r9546  
    2727#include "usrp/usrp_prims.h" 
    2828#include "usrp_commands.h" 
    29 #include "usrp_ids.h" 
    30 #include "usrp_i2c_addr.h" 
    31 #include "fpga_regs_common.h" 
    32 #include "fpga_regs_standard.h" 
    3329#include <usb.h> 
    3430#include <errno.h> 
     
    3834#include <string.h> 
    3935#include <ctype.h> 
    40 #include <time.h>               // FIXME should check with autoconf (nanosleep) 
    41 #include <algorithm> 
    4236#include <ad9862.h> 
    4337#include <assert.h> 
     
    4741}; 
    4842 
    49 #define VERBOSE 0 
    50  
    5143using namespace ad9862; 
    5244 
    53 static const int FIRMWARE_HASH_SLOT     = 0; 
    54 static const int FPGA_HASH_SLOT         = 1; 
    55  
    56 static const int hash_slot_addr[2] = { 
    57   USRP_HASH_SLOT_0_ADDR, 
    58   USRP_HASH_SLOT_1_ADDR 
    59 }; 
    60  
    61 static const char *default_firmware_filename = "std.ihx"; 
    62 static const char *default_fpga_filename     = "std_2rxhb_2tx.rbf"; 
    63  
    64 #include "std_paths.h" 
    65 #include <stdio.h> 
     45struct usb_device_descriptor 
     46get_usb_device_descriptor (struct usb_device *q) 
     47{ 
     48  return q->descriptor; 
     49} 
     50 
     51struct usb_device * 
     52get_usb_device (struct usb_dev_handle *udh) 
     53{ 
     54  return usb_device (udh); 
     55} 
     56 
     57int 
     58usb_control_transfer (struct usb_dev_handle *udh, int request_type, 
     59                      int request, int value, int index, 
     60                      unsigned char *data, int length, unsigned int timeout) 
     61{ 
     62  return usb_control_msg (udh, request_type,  
     63                          request, value, index, 
     64                          (char*) data, length, (int) timeout); 
     65 
     66} 
     67 
     68 
     69// ---------------------------------------------------------------- 
     70 
    6671 
    6772void 
     
    8590} 
    8691 
    87 // ---------------------------------------------------------------- 
    88  
    89 /* 
    90  * q must be a real USRP, not an FX2.  Return its hardware rev number. 
    91  */ 
    92 int 
    93 usrp_hw_rev (struct usb_device *q) 
    94 { 
    95   return q->descriptor.bcdDevice & 0x00FF; 
    96 } 
    97  
    98 /* 
    99  * q must be a real USRP, not an FX2.  Return true if it's configured. 
    100  */ 
    101 bool 
    102 _usrp_configured_p (struct usb_device *q) 
    103 { 
    104   return (q->descriptor.bcdDevice & 0xFF00) != 0; 
    105 } 
    106  
    107 bool 
    108 usrp_usrp_p (struct usb_device *q) 
    109 { 
    110   return (q->descriptor.idVendor == USB_VID_FSF 
    111           && q->descriptor.idProduct == USB_PID_FSF_USRP); 
    112 } 
    113  
    114 bool 
    115 usrp_fx2_p (struct usb_device *q) 
    116 { 
    117   return (q->descriptor.idVendor == USB_VID_CYPRESS 
    118           && q->descriptor.idProduct == USB_PID_CYPRESS_FX2); 
    119 } 
    120  
    121 // ---------------------------------------------------------------- 
     92 
     93// ---------------------------------------------------------------- 
     94 
    12295 
    12396struct usb_device * 
     
    202175} 
    203176 
    204 // ---------------------------------------------------------------- 
    205 // write internal ram using Cypress vendor extension 
    206  
    207 bool 
    208 write_internal_ram (struct usb_dev_handle *udh, unsigned char *buf, 
    209                     int start_addr, size_t len) 
    210 { 
    211   int addr; 
    212   int n; 
    213   int a; 
    214   int quanta = MAX_EP0_PKTSIZE; 
    215  
    216   for (addr = start_addr; addr < start_addr + (int) len; addr += quanta){ 
    217     n = len + start_addr - addr; 
    218     if (n > quanta) 
    219       n = quanta; 
    220  
    221     a = usb_control_msg (udh, 0x40, 0xA0, 
    222                          addr, 0, (char *)(buf + (addr - start_addr)), n, 1000); 
    223  
    224     if (a < 0){ 
    225       fprintf(stderr,"write_internal_ram failed: %s\n", usb_strerror()); 
    226       return false; 
    227     } 
    228   } 
    229   return true; 
    230 } 
    231  
    232177 
    233178// ---------------------------------------------------------------- 
    234179// write vendor extension command to USRP 
     180 
    235181 
    236182int 
     
    253199 
    254200 
    255 bool 
    256 usrp_set_hash (struct usb_dev_handle *udh, int which, 
    257                const unsigned char hash[USRP_HASH_SIZE]) 
    258 { 
    259   which &= 1; 
    260    
    261   // we use the Cypress firmware down load command to jam it in. 
    262   int r = usb_control_msg (udh, 0x40, 0xa0, hash_slot_addr[which], 0, 
    263                            (char *) hash, USRP_HASH_SIZE, 1000); 
    264   return r == USRP_HASH_SIZE; 
    265 } 
    266  
    267 bool 
    268 usrp_get_hash (struct usb_dev_handle *udh, int which,  
    269                unsigned char hash[USRP_HASH_SIZE]) 
    270 { 
    271   which &= 1; 
    272    
    273   // we use the Cypress firmware upload command to fetch it. 
    274   int r = usb_control_msg (udh, 0xc0, 0xa0, hash_slot_addr[which], 0, 
    275                            (char *) hash, USRP_HASH_SIZE, 1000); 
    276   return r == USRP_HASH_SIZE; 
    277 } 
    278  
    279 bool 
    280 usrp_write_fpga_reg (struct usb_dev_handle *udh, int reg, int value) 
    281 { 
    282   switch (usrp_hw_rev (usb_device (udh))){ 
    283   case 0:                       // not supported ;) 
    284     abort();     
    285  
    286   default: 
    287     return usrp1_fpga_write (udh, reg, value); 
    288   } 
    289 } 
    290  
    291 bool 
    292 usrp_read_fpga_reg (struct usb_dev_handle *udh, int reg, int *value) 
    293 { 
    294   switch (usrp_hw_rev (usb_device (udh))){ 
    295   case 0:               // not supported ;) 
    296     abort(); 
    297      
    298   default: 
    299     return usrp1_fpga_read (udh, reg, value); 
    300   } 
    301 } 
    302  
    303  
    304 void 
    305 power_down_9862s (struct usb_dev_handle *udh) 
    306 { 
    307   static const unsigned char regs[] = { 
    308     REG_RX_PWR_DN,      0x01,              // everything 
    309     REG_TX_PWR_DN,      0x0f,              // pwr dn digital and analog_both 
    310     REG_TX_MODULATOR,   0x00               // coarse & fine modulators disabled 
    311   }; 
    312  
    313   switch (usrp_hw_rev (usb_device (udh))){ 
    314   case 0: 
    315     break; 
    316  
    317   default: 
    318     usrp_9862_write_many_all (udh, regs, sizeof (regs)); 
    319     break; 
    320   } 
    321 } 
    322  
    323 // ---------------------------------------------------------------- 
     201// ---------------------------------------------------------------- 
     202 
    324203 
    325204std::string 
  • ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/usrp_prims_libusb1.cc

    r9542 r9546  
    4242#include <ad9862.h> 
    4343#include <assert.h> 
     44#include "std_paths.h" 
    4445 
    4546extern "C" { 
     
    4748}; 
    4849 
    49 #define VERBOSE 0 
    50  
    5150using namespace ad9862; 
    5251 
    53 static const int FIRMWARE_HASH_SLOT     = 0; 
    54 static const int FPGA_HASH_SLOT         = 1; 
    55  
    56 static const int hash_slot_addr[2] = { 
    57   USRP_HASH_SLOT_0_ADDR, 
    58   USRP_HASH_SLOT_1_ADDR 
    59 }; 
    60  
    61 static const char *default_firmware_filename = "std.ihx"; 
    62 static const char *default_fpga_filename     = "std_2rxhb_2tx.rbf"; 
    63  
    64 #include "std_paths.h" 
    65 #include <stdio.h> 
     52 
     53struct libusb_device_descriptor 
     54get_usb_device_descriptor(struct libusb_device *q) 
     55{ 
     56  int ret; 
     57  struct libusb_device_descriptor desc; 
     58 
     59  if ((ret = libusb_get_device_descriptor(q, &desc)) < 0) 
     60    fprintf (stderr, "usrp: libusb_get_device_descriptor failed %d\n", ret); 
     61 
     62  return desc; 
     63} 
     64 
     65struct libusb_device * 
     66get_usb_device (struct libusb_device_handle *udh) 
     67{ 
     68  return libusb_get_device (udh); 
     69} 
     70 
     71int 
     72usb_control_transfer (struct usb_dev_handle *udh, uint8_t request_type, 
     73                      uint8_t request, uint16_t value, uint16_t index, 
     74                      unsigned char *data, uint16_t length, 
     75                      unsigned int timeout) 
     76{ 
     77  return libusb_control_transfer (udh, request_type, request, value, index, 
     78                                  *data, length, timeout); 
     79 
     80} 
     81 
     82 
     83// ---------------------------------------------------------------- 
     84 
    6685 
    6786void 
     
    8099} 
    81100 
    82 // ---------------------------------------------------------------- 
    83  
    84 /* 
    85  * q must be a real USRP, not an FX2.  Return its hardware rev number. 
    86  */ 
    87 int 
    88 usrp_hw_rev (struct libusb_device *q) 
    89 { 
    90   struct libusb_device_descriptor desc; 
    91   if (libusb_get_device_descriptor(q, &desc) < 0) 
    92     fprintf (stderr, "usrp: libusb_get_device_descriptor failed\n"); 
    93  
    94   return desc.bcdDevice & 0x00FF; 
    95 } 
    96  
    97 /* 
    98  * q must be a real USRP, not an FX2.  Return true if it's configured. 
    99  */ 
    100 bool 
    101 _usrp_configured_p (struct libusb_device *q) 
    102 { 
    103   struct libusb_device_descriptor desc; 
    104   if (libusb_get_device_descriptor(q, &desc) < 0) 
    105     fprintf (stderr, "usrp: libusb_get_device_descriptor failed\n"); 
    106  
    107   return (desc.bcdDevice & 0xFF00) != 0; 
    108 } 
    109  
    110 bool 
    111 usrp_usrp_p (struct libusb_device *q) 
    112 { 
    113   struct libusb_device_descriptor desc; 
    114   if (libusb_get_device_descriptor(q, &desc) < 0) 
    115     fprintf (stderr, "usrp: libusb_get_device_descriptor failed\n"); 
    116  
    117   return (desc.idVendor == USB_VID_FSF 
    118           && desc.idProduct == USB_PID_FSF_USRP); 
    119 } 
    120  
    121 bool 
    122 usrp_fx2_p (struct libusb_device *q) 
    123 { 
    124   struct libusb_device_descriptor desc; 
    125   if (libusb_get_device_descriptor(q, &desc) < 0) 
    126     fprintf (stderr, "usrp: libusb_get_device_descriptor failed\n"); 
    127  
    128   return (desc.idVendor == USB_VID_CYPRESS 
    129           && desc.idProduct == USB_PID_CYPRESS_FX2); 
    130 } 
    131  
    132  
    133 // ---------------------------------------------------------------- 
    134101 
    135102struct libusb_device * 
     
    208175} 
    209176 
    210 // ---------------------------------------------------------------- 
    211 // write internal ram using Cypress vendor extension 
    212  
    213 bool 
    214 write_internal_ram (struct libusb_device_handle *udh, unsigned char *buf, 
    215                     int start_addr, size_t len) 
    216 { 
    217   int addr; 
    218   int n; 
    219   int a; 
    220   int quanta = MAX_EP0_PKTSIZE; 
    221  
    222   for (addr = start_addr; addr < start_addr + (int) len; addr += quanta){ 
    223     n = len + start_addr - addr; 
    224     if (n > quanta) 
    225       n = quanta; 
    226  
    227     a = libusb_control_transfer (udh, 0x40, 0xA0, 
    228                          addr, 0, (unsigned char *)(buf + (addr - start_addr)), n, 1000); 
    229  
    230     if (a < 0){ 
    231       fprintf(stderr,"write_internal_ram failed: %u\n", a); 
    232       return false; 
    233     } 
    234   } 
    235   return true; 
    236 } 
    237177 
    238178// ---------------------------------------------------------------- 
    239179// write vendor extension command to USRP 
     180 
    240181 
    241182int 
     
    259200} 
    260201 
    261 bool 
    262 usrp_set_hash (struct libusb_device_handle *udh, int which, 
    263                const unsigned char hash[USRP_HASH_SIZE]) 
    264 { 
    265   which &= 1; 
    266  
    267   // we use the Cypress firmware down load command to jam it in. 
    268   int r = libusb_control_transfer (udh, 0x40, 0xa0, hash_slot_addr[which], 0, 
    269                            (unsigned char *) hash, USRP_HASH_SIZE, 1000); 
    270   return r == USRP_HASH_SIZE; 
    271 } 
    272    
    273 bool 
    274 usrp_get_hash (struct libusb_device_handle *udh, int which, 
    275                unsigned char hash[USRP_HASH_SIZE]) 
    276 { 
    277   which &= 1; 
    278  
    279   // we use the Cypress firmware upload command to fetch it. 
    280   int r = libusb_control_transfer (udh, 0xc0, 0xa0, hash_slot_addr[which], 0, 
    281                            (unsigned char *) hash, USRP_HASH_SIZE, 1000); 
    282   return r == USRP_HASH_SIZE; 
    283 } 
    284  
    285 bool 
    286 usrp_write_fpga_reg (struct libusb_device_handle *udh, int reg, int value) 
    287 { 
    288   switch (usrp_hw_rev (libusb_get_device (udh))){ 
    289   case 0:                       // not supported ;) 
    290     abort(); 
    291  
    292   default: 
    293     return usrp1_fpga_write (udh, reg, value); 
    294   } 
    295 } 
    296  
    297 bool 
    298 usrp_read_fpga_reg (struct libusb_device_handle *udh, int reg, int *value) 
    299 { 
    300   switch (usrp_hw_rev (libusb_get_device (udh))){ 
    301   case 0:               // not supported ;) 
    302     abort(); 
    303  
    304   default: 
    305     return usrp1_fpga_read (udh, reg, value); 
    306   } 
    307 } 
    308  
    309  
    310  
    311 void 
    312 power_down_9862s (struct libusb_device_handle *udh) 
    313 { 
    314   static const unsigned char regs[] = { 
    315     REG_RX_PWR_DN,      0x01,                   // everything 
    316     REG_TX_PWR_DN,      0x0f,                   // pwr dn digital and analog_both 
    317     REG_TX_MODULATOR,   0x00                    // coarse & fine modulators disabled 
    318   }; 
    319  
    320   switch (usrp_hw_rev (libusb_get_device (udh))){ 
    321   case 0: 
    322     break; 
    323  
    324   default: 
    325     usrp_9862_write_many_all (udh, regs, sizeof (regs)); 
    326     break; 
    327   } 
    328 } 
    329  
    330202 
    331203// ----------------------------------------------------------------