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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or_debug_proxy/] [src/] [win_usb_driver_calls.c] - Diff between revs 39 and 47

Only display areas with differences | Details | Blame | View Log

Rev 39 Rev 47
/*$$HEADER*/
/*$$HEADER*/
/******************************************************************************/
/******************************************************************************/
/*                                                                            */
/*                                                                            */
/*                    H E A D E R   I N F O R M A T I O N                     */
/*                    H E A D E R   I N F O R M A T I O N                     */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/******************************************************************************/
 
 
// Project Name                   : OpenRISC Debug Proxy
// Project Name                   : OpenRISC Debug Proxy
// File Name                      : win_usb_driver_calls.c
// File Name                      : win_usb_driver_calls.c
// Prepared By                    : jb
// Prepared By                    : jb
// Project Start                  : 2008-10-01
// Project Start                  : 2008-10-01
 
 
/*$$COPYRIGHT NOTICE*/
/*$$COPYRIGHT NOTICE*/
/******************************************************************************/
/******************************************************************************/
/*                                                                            */
/*                                                                            */
/*                      C O P Y R I G H T   N O T I C E                       */
/*                      C O P Y R I G H T   N O T I C E                       */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/******************************************************************************/
/*
/*
  This library is free software; you can redistribute it and/or
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation;
  License as published by the Free Software Foundation;
  version 2.1 of the License, a copy of which is available from
  version 2.1 of the License, a copy of which is available from
  http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
  http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
 
 
  This library is distributed in the hope that it will be useful,
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  Lesser General Public License for more details.
 
 
  You should have received a copy of the GNU Lesser General Public
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
*/
 
 
/*$$DESCRIPTION*/
/*$$DESCRIPTION*/
/******************************************************************************/
/******************************************************************************/
/*                                                                            */
/*                                                                            */
/*                           D E S C R I P T I O N                            */
/*                           D E S C R I P T I O N                            */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/******************************************************************************/
//
//
// Some generically named functions for interfacing to the JTAG driver 
// Some generically named functions for interfacing to the JTAG driver 
// functions, making the code calling these platform independant. The correct 
// functions, making the code calling these platform independant. The correct 
// driver calling file (either Cygwin or Linux driver) is included at compile 
// driver calling file (either Cygwin or Linux driver) is included at compile 
// time.
// time.
// Also included in this file is the USB-JTAG chip initialisation function.
// Also included in this file is the USB-JTAG chip initialisation function.
//
//
 
 
 
 
/*$$CHANGE HISTORY*/
/*$$CHANGE HISTORY*/
/******************************************************************************/
/******************************************************************************/
/*                                                                            */
/*                                                                            */
/*                         C H A N G E  H I S T O R Y                         */
/*                         C H A N G E  H I S T O R Y                         */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/******************************************************************************/
 
 
// Date         Version Description
// Date         Version Description
//------------------------------------------------------------------------
//------------------------------------------------------------------------
// 081101               First revision                                  jb
// 081101               First revision                                  jb
 
 
 
 
#include <stdio.h>
#include <stdio.h>
#include <assert.h>
#include <assert.h>
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <windows.h>
#include <windows.h>
 
 
#include "win_FTCJTAG.h"
#include "win_FTCJTAG.h"
 
 
#include "win_FTCJTAG_ptrs.h"   
#include "win_FTCJTAG_ptrs.h"   
 
 
#include "usb_driver_calls.h"
#include "usb_driver_calls.h"
 
 
#include "or_debug_proxy.h"
#include "or_debug_proxy.h"
 
 
 
 
// Load the pointers and loading functions of the FTCJTAG driver
// Load the pointers and loading functions of the FTCJTAG driver
int getFTDIJTAGFunctions (){
int getFTDIJTAGFunctions (){
 
 
  HINSTANCE hLib;
  HINSTANCE hLib;
 
 
  /* Load the library */
  /* Load the library */
  hLib = LoadLibrary("lib/FTCJTAG.dll");
  hLib = LoadLibrary("lib/FTCJTAG.dll");
 
 
  if (hLib == NULL) {
  if (hLib == NULL) {
    printf("Loading of library file \"FTCJTAG.dll\" failed!\n");
    printf("Loading of library file \"FTCJTAG.dll\" failed!\n");
    return -1;
    return -1;
  }
  }
 
 
 
 
  /* get the address of the functions */
  /* get the address of the functions */
  jtagGetNumDevices = (jtagGetNumDevicesPtr) GetProcAddress(hLib, "JTAG_GetNumDevices");
  jtagGetNumDevices = (jtagGetNumDevicesPtr) GetProcAddress(hLib, "JTAG_GetNumDevices");
 
 
  if (jtagGetNumDevices == NULL) {
  if (jtagGetNumDevices == NULL) {
    printf("GetProcAddress for JTAG_GetNumDevices Failed.\n");
    printf("GetProcAddress for JTAG_GetNumDevices Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagInitDevice = (jtagInitDevicePtr) GetProcAddress(hLib, "JTAG_InitDevice");
  jtagInitDevice = (jtagInitDevicePtr) GetProcAddress(hLib, "JTAG_InitDevice");
  if (jtagInitDevice == NULL) {
  if (jtagInitDevice == NULL) {
    printf("GetProcAddress for JTAG_InitDevice  Failed.\n");
    printf("GetProcAddress for JTAG_InitDevice  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagOpen = (jtagOpenPtr) GetProcAddress(hLib, "JTAG_Open");
  jtagOpen = (jtagOpenPtr) GetProcAddress(hLib, "JTAG_Open");
  if (jtagOpen == NULL) {
  if (jtagOpen == NULL) {
    printf("GetProcAddress for JTAG_Open  Failed.\n");
    printf("GetProcAddress for JTAG_Open  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagOpenEx = (jtagOpenExPtr) GetProcAddress(hLib, "JTAG_OpenEx");
  jtagOpenEx = (jtagOpenExPtr) GetProcAddress(hLib, "JTAG_OpenEx");
  if (jtagOpenEx == NULL) {
  if (jtagOpenEx == NULL) {
    printf("GetProcAddress for JTAG_OpenEx  Failed.\n");
    printf("GetProcAddress for JTAG_OpenEx  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagGetDeviceNameLocID = (jtagGetDeviceNameLocIDPtr) GetProcAddress(hLib, "JTAG_GetDeviceNameLocID");
  jtagGetDeviceNameLocID = (jtagGetDeviceNameLocIDPtr) GetProcAddress(hLib, "JTAG_GetDeviceNameLocID");
  if (jtagGetDeviceNameLocID == NULL) {
  if (jtagGetDeviceNameLocID == NULL) {
    printf("GetProcAddress for  Failed JTAG_GetDeviceNameLocID.\n");
    printf("GetProcAddress for  Failed JTAG_GetDeviceNameLocID.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagClose = (jtagClosePtr) GetProcAddress(hLib, "JTAG_Close");
  jtagClose = (jtagClosePtr) GetProcAddress(hLib, "JTAG_Close");
  if (jtagClose == NULL) {
  if (jtagClose == NULL) {
    printf("GetProcAddress for JTAG_Close  Failed.\n");
    printf("GetProcAddress for JTAG_Close  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagGetClock = (jtagGetClockPtr) GetProcAddress(hLib, "JTAG_GetClock");
  jtagGetClock = (jtagGetClockPtr) GetProcAddress(hLib, "JTAG_GetClock");
  if (jtagGetClock == NULL) {
  if (jtagGetClock == NULL) {
    printf("GetProcAddress for JTAG_GetClock  Failed.\n");
    printf("GetProcAddress for JTAG_GetClock  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagSetClock = (jtagSetClockPtr) GetProcAddress(hLib, "JTAG_SetClock");
  jtagSetClock = (jtagSetClockPtr) GetProcAddress(hLib, "JTAG_SetClock");
  if (jtagSetClock == NULL) {
  if (jtagSetClock == NULL) {
    printf("GetProcAddress for JTAG_SetClock  Failed.\n");
    printf("GetProcAddress for JTAG_SetClock  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagSetLoopback = (jtagSetLoopbackPtr) GetProcAddress(hLib, "JTAG_SetLoopback");
  jtagSetLoopback = (jtagSetLoopbackPtr) GetProcAddress(hLib, "JTAG_SetLoopback");
  if (jtagSetLoopback == NULL) {
  if (jtagSetLoopback == NULL) {
    printf("GetProcAddress for JTAG_SetLoopback  Failed.\n");
    printf("GetProcAddress for JTAG_SetLoopback  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagSetGPIOs = (jtagSetGPIOsPtr) GetProcAddress(hLib, "JTAG_SetGPIOs");
  jtagSetGPIOs = (jtagSetGPIOsPtr) GetProcAddress(hLib, "JTAG_SetGPIOs");
  if (jtagSetGPIOs == NULL) {
  if (jtagSetGPIOs == NULL) {
    printf("GetProcAddress for JTAG_SetGPIOs  Failed.\n");
    printf("GetProcAddress for JTAG_SetGPIOs  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagGetGPIOs = (jtagGetGPIOsPtr) GetProcAddress(hLib, "JTAG_GetGPIOs");
  jtagGetGPIOs = (jtagGetGPIOsPtr) GetProcAddress(hLib, "JTAG_GetGPIOs");
  if (jtagGetGPIOs == NULL) {
  if (jtagGetGPIOs == NULL) {
    printf("GetProcAddress for JTAG_GetGPIOs  Failed.\n");
    printf("GetProcAddress for JTAG_GetGPIOs  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagWrite = (jtagWritePtr) GetProcAddress(hLib, "JTAG_Write");
  jtagWrite = (jtagWritePtr) GetProcAddress(hLib, "JTAG_Write");
  if (jtagWrite == NULL) {
  if (jtagWrite == NULL) {
    printf("GetProcAddress for JTAG_Write  Failed.\n");
    printf("GetProcAddress for JTAG_Write  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagRead = (jtagReadPtr) GetProcAddress(hLib, "JTAG_Read");
  jtagRead = (jtagReadPtr) GetProcAddress(hLib, "JTAG_Read");
  if (jtagRead == NULL) {
  if (jtagRead == NULL) {
    printf("GetProcAddress for JTAG_Read  Failed.\n");
    printf("GetProcAddress for JTAG_Read  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagWriteRead = (jtagWriteReadPtr) GetProcAddress(hLib, "JTAG_WriteRead");
  jtagWriteRead = (jtagWriteReadPtr) GetProcAddress(hLib, "JTAG_WriteRead");
  if (jtagWriteRead == NULL) {
  if (jtagWriteRead == NULL) {
    printf("GetProcAddress for JTAG_WriteRead  Failed.\n");
    printf("GetProcAddress for JTAG_WriteRead  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagAddWriteCmd = (jtagAddWriteCmdPtr) GetProcAddress(hLib, "JTAG_AddWriteCmd");
  jtagAddWriteCmd = (jtagAddWriteCmdPtr) GetProcAddress(hLib, "JTAG_AddWriteCmd");
  if (jtagAddWriteCmd == NULL) {
  if (jtagAddWriteCmd == NULL) {
    printf("GetProcAddress for JTAG_AddWriteCmd  Failed.\n");
    printf("GetProcAddress for JTAG_AddWriteCmd  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagAddReadCmd = (jtagAddReadCmdPtr) GetProcAddress(hLib, "JTAG_AddReadCmd");
  jtagAddReadCmd = (jtagAddReadCmdPtr) GetProcAddress(hLib, "JTAG_AddReadCmd");
  if (jtagAddReadCmd == NULL) {
  if (jtagAddReadCmd == NULL) {
    printf("GetProcAddress for JTAG_AddReadCmd  Failed.\n");
    printf("GetProcAddress for JTAG_AddReadCmd  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagAddWriteReadCmd = (jtagAddWriteReadCmdPtr) GetProcAddress(hLib, "JTAG_AddWriteReadCmd");
  jtagAddWriteReadCmd = (jtagAddWriteReadCmdPtr) GetProcAddress(hLib, "JTAG_AddWriteReadCmd");
  if (jtagAddWriteReadCmd == NULL) {
  if (jtagAddWriteReadCmd == NULL) {
    printf("GetProcAddress for JTAG_AddWriteReadCmd  Failed.\n");
    printf("GetProcAddress for JTAG_AddWriteReadCmd  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagClearDeviceCmdSequence = (jtagClearDeviceCmdSequencePtr) GetProcAddress(hLib, "JTAG_ClearDeviceCmdSequence");
  jtagClearDeviceCmdSequence = (jtagClearDeviceCmdSequencePtr) GetProcAddress(hLib, "JTAG_ClearDeviceCmdSequence");
  if (jtagClearDeviceCmdSequence == NULL) {
  if (jtagClearDeviceCmdSequence == NULL) {
    printf("GetProcAddress for  Failed.\n JTAG_ClearDeviceCmdSequence");
    printf("GetProcAddress for  Failed.\n JTAG_ClearDeviceCmdSequence");
    return -1;
    return -1;
  }
  }
 
 
  jtagAddDeviceReadCmd = (jtagAddDeviceReadCmdPtr) GetProcAddress(hLib, "JTAG_AddDeviceReadCmd");
  jtagAddDeviceReadCmd = (jtagAddDeviceReadCmdPtr) GetProcAddress(hLib, "JTAG_AddDeviceReadCmd");
  if (jtagAddDeviceReadCmd == NULL) {
  if (jtagAddDeviceReadCmd == NULL) {
    printf("GetProcAddress for  Failed JTAG_AddDeviceReadCmd.\n");
    printf("GetProcAddress for  Failed JTAG_AddDeviceReadCmd.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagAddDeviceWriteReadCmd = (jtagAddDeviceWriteReadCmdPtr) GetProcAddress(hLib, "JTAG_AddDeviceWriteReadCmd");
  jtagAddDeviceWriteReadCmd = (jtagAddDeviceWriteReadCmdPtr) GetProcAddress(hLib, "JTAG_AddDeviceWriteReadCmd");
  if (jtagAddDeviceWriteReadCmd == NULL) {
  if (jtagAddDeviceWriteReadCmd == NULL) {
    printf("GetProcAddress for  Failed.\n JTAG_AddDeviceWriteReadCmd");
    printf("GetProcAddress for  Failed.\n JTAG_AddDeviceWriteReadCmd");
    return -1;
    return -1;
  }
  }
 
 
  jtagExecuteCmdSequence = (jtagExecuteCmdSequencePtr) GetProcAddress(hLib, "JTAG_ExecuteCmdSequence");
  jtagExecuteCmdSequence = (jtagExecuteCmdSequencePtr) GetProcAddress(hLib, "JTAG_ExecuteCmdSequence");
  if (jtagExecuteCmdSequence == NULL) {
  if (jtagExecuteCmdSequence == NULL) {
    printf("GetProcAddress for  Failed JTAG_ExecuteCmdSequence.\n");
    printf("GetProcAddress for  Failed JTAG_ExecuteCmdSequence.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagGetDllVersion = (jtagGetDllVersionPtr) GetProcAddress(hLib, "JTAG_GetDllVersion");
  jtagGetDllVersion = (jtagGetDllVersionPtr) GetProcAddress(hLib, "JTAG_GetDllVersion");
  if (jtagGetDllVersion == NULL) {
  if (jtagGetDllVersion == NULL) {
    printf("GetProcAddress for JTAG_GetDllVersion  Failed.\n");
    printf("GetProcAddress for JTAG_GetDllVersion  Failed.\n");
    return -1;
    return -1;
  }
  }
 
 
  jtagGetErrorCodeString = (jtagGetErrorCodeStringPtr) GetProcAddress(hLib, "JTAG_GetErrorCodeString");
  jtagGetErrorCodeString = (jtagGetErrorCodeStringPtr) GetProcAddress(hLib, "JTAG_GetErrorCodeString");
  if (jtagGetErrorCodeString == NULL) {
  if (jtagGetErrorCodeString == NULL) {
    printf("GetProcAddress for  Failed JTAG_GetErrorCodeString.\n");
    printf("GetProcAddress for  Failed JTAG_GetErrorCodeString.\n");
    return -1;
    return -1;
  }
  }
 
 
  //   = (Ptr) GetProcAddress(hLib, "");  
  //   = (Ptr) GetProcAddress(hLib, "");  
  //if ( == NULL) {
  //if ( == NULL) {
  //  printf("GetProcAddress for  Failed.\n");
  //  printf("GetProcAddress for  Failed.\n");
  //  return -1;
  //  return -1;
  // }
  // }
 
 
  return 0;
  return 0;
 
 
}
}
 
 
 
 
// Global USB JTAG device handle
// Global USB JTAG device handle
FTC_HANDLE ftHandle;
FTC_HANDLE ftHandle;
 
 
FTC_STATUS
FTC_STATUS
FT2232_USB_JTAG_WriteDataToExternalDevice(
FT2232_USB_JTAG_WriteDataToExternalDevice(
                                          //FTC_HANDLE ftHandle, 
                                          //FTC_HANDLE ftHandle, 
                                          BOOL bInstructionTestData,
                                          BOOL bInstructionTestData,
                                          DWORD dwNumBitsToWrite,
                                          DWORD dwNumBitsToWrite,
                                          PWriteDataByteBuffer pWriteDataBuffer,
                                          PWriteDataByteBuffer pWriteDataBuffer,
                                          DWORD dwNumBytesToWrite,
                                          DWORD dwNumBytesToWrite,
                                          DWORD dwTapControllerState)
                                          DWORD dwTapControllerState)
{
{
  // Return the appropritae call to the Windows driver
  // Return the appropritae call to the Windows driver
  return (jtagWrite)(
  return (jtagWrite)(
                     ftHandle,
                     ftHandle,
                     bInstructionTestData,
                     bInstructionTestData,
                     dwNumBitsToWrite,
                     dwNumBitsToWrite,
                     pWriteDataBuffer,
                     pWriteDataBuffer,
                     dwNumBytesToWrite,
                     dwNumBytesToWrite,
                     dwTapControllerState);
                     dwTapControllerState);
 
 
}
}
 
 
 
 
// Read data from external device
// Read data from external device
FTC_STATUS
FTC_STATUS
FT2232_USB_JTAG_ReadDataFromExternalDevice(
FT2232_USB_JTAG_ReadDataFromExternalDevice(
                                           //FTC_HANDLE ftHandle, 
                                           //FTC_HANDLE ftHandle, 
                                            BOOL bInstructionTestData,
                                            BOOL bInstructionTestData,
                                            DWORD dwNumBitsToRead,
                                            DWORD dwNumBitsToRead,
                                            PReadDataByteBuffer pReadDataBuffer,
                                            PReadDataByteBuffer pReadDataBuffer,
                                            LPDWORD lpdwNumBytesReturned,
                                            LPDWORD lpdwNumBytesReturned,
                                            DWORD dwTapControllerState)
                                            DWORD dwTapControllerState)
 
 
{
{
  return (jtagRead)(
  return (jtagRead)(
                    ftHandle,
                    ftHandle,
                    bInstructionTestData,
                    bInstructionTestData,
                    dwNumBitsToRead,
                    dwNumBitsToRead,
                    pReadDataBuffer,
                    pReadDataBuffer,
                    lpdwNumBytesReturned,
                    lpdwNumBytesReturned,
                    dwTapControllerState);
                    dwTapControllerState);
 
 
}
}
 
 
 
 
 
 
 
 
 
 
 
 
// Write Read
// Write Read
FTC_STATUS
FTC_STATUS
FT2232_USB_JTAG_WriteReadDataToFromExternalDevice(
FT2232_USB_JTAG_WriteReadDataToFromExternalDevice(
                                                  //FTC_HANDLE ftHandle, 
                                                  //FTC_HANDLE ftHandle, 
                                                  BOOL bInstructionTestData,
                                                  BOOL bInstructionTestData,
                                                  DWORD dwNumBitsToWriteRead,
                                                  DWORD dwNumBitsToWriteRead,
                                                  PWriteDataByteBuffer pWriteDataBuffer,
                                                  PWriteDataByteBuffer pWriteDataBuffer,
                                                  DWORD dwNumBytesToWrite,
                                                  DWORD dwNumBytesToWrite,
                                                  PReadDataByteBuffer pReadDataBuffer,
                                                  PReadDataByteBuffer pReadDataBuffer,
                                                  LPDWORD lpdwNumBytesReturned,
                                                  LPDWORD lpdwNumBytesReturned,
                                                  DWORD dwTapControllerState)
                                                  DWORD dwTapControllerState)
{
{
 
 
 return (jtagWriteRead)(
 return (jtagWriteRead)(
                        ftHandle,
                        ftHandle,
                        bInstructionTestData,
                        bInstructionTestData,
                        dwNumBitsToWriteRead,
                        dwNumBitsToWriteRead,
                        pWriteDataBuffer,
                        pWriteDataBuffer,
                        dwNumBytesToWrite,
                        dwNumBytesToWrite,
                        pReadDataBuffer,
                        pReadDataBuffer,
                        lpdwNumBytesReturned,
                        lpdwNumBytesReturned,
                        dwTapControllerState);
                        dwTapControllerState);
 
 
}
}
 
 
 
 
 
 
// Close device
// Close device
FTC_STATUS
FTC_STATUS
FT2232_USB_JTAG_CloseDevice()
FT2232_USB_JTAG_CloseDevice()
{
{
  return (jtagClose)(ftHandle);
  return (jtagClose)(ftHandle);
}
}
 
 
 
void
 
reinit_usb_jtag(void)
 
{
 
  FTC_STATUS Status = FTC_SUCCESS;
 
  if (DEBUG_USB_DRVR_FUNCS) printf("win_usb_driver_calls: reset_usb_jtag() - ");
 
  Status = (jtagInitDevice)(ftHandle, 0);
 
  if (DEBUG_USB_DRVR_FUNCS) printf("return Status: %d\n", (int) Status);
 
}
 
 
// Set clock frequency
// Set clock frequency
// Frequency = 12Mhz/((1+divisor)*2), 
// Frequency = 12Mhz/((1+divisor)*2), 
// divisor=1000 => Freq=5995Hz~=6kHz, divisor=500=>Freq=12kHz
// divisor=1000 => Freq=5995Hz~=6kHz, divisor=500=>Freq=12kHz
#define USB_JTAG_CLK_DIVIDER 0
#define USB_JTAG_CLK_DIVIDER 0
 
 
int init_usb_jtag()
int init_usb_jtag()
{
{
  FTC_STATUS Status = FTC_SUCCESS;
  FTC_STATUS Status = FTC_SUCCESS;
  DWORD dwNumDevices = 0;
  DWORD dwNumDevices = 0;
  char szDeviceName[100];
  char szDeviceName[100];
  DWORD dwLocationID = 0;
  DWORD dwLocationID = 0;
  // Made global: FTC_HANDLE ftHandle;
  // Made global: FTC_HANDLE ftHandle;
  DWORD dwClockFrequencyHz = 0;
  DWORD dwClockFrequencyHz = 0;
  FTC_INPUT_OUTPUT_PINS LowInputOutputPinsData;
  FTC_INPUT_OUTPUT_PINS LowInputOutputPinsData;
  FTC_INPUT_OUTPUT_PINS HighInputOutputPinsData;
  FTC_INPUT_OUTPUT_PINS HighInputOutputPinsData;
  FTC_LOW_HIGH_PINS LowPinsInputData;
  FTC_LOW_HIGH_PINS LowPinsInputData;
  FTC_LOW_HIGH_PINS HighPinsInputData;
  FTC_LOW_HIGH_PINS HighPinsInputData;
  BOOL bPerformCommandSequence = false;
  BOOL bPerformCommandSequence = false;
 
 
  DWORD dwLoopCntr = 0;
  DWORD dwLoopCntr = 0;
  char szDllVersion[10];
  char szDllVersion[10];
 
 
  Status = (jtagGetNumDevices)(&dwNumDevices);
  Status = (jtagGetNumDevices)(&dwNumDevices);
  if (DEBUG_USB_DRVR_FUNCS)
  if (DEBUG_USB_DRVR_FUNCS)
    printf("JTAG_GetNumDevices returned Status: 0x%x and %d devices\n",
    printf("JTAG_GetNumDevices returned Status: 0x%x and %d devices\n",
                    Status, dwNumDevices);
                    Status, dwNumDevices);
 
 
 
 
 
 
  if (dwNumDevices == 0)
  if (dwNumDevices == 0)
    {
    {
      printf("Error: USB debug cable not detected\nPlease ensure the device is attached and correctly installed\n\n");
      printf("Error: USB debug cable not detected\nPlease ensure the device is attached and correctly installed\n\n");
      exit(-1);
      exit(-1);
    }
    }
 
 
 
 
  Status = (jtagGetDllVersion)(szDllVersion, 10);
  Status = (jtagGetDllVersion)(szDllVersion, 10);
 
 
  if (DEBUG_USB_DRVR_FUNCS)
  if (DEBUG_USB_DRVR_FUNCS)
    printf("JTAG_GetDLLVersion returned Status: 0x%x and version %s\n",
    printf("JTAG_GetDLLVersion returned Status: 0x%x and version %s\n",
                     Status, szDllVersion);
                     Status, szDllVersion);
 
 
 
 
  // To do: Iterate through dwNumDevices by index number ,looking for the ORSoC Device, "ORSoC OpenRISC debug cable A\0",
  // To do: Iterate through dwNumDevices by index number ,looking for the ORSoC Device, "ORSoC OpenRISC debug cable A\0",
 
 
  if ((Status == FTC_SUCCESS) && (dwNumDevices > 0))
  if ((Status == FTC_SUCCESS) && (dwNumDevices > 0))
    {
    {
      if (dwNumDevices == 1)
      if (dwNumDevices == 1)
        {
        {
          Status = (jtagGetDeviceNameLocID)(0,szDeviceName,50, &dwLocationID);
          Status = (jtagGetDeviceNameLocID)(0,szDeviceName,50, &dwLocationID);
 
 
          if (DEBUG_USB_DRVR_FUNCS)
          if (DEBUG_USB_DRVR_FUNCS)
            printf("JTAG_GetDeviceNameLocID: %s at: 0x%x\n",
            printf("JTAG_GetDeviceNameLocID: %s at: 0x%x\n",
                   szDeviceName, dwLocationID);
                   szDeviceName, dwLocationID);
 
 
          if (Status == FTC_SUCCESS)
          if (Status == FTC_SUCCESS)
            {
            {
              Status = (jtagOpenEx)(szDeviceName, dwLocationID, &ftHandle);
              Status = (jtagOpenEx)(szDeviceName, dwLocationID, &ftHandle);
 
 
            }
            }
        }
        }
      else
      else
        {
        {
          if (dwNumDevices == 2)
          if (dwNumDevices == 2)
            {
            {
              Status=(jtagGetDeviceNameLocID)(1,szDeviceName,50,&dwLocationID);
              Status=(jtagGetDeviceNameLocID)(1,szDeviceName,50,&dwLocationID);
 
 
              if (Status == FTC_SUCCESS)
              if (Status == FTC_SUCCESS)
                {
                {
                  Status = (jtagOpenEx)(szDeviceName, dwLocationID, &ftHandle);
                  Status = (jtagOpenEx)(szDeviceName, dwLocationID, &ftHandle);
                }
                }
            }
            }
        }
        }
    }
    }
 
 
 
 
  if ((Status == FTC_SUCCESS) && (dwNumDevices > 0))
  if ((Status == FTC_SUCCESS) && (dwNumDevices > 0))
    {
    {
      Status = (jtagInitDevice)(ftHandle, 0);
      Status = (jtagInitDevice)(ftHandle, 0);
 
 
      // Set clock frequency
      // Set clock frequency
      // Frequency = 12Mhz/((1+divisor)*2), 
      // Frequency = 12Mhz/((1+divisor)*2), 
      // divisor=1000 => Freq=5995Hz~=6kHz, divisor=500=>Freq=12kHz
      // divisor=1000 => Freq=5995Hz~=6kHz, divisor=500=>Freq=12kHz
      if (Status == FTC_SUCCESS)
      if (Status == FTC_SUCCESS)
        Status = (jtagSetClock)(ftHandle, USB_JTAG_CLK_DIVIDER,
        Status = (jtagSetClock)(ftHandle, USB_JTAG_CLK_DIVIDER,
                                &dwClockFrequencyHz);
                                &dwClockFrequencyHz);
 
 
 
 
      if (Status == FTC_SUCCESS){
      if (Status == FTC_SUCCESS){
        printf("USB JTAG interface initialised\n");
        printf("USB JTAG interface initialised\n");
        Status = (jtagGetClock)(5, &dwClockFrequencyHz);
        Status = (jtagGetClock)(5, &dwClockFrequencyHz);
      }
      }
 
 
      if (Status == FTC_SUCCESS)
      if (Status == FTC_SUCCESS)
        { // true=output, false=input
        { // true=output, false=input
          LowInputOutputPinsData.bPin1InputOutputState = true; // ADBUS4 - 
          LowInputOutputPinsData.bPin1InputOutputState = true; // ADBUS4 - 
          // set ADBUS4 to output 0 to enable JTAG buffers on Olimex devices
          // set ADBUS4 to output 0 to enable JTAG buffers on Olimex devices
          LowInputOutputPinsData.bPin2InputOutputState = true; //ADBUS5
          LowInputOutputPinsData.bPin2InputOutputState = true; //ADBUS5
          LowInputOutputPinsData.bPin3InputOutputState = true;
          LowInputOutputPinsData.bPin3InputOutputState = true;
          LowInputOutputPinsData.bPin4InputOutputState = true;
          LowInputOutputPinsData.bPin4InputOutputState = true;
          //ADBUS4 = 0 (enable JTAG buffers on Olimex devices)
          //ADBUS4 = 0 (enable JTAG buffers on Olimex devices)
          LowInputOutputPinsData.bPin1LowHighState = false; // ADBUS4
          LowInputOutputPinsData.bPin1LowHighState = false; // ADBUS4
          LowInputOutputPinsData.bPin2LowHighState = false; // ADBUS5
          LowInputOutputPinsData.bPin2LowHighState = false; // ADBUS5
          LowInputOutputPinsData.bPin3LowHighState = true; // ADBUS6
          LowInputOutputPinsData.bPin3LowHighState = true; // ADBUS6
          LowInputOutputPinsData.bPin4LowHighState = true; // ADBUS7
          LowInputOutputPinsData.bPin4LowHighState = true; // ADBUS7
 
 
          HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
          HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
          HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
          HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
          HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
          HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
          HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
          HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
          HighInputOutputPinsData.bPin1LowHighState = true; // ACBUS0
          HighInputOutputPinsData.bPin1LowHighState = true; // ACBUS0
          HighInputOutputPinsData.bPin2LowHighState = true; // ACBUS1
          HighInputOutputPinsData.bPin2LowHighState = true; // ACBUS1
          HighInputOutputPinsData.bPin3LowHighState = true; // ACBUS2
          HighInputOutputPinsData.bPin3LowHighState = true; // ACBUS2
            HighInputOutputPinsData.bPin4LowHighState =true; // ACBUS3
            HighInputOutputPinsData.bPin4LowHighState =true; // ACBUS3
 
 
          Status = (jtagSetGPIOs)(ftHandle, true, &LowInputOutputPinsData,
          Status = (jtagSetGPIOs)(ftHandle, true, &LowInputOutputPinsData,
                                        true, &HighInputOutputPinsData);
                                        true, &HighInputOutputPinsData);
 
 
          if (Status == FTC_SUCCESS)
          if (Status == FTC_SUCCESS)
            Status = (jtagGetGPIOs)(ftHandle, true, &LowPinsInputData,
            Status = (jtagGetGPIOs)(ftHandle, true, &LowPinsInputData,
                                    true, &HighPinsInputData);
                                    true, &HighPinsInputData);
 
 
          if (DEBUG_USB_DRVR_FUNCS)
          if (DEBUG_USB_DRVR_FUNCS)
            printf("JTAG low gpio pins values: (ADBUS7-ADBUS4):%x%x%x%x\n",
            printf("JTAG low gpio pins values: (ADBUS7-ADBUS4):%x%x%x%x\n",
                   (LowPinsInputData.bPin4LowHighState==true),
                   (LowPinsInputData.bPin4LowHighState==true),
                   (LowPinsInputData.bPin3LowHighState==true),
                   (LowPinsInputData.bPin3LowHighState==true),
                   (LowPinsInputData.bPin2LowHighState==true),
                   (LowPinsInputData.bPin2LowHighState==true),
                   (LowPinsInputData.bPin1LowHighState==true));
                   (LowPinsInputData.bPin1LowHighState==true));
 
 
          if (DEBUG_USB_DRVR_FUNCS)
          if (DEBUG_USB_DRVR_FUNCS)
            printf("JTAG high gpio pins values: (ACBUS3-ACBUS0): %x%x%x%x\n",
            printf("JTAG high gpio pins values: (ACBUS3-ACBUS0): %x%x%x%x\n",
                   (HighPinsInputData.bPin4LowHighState==true),
                   (HighPinsInputData.bPin4LowHighState==true),
                   (HighPinsInputData.bPin3LowHighState==true),
                   (HighPinsInputData.bPin3LowHighState==true),
                   (HighPinsInputData.bPin2LowHighState==true),
                   (HighPinsInputData.bPin2LowHighState==true),
                   (HighPinsInputData.bPin1LowHighState==true));
                   (HighPinsInputData.bPin1LowHighState==true));
        }
        }
    }
    }
 
 
  if (Status == FTC_SUCCESS)
  if (Status == FTC_SUCCESS)
    return 0;
    return 0;
  else
  else
    return 1;
    return 1;
 
 
}
}
 
 

powered by: WebSVN 2.1.0

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