libusbK 
3.0
Library Documentation
© 2011-2021 Travis Lee Robinson. All rights reserved.
examples.h File Reference

Common include file used only in examples. More...

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include "libusbk.h"

Go to the source code of this file.

Macros

#define EXAMPLES_USE_BENCHMARK_CONFIGURE   1
 Enables/disables custom vendor control request (supported by the Benchmark Device Firmware). More...
 
#define EXAMPLE_VID   0x04D8
 Default example vendor id.
 
#define EXAMPLE_PID   0xFA2E
 Default example product id.
 
#define DL_PREPEND(head, add)
 Doubly linked list macro for C structures. utlist.h More...
 
#define DL_APPEND(head, add)
 Adds an element to the end of a linked list. More...
 
#define DL_DELETE(head, del)
 Removes an element from a linked list. More...
 
#define DL_FOREACH(head, el)   for(el=head;el;el=el->next)
 Start a foreach like enumeration though a linked list using a for loop. More...
 
#define DL_FOREACH_SAFE(head, el, tmp)   for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)
 Start a foreach like enumeration though a linked list using a for loop. More...
 
#define DL_SEARCH_SCALAR(head, out, field, val)
 Searches for a scalar field using a DL_FOREACH. More...
 
#define DL_SEARCH(head, out, elt, cmp)
 Searches for an element using a user-defined compare function such as memcmp or strcmp. More...
 

Enumerations

enum  BM_COMMAND
 Custom vendor requests that must be implemented in the benchmark firmware.
 
enum  BM_TEST_TYPE
 Tests supported by the official benchmark firmware.
 

Functions

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 vid/pid. More...
 

Detailed Description

Common include file used only in examples.

Macro Definition Documentation

#define EXAMPLES_USE_BENCHMARK_CONFIGURE   1

Enables/disables custom vendor control request (supported by the Benchmark Device Firmware).

Note
If your example device is not running Benchmark Firmware, set this define to "0".
#define DL_PREPEND (   head,
  add 
)
Value:
do { \
(add)->next = head; \
if (head) { \
(add)->prev = (head)->prev; \
(head)->prev = (add); \
} else { \
(add)->prev = (add); \
} \
(head) = (add); \
} while (0)

Doubly linked list macro for C structures. utlist.h

Provided by Troy D. Hanson

Attention
All lists used by the libusbK library are non-circular doubly-linked lists. (DL_ prefixed macros)

This file contains macros to manipulate singly and doubly-linked lists:

  1. LL_ macros: singly-linked lists.
  2. DL_ macros: doubly-linked lists.
  3. CDL_ macros: circular doubly-linked lists.
Note
Only a small subset of the utlist.h macros are documented. Undocumented macros will not appear in this documentation but can be downloaded here:
To use singly-linked lists, your structure must have a "next" pointer.
To use doubly-linked lists, your structure must "prev" and "next" pointers.
Either way, the pointer to the head of the list must be initialized to NULL.
struct item
{
int id;
struct item *prev, *next;
}
struct item *list = NULL:
int main()
{
struct item *item;
... allocate and populate item ...
DL_APPEND(list, item);
}

Performance Considerations:

  • For doubly-linked lists, the append and delete macros are O(1)
  • For singly-linked lists, append and delete are O(n) but prepend is O(1)
  • The sort macro is O(n log(n)) for all types of single/double/circular lists.Adds an element to the beginning of a linked list.
Parameters
headFirst element of the list.
addElement to add.
#define DL_APPEND (   head,
  add 
)
Value:
do { \
if (head) { \
(add)->prev = (head)->prev; \
(head)->prev->next = (add); \
(head)->prev = (add); \
(add)->next = NULL; \
} else { \
(head)=(add); \
(head)->prev = (head); \
(head)->next = NULL; \
} \
} while (0);

Adds an element to the end of a linked list.

Parameters
headFirst element of the list.
addElement to add.
Examples:
xfer-async-loop.c, xfer-async.c, xfer-iso-asap.c, and xfer-iso.c.
#define DL_DELETE (   head,
  del 
)
Value:
do { \
if ((del)->prev == (del)) { \
(head)=NULL; \
} else if ((del)==(head)) { \
(del)->next->prev = (del)->prev; \
(head) = (del)->next; \
} else { \
(del)->prev->next = (del)->next; \
if ((del)->next) { \
(del)->next->prev = (del)->prev; \
} else { \
(head)->prev = (del)->prev; \
} \
} \
} while (0);

Removes an element from a linked list.

Parameters
headFirst element of the list.
delElement to remove.
Attention
DL_DELETE does not free or de-allocate memory. It "de-links" the element specified by del from the list.
Examples:
xfer-async-loop.c, xfer-iso-asap.c, and xfer-iso.c.
#define DL_FOREACH (   head,
  el 
)    for(el=head;el;el=el->next)

Start a foreach like enumeration though a linked list using a for loop.

Parameters
headFirst element of the list.
elassigned to an element of the linked list on each iteration.
Examples:
xfer-async.c.
#define DL_FOREACH_SAFE (   head,
  el,
  tmp 
)    for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp)

Start a foreach like enumeration though a linked list using a for loop.

Parameters
headFirst element of the list.
elassigned to an element of the linked list on each iteration.
tmpA temporary list element used to ensure safe deletion during iteration.
Attention
This version is safe for deleting the elements during iteration.
Examples:
xfer-iso-asap.c, and xfer-iso.c.
#define DL_SEARCH_SCALAR (   head,
  out,
  field,
  val 
)
Value:
do { \
DL_FOREACH(head,out) { \
if ((out)->field == (val)) break; \
} \
} while(0)
#define DL_FOREACH(head, el)
Start a foreach like enumeration though a linked list using a for loop.
Definition: examples.h:283

Searches for a scalar field using a DL_FOREACH.

Parameters
headFirst element of the list.
outFirst element whose field value equals val.
fieldName of the field member to search.
valValue to compare with the field member.
#define DL_SEARCH (   head,
  out,
  elt,
  cmp 
)
Value:
do { \
DL_FOREACH(head,out) { \
if ((cmp(out,elt))==0) break; \
} \
} while(0)
#define DL_FOREACH(head, el)
Start a foreach like enumeration though a linked list using a for loop.
Definition: examples.h:283

Searches for an element using a user-defined compare function such as memcmp or strcmp.

Parameters
headFirst element of the list.
outFirst matching element that matched (user-defined compare function returned 0).
eltMatching criteria (passed as a second paramater to the user-defined compare function)
cmpUser-defined compare function or macro.

Function Documentation

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 vid/pid.

Arguments are interpreted as follows:

  • vid=<4 digit hex>
    • hex number is a vendor id.
  • pid=<4 digit hex>
    • hex number is a product id.
Parameters
DeviceListOn success, contains a pointer to the device list.
DeviceInfoOn success, contains a pointer to the first device info structure which matched.
argcThe argc parameter of the main() application function.
argvThe argv parameter of the main() application function.
Returns
TRUE if a devices was found, otherwise FALSE.
Examples:
config-interface.c, load-driver-api.c, open-device.c, pipe-policy-timeout.c, power-policy-suspend.c, xfer-async-loop.c, xfer-async.c, xfer-control.c, xfer-iso-asap.c, xfer-iso.c, xfer-stream.c, and xfer-sync.c.