OpenCores
URL https://opencores.org/ocsvn/adv_debug_sys/adv_debug_sys/trunk

Subversion Repositories adv_debug_sys

[/] [adv_debug_sys/] [trunk/] [Software/] [adv_jtag_bridge/] [cable_usbblaster.c] - Diff between revs 8 and 14

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 8 Rev 14
Line 50... Line 50...
#define USBBLASTER_CMD_BYTESHIFT 0x80
#define USBBLASTER_CMD_BYTESHIFT 0x80
 
 
 
 
static struct usb_device *usbblaster_device;
static struct usb_device *usbblaster_device;
 
 
static uint8_t *data_out_scratchpad = NULL;
static char *data_out_scratchpad = NULL;
static int data_out_scratchpad_size = 0;
static int data_out_scratchpad_size = 0;
static uint8_t *data_in_scratchpad = NULL;
static char *data_in_scratchpad = NULL;
static int data_in_scratchpad_size = 0;
static int data_in_scratchpad_size = 0;
 
 
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/*-------------------------------------[ USB Blaster specific functions ]---*/
/*-------------------------------------[ USB Blaster specific functions ]---*/
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
Line 207... Line 207...
    return APP_ERR_USB;
    return APP_ERR_USB;
  }
  }
 
 
  usb_close(h_device);
  usb_close(h_device);
 
 
  data_out_scratchpad = (uint8_t *) malloc(64);
  data_out_scratchpad = (char *) malloc(64);
  data_out_scratchpad_size = 64;
  data_out_scratchpad_size = 64;
  data_in_scratchpad = (uint8_t *) malloc(64);
  data_in_scratchpad = (char *) malloc(64);
  data_in_scratchpad_size = 64;
  data_in_scratchpad_size = 64;
 
 
  return APP_ERR_NONE;
  return APP_ERR_NONE;
}
}
 
 
 
 
int cable_usbblaster_out(uint8_t value)
int cable_usbblaster_out(uint8_t value)
{
{
  int             rv;                  // to catch return values of functions
  int             rv;                  // to catch return values of functions
  usb_dev_handle *h_device;            // handle on the ubs device
  usb_dev_handle *h_device;            // handle on the ubs device
  uint8_t out;
  char out;
  int err = APP_ERR_NONE;
  int err = APP_ERR_NONE;
 
 
  // open the device
  // open the device
  h_device = usb_open(usbblaster_device);
  h_device = usb_open(usbblaster_device);
  if (h_device == NULL){
  if (h_device == NULL){
Line 277... Line 277...
int cable_usbblaster_inout(uint8_t value, uint8_t *in_bit)
int cable_usbblaster_inout(uint8_t value, uint8_t *in_bit)
{
{
  int             rv;                  // to catch return values of functions
  int             rv;                  // to catch return values of functions
  usb_dev_handle *h_device;            // handle on the usb device
  usb_dev_handle *h_device;            // handle on the usb device
  char ret[3] = {0,0,0};               // Two useless bytes (0x31,0x60) always precede the useful byte
  char ret[3] = {0,0,0};               // Two useless bytes (0x31,0x60) always precede the useful byte
  unsigned char out;
  char out;
 
 
  out = (USBBLASTER_CMD_OE | USBBLASTER_CMD_nCS);  // Set output enable (?) and nCS (necessary for byte-shift reads)
  out = (USBBLASTER_CMD_OE | USBBLASTER_CMD_nCS);  // Set output enable (?) and nCS (necessary for byte-shift reads)
  out |=  USBBLASTER_CMD_READ;
  out |=  USBBLASTER_CMD_READ;
 
 
  // Translate to USB blaster protocol
  // Translate to USB blaster protocol
Line 415... Line 415...
 
 
  // Copy stream into out.  Not pretty, but better than changing the interface to the upper layers;
  // Copy stream into out.  Not pretty, but better than changing the interface to the upper layers;
  // 32 bits are easier to work with than 8 bits in upper layers.
  // 32 bits are easier to work with than 8 bits in upper layers.
  if(data_out_scratchpad_size < (bytes_to_transfer+1)) {
  if(data_out_scratchpad_size < (bytes_to_transfer+1)) {
    free(data_out_scratchpad);
    free(data_out_scratchpad);
    data_out_scratchpad = (uint8_t *) malloc(bytes_to_transfer+1);  // free/malloc instead of realloc will save copy time
    data_out_scratchpad = (char *) malloc(bytes_to_transfer+1);  // free/malloc instead of realloc will save copy time
    if(data_out_scratchpad == NULL) {
    if(data_out_scratchpad == NULL) {
      usb_release_interface(h_device, usbblaster_device->config->interface->altsetting->bInterfaceNumber);
      usb_release_interface(h_device, usbblaster_device->config->interface->altsetting->bInterfaceNumber);
      usb_close(h_device);
      usb_close(h_device);
      return APP_ERR_MALLOC;
      return APP_ERR_MALLOC;
    }
    }
Line 530... Line 530...
 
 
  // Copy stream into out.  Not pretty, but better than changing the interface to the upper layers;
  // Copy stream into out.  Not pretty, but better than changing the interface to the upper layers;
  // 32 bits are easier to work with than 8 bits in upper layers.
  // 32 bits are easier to work with than 8 bits in upper layers.
  if(data_out_scratchpad_size < (bytes_to_transfer+1)) {
  if(data_out_scratchpad_size < (bytes_to_transfer+1)) {
    free(data_out_scratchpad);
    free(data_out_scratchpad);
    data_out_scratchpad = (uint8_t *) malloc(bytes_to_transfer+1);  // free/malloc instead of realloc will save copy time
    data_out_scratchpad = (char *) malloc(bytes_to_transfer+1);  // free/malloc instead of realloc will save copy time
    if(data_out_scratchpad == NULL) {
    if(data_out_scratchpad == NULL) {
      usb_release_interface(h_device, usbblaster_device->config->interface->altsetting->bInterfaceNumber);
      usb_release_interface(h_device, usbblaster_device->config->interface->altsetting->bInterfaceNumber);
      usb_close(h_device);
      usb_close(h_device);
      return APP_ERR_MALLOC;
      return APP_ERR_MALLOC;
    }
    }
Line 563... Line 563...
 
 
 
 
  // Make sure we have a big-enough buffer to hold the incoming data
  // Make sure we have a big-enough buffer to hold the incoming data
  if(data_in_scratchpad_size < (bytes_to_transfer+2)) {
  if(data_in_scratchpad_size < (bytes_to_transfer+2)) {
    free(data_in_scratchpad);
    free(data_in_scratchpad);
    data_in_scratchpad = (uint8_t *) malloc(bytes_to_transfer+2);  // free/malloc instead of realloc will save copy time
    data_in_scratchpad = (char *) malloc(bytes_to_transfer+2);  // free/malloc instead of realloc will save copy time
    if(data_in_scratchpad == NULL) {
    if(data_in_scratchpad == NULL) {
      usb_release_interface(h_device, usbblaster_device->config->interface->altsetting->bInterfaceNumber);
      usb_release_interface(h_device, usbblaster_device->config->interface->altsetting->bInterfaceNumber);
      usb_close(h_device);
      usb_close(h_device);
      return APP_ERR_MALLOC;
      return APP_ERR_MALLOC;
    }
    }
Line 586... Line 586...
      usb_release_interface(h_device, usbblaster_device->config->interface->altsetting->bInterfaceNumber);
      usb_release_interface(h_device, usbblaster_device->config->interface->altsetting->bInterfaceNumber);
      usb_close(h_device);
      usb_close(h_device);
      return APP_ERR_USB;
      return APP_ERR_USB;
    }
    }
 
 
 
 
    /*
    /*
    debug("Read %i bytes: ", rv);
    debug("Read %i bytes: ", rv);
    for(i = 0; i < rv; i++)
    for(i = 0; i < rv; i++)
      debug("0x%X ", data_in_scratchpad[i]);
      debug("0x%X ", data_in_scratchpad[i]);
    debug("\n");
    debug("\n");
Line 599... Line 598...
    if(rv > 2) retries = 0;
    if(rv > 2) retries = 0;
    else retries++;
    else retries++;
 
 
    /* Put the received bytes into the return stream.  */
    /* Put the received bytes into the return stream.  */
    for(i = 0; i < (rv-2); i++) {
    for(i = 0; i < (rv-2); i++) {
      uint32_t tmp = data_in_scratchpad[2+i];  // do type promotion before shift
      // Do size/type promotion before shift.  Must cast to unsigned, else the value may be
 
      // sign-extended through the upper 16 bits of the uint32_t.
 
      uint32_t tmp = (unsigned char) data_in_scratchpad[2+i];
      instream[(bytes_received+i)>>2] |= (tmp << ((i & 0x3)*8));
      instream[(bytes_received+i)>>2] |= (tmp << ((i & 0x3)*8));
    }
    }
 
 
    bytes_received += (rv-2);
    bytes_received += (rv-2);
  }
  }

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.