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/2006
-- gerrit commit a7c66ae0e500a323ce78edd0fe7734fe8f4e042a Author: Rob Brown <r...@cobbleware.com> Date: Sun Mar 2 23:56:03 2014 +1300 Small updates Change-Id: I22e0fb15e5ac33bab7e75af8e7792cbab812abbf Signed-off-by: Rob Brown <r...@cobbleware.com> diff --git a/src/jtag/drivers/ft2232.c b/src/jtag/drivers/ft2232.c index a3a1312..2a8d210 100644 --- a/src/jtag/drivers/ft2232.c +++ b/src/jtag/drivers/ft2232.c @@ -2342,9 +2342,8 @@ static int ft2232_init(void) uint32_t bytes_written; #ifdef BUILD_FT2232_WINDOWS_FTD2XX_DLL - if (!ftd2xx_dll_api_init()) { - return ERROR_JTAG_INIT_FAILED; - } + if (!ftd2xx_dll_api_init()) + return ERROR_JTAG_INIT_FAILED; #endif if (tap_get_tms_path_len(TAP_IRPAUSE, TAP_IRPAUSE) == 7) diff --git a/src/jtag/drivers/ftd2xx_api.c b/src/jtag/drivers/ftd2xx_api.c new file mode 100644 index 0000000..e304804 --- /dev/null +++ b/src/jtag/drivers/ftd2xx_api.c @@ -0,0 +1,146 @@ +/************************************************************************** +* Copyright (C) 2014 by Rob Brown <r...@cobbleware.com> * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +***************************************************************************/ + +/** + * @file + * This file loads the required functions from the ftd2xx DLL file that's + * installed with FTDI drivers. + * There's a very basic reference count in case more that one driver is + * active at once; I don't know if that's possible or whether it will be + * possible in the future, but it won't hurt in any case. + * The 64-bit DLL will be loaded if possible. That will require: + * a) a 64-bit OS + * b) the 64-bit drivers from FTDI to be installed + * c) openocd.exe to be built 64-bit. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include <log.h> + +#include <windows.h> + +#include "ftd2xx_api.h" + +static bool loadSuccess = false; +static int refCount = 0; +static HMODULE hDll; + +FT_Open_t FTAPI_Open; +FT_OpenEx_t FTAPI_OpenEx; +FT_Close_t FTAPI_Close; +FT_Purge_t FTAPI_Purge; +FT_Write_t FTAPI_Write; +FT_Read_t FTAPI_Read; +FT_ListDevices_t FTAPI_ListDevices; +FT_SetLatencyTimer_t FTAPI_SetLatencyTimer; +FT_GetLatencyTimer_t FTAPI_GetLatencyTimer; +FT_GetDriverVersion_t FTAPI_GetDriverVersion; +FT_SetTimeouts_t FTAPI_SetTimeouts; +FT_SetBitMode_t FTAPI_SetBitMode; +FT_GetDeviceInfo_t FTAPI_GetDeviceInfo; +FT_ReadEE_t FTAPI_ReadEE; +FT_WriteEE_t FTAPI_WriteEE; +FT_SetBaudRate_t FTAPI_SetBaudRate; + +bool ftd2xx_dll_api_init(void) +{ + bool b64 = false; + + /* Only want to load the DLL once, just in case multiple drivers call this */ + if (loadSuccess) { + refCount++; + return true; + } + + hDll = LoadLibrary("ftd2xx64.dll"); + + if (hDll!=NULL) { + LOG_DEBUG("Opened the 64-bit DLL."); + } + else { + hDll = LoadLibrary("ftd2xx.dll"); + if (hDll == NULL) { + LOG_USER("Failed to open the FTDI DLL."); + return FALSE; + } + else { + LOG_DEBUG("Opened the 32-bit DLL."); + } + } + + FTAPI_Open = (FT_Open_t)GetProcAddress(hDll,"FT_Open"); + FTAPI_OpenEx = (FT_OpenEx_t)GetProcAddress(hDll,"FT_OpenEx"); + FTAPI_Close = (FT_Close_t)GetProcAddress(hDll,"FT_Close"); + FTAPI_Purge = (FT_Purge_t)GetProcAddress(hDll,"FT_Purge"); + FTAPI_Write = (FT_Write_t)GetProcAddress(hDll,"FT_Write"); + FTAPI_Read = (FT_Read_t)GetProcAddress(hDll,"FT_Read"); + FTAPI_ListDevices = (FT_ListDevices_t)GetProcAddress(hDll,"FT_ListDevices"); + FTAPI_SetLatencyTimer = (FT_SetLatencyTimer_t)GetProcAddress(hDll,"FT_SetLatencyTimer"); + FTAPI_GetLatencyTimer = (FT_GetLatencyTimer_t)GetProcAddress(hDll,"FT_GetLatencyTimer"); + FTAPI_GetDriverVersion = (FT_GetDriverVersion_t)GetProcAddress(hDll,"FT_GetDriverVersion"); + FTAPI_SetTimeouts = (FT_SetTimeouts_t)GetProcAddress(hDll,"FT_SetTimeouts"); + FTAPI_SetBitMode = (FT_SetBitMode_t)GetProcAddress(hDll,"FT_SetBitMode"); + FTAPI_GetDeviceInfo = (FT_GetDeviceInfo_t)GetProcAddress(hDll,"FT_GetDeviceInfo"); + FTAPI_ReadEE = (FT_ReadEE_t)GetProcAddress(hDll,"FT_ReadEE"); + FTAPI_WriteEE = (FT_WriteEE_t)GetProcAddress(hDll,"FT_WriteEE"); + FTAPI_SetBaudRate = (FT_SetBaudRate_t)GetProcAddress(hDll,"FT_SetBaudRate"); + + if ((FTAPI_Open == NULL) || + (FTAPI_OpenEx == NULL) || + (FTAPI_Close == NULL) || + (FTAPI_Purge == NULL) || + (FTAPI_Write == NULL) || + (FTAPI_Read == NULL) || + (FTAPI_ListDevices == NULL) || + (FTAPI_SetLatencyTimer == NULL) || + (FTAPI_GetLatencyTimer == NULL) || + (FTAPI_GetDriverVersion == NULL) || + (FTAPI_SetTimeouts == NULL) || + (FTAPI_SetBitMode == NULL) || + (FTAPI_GetDeviceInfo == NULL) || + (FTAPI_ReadEE == NULL) || + (FTAPI_WriteEE == NULL) || + (FTAPI_SetBaudRate == NULL)) + { + LOG_USER("Failed to load the DLL functions."); + FreeLibrary(hDll); + } + else { + LOG_DEBUG("Loaded DLL functions successfully."); + loadSuccess = true; + } + + return loadSuccess; +} + +void ftd2xx_dll_api_shutdown(void) +{ + if (loadSuccess) + { + if (refCount) + { + refCount--; + return; + } + FreeLibrary(hDll); + loadSuccess = false; + } +} diff --git a/src/jtag/drivers/ftd2xx_api.h b/src/jtag/drivers/ftd2xx_api.h new file mode 100644 index 0000000..7d8cd49 --- /dev/null +++ b/src/jtag/drivers/ftd2xx_api.h @@ -0,0 +1,94 @@ +/*************************************************************************** + * Copyright (C) 2014 by Spencer Oliver <s...@spen-soft.co.uk> * + * * + * Written by Rob Brown (r...@cobbleware.com) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#ifndef FTD2XX_API_H +#define FTD2XX_API_H + +#include <ftd2xx.h> + +#ifdef BUILD_FT2232_WINDOWS_FTD2XX_DLL +#ifdef __cplusplus +extern "C" { +#endif + +typedef FT_STATUS __stdcall (*FT_Open_t)(int deviceNumber, FT_HANDLE *pHandle); +typedef FT_STATUS __stdcall (*FT_OpenEx_t)(PVOID pArg1, DWORD Flags, FT_HANDLE *pHandle); +typedef FT_STATUS __stdcall (*FT_Close_t)(FT_HANDLE ftHandle); +typedef FT_STATUS __stdcall (*FT_Purge_t)(FT_HANDLE ftHandle, ULONG Mask); +typedef FT_STATUS __stdcall (*FT_Write_t)(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToWrite, LPDWORD lpBytesWritten); +typedef FT_STATUS __stdcall (*FT_Read_t)(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToRead, LPDWORD lpBytesReturned); +typedef FT_STATUS __stdcall (*FT_ListDevices_t)(PVOID pArg1, PVOID pArg2, DWORD Flags); +typedef FT_STATUS __stdcall (*FT_SetLatencyTimer_t)(FT_HANDLE ftHandle, UCHAR ucLatency); +typedef FT_STATUS __stdcall (*FT_GetLatencyTimer_t)(FT_HANDLE ftHandle, PUCHAR pucLatency); +typedef FT_STATUS __stdcall (*FT_GetDriverVersion_t)(FT_HANDLE ftHandle, LPDWORD lpdwVersion); +typedef FT_STATUS __stdcall (*FT_SetTimeouts_t)(FT_HANDLE ftHandle, ULONG ReadTimeout, ULONG WriteTimeout); +typedef FT_STATUS __stdcall (*FT_SetBitMode_t)(FT_HANDLE ftHandle, UCHAR ucMask, UCHAR ucEnable); +typedef FT_STATUS __stdcall (*FT_GetDeviceInfo_t)(FT_HANDLE ftHandle, FT_DEVICE *lpftDevice, LPDWORD lpdwID, PCHAR SerialNumber, PCHAR Description, LPVOID Dummy); +typedef FT_STATUS __stdcall (*FT_ReadEE_t)(FT_HANDLE ftHandle, DWORD dwWordOffset, LPWORD lpwValue); +typedef FT_STATUS __stdcall (*FT_WriteEE_t)(FT_HANDLE ftHandle, DWORD dwWordOffset, WORD wValue); +typedef FT_STATUS __stdcall (*FT_SetBaudRate_t)(FT_HANDLE ftHandle, ULONG BaudRate); + +extern FT_Open_t FTAPI_Open; +extern FT_OpenEx_t FTAPI_OpenEx; +extern FT_Close_t FTAPI_Close; +extern FT_Purge_t FTAPI_Purge; +extern FT_Write_t FTAPI_Write; +extern FT_Read_t FTAPI_Read; +extern FT_ListDevices_t FTAPI_ListDevices; +extern FT_SetLatencyTimer_t FTAPI_SetLatencyTimer; +extern FT_GetLatencyTimer_t FTAPI_GetLatencyTimer; +extern FT_GetDriverVersion_t FTAPI_GetDriverVersion; +extern FT_SetTimeouts_t FTAPI_SetTimeouts; +extern FT_SetBitMode_t FTAPI_SetBitMode; +extern FT_GetDeviceInfo_t FTAPI_GetDeviceInfo; +extern FT_ReadEE_t FTAPI_ReadEE; +extern FT_WriteEE_t FTAPI_WriteEE; +extern FT_SetBaudRate_t FTAPI_SetBaudRate; + +bool ftd2xx_dll_api_init(void); +void ftd2xx_dll_api_shutdown(void); + +#ifdef __cplusplus +} +#endif + +#else + +#define FTAPI_Open FT_Open +#define FTAPI_OpenEx FT_OpenEx; +#define FTAPI_Close FT_Close; +#define FTAPI_Purge FT_Purge; +#define FTAPI_Write FT_Write; +#define FTAPI_Read FT_Read; +#define FTAPI_ListDevices FT_ListDevices; +#define FTAPI_SetLatencyTimer FT_SetLatencyTimer; +#define FTAPI_GetLatencyTimer FT_GetLatencyTimer; +#define FTAPI_GetDriverVersion FT_GetDriverVersion; +#define FTAPI_SetTimeouts FT_SetTimeouts; +#define FTAPI_SetBitMode FT_SetBitMode; +#define FTAPI_GetDeviceInfo FT_GetDeviceInfo; +#define FTAPI_ReadEE FT_ReadEE; +#define FTAPI_WriteEE FT_WriteEE; +#define FTAPI_SetBaudRate FT_SetBaudRate; + +#endif + +#endif // FTD2XX_API_H -- ------------------------------------------------------------------------------ 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