This is an automated email from Gerrit.

Rob Brown (r...@cobbleware.com) just uploaded a new patch set to Gerrit, which 
you can find at http://openocd.zylin.com/2005

-- gerrit

commit d085c445513c17dfc83202c2ce3b565b8d9908ed
Author: Rob Brown <r...@cobbleware.com>
Date:   Sun Mar 2 22:55:53 2014 +1300

    topic: Use ftd2xx DLL on windows
    
    OpenOCD binaries which include the static FTDI library can't be
    distributed. This patch adds the "--with-ftd2xx-lib=shared" configure
    option for Windows, to produce a binary that will use the FTDI library
    through the DLL that is installed with FTDI drivers. The resulting
    binary does not include any FTDI binary code and so can be distributed
    without running afoul of the GPL.
    
    Whether this is a desirable thing is open to debate; the libftdi driver is
    getting better all the time. At the moment though, it seems that FTD2XX
    has a performance advantage.
    
    I personally use the FTDI driver for my JTAG adapters because I also use
    other software (Rowley CrossWorks) which needs that driver. I couldn't get
    the FTDI driver and libftdi to coexist which may be my own incompetence,
    but in any case, there may be other users for whom the FTDI driver is
    preferable, and I think it would be good to enable a binary OpenOCD
    download that will work for those users.
    
    Change-Id: I7c4fc576f14369172fe35d61445619e33b7a52a2
    Signed-off-by: Rob Brown <r...@cobbleware.com>

diff --git a/configure.ac b/configure.ac
index 73f7bef..e44045b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -140,6 +140,7 @@ build_bitq=no
 is_cygwin=no
 is_mingw=no
 is_win32=no
+is_win32_ftd2xx_dll=no
 is_darwin=no
 
 # guess-rev.sh only exists in the repository, not in the released archives
@@ -214,13 +215,14 @@ m4_define([HIDAPI_ADAPTERS],
        [[[cmsis_dap], [CMSIS-DAP Compliant Debugger], [CMSIS_DAP]]])
 
 #========================================
-# FTD2XXX support comes in 4 forms.
-#    (1) win32 - via a zip file
-#    (2) linux - via a tar file
-#    (3) linux/cygwin/mingw - via libftdi
-#    (4) darwin - installed under /usr/local
+# FTD2XXX support comes in 5 forms.
+#    (1) win32 - via a zip file (static library)
+#    (2) win32 - via a zip file (loading ftd2xx.dll at runtime)
+#    (3) linux - via a tar file
+#    (4) linux/cygwin/mingw - via libftdi
+#    (5) darwin - installed under /usr/local
 #
-# In case (1) and (2) we need to know where the package was unpacked.
+# In case (1), (2), and (3) we need to know where the package was unpacked.
 
 AC_ARG_WITH(ftd2xx-win32-zipdir,
   AS_HELP_STRING([--with-ftd2xx-win32-zipdir],[Where (CYGWIN/MINGW) the zip 
file from ftdichip.com was unpacked (default=search)]),
@@ -785,7 +787,7 @@ then
 fi
 
 if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx = yes -o 
$build_usb_blaster_ftd2xx = yes -o $build_openjtag_ftd2xx = yes; then
-  AC_MSG_CHECKING([for ftd2xx.lib exists (win32)])
+  AC_MSG_CHECKING([whether ftd2xx library files exist (win32)])
 
   # if we are given a zipdir...
   if test "${with_ftd2xx_win32_zipdir+set}" = set
@@ -797,6 +799,7 @@ if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx 
= yes -o $build_usb_b
     fi
     CFLAGS="$CFLAGS -I$with_ftd2xx_win32_zipdir"
 
+    if test $with_ftd2xx_lib = static; then
     # And calculate the LDFLAGS for the machine
     case "$host_cpu" in
     i?86|x86_32)
@@ -816,11 +819,22 @@ if test $build_ft2232_ftd2xx = yes -o 
$build_presto_ftd2xx = yes -o $build_usb_b
     if test ! -f $f ; then
          AC_MSG_ERROR([Library: $f not found])
     fi
+    fi # with_ftd2xx_lib = static
+    AC_MSG_RESULT([looks OK])
   else
