No changes between revisions
/Modules/CPLD_FPGA/XILINX_XVC/XVC_SOFTWARE/PrjInfo.txt
0,0 → 1,29
//
// Toto je popisný soubor pro popis obsahu adresáře (příklad)
//
 
[InfoShortDescription.en]
Xilinx Virtual Cable Sofware (program mlab_xvcd)
[InfoShortDescription.cs]
Xilinx Virtual Cable Sofware (program mlab_xvcd)
 
[InfoLongDescription.en]
The mlab_xvcd program converts JTAG commands received across TCP/IP
network via XVC protocol to outputs of the programming
cable (module) which is based on FTDI's USB chips like
popular FT232R, FT220X etc.
Used XVC protocol is directly supported by XILINX development
tools (both configuration tool IMPACT and debugging
embedded logic analyzer ChipScope Analyzer).
 
[InfoLongDescription.cs]
Program mlab_xvcd je obslužný program, který převádí JTAG příkazy
zasílané prostřednictvím XVC protokolu přes TCP/IP síť
na příslušné výstupy JTAG kabelu (modulku) založeného
na USB převodnících firmy FTDI (FT232R, FT220X, ...).
Protokol XVC přímo podporují vývojové nástroje XILINX
(nahrávání konfigurace program IMPACT a ladění pomocí
logického analyzátoru ChipScope Analyzer).
 
[End]
/Modules/CPLD_FPGA/XILINX_XVC/XVC_SOFTWARE/XVC_1x/!____!.txt
0,0 → 1,14
FTDI D2XX library, use latest version from http://www.ftdichip.com
 
ftd2xx.h
ftd2xx.lib
 
Main program, pin configuration is here (in .h file)
 
mlab_xvcd.h
mlab_xvcd.cpp
 
Hardware layer, uses FTDI D2XX library
 
mlab_xvcd_port_FTDI.h
mlab_xvcd_port_FTDI.cpp
/Modules/CPLD_FPGA/XILINX_XVC/XVC_SOFTWARE/XVC_1x/BIN/mlab_xvcd.exe
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/CPLD_FPGA/XILINX_XVC/XVC_SOFTWARE/XVC_1x/ftd2xx.h
0,0 → 1,1341
/*++
 
Copyright © 2001-2011 Future Technology Devices International Limited
 
THIS SOFTWARE IS PROVIDED BY FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
FTDI DRIVERS MAY BE USED ONLY IN CONJUNCTION WITH PRODUCTS BASED ON FTDI PARTS.
 
FTDI DRIVERS MAY BE DISTRIBUTED IN ANY FORM AS LONG AS LICENSE INFORMATION IS NOT MODIFIED.
 
IF A CUSTOM VENDOR ID AND/OR PRODUCT ID OR DESCRIPTION STRING ARE USED, IT IS THE
RESPONSIBILITY OF THE PRODUCT MANUFACTURER TO MAINTAIN ANY CHANGES AND SUBSEQUENT WHQL
RE-CERTIFICATION AS A RESULT OF MAKING THESE CHANGES.
 
 
Module Name:
 
ftd2xx.h
 
Abstract:
 
Native USB device driver for FTDI FT232x, FT245x, FT2232x and FT4232x devices
FTD2XX library definitions
 
Environment:
 
kernel & user mode
 
 
--*/
 
 
#ifndef FTD2XX_H
#define FTD2XX_H
 
// The following ifdef block is the standard way of creating macros
// which make exporting from a DLL simpler. All files within this DLL
// are compiled with the FTD2XX_EXPORTS symbol defined on the command line.
// This symbol should not be defined on any project that uses this DLL.
// This way any other project whose source files include this file see
// FTD2XX_API functions as being imported from a DLL, whereas this DLL
// sees symbols defined with this macro as being exported.
 
#ifdef FTD2XX_EXPORTS
#define FTD2XX_API __declspec(dllexport)
#else
#define FTD2XX_API __declspec(dllimport)
#endif
 
 
typedef PVOID FT_HANDLE;
typedef ULONG FT_STATUS;
 
//
// Device status
//
enum {
FT_OK,
FT_INVALID_HANDLE,
FT_DEVICE_NOT_FOUND,
FT_DEVICE_NOT_OPENED,
FT_IO_ERROR,
FT_INSUFFICIENT_RESOURCES,
FT_INVALID_PARAMETER,
FT_INVALID_BAUD_RATE,
 
FT_DEVICE_NOT_OPENED_FOR_ERASE,
FT_DEVICE_NOT_OPENED_FOR_WRITE,
FT_FAILED_TO_WRITE_DEVICE,
FT_EEPROM_READ_FAILED,
FT_EEPROM_WRITE_FAILED,
FT_EEPROM_ERASE_FAILED,
FT_EEPROM_NOT_PRESENT,
FT_EEPROM_NOT_PROGRAMMED,
FT_INVALID_ARGS,
FT_NOT_SUPPORTED,
FT_OTHER_ERROR,
FT_DEVICE_LIST_NOT_READY,
};
 
 
#define FT_SUCCESS(status) ((status) == FT_OK)
 
//
// FT_OpenEx Flags
//
 
#define FT_OPEN_BY_SERIAL_NUMBER 1
#define FT_OPEN_BY_DESCRIPTION 2
#define FT_OPEN_BY_LOCATION 4
 
//
// FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags
//
 
#define FT_LIST_NUMBER_ONLY 0x80000000
#define FT_LIST_BY_INDEX 0x40000000
#define FT_LIST_ALL 0x20000000
 
#define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL)
 
//
// Baud Rates
//
 
#define FT_BAUD_300 300
#define FT_BAUD_600 600
#define FT_BAUD_1200 1200
#define FT_BAUD_2400 2400
#define FT_BAUD_4800 4800
#define FT_BAUD_9600 9600
#define FT_BAUD_14400 14400
#define FT_BAUD_19200 19200
#define FT_BAUD_38400 38400
#define FT_BAUD_57600 57600
#define FT_BAUD_115200 115200
#define FT_BAUD_230400 230400
#define FT_BAUD_460800 460800
#define FT_BAUD_921600 921600
 
//
// Word Lengths
//
 
#define FT_BITS_8 (UCHAR) 8
#define FT_BITS_7 (UCHAR) 7
 
//
// Stop Bits
//
 
#define FT_STOP_BITS_1 (UCHAR) 0
#define FT_STOP_BITS_2 (UCHAR) 2
 
//
// Parity
//
 
#define FT_PARITY_NONE (UCHAR) 0
#define FT_PARITY_ODD (UCHAR) 1
#define FT_PARITY_EVEN (UCHAR) 2
#define FT_PARITY_MARK (UCHAR) 3
#define FT_PARITY_SPACE (UCHAR) 4
 
//
// Flow Control
//
 
#define FT_FLOW_NONE 0x0000
#define FT_FLOW_RTS_CTS 0x0100
#define FT_FLOW_DTR_DSR 0x0200
#define FT_FLOW_XON_XOFF 0x0400
 
//
// Purge rx and tx buffers
//
#define FT_PURGE_RX 1
#define FT_PURGE_TX 2
 
//
// Events
//
 
typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD);
 
#define FT_EVENT_RXCHAR 1
#define FT_EVENT_MODEM_STATUS 2
#define FT_EVENT_LINE_STATUS 4
 
//
// Timeouts
//
 
#define FT_DEFAULT_RX_TIMEOUT 300
#define FT_DEFAULT_TX_TIMEOUT 300
 
//
// Device types
//
 
typedef ULONG FT_DEVICE;
 
enum {
FT_DEVICE_BM,
FT_DEVICE_AM,
FT_DEVICE_100AX,
FT_DEVICE_UNKNOWN,
FT_DEVICE_2232C,
FT_DEVICE_232R,
FT_DEVICE_2232H,
FT_DEVICE_4232H,
FT_DEVICE_232H,
FT_DEVICE_X_SERIES
};
 
//
// Bit Modes
//
 
#define FT_BITMODE_RESET 0x00
#define FT_BITMODE_ASYNC_BITBANG 0x01
#define FT_BITMODE_MPSSE 0x02
#define FT_BITMODE_SYNC_BITBANG 0x04
#define FT_BITMODE_MCU_HOST 0x08
#define FT_BITMODE_FAST_SERIAL 0x10
#define FT_BITMODE_CBUS_BITBANG 0x20
#define FT_BITMODE_SYNC_FIFO 0x40
 
//
// FT232R CBUS Options EEPROM values
//
 
#define FT_232R_CBUS_TXDEN 0x00 // Tx Data Enable
#define FT_232R_CBUS_PWRON 0x01 // Power On
#define FT_232R_CBUS_RXLED 0x02 // Rx LED
#define FT_232R_CBUS_TXLED 0x03 // Tx LED
#define FT_232R_CBUS_TXRXLED 0x04 // Tx and Rx LED
#define FT_232R_CBUS_SLEEP 0x05 // Sleep
#define FT_232R_CBUS_CLK48 0x06 // 48MHz clock
#define FT_232R_CBUS_CLK24 0x07 // 24MHz clock
#define FT_232R_CBUS_CLK12 0x08 // 12MHz clock
#define FT_232R_CBUS_CLK6 0x09 // 6MHz clock
#define FT_232R_CBUS_IOMODE 0x0A // IO Mode for CBUS bit-bang
#define FT_232R_CBUS_BITBANG_WR 0x0B // Bit-bang write strobe
#define FT_232R_CBUS_BITBANG_RD 0x0C // Bit-bang read strobe
 
//
// FT232H CBUS Options EEPROM values
//
 
#define FT_232H_CBUS_TRISTATE 0x00 // Tristate
#define FT_232H_CBUS_TXLED 0x01 // Tx LED
#define FT_232H_CBUS_RXLED 0x02 // Rx LED
#define FT_232H_CBUS_TXRXLED 0x03 // Tx and Rx LED
#define FT_232H_CBUS_PWREN 0x04 // Power Enable
#define FT_232H_CBUS_SLEEP 0x05 // Sleep
#define FT_232H_CBUS_DRIVE_0 0x06 // Drive pin to logic 0
#define FT_232H_CBUS_DRIVE_1 0x07 // Drive pin to logic 1
#define FT_232H_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang
#define FT_232H_CBUS_TXDEN 0x09 // Tx Data Enable
#define FT_232H_CBUS_CLK30 0x0A // 30MHz clock
#define FT_232H_CBUS_CLK15 0x0B // 15MHz clock
#define FT_232H_CBUS_CLK7_5 0x0C // 7.5MHz clock
 
//
// FT X Series CBUS Options EEPROM values
//
 
#define FT_X_SERIES_CBUS_TRISTATE 0x00 // Tristate
#define FT_X_SERIES_CBUS_RXLED 0x01 // Tx LED
#define FT_X_SERIES_CBUS_TXLED 0x02 // Rx LED
#define FT_X_SERIES_CBUS_TXRXLED 0x03 // Tx and Rx LED
#define FT_X_SERIES_CBUS_PWREN 0x04 // Power Enable
#define FT_X_SERIES_CBUS_SLEEP 0x05 // Sleep
#define FT_X_SERIES_CBUS_DRIVE_0 0x06 // Drive pin to logic 0
#define FT_X_SERIES_CBUS_DRIVE_1 0x07 // Drive pin to logic 1
#define FT_X_SERIES_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang
#define FT_X_SERIES_CBUS_TXDEN 0x09 // Tx Data Enable
#define FT_X_SERIES_CBUS_CLK24 0x0A // 24MHz clock
#define FT_X_SERIES_CBUS_CLK12 0x0B // 12MHz clock
#define FT_X_SERIES_CBUS_CLK6 0x0C // 6MHz clock
#define FT_X_SERIES_CBUS_BCD_CHARGER 0x0D // Battery charger detected
#define FT_X_SERIES_CBUS_BCD_CHARGER_N 0x0E // Battery charger detected inverted
#define FT_X_SERIES_CBUS_I2C_TXE 0x0F // I2C Tx empty
#define FT_X_SERIES_CBUS_I2C_RXF 0x10 // I2C Rx full
#define FT_X_SERIES_CBUS_VBUS_SENSE 0x11 // Detect VBUS
#define FT_X_SERIES_CBUS_BITBANG_WR 0x12 // Bit-bang write strobe
#define FT_X_SERIES_CBUS_BITBANG_RD 0x13 // Bit-bang read strobe
#define FT_X_SERIES_CBUS_TIMESTAMP 0x14 // Toggle output when a USB SOF token is received
#define FT_X_SERIES_CBUS_KEEP_AWAKE 0x15 //
 
 
// Driver types
#define FT_DRIVER_TYPE_D2XX 0
#define FT_DRIVER_TYPE_VCP 1
 
 
 
#ifdef __cplusplus
extern "C" {
#endif
 
 
FTD2XX_API
FT_STATUS WINAPI FT_Open(
int deviceNumber,
FT_HANDLE *pHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_OpenEx(
PVOID pArg1,
DWORD Flags,
FT_HANDLE *pHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_ListDevices(
PVOID pArg1,
PVOID pArg2,
DWORD Flags
);
 
FTD2XX_API
FT_STATUS WINAPI FT_Close(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_Read(
FT_HANDLE ftHandle,
LPVOID lpBuffer,
DWORD dwBytesToRead,
LPDWORD lpBytesReturned
);
 
FTD2XX_API
FT_STATUS WINAPI FT_Write(
FT_HANDLE ftHandle,
LPVOID lpBuffer,
DWORD dwBytesToWrite,
LPDWORD lpBytesWritten
);
 
FTD2XX_API
FT_STATUS WINAPI FT_IoCtl(
FT_HANDLE ftHandle,
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetBaudRate(
FT_HANDLE ftHandle,
ULONG BaudRate
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetDivisor(
FT_HANDLE ftHandle,
USHORT Divisor
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetDataCharacteristics(
FT_HANDLE ftHandle,
UCHAR WordLength,
UCHAR StopBits,
UCHAR Parity
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetFlowControl(
FT_HANDLE ftHandle,
USHORT FlowControl,
UCHAR XonChar,
UCHAR XoffChar
);
 
FTD2XX_API
FT_STATUS WINAPI FT_ResetDevice(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetDtr(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_ClrDtr(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetRts(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_ClrRts(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetModemStatus(
FT_HANDLE ftHandle,
ULONG *pModemStatus
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetChars(
FT_HANDLE ftHandle,
UCHAR EventChar,
UCHAR EventCharEnabled,
UCHAR ErrorChar,
UCHAR ErrorCharEnabled
);
 
FTD2XX_API
FT_STATUS WINAPI FT_Purge(
FT_HANDLE ftHandle,
ULONG Mask
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetTimeouts(
FT_HANDLE ftHandle,
ULONG ReadTimeout,
ULONG WriteTimeout
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetQueueStatus(
FT_HANDLE ftHandle,
DWORD *dwRxBytes
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetEventNotification(
FT_HANDLE ftHandle,
DWORD Mask,
PVOID Param
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetStatus(
FT_HANDLE ftHandle,
DWORD *dwRxBytes,
DWORD *dwTxBytes,
DWORD *dwEventDWord
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetBreakOn(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetBreakOff(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetWaitMask(
FT_HANDLE ftHandle,
DWORD Mask
);
 
FTD2XX_API
FT_STATUS WINAPI FT_WaitOnMask(
FT_HANDLE ftHandle,
DWORD *Mask
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetEventStatus(
FT_HANDLE ftHandle,
DWORD *dwEventDWord
);
 
FTD2XX_API
FT_STATUS WINAPI FT_ReadEE(
FT_HANDLE ftHandle,
DWORD dwWordOffset,
LPWORD lpwValue
);
 
FTD2XX_API
FT_STATUS WINAPI FT_WriteEE(
FT_HANDLE ftHandle,
DWORD dwWordOffset,
WORD wValue
);
 
FTD2XX_API
FT_STATUS WINAPI FT_EraseEE(
FT_HANDLE ftHandle
);
 
//
// structure to hold program data for FT_EE_Program, FT_EE_ProgramEx, FT_EE_Read
// and FT_EE_ReadEx functions
//
typedef struct ft_program_data {
 
DWORD Signature1; // Header - must be 0x00000000
DWORD Signature2; // Header - must be 0xffffffff
DWORD Version; // Header - FT_PROGRAM_DATA version
// 0 = original
// 1 = FT2232 extensions
// 2 = FT232R extensions
// 3 = FT2232H extensions
// 4 = FT4232H extensions
// 5 = FT232H extensions
 
WORD VendorId; // 0x0403
WORD ProductId; // 0x6001
char *Manufacturer; // "FTDI"
char *ManufacturerId; // "FT"
char *Description; // "USB HS Serial Converter"
char *SerialNumber; // "FT000001" if fixed, or NULL
WORD MaxPower; // 0 < MaxPower <= 500
WORD PnP; // 0 = disabled, 1 = enabled
WORD SelfPowered; // 0 = bus powered, 1 = self powered
WORD RemoteWakeup; // 0 = not capable, 1 = capable
//
// Rev4 (FT232B) extensions
//
UCHAR Rev4; // non-zero if Rev4 chip, zero otherwise
UCHAR IsoIn; // non-zero if in endpoint is isochronous
UCHAR IsoOut; // non-zero if out endpoint is isochronous
UCHAR PullDownEnable; // non-zero if pull down enabled
UCHAR SerNumEnable; // non-zero if serial number to be used
UCHAR USBVersionEnable; // non-zero if chip uses USBVersion
WORD USBVersion; // BCD (0x0200 => USB2)
//
// Rev 5 (FT2232) extensions
//
UCHAR Rev5; // non-zero if Rev5 chip, zero otherwise
UCHAR IsoInA; // non-zero if in endpoint is isochronous
UCHAR IsoInB; // non-zero if in endpoint is isochronous
UCHAR IsoOutA; // non-zero if out endpoint is isochronous
UCHAR IsoOutB; // non-zero if out endpoint is isochronous
UCHAR PullDownEnable5; // non-zero if pull down enabled
UCHAR SerNumEnable5; // non-zero if serial number to be used
UCHAR USBVersionEnable5; // non-zero if chip uses USBVersion
WORD USBVersion5; // BCD (0x0200 => USB2)
UCHAR AIsHighCurrent; // non-zero if interface is high current
UCHAR BIsHighCurrent; // non-zero if interface is high current
UCHAR IFAIsFifo; // non-zero if interface is 245 FIFO
UCHAR IFAIsFifoTar; // non-zero if interface is 245 FIFO CPU target
UCHAR IFAIsFastSer; // non-zero if interface is Fast serial
UCHAR AIsVCP; // non-zero if interface is to use VCP drivers
UCHAR IFBIsFifo; // non-zero if interface is 245 FIFO
UCHAR IFBIsFifoTar; // non-zero if interface is 245 FIFO CPU target
UCHAR IFBIsFastSer; // non-zero if interface is Fast serial
UCHAR BIsVCP; // non-zero if interface is to use VCP drivers
//
// Rev 6 (FT232R) extensions
//
UCHAR UseExtOsc; // Use External Oscillator
UCHAR HighDriveIOs; // High Drive I/Os
UCHAR EndpointSize; // Endpoint size
UCHAR PullDownEnableR; // non-zero if pull down enabled
UCHAR SerNumEnableR; // non-zero if serial number to be used
UCHAR InvertTXD; // non-zero if invert TXD
UCHAR InvertRXD; // non-zero if invert RXD
UCHAR InvertRTS; // non-zero if invert RTS
UCHAR InvertCTS; // non-zero if invert CTS
UCHAR InvertDTR; // non-zero if invert DTR
UCHAR InvertDSR; // non-zero if invert DSR
UCHAR InvertDCD; // non-zero if invert DCD
UCHAR InvertRI; // non-zero if invert RI
UCHAR Cbus0; // Cbus Mux control
UCHAR Cbus1; // Cbus Mux control
UCHAR Cbus2; // Cbus Mux control
UCHAR Cbus3; // Cbus Mux control
UCHAR Cbus4; // Cbus Mux control
UCHAR RIsD2XX; // non-zero if using D2XX driver
//
// Rev 7 (FT2232H) Extensions
//
UCHAR PullDownEnable7; // non-zero if pull down enabled
UCHAR SerNumEnable7; // non-zero if serial number to be used
UCHAR ALSlowSlew; // non-zero if AL pins have slow slew
UCHAR ALSchmittInput; // non-zero if AL pins are Schmitt input
UCHAR ALDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR AHSlowSlew; // non-zero if AH pins have slow slew
UCHAR AHSchmittInput; // non-zero if AH pins are Schmitt input
UCHAR AHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR BLSlowSlew; // non-zero if BL pins have slow slew
UCHAR BLSchmittInput; // non-zero if BL pins are Schmitt input
UCHAR BLDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR BHSlowSlew; // non-zero if BH pins have slow slew
UCHAR BHSchmittInput; // non-zero if BH pins are Schmitt input
UCHAR BHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR IFAIsFifo7; // non-zero if interface is 245 FIFO
UCHAR IFAIsFifoTar7; // non-zero if interface is 245 FIFO CPU target
UCHAR IFAIsFastSer7; // non-zero if interface is Fast serial
UCHAR AIsVCP7; // non-zero if interface is to use VCP drivers
UCHAR IFBIsFifo7; // non-zero if interface is 245 FIFO
UCHAR IFBIsFifoTar7; // non-zero if interface is 245 FIFO CPU target
UCHAR IFBIsFastSer7; // non-zero if interface is Fast serial
UCHAR BIsVCP7; // non-zero if interface is to use VCP drivers
UCHAR PowerSaveEnable; // non-zero if using BCBUS7 to save power for self-powered designs
//
// Rev 8 (FT4232H) Extensions
//
UCHAR PullDownEnable8; // non-zero if pull down enabled
UCHAR SerNumEnable8; // non-zero if serial number to be used
UCHAR ASlowSlew; // non-zero if A pins have slow slew
UCHAR ASchmittInput; // non-zero if A pins are Schmitt input
UCHAR ADriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR BSlowSlew; // non-zero if B pins have slow slew
UCHAR BSchmittInput; // non-zero if B pins are Schmitt input
UCHAR BDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR CSlowSlew; // non-zero if C pins have slow slew
UCHAR CSchmittInput; // non-zero if C pins are Schmitt input
UCHAR CDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR DSlowSlew; // non-zero if D pins have slow slew
UCHAR DSchmittInput; // non-zero if D pins are Schmitt input
UCHAR DDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR ARIIsTXDEN; // non-zero if port A uses RI as RS485 TXDEN
UCHAR BRIIsTXDEN; // non-zero if port B uses RI as RS485 TXDEN
UCHAR CRIIsTXDEN; // non-zero if port C uses RI as RS485 TXDEN
UCHAR DRIIsTXDEN; // non-zero if port D uses RI as RS485 TXDEN
UCHAR AIsVCP8; // non-zero if interface is to use VCP drivers
UCHAR BIsVCP8; // non-zero if interface is to use VCP drivers
UCHAR CIsVCP8; // non-zero if interface is to use VCP drivers
UCHAR DIsVCP8; // non-zero if interface is to use VCP drivers
//
// Rev 9 (FT232H) Extensions
//
UCHAR PullDownEnableH; // non-zero if pull down enabled
UCHAR SerNumEnableH; // non-zero if serial number to be used
UCHAR ACSlowSlewH; // non-zero if AC pins have slow slew
UCHAR ACSchmittInputH; // non-zero if AC pins are Schmitt input
UCHAR ACDriveCurrentH; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR ADSlowSlewH; // non-zero if AD pins have slow slew
UCHAR ADSchmittInputH; // non-zero if AD pins are Schmitt input
UCHAR ADDriveCurrentH; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR Cbus0H; // Cbus Mux control
UCHAR Cbus1H; // Cbus Mux control
UCHAR Cbus2H; // Cbus Mux control
UCHAR Cbus3H; // Cbus Mux control
UCHAR Cbus4H; // Cbus Mux control
UCHAR Cbus5H; // Cbus Mux control
UCHAR Cbus6H; // Cbus Mux control
UCHAR Cbus7H; // Cbus Mux control
UCHAR Cbus8H; // Cbus Mux control
UCHAR Cbus9H; // Cbus Mux control
UCHAR IsFifoH; // non-zero if interface is 245 FIFO
UCHAR IsFifoTarH; // non-zero if interface is 245 FIFO CPU target
UCHAR IsFastSerH; // non-zero if interface is Fast serial
UCHAR IsFT1248H; // non-zero if interface is FT1248
UCHAR FT1248CpolH; // FT1248 clock polarity - clock idle high (1) or clock idle low (0)
UCHAR FT1248LsbH; // FT1248 data is LSB (1) or MSB (0)
UCHAR FT1248FlowControlH; // FT1248 flow control enable
UCHAR IsVCPH; // non-zero if interface is to use VCP drivers
UCHAR PowerSaveEnableH; // non-zero if using ACBUS7 to save power for self-powered designs
} FT_PROGRAM_DATA, *PFT_PROGRAM_DATA;
 
FTD2XX_API
FT_STATUS WINAPI FT_EE_Program(
FT_HANDLE ftHandle,
PFT_PROGRAM_DATA pData
);
 
FTD2XX_API
FT_STATUS WINAPI FT_EE_ProgramEx(
FT_HANDLE ftHandle,
PFT_PROGRAM_DATA pData,
char *Manufacturer,
char *ManufacturerId,
char *Description,
char *SerialNumber
);
 
FTD2XX_API
FT_STATUS WINAPI FT_EE_Read(
FT_HANDLE ftHandle,
PFT_PROGRAM_DATA pData
);
 
FTD2XX_API
FT_STATUS WINAPI FT_EE_ReadEx(
FT_HANDLE ftHandle,
PFT_PROGRAM_DATA pData,
char *Manufacturer,
char *ManufacturerId,
char *Description,
char *SerialNumber
);
 
FTD2XX_API
FT_STATUS WINAPI FT_EE_UASize(
FT_HANDLE ftHandle,
LPDWORD lpdwSize
);
 
FTD2XX_API
FT_STATUS WINAPI FT_EE_UAWrite(
FT_HANDLE ftHandle,
PUCHAR pucData,
DWORD dwDataLen
);
 
FTD2XX_API
FT_STATUS WINAPI FT_EE_UARead(
FT_HANDLE ftHandle,
PUCHAR pucData,
DWORD dwDataLen,
LPDWORD lpdwBytesRead
);
 
 
typedef struct ft_eeprom_header {
FT_DEVICE deviceType; // FTxxxx device type to be programmed
// Device descriptor options
WORD VendorId; // 0x0403
WORD ProductId; // 0x6001
UCHAR SerNumEnable; // non-zero if serial number to be used
// Config descriptor options
WORD MaxPower; // 0 < MaxPower <= 500
UCHAR SelfPowered; // 0 = bus powered, 1 = self powered
UCHAR RemoteWakeup; // 0 = not capable, 1 = capable
// Hardware options
UCHAR PullDownEnable; // non-zero if pull down in suspend enabled
} FT_EEPROM_HEADER, *PFT_EEPROM_HEADER;
 
 
// FT232B EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program
typedef struct ft_eeprom_232b {
// Common header
FT_EEPROM_HEADER common; // common elements for all device EEPROMs
} FT_EEPROM_232B, *PFT_EEPROM_232B;
 
 
// FT2232 EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program
typedef struct ft_eeprom_2232 {
// Common header
FT_EEPROM_HEADER common; // common elements for all device EEPROMs
// Drive options
UCHAR AIsHighCurrent; // non-zero if interface is high current
UCHAR BIsHighCurrent; // non-zero if interface is high current
// Hardware options
UCHAR AIsFifo; // non-zero if interface is 245 FIFO
UCHAR AIsFifoTar; // non-zero if interface is 245 FIFO CPU target
UCHAR AIsFastSer; // non-zero if interface is Fast serial
UCHAR BIsFifo; // non-zero if interface is 245 FIFO
UCHAR BIsFifoTar; // non-zero if interface is 245 FIFO CPU target
UCHAR BIsFastSer; // non-zero if interface is Fast serial
// Driver option
UCHAR ADriverType; //
UCHAR BDriverType; //
} FT_EEPROM_2232, *PFT_EEPROM_2232;
 
 
// FT232R EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program
typedef struct ft_eeprom_232r {
// Common header
FT_EEPROM_HEADER common; // common elements for all device EEPROMs
// Drive options
UCHAR IsHighCurrent; // non-zero if interface is high current
// Hardware options
UCHAR UseExtOsc; // Use External Oscillator
UCHAR InvertTXD; // non-zero if invert TXD
UCHAR InvertRXD; // non-zero if invert RXD
UCHAR InvertRTS; // non-zero if invert RTS
UCHAR InvertCTS; // non-zero if invert CTS
UCHAR InvertDTR; // non-zero if invert DTR
UCHAR InvertDSR; // non-zero if invert DSR
UCHAR InvertDCD; // non-zero if invert DCD
UCHAR InvertRI; // non-zero if invert RI
UCHAR Cbus0; // Cbus Mux control
UCHAR Cbus1; // Cbus Mux control
UCHAR Cbus2; // Cbus Mux control
UCHAR Cbus3; // Cbus Mux control
UCHAR Cbus4; // Cbus Mux control
// Driver option
UCHAR DriverType; //
} FT_EEPROM_232R, *PFT_EEPROM_232R;
 
 
// FT2232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program
typedef struct ft_eeprom_2232h {
// Common header
FT_EEPROM_HEADER common; // common elements for all device EEPROMs
// Drive options
UCHAR ALSlowSlew; // non-zero if AL pins have slow slew
UCHAR ALSchmittInput; // non-zero if AL pins are Schmitt input
UCHAR ALDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR AHSlowSlew; // non-zero if AH pins have slow slew
UCHAR AHSchmittInput; // non-zero if AH pins are Schmitt input
UCHAR AHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR BLSlowSlew; // non-zero if BL pins have slow slew
UCHAR BLSchmittInput; // non-zero if BL pins are Schmitt input
UCHAR BLDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR BHSlowSlew; // non-zero if BH pins have slow slew
UCHAR BHSchmittInput; // non-zero if BH pins are Schmitt input
UCHAR BHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
// Hardware options
UCHAR AIsFifo; // non-zero if interface is 245 FIFO
UCHAR AIsFifoTar; // non-zero if interface is 245 FIFO CPU target
UCHAR AIsFastSer; // non-zero if interface is Fast serial
UCHAR BIsFifo; // non-zero if interface is 245 FIFO
UCHAR BIsFifoTar; // non-zero if interface is 245 FIFO CPU target
UCHAR BIsFastSer; // non-zero if interface is Fast serial
UCHAR PowerSaveEnable; // non-zero if using BCBUS7 to save power for self-powered designs
// Driver option
UCHAR ADriverType; //
UCHAR BDriverType; //
} FT_EEPROM_2232H, *PFT_EEPROM_2232H;
 
 
// FT4232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program
typedef struct ft_eeprom_4232h {
// Common header
FT_EEPROM_HEADER common; // common elements for all device EEPROMs
// Drive options
UCHAR ASlowSlew; // non-zero if A pins have slow slew
UCHAR ASchmittInput; // non-zero if A pins are Schmitt input
UCHAR ADriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR BSlowSlew; // non-zero if B pins have slow slew
UCHAR BSchmittInput; // non-zero if B pins are Schmitt input
UCHAR BDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR CSlowSlew; // non-zero if C pins have slow slew
UCHAR CSchmittInput; // non-zero if C pins are Schmitt input
UCHAR CDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR DSlowSlew; // non-zero if D pins have slow slew
UCHAR DSchmittInput; // non-zero if D pins are Schmitt input
UCHAR DDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
// Hardware options
UCHAR ARIIsTXDEN; // non-zero if port A uses RI as RS485 TXDEN
UCHAR BRIIsTXDEN; // non-zero if port B uses RI as RS485 TXDEN
UCHAR CRIIsTXDEN; // non-zero if port C uses RI as RS485 TXDEN
UCHAR DRIIsTXDEN; // non-zero if port D uses RI as RS485 TXDEN
// Driver option
UCHAR ADriverType; //
UCHAR BDriverType; //
UCHAR CDriverType; //
UCHAR DDriverType; //
} FT_EEPROM_4232H, *PFT_EEPROM_4232H;
 
 
// FT232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program
typedef struct ft_eeprom_232h {
// Common header
FT_EEPROM_HEADER common; // common elements for all device EEPROMs
// Drive options
UCHAR ACSlowSlew; // non-zero if AC bus pins have slow slew
UCHAR ACSchmittInput; // non-zero if AC bus pins are Schmitt input
UCHAR ACDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR ADSlowSlew; // non-zero if AD bus pins have slow slew
UCHAR ADSchmittInput; // non-zero if AD bus pins are Schmitt input
UCHAR ADDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
// CBUS options
UCHAR Cbus0; // Cbus Mux control
UCHAR Cbus1; // Cbus Mux control
UCHAR Cbus2; // Cbus Mux control
UCHAR Cbus3; // Cbus Mux control
UCHAR Cbus4; // Cbus Mux control
UCHAR Cbus5; // Cbus Mux control
UCHAR Cbus6; // Cbus Mux control
UCHAR Cbus7; // Cbus Mux control
UCHAR Cbus8; // Cbus Mux control
UCHAR Cbus9; // Cbus Mux control
// FT1248 options
UCHAR FT1248Cpol; // FT1248 clock polarity - clock idle high (1) or clock idle low (0)
UCHAR FT1248Lsb; // FT1248 data is LSB (1) or MSB (0)
UCHAR FT1248FlowControl; // FT1248 flow control enable
// Hardware options
UCHAR IsFifo; // non-zero if interface is 245 FIFO
UCHAR IsFifoTar; // non-zero if interface is 245 FIFO CPU target
UCHAR IsFastSer; // non-zero if interface is Fast serial
UCHAR IsFT1248 ; // non-zero if interface is FT1248
UCHAR PowerSaveEnable; //
// Driver option
UCHAR DriverType; //
} FT_EEPROM_232H, *PFT_EEPROM_232H;
 
 
// FT X Series EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program
typedef struct ft_eeprom_x_series {
// Common header
FT_EEPROM_HEADER common; // common elements for all device EEPROMs
// Drive options
UCHAR ACSlowSlew; // non-zero if AC bus pins have slow slew
UCHAR ACSchmittInput; // non-zero if AC bus pins are Schmitt input
UCHAR ACDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
UCHAR ADSlowSlew; // non-zero if AD bus pins have slow slew
UCHAR ADSchmittInput; // non-zero if AD bus pins are Schmitt input
UCHAR ADDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA
// CBUS options
UCHAR Cbus0; // Cbus Mux control
UCHAR Cbus1; // Cbus Mux control
UCHAR Cbus2; // Cbus Mux control
UCHAR Cbus3; // Cbus Mux control
UCHAR Cbus4; // Cbus Mux control
UCHAR Cbus5; // Cbus Mux control
UCHAR Cbus6; // Cbus Mux control
// UART signal options
UCHAR InvertTXD; // non-zero if invert TXD
UCHAR InvertRXD; // non-zero if invert RXD
UCHAR InvertRTS; // non-zero if invert RTS
UCHAR InvertCTS; // non-zero if invert CTS
UCHAR InvertDTR; // non-zero if invert DTR
UCHAR InvertDSR; // non-zero if invert DSR
UCHAR InvertDCD; // non-zero if invert DCD
UCHAR InvertRI; // non-zero if invert RI
// Battery Charge Detect options
UCHAR BCDEnable; // Enable Battery Charger Detection
UCHAR BCDForceCbusPWREN; // asserts the power enable signal on CBUS when charging port detected
UCHAR BCDDisableSleep; // forces the device never to go into sleep mode
// I2C options
WORD I2CSlaveAddress; // I2C slave device address
DWORD I2CDeviceId; // I2C device ID
UCHAR I2CDisableSchmitt; // Disable I2C Schmitt trigger
// FT1248 options
UCHAR FT1248Cpol; // FT1248 clock polarity - clock idle high (1) or clock idle low (0)
UCHAR FT1248Lsb; // FT1248 data is LSB (1) or MSB (0)
UCHAR FT1248FlowControl; // FT1248 flow control enable
// Hardware options
UCHAR RS485EchoSuppress; //
UCHAR PowerSaveEnable; //
// Driver option
UCHAR DriverType; //
} FT_EEPROM_X_SERIES, *PFT_EEPROM_X_SERIES;
 
 
FTD2XX_API
FT_STATUS WINAPI FT_EEPROM_Read(
FT_HANDLE ftHandle,
void *eepromData,
DWORD eepromDataSize,
char *Manufacturer,
char *ManufacturerId,
char *Description,
char *SerialNumber
);
 
 
FTD2XX_API
FT_STATUS WINAPI FT_EEPROM_Program(
FT_HANDLE ftHandle,
void *eepromData,
DWORD eepromDataSize,
char *Manufacturer,
char *ManufacturerId,
char *Description,
char *SerialNumber
);
 
 
FTD2XX_API
FT_STATUS WINAPI FT_SetLatencyTimer(
FT_HANDLE ftHandle,
UCHAR ucLatency
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetLatencyTimer(
FT_HANDLE ftHandle,
PUCHAR pucLatency
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetBitMode(
FT_HANDLE ftHandle,
UCHAR ucMask,
UCHAR ucEnable
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetBitMode(
FT_HANDLE ftHandle,
PUCHAR pucMode
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetUSBParameters(
FT_HANDLE ftHandle,
ULONG ulInTransferSize,
ULONG ulOutTransferSize
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetDeadmanTimeout(
FT_HANDLE ftHandle,
ULONG ulDeadmanTimeout
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetDeviceInfo(
FT_HANDLE ftHandle,
FT_DEVICE *lpftDevice,
LPDWORD lpdwID,
PCHAR SerialNumber,
PCHAR Description,
LPVOID Dummy
);
 
FTD2XX_API
FT_STATUS WINAPI FT_StopInTask(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_RestartInTask(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_SetResetPipeRetryCount(
FT_HANDLE ftHandle,
DWORD dwCount
);
 
FTD2XX_API
FT_STATUS WINAPI FT_ResetPort(
FT_HANDLE ftHandle
);
 
FTD2XX_API
FT_STATUS WINAPI FT_CyclePort(
FT_HANDLE ftHandle
);
 
 
//
// Win32-type functions
//
 
FTD2XX_API
FT_HANDLE WINAPI FT_W32_CreateFile(
LPCTSTR lpszName,
DWORD dwAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreate,
DWORD dwAttrsAndFlags,
HANDLE hTemplate
);
 
FTD2XX_API
BOOL WINAPI FT_W32_CloseHandle(
FT_HANDLE ftHandle
);
 
FTD2XX_API
BOOL WINAPI FT_W32_ReadFile(
FT_HANDLE ftHandle,
LPVOID lpBuffer,
DWORD nBufferSize,
LPDWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped
);
 
FTD2XX_API
BOOL WINAPI FT_W32_WriteFile(
FT_HANDLE ftHandle,
LPVOID lpBuffer,
DWORD nBufferSize,
LPDWORD lpBytesWritten,
LPOVERLAPPED lpOverlapped
);
 
FTD2XX_API
DWORD WINAPI FT_W32_GetLastError(
FT_HANDLE ftHandle
);
 
FTD2XX_API
BOOL WINAPI FT_W32_GetOverlappedResult(
FT_HANDLE ftHandle,
LPOVERLAPPED lpOverlapped,
LPDWORD lpdwBytesTransferred,
BOOL bWait
);
 
FTD2XX_API
BOOL WINAPI FT_W32_CancelIo(
FT_HANDLE ftHandle
);
 
 
//
// Win32 COMM API type functions
//
typedef struct _FTCOMSTAT {
DWORD fCtsHold : 1;
DWORD fDsrHold : 1;
DWORD fRlsdHold : 1;
DWORD fXoffHold : 1;
DWORD fXoffSent : 1;
DWORD fEof : 1;
DWORD fTxim : 1;
DWORD fReserved : 25;
DWORD cbInQue;
DWORD cbOutQue;
} FTCOMSTAT, *LPFTCOMSTAT;
 
typedef struct _FTDCB {
DWORD DCBlength; /* sizeof(FTDCB) */
DWORD BaudRate; /* Baudrate at which running */
DWORD fBinary: 1; /* Binary Mode (skip EOF check) */
DWORD fParity: 1; /* Enable parity checking */
DWORD fOutxCtsFlow:1; /* CTS handshaking on output */
DWORD fOutxDsrFlow:1; /* DSR handshaking on output */
DWORD fDtrControl:2; /* DTR Flow control */
DWORD fDsrSensitivity:1; /* DSR Sensitivity */
DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */
DWORD fOutX: 1; /* Enable output X-ON/X-OFF */
DWORD fInX: 1; /* Enable input X-ON/X-OFF */
DWORD fErrorChar: 1; /* Enable Err Replacement */
DWORD fNull: 1; /* Enable Null stripping */
DWORD fRtsControl:2; /* Rts Flow control */
DWORD fAbortOnError:1; /* Abort all reads and writes on Error */
DWORD fDummy2:17; /* Reserved */
WORD wReserved; /* Not currently used */
WORD XonLim; /* Transmit X-ON threshold */
WORD XoffLim; /* Transmit X-OFF threshold */
BYTE ByteSize; /* Number of bits/byte, 4-8 */
BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */
BYTE StopBits; /* 0,1,2 = 1, 1.5, 2 */
char XonChar; /* Tx and Rx X-ON character */
char XoffChar; /* Tx and Rx X-OFF character */
char ErrorChar; /* Error replacement char */
char EofChar; /* End of Input character */
char EvtChar; /* Received Event character */
WORD wReserved1; /* Fill for now. */
} FTDCB, *LPFTDCB;
 
typedef struct _FTTIMEOUTS {
DWORD ReadIntervalTimeout; /* Maximum time between read chars. */
DWORD ReadTotalTimeoutMultiplier; /* Multiplier of characters. */
DWORD ReadTotalTimeoutConstant; /* Constant in milliseconds. */
DWORD WriteTotalTimeoutMultiplier; /* Multiplier of characters. */
DWORD WriteTotalTimeoutConstant; /* Constant in milliseconds. */
} FTTIMEOUTS,*LPFTTIMEOUTS;
 
 
FTD2XX_API
BOOL WINAPI FT_W32_ClearCommBreak(
FT_HANDLE ftHandle
);
 
FTD2XX_API
BOOL WINAPI FT_W32_ClearCommError(
FT_HANDLE ftHandle,
LPDWORD lpdwErrors,
LPFTCOMSTAT lpftComstat
);
 
FTD2XX_API
BOOL WINAPI FT_W32_EscapeCommFunction(
FT_HANDLE ftHandle,
DWORD dwFunc
);
 
FTD2XX_API
BOOL WINAPI FT_W32_GetCommModemStatus(
FT_HANDLE ftHandle,
LPDWORD lpdwModemStatus
);
 
FTD2XX_API
BOOL WINAPI FT_W32_GetCommState(
FT_HANDLE ftHandle,
LPFTDCB lpftDcb
);
 
FTD2XX_API
BOOL WINAPI FT_W32_GetCommTimeouts(
FT_HANDLE ftHandle,
FTTIMEOUTS *pTimeouts
);
 
FTD2XX_API
BOOL WINAPI FT_W32_PurgeComm(
FT_HANDLE ftHandle,
DWORD dwMask
);
 
FTD2XX_API
BOOL WINAPI FT_W32_SetCommBreak(
FT_HANDLE ftHandle
);
 
FTD2XX_API
BOOL WINAPI FT_W32_SetCommMask(
FT_HANDLE ftHandle,
ULONG ulEventMask
);
 
FTD2XX_API
BOOL WINAPI FT_W32_GetCommMask(
FT_HANDLE ftHandle,
LPDWORD lpdwEventMask
);
 
FTD2XX_API
BOOL WINAPI FT_W32_SetCommState(
FT_HANDLE ftHandle,
LPFTDCB lpftDcb
);
 
FTD2XX_API
BOOL WINAPI FT_W32_SetCommTimeouts(
FT_HANDLE ftHandle,
FTTIMEOUTS *pTimeouts
);
 
FTD2XX_API
BOOL WINAPI FT_W32_SetupComm(
FT_HANDLE ftHandle,
DWORD dwReadBufferSize,
DWORD dwWriteBufferSize
);
 
FTD2XX_API
BOOL WINAPI FT_W32_WaitCommEvent(
FT_HANDLE ftHandle,
PULONG pulEvent,
LPOVERLAPPED lpOverlapped
);
 
 
//
// Device information
//
 
typedef struct _ft_device_list_info_node {
ULONG Flags;
ULONG Type;
ULONG ID;
DWORD LocId;
char SerialNumber[16];
char Description[64];
FT_HANDLE ftHandle;
} FT_DEVICE_LIST_INFO_NODE;
 
// Device information flags
enum {
FT_FLAGS_OPENED = 1,
FT_FLAGS_HISPEED = 2
};
 
 
FTD2XX_API
FT_STATUS WINAPI FT_CreateDeviceInfoList(
LPDWORD lpdwNumDevs
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetDeviceInfoList(
FT_DEVICE_LIST_INFO_NODE *pDest,
LPDWORD lpdwNumDevs
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetDeviceInfoDetail(
DWORD dwIndex,
LPDWORD lpdwFlags,
LPDWORD lpdwType,
LPDWORD lpdwID,
LPDWORD lpdwLocId,
LPVOID lpSerialNumber,
LPVOID lpDescription,
FT_HANDLE *pftHandle
);
 
 
//
// Version information
//
 
FTD2XX_API
FT_STATUS WINAPI FT_GetDriverVersion(
FT_HANDLE ftHandle,
LPDWORD lpdwVersion
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetLibraryVersion(
LPDWORD lpdwVersion
);
 
 
FTD2XX_API
FT_STATUS WINAPI FT_Rescan(
void
);
 
FTD2XX_API
FT_STATUS WINAPI FT_Reload(
WORD wVid,
WORD wPid
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetComPortNumber(
FT_HANDLE ftHandle,
LPLONG lpdwComPortNumber
);
 
 
//
// FT232H additional EEPROM functions
//
 
FTD2XX_API
FT_STATUS WINAPI FT_EE_ReadConfig(
FT_HANDLE ftHandle,
UCHAR ucAddress,
PUCHAR pucValue
);
 
FTD2XX_API
FT_STATUS WINAPI FT_EE_WriteConfig(
FT_HANDLE ftHandle,
UCHAR ucAddress,
UCHAR ucValue
);
 
FTD2XX_API
FT_STATUS WINAPI FT_EE_ReadECC(
FT_HANDLE ftHandle,
UCHAR ucOption,
LPWORD lpwValue
);
 
FTD2XX_API
FT_STATUS WINAPI FT_GetQueueStatusEx(
FT_HANDLE ftHandle,
DWORD *dwRxBytes
);
 
 
#ifdef __cplusplus
}
#endif
 
 
#endif /* FTD2XX_H */
 
/Modules/CPLD_FPGA/XILINX_XVC/XVC_SOFTWARE/XVC_1x/ftd2xx.lib
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Modules/CPLD_FPGA/XILINX_XVC/XVC_SOFTWARE/XVC_1x/mlab_xvcd.cpp
0,0 → 1,577
// MLAB Xilinx Virtual Cable Network Server
// ----------------------------------------
//
// (c) miho 2012 http://www.mlab.cz/PermaLink/XVC_SOFTWARE
//
// This program if free.
//
//
// History:
//
// 1.00 2012_09 Proof of concept (no configuration, not for public release)
// 1.01 2012_09 Added parameter for device selection
// 1.02 2012_12 Error handling and debugged
// 1.03 2012_12 Release version ready to publish
//
//
// Purpose:
//
// XILINX development software (ISE, WebPack) supports several types of JTAG programming
// cables. Among them there is one particularly interesting. It is Xilinx Virtual Cable
// which uses (documented) XVC network protocol to send JTAG commands across TCP/IP network.
// So it is possible to realize own hardware/software and have it directly supported by
// XILINX development software (both IMPACT and ChipScope).
//
// This program listens TCP data send by XILINX ISE IMAPACT (or ChipScope) and sends it
// to the JTAG device (typically FPGA) connected to FTDI USB Chip. You can use ordinary
// USB/RS232 translator based on FT232R chip or you can use our own module from
// http://www.mlab.cz/PermaLink/XVC_FT220X
//
// Target device JTAG port is connected to pins on FTDI USB chip. Program writes to standard
// output Which pins are used. Program writes what to set in ISE to enable XVC plugin.
//
//
// Environment:
//
// This is Win32 Console Application and run in WinXP / Win7 / Win8 both 32 and 64 bit.
//
// Program needs to listen to the network so it is necessary to allow doing so. In Windows
// firewall configuration enable networking for the exe file.
// WinXP: run as Administrator c:\WINDOWS\System32\firewall.cpl and add the exe file
// Win7: the system asks directly to do so
//
//
// Technology:
//
// The program uses Windows WINSOCK2 library for network communication
// and FTDI ftd2xx library for communication with FTDI USB chip.
// It can be staticly linked to minimize dependencies on libraries.
// Program requires FTDI drivers installed.
// Because of the usage of standard libraries you don't need to solve how to sign drivers.
//
// The program was debug with FT232R and FT220X device.
// It should work with any similar FTDI USB chip.
//
// XVC protocol is documented (you have to ask XILINX support to gain access).
// The program is inspired by the work http://debugmo.de/2012/02/xvcd-the-xilinx-virtual-cable-daemon/
// Ask Google about Xilinx Virtual Cable.
//
//
// Translation:
//
// MS Visual C++ 2010 Express (free, registration required)
// Create new empty project for Win32 Console Application and name project mlab_xvcd (to build mlab_xvcd.exe)
// Header Files / Add / Existing Items - all .h files
// Resource Files / Add / Existing Items - all .lib files
// Source Files / Add / Existing Items - all .cpp files
// Select Release version (no debug info)
// Set static linkage Project Properties / Configuration Release / Configuration Properties
// / Code Generation / Runtime Library = Multithreaded (/MT)
//
//
// Problems:
//
// Programming of SPI FLASH configuration memory connected to FPGA does not work. No idea why.
// It does not work for internal FLASH of Spartan XC3SxxAN either.
//
//
// Possible improvements:
//
// Linux version (Winsock library differs).
// External definition of JTAG pins.
 
 
// Library Definitions
// -------------------
 
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
 
#include "mlab_xvcd.h" // Program Configuration
#include <windows.h> // Windows Console Application
#include <winsock2.h> // Windows WinSock2
#include <ws2tcpip.h> // Windows WinSock2
#include <stdlib.h> // Standard Library (exit, atoi, ...)
#include <stdio.h> // Standard IO (printf, ...)
#include <signal.h> // CTRL+C handling
 
// Link with library
#pragma comment (lib, "Ws2_32.lib")
 
#define XVC_RX_BUFLEN (XVC_JTAG_LEN/8*2+20) // Length of receive buffer in bytes (command+length+TMSbuffer+TDIbuffer)
#define XVC_TX_BUFLEN (XVC_JTAG_LEN/8) // Length of transmit buffer in bytes (TDObuffer)
 
 
// JTAG state machine
// ------------------
 
// JTAG States
enum
{
test_logic_reset, run_test_idle, // Starts from 0
 
select_dr_scan, capture_dr, shift_dr,
exit1_dr, pause_dr, exit2_dr, update_dr,
 
select_ir_scan, capture_ir, shift_ir,
exit1_ir, pause_ir, exit2_ir, update_ir,
 
num_states
};
 
 
// JTAG State Machine transfer Function
static int jtagStep(int state, int tms)
{
static const int next_state[num_states][2] =
{
/* JTAG State -->> New State */
/* -------------------------------------------------------------*/
/* | TMS=0 | TMS=1 */
/* -------------------------------------------------------------*/
/* [test_logic_reset] -> */ { run_test_idle, test_logic_reset },
/* [run_test_idle] -> */ { run_test_idle, select_dr_scan },
/* [select_dr_scan] -> */ { capture_dr, select_ir_scan },
/* [capture_dr] -> */ { shift_dr, exit1_dr },
/* [shift_dr] -> */ { shift_dr, exit1_dr },
/* [exit1_dr] -> */ { pause_dr, update_dr },
/* [pause_dr] -> */ { pause_dr, exit2_dr },
/* [exit2_dr] -> */ { shift_dr, update_dr },
/* [update_dr] -> */ { run_test_idle, select_dr_scan },
/* [select_ir_scan] -> */ { capture_ir, test_logic_reset },
/* [capture_ir] -> */ { shift_ir, exit1_ir },
/* [shift_ir] -> */ { shift_ir, exit1_ir },
/* [exit1_ir] -> */ { pause_ir, update_ir },
/* [pause_ir] -> */ { pause_ir, exit2_ir },
/* [exit2_ir] -> */ { shift_ir, update_ir },
/* [update_ir] -> */ { run_test_idle, select_dr_scan }
};
 
return next_state[state][tms];
}
 
 
int handleData(SOCKET ClientSocket)
{
 
bool seen_tlr = false;
bool jtagError = false;
 
static int jtag_state;
 
do
{
int iResult;
 
// Read Command
char command[16];
int commandLen = 0;
 
// Read String terminated by ':'
do
{
iResult = recv(ClientSocket, command+commandLen, 1, 0);
if (iResult==0)
{
printf("\n Connection Closed\n\n");
return -1;
}
else if (iResult==1)
{
commandLen++;
}
else
{
fprintf(stderr, "Error Reading Command\n");
return -2;
}
}
while (command[commandLen-1]!=':' && commandLen<sizeof(command)-1 );
command[commandLen] = char(0);
 
if (0==strncmp(command, "shift:", sizeof(command)))
{
}
else
{
fprintf(stderr, "Invalid Command '%s'\n", command);
return -2;
}
 
// Read Length (in bits, 32bit integer)
int len;
 
iResult = recv(ClientSocket, (char *)&len, 4, 0); // pøepsat pøenositelnì
if (iResult==0)
{
printf("\n Connection Closed\n\n");
return -1;
}
if (iResult != 4)
{
fprintf(stderr, "Reading Length Failed\n");
return -2;
}
 
char buffer[2048];
 
// Read Data (data string for TMS and TDI)
int nr_bytes = (len + 7) / 8;
if (nr_bytes * 2 > sizeof(buffer))
{
fprintf(stderr, "Buffer Size Exceeded\n");
return -2;
}
 
int iReceivedBytes=0;
while (iReceivedBytes<nr_bytes * 2)
{
iResult = recv(ClientSocket, buffer+iReceivedBytes, nr_bytes * 2 - iReceivedBytes, 0);
if (iResult==0)
{
printf("\n Connection Closed\n\n");
return -1;
}
if (iResult<=0)
{
fprintf(stderr, "Reading Data Failed %d %d\n", iResult, nr_bytes * 2);
return -2;
}
iReceivedBytes += iResult;
}
 
char result[1024];
memset(result, 0, nr_bytes);
 
// Deal with JTAG
 
// Only allow exiting if the state is rti and the IR
// has the default value (IDCODE) by going through test_logic_reset.
// As soon as going through capture_dr or capture_ir no exit is
// allowed as this will change DR/IR.
seen_tlr = (seen_tlr || jtag_state == test_logic_reset) && (jtag_state != capture_dr) && (jtag_state != capture_ir);
// Due to a weird bug(??) xilinx impacts goes through another "capture_ir"/"capture_dr" cycle after
// reading IR/DR which unfortunately sets IR to the read-out IR value.
// Just ignore these transactions.
if ((jtag_state == exit1_ir && len == 5 && buffer[0] == 0x17) || (jtag_state == exit1_dr && len == 4 && buffer[0] == 0x0b))
{
// printf("Ignoring Bogus jtag State movement at jtag_state %d\n", jtag_state);
}
else
{
for (int i = 0; i < len; ++i)
{
//
// Do the actual cycle.
//
int tms = !!(buffer[i/8] & (1<<(i&7)));
//
// Track the state.
//
jtag_state = jtagStep(jtag_state, tms);
}
if (jtagScan((unsigned char *) buffer, (unsigned char *) buffer + nr_bytes, (unsigned char *) result, len) < 0)
{
//fprintf(stderr, "jtagScan failed\n");
// Can't stop now, have to sent (any) answer not to hung the IMPACT
jtagError = true;
}
}
 
// Send the Ansver
iResult = send(ClientSocket, result, nr_bytes, 0 );
if (iResult == SOCKET_ERROR)
{
printf("Send Failed with Error: %d\n", WSAGetLastError());
closesocket(ClientSocket);
WSACleanup();
return -2;
}
// printf("Bytes Sent: %d\n", iSendResult);
// printf("jtag state %d\n", jtag_state);
}
while (!(seen_tlr && jtag_state == run_test_idle));
 
return jtagError ? -2 : 0;
}
 
 
// Stop Handler - switch JTAG port off and stop program
void stopHandler(int sig)
{
jtagClosePort();
exit(1);
}
 
 
// Print help and stop program with error
void Help(char *progName)
{
fprintf(stderr, "Bad Parameters\n");
fprintf(stderr, "\n");
fprintf(stderr, "Usage: %s [arg]\n", progName);
fprintf(stderr, "\n");
fprintf(stderr, " Where [arg] is one of: \n");
fprintf(stderr, " -d Description Fing FTDI device by Description\n");
fprintf(stderr, " -l Location Fing FTDI device by Loaction\n");
fprintf(stderr, " -s Serial_number Fing FTDI device by it's SN\n");
fprintf(stderr, " -n Number Use N-th FTDI device\n");
fprintf(stderr, " The first FTDI device is used if no argument\n");
exit(2);
}
 
 
int __cdecl main(int argc, char *argv[])
{
// Variables
bool verbose = true;
 
// Program Info
printf("\n");
printf("Xilinx Virtual Cable Network Server\n");
printf("===================================\n");
printf("(c) miho 2012 v " VERSION "\n\n");
 
// Get program name
char *cp;
char *progName;
cp = argv[0];
progName=cp;
while (cp[0]!='\0')
{
if (cp[0]=='/' || cp[0]=='\\')
progName=cp+1;
cp++;
}
 
// Process command line params
char *findDeviceByStr = 0; // String parameter
int findDeviceBy = 0; // What does the string means
 
if (argc>1)
{
if (argc==3)
{
findDeviceByStr = argv[2];
if (strcmp(argv[1], "-d")==0)
{
findDeviceBy = OPEN_BY_DESCRIPTION;
}
else if (strcmp(argv[1], "-l")==0)
{
findDeviceBy = OPEN_BY_LOCATION;
}
else if (strcmp(argv[1], "-s")==0)
{
findDeviceBy = OPEN_BY_SERIAL_NUMBER;
}
else if (strcmp(argv[1], "-n")==0)
{
findDeviceBy = 0;
}
else
{
Help(progName);
}
}
else
{
Help(progName);
}
}
else
{
// Empty String - find device by number and number is empty
findDeviceBy = 0;
findDeviceByStr = "";
}
 
// Find, Init and Open FTDI USB Chip
if (jtagOpenPort(findDeviceBy, findDeviceByStr)<0) {
// No Device Found
fprintf(stderr, "ERROR: No Device Found\n");
return -1;
}
 
// Signal Handler (for CRTL+C)
signal(SIGINT, &stopHandler);
 
printf("Starting Network Server\n");
WSADATA wsaData;
int iResult;
 
SOCKET ListenSocket = INVALID_SOCKET;
SOCKET ClientSocket = INVALID_SOCKET;
 
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0)
{
fprintf(stderr, "WSAStartup failed with error: %d\n", iResult);
jtagClosePort();
return -2;
}
 
// Display HostName and Address
char sMyName[255];
gethostname(sMyName, sizeof(sMyName));
printf(" Host Name %s\n", sMyName);
hostent * pHostInfo;
pHostInfo = gethostbyname(sMyName);
printf(" Network Name %s\n", pHostInfo->h_name);
if (pHostInfo->h_length>0 && pHostInfo->h_length<=16)
{
printf(" Host Address ");
for (int i=0; i<pHostInfo->h_length-1; i++)
{
printf("%d.", (unsigned char)pHostInfo->h_addr_list[0][i]);
}
printf("%d\n", (unsigned char)pHostInfo->h_addr_list[0][pHostInfo->h_length-1]);
}
 
// Create Protocol Structure
struct addrinfo hints;
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET; // IP6
hints.ai_socktype = SOCK_STREAM; // Reliable two-way connection
hints.ai_protocol = IPPROTO_TCP; // Protocol TCP
hints.ai_flags = AI_PASSIVE;
 
// Resolve the server address and port (allocate structure "result")
struct addrinfo *result = NULL;
iResult = getaddrinfo(NULL, XVC_TCP_PORT, &hints, &result);
if ( iResult != 0 )
{
fprintf(stderr, "getaddrinfo failed with error: %d\n", iResult);
WSACleanup();
jtagClosePort();
return -2;
}
 
// Create a SOCKET
ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (ListenSocket == INVALID_SOCKET)
{
fprintf(stderr, "socket failed with error: %ld\n", WSAGetLastError());
freeaddrinfo(result);
WSACleanup();
jtagClosePort();
return -2;
}
 
// Bind the SOCKED (assign the address)
iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);
if (iResult == SOCKET_ERROR)
{
fprintf(stderr, "Bind failed with error: %d\n", WSAGetLastError());
freeaddrinfo(result);
closesocket(ListenSocket);
WSACleanup();
jtagClosePort();
return -2;
}
 
if (verbose)
{
printf(" Bound Socket %s\n", XVC_TCP_PORT);
}
 
// Help for user
printf(" Set in IMPACT xilinx_xvc host=%s:%s disableversioncheck=true\n", sMyName, XVC_TCP_PORT);
 
freeaddrinfo(result);
 
// Listen SOCKET
iResult = listen(ListenSocket, SOMAXCONN);
if (iResult == SOCKET_ERROR)
{
printf("listen failed with error: %d\n", WSAGetLastError());
closesocket(ListenSocket);
WSACleanup();
jtagClosePort();
return -2;
}
 
printf("\n");
 
do
{
printf(" Listen\n");
jtagSetLED(true);
 
// Accept a client SOCKET
sockaddr ClientSocetAddr;
int ClientSocetAddrLen = sizeof(sockaddr);
ClientSocket = accept(ListenSocket, &ClientSocetAddr, &ClientSocetAddrLen);
if (ClientSocket == INVALID_SOCKET)
{
printf("accept failed with error: %d\n", WSAGetLastError());
closesocket(ListenSocket);
WSACleanup();
jtagClosePort();
return -2;
}
 
// Print Accepted + Address
printf(" Accepted ");
jtagSetLED(false);
for (int i=2; i<2+4-1; i++)
{
printf("%d.", (unsigned char)ClientSocetAddr.sa_data[i]);
}
printf("%d:%d\n", (unsigned char)ClientSocetAddr.sa_data[2+4-1], (unsigned char)ClientSocetAddr.sa_data[0]*256+(unsigned char)ClientSocetAddr.sa_data[1]);
 
// Process Data until the peer shuts down the connection
int Cnt = 0;
printf(" Handle Data ");
do
{
iResult = handleData(ClientSocket);
if (iResult>=0)
{
printf(".");
Cnt++;
if (Cnt>40)
{
Cnt = 0;
printf("\n ");
}
}
}
while (iResult >= 0);
 
// Connection Closed by peer
if (iResult==-1)
{
// JTAG port
jtagSetIdle();
}
 
// Error - shutdown the connection
if (iResult==-2)
{
fprintf(stderr, " Disconnect\n");
iResult = shutdown(ClientSocket, SD_SEND);
if (iResult == SOCKET_ERROR)
{
fprintf(stderr, "shutdown failed with error: %d\n", WSAGetLastError());
}
iResult=-2; // Error
}
 
// cleanup
closesocket(ClientSocket);
 
}
// If not Error Listen Again
while (iResult!=-2);
 
// cleanup
closesocket(ListenSocket);
WSACleanup();
jtagClosePort();
 
return 1;
}
/Modules/CPLD_FPGA/XILINX_XVC/XVC_SOFTWARE/XVC_1x/mlab_xvcd.h
0,0 → 1,37
// Program Version
// ---------------
 
#define VERSION "1.03" // Program version
 
 
// JTAG Port Definitions
// ---------------------
 
// Use FTDI as Port Interface
#include "mlab_xvcd_port_FTDI.h"
 
// JTAG Port Pin Masks (look at mlab_xvcd_port_FTDI.h for pin names)
#define PORT_TCK FTDI_TXD // JTAG TCK (output)
#define PORT_TDI FTDI_RXD // JTAG TDI (output)
#define PORT_TDO FTDI_RTS // JTAG TDO (input)
#define PORT_TMS FTDI_CTS // JTAG TMS (output)
#define PORT_LED FTDI_RI | CBUS3 // Activituy LED (output)
 
// FTDI Settings
#define BAUD_RATE 1000000 // Baoud Rate (mult it by 16)
#define USB_LATENCY 1 // FTDI USB Latency Timer in ms (FT232R 0, FT2232 1)
 
// Performance Data (configuring XC3S50AN)
// ----------------
// BAUD_RATE USB_LATENCY --> FT220X FT232R
// 1000000 1 3s 2s
// 10000000 1 3s
// 1000000 0 2.8s
 
 
// Network Definitions
// -------------------
 
// TCP/IP
#define XVC_TCP_PORT "2542" // TCP Port Number to Listen to (string!)
#define XVC_JTAG_LEN (1024*8) // JTAG String Length in bits
/Modules/CPLD_FPGA/XILINX_XVC/XVC_SOFTWARE/XVC_1x/mlab_xvcd_port_FTDI.cpp
0,0 → 1,471
// Include FTDI library
#include "mlab_xvcd_port_FTDI.h"
 
 
// JTAG Output Pin Mask
#define IO_OUTPUT_MASK (PORT_TCK|PORT_TDI|PORT_TMS|PORT_LED) // Mask for all Output Pins
 
 
// Global Variables
FT_HANDLE ftHandle; // Handle for FTDI device
bool ftHandleValid = false; // Valid Handle
unsigned char PinStatus = 0; // Status of DBUS pins
unsigned char LedMask = 0; // LED Mask for DBUS data transfer
 
 
// Convert string to int (both decimal and hex string)
int atoiEx(char *s)
{
if (s[0]=='0' && (s[1]=='x' || s[1]=='X'))
{
// Hex Value
int i;
#pragma warning(disable: 4996) // Disable MS warning about scanf
sscanf(s, "%x", &i);
return i;
}
else
{
// Decimal Value
return atoi(s);
}
}
 
 
// Print FTDI Pin Names (from mask value)
void jtagPrintPinNames(int pinMask)
{
// 16bit (MSB is CBUS, LSB is DBUS)
int bit=15;
bool useDelimiter=false;
 
do
{
int mask = 1 << bit;
if (pinMask & mask)
{
if (useDelimiter)
{
printf("+");
}
if (bit > 7)
{
printf("CBUS%c", '0' + bit - 8);
}
else
{
printf("DBUS%c", '0' + bit);
switch (mask)
{
case FTDI_TXD: printf("(TXD)"); break;
case FTDI_RXD: printf("(RXD)"); break;
case FTDI_RTS: printf("(RTS)"); break;
case FTDI_CTS: printf("(CTS)"); break;
case FTDI_DTR: printf("(DTR)"); break;
case FTDI_DSR: printf("(DSR)"); break;
case FTDI_DCD: printf("(DCD)"); break;
case FTDI_RI: printf("(RI) "); break;
}
}
useDelimiter = true;
}
}
while (bit-- > 0);
}
 
 
// Verify pin usage
void jtagCheckPinConfig()
{
// Check CBUS usage
if ( (PORT_TCK) > 0x00FF )
fprintf(stderr, "\nFTDI: INTERNAL ERROR: TCK can't use CBUS signal"), exit(2);
if ( (PORT_TCK) == 0 )
fprintf(stderr, "\nFTDI: INTERNAL ERROR: TCK not defined"), exit(2);
if ( (PORT_TDI) > 0x00FF )
fprintf(stderr, "\nFTDI: INTERNAL ERROR: TDI can't use CBUS signal"), exit(2);
if ( (PORT_TDI) == 0 )
fprintf(stderr, "\nFTDI: INTERNAL ERROR: TDI not defined"), exit(2);
 
if ( (PORT_TDO) > 0x00FF )
fprintf(stderr, "\nFTDI: INTERNAL ERROR: TDO can't use CBUS signal"), exit(2);
if ( (PORT_TDO) == 0 )
fprintf(stderr, "\nFTDI: INTERNAL ERROR: TDO not defined"), exit(2);
 
if ( (PORT_TMS) > 0x00FF)
fprintf(stderr, "\nFTDI: INTERNAL ERROR: TMS can't use CBUS signal"), exit(2);
if ( (PORT_TMS) == 0 )
fprintf(stderr, "\nFTDI: INTERNAL ERROR: TMS not defined"), exit(2);
 
if ( (PORT_LED) > 0x0FFF)
fprintf(stderr, "\nFTDI: INTERNAL ERROR: LED can't use CBUS signal > 3"), exit(2);
}
 
 
// Print JTAG Pin Assignment
void jtagPrintPinConfig()
{
// Print pin masks human readable
printf(" JTAG Port Pins "); printf("TCK->"); jtagPrintPinNames(PORT_TCK); printf("\n");
printf(" "); printf("TDI->"); jtagPrintPinNames(PORT_TDI); printf("\n");
printf(" "); printf("TDO->"); jtagPrintPinNames(PORT_TDO); printf("\n");
printf(" "); printf("TMS->"); jtagPrintPinNames(PORT_TMS); printf("\n");
printf(" "); printf("LED->"); jtagPrintPinNames(PORT_LED); printf("\n");
}
 
 
// Connect to FTDI driver
int jtagOpenPort(int findDeviceBy, char *findDeviceByStr)
{
// Enumerate FTDI Devices
// ----------------------
 
FT_STATUS ftStatus;
 
// Print Library Version
printf("FTDI Connect\n");
DWORD dwLibraryVer;
ftStatus = FT_GetLibraryVersion(&dwLibraryVer);
if (ftStatus == FT_OK)
printf(" Library Version 0x%x\n", dwLibraryVer);
else
fprintf(stderr, "\nFTDI: Error Reading Library Version\n");
 
// Create Device Information List
DWORD numDevs = 0;
ftStatus = FT_CreateDeviceInfoList(&numDevs);
if (ftStatus == FT_OK)
printf(" Devices Found %d\n", numDevs);
else
printf(" No FTDI Device Found\n");
 
if (numDevs==0)
return -1;
 
// Print Config Info
jtagPrintPinConfig();
jtagCheckPinConfig();
printf("\n");
 
// List All FTDI Devices
FT_HANDLE ftHandleTemp;
DWORD Flags;
DWORD ID;
DWORD Type;
DWORD LocId;
char SerialNumber[16];
char Description[64];
for (DWORD i=0; i<numDevs; i++)
{
ftStatus = FT_GetDeviceInfoDetail(i, &Flags, &Type, &ID, &LocId, SerialNumber, Description, &ftHandleTemp);
if (ftStatus == FT_OK)
{
printf("Device %d\n", i);
printf(" Description \"%s\"\n", Description);
printf(" SerialNumber \"%s\"\n", SerialNumber);
//printf(" Flags 0x%x\n", Flags);
//printf(" Type 0x%x\n", Type);
//printf(" ID 0x%x\n", ID);
printf(" Location 0x%x\n\n", LocId);
}
}
 
// Select one Device and Open It
unsigned int selectedDeviceIndex = 0;
if (findDeviceBy==0)
{
// Select by Device Number
selectedDeviceIndex = atoiEx(findDeviceByStr);
if (numDevs<=selectedDeviceIndex)
{
fprintf(stderr, " There is no Device Number %d\n\n", selectedDeviceIndex);
return -1;
}
// Open device
ftStatus = FT_Open(selectedDeviceIndex, &ftHandle);
}
else
{
// Select by Description / Serial Number / Location
if (findDeviceBy==FT_OPEN_BY_LOCATION)
{
// Open device (location is number, not string)
int findDeviceByInt = atoiEx(findDeviceByStr);
ftStatus = FT_OpenEx((void*)findDeviceByInt, findDeviceBy, &ftHandle);
}
else
{
ftStatus = FT_OpenEx(findDeviceByStr, findDeviceBy, &ftHandle);
}
}
 
// Check Status
if (ftStatus == FT_OK)
{
ftHandleValid = true;
//printf(" FTDI Device Opened\n");
}
else
{
fprintf(stderr, " Can't Open FTDI Device (error code %d)\n\n", ftStatus);
return -1;
}
 
// Selected Device
ftStatus = FT_GetDeviceInfo(ftHandle, &Type, &ID, SerialNumber, Description, 0);
if (ftStatus == FT_OK)
{
printf("Selected Device\n");
printf(" Description \"%s\"\n", Description);
printf(" SerialNumber \"%s\"\n", SerialNumber);
//printf(" Type 0x%x\n", Type);
//printf(" ID 0x%x\n", ID);
}
 
// Get Driver Version
DWORD dwDriverVer;
ftStatus = FT_GetDriverVersion(ftHandle, &dwDriverVer);
if (ftStatus == FT_OK)
{
printf(" Device Driver Ver 0x%x\n", dwDriverVer);
}
else
{
fprintf(stderr, "FTDI: Error Reading Driver Version\n");
}
 
// Set BitBang Mode
ftStatus = FT_SetBitMode(ftHandle, (UCHAR)IO_OUTPUT_MASK, FT_BITMODE_SYNC_BITBANG); //FT_BITMODE_SYNC_BITBANG / FT_BITMODE_ASYNC_BITBANG
if (ftStatus == FT_OK)
{
// printf("Set BitBang Mode\n");
}
else
{
fprintf(stderr, "FTDI: Set BitBang Mode Failed %d\n", ftStatus);
}
 
// Set Baud Rate
ftStatus = FT_SetBaudRate(ftHandle, BAUD_RATE);
if (ftStatus == FT_OK)
{
printf(" Baud Rate %d\n", BAUD_RATE);
}
else
{
fprintf(stderr, "FTDI: Set Baud Rate Failed %d\n", ftStatus);
}
 
ftStatus = FT_Purge(ftHandle, FT_PURGE_RX | FT_PURGE_TX); // Purge both Rx and Tx buffers
if (ftStatus == FT_OK)
{
// printf("Purge \n");
}
else
{
fprintf(stderr, "FTDI: FT_Purge failed %d\n", ftStatus);
}
 
ftStatus = FT_SetLatencyTimer(ftHandle, USB_LATENCY); // Latency in ms
if (ftStatus == FT_OK)
{
printf(" USB Latency %d\n", USB_LATENCY);
}
else
{
fprintf(stderr, "FTDI: Set USB Latency Timer Failed %d\n", ftStatus);
}
 
printf("\n");
return 0;
}
 
 
// Enable or Disable Activity LED
void jtagSetLED(bool LedEnable)
{
 
// DBUS Connected LED (BitBang Mode)
LedMask = LedEnable ? PORT_LED & 0xFF : 0; // Set mask for jtagScan function
if (PORT_LED & 0xFF)
{
// Set / Reset LED Pin
DWORD BytesWritten;
DWORD BytesReceived;
unsigned char DataOut = LedMask | (PinStatus & ~PORT_LED); // Preserve PinStatus
unsigned char Dummy;
FT_Write(ftHandle, &DataOut, 1, &BytesWritten ); // Send 1 byte
FT_Read (ftHandle, &Dummy, 1, &BytesReceived); // Read 1 byte
//printf("[PinStatus %x DataOut %x]", PinStatus, DataOut);
}
 
// CBUS Connected LED (BitBang Mode) 1 and 0 state of the port
const unsigned char On = ( (((PORT_LED) & 0x0F00) >> 4) | (((PORT_LED) & 0x0F00) >> 8) );
const unsigned char Off = ( (((PORT_LED) & 0x0F00) >> 4) );
 
if (On)
{
FT_STATUS ftStatus;
 
// Set / Reset LED Pin
ftStatus = FT_SetBitMode(ftHandle, LedEnable ? On : Off, FT_BITMODE_CBUS_BITBANG);
 
// Return to used Mode
ftStatus = FT_SetBitMode(ftHandle, (UCHAR)IO_OUTPUT_MASK, FT_BITMODE_SYNC_BITBANG); //FT_BITMODE_SYNC_BITBANG / FT_BITMODE_ASYNC_BITBANG
}
}
 
 
// Set port to Idle state
void jtagSetIdle()
{
char b = 0; // Idle State for JTAG pins
DWORD BytesWritten;
DWORD BytesReceived;
 
// Write (idle state of pins)
FT_Write(ftHandle, &b, 1, &BytesWritten);
// Read (not to left data in input fifo)
FT_Read(ftHandle, &b, 1, &BytesReceived);
}
 
 
// Close FTDI connection
int jtagClosePort()
{
if (ftHandleValid)
{
jtagSetLED(false);
// Switch Off the Outputs
FT_Purge(ftHandle, FT_PURGE_RX | FT_PURGE_TX); // Purge both Rx and Tx buffers
FT_SetBitMode(ftHandle, 0, FT_BITMODE_SYNC_BITBANG);
// Close FTDI Lib
FT_Close(ftHandle);
ftHandleValid = false;
}
return 0;
}
 
 
// Send data to JTAG port and bring returned data
int jtagScan(const unsigned char *TMS, const unsigned char *TDI, unsigned char *TDO, int bits)
{
FT_STATUS ftStatus;
DWORD BytesWritten;
DWORD BytesReceived;
int r, t;
 
// Decompose TDI and TMS byte array to raw bitstream
//(1 TDI bit + 1 TMS bit --> 1 byte + 1 byte with TCK)
unsigned char buffer[16384];
if (bits > sizeof(buffer)/2)
{
fprintf(stderr, "\n FTDI: Out of Buffer Space for %d bits\n", bits);
return -1;
}
 
// Switch LED On
jtagSetLED(true);
 
// Prepare transmit data to buffer
for (int i = 0; i < bits; ++i)
{
unsigned char v = 0 | LedMask; // LED On / Off (on DBUS)
if (TMS[i/8] & (1<<(i&7)))
{
v |= (PORT_TMS);
// printf("T");
}
else
{
// printf("t");
}
if (TDI[i/8] & (1<<(i&7)))
{
v |= (PORT_TDI);
// printf("|");
}
else
{
// printf(".");
}
buffer[i * 2 + 0] = v;
buffer[i * 2 + 1] = v | (PORT_TCK);
}
PinStatus = buffer[bits*2-1];
// printf("\n");
 
// Send data to FTDI
r = 0;
while (r < bits * 2)
{
t = bits * 2 - r;
if (t > FTDI_MAX_WRITESIZE)
{
t = FTDI_MAX_WRITESIZE;
}
// printf("writing %d bytes to FTDI\n", t);
ftStatus = FT_Write(ftHandle, buffer+r, t, &BytesWritten);
if (ftStatus != FT_OK)
{
fprintf(stderr, "\n FTDI: Error Writing\n");
return -2;
}
 
int i = 0;
while (i < t)
{
FT_SetTimeouts(ftHandle, 5000, 0); // timeout 5 sec
ftStatus = FT_Read(ftHandle, buffer+r+i, t-i, &BytesReceived);
if (ftStatus == FT_OK)
{
if (BytesReceived == t-i)
{
// FT_Read OK
// printf("Read from FTDI %d bytes", BytesReceived);
}
else
{
// FT_Read Timeout
fprintf(stderr, "\n FTDI: Read Timeout\n");
return -2;
}
}
else
{
fprintf(stderr, "\n FTDI: Error Reading\n");// Error
return -2;
}
 
i += BytesReceived;
}
r += t;
}
 
// Pack TDO bitstream from receive buffer to byte array
memset(TDO, 0, (bits + 7) / 8);
for (int i = 0; i < bits; ++i)
{
if (buffer[i * 2 + 1] & (PORT_TDO))
{
TDO[i/8] |= 1 << (i&7);
// printf("H");
}
else
{
// printf("L");
}
}
// printf("\n");
// printf(" Bits %d ", bit_counter);
 
// Switch LED Off
jtagSetLED(false);
 
return 0;
}
/Modules/CPLD_FPGA/XILINX_XVC/XVC_SOFTWARE/XVC_1x/mlab_xvcd_port_FTDI.h
0,0 → 1,81
#ifndef MLAB_XVCD_PORT_FTDI_H
#define MLAB_XVCD_PORT_FTDI_H
 
 
// Pin Defs
// --------
 
// FTDI Pin Mask Definitions (valid for FT232R)
#define DBUS0 0x0001 // Bit 0 Data Bus
#define DBUS1 0x0002 // Bit 1
#define DBUS2 0x0004 // Bit 2
#define DBUS3 0x0008 // Bit 3
#define DBUS4 0x0010 // Bit 4
#define DBUS5 0x0020 // Bit 5
#define DBUS6 0x0040 // Bit 6
#define DBUS7 0x0080 // Bit 7
 
#define CBUS0 0x0100 // Bit 0 Control Bus
#define CBUS1 0x0200 // Bit 1
#define CBUS2 0x0400 // Bit 2
#define CBUS3 0x0800 // Bit 3
 
#define FTDI_TXD DBUS0 // Bit 0 RS232 Signal Alias
#define FTDI_RXD DBUS1 // Bit 1
#define FTDI_RTS DBUS2 // Bit 2
#define FTDI_CTS DBUS3 // Bit 3
#define FTDI_DTR DBUS4 // Bit 4
#define FTDI_DSR DBUS5 // Bit 5
#define FTDI_DCD DBUS6 // Bit 6
#define FTDI_RI DBUS7 // Bit 7
 
 
// Includes
// --------
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
 
#include <windows.h> // Windows Console Application
#include <stdlib.h> // Standard Library (exit, atoi, ...)
#include <stdio.h> // Standard IO (printf, ...)
#include "mlab_xvcd.h" // Program Config (pin defs, settings, ...)
 
// Link with library
#include "ftd2xx.h" // FTDI Library
#pragma comment (lib, "ftd2xx.lib") // Tell MS compiller to link with this library
 
 
// Public Definitions
// ------------------
 
 
// Find Mode (for port open)
#define OPEN_BY_DESCRIPTION FT_OPEN_BY_DESCRIPTION // Find device by Description String
#define OPEN_BY_LOCATION FT_OPEN_BY_LOCATION // Find device by Bus Location
#define OPEN_BY_SERIAL_NUMBER FT_OPEN_BY_SERIAL_NUMBER // Find device by it's Serial Number
 
// Max Data lengt to send to FTDI as one block
#define FTDI_MAX_WRITESIZE 1024
 
 
// Function Prototypes (public functions only)
// -------------------------------------------
 
// Connect to FTDI driver
// Find the device and open driver
int jtagOpenPort(int findDeviceBy, char *findDeviceByStr);
 
// Enable or Disable Activity LED
void jtagSetLED(bool LedEnable);
 
// Set port to Idle state (all zeroes)
void jtagSetIdle();
 
// Close FTDI connection
int jtagClosePort();
 
// Send data to JTAG port and bring returned data
// Turn LED On during processing
int jtagScan(const unsigned char *TMS, const unsigned char *TDI, unsigned char *TDO, int bits);
 
#endif