Cat
LALUsb.h
Go to the documentation of this file.
1 // LALUsb.h : main header file of LALusbv2 project
2 // (LALUsb 2.0 V 1.0.2.1)
3 // Author C. CHEIKALI
4 // Created 06/06/07
5 // Last modified :
6 // 17/02/2011 : Added Synchronous i/o mode management for 2232H
7 // 11/01/2011 : two error codes added
8 // 26/05/2010 : Interrupt and frame management routines are now reachable from the DLL
9 // 31/03/2008 : Adapted to the latest version of ftd2xx.h
10 
11 #ifndef __USB_LAL_H__
12 #define __USB_LAL_H__
13 
14 #ifdef _WINDOWS_
15 
16  #ifdef LALUSB_EXPORTS
17  #define LALUSB_API __declspec(dllexport)
18  #define _cstmcall _stdcall
19  #else
20  #ifdef LALUSB_STATIC
21  #define LALUSB_API
22  #define _cstmcall __cdecl
23  #else
24  #define LALUSB_API __declspec(dllimport)
25  #define _cstmcall _stdcall
26  #endif
27  #endif
28 #else
29  #define LALUSB_API
30  #define _cstmcall
31 
32  #include <fcntl.h>
33  #include <sys/types.h>
34  #include <sys/stat.h>
35 
36 #endif
37 
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 
42 #include "ftd2xx.h"
43 
44 /******************************* definitions ******************************/
45 
46 typedef enum
47 {
51 
52 #define MAXDEVS 40 // This number may be increased up to 127
53 
54 // Printf-like function type
55 
56 #if !defined (PrintfFunc)
57  typedef void (*PrintfFunc)(char *format, ...);
58 #endif
59 
60 // Error printing function type
61 
62 #if !defined (PerrorFunc)
63  typedef void (*PerrorFunc)(char *msg);
64 #endif
65 
66 // Errors that may occur
67 
68 #define USB_NoErr FT_OK
69 #define FrameNoErr FT_OK
70 
72 
73 #ifndef LALUSB_EXPORTS
75 #endif
76 
77 /******************************* Prototypes ******************************/
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
83 // Initialization
84 
85 LALUSB_API BOOL _cstmcall USB_FindDevices (char *DeviceDescriptionStr);
86 LALUSB_API BOOL _cstmcall USB_Init (int id, BOOL verbose);
89 LALUSB_API FT_STATUS _cstmcall GetDeviceDesc (char *buffer, int index);
91 
92 // Open and close devices
93 
94 LALUSB_API int _cstmcall OpenUsbDevice (char *sernumstr);
95 LALUSB_API void _cstmcall CloseUsbDevice (int id);
97 
100 
101 // Buffers and I/O operation
102 
104 LALUSB_API BOOL _cstmcall USB_Write (int id, void *buf, int count, int *written);
105 LALUSB_API BOOL _cstmcall USB_Read (int id, void *buf, int maxcnt, int *rdcount);
107 // LALUSB_API int USB_GetStatusEx (int id, TXRX_STATUS stat, DWORD *pEventDWord);
108 
109 // Parameters
110 
111 LALUSB_API BOOL _cstmcall USB_SetTimeouts (int id, int tx_timeout, int rx_timeout);
112 LALUSB_API BOOL _cstmcall USB_SetXferSize (int id, unsigned long txsize, unsigned long rxsize);
115 LALUSB_API BOOL _cstmcall USB_SetBaudRate (int id, int baud);
116 
117 // Error handling
118 
119 LALUSB_API void _cstmcall USB_Perror (USB_Error err_code);
122 LALUSB_API void _cstmcall USB_PrintErrMsg (char *msg);
123 LALUSB_API char * _cstmcall GetErrMsg (USB_Error err_code);
124 
125 void USB_Printf (char *format,...);
127 USB_Error GetUSB_Errno (void);
128 
129 // IO transfer mode management (asynchronous or synchronous)
130 
131 LALUSB_API BOOL _cstmcall USB_ResetMode(int id); // Tranfer mode is set to asynchronous i/o
132 LALUSB_API BOOL _cstmcall USB_SetSynchronousMode(int id, int sleep_time); // sleep_time is the time (in ms) between resetting tranfer mode and setting it to synchronous
134 
135 // EEPROM management
136 
140 LALUSB_API BOOL _cstmcall USB_SetSerialNumber (int id, char *sernum);
143 LALUSB_API BOOL _cstmcall USB_SetDescStr (int id, char *desc_str);
146 LALUSB_API BOOL _cstmcall USB_SetPowerSource (int id, unsigned short powersrc);
147 LALUSB_API BOOL _cstmcall USB_SetMaxPower (int id, unsigned short current);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 // ********************************************************************************
154 // ********************************************************************************
155 // **************************** LAL Frames Management *****************************
156 // ********************************************************************************
157 // ********************************************************************************
158 
159 // Definitions
160 
161 #define FRAME_HEADER 0x000000AA
162 #define FRAME_TRAILER 0x00000055
163 #define IS_INTERRUPT 0x0000007F
164 
165 #define DATA_READ 0x00000080
166 #define DATA_WRITE 0x0000007F
167 
168 #define USER_IRQ_FLAG 0x00000080
169 
170 /*
171 #ifndef _WINDOWS_
172  typedef unsigned char UCHAR;
173 
174  #define BOOL unsigned long
175  #ifndef FALSE
176  #define FALSE 0
177  #define TRUE !FALSE
178  #endif
179 #endif
180 */
181 
182 #ifdef __cplusplus
183 extern "C" {
184 #endif
185 
187 {
188  FE_NONE, // No frame error nor interrupt
189  FE_DEVICE, // Error (Interrupt) came from device
190  FE_SOFTWARE, // Error detected by the software
191  FE_USER, // User interrupt
192  FE_ERROR, // Interrupt has been generated by an error
193  FE_HEADER, // Header error
194  FE_TRAILER, // Trailer error
196 }FrameError;
197 // USB_IO_ERROR
198 
200 {
211 
212 typedef struct _int_frame_info
213 {
214  int source; // interrupt source : device (interrupt) or software (error)
215  int type; // interrupt type : error or user interrupt
216  int error_type; // error type : header, trailer or none if it's a user interrupt
217  int io_dir; // specifies the type of io operation (in/out)
218  int sub_addr; // current sub-address or command
219  int last_sub_addr; // last command for which data were processed normally
220  int status; // incoming user-defined status bits
221  USB_Error err_code; // FTDI error_code if the error comes from the chip/driver
223 
224 typedef enum _fake_errors
225 {
226  FK_LETSBETRUE = 1, // No error
227  FK_HEADER = 2, // header
228  FK_TRAILER = 4, // trailer
229  FK_COUNT = 8, // bad number of bytes
232 
233 // Prototypes
234 
235 LALUSB_API int _cstmcall UsbWrt (int id, char sub_addr, void *buffer, int count);
236 LALUSB_API int _cstmcall UsbRd (int id, char sub_addr, void *array, int count);
237 LALUSB_API int _cstmcall UsbRdEx (int id, void *array, int maxcnt, int *frames);
238 LALUSB_API int _cstmcall UsbReadEx (int id, void *array, int maxcnt, int *frames, int *frame_size);
239 
243 LALUSB_API InterruptFrameInfoPtr _cstmcall GetLastFrame(void);
249 
252 
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 #endif // __USB_LAL_H__
260 
LALUSB_API int _cstmcall UsbRdEx(int id, void *array, int maxcnt, int *frames)
_fake_errors
Definition: LALUsbML.h:227
LALUSB_API int _cstmcall GetLastFrameStatus(void)
LALUSB_API void _cstmcall CloseUsbDevice(int id)
LALUSB_API int _cstmcall UsbRd(int id, char sub_addr, void *array, int count)
LALUSB_API void _cstmcall USB_Perror(USB_Error err_code)
LALUSB_API char *_cstmcall USB_GetEpromDeviceDesc(void)
unsigned char UCHAR
Definition: WinTypes.h:11
LALUSB_API void _cstmcall PrintFrameInfo(void)
LALUSB_API int _cstmcall USB_GetNumberOfDevs(void)
struct _int_frame_info InterruptFrameInfo
LALUSB_API PerrorFunc pfError
LALUSB_API BOOL _cstmcall USB_SetXferSize(int id, unsigned long txsize, unsigned long rxsize)
LALUSB_API BOOL _cstmcall USB_SetPowerSource(int id, unsigned short powersrc)
enum _fake_errors FakeErrorType
LALUSB_API BOOL _cstmcall USB_Read(int id, void *buf, int maxcnt, int *rdcount)
USB_Error GetUSB_Errno(void)
TXRX_STATUS
Definition: LALUsbML.h:47
_extended_usb_errors
Definition: LALUsbML.h:199
LALUSB_API void _cstmcall UsbSetIntCheckingState(BOOL truefalse)
#define LALUSB_API
Definition: LALUsb.h:29
TXRX_STATUS
Definition: LALUsb.h:46
LALUSB_API char *_cstmcall GetErrMsg(USB_Error err_code)
LALUSB_API BOOL _cstmcall USB_SetDescStr(int id, char *desc_str)
LALUSB_API int _cstmcall USB_GetStatus(int id, TXRX_STATUS)
LALUSB_API BOOL _cstmcall USB_SetMaxPower(int id, unsigned short current)
FT_STATUS USB_Error
Definition: LALUsbML.h:72
LALUSB_API void _cstmcall ResetTotalByteCount(void)
LALUSB_API ULONG _cstmcall GetLostFrames(void)
void(* PrintfFunc)(char *format,...)
Definition: LALUsb.h:57
LALUSB_API BOOL _cstmcall USB_EraseEEpromData(int id)
LALUSB_API int _cstmcall OpenUsbDevice(char *sernumstr)
LALUSB_API InterruptFrameInfoPtr _cstmcall GetLastFrame(void)
LALUSB_API BOOL _cstmcall USB_ResetDevice(int id)
LALUSB_API BOOL _cstmcall USB_ResetMode(int id)
LALUSB_API int _cstmcall UsbReadEx(int id, void *array, int maxcnt, int *frames, int *frame_size)
LALUSB_API BOOL _cstmcall USB_SetTimeouts(int id, int tx_timeout, int rx_timeout)
LALUSB_API BOOL _cstmcall USB_Write(int id, void *buf, int count, int *written)
LALUSB_API ULONG _cstmcall GetTotalByteCount(void)
_frame_error_constants
Definition: LALUsbML.h:186
list index
Definition: images.py:1021
LALUSB_API ULONG _cstmcall GetTrailerErrors(void)
LALUSB_API void _cstmcall USB_SetPrintfFunc(PrintfFunc func)
LALUSB_API char *_cstmcall USB_GetEpromSerialNum(void)
LALUSB_API void _cstmcall dbg_CloseLogFile(void)
LALUSB_API void _cstmcall USB_PrintErrMsg(char *msg)
void(* PerrorFunc)(char *msg)
Definition: LALUsb.h:63
LALUSB_API BOOL _cstmcall USB_SetLatencyTimer(int id, UCHAR msecs)
LALUSB_API void _cstmcall ResetFrameErrors(void)
unsigned long ULONG
Definition: WinTypes.h:8
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
LALUSB_API BOOL _cstmcall USB_SetBaudRate(int id, int baud)
LALUSB_API BOOL _cstmcall USB_Init(int id, BOOL verbose)
#define _cstmcall
Definition: LALUsb.h:30
enum _extended_usb_errors Ext_USB_Error
LALUSB_API void _cstmcall ResetLostFrames(void)
USB_Error err_code
Definition: LALUsbML.h:224
LALUSB_API ULONG _cstmcall GetHeaderErrors(void)
LALUSB_API BOOL _cstmcall USB_SetSerialNumber(int id, char *sernum)
LALUSB_API void _cstmcall USB_SetPerrorFunc(PerrorFunc func)
LALUSB_API FT_STATUS _cstmcall GetDeviceSerNum(char *buffer, int index)
int BOOL
Definition: WinTypes.h:15
struct _int_frame_info * InterruptFrameInfoPtr
LALUSB_API void _cstmcall USB_CloseAll(void)
LALUSB_API BOOL _cstmcall USB_SetFlowControlToHardware(int id)
LALUSB_API FT_STATUS _cstmcall GetDeviceDesc(char *buffer, int index)
LALUSB_API BOOL _cstmcall USB_GetLatencyTimer(int id, PUCHAR msecs)
LALUSB_API BOOL _cstmcall USB_WriteEEpromData(int id)
void USB_Printf(char *format,...)
LALUSB_API void _cstmcall dbg_OpenLogFile(void)
enum _frame_error_constants FrameError
FT_STATUS USB_Error
Definition: LALUsb.h:71
LALUSB_API BOOL _cstmcall USB_SetSynchronousMode(int id, int sleep_time)
enum _fake_errors FakeErrorType
LALUSB_API BOOL _cstmcall USB_ReadEEpromData(int id, BOOL verbose)
unsigned char * PUCHAR
Definition: WinTypes.h:19
LALUSB_API void _cstmcall GenerateFakeError(FakeErrorType fet, BOOL onoff)
LALUSB_API int _cstmcall UsbWrt(int id, char sub_addr, void *buffer, int count)
LALUSB_API BOOL _cstmcall USB_PurgeBuffers(int id)
LALUSB_API char *_cstmcall USB_GetDefaultSerialNum(void)
LALUSB_API char *_cstmcall USB_GetDefaultDeviceDesc(void)
LALUSB_API BOOL _cstmcall USB_FindDevices(char *DeviceDescriptionStr)
ULONG FT_STATUS
Definition: ftd2xx.h:74