+  AC_MSG_RESULT([not found.])
+  if test $with_ftd2xx_lib = static; then
     LIBS="$LIBS -lftd2xx"
-    AC_MSG_WARN([ASSUMPTION: The (win32) FTDICHIP.COM files: ftd2xx.h and 
ftd2xx.lib are in a proper place])
+    AC_MSG_WARN([ASSUMPTION: The (win32) FTDICHIP.COM files: ftd2xx.h and 
ftd2xx.lib will be found during the build])
+  else
+    AC_MSG_WARN([ASSUMPTION: The (win32) FTDICHIP.COM file: ftd2xx.h will be 
found during the build])
+  fi
   fi
 fi
+if test $with_ftd2xx_lib = shared; then
+  AC_DEFINE([BUILD_FT2232_WINDOWS_FTD2XX_DLL], [1], [1 if you want ftd2xx 
ft2232 through the DLL.])
+  is_win32_ftd2xx_dll=yes
+fi
 fi # win32
 
 if test $is_darwin = yes ; then
@@ -832,6 +846,9 @@ if test "${with_ftd2xx_linux_tardir+set}" = set
 then
    AC_MSG_ERROR([The option: with_ftd2xx_linux_tardir is for LINUX only.])
 fi
+if test $with_ftd2xx_lib = shared; then
+   AC_MSG_ERROR([The option: --with-ftd2xx_lib=shared is for Linux and win32 
only])
+fi
 
 if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx = yes -o 
$build_usb_blaster_ftd2xx = yes ; then
    AC_MSG_CHECKING([for libftd2xx.a (darwin)])
@@ -922,7 +939,6 @@ if test $build_ft2232_ftd2xx = yes -o $build_presto_ftd2xx 
= yes -o $build_usb_b
 # Before we go any further - make sure we can *BUILD* and *RUN*
 # a simple app with the "ftd2xx.lib" file - in what ever form we where given
 # We should be able to compile, link and run this test program now
-AC_MSG_CHECKING([whether ftd2xx library works])
 
 #
 # Save the LDFLAGS for later..
@@ -933,6 +949,24 @@ _CFLAGS=`eval echo $CFLAGS`
 LDFLAGS=$_LDFLAGS
 CFLAGS=$_CFLAGS
 
+AC_MSG_CHECKING([for ftd2xx.h])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include "confdefs.h"
+#if IS_WIN32
+#include "windows.h"
+#endif
+#include <stdio.h>
+#include <ftd2xx.h>
+
+DWORD x = FT_OK;
+    ]], [])], [
+    AC_MSG_RESULT([yes])
+  ], [
+    AC_MSG_ERROR([ftd2xx.h is not usable.])
+  ])
+
+if test $is_win32_ftd2xx_dll = no; then
+AC_MSG_CHECKING([whether ftd2xx library works])
 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
 #include "confdefs.h"
 #if IS_WIN32
@@ -950,6 +984,7 @@ AC_RUN_IFELSE([AC_LANG_PROGRAM([[
   ], [
     AC_MSG_RESULT([Skipping as we are cross-compiling])
   ])
+fi
 
 AC_MSG_CHECKING([for ftd2xx highspeed device support])
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
@@ -1159,6 +1194,7 @@ AM_CONDITIONAL([BCM2835GPIO], [test $build_bcm2835gpio = 
yes])
 AM_CONDITIONAL([BITBANG], [test $build_bitbang = yes])
 AM_CONDITIONAL([FT2232_LIBFTDI], [test $build_ft2232_libftdi = yes])
 AM_CONDITIONAL([FT2232_DRIVER], [test $build_ft2232_ftd2xx = yes -o 
$build_ft2232_libftdi = yes])
+AM_CONDITIONAL([FT2232_DLL], [test $is_win32_ftd2xx_dll = yes])
 AM_CONDITIONAL([USB_BLASTER_LIBFTDI], [test $build_usb_blaster_libftdi = yes])
 AM_CONDITIONAL([USB_BLASTER_FTD2XX], [test $build_usb_blaster_ftd2xx = yes])
 AM_CONDITIONAL([JTAG_VPI], [test $build_jtag_vpi = yes -o $build_jtag_vpi = 
yes])
diff --git a/src/jtag/drivers/Makefile.am b/src/jtag/drivers/Makefile.am
index 72fbb34..47433ab 100644
--- a/src/jtag/drivers/Makefile.am
+++ b/src/jtag/drivers/Makefile.am
@@ -45,6 +45,9 @@ endif
 if FTDI
 DRIVERFILES += ftdi.c mpsse.c
 endif
+if FT2232_DLL
+DRIVERFILES += ftd2xx_api.c
+endif
 if JTAG_VPI
 DRIVERFILES += jtag_vpi.c
 endif
diff --git a/src/jtag/drivers/ft2232.c b/src/jtag/drivers/ft2232.c
index c4a74ef..a3a1312 100644
--- a/src/jtag/drivers/ft2232.c
+++ b/src/jtag/drivers/ft2232.c
@@ -98,7 +98,7 @@
 
 /* FT2232 access library includes */
 #if BUILD_FT2232_FTD2XX == 1
-#include <ftd2xx.h>
+#include <ftd2xx_api.h>
 #include "ftd2xx_common.h"
 
 enum ftdi_interface {
@@ -524,7 +524,7 @@ static int ft2232_write(uint8_t *buf, int size, uint32_t 
*bytes_written)
 #if BUILD_FT2232_FTD2XX == 1
        FT_STATUS status;
        DWORD dw_bytes_written = 0;
-       status = FT_Write(ftdih, buf, size, &dw_bytes_written);
+       status = FTAPI_Write(ftdih, buf, size, &dw_bytes_written);
        if (status != FT_OK) {
                *bytes_written = dw_bytes_written;
                LOG_ERROR("FT_Write returned: %s", 
ftd2xx_status_string(status));
@@ -558,7 +558,7 @@ static int ft2232_read(uint8_t *buf, uint32_t size, 
uint32_t *bytes_read)
        *bytes_read = 0;
 
        while ((*bytes_read < size) && timeout--) {
-               status = FT_Read(ftdih, buf + *bytes_read, size -
+               status = FTAPI_Read(ftdih, buf + *bytes_read, size -
                                *bytes_read, &dw_bytes_read);
                if (status != FT_OK) {
                        *bytes_read = 0;
@@ -2084,7 +2084,7 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, 
int more, int *try_mor
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       status = FT_OpenEx(openex_string, openex_flags, &ftdih);
+       status = FTAPI_OpenEx(openex_string, openex_flags, &ftdih);
        if (status != FT_OK) {
                /* under Win32, the FTD2XX driver appends an "A" to the end
                 * of the description, if we tried by the desc, then
@@ -2092,7 +2092,7 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, 
int more, int *try_mor
                if (openex_string == ft2232_device_desc) {
                        /* Try the alternate method. */
                        openex_string = ft2232_device_desc_A;
-                       status = FT_OpenEx(openex_string, openex_flags, &ftdih);
+                       status = FTAPI_OpenEx(openex_string, openex_flags, 
&ftdih);
                        if (status == FT_OK) {
                                /* yea, the "alternate" method worked! */
                        } else {
@@ -2116,7 +2116,7 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, 
int more, int *try_mor
                }
                LOG_ERROR("unable to open ftdi device: %s",
                        ftd2xx_status_string(status));
-               status = FT_ListDevices(&num_devices, NULL, 
FT_LIST_NUMBER_ONLY);
+               status = FTAPI_ListDevices(&num_devices, NULL, 
FT_LIST_NUMBER_ONLY);
                if (status == FT_OK) {
                        char **desc_array = malloc(sizeof(char *) * 
(num_devices + 1));
                        uint32_t i;
@@ -2126,7 +2126,7 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, 
int more, int *try_mor
 
                        desc_array[num_devices] = NULL;
 
-                       status = FT_ListDevices(desc_array, &num_devices, 
FT_LIST_ALL | openex_flags);
+                       status = FTAPI_ListDevices(desc_array, &num_devices, 
FT_LIST_ALL | openex_flags);
 
                        if (status == FT_OK) {
                                LOG_ERROR("ListDevices: %" PRIu32, 
(uint32_t)num_devices);
@@ -2143,20 +2143,20 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t 
pid, int more, int *try_mor
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       status = FT_SetLatencyTimer(ftdih, ft2232_latency);
+       status = FTAPI_SetLatencyTimer(ftdih, ft2232_latency);
        if (status != FT_OK) {
                LOG_ERROR("unable to set latency timer: %s",
                        ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       status = FT_GetLatencyTimer(ftdih, &latency_timer);
+       status = FTAPI_GetLatencyTimer(ftdih, &latency_timer);
        if (status != FT_OK) {
                /* ftd2xx 1.04 (linux) has a bug when calling FT_GetLatencyTimer
                 * so ignore errors if using this driver version */
                DWORD dw_version;
 
-               status = FT_GetDriverVersion(ftdih, &dw_version);
+               status = FTAPI_GetDriverVersion(ftdih, &dw_version);
                LOG_ERROR("unable to get latency timer: %s",
                        ftd2xx_status_string(status));
 
@@ -2168,21 +2168,21 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t 
pid, int more, int *try_mor
        } else
                LOG_DEBUG("current latency timer: %i", latency_timer);
 
-       status = FT_SetTimeouts(ftdih, 5000, 5000);
+       status = FTAPI_SetTimeouts(ftdih, 5000, 5000);
        if (status != FT_OK) {
                LOG_ERROR("unable to set timeouts: %s",
                        ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       status = FT_SetBitMode(ftdih, 0x0b, 2);
+       status = FTAPI_SetBitMode(ftdih, 0x0b, 2);
        if (status != FT_OK) {
                LOG_ERROR("unable to enable bit i/o mode: %s",
                        ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       status = FT_GetDeviceInfo(ftdih, &ftdi_device, &deviceID,
+       status = FTAPI_GetDeviceInfo(ftdih, &ftdi_device, &deviceID,
                        SerialNumber, Description, NULL);
        if (status != FT_OK) {
                LOG_ERROR("unable to get FT_GetDeviceInfo: %s",
@@ -2208,7 +2208,7 @@ static int ft2232_purge_ftd2xx(void)
 {
        FT_STATUS status;
 
-       status = FT_Purge(ftdih, FT_PURGE_RX | FT_PURGE_TX);
+       status = FTAPI_Purge(ftdih, FT_PURGE_RX | FT_PURGE_TX);
        if (status != FT_OK) {
                LOG_ERROR("error purging ftd2xx device: %s",
                        ftd2xx_status_string(status));
@@ -2341,7 +2341,13 @@ static int ft2232_init(void)
        int retval;
        uint32_t bytes_written;
 
-       if (tap_get_tms_path_len(TAP_IRPAUSE, TAP_IRPAUSE) == 7)
+#ifdef BUILD_FT2232_WINDOWS_FTD2XX_DLL
+   if (!ftd2xx_dll_api_init()) {
+      return ERROR_JTAG_INIT_FAILED;
+   }
+#endif
+
+   if (tap_get_tms_path_len(TAP_IRPAUSE, TAP_IRPAUSE) == 7)
                LOG_DEBUG("ft2232 interface using 7 step jtag state 
transitions");
        else
                LOG_DEBUG("ft2232 interface using shortest path jtag state 
transitions");
@@ -3143,7 +3149,7 @@ static int ft2232_quit(void)
 {
 #if BUILD_FT2232_FTD2XX == 1
 
-       FT_Close(ftdih);
+       FTAPI_Close(ftdih);
 #elif BUILD_FT2232_LIBFTDI == 1
        ftdi_usb_close(&ftdic);
 
@@ -3153,7 +3159,11 @@ static int ft2232_quit(void)
        free(ft2232_buffer);
        ft2232_buffer = NULL;
 
-       return ERROR_OK;
+#ifdef BUILD_FT2232_WINDOWS_FTD2XX_DLL
+   ftd2xx_dll_api_shutdown();
+#endif
+
+   return ERROR_OK;
 }
 
 COMMAND_HANDLER(ft2232_handle_device_desc_command)
@@ -3454,7 +3464,7 @@ static int signalyzer_h_ctrl_read(int address, unsigned 
short *value);
 static int signalyzer_h_ctrl_write(int address, unsigned short value)
 {
 #if BUILD_FT2232_FTD2XX == 1
-       return FT_WriteEE(ftdih, address, value);
+       return FTAPI_WriteEE(ftdih, address, value);
 #elif BUILD_FT2232_LIBFTDI == 1
        return 0;
 #endif
@@ -3463,7 +3473,7 @@ static int signalyzer_h_ctrl_write(int address, unsigned 
short value)
 #if BUILD_FT2232_FTD2XX == 1
 static int signalyzer_h_ctrl_read(int address, unsigned short *value)
 {
-       return FT_ReadEE(ftdih, address, value);
+       return FTAPI_ReadEE(ftdih, address, value);
 }
 #endif
 
diff --git a/src/jtag/drivers/presto.c b/src/jtag/drivers/presto.c
index 45e434a..2f1fb3d 100644
--- a/src/jtag/drivers/presto.c
+++ b/src/jtag/drivers/presto.c
@@ -37,7 +37,7 @@
 
 /* PRESTO access library includes */
 #if BUILD_PRESTO_FTD2XX == 1
-#include <ftd2xx.h>
+#include "ftd2xx_api.h"
 #include "ftd2xx_common.h"
 #elif BUILD_PRESTO_LIBFTDI == 1
 #include <ftdi.h>
@@ -99,7 +99,7 @@ static int presto_write(uint8_t *buf, uint32_t size)
 {
 #if BUILD_PRESTO_FTD2XX == 1
        DWORD ftbytes;
-       presto->status = FT_Write(presto->handle, buf, size, &ftbytes);
+       presto->status = FTAPI_Write(presto->handle, buf, size, &ftbytes);
        if (presto->status != FT_OK) {
                LOG_ERROR("FT_Write returned: %s", 
ftd2xx_status_string(presto->status));
                return ERROR_JTAG_DEVICE_ERROR;
@@ -128,7 +128,7 @@ static int presto_read(uint8_t *buf, uint32_t size)
 {
 #if BUILD_PRESTO_FTD2XX == 1
        DWORD ftbytes;
-       presto->status = FT_Read(presto->handle, buf, size, &ftbytes);
+       presto->status = FTAPI_Read(presto->handle, buf, size, &ftbytes);
        if (presto->status != FT_OK) {
                LOG_ERROR("FT_Read returned: %s", 
ftd2xx_status_string(presto->status));
                return ERROR_JTAG_DEVICE_ERROR;
@@ -190,7 +190,7 @@ static int presto_open_ftd2xx(char *req_serial)
        }
 #endif
 
-       presto->status = FT_ListDevices(&numdevs, NULL, FT_LIST_NUMBER_ONLY);
+       presto->status = FTAPI_ListDevices(&numdevs, NULL, FT_LIST_NUMBER_ONLY);
        if (presto->status != FT_OK) {
                LOG_ERROR("FT_ListDevices failed: %s", 
ftd2xx_status_string(presto->status));
                return ERROR_JTAG_DEVICE_ERROR;
@@ -198,7 +198,7 @@ static int presto_open_ftd2xx(char *req_serial)
 
        LOG_DEBUG("FTDI devices available: %" PRIu32, (uint32_t)numdevs);
        for (i = 0; i < numdevs; i++) {
-               presto->status = FT_Open(i, &(presto->handle));
+               presto->status = FTAPI_Open(i, &(presto->handle));
                if (presto->status != FT_OK) {
                        /* this is not fatal, the device may be legitimately 
open by other process,
                         *hence debug message only */
@@ -207,7 +207,7 @@ static int presto_open_ftd2xx(char *req_serial)
                }
                LOG_DEBUG("FTDI device %i open", (int)i);
 
-               presto->status = FT_GetDeviceInfo(presto->handle, &device,
+               presto->status = FTAPI_GetDeviceInfo(presto->handle, &device,
                                &vidpid, presto->serial, devname, NULL);
                if (presto->status == FT_OK) {
                        if (vidpid == PRESTO_VID_PID && (req_serial == NULL ||
@@ -218,27 +218,27 @@ static int presto_open_ftd2xx(char *req_serial)
                                        presto->status));
 
                LOG_DEBUG("FTDI device %i does not match, closing", (int)i);
-               FT_Close(presto->handle);
+               FTAPI_Close(presto->handle);
                presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE;
        }
 
        if (presto->handle == (FT_HANDLE)INVALID_HANDLE_VALUE)
                return ERROR_JTAG_DEVICE_ERROR; /* presto not open, return */
 
-       presto->status = FT_SetLatencyTimer(presto->handle, 1);
+       presto->status = FTAPI_SetLatencyTimer(presto->handle, 1);
        if (presto->status != FT_OK)
                return ERROR_JTAG_DEVICE_ERROR;
 
-       presto->status = FT_SetTimeouts(presto->handle, 100, 0);
+       presto->status = FTAPI_SetTimeouts(presto->handle, 100, 0);
        if (presto->status != FT_OK)
                return ERROR_JTAG_DEVICE_ERROR;
 
-       presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX);
+       presto->status = FTAPI_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX);
        if (presto->status != FT_OK)
                return ERROR_JTAG_DEVICE_ERROR;
 
        presto_data = 0xD0;
-       presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes);
+       presto->status = FTAPI_Write(presto->handle, &presto_data, 1, &ftbytes);
        if (presto->status != FT_OK)
                return ERROR_JTAG_DEVICE_ERROR;
 
@@ -246,48 +246,48 @@ static int presto_open_ftd2xx(char *req_serial)
         * under Linux for unknown reason,
         * probably a bug in library threading */
        usleep(100000);
-       presto->status = FT_Read(presto->handle, &presto_data, 1, &ftbytes);
+       presto->status = FTAPI_Read(presto->handle, &presto_data, 1, &ftbytes);
        if (presto->status != FT_OK)
                return ERROR_JTAG_DEVICE_ERROR;
 
        if (ftbytes != 1) {
                LOG_DEBUG("PRESTO reset");
 
-               presto->status = FT_Purge(presto->handle, FT_PURGE_TX | 
FT_PURGE_RX);
+               presto->status = FTAPI_Purge(presto->handle, FT_PURGE_TX | 
FT_PURGE_RX);
                if (presto->status != FT_OK)
                        return ERROR_JTAG_DEVICE_ERROR;
-               presto->status = FT_SetBitMode(presto->handle, 0x80, 1);
+               presto->status = FTAPI_SetBitMode(presto->handle, 0x80, 1);
                if (presto->status != FT_OK)
                        return ERROR_JTAG_DEVICE_ERROR;
-               presto->status = FT_SetBaudRate(presto->handle, 9600);
+               presto->status = FTAPI_SetBaudRate(presto->handle, 9600);
                if (presto->status != FT_OK)
                        return ERROR_JTAG_DEVICE_ERROR;
 
                presto_data = 0;
                for (i = 0; i < 4 * 62; i++) {
-                       presto->status = FT_Write(presto->handle, &presto_data, 
1, &ftbytes);
+                       presto->status = FTAPI_Write(presto->handle, 
&presto_data, 1, &ftbytes);
                        if (presto->status != FT_OK)
                                return ERROR_JTAG_DEVICE_ERROR;
                }
                usleep(100000);
 
-               presto->status = FT_SetBitMode(presto->handle, 0x00, 0);
+               presto->status = FTAPI_SetBitMode(presto->handle, 0x00, 0);
                if (presto->status != FT_OK)
                        return ERROR_JTAG_DEVICE_ERROR;
 
-               presto->status = FT_Purge(presto->handle, FT_PURGE_TX | 
FT_PURGE_RX);
+               presto->status = FTAPI_Purge(presto->handle, FT_PURGE_TX | 
FT_PURGE_RX);
                if (presto->status != FT_OK)
                        return ERROR_JTAG_DEVICE_ERROR;
 
                presto_data = 0xD0;
-               presto->status = FT_Write(presto->handle, &presto_data, 1, 
&ftbytes);
+               presto->status = FTAPI_Write(presto->handle, &presto_data, 1, 
&ftbytes);
                if (presto->status != FT_OK)
                        return ERROR_JTAG_DEVICE_ERROR;
 
                /* delay between first write/read turnaround (after purge?) 
necessary under Linux for unknown reason,
                   probably a bug in library threading */
                usleep(100000);
-               presto->status = FT_Read(presto->handle, &presto_data, 1, 
&ftbytes);
+               presto->status = FTAPI_Read(presto->handle, &presto_data, 1, 
&ftbytes);
                if (presto->status != FT_OK)
                        return ERROR_JTAG_DEVICE_ERROR;
 
@@ -297,11 +297,11 @@ static int presto_open_ftd2xx(char *req_serial)
                }
        }
 
-       presto->status = FT_SetTimeouts(presto->handle, 0, 0);
+       presto->status = FTAPI_SetTimeouts(presto->handle, 0, 0);
        if (presto->status != FT_OK)
                return ERROR_JTAG_DEVICE_ERROR;
 
-       presto->status = FT_Write(presto->handle, &presto_init_seq,
+       presto->status = FTAPI_Write(presto->handle, &presto_init_seq,
                        sizeof(presto_init_seq), &ftbytes);
 
        if (presto->status != FT_OK || ftbytes != sizeof(presto_init_seq))
@@ -411,22 +411,22 @@ static int presto_close(void)
        if (presto->handle == (FT_HANDLE)INVALID_HANDLE_VALUE)
                return result;
 
-       presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX);
+       presto->status = FTAPI_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX);
        if (presto->status != FT_OK)
                result = ERROR_JTAG_DEVICE_ERROR;
 
-       presto->status = FT_Write(presto->handle,
+       presto->status = FTAPI_Write(presto->handle,
                        &presto_init_seq,
                        sizeof(presto_init_seq),
                        &ftbytes);
        if (presto->status != FT_OK || ftbytes != sizeof(presto_init_seq))
                result = ERROR_JTAG_DEVICE_ERROR;
 
-       presto->status = FT_SetLatencyTimer(presto->handle, 16);
+       presto->status = FTAPI_SetLatencyTimer(presto->handle, 16);
        if (presto->status != FT_OK)
                result = ERROR_JTAG_DEVICE_ERROR;
 
-       presto->status = FT_Close(presto->handle);
+       presto->status = FTAPI_Close(presto->handle);
        if (presto->status != FT_OK)
                result = ERROR_JTAG_DEVICE_ERROR;
        else
@@ -755,7 +755,13 @@ static const struct command_registration 
presto_command_handlers[] = {
 
 static int presto_jtag_init(void)
 {
-       if (presto_open(presto_serial) != ERROR_OK) {
+#ifdef BUILD_FT2232_WINDOWS_FTD2XX_DLL
+   if (!ftd2xx_dll_api_init()) {
+      return ERROR_JTAG_INIT_FAILED;
+   }
+#endif
+
+   if (presto_open(presto_serial) != ERROR_OK) {
                presto_close();
                if (presto_serial != NULL)
                        LOG_ERROR("Cannot open PRESTO, serial number '%s'", 
presto_serial);
@@ -780,7 +786,11 @@ static int presto_jtag_quit(void)
                presto_serial = NULL;
        }
 
-       return ERROR_OK;
+#ifdef BUILD_FT2232_WINDOWS_FTD2XX_DLL
+   ftd2xx_dll_api_shutdown();
+#endif
+
+   return ERROR_OK;
 }
 
 struct jtag_interface presto_interface = {
diff --git a/src/jtag/drivers/usb_blaster/ublast_access_ftd2xx.c 
b/src/jtag/drivers/usb_blaster/ublast_access_ftd2xx.c
index 14351fb..eb448e6 100644
--- a/src/jtag/drivers/usb_blaster/ublast_access_ftd2xx.c
+++ b/src/jtag/drivers/usb_blaster/ublast_access_ftd2xx.c
@@ -29,7 +29,7 @@
 
 #include "ublast_access.h"
 
-#include <ftd2xx.h>
+#include "jtag/drivers/ftd2xx_api.h"
 #include "jtag/drivers/ftd2xx_common.h"
 
 static FT_HANDLE *ublast_getftdih(struct ublast_lowlevel *low)
@@ -44,7 +44,7 @@ static int ublast_ftd2xx_write(struct ublast_lowlevel *low, 
uint8_t *buf, int si
        DWORD dw_bytes_written;
        FT_HANDLE *ftdih = ublast_getftdih(low);
 
-       status = FT_Write(*ftdih, buf, size, &dw_bytes_written);
+       status = FTAPI_Write(*ftdih, buf, size, &dw_bytes_written);
        if (status != FT_OK) {
                *bytes_written = dw_bytes_written;
                LOG_ERROR("FT_Write returned: %s", 
ftd2xx_status_string(status));
@@ -61,7 +61,7 @@ static int ublast_ftd2xx_read(struct ublast_lowlevel *low, 
uint8_t *buf,
        FT_STATUS status;
        FT_HANDLE *ftdih = ublast_getftdih(low);
 
-       status = FT_Read(*ftdih, buf, size, &dw_bytes_read);
+       status = FTAPI_Read(*ftdih, buf, size, &dw_bytes_read);
        if (status != FT_OK) {
                *bytes_read = dw_bytes_read;
                LOG_ERROR("FT_Read returned: %s", ftd2xx_status_string(status));
@@ -77,7 +77,13 @@ static int ublast_ftd2xx_init(struct ublast_lowlevel *low)
        FT_HANDLE *ftdih = ublast_getftdih(low);
        uint8_t latency_timer;
 
-       LOG_INFO("usb blaster interface using FTD2XX");
+#ifdef BUILD_FT2232_WINDOWS_FTD2XX_DLL
+   if (!ftd2xx_dll_api_init()) {
+      return ERROR_JTAG_INIT_FAILED;
+   }
+#endif
+
+   LOG_INFO("usb blaster interface using FTD2XX");
        /* Open by device description */
        if (low->ublast_device_desc == NULL) {
                LOG_WARNING("no usb blaster device description specified, "
@@ -93,14 +99,14 @@ static int ublast_ftd2xx_init(struct ublast_lowlevel *low)
                            low->ublast_vid, low->ublast_pid);
        }
 #endif
-       status = FT_OpenEx(low->ublast_device_desc, FT_OPEN_BY_DESCRIPTION,
+       status = FTAPI_OpenEx(low->ublast_device_desc, FT_OPEN_BY_DESCRIPTION,
                           ftdih);
        if (status != FT_OK) {
                DWORD num_devices;
 
                LOG_ERROR("unable to open ftdi device: %s",
                          ftd2xx_status_string(status));
-               status = FT_ListDevices(&num_devices, NULL, 
FT_LIST_NUMBER_ONLY);
+               status = FTAPI_ListDevices(&num_devices, NULL, 
FT_LIST_NUMBER_ONLY);
                if (status == FT_OK) {
                        char **desc_array =
                                malloc(sizeof(char *) * (num_devices + 1));
@@ -110,7 +116,7 @@ static int ublast_ftd2xx_init(struct ublast_lowlevel *low)
                                desc_array[i] = malloc(64);
                        desc_array[num_devices] = NULL;
 
-                       status = FT_ListDevices(desc_array, &num_devices,
+                       status = FTAPI_ListDevices(desc_array, &num_devices,
                                                FT_LIST_ALL | 
FT_OPEN_BY_DESCRIPTION);
 
                        if (status == FT_OK) {
@@ -128,21 +134,21 @@ static int ublast_ftd2xx_init(struct ublast_lowlevel *low)
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       status = FT_SetLatencyTimer(*ftdih, 2);
+       status = FTAPI_SetLatencyTimer(*ftdih, 2);
        if (status != FT_OK) {
                LOG_ERROR("unable to set latency timer: %s",
                                ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       status = FT_GetLatencyTimer(*ftdih, &latency_timer);
+       status = FTAPI_GetLatencyTimer(*ftdih, &latency_timer);
        if (status != FT_OK)
                LOG_ERROR("unable to get latency timer: %s",
                                ftd2xx_status_string(status));
        else
                LOG_DEBUG("current latency timer: %i", latency_timer);
 
-       status = FT_SetBitMode(*ftdih, 0x00, 0);
+       status = FTAPI_SetBitMode(*ftdih, 0x00, 0);
        if (status != FT_OK) {
                LOG_ERROR("unable to disable bit i/o mode: %s",
                                ftd2xx_status_string(status));
@@ -155,7 +161,12 @@ static int ublast_ftd2xx_quit(struct ublast_lowlevel *low)
 {
        FT_HANDLE *ftdih = ublast_getftdih(low);
 
-       FT_Close(*ftdih);
+       FTAPI_Close(*ftdih);
+
+#ifdef BUILD_FT2232_WINDOWS_FTD2XX_DLL
+   ftd2xx_dll_api_shutdown();
+#endif
+
        return ERROR_OK;
 }
 

-- 

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to