Cat
LALUsbML.h
Go to the documentation of this file.
1 // Tab size = 4 characters
2 // LALUsbML.h : main header file of LALusbv2 project
3 // (LALUsbML 0.1.0a)
4 // Author C. CHEIKALI
5 // Created 03/02/12
6 // Last modified : 03/02/2012 adaptation from LALUsb.h (LALUsb 2.0 library)
7 // 18/09/2012 version 0.1.0a
8 // 28/09/2012 version 0.1.0f
9 // 02/10/2012 version 0.1.1a
10 // 17/10/2012 version 0.1.2
11 
12 #ifndef __USB_LAL_H__
13 #define __USB_LAL_H__
14 
15 #ifdef _WINDOWS_
16 
17  #ifdef LALUSBML_EXPORTS
18  #define LALUSB_API __declspec(dllexport)
19  #define _cstmcall _stdcall
20  #else
21  #ifdef LALUSBML_STATIC
22  #define LALUSB_API
23  #define _cstmcall __cdecl
24  #else
25  #define LALUSB_API __declspec(dllimport)
26  #define _cstmcall _stdcall
27  #endif
28  #endif
29 #else
30  #define LALUSB_API
31  #define _cstmcall
32 
33  #include <fcntl.h>
34  #include <sys/types.h>
35  #include <sys/stat.h>
36 
37 #endif
38 
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 
43 #include "ftd2xx.h"
44 
45 /******************************* definitions ******************************/
46 
47 typedef enum
48 {
52 
53 
54 
55 // Printf-like function type
56 
57 #if !defined (PrintfFunc)
58  typedef void (*PrintfFunc)(char *format, ...);
59 #endif
60 
61 // Error printing function type
62 
63 #if !defined (PerrorFunc)
64  typedef void (*PerrorFunc)(char *msg);
65 #endif
66 
67 // Errors that may occur
68 
69 #define USB_NoErr FT_OK
70 #define FrameNoErr FT_OK
71 
73 
74 #ifndef LALUSB_EXPORTS
76 #endif
77 
78 /******************************* Prototypes ******************************/
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
84 // Initialization
85 
86 LALUSB_API BOOL _cstmcall USB_FindDevices (char *DeviceDescriptionStr);
87 LALUSB_API BOOL _cstmcall USB_Init (int id, BOOL verbose);
90 LALUSB_API FT_STATUS _cstmcall GetDeviceDesc (char *buffer, int index);
92 
93 // Open and close devices
94 
95 LALUSB_API int _cstmcall OpenUsbDevice (char *sernumstr);
96 LALUSB_API void _cstmcall CloseUsbDevice (int id);
98 
101 
102 // Buffers and I/O operation
103 
105 LALUSB_API BOOL _cstmcall USB_Write (int id, void *buf, int count, int *written);
106 LALUSB_API BOOL _cstmcall USB_Read (int id, void *buf, int maxcnt, int *rdcount);
108 // LALUSB_API int USB_GetStatusEx (int id, TXRX_STATUS stat, DWORD *pEventDWord);
109 
110 // Parameters
111 
112 LALUSB_API BOOL _cstmcall USB_SetTimeouts (int id, int tx_timeout, int rx_timeout);
113 LALUSB_API BOOL _cstmcall USB_SetXferSize (int id, unsigned long txsize, unsigned long rxsize);
116 LALUSB_API BOOL _cstmcall USB_SetBaudRate (int id, int baud);
117 
118 // Error handling
119 
120 LALUSB_API void _cstmcall USB_Perror (USB_Error err_code);
123 LALUSB_API void _cstmcall USB_PrintErrMsg (char *msg);
124 LALUSB_API char * _cstmcall GetErrMsg (USB_Error err_code);
125 
126 void USB_Printf (char *format,...);
128 USB_Error GetUSB_Errno (void);
129 
130 // IO transfer mode management (asynchronous or synchronous)
131 
132 LALUSB_API BOOL _cstmcall USB_ResetMode(int id); // Tranfer mode is set to asynchronous i/o
133 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
135 
136 // EEPROM management
137 
141 LALUSB_API BOOL _cstmcall USB_SetSerialNumber (int id, char *sernum);
144 LALUSB_API BOOL _cstmcall USB_SetDescStr (int id, char *desc_str);
147 LALUSB_API BOOL _cstmcall USB_SetPowerSource (int id, unsigned short powersrc);
148 LALUSB_API BOOL _cstmcall USB_SetMaxPower (int id, unsigned short current);
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 // ********************************************************************************
155 // ********************************************************************************
156 // **************************** LAL Frames Management *****************************
157 // ********************************************************************************
158 // ********************************************************************************
159 
160 // Definitions
161 
162 #define FRAME_HEADER 0x000000AA
163 #define FRAME_TRAILER 0x00000055
164 #define IS_INTERRUPT 0x0000007F
165 
166 #define DATA_READ 0x00000080
167 #define DATA_WRITE 0x0000007F
168 
169 #define USER_IRQ_FLAG 0x00000080
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 {
214 
215 typedef struct _int_frame_info
216 {
217  int source; // interrupt source : device (interrupt) or software (error) FE_DEVICE/ FE_SOFTWARE)
218  int type; // interrupt type : error or user interrupt --> FE_ERROR, FE_USER
219  int error_type; // error type : header, trailer or none if it's a user interrupt
220  int io_dir; // specifies the type of io operation (in/out)
221  int sub_addr; // current sub-address or command
222  int last_sub_addr; // last command for which data were processed normally
223  int status; // incoming user-defined status bits
224  USB_Error err_code; // FTDI error_code if the error comes from the chip/driver
226 
227 typedef enum _fake_errors
228 {
229  FK_LETSBETRUE = 1, // No error
230  FK_HEADER = 2, // header
231  FK_TRAILER = 4, // trailer
232  FK_COUNT = 8, // bad number of bytes
235 
236 #define MAXLAYER 8
237 
238 // Prototypes
239 
240 LALUSB_API int _cstmcall UsbWrt (int id, char sub_addr, void *buffer, int count);
241 LALUSB_API int _cstmcall UsbRd (int id, char sub_addr, void *array, int count);
242 LALUSB_API int _cstmcall UsbRdEx (int id, void *array, int maxcnt, int *frames);
243 LALUSB_API int _cstmcall UsbReadEx (int id, void *array, int maxcnt, int *frames, int *frame_size);
244 
248 LALUSB_API InterruptFrameInfoPtr _cstmcall GetLastFrame(void);
254 
257 
258 // ML Section
259 
260 LALUSB_API int _cstmcall UsbWrtML (int id, int *target_path_array, char sub_addr, void *buffer, int count);
261 LALUSB_API int _cstmcall UsbReadML (int id, int *target_path_array, char sub_addr, void *buffer, int usercount);
262 LALUSB_API int _cstmcall UsbRequestForReadML (int id, int *target_path_array, char sub_addr, void *buffer, int count);
263 LALUSB_API int _cstmcall UsbReadExML (int id, int *target_path_array, void *array, int maxcnt,
264  int *frames, int *frame_size, int *sub_add_array);
266 LALUSB_API int _cstmcall UsbGetNlayers (int id);
267 LALUSB_API int _cstmcall UsbSetMaxLayer (int id, int num_layers);
268 LALUSB_API int _cstmcall UsbGetMaxLayer (int id, int *num_layers);
269 
270 #pragma pack(1)
271 typedef struct _ml_frame
272 {
273  unsigned int frame_id;
274  int frame_num; // frame index
275  int data_size; // frame size
276  char sub_address; // target (or source) sub_address
277  int nlayer; // number of layers for this frame
278  int path[MAXLAYER]; // LP target (or source) path
279  unsigned char *user_data; // user data space
280 }ML_Frame;
281 #pragma pack()
282 
283 LALUSB_API int _cstmcall UsbReadExML_New(int id, void *array, ML_Frame *mf_array, int max_num_bytes, int *frames);
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 
289 #endif // __USB_LAL_H__
LALUSB_API int *_cstmcall UsbGetTargetPathArray(int id)
LALUSB_API void _cstmcall ResetTotalByteCount(void)
_fake_errors
Definition: LALUsbML.h:227
LALUSB_API BOOL _cstmcall USB_Read(int id, void *buf, int maxcnt, int *rdcount)
LALUSB_API char *_cstmcall USB_GetDefaultSerialNum(void)
LALUSB_API BOOL _cstmcall USB_GetLatencyTimer(int id, PUCHAR msecs)
LALUSB_API char *_cstmcall USB_GetDefaultDeviceDesc(void)
LALUSB_API void _cstmcall USB_Perror(USB_Error err_code)
LALUSB_API int _cstmcall UsbReadExML_New(int id, void *array, ML_Frame *mf_array, int max_num_bytes, int *frames)
unsigned char UCHAR
Definition: WinTypes.h:11
LALUSB_API void _cstmcall ResetFrameErrors(void)
LALUSB_API ULONG _cstmcall GetLostFrames(void)
LALUSB_API int _cstmcall UsbReadEx(int id, void *array, int maxcnt, int *frames, int *frame_size)
LALUSB_API BOOL _cstmcall USB_ReadEEpromData(int id, BOOL verbose)
void(* PrintfFunc)(char *format,...)
Definition: LALUsbML.h:58
LALUSB_API BOOL _cstmcall USB_SetLatencyTimer(int id, UCHAR msecs)
LALUSB_API int _cstmcall GetLastFrameStatus(void)
TXRX_STATUS
Definition: LALUsbML.h:47
LALUSB_API int _cstmcall UsbRd(int id, char sub_addr, void *array, int count)
LALUSB_API void _cstmcall dbg_CloseLogFile(void)
_extended_usb_errors
Definition: LALUsbML.h:199
LALUSB_API void _cstmcall USB_SetPerrorFunc(PerrorFunc func)
enum _extended_usb_errors Ext_USB_Error
LALUSB_API InterruptFrameInfoPtr _cstmcall GetLastFrame(void)
LALUSB_API BOOL _cstmcall USB_ResetDevice(int id)
LALUSB_API BOOL _cstmcall USB_SetFlowControlToHardware(int id)
LALUSB_API int _cstmcall OpenUsbDevice(char *sernumstr)
unsigned int frame_id
Definition: LALUsbML.h:273
FT_STATUS USB_Error
Definition: LALUsbML.h:72
LALUSB_API FT_STATUS _cstmcall GetDeviceSerNum(char *buffer, int index)
LALUSB_API ULONG _cstmcall GetTrailerErrors(void)
LALUSB_API void _cstmcall USB_SetPrintfFunc(PrintfFunc func)
LALUSB_API BOOL _cstmcall USB_SetMaxPower(int id, unsigned short current)
LALUSB_API BOOL _cstmcall USB_ResetMode(int id)
LALUSB_API int _cstmcall USB_GetStatus(int id, TXRX_STATUS)
LALUSB_API void _cstmcall dbg_OpenLogFile(void)
LALUSB_API int _cstmcall UsbRequestForReadML(int id, int *target_path_array, char sub_addr, void *buffer, int count)
LALUSB_API void _cstmcall CloseUsbDevice(int id)
LALUSB_API BOOL _cstmcall USB_PurgeBuffers(int id)
void USB_Printf(char *format,...)
void(* PerrorFunc)(char *msg)
Definition: LALUsbML.h:64
USB_Error GetUSB_Errno(void)
LALUSB_API BOOL _cstmcall USB_SetDescStr(int id, char *desc_str)
_frame_error_constants
Definition: LALUsbML.h:186
list index
Definition: images.py:1021
LALUSB_API int _cstmcall UsbGetMaxLayer(int id, int *num_layers)
int frame_num
Definition: LALUsbML.h:274
enum _frame_error_constants FrameError
LALUSB_API int _cstmcall UsbWrtML(int id, int *target_path_array, char sub_addr, void *buffer, int count)
LALUSB_API char *_cstmcall USB_GetEpromDeviceDesc(void)
LALUSB_API int _cstmcall UsbReadML(int id, int *target_path_array, char sub_addr, void *buffer, int usercount)
struct _int_frame_info InterruptFrameInfo
#define LALUSB_API
Definition: LALUsbML.h:30
LALUSB_API BOOL _cstmcall USB_SetBaudRate(int id, int baud)
LALUSB_API int _cstmcall UsbSetMaxLayer(int id, int num_layers)
LALUSB_API int _cstmcall USB_GetNumberOfDevs(void)
LALUSB_API BOOL _cstmcall USB_SetPowerSource(int id, unsigned short powersrc)
LALUSB_API void _cstmcall USB_PrintErrMsg(char *msg)
LALUSB_API BOOL _cstmcall USB_SetSerialNumber(int id, char *sernum)
LALUSB_API void _cstmcall USB_CloseAll(void)
unsigned long ULONG
Definition: WinTypes.h:8
LALUSB_API ULONG _cstmcall GetTotalByteCount(void)
LALUSB_API BOOL _cstmcall USB_SetTimeouts(int id, int tx_timeout, int rx_timeout)
LALUSB_API int _cstmcall UsbReadExML(int id, int *target_path_array, void *array, int maxcnt, int *frames, int *frame_size, int *sub_add_array)
LALUSB_API BOOL _cstmcall USB_FindDevices(char *DeviceDescriptionStr)
LALUSB_API BOOL _cstmcall USB_Init(int id, BOOL verbose)
unsigned char * user_data
Definition: LALUsbML.h:279
int data_size
Definition: LALUsbML.h:275
struct _ml_frame ML_Frame
LALUSB_API BOOL _cstmcall USB_Write(int id, void *buf, int count, int *written)
USB_Error err_code
Definition: LALUsbML.h:224
LALUSB_API FT_STATUS _cstmcall GetDeviceDesc(char *buffer, int index)
LALUSB_API BOOL _cstmcall USB_SetSynchronousMode(int id, int sleep_time)
LALUSB_API int _cstmcall UsbWrt(int id, char sub_addr, void *buffer, int count)
LALUSB_API BOOL _cstmcall USB_EraseEEpromData(int id)
int BOOL
Definition: WinTypes.h:15
LALUSB_API char *_cstmcall USB_GetEpromSerialNum(void)
LALUSB_API BOOL _cstmcall USB_WriteEEpromData(int id)
LALUSB_API int _cstmcall UsbRdEx(int id, void *array, int maxcnt, int *frames)
LALUSB_API char *_cstmcall GetErrMsg(USB_Error err_code)
LALUSB_API void _cstmcall UsbSetIntCheckingState(BOOL truefalse)
LALUSB_API PerrorFunc pfError
#define _cstmcall
Definition: LALUsbML.h:31
LALUSB_API int _cstmcall UsbGetNlayers(int id)
enum _fake_errors FakeErrorType
struct _int_frame_info * InterruptFrameInfoPtr
#define MAXLAYER
Definition: LALUsbML.h:236
unsigned char * PUCHAR
Definition: WinTypes.h:19
LALUSB_API BOOL _cstmcall USB_SetXferSize(int id, unsigned long txsize, unsigned long rxsize)
LALUSB_API USB_Error _cstmcall USB_GetLastError(void)
LALUSB_API void _cstmcall ResetLostFrames(void)
int nlayer
Definition: LALUsbML.h:277
char sub_address
Definition: LALUsbML.h:276
LALUSB_API ULONG _cstmcall GetHeaderErrors(void)
LALUSB_API void _cstmcall PrintFrameInfo(void)
ULONG FT_STATUS
Definition: ftd2xx.h:74