This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Connect a client driver to the USB stack
#include <sys/usbdi.h> int usbd_connect( usbd_connect_parm_t *parm, struct usbd_connection **connection );
You use the usbd_connect() function to connect to a USB device and to provide insertion/removal callbacks (in the usbd_connect_parm_t data structure).
typedef struct usbd_connect_parm { const char *path; _uint16 vusb; _uint16 vusbd; _uint32 flags; int argc; char **argv; _uint32 evtbufsz; usbd_device_ident_t *ident; usbd_funcs_t *funcs; _uint16 connect_wait } usbd_connect_parm_t;
typedef struct usbd_device_ident { _uint32 vendor; _uint32 device; _uint32 dclass; _uint32 subclass; _uint32 protocol; } usbd_device_ident_t;
You would typically make the usbd_device_ident structure be a filter for devices you support from this specific class driver.
typedef struct usbd_funcs { _uint32 nentries; void (*insertion)(struct usbd_connection *, usbd_device_instance_t *instance); void (*removal)(struct usbd_connection *, usbd_device_instance_t *instance); void (*event)(struct usbd_connection *, usbd_device_instance_t *instance, _uint16 type); } usbd_funcs_t;
The callback functions are contained here.
By passing NULL as the usbd_funcs, you're saying that you're not interested in receiving dynamic insertion/removal notifications, which means that you won't be a fully operational class driver. No asynchronous I/O will be allowed, no event thread, etc. This approach is taken, for example, by the usb display utility. |
A class driver (in its main(), probably) for a 3COM Ethernet card might connect like this:
usbd_device_ident_t interest = { USB_VENDOR_3COM, USB_PRODUCT_3COM_3C19250, USBD_CONNECT_WILDCARD, USBD_CONNECT_WILDCARD, USBD_CONNECT_WILDCARD, }; usbd_funcs_t funcs = { _USBDI_NFUNCS, insertion, removal, NULL }; usbd_connect_parm_t cparms = { NULL, USB_VERSION, USBD_VERSION, 0, argc, argv, 0, &interest, &funcs }; struct usbd_connection *connection; int error; error = usbd_connect(&cparms, &connection);
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
The usbd_connect() function creates a thread on your behalf that's used by the library to monitor the USB stack for device insertion or removal. Since your insertion and removal callback functions are called by this new thread, you must ensure that any common resources used between that thread and any other thread(s) in your class driver are properly protected (e.g. via a mutex).
usbd_args_lookup(), usbd_attach(), usbd_detach(), usbd_disconnect()