libusbK 
3.0
Library Documentation
© 2011-2021 Travis Lee Robinson. All rights reserved.
examples.h
Go to the documentation of this file.
1 
5 #include <windows.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <conio.h>
9 
10 #include "libusbk.h"
11 
12 #ifndef __EXAMPLE_H_
13 #define __EXAMPLE_H_
14 
16 
19 #define EXAMPLES_USE_BENCHMARK_CONFIGURE 1
20 
22 #ifndef EXAMPLE_VID
23 #define EXAMPLE_VID 0x04D8
24 #endif
25 
27 #ifndef EXAMPLE_PID
28 #define EXAMPLE_PID 0xFA2E
29 #endif
30 
32 typedef enum _BM_COMMAND
33 {
34  BM_COMMAND_SET_TEST = 0x0E,
35  BM_COMMAND_GET_TEST = 0x0F,
36  BM_COMMAND_SET_VBUF = 0x10,
37  BM_COMMAND_GET_VBUF = 0x11,
38 } BM_COMMAND;
39 
41 typedef enum _BM_TEST_TYPE
42 {
43  BM_TEST_TYPE_NONE = 0x00,
44  BM_TEST_TYPE_READ = 0x01,
45  BM_TEST_TYPE_WRITE = 0x02,
46  BM_TEST_TYPE_LOOP = BM_TEST_TYPE_READ | BM_TEST_TYPE_WRITE,
47 } BM_TEST_TYPE, *PBM_TEST_TYPE;
48 
50 
72 BOOL Examples_GetTestDevice(KLST_HANDLE* DeviceList,
73  KLST_DEVINFO_HANDLE* DeviceInfo,
74  int argc,
75  char* argv[]);
76 BOOL Examples_GetTestDeviceEx(KLST_HANDLE* DeviceList,
77  KLST_DEVINFO_HANDLE* DeviceInfo,
78  int argc,
79  char* argv[],
80  KLST_FLAG Flags);
81 
82 BOOL Bench_Configure(KUSB_HANDLE UsbHandle,
83  BM_COMMAND Command,
84  UCHAR InterfaceNumber,
85  PKUSB_DRIVER_API DriverAPI,
86  PBM_TEST_TYPE TestType);
87 
88 BOOL Examples_GetArgVal(int argc, char* argv[], LPCSTR argName, PUINT argValue, BOOL isHex);
89 BOOL Examples_GetArgStr(int argc, char* argv[], LPCSTR argName, LPSTR argValue, PUINT argValLength);
90 
91 typedef struct _DATA_COUNTER_STATS
92 {
93  LARGE_INTEGER Freq;
94  LARGE_INTEGER Start;
95  LARGE_INTEGER Stop;
96 
97  LONGLONG TotalBytes;
98  double Bps;
99  double dFreq;
100  double Duration;
101 
102 } DATA_COUNTER_STATS, *PDATA_COUNTER_STATS;
103 
104 #define mDcs_Init(mDataCounterStats) do { \
105  memset((mDataCounterStats),0,sizeof(DATA_COUNTER_STATS)); \
106  QueryPerformanceFrequency(&((mDataCounterStats)->Freq)); \
107  (mDataCounterStats)->dFreq = 1.0/(double)(mDataCounterStats)->Freq.QuadPart; \
108  QueryPerformanceCounter(&((mDataCounterStats)->Start)); \
109  }while(0)
110 
111 #define mDcs_MarkStop(mDataCounterStats,mAddTransferLength) do { \
112  QueryPerformanceCounter(&((mDataCounterStats)->Stop)); \
113  (mDataCounterStats)->TotalBytes+=(LONG)(mAddTransferLength); \
114  (mDataCounterStats)->Duration = \
115  ((mDataCounterStats)->dFreq) * \
116  ((double) ((mDataCounterStats)->Stop.QuadPart - (mDataCounterStats)->Start.QuadPart)); \
117  if ((mDataCounterStats)->Duration != 0.0) \
118  (mDataCounterStats)->Bps = ((double)(mDataCounterStats)->TotalBytes) / (mDataCounterStats)->Duration; \
119  }while(0)
120 
121 
122 #endif
123 
124 
125 
126 #ifndef UTLIST_H
127 #define UTLIST_H
128 
176 /*
177 Copyright (c) 2007-2010, Troy D. Hanson http://uthash.sourceforge.net
178 All rights reserved.
179 
180 Redistribution and use in source and binary forms, with or without
181 modification, are permitted provided that the following conditions are met:
182 
183  * Redistributions of source code must retain the above copyright
184  notice, this list of conditions and the following disclaimer.
185 
186 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
187 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
188 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
189 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
190 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
191 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
192 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
193 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
194 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
195 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
196 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
197 */
198 
199 /******************************************************************************
200  * doubly linked list macros (non-circular) *
201  *****************************************************************************/
202 
204 
211 #define DL_PREPEND(head,add) \
212  do { \
213  (add)->next = head; \
214  if (head) { \
215  (add)->prev = (head)->prev; \
216  (head)->prev = (add); \
217  } else { \
218  (add)->prev = (add); \
219  } \
220  (head) = (add); \
221  } while (0)
222 
224 
231 #define DL_APPEND(head,add) \
232  do { \
233  if (head) { \
234  (add)->prev = (head)->prev; \
235  (head)->prev->next = (add); \
236  (head)->prev = (add); \
237  (add)->next = NULL; \
238  } else { \
239  (head)=(add); \
240  (head)->prev = (head); \
241  (head)->next = NULL; \
242  } \
243  } while (0);
244 
246 
258 #define DL_DELETE(head,del) \
259  do { \
260  if ((del)->prev == (del)) { \
261  (head)=NULL; \
262  } else if ((del)==(head)) { \
263  (del)->next->prev = (del)->prev; \
264  (head) = (del)->next; \
265  } else { \
266  (del)->prev->next = (del)->next; \
267  if ((del)->next) { \
268  (del)->next->prev = (del)->prev; \
269  } else { \
270  (head)->prev = (del)->prev; \
271  } \
272  } \
273  } while (0);
274 
276 
283 #define DL_FOREACH(head,el) \
284  for(el=head;el;el=el->next)
285 
287 
297 #define DL_FOREACH_SAFE(head,el,tmp) \
298  for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
299 
300 /* these are identical to their singly-linked list counterparts */
301 
303 
316 #define DL_SEARCH_SCALAR(head,out,field,val) \
317  do { \
318  DL_FOREACH(head,out) { \
319  if ((out)->field == (val)) break; \
320  } \
321  } while(0)
322 
324 
337 #define DL_SEARCH(head,out,elt,cmp) \
338  do { \
339  DL_FOREACH(head,out) { \
340  if ((cmp(out,elt))==0) break; \
341  } \
342  } while(0)
343 
344 #endif /* UTLIST_H */
345 
346 
functions for usb device communication.
KLIB_HANDLE KLST_HANDLE
Opaque LstK handle, see LstK_Init.
Definition: libusbk.h:131
BM_TEST_TYPE
Tests supported by the official benchmark firmware.
Definition: examples.h:41
KLST_FLAG
Device list initialization flags.
Definition: libusbk.h:350
Driver API function set structure.
Definition: libusbk.h:2045
BOOL Examples_GetTestDevice(KLST_HANDLE *DeviceList, KLST_DEVINFO_HANDLE *DeviceInfo, int argc, char *argv[])
Helper function for examples; searches a command line argument list for devices matching a specific v...
BM_COMMAND
Custom vendor requests that must be implemented in the benchmark firmware.
Definition: examples.h:32
Semi-opaque device information structure of a device list.
Definition: libusbk.h:284
KLIB_HANDLE KUSB_HANDLE
Opaque UsbK handle, see UsbK_Init.
Definition: libusbk.h:128