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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or_debug_proxy/] [src/] [usb_functions.c] - Diff between revs 47 and 79

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

Rev 47 Rev 79
Line 52... Line 52...
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/******************************************************************************/
// Date         Version Description
// Date         Version Description
//------------------------------------------------------------------------
//------------------------------------------------------------------------
// 081101               First revision                                  jb
// 081101               First revision                                  jb
 
// 100408               Fixed up retries                                jb
 
 
#include <assert.h>
#include <assert.h>
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
Line 87... Line 88...
DWORD dwNumBytesReturned = 0;
DWORD dwNumBytesReturned = 0;
 
 
/* Crc of current read or written data.  */
/* Crc of current read or written data.  */
uint32_t crc_r, crc_w = 0;
uint32_t crc_r, crc_w = 0;
 
 
 
/* Number of retries for a command */
 
uint32_t retries;
 
 
/* Generates new crc, sending in new bit input_bit */
/* Generates new crc, sending in new bit input_bit */
uint32_t crc_calc(uint32_t crc, uint32_t input_bit) {
uint32_t crc_calc(uint32_t crc, uint32_t input_bit) {
        uint32_t d = (input_bit) ? 0xfffffff : 0x0000000;
        uint32_t d = (input_bit) ? 0xfffffff : 0x0000000;
        uint32_t crc_32 = ((crc >> 31)&1) ? 0xfffffff : 0x0000000;
        uint32_t crc_32 = ((crc >> 31)&1) ? 0xfffffff : 0x0000000;
        crc <<= 1;
        crc <<= 1;
Line 517... Line 521...
 
 
   // JTAG driver things
   // JTAG driver things
  FTC_STATUS Status = FTC_SUCCESS;
  FTC_STATUS Status = FTC_SUCCESS;
  WriteDataByteBuffer WriteDataBuffer;
  WriteDataByteBuffer WriteDataBuffer;
  ReadDataByteBuffer ReadDataBuffer;
  ReadDataByteBuffer ReadDataBuffer;
 
  retries = 0;
 try_again:
 try_again:
  usb_dbg_set_chain(dbg_chain);
  usb_dbg_set_chain(dbg_chain);
  if (DEBUG_CMDS) printf("\n");
  if (DEBUG_CMDS) printf("\n");
  if (DEBUG_CMDS) printf("comm %d %d %8x \n", type,len,adr);
  if (DEBUG_CMDS) printf("comm %d %d %8x \n", type,len,adr);
 
 
Line 610... Line 614...
  status = bit_reverse_data(status, DC_STATUS_SIZE);
  status = bit_reverse_data(status, DC_STATUS_SIZE);
  crc_read = bit_reverse_data(crc_read, DBG_CRC_SIZE);
  crc_read = bit_reverse_data(crc_read, DBG_CRC_SIZE);
 
 
  //printf("%x %x %x\n", status, crc_read, crc_generated);
  //printf("%x %x %x\n", status, crc_read, crc_generated);
  /* CRCs must match, otherwise retry */
  /* CRCs must match, otherwise retry */
  uint32_t tries = 0;
  //uint32_t tries = 0;
  if (crc_read != crc_generated) {
  if (crc_read != crc_generated) {
    tries++;
    retries++;
    if (tries < 2)
    if (retries < 2)
      {
      {
        if (DEBUG_USB_DRVR_FUNCS)
        if (DEBUG_USB_DRVR_FUNCS)
          printf("usb_functions - usb_dbg_command - CRC fail. Going again\n");
          printf("usb_functions - usb_dbg_command - CRC fail. Going again\n");
        goto try_again;
        goto try_again;
      }
      }
    else if (tries < 8)
    else if (retries < 8)
      {
      {
        reset_tap();
        reset_tap();
        goto try_again;
        goto try_again;
      }
      }
    else return DBG_ERR_CRC;
    else return DBG_ERR_CRC;
  }
  }
  /* we should read expected status value, otherwise retry */
  /* we should read expected status value, otherwise retry */
  tries = 0;
 
  if (status != 0) {
  if (status != 0) {
    if (tries < 2)
    if (retries < 2)
      {
      {
        if (DEBUG_USB_DRVR_FUNCS)
        if (DEBUG_USB_DRVR_FUNCS)
          printf("usb_functions - usb_dbg_command - bad status (%d). Going again\n",status);
          printf("usb_functions - usb_dbg_command - bad status (%d). Going again\n",status);
        goto try_again;
        goto try_again;
      }
      }
    else if (tries < 8)
    else if (retries < 8)
      {
      {
        reset_tap();
        reset_tap();
        goto try_again;
        goto try_again;
      }
      }
    else return status;
    else return status;
Line 657... Line 660...
  uint32_t i,status, crc_generated, crc_read;
  uint32_t i,status, crc_generated, crc_read;
  // JTAG driver things
  // JTAG driver things
  FTC_STATUS Status = FTC_SUCCESS;
  FTC_STATUS Status = FTC_SUCCESS;
  WriteDataByteBuffer WriteDataBuffer;
  WriteDataByteBuffer WriteDataBuffer;
  ReadDataByteBuffer ReadDataBuffer;
  ReadDataByteBuffer ReadDataBuffer;
 
  retries = 0;
try_again:
try_again:
  usb_dbg_set_chain(dbg_chain);
  usb_dbg_set_chain(dbg_chain);
        if (DEBUG_CMDS) printf("\n");
        if (DEBUG_CMDS) printf("\n");
        if (DEBUG_CMDS) printf("ctrl\n");
        if (DEBUG_CMDS) printf("ctrl\n");
        if (DEBUG_CMDS) printf("reset %x stall %x\n", reset, stall);
        if (DEBUG_CMDS) printf("reset %x stall %x\n", reset, stall);
Line 737... Line 740...
        status = bit_reverse_data(status, DC_STATUS_SIZE);
        status = bit_reverse_data(status, DC_STATUS_SIZE);
        crc_read = bit_reverse_data(crc_read, DBG_CRC_SIZE);
        crc_read = bit_reverse_data(crc_read, DBG_CRC_SIZE);
 
 
        /* CRCs must match, otherwise retry */
        /* CRCs must match, otherwise retry */
        //printf("%x %x %x\n", status, crc_read, crc_generated);
        //printf("%x %x %x\n", status, crc_read, crc_generated);
        uint32_t tries = 0;
 
          if (crc_read != crc_generated) {
          if (crc_read != crc_generated) {
          tries++;
          retries++;
          if (tries < 2)
          if (retries < 2)
            {
            {
              if (DEBUG_USB_DRVR_FUNCS)
              if (DEBUG_USB_DRVR_FUNCS)
                printf("usb_functions - usb_dbg_ctrl - CRC fail. Going again\n");
                printf("usb_functions - usb_dbg_ctrl - CRC fail. Going again\n");
              goto try_again;
              goto try_again;
            }
            }
          else if (tries < 8)
          else if (retries < 8)
            {
            {
              reset_tap();
              reset_tap();
              goto try_again;
              goto try_again;
            }
            }
          else return DBG_ERR_CRC;
          else return DBG_ERR_CRC;
        }
        }
        /* we should read expected status value, otherwise retry */
        /* we should read expected status value, otherwise retry */
        tries = 0;
        retries = 0;
        if (status != 0) {
        if (status != 0) {
          if (tries < 2)
          if (retries < 2)
            {
            {
              if (DEBUG_USB_DRVR_FUNCS)
              if (DEBUG_USB_DRVR_FUNCS)
                printf("usb_functions - usb_dbg_ctrl - bad status (%d). Going again\n",status);
                printf("usb_functions - usb_dbg_ctrl - bad status (%d). Going again\n",status);
              goto try_again;
              goto try_again;
            }
            }
          else if (tries < 8)
          else if (retries < 8)
            {
            {
              reset_tap();
              reset_tap();
              goto try_again;
              goto try_again;
            }
            }
          else return status;
          else return status;
Line 785... Line 787...
 
 
  // JTAG driver things
  // JTAG driver things
  FTC_STATUS Status = FTC_SUCCESS;
  FTC_STATUS Status = FTC_SUCCESS;
  WriteDataByteBuffer WriteDataBuffer;
  WriteDataByteBuffer WriteDataBuffer;
  ReadDataByteBuffer ReadDataBuffer;
  ReadDataByteBuffer ReadDataBuffer;
 
  retries = 0;
 
 
 try_again:
 try_again:
  usb_dbg_set_chain(dbg_chain);
  usb_dbg_set_chain(dbg_chain);
  if (DEBUG_CMDS) printf("\n");
  if (DEBUG_CMDS) printf("\n");
  if (DEBUG_CMDS) printf("ctrl_read\n");
  if (DEBUG_CMDS) printf("ctrl_read\n");
Line 875... Line 877...
  crc_read = bit_reverse_data(crc_read, DBG_CRC_SIZE);
  crc_read = bit_reverse_data(crc_read, DBG_CRC_SIZE);
 
 
 
 
  /* CRCs must match, otherwise retry */
  /* CRCs must match, otherwise retry */
  //printf("%x %x %x\n", status, crc_generated, crc_read);
  //printf("%x %x %x\n", status, crc_generated, crc_read);
  uint32_t tries = 0;
 
  if (crc_read != crc_generated) {
  if (crc_read != crc_generated) {
    tries++;
    retries++;
    if (tries < 2)
    if (retries < 2)
      {
      {
        if (DEBUG_USB_DRVR_FUNCS)
        if (DEBUG_USB_DRVR_FUNCS)
          printf("usb_functions - usb_dbg_ctrl_read - CRC fail. Going again\n");
          printf("usb_functions - usb_dbg_ctrl_read - CRC fail. Going again\n");
        goto try_again;
        goto try_again;
      }
      }
    else if (tries < 8)
    else if (retries < 8)
      {
      {
        reset_tap();
        reset_tap();
        goto try_again;
        goto try_again;
      }
      }
    else return DBG_ERR_CRC;
    else return DBG_ERR_CRC;
        }
        }
  /* we should read expected status value, otherwise retry */
  /* we should read expected status value, otherwise retry */
  tries = 0;
  retries = 0;
  if (status != 0) {
  if (status != 0) {
    if (tries < 2)
    if (retries < 2)
      {
      {
        if (DEBUG_USB_DRVR_FUNCS)
        if (DEBUG_USB_DRVR_FUNCS)
          printf("usb_functions - usb_dbg_ctrl_read - bad status (%d). Going again\n",status);
          printf("usb_functions - usb_dbg_ctrl_read - bad status (%d). Going again\n",status);
        goto try_again;
        goto try_again;
      }
      }
    else if (tries < 8)
    else if (retries < 8)
      {
      {
        reset_tap();
        reset_tap();
        goto try_again;
        goto try_again;
      }
      }
    else return status;
    else return status;
Line 919... Line 920...
 
 
/* issues a burst read/write */
/* issues a burst read/write */
int usb_dbg_go(unsigned char *data, uint16_t len, uint32_t read) {
int usb_dbg_go(unsigned char *data, uint16_t len, uint32_t read) {
        uint32_t status, crc_generated, crc_read;
        uint32_t status, crc_generated, crc_read;
        int i,j;
        int i,j;
        int tries = 0;
 
        uint8_t data_byte;
        uint8_t data_byte;
 
        retries = 0;
        // JTAG driver things
        // JTAG driver things
        FTC_STATUS Status = FTC_SUCCESS;
        FTC_STATUS Status = FTC_SUCCESS;
        WriteDataByteBuffer WriteDataBuffer;
        WriteDataByteBuffer WriteDataBuffer;
        ReadDataByteBuffer ReadDataBuffer;
        ReadDataByteBuffer ReadDataBuffer;
 
 
Line 1075... Line 1075...
        /* CRCs must match, otherwise retry */
        /* CRCs must match, otherwise retry */
 
 
        //printf("%x %x %x\n", status, crc_read, crc_generated);
        //printf("%x %x %x\n", status, crc_read, crc_generated);
 
 
        if (crc_read != crc_generated) {
        if (crc_read != crc_generated) {
          tries++;
          retries++;
          if (tries < 8)
          if (retries < 8)
            {
            {
              if (DEBUG_USB_DRVR_FUNCS) printf("usb_functions - usb_dbg_go - CRC fail (%d) try %d. Going again\n",status, tries);
              if (DEBUG_USB_DRVR_FUNCS) printf("usb_functions - usb_dbg_go - CRC fail (%d) try %d. Going again\n",status, retries);
              reset_tap() ;
              reset_tap() ;
              goto try_again;
              goto try_again;
            }
            }
          else return DBG_ERR_CRC;
          else return DBG_ERR_CRC;
        }
        }
        //if (crc_read == crc_generated)
        //if (crc_read == crc_generated)
        //tries = 0;
        //tries = 0;
        /* we should read expected status value, otherwise retry */
        /* we should read expected status value, otherwise retry */
        if (status != 0) {
        if (status != 0) {
          tries++;
          retries++;
          if (tries < 8)
          if (retries < 8)
            {
            {
              if (DEBUG_USB_DRVR_FUNCS) printf("usb_functions - usb_dbg_go - bad status (%d) try %d. Going again\n",status, tries);
              if (DEBUG_USB_DRVR_FUNCS) printf("usb_functions - usb_dbg_go - bad status (%d) try %d. Going again\n",status, retries);
              reset_tap();
              reset_tap();
              goto try_again;
              goto try_again;
 
 
            }
            }
          else return status;
          else return status;

powered by: WebSVN 2.1.0

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