diff --git a/api/liboni/Makefile b/api/liboni/Makefile index d799780..859466c 100644 --- a/api/liboni/Makefile +++ b/api/liboni/Makefile @@ -11,7 +11,7 @@ OBJ := $(SRC:.c=.o) POSIX_OBJ := $(POSIX_SRC:.c=.o) CFLAGS := -Wall -W -Werror -fPIC -O3 ISOCFLAGS := -pedantic -LDFLAGS := -L. +LDFLAGS := -L. -ldl PREFIX := /usr/local # Turn wildcard list into comma separated list @@ -51,7 +51,7 @@ $(SNAME): $(OBJ) $(POSIX_OBJ) $(DNAME): LDFLAGS += -shared $(DNAME): $(OBJ) $(POSIX_OBJ) - $(CC) $(LDFLAGS) $^ -o $@ + $(CC) $^ -o $@ $(LDFLAGS) $(OBJ): CFLAGS += $(ISOCFLAGS) diff --git a/api/liboni/drivers/ft600/Makefile b/api/liboni/drivers/ft600/Makefile index e48d407..1dafcee 100644 --- a/api/liboni/drivers/ft600/Makefile +++ b/api/liboni/drivers/ft600/Makefile @@ -6,9 +6,9 @@ DNAMELN := $(NAME).so SRC := onidriver_ft600.c circbuffer.c OBJ := $(SRC:.c=.o) FT_PATH := ./ft3dxx/linux -CFLAGS := -pedantic -Wall -W -Werror -fPIC -O2 -g $(DEFS) -I$(FT_PATH) +CFLAGS := -pedantic -Wall -W -Werror -fPIC -O2 $(DEFS) -I$(FT_PATH) LDFLAGS := -L. -L$(FT_PATH) -LIBS := -lftd3xx -lpthread +LIBS := -lftd3xx -pthread PREFIX := /usr/local # Turn wildcard list into comma separated list @@ -29,8 +29,8 @@ install: $(SNAME) $(DNAME) ## Install driver. Defaults to make install PREFIX=/u @[ -d $(DESTDIR)$(PREFIX)/lib ] || mkdir -p $(DESTDIR)$(PREFIX)/lib @[ -d $(DESTDIR)$(PREFIX)/include ] || mkdir -p $(DESTDIR)$(PREFIX)/include cp $(DNAME) $(DESTDIR)$(PREFIX)/lib/$(DNAME) - cp $(wildcard $(FT_PATH)/*.so*) $(DESTDIR)$(PREFIX)/lib/ - cp $(wildcard $(FT_PATH)/*.h) $(DESTDIR)$(PREFIX)/include/ +# cp $(wildcard $(FT_PATH)/*.so*) $(DESTDIR)$(PREFIX)/lib/ +# cp $(wildcard $(FT_PATH)/*.h) $(DESTDIR)$(PREFIX)/include/ @[ -d $(DESTDIR)$(PREFIX)/lib/$(DNAMELN) ] || $(RM) $(DESTDIR)$(PREFIX)/lib/$(DNAMELN) ln -s $(DESTDIR)$(PREFIX)/lib/$(DNAME) $(DESTDIR)$(PREFIX)/lib/$(DNAMELN) ldconfig diff --git a/api/liboni/drivers/ft600/ft3dxx/linux/FTD3XX.h b/api/liboni/drivers/ft600/ft3dxx/linux/FTD3XX.h old mode 100755 new mode 100644 index 7620ebe..6377c4f --- a/api/liboni/drivers/ft600/ft3dxx/linux/FTD3XX.h +++ b/api/liboni/drivers/ft600/ft3dxx/linux/FTD3XX.h @@ -1,3 +1,43 @@ +/*++ + +Copyright � 2016-2021 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: + +ftd3xx.h + +Abstract: + +Superspeed USB device driver for FTDI FT60X devices +FTD3XX library definitions +Applies to Linux (__linux__ macro set) + +Environment: + +User Mode + + +--*/ + #ifndef FTD3XX_H_DKFTHSPV #define FTD3XX_H_DKFTHSPV @@ -13,67 +53,11 @@ #include #endif -#if defined(_WIN32) || defined(_WIN64) - -#include -#ifdef FTD3XX_EXPORTS - #define FTD3XX_API __declspec(dllexport) -#elif defined(FTD3XX_STATIC) - #define FTD3XX_API +#if defined (__linux__) || defined (__APPLE__) +// Compiling on a non-Windows platform. +#include "Types.h" #else - #define FTD3XX_API __declspec(dllimport) -#endif - -#else /* _WIN32 || _WIN64 */ - -#define WINAPI -#ifndef FTD3XX_EXPORTS -#define FTD3XX_API -#else /* !FTD3XX_EXPORTS */ -#define FTD3XX_API __attribute__((visibility("default"))) -#endif /* FTD3XX_EXPORTS */ - -typedef uint16_t WORD; -typedef uint32_t DWORD; -typedef uint64_t DWORD64; -typedef uint32_t * LPDWORD; -typedef uint8_t BYTE; -typedef uint8_t UCHAR; -typedef uint16_t USHORT; -typedef USHORT * PUSHORT; -typedef unsigned int ULONG; -typedef uint16_t WCHAR; -typedef uint8_t * LPBYTE; -typedef bool BOOL; -typedef UCHAR *PUCHAR; -typedef ULONG *PULONG; -typedef const char * LPCSTR; - -typedef void VOID; -typedef void * PVOID; -typedef void * LPVOID; -typedef char * PCHAR; -typedef void * HANDLE; - -typedef struct _OVERLAPPED { - DWORD Internal; - DWORD InternalHigh; - union { - struct { - DWORD Offset; - DWORD OffsetHigh; - }; - PVOID Pointer; - }; - HANDLE hEvent; -} OVERLAPPED, *LPOVERLAPPED; - -typedef struct _SECURITY_ATTRIBUTES { - DWORD nLength; - LPVOID lpSecurityDescriptor; - BOOL bInheritHandle; -} SECURITY_ATTRIBUTES , *LPSECURITY_ATTRIBUTES; - +#error "Unknown compiler" #endif /* OTHER OS */ // @@ -94,8 +78,8 @@ typedef struct _SECURITY_ATTRIBUTES { // // Pipe Direction // -#define FT_IS_READ_PIPE(ucEndpoint) ((ucEndpoint) & 0x80) -#define FT_IS_WRITE_PIPE(ucEndpoint) (!((ucEndpoint) & 0x80)) +#define FT_IS_READ_PIPE(ucPipeID) ((ucPipeID) & 0x80) +#define FT_IS_WRITE_PIPE(ucPipeID) (!((ucPipeID) & 0x80)) // // Pipe type @@ -129,7 +113,6 @@ typedef struct _SECURITY_ATTRIBUTES { #define FT_LIST_BY_INDEX 0x40000000 #define FT_LIST_NUMBER_ONLY 0x80000000 - // // GPIO direction, value // @@ -140,8 +123,28 @@ typedef struct _SECURITY_ATTRIBUTES { #define FT_GPIO_0 0 #define FT_GPIO_1 1 +// +// Open/Create handle +// typedef PVOID FT_HANDLE, *PFT_HANDLE; +/* Use Event* like a Windows HANDLE */ +typedef struct Event +{ + /** Verify that handle really does point to an Event structure. */ + int signature; + /** Contains a mutex amd a condition on which threads may wait. */ + EVENT_HANDLE eh; + /** State of the event: 1 is signalled, 0 is not signalled. */ + int signalled; + /** Only reset state when caller explicitly requests it. */ + int manualReset; +} +Event; + +// +// FT Status Codes +// enum _FT_STATUS { FT_OK, FT_INVALID_HANDLE, @@ -178,25 +181,43 @@ enum _FT_STATUS { FT_INCORRECT_DEVICE_PATH, FT_OTHER_ERROR, + }; +// +// FT Status macros +// typedef ULONG FT_STATUS; #define FT_SUCCESS(status) ((status) == FT_OK) #define FT_FAILED(status) ((status) != FT_OK) -typedef enum _FT_PIPE_TYPE { +// +// Pipe types +// +typedef enum _FT_PIPE_TYPE +{ FTPipeTypeControl, FTPipeTypeIsochronous, FTPipeTypeBulk, FTPipeTypeInterrupt + } FT_PIPE_TYPE; -typedef struct _FT_COMMON_DESCRIPTOR { +// +// Common descriptor header +// +typedef struct _FT_COMMON_DESCRIPTOR +{ UCHAR bLength; UCHAR bDescriptorType; + } FT_COMMON_DESCRIPTOR, *PFT_COMMON_DESCRIPTOR; -typedef struct _FT_DEVICE_DESCRIPTOR{ +// +// Device descriptor +// +typedef struct _FT_DEVICE_DESCRIPTOR +{ UCHAR bLength; UCHAR bDescriptorType; USHORT bcdUSB; @@ -211,9 +232,14 @@ typedef struct _FT_DEVICE_DESCRIPTOR{ UCHAR iProduct; UCHAR iSerialNumber; UCHAR bNumConfigurations; + } FT_DEVICE_DESCRIPTOR, *PFT_DEVICE_DESCRIPTOR; -typedef struct _FT_CONFIGURATION_DESCRIPTOR { +// +// Configuration descriptor +// +typedef struct _FT_CONFIGURATION_DESCRIPTOR +{ UCHAR bLength; UCHAR bDescriptorType; USHORT wTotalLength; @@ -222,9 +248,14 @@ typedef struct _FT_CONFIGURATION_DESCRIPTOR { UCHAR iConfiguration; UCHAR bmAttributes; UCHAR MaxPower; + } FT_CONFIGURATION_DESCRIPTOR, *PFT_CONFIGURATION_DESCRIPTOR; -typedef struct _FT_INTERFACE_DESCRIPTOR { +// +// Interface descriptor +// +typedef struct _FT_INTERFACE_DESCRIPTOR +{ UCHAR bLength; UCHAR bDescriptorType; UCHAR bInterfaceNumber; @@ -234,47 +265,81 @@ typedef struct _FT_INTERFACE_DESCRIPTOR { UCHAR bInterfaceSubClass; UCHAR bInterfaceProtocol; UCHAR iInterface; + } FT_INTERFACE_DESCRIPTOR, *PFT_INTERFACE_DESCRIPTOR; -typedef struct _FT_STRING_DESCRIPTOR { +// +// String descriptor +// +typedef struct _FT_STRING_DESCRIPTOR +{ UCHAR bLength; UCHAR bDescriptorType; WCHAR szString[256]; + } FT_STRING_DESCRIPTOR, *PFT_STRING_DESCRIPTOR; -typedef struct _FT_PIPE_INFORMATION { +// +// Pipe information +// +typedef struct _FT_PIPE_INFORMATION +{ FT_PIPE_TYPE PipeType; UCHAR PipeId; USHORT MaximumPacketSize; UCHAR Interval; + } FT_PIPE_INFORMATION, *PFT_PIPE_INFORMATION; -typedef struct _FT_SETUP_PACKET { +// +// Control setup packet +// +typedef struct _FT_SETUP_PACKET +{ UCHAR RequestType; UCHAR Request; USHORT Value; USHORT Index; USHORT Length; + } FT_SETUP_PACKET, *PFT_SETUP_PACKET; -typedef enum _E_FT_NOTIFICATION_CALLBACK_TYPE { +// +// Notification callback type +// +typedef enum _E_FT_NOTIFICATION_CALLBACK_TYPE +{ E_FT_NOTIFICATION_CALLBACK_TYPE_DATA, E_FT_NOTIFICATION_CALLBACK_TYPE_GPIO, E_FT_NOTIFICATION_CALLBACK_TYPE_INTERRUPT, + } E_FT_NOTIFICATION_CALLBACK_TYPE; -typedef struct _FT_NOTIFICATION_CALLBACK_INFO_DATA { +// +// Notification callback information data +// +typedef struct _FT_NOTIFICATION_CALLBACK_INFO_DATA +{ ULONG ulRecvNotificationLength; UCHAR ucEndpointNo; + } FT_NOTIFICATION_CALLBACK_INFO_DATA; -typedef struct _FT_NOTIFICATION_CALLBACK_INFO_GPIO { +// +// Notification callback information gpio +// +typedef struct _FT_NOTIFICATION_CALLBACK_INFO_GPIO +{ BOOL bGPIO0; BOOL bGPIO1; + } FT_NOTIFICATION_CALLBACK_INFO_GPIO; +// +// Notification callback function +// typedef VOID(*FT_NOTIFICATION_CALLBACK)(PVOID pvCallbackContext, - E_FT_NOTIFICATION_CALLBACK_TYPE eCallbackType, PVOID pvCallbackInfo); + E_FT_NOTIFICATION_CALLBACK_TYPE eCallbackType, PVOID pvCallbackInfo); // // Chip configuration - FlashEEPROMDetection @@ -300,51 +365,60 @@ typedef VOID(*FT_NOTIFICATION_CALLBACK)(PVOID pvCallbackContext, // // Chip configuration - FIFO Clock Speed // -typedef enum { +typedef enum +{ CONFIGURATION_FIFO_CLK_100, CONFIGURATION_FIFO_CLK_66, CONFIGURATION_FIFO_CLK_50, CONFIGURATION_FIFO_CLK_40, + } CONFIGURATION_FIFO_CLK; // // Chip configuration - FIFO Mode // -typedef enum { +typedef enum +{ CONFIGURATION_FIFO_MODE_245, CONFIGURATION_FIFO_MODE_600, CONFIGURATION_FIFO_MODE_COUNT, + } CONFIGURATION_FIFO_MODE; // // Chip configuration - Channel Configuration // -typedef enum { +typedef enum +{ CONFIGURATION_CHANNEL_CONFIG_4, CONFIGURATION_CHANNEL_CONFIG_2, CONFIGURATION_CHANNEL_CONFIG_1, CONFIGURATION_CHANNEL_CONFIG_1_OUTPIPE, CONFIGURATION_CHANNEL_CONFIG_1_INPIPE, CONFIGURATION_CHANNEL_CONFIG_COUNT, + } CONFIGURATION_CHANNEL_CONFIG; // // Chip configuration - Optional Feature Support // -typedef enum { +typedef enum +{ CONFIGURATION_OPTIONAL_FEATURE_DISABLEALL = 0, - CONFIGURATION_OPTIONAL_FEATURE_ENABLEBATTERYCHARGING = 1, - CONFIGURATION_OPTIONAL_FEATURE_DISABLECANCELSESSIONUNDERRUN = 2, - CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCH1 = 4, - CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCH2 = 8, - CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCH3 = 0x10, - CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCH4 = 0x20, - CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCHALL = 0x3C, - CONFIGURATION_OPTIONAL_FEATURE_DISABLEUNDERRUN_INCH1 = (0x1 << 6), - CONFIGURATION_OPTIONAL_FEATURE_DISABLEUNDERRUN_INCH2 = (0x1 << 7), - CONFIGURATION_OPTIONAL_FEATURE_DISABLEUNDERRUN_INCH3 = (0x1 << 8), - CONFIGURATION_OPTIONAL_FEATURE_DISABLEUNDERRUN_INCH4 = (0x1 << 9), - CONFIGURATION_OPTIONAL_FEATURE_DISABLEUNDERRUN_INCHALL = (0xF << 6), + CONFIGURATION_OPTIONAL_FEATURE_ENABLEBATTERYCHARGING = (0x1 << 0), + CONFIGURATION_OPTIONAL_FEATURE_DISABLECANCELSESSIONUNDERRUN = (0x1 << 1), /* Setting this will Ignore session underrun */ + CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCH1 = (0x1 << 2), + CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCH2 = (0x1 << 3), + CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCH3 = (0x1 << 4), + CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCH4 = (0x1 << 5), + CONFIGURATION_OPTIONAL_FEATURE_ENABLENOTIFICATIONMESSAGE_INCHALL = (0xF << 2), + CONFIGURATION_OPTIONAL_FEATURE_DISABLEUNDERRUN_INCH1 = (0x1 << 6), /* Setting this will Ignore underrun at FIFO Bus-Width for IN channel#1 */ + CONFIGURATION_OPTIONAL_FEATURE_DISABLEUNDERRUN_INCH2 = (0x1 << 7), /* Setting this will Ignore underrun at FIFO Bus-Width for IN channel#2 */ + CONFIGURATION_OPTIONAL_FEATURE_DISABLEUNDERRUN_INCH3 = (0x1 << 8), /* Setting this will Ignore underrun at FIFO Bus-Width for IN channel#3 */ + CONFIGURATION_OPTIONAL_FEATURE_DISABLEUNDERRUN_INCH4 = (0x1 << 9), /* Setting this will Ignore underrun at FIFO Bus-Width for IN channel#4 */ + CONFIGURATION_OPTIONAL_FEATURE_DISABLEUNDERRUN_INCHALL = (0xF << 6), /* Setting this will Ignore underrun at FIFO Bus-Width for all IN channel */ + CONFIGURATION_OPTIONAL_FEATURE_ENABLEALL = 0xFFFF, + } CONFIGURATION_OPTIONAL_FEATURE_SUPPORT; // @@ -372,11 +446,11 @@ typedef enum { #define CONFIGURATION_DEFAULT_MSIOCONTROL 0x10800 #define CONFIGURATION_DEFAULT_GPIOCONTROL 0x0 -// // // Chip configuration structure // -typedef struct { +typedef struct +{ // Device Descriptor USHORT VendorID; USHORT ProductID; @@ -385,12 +459,12 @@ typedef struct { UCHAR StringDescriptors[128]; // Configuration Descriptor - UCHAR Reserved; + UCHAR bInterval; // Interrupt interval (Valid range: 1-16) UCHAR PowerAttributes; USHORT PowerConsumption; // Data Transfer Configuration - UCHAR reserved; + UCHAR Reserved2; UCHAR FIFOClock; UCHAR FIFOMode; UCHAR ChannelConfig; @@ -403,51 +477,65 @@ typedef struct { // MSIO and GPIO Configuration ULONG MSIO_Control; ULONG GPIO_Control; + } FT_60XCONFIGURATION, *PFT_60XCONFIGURATION; // // Device types // -typedef enum _FT_DEVICE { + +typedef enum _FT_DEVICE +{ FT_DEVICE_UNKNOWN = 3, FT_DEVICE_600 = 600, FT_DEVICE_601 = 601, FT_DEVICE_602 = 602, FT_DEVICE_603 = 603, + } FT_DEVICE; // // Device information // -typedef enum _FT_FLAGS { + +typedef enum _FT_FLAGS +{ FT_FLAGS_OPENED = 1, FT_FLAGS_HISPEED = 2, FT_FLAGS_SUPERSPEED = 4 + } FT_FLAGS; -typedef struct _FT_DEVICE_LIST_INFO_NODE { +typedef struct _FT_DEVICE_LIST_INFO_NODE +{ ULONG Flags; // FT_FLAGS ULONG Type; ULONG ID; DWORD LocId; - char SerialNumber[32]; + char SerialNumber[16]; char Description[32]; FT_HANDLE ftHandle; + } FT_DEVICE_LIST_INFO_NODE; -enum FT_GPIO_PULL { +enum FT_GPIO_PULL +{ GPIO_PULL_50K_PD, GPIO_PULL_HIZ, GPIO_PULL_50K_PU, GPIO_PULL_DEFAULT = GPIO_PULL_50K_PD + }; -enum FT_PIPE_DIRECTION { +enum FT_PIPE_DIRECTION +{ FT_PIPE_DIR_IN, FT_PIPE_DIR_OUT, FT_PIPE_DIR_COUNT, + }; +#if defined (__linux__) || defined (__APPLE__) struct FT_PIPE_TRANSFER_CONF { /* set to true PIPE is not used, default set to FALSE */ BOOL fPipeNotUsed; @@ -470,8 +558,11 @@ struct FT_PIPE_TRANSFER_CONF { /* 1G by default, used by FT600 and FT601 only, set 0 to use * default value */ DWORD dwStreamingSize; + }; +#endif /*__linux__ __APPLE__*/ +#if defined (__linux__) || defined (__APPLE__) typedef struct _FT_TRANSFER_CONF { /* structure size: sizeof(FT_TRANSFER_CONF) */ WORD wStructSize; @@ -489,30 +580,88 @@ typedef struct _FT_TRANSFER_CONF { /* Do not flush device side residue buffer after reopen the * device, default set to FALSE */ BOOL fKeepDeviceSideBufferAfterReopen; + } FT_TRANSFER_CONF; +#endif /*__linux__ __APPLE__*/ + +// +// API Functions +// +// Declare FTD3XX_STATIC if using the static library +// Else if using dynamic link library +// Don't enable FTD3XX_EXPORTS +// + +#ifndef FTD3XX_EXPORTS +#define FTD3XX_API +#else /* !FTD3XX_EXPORTS */ +#define FTD3XX_API __attribute__((visibility("default"))) +#endif /* FTD3XX_EXPORTS */ + #ifdef __cplusplus extern "C" { #endif -/********************************************************************** -* Linux only APIs * -**********************************************************************/ +FTD3XX_API FT_STATUS FT_Create( + PVOID pvArg, + DWORD dwFlags, + FT_HANDLE *pftHandle + ); + +FTD3XX_API FT_STATUS FT_Close( + FT_HANDLE ftHandle); + +FTD3XX_API FT_STATUS FT_GetVIDPID( + FT_HANDLE ftHandle, + PUSHORT puwVID, + PUSHORT puwPID + ); + +FTD3XX_API FT_STATUS FT_WritePipe( + FT_HANDLE ftHandle, + UCHAR ucPipeID, + PUCHAR pucBuffer, + ULONG ulBufferLength, + PULONG pulBytesTransferred, + DWORD dwTimeoutInMs); + +FTD3XX_API FT_STATUS FT_ReadPipe( + FT_HANDLE ftHandle, + UCHAR ucPipeID, + PUCHAR pucBuffer, + ULONG ulBufferLength, + PULONG pulBytesTransferred, + DWORD dwTimeoutInMs); -/* Set transfer parameters for each FIFO channel - * Must be called before FT_Create is called. Need to be called again - * after FT_Close(), otherwise default parameters will be used. + +/* WritePipe with timeout * - * Default value will be used for each FIFO channel if this function - * is not been called. Please refer to structure defines for default - * value. + * dwFifoID: FIFO interface ID. Valid values are 0-3 which represents + * FIFO channel 1-4 for FT600 and FT601 + * dwTimeoutInMs: timeout in milliseconds, 0 means return immediately + * if no data */ +FTD3XX_API FT_STATUS FT_WritePipeEx( + FT_HANDLE ftHandle, + UCHAR ucFifoID, + PUCHAR pucBuffer, + ULONG ulBufferLength, + PULONG pulBytesTransferred, + DWORD dwTimeoutInMs); + +/* WritePipeAsync with Overlapped * - * pConf: Please refer to structure FT_TRANSFER_CONF * dwFifoID: FIFO interface ID. Valid values are 0-3 which represents - * FIFO channel 1-4 for FT600 and FT601 */ -FTD3XX_API FT_STATUS WINAPI FT_SetTransferParams( - FT_TRANSFER_CONF *pConf, - DWORD dwFifoID); + * FIFO channel 1-4 for FT600 and FT601 + * pOverlapped: An optional pointer to an OVERLAPPED structure, + * this is used for asynchronous operations */ +FTD3XX_API FT_STATUS FT_WritePipeAsync( + FT_HANDLE ftHandle, + UCHAR ucFifoID, + PUCHAR pucBuffer, + ULONG ulBufferLength, + PULONG pulBytesTransferred, + LPOVERLAPPED pOverlapped); /* ReadPipe with timeout * @@ -520,305 +669,231 @@ FTD3XX_API FT_STATUS WINAPI FT_SetTransferParams( * FIFO channel 1-4 for FT600 and FT601 * dwTimeoutInMs: timeout in milliseconds, 0 means return immediately * if no data */ -FTD3XX_API FT_STATUS WINAPI FT_ReadPipeEx( - FT_HANDLE ftHandle, - UCHAR ucFifoID, - PUCHAR pucBuffer, - ULONG ulBufferLength, - PULONG pulBytesTransferred, - DWORD dwTimeoutInMs); - -/* WritePipe with timeout +FTD3XX_API FT_STATUS FT_ReadPipeEx( + FT_HANDLE ftHandle, + UCHAR ucFifoID, + PUCHAR pucBuffer, + ULONG ulBufferLength, + PULONG pulBytesTransferred, + DWORD dwTimeoutInMs); + +/* ReadPipe_Async with Overlapped * * dwFifoID: FIFO interface ID. Valid values are 0-3 which represents * FIFO channel 1-4 for FT600 and FT601 * dwTimeoutInMs: timeout in milliseconds, 0 means return immediately * if no data */ -FTD3XX_API FT_STATUS WINAPI FT_WritePipeEx( - FT_HANDLE ftHandle, - UCHAR ucFifoID, - PUCHAR pucBuffer, - ULONG ulBufferLength, - PULONG pulBytesTransferred, - DWORD dwTimeoutInMs); +FTD3XX_API FT_STATUS FT_ReadPipeAsync( + FT_HANDLE ftHandle, + UCHAR ucFifoID, + PUCHAR pucBuffer, + ULONG ulBufferLength, + PULONG pulBytesTransferred, + LPOVERLAPPED pOverlapped); + + +FTD3XX_API FT_STATUS FT_GetOverlappedResult( + FT_HANDLE ftHandle, + LPOVERLAPPED pOverlapped, + PULONG pulBytesTransferred, + BOOL bWait + ); + +FTD3XX_API FT_STATUS FT_InitializeOverlapped( + FT_HANDLE ftHandle, + LPOVERLAPPED pOverlapped + ); + +FTD3XX_API FT_STATUS FT_ReleaseOverlapped( + FT_HANDLE ftHandle, + LPOVERLAPPED pOverlapped + ); + +FTD3XX_API FT_STATUS FT_SetStreamPipe( + FT_HANDLE ftHandle, + BOOL bAllWritePipes, + BOOL bAllReadPipes, + UCHAR ucPipeID, + ULONG ulStreamSize + ); + +FTD3XX_API FT_STATUS FT_ClearStreamPipe( + FT_HANDLE ftHandle, + BOOL bAllWritePipes, + BOOL bAllReadPipes, + UCHAR ucPipeID + ); + +FTD3XX_API FT_STATUS FT_FlushPipe( + FT_HANDLE ftHandle, + UCHAR ucPipeID + ); + +FTD3XX_API FT_STATUS FT_AbortPipe( + FT_HANDLE ftHandle, + UCHAR ucPipeID + ); + +FTD3XX_API FT_STATUS FT_GetDeviceDescriptor( + FT_HANDLE ftHandle, + PFT_DEVICE_DESCRIPTOR ptDescriptor + ); + +FTD3XX_API FT_STATUS FT_GetConfigurationDescriptor( + FT_HANDLE ftHandle, + PFT_CONFIGURATION_DESCRIPTOR ptDescriptor + ); + +FTD3XX_API FT_STATUS FT_GetInterfaceDescriptor( + FT_HANDLE ftHandle, + UCHAR ucInterfaceIndex, + PFT_INTERFACE_DESCRIPTOR ptDescriptor + ); + +FTD3XX_API FT_STATUS FT_GetPipeInformation( + FT_HANDLE ftHandle, + UCHAR ucInterfaceIndex, + UCHAR ucPipeID, + PFT_PIPE_INFORMATION ptPipeInformation + ); + +FTD3XX_API FT_STATUS FT_GetStringDescriptor( + FT_HANDLE ftHandle, + UCHAR ucStringIndex, + PFT_STRING_DESCRIPTOR ptDescriptor + ); + +FTD3XX_API FT_STATUS FT_GetDescriptor( + FT_HANDLE ftHandle, + UCHAR ucDescriptorType, + UCHAR ucIndex, + PUCHAR pucBuffer, + ULONG ulBufferLength, + PULONG pulLengthTransferred + ); + +FTD3XX_API FT_STATUS FT_ControlTransfer( + FT_HANDLE ftHandle, + FT_SETUP_PACKET tSetupPacket, + PUCHAR pucBuffer, + ULONG ulBufferLength, + PULONG pulLengthTransferred + ); + +FTD3XX_API FT_STATUS FT_SetNotificationCallback( + FT_HANDLE ftHandle, + FT_NOTIFICATION_CALLBACK pCallback, + PVOID pvCallbackContext + ); + +FTD3XX_API VOID FT_ClearNotificationCallback( + FT_HANDLE ftHandle + ); + +FTD3XX_API FT_STATUS FT_GetChipConfiguration( + FT_HANDLE ftHandle, + PVOID pvConfiguration + ); + +FTD3XX_API FT_STATUS FT_SetChipConfiguration( + FT_HANDLE ftHandle, + PVOID pvConfiguration + ); + +FTD3XX_API FT_STATUS FT_GetFirmwareVersion( + FT_HANDLE ftHandle, + PULONG pulFirmwareVersion + ); + +FTD3XX_API FT_STATUS FT_ResetDevicePort( + FT_HANDLE ftHandle + ); + +FTD3XX_API FT_STATUS FT_CycleDevicePort( + FT_HANDLE ftHandle + ); + +FTD3XX_API FT_STATUS FT_CreateDeviceInfoList( + LPDWORD lpdwNumDevs + ); + +FTD3XX_API FT_STATUS FT_GetDeviceInfoList( + FT_DEVICE_LIST_INFO_NODE *ptDest, + LPDWORD lpdwNumDevs + ); + +FTD3XX_API FT_STATUS FT_GetDeviceInfoDetail( + DWORD dwIndex, + LPDWORD lpdwFlags, + LPDWORD lpdwType, + LPDWORD lpdwID, + LPDWORD lpdwLocId, + LPVOID lpSerialNumber, + LPVOID lpDescription, + FT_HANDLE *pftHandle + ); + +FTD3XX_API FT_STATUS FT_ListDevices( + PVOID pArg1, + PVOID pArg2, + DWORD Flags + ); + +FTD3XX_API FT_STATUS FT_IsDevicePath( + FT_HANDLE ftHandle, + LPCSTR pucDevicePath + ); + + // + // Version information + // + +FTD3XX_API FT_STATUS FT_GetDriverVersion( + FT_HANDLE ftHandle, + LPDWORD lpdwVersion + ); + +FTD3XX_API FT_STATUS FT_GetLibraryVersion( + LPDWORD lpdwVersion + ); + +FTD3XX_API FT_STATUS FT_SetPipeTimeout( + FT_HANDLE ftHandle, + UCHAR ucPipeID, + DWORD dwTimeoutInMs + ); -/* Get total unread buffer length in library's queue - * - * dwFifoID: FIFO interface ID. Valid values are 0-3 which represents - * FIFO channel 1-4 for FT600 and FT601 */ -FTD3XX_API FT_STATUS WINAPI FT_GetReadQueueStatus( - FT_HANDLE ftHandle, - UCHAR ucFifoID, - LPDWORD lpdwAmountInQueue); - -/* Get total unsent buffer length in library's queue - * - * dwFifoID: FIFO interface ID. Valid values are 0-3 which represents - * FIFO channel 1-4 for FT600 and FT601 */ -FTD3XX_API FT_STATUS WINAPI FT_GetWriteQueueStatus( - FT_HANDLE ftHandle, - UCHAR ucFifoID, - LPDWORD lpdwAmountInQueue); - -/* Read unsent buffer for OUT pipe - * Set byBuffer to NULL first to close the pipe to get accurate buffer - * length, allocate buffer with the length, then call this function - * again with the allocated buffer to read out all buffers - * - * dwFifoID: FIFO interface ID. Valid values are 0-3 which represents - * FIFO channel 1-4 for FT600 and FT601 - * byBuffer: User allocated buffer - * lpdwBufferLength: Pointer to receive the size of buffer if byBuffer - * is NULL. Size of buffer if byBuffer is not NULL. */ -FTD3XX_API FT_STATUS WINAPI FT_GetUnsentBuffer( - FT_HANDLE ftHandle, - UCHAR ucFifoID, - BYTE *byBuffer, - LPDWORD lpdwBufferLength); - -FTD3XX_API FT_STATUS WINAPI FT_SetPipeTimeout( - FT_HANDLE ftHandle, - UCHAR ucEndpoint, - DWORD dwTimeoutInMs - ); - -FTD3XX_API FT_STATUS WINAPI FT_CreateDeviceInfoList( - LPDWORD lpdwNumDevs - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetDeviceInfoList( - FT_DEVICE_LIST_INFO_NODE *ptDest, - LPDWORD lpdwNumDevs - ); - -FTD3XX_API FT_STATUS WINAPI FT_ListDevices( - PVOID pArg1, - PVOID pArg2, - DWORD Flags - ); - -FTD3XX_API FT_STATUS WINAPI FT_Create( - PVOID pvArg, - DWORD dwFlags, - FT_HANDLE *pftHandle - ); - -FTD3XX_API FT_STATUS WINAPI FT_Close( - FT_HANDLE ftHandle); - -FTD3XX_API FT_STATUS WINAPI FT_GetVIDPID( - FT_HANDLE ftHandle, - PUSHORT puwVID, - PUSHORT puwPID - ); - -FTD3XX_API FT_STATUS WINAPI FT_WritePipe( - FT_HANDLE ftHandle, - UCHAR ucEndpoint, - PUCHAR pucBuffer, - ULONG ulBufferLength, - PULONG pulBytesTransferred, - LPOVERLAPPED pOverlapped - ); - -FTD3XX_API FT_STATUS WINAPI FT_ReadPipe( - FT_HANDLE ftHandle, - UCHAR ucEndpoint, - PUCHAR pucBuffer, - ULONG ulBufferLength, - PULONG pulBytesTransferred, - LPOVERLAPPED pOverlapped - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetOverlappedResult( - FT_HANDLE ftHandle, - LPOVERLAPPED pOverlapped, - PULONG pulBytesTransferred, - BOOL bWait - ); - -FTD3XX_API FT_STATUS WINAPI FT_InitializeOverlapped( - FT_HANDLE ftHandle, - LPOVERLAPPED pOverlapped - ); - -FTD3XX_API FT_STATUS WINAPI FT_ReleaseOverlapped( - FT_HANDLE ftHandle, - LPOVERLAPPED pOverlapped - ); - -FTD3XX_API FT_STATUS WINAPI FT_SetStreamPipe( - FT_HANDLE ftHandle, - BOOL bAllWritePipes, - BOOL bAllReadPipes, - UCHAR ucEndpoint, - ULONG ulStreamSize - ); - -FTD3XX_API FT_STATUS WINAPI FT_ClearStreamPipe( - FT_HANDLE ftHandle, - BOOL bAllWritePipes, - BOOL bAllReadPipes, - UCHAR ucEndpoint - ); - -FTD3XX_API FT_STATUS WINAPI FT_FlushPipe( - FT_HANDLE ftHandle, - UCHAR ucEndpoint - ); - -FTD3XX_API FT_STATUS WINAPI FT_AbortPipe( - FT_HANDLE ftHandle, - UCHAR ucEndpoint - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetDeviceDescriptor( - FT_HANDLE ftHandle, - PFT_DEVICE_DESCRIPTOR ptDescriptor - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetConfigurationDescriptor( - FT_HANDLE ftHandle, - PFT_CONFIGURATION_DESCRIPTOR ptDescriptor - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetInterfaceDescriptor( - FT_HANDLE ftHandle, - UCHAR ucInterfaceIndex, - PFT_INTERFACE_DESCRIPTOR ptDescriptor - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetPipeInformation( - FT_HANDLE ftHandle, - UCHAR ucInterfaceIndex, - UCHAR ucEndpoint, - PFT_PIPE_INFORMATION ptPipeInformation - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetStringDescriptor( - FT_HANDLE ftHandle, - UCHAR ucStringIndex, - PFT_STRING_DESCRIPTOR ptDescriptor - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetDescriptor( - FT_HANDLE ftHandle, - UCHAR ucDescriptorType, - UCHAR ucIndex, - PUCHAR pucBuffer, - ULONG ulBufferLength, - PULONG pulLengthTransferred - ); - -FTD3XX_API FT_STATUS WINAPI FT_ControlTransfer( - FT_HANDLE ftHandle, - FT_SETUP_PACKET tSetupPacket, - PUCHAR pucBuffer, - ULONG ulBufferLength, - PULONG pulLengthTransferred - ); - -FTD3XX_API FT_STATUS WINAPI FT_SetGPIO( - FT_HANDLE ftHandle, - UCHAR ucDirection, - UCHAR ucValue - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetGPIO( - FT_HANDLE ftHandle, - UCHAR ucDirection, - FT_NOTIFICATION_CALLBACK pCallback, - PVOID pvCallbackContext, - USHORT uwCallbackLatency - ); - -FTD3XX_API FT_STATUS WINAPI FT_SetNotificationCallback( - FT_HANDLE ftHandle, - FT_NOTIFICATION_CALLBACK pCallback, - PVOID pvCallbackContext - ); - -FTD3XX_API VOID WINAPI FT_ClearNotificationCallback( - FT_HANDLE ftHandle - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetChipConfiguration( - FT_HANDLE ftHandle, - PVOID pvConfiguration - ); - -FTD3XX_API FT_STATUS WINAPI FT_SetChipConfiguration( - FT_HANDLE ftHandle, - PVOID pvConfiguration - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetFirmwareVersion( - FT_HANDLE ftHandle, - PULONG pulFirmwareVersion - ); - -FTD3XX_API FT_STATUS WINAPI FT_ResetDevicePort( - FT_HANDLE ftHandle - ); - -FTD3XX_API FT_STATUS WINAPI FT_CycleDevicePort( - FT_HANDLE ftHandle - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetDeviceInfoDetail( - DWORD dwIndex, - LPDWORD lpdwFlags, - LPDWORD lpdwType, - LPDWORD lpdwID, - LPDWORD lpdwLocId, - LPVOID lpSerialNumber, - LPVOID lpDescription, - FT_HANDLE *pftHandle - ); - -FTD3XX_API FT_STATUS WINAPI FT_IsDevicePath( - FT_HANDLE ftHandle, - LPCSTR pucDevicePath - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetDriverVersion( - FT_HANDLE ftHandle, - LPDWORD lpdwVersion - ); - -FTD3XX_API FT_STATUS WINAPI FT_GetLibraryVersion( - LPDWORD lpdwVersion - ); /* Enable GPIOs * Each bit represents one GPIO setting, GPIO0-GPIO2 from LSB to MSB * * dwMask: set bit to 0 to skip the GPIO, 1 to enable the GPIO - * dwDirection: set bit to 0 for input, 1 for output */ -FTD3XX_API FT_STATUS WINAPI FT_EnableGPIO( - FT_HANDLE ftHandle, - DWORD dwMask, - DWORD dwDirection - ); + * dwDirection: set bit to 0 for input, 1 for output + * refer to enum FT_PIPE_DIRECTION */ +FTD3XX_API FT_STATUS FT_EnableGPIO( + FT_HANDLE ftHandle, + DWORD dwMask, + DWORD dwDirection + ); /* Set GPIO level * Each bit represents one GPIO setting, GPIO0-GPIO2 from LSB to MSB * * dwMask: set bit to 0 to skip the GPIO, 1 to enable the GPIO * dwDirection: set bit to 0 for low, 1 for high */ -FTD3XX_API FT_STATUS WINAPI FT_WriteGPIO( - FT_HANDLE ftHandle, - DWORD dwMask, - DWORD dwLevel - ); +FTD3XX_API FT_STATUS FT_WriteGPIO( + FT_HANDLE ftHandle, + DWORD dwMask, + DWORD dwLevel + ); /* Get level of all GPIOs * Each bit represents one GPIO setting, GPIO0-GPIO2, RD_N, OE_N from * LSB to MSB */ -FTD3XX_API FT_STATUS WINAPI FT_ReadGPIO( - FT_HANDLE ftHandle, - DWORD *pdwData - ); +FTD3XX_API FT_STATUS FT_ReadGPIO( + FT_HANDLE ftHandle, + DWORD *pdwData + ); /* Set GPIO internal pull resisters * dwMask: Each bit represents one GPIO setting, GPIO0-GPIO2 from @@ -828,11 +903,87 @@ FTD3XX_API FT_STATUS WINAPI FT_ReadGPIO( * * dwMask: set bit to 0 to skip the GPIO, 1 to enable the GPIO * dwPull: refer to enum FT_GPIO_PULL */ -FTD3XX_API FT_STATUS WINAPI FT_SetGPIOPull( - FT_HANDLE ftHandle, - DWORD dwMask, - DWORD dwPull - ); +FTD3XX_API FT_STATUS FT_SetGPIOPull( + FT_HANDLE ftHandle, + DWORD dwMask, + DWORD dwPull + ); + + +#if defined (__linux__) || defined (__APPLE__) +FTD3XX_API FT_STATUS FT_SetGPIO( + FT_HANDLE ftHandle, + UCHAR ucDirection, + UCHAR ucValue + ); +#endif /*__linux__ __APPLE__*/ + +#if defined (__linux__) || defined (__APPLE__) +FTD3XX_API FT_STATUS FT_GetGPIO( + FT_HANDLE ftHandle, + UCHAR ucDirection, + FT_NOTIFICATION_CALLBACK pCallback, + PVOID pvCallbackContext, + USHORT uwCallbackLatency + ); +#endif /*__linux__ __APPLE__*/ + +#if defined (__linux__) || defined (__APPLE__) +/* Set transfer parameters for each FIFO channel + * Must be called before FT_Create is called. Need to be called again + * after FT_Close(), otherwise default parameters will be used. + * + * Default value will be used for each FIFO channel if this function + * is not been called. Please refer to structure defines for default + * value. + * + * pConf: Please refer to structure FT_TRANSFER_CONF + * dwFifoID: FIFO interface ID. Valid values are 0-3 which represents + * FIFO channel 1-4 for FT600 and FT601 */ +FTD3XX_API FT_STATUS FT_SetTransferParams( + FT_TRANSFER_CONF *pConf, + DWORD dwFifoID); +#endif /*__linux__ __APPLE__*/ + +#if defined (__linux__) || defined (__APPLE__) +/* Get total unread buffer length in library's queue + * + * dwFifoID: FIFO interface ID. Valid values are 0-3 which represents + * FIFO channel 1-4 for FT600 and FT601 */ +FTD3XX_API FT_STATUS FT_GetReadQueueStatus( + FT_HANDLE ftHandle, + UCHAR ucFifoID, + LPDWORD lpdwAmountInQueue); +#endif /*__linux__ __APPLE__*/ + +#if defined (__linux__) || defined (__APPLE__) +/* Get total unsent buffer length in library's queue + * + * dwFifoID: FIFO interface ID. Valid values are 0-3 which represents + * FIFO channel 1-4 for FT600 and FT601 */ +FTD3XX_API FT_STATUS FT_GetWriteQueueStatus( + FT_HANDLE ftHandle, + UCHAR ucFifoID, + LPDWORD lpdwAmountInQueue); +#endif /*__linux__ __APPLE__*/ + +#if defined (__linux__) || defined (__APPLE__) +/* Read unsent buffer for OUT pipe + * Set byBuffer to NULL first to close the pipe to get accurate buffer + * length, allocate buffer with the length, then call this function + * again with the allocated buffer to read out all buffers + * + * dwFifoID: FIFO interface ID. Valid values are 0-3 which represents + * FIFO channel 1-4 for FT600 and FT601 + * byBuffer: User allocated buffer + * lpdwBufferLength: Pointer to receive the size of buffer if byBuffer + * is NULL. Size of buffer if byBuffer is not NULL. */ +FTD3XX_API FT_STATUS FT_GetUnsentBuffer( + FT_HANDLE ftHandle, + UCHAR ucFifoID, + BYTE *byBuffer, + LPDWORD lpdwBufferLength); +#endif /*__linux__ __APPLE__*/ #ifdef __cplusplus } diff --git a/api/liboni/drivers/ft600/ft3dxx/linux/Types.h b/api/liboni/drivers/ft600/ft3dxx/linux/Types.h new file mode 100644 index 0000000..23eac7c --- /dev/null +++ b/api/liboni/drivers/ft600/ft3dxx/linux/Types.h @@ -0,0 +1,152 @@ +#ifndef __LINUX_TYPES__ +#define __LINUX_TYPES__ + +typedef unsigned int DWORD; +typedef unsigned int ULONG; +typedef unsigned short USHORT; +typedef unsigned short SHORT; +typedef unsigned char UCHAR; +typedef unsigned short WORD; +typedef unsigned short WCHAR; +typedef unsigned char BYTE; +typedef BYTE *LPBYTE; +typedef unsigned int BOOL; +typedef unsigned char BOOLEAN; +typedef unsigned char CHAR; +typedef BOOL *LPBOOL; +typedef UCHAR *PUCHAR; +typedef const char *LPCSTR; +typedef char *PCHAR; +typedef void *PVOID; +typedef void *HANDLE; +typedef unsigned int LONG; +typedef int INT; +typedef unsigned int UINT; +typedef char *LPSTR; +typedef char *LPTSTR; +typedef const char *LPCTSTR; +typedef DWORD *LPDWORD; +typedef WORD *LPWORD; +typedef ULONG *PULONG; +typedef LONG *LPLONG; +typedef PVOID LPVOID; +typedef void VOID; +typedef USHORT *PUSHORT; +typedef unsigned long long int ULONGLONG; + +typedef struct _OVERLAPPED { + DWORD Internal; + DWORD InternalHigh; + union { + struct{ + DWORD Offset; + DWORD OffsetHigh; + }; + PVOID Pointer; + }; + HANDLE hEvent; +} OVERLAPPED, *LPOVERLAPPED; + +typedef struct _SECURITY_ATTRIBUTES { + DWORD nLength; + LPVOID lpSecurityDescriptor; + BOOL bInheritHandle; +} SECURITY_ATTRIBUTES , *LPSECURITY_ATTRIBUTES; + +#include +// Substitute for HANDLE returned by LINUX CreateEvent API. +// FT_SetEventNotification expects parameter 3 to be the address +// of one of these structures. +typedef struct _EVENT_HANDLE +{ + pthread_cond_t eCondVar; + pthread_mutex_t eMutex; + int iVar; +} EVENT_HANDLE; + +typedef struct timeval SYSTEMTIME; +typedef struct timeval FILETIME; + +// WaitForSingleObject return values. +#define WAIT_ABANDONED 0x00000080L +#define WAIT_OBJECT_0 0x00000000L +#define WAIT_TIMEOUT 0x00000102L +#define WAIT_FAILED 0xFFFFFFFF +// Special value for WaitForSingleObject dwMilliseconds parameter +#define INFINITE 0xFFFFFFFF // Infinite timeout + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef CONST +#define CONST const +#endif +// +// Modem Status Flags +// +#define MS_CTS_ON ((DWORD)0x0010) +#define MS_DSR_ON ((DWORD)0x0020) +#define MS_RING_ON ((DWORD)0x0040) +#define MS_RLSD_ON ((DWORD)0x0080) + +// +// Error Flags +// +#define CE_RXOVER 0x0001 // Receive Queue overflow +#define CE_OVERRUN 0x0002 // Receive Overrun Error +#define CE_RXPARITY 0x0004 // Receive Parity Error +#define CE_FRAME 0x0008 // Receive Framing error +#define CE_BREAK 0x0010 // Break Detected +#define CE_TXFULL 0x0100 // TX Queue is full +#define CE_PTO 0x0200 // LPTx Timeout +#define CE_IOE 0x0400 // LPTx I/O Error +#define CE_DNS 0x0800 // LPTx Device not selected +#define CE_OOP 0x1000 // LPTx Out-Of-Paper +#define CE_MODE 0x8000 // Requested mode unsupported + +// +// Events +// +#define EV_RXCHAR 0x0001 // Any Character received +#define EV_RXFLAG 0x0002 // Received certain character +#define EV_TXEMPTY 0x0004 // Transmit Queue Empty +#define EV_CTS 0x0008 // CTS changed state +#define EV_DSR 0x0010 // DSR changed state +#define EV_RLSD 0x0020 // RLSD changed state +#define EV_BREAK 0x0040 // BREAK received +#define EV_ERR 0x0080 // Line status error occurred +#define EV_RING 0x0100 // Ring signal detected +#define EV_PERR 0x0200 // Printer error occured +#define EV_RX80FULL 0x0400 // Receive buffer is 80 percent full +#define EV_EVENT1 0x0800 // Provider specific event 1 +#define EV_EVENT2 0x1000 // Provider specific event 2 + +// +// Escape Functions +// +#define SETXOFF 1 // Simulate XOFF received +#define SETXON 2 // Simulate XON received +#define SETRTS 3 // Set RTS high +#define CLRRTS 4 // Set RTS low +#define SETDTR 5 // Set DTR high +#define CLRDTR 6 // Set DTR low +#define RESETDEV 7 // Reset device if possible +#define SETBREAK 8 // Set the device break line. +#define CLRBREAK 9 // Clear the device break line. + +// +// PURGE function flags. +// +#define PURGE_TXABORT 0x0001 // Kill the pending/current writes to the comm port. +#define PURGE_RXABORT 0x0002 // Kill the pending/current reads to the comm port. +#define PURGE_TXCLEAR 0x0004 // Kill the transmit queue if there. +#define PURGE_RXCLEAR 0x0008 // Kill the typeahead buffer if there. + +#ifndef INVALID_HANDLE_VALUE +#define INVALID_HANDLE_VALUE 0xFFFFFFFF +#endif + +#endif /* __LINUX_TYPES__ */ diff --git a/api/liboni/drivers/ft600/ft3dxx/linux/d3xx-linux-x86_64-0.5.21.tar.zip b/api/liboni/drivers/ft600/ft3dxx/linux/d3xx-linux-x86_64-0.5.21.tar.zip deleted file mode 100644 index dd2b69b..0000000 Binary files a/api/liboni/drivers/ft600/ft3dxx/linux/d3xx-linux-x86_64-0.5.21.tar.zip and /dev/null differ diff --git a/api/liboni/drivers/ft600/onidriver_ft600.c b/api/liboni/drivers/ft600/onidriver_ft600.c index afc4db6..2fb9f15 100644 --- a/api/liboni/drivers/ft600/onidriver_ft600.c +++ b/api/liboni/drivers/ft600/onidriver_ft600.c @@ -11,13 +11,11 @@ #ifdef _WIN32 #include -#define DEFAULT_OVERLAPPED 4 #define SERIAL_LEN 16 #define FTD3XX_STATIC #else #include -#include #define Sleep(x) usleep((x)*1000) #define TRUE true #define FALSE false @@ -25,11 +23,20 @@ #endif #include +#define POLL_CONTROL +//#define LINUX_ASYNC + +#ifdef POLL_CONTROL +#include +#endif + + #if defined(_WIN32) && defined(DRIVER_1308_WORKAROUND) #define FT_ReadPipeEx FT_ReadPipe #endif +#define DEFAULT_OVERLAPPED 4 #define DEFAULT_AUXSIZE 8192 #define DEFAULT_BLOCKREAD 4096 #define DEFAULT_BLOCKWRITE 4096 @@ -87,16 +94,17 @@ struct oni_ft600_ctx_impl { unsigned int lastReadIndex; size_t lastReadOffset; size_t lastReadRead; -#ifdef _WIN32 uint8_t* inBuffer; unsigned int numInOverlapped; - OVERLAPPED cmdOverlapped; - OVERLAPPED sigOverlapped; - OVERLAPPED outOverlapped; OVERLAPPED* inOverlapped; ULONG* inTransferred; -#else +#ifdef POLL_CONTROL pthread_mutex_t controlMutex; +#endif +#ifdef _WIN32 + OVERLAPPED cmdOverlapped; + OVERLAPPED sigOverlapped; + OVERLAPPED outOverlapped; #endif struct { oni_dev_idx_t dev_idx; @@ -160,7 +168,7 @@ inline void fill_control_buffers(oni_ft600_ctx ctx, ULONG transferred) break; case SIG_SIGNAL: lastIndex = index; - while (index < transferred && ctx->auxBuffer[index] != 0) { /*printf("ii %ld t %d\n",index,transferred);*/ index++; } + while (index < transferred && ctx->auxBuffer[index] != 0) { index++; } if (index >= transferred) index--; while (!circBufferCanWrite(&ctx->signalBuffer, index - lastIndex + 1)); circBufferWrite(&ctx->signalBuffer, ctx->auxBuffer + lastIndex, index - lastIndex + 1); @@ -180,7 +188,7 @@ inline void fill_control_buffers(oni_ft600_ctx ctx, ULONG transferred) } while (index < transferred); } -#ifdef _WIN32 +#ifndef POLL_CONTROL void oni_ft600_usb_callback(PVOID context, E_FT_NOTIFICATION_CALLBACK_TYPE type, PVOID cinfo) { FT_STATUS ftStatus; @@ -191,8 +199,9 @@ void oni_ft600_usb_callback(PVOID context, E_FT_NOTIFICATION_CALLBACK_TYPE type, ULONG transferred; ULONG total = 0; - do { +#ifdef _WIN32 + FT_ReadPipe(ctx->ftHandle, info->ucEndpointNo, ctx->auxBuffer + total, @@ -201,38 +210,42 @@ void oni_ft600_usb_callback(PVOID context, E_FT_NOTIFICATION_CALLBACK_TYPE type, &ctx->sigOverlapped); ftStatus = FT_GetOverlappedResult( ctx->ftHandle, &ctx->sigOverlapped, &transferred, TRUE); +#else + ftStatus = FT_ReadPipe(ctx->ftHandle, + info->ucEndpointNo, + ctx->auxBuffer + total, + info->ulRecvNotificationLength - total, + &transferred, + 0); +#endif + if (ftStatus != FT_OK) { - ctx->sigError = 1; - return; - } + ctx->sigError = 1; + return; + } total += transferred; } while (total < info->ulRecvNotificationLength); + + + if (total > 0) { fill_control_buffers(ctx, transferred); } } -#else +#else void oni_ft600_update_control(oni_ft600_ctx ctx) { FT_STATUS ftStatus; DWORD toread = ctx->auxSize; ULONG transferred; + if (pthread_mutex_trylock(&ctx->controlMutex) == 0) { - ftStatus = FT_GetReadQueueStatus(ctx->ftHandle, pipeid_control, &toread); - if (ftStatus != FT_OK) - { - ctx->sigError = 1; - pthread_mutex_unlock(&ctx->controlMutex); - return; - } - toread = MIN(toread,ctx->auxSize); - if (toread > 0) - { - ftStatus = FT_ReadPipeEx(ctx->ftHandle, 1, ctx->auxBuffer, toread, &transferred, 5000); + + ftStatus = FT_ReadPipeEx(ctx->ftHandle, pipeid_control, ctx->auxBuffer, toread, &transferred,0); if (ftStatus != FT_OK && ftStatus != FT_TIMEOUT && ftStatus != FT_IO_PENDING) { ctx->sigError = 1; @@ -243,23 +256,9 @@ void oni_ft600_update_control(oni_ft600_ctx ctx) { fill_control_buffers(ctx, transferred); } - } pthread_mutex_unlock(&ctx->controlMutex); } } - -void flushPipe(oni_ft600_ctx ctx, int pipe) -{ - FT_STATUS ftStatus; - unsigned char nullbuf[10]; - ULONG transferred; - do - { - ftStatus = FT_ReadPipeEx(ctx->ftHandle, pipe, nullbuf, 10, &transferred, 100); - if (ftStatus != FT_OK && ftStatus != FT_TIMEOUT && ftStatus != FT_IO_PENDING) break; - } while(transferred > 0); -} - #endif static inline oni_conf_off_t _oni_register_offset(oni_config_t reg); @@ -289,12 +288,11 @@ inline void oni_ft600_reset_acq(oni_ft600_ctx ctx, int hard) } FT_AbortPipe(ctx->ftHandle, pipe_in); FT_AbortPipe(ctx->ftHandle, pipe_out); - FT_AbortPipe(ctx->ftHandle, pipe_cmd); - FT_AbortPipe(ctx->ftHandle, pipe_sig); +// FT_AbortPipe(ctx->ftHandle, pipe_cmd); +// FT_AbortPipe(ctx->ftHandle, pipe_sig); #ifndef _WIN32 -//TODO: fix with proper resets once we have the board -// FT_FlushPipe(ctx->ftHandle, pipe_in); -// FT_FlushPipe(ctx->ftHandle, pipe_out); + FT_FlushPipe(ctx->ftHandle, pipe_in); + FT_FlushPipe(ctx->ftHandle, pipe_out); // FT_FlushPipe(ctx->ftHandle, pipe_cmd); // FT_FlushPipe(ctx->ftHandle, pipe_sig); #endif @@ -307,12 +305,12 @@ inline void oni_ft600_stop_acq(oni_ft600_ctx ctx) { ctx->state = STATE_INIT; Sleep(10); -#ifdef _WIN32 +#if defined _WIN32 || defined LINUX_ASYNC FT_ClearStreamPipe(ctx->ftHandle, FALSE, FALSE, pipe_in); +#endif FT_AbortPipe(ctx->ftHandle, pipe_in); -#else - FT_AbortPipe(ctx->ftHandle, pipe_in); - flushPipe(ctx, pipeid_data); +#ifndef _WIN32 + FT_FlushPipe(ctx->ftHandle, pipe_in); #endif oni_ft600_restart_acq(ctx); } @@ -352,24 +350,21 @@ oni_driver_ctx oni_driver_create_ctx() ctx->outBlockSize = DEFAULT_BLOCKWRITE; ctx->regBuffer.size = DEFAULT_REGSIZE; ctx->signalBuffer.size = DEFAULT_SIGNALSIZE; - -#if _WIN32 ctx->numInOverlapped = DEFAULT_OVERLAPPED; -#endif return ctx; } void oni_ft600_free_ctx(oni_ft600_ctx ctx) { -#ifdef _WIN32 if (ctx->inBuffer != NULL) free(ctx->inBuffer); -#endif if (ctx->auxBuffer != NULL) free(ctx->auxBuffer); circBufferRelease(&ctx->signalBuffer); circBufferRelease(&ctx->regBuffer); if (ctx->ftHandle != NULL) { +#ifndef POLL_CONTROL FT_ClearNotificationCallback(ctx->ftHandle); +#endif FT_AbortPipe(ctx->ftHandle, pipe_in); FT_AbortPipe(ctx->ftHandle, pipe_out); FT_AbortPipe(ctx->ftHandle, pipe_cmd); @@ -378,14 +373,21 @@ void oni_ft600_free_ctx(oni_ft600_ctx ctx) FT_ReleaseOverlapped(ctx->ftHandle, &ctx->outOverlapped); FT_ReleaseOverlapped(ctx->ftHandle, &ctx->sigOverlapped); FT_ReleaseOverlapped(ctx->ftHandle, &ctx->cmdOverlapped); +#endif if (ctx->inOverlapped != NULL) { - for (int i = 0; i < ctx->numInOverlapped; i++) + for (unsigned int i = 0; i < ctx->numInOverlapped; i++) FT_ReleaseOverlapped(ctx->ftHandle, &ctx->inOverlapped[i]); free(ctx->inOverlapped); } if (ctx->inTransferred != NULL) free(ctx->inTransferred); -#else +#ifdef POLL_CONTROL pthread_mutex_destroy(&ctx->controlMutex); +#endif +#ifndef _WIN32 + FT_FlushPipe(ctx->ftHandle, pipe_in); + FT_FlushPipe(ctx->ftHandle, pipe_out); + FT_FlushPipe(ctx->ftHandle, pipe_cmd); + FT_FlushPipe(ctx->ftHandle, pipe_sig); #endif FT_Close(ctx->ftHandle); ctx->ftHandle = NULL; @@ -406,10 +408,11 @@ int oni_driver_init(oni_driver_ctx driver_ctx, int host_idx) ftTransfer.wStructSize = sizeof(FT_TRANSFER_CONF); // The spec defines that only one simultaneous call to each pipe must be // done, so disable built-in thred safety for performance - ftTransfer.pipe[FT_PIPE_DIR_IN].fNonThreadSafeTransfer = FALSE; - ftTransfer.pipe[FT_PIPE_DIR_OUT].fNonThreadSafeTransfer = FALSE; + ftTransfer.pipe[FT_PIPE_DIR_IN].fNonThreadSafeTransfer = false; + ftTransfer.pipe[FT_PIPE_DIR_OUT].fNonThreadSafeTransfer = false; CHECK_FTERR(FT_SetTransferParams(&ftTransfer, pipeid_data)); - // And control is mutexed in the onidriver + ftTransfer.pipe[FT_PIPE_DIR_IN].fNonThreadSafeTransfer = false; + ftTransfer.pipe[FT_PIPE_DIR_OUT].fNonThreadSafeTransfer = false; CHECK_FTERR(FT_SetTransferParams(&ftTransfer, pipeid_control)); // unused pipes @@ -446,8 +449,8 @@ int oni_driver_init(oni_driver_ctx driver_ctx, int host_idx) if (ftStatus != FT_OK) ctx->ftHandle = NULL; else - break; - } + break; + } } devIdx++; } @@ -458,19 +461,21 @@ int oni_driver_init(oni_driver_ctx driver_ctx, int host_idx) else if (ctx->ftHandle == NULL) return ONI_EINIT; + #ifdef _WIN32 FT_InitializeOverlapped(ctx->ftHandle, &ctx->outOverlapped); FT_InitializeOverlapped(ctx->ftHandle, &ctx->sigOverlapped); FT_InitializeOverlapped(ctx->ftHandle, &ctx->cmdOverlapped); +#endif ctx->inOverlapped = malloc(ctx->numInOverlapped * sizeof(OVERLAPPED)); CHECK_NULL(ctx->inOverlapped); - for (int i = 0; i < ctx->numInOverlapped; i++) + for (unsigned int i = 0; i < ctx->numInOverlapped; i++) FT_InitializeOverlapped(ctx->ftHandle, &ctx->inOverlapped[i]); ctx->inTransferred = malloc(ctx->numInOverlapped * sizeof(ULONG)); CHECK_NULL(ctx->inTransferred); ctx->inBuffer = malloc(2 * (size_t)ctx->numInOverlapped * ctx->inBlockSize); CHECK_NULL(ctx->inBuffer); -#else +#ifdef POLL_CONTROL if (pthread_mutex_init(&ctx->controlMutex, NULL) != 0) { oni_ft600_free_ctx(ctx); @@ -482,15 +487,17 @@ int oni_driver_init(oni_driver_ctx driver_ctx, int host_idx) ctx->auxBuffer = malloc(ctx->auxSize); CHECK_NULL(ctx->auxBuffer); -#ifdef _WIN32 +#ifndef POLL_CONTROL CHECK_FTERR(FT_SetNotificationCallback(ctx->ftHandle, oni_ft600_usb_callback, ctx)); +#endif //CHECK_FTERR(FT_SetStreamPipe(ctx->ftHandle, FALSE, FALSE, pipe_in, ctx->inBlockSize)); +#ifdef _WIN32 CHECK_FTERR(FT_SetPipeTimeout(ctx->ftHandle, pipe_in, 0)); CHECK_FTERR(FT_SetPipeTimeout(ctx->ftHandle, pipe_out, 0)); CHECK_FTERR(FT_SetPipeTimeout(ctx->ftHandle, pipe_cmd, 0)); CHECK_FTERR(FT_SetPipeTimeout(ctx->ftHandle, pipe_sig, 0)); - #endif + //Enable GPIOs CHECK_FTERR(FT_SetGPIOPull(ctx->ftHandle,0x3,0x05)) CHECK_FTERR(FT_WriteGPIO(ctx->ftHandle, 0x01, 0x00)); @@ -533,9 +540,9 @@ int oni_driver_read_stream(oni_driver_ctx driver_ctx, { while (!circBufferCanRead(&ctx->signalBuffer, size)) { -#ifndef _WIN32 +#ifdef POLL_CONTROL oni_ft600_update_control(ctx); -#endif +#endif if (ctx->sigError) { ctx->sigError = 0; @@ -554,8 +561,7 @@ int oni_driver_read_stream(oni_driver_ctx driver_ctx, FT_STATUS ftStatus; int read = 0; if (remaining < ctx->inBlockSize) return ONI_EINVALREADSIZE; -#ifdef _WIN32 - // printf("read: %d\n", remaining); +#if defined _WIN32 || defined LINUX_ASYNC size_t to_read; uint8_t* dstPtr = data; uint8_t* srcPtr; @@ -566,74 +572,51 @@ int oni_driver_read_stream(oni_driver_ctx driver_ctx, to_read = ctx->lastReadRead - ctx->lastReadOffset; srcPtr = ctx->inBuffer + ctx->inBlockSize * (size_t)lastIndex + ctx->lastReadOffset; memcpy(dstPtr, srcPtr, to_read); - //printf("%d - %d - %d\n", lastIndex, to_read, ctx->lastReadOffset); - /* printf("cD: "); - for (int i = 0; i < to_read; i++) - printf("%x ", *(dstPtr + i)); - printf("\n cS: "); - for (int i = 0; i < to_read; i++) - printf("%x ", *(srcPtr + i));*/ remaining -= to_read; dstPtr += to_read; read += to_read; - // printf("r %d rem %d\n", to_read, remaining); } while (remaining > 0) { - unsigned int simIndex = ctx->nextReadIndex % ctx->numInOverlapped; + unsigned int simIndex = ctx->nextReadIndex % ctx->numInOverlapped; unsigned int nextIndex = (ctx->nextReadIndex + ctx->numInOverlapped) % (2 * ctx->numInOverlapped); - ULONG transferred; + ULONG transferred = 0; + ftStatus = FT_GetOverlappedResult(ctx->ftHandle, &ctx->inOverlapped[simIndex], &ctx->inTransferred[simIndex], TRUE); + if (ftStatus != FT_OK) { - printf("Read failure %d\n", ftStatus); - return ONI_EREADFAILURE; - } - transferred = ctx->inTransferred[simIndex]; - // read in the next part of the double buffer - /* memset(ctx->inBuffer + ((size_t)nextIndex * ctx->inBlockSize), - 0, - ctx->inBlockSize);*/ - FT_ReadPipeEx(ctx->ftHandle, - pipe_in, - ctx->inBuffer - + ((size_t)nextIndex * ctx->inBlockSize), - ctx->inBlockSize, - &ctx->inTransferred[simIndex], - &ctx->inOverlapped[simIndex]); - // printf("R: %d\n", simIndex); - srcPtr - = ctx->inBuffer + ctx->inBlockSize * (size_t)ctx->nextReadIndex; - to_read = MIN(remaining, transferred); - /* printf("\n%d - %d - %d - %d - %d\n", - ctx->nextReadIndex, - nextIndex, - simIndex, - to_read, transferred);*/ - memcpy(dstPtr, srcPtr, to_read); - /* printf("D: "); - for (int i = 0; i < to_read; i++) - printf("%x ", *(dstPtr + i)); - printf("\n S: "); - for (int i = 0; i < to_read; i++) - printf("%x ", *(srcPtr + i));*/ - remaining -= to_read; - dstPtr += to_read; - read += to_read; + printf("Read failure %d\n", ftStatus); + return ONI_EREADFAILURE; + } + transferred = ctx->inTransferred[simIndex]; + //read in the next part of the double buffer +#ifdef _WIN32 + FT_ReadPipeEx(ctx->ftHandle, pipe_in, ctx->inBuffer + ((size_t)nextIndex * ctx->inBlockSize), ctx->inBlockSize, + &ctx->inTransferred[simIndex], &ctx->inOverlapped[simIndex]); +#else + FT_ReadPipeAsync(ctx->ftHandle, pipeid_data, ctx->inBuffer + ((size_t)nextIndex * ctx->inBlockSize), ctx->inBlockSize, + &ctx->inTransferred[simIndex], &ctx->inOverlapped[simIndex]); +#endif + srcPtr = ctx->inBuffer + ctx->inBlockSize * (size_t)ctx->nextReadIndex; + to_read = MIN(remaining, transferred); + memcpy(dstPtr, srcPtr, to_read); + remaining -= to_read; + dstPtr += to_read; + read += to_read; ctx->lastReadIndex = ctx->nextReadIndex; ctx->nextReadIndex = (ctx->nextReadIndex + 1) % (2 * ctx->numInOverlapped); if (to_read < transferred) { - // printf("t %d r %d - %d\n", transferred, to_read, ctx->nextReadIndex); - ctx->lastReadRead = transferred; - ctx->lastReadOffset = to_read; + ctx->lastReadRead = transferred; + ctx->lastReadOffset = to_read; } else { ctx->lastReadOffset = 0; - } - } -#else + } + } +#else ULONG transferred; uint8_t* dstPtr = (uint8_t*)data; do @@ -651,7 +634,6 @@ int oni_driver_read_stream(oni_driver_ctx driver_ctx, } } while (remaining > 0); #endif - // printf("rr: %d a %p\n", read,data); return read; } @@ -756,11 +738,13 @@ int oni_driver_write_config(oni_driver_ctx driver_ctx, *(uint32_t*)(buffer + 5) = value; size = 9; } + + if (reg == ONI_CONFIG_RESET && value != 0) + { + oni_ft600_stop_acq(ctx); + } int res = oni_ft600_sendcmd(ctx, buffer, size); if (res != ONI_ESUCCESS) return res; - - if (reg == ONI_CONFIG_RESET && value != 0) oni_ft600_stop_acq(ctx); - return ONI_ESUCCESS; } @@ -775,9 +759,9 @@ int oni_driver_read_config(oni_driver_ctx driver_ctx, oni_config_t reg, oni_reg_ while (!circBufferCanRead(&ctx->regBuffer, sizeof(oni_reg_val_t))) { -#ifndef _WIN32 +#ifdef POLL_CONTROL oni_ft600_update_control(ctx); -#endif +#endif if (ctx->sigError) { ctx->sigError = 0; @@ -792,15 +776,21 @@ int oni_driver_read_config(oni_driver_ctx driver_ctx, oni_config_t reg, oni_reg_ inline void oni_ft600_start_acq(oni_ft600_ctx ctx) { - #if _WIN32 - FT_STATUS rc; - rc = FT_SetStreamPipe(ctx->ftHandle, FALSE, FALSE, pipe_in, ctx->inBlockSize); + +#if defined _WIN32 || defined LINUX_ASYNC + FT_SetStreamPipe(ctx->ftHandle, FALSE, FALSE, pipe_in, ctx->inBlockSize); +#endif for (size_t i = 0; i < ctx->numInOverlapped; i++) { +#if _WIN32 FT_ReadPipeEx(ctx->ftHandle, pipe_in, ctx->inBuffer + (i * ctx->inBlockSize), ctx->inBlockSize, &ctx->inTransferred[i], &ctx->inOverlapped[i]); - // printf("R: %d\n", i); - } +#else +#ifdef LINUX_ASYNC + FT_ReadPipeAsync(ctx->ftHandle, pipeid_data, ctx->inBuffer + (i * ctx->inBlockSize), ctx->inBlockSize, &ctx->inTransferred[i], &ctx->inOverlapped[i]); +#endif #endif + } + ctx->state = STATE_RUNNING; } @@ -833,7 +823,7 @@ int oni_driver_set_opt_callback(oni_driver_ctx driver_ctx, uint32_t size = *(oni_size_t*)value; if (size % sizeof(uint32_t) != 0) return ONI_EINVALREADSIZE; ctx->inBlockSize = size; -#ifdef _WIN32 + if (ctx->state == STATE_INIT) //memory already allocated { free(ctx->inBuffer); @@ -842,7 +832,7 @@ int oni_driver_set_opt_callback(oni_driver_ctx driver_ctx, // FT_ClearStreamPipe(ctx->ftHandle, FALSE, FALSE, pipe_in); // FT_SetStreamPipe(ctx->ftHandle, FALSE, FALSE, pipe_in,size); } -#endif + } return ONI_ESUCCESS; } @@ -886,12 +876,12 @@ int oni_driver_get_opt(oni_driver_ctx driver_ctx, else if (driver_option == 1) { if (*option_len < sizeof(uint32_t)) return ONI_EBUFFERSIZE; - if (FT_GetLibraryVersion(ctx->ftHandle, value) == FT_OK) + if (FT_GetLibraryVersion(value) == FT_OK) return ONI_ESUCCESS; else return ONI_ESEEKFAILURE; } else - return ONI_EINVALOPT; + return ONI_EINVALOPT; } const oni_driver_info_t* oni_driver_info()