|
NAMEusb_fifo_alloc_buffer ,
usb_fifo_attach ,
usb_fifo_detach ,
usb_fifo_free_buffer ,
usb_fifo_get_data ,
usb_fifo_get_data_buffer ,
usb_fifo_get_data_error ,
usb_fifo_get_data_linear ,
usb_fifo_put_bytes_max ,
usb_fifo_put_data ,
usb_fifo_put_data_buffer ,
usb_fifo_put_data_error ,
usb_fifo_put_data_linear ,
usb_fifo_reset ,
usb_fifo_softc ,
usb_fifo_wakeup ,
usbd_do_request ,
usbd_do_request_flags ,
usbd_errstr ,
usbd_lookup_id_by_info ,
usbd_lookup_id_by_uaa ,
usbd_transfer_clear_stall ,
usbd_transfer_drain ,
usbd_transfer_pending ,
usbd_transfer_poll ,
usbd_transfer_setup ,
usbd_transfer_start ,
usbd_transfer_stop ,
usbd_transfer_submit ,
usbd_transfer_unsetup ,
usbd_xfer_clr_flag ,
usbd_xfer_frame_data ,
usbd_xfer_frame_len ,
usbd_xfer_get_frame ,
usbd_xfer_get_priv ,
usbd_xfer_is_stalled ,
usbd_xfer_max_framelen ,
usbd_xfer_max_frames ,
usbd_xfer_max_len ,
usbd_xfer_set_flag ,
usbd_xfer_set_frame_data ,
usbd_xfer_set_frame_len ,
usbd_xfer_set_frame_offset ,
usbd_xfer_set_frames ,
usbd_xfer_set_interval ,
usbd_xfer_set_priv ,
usbd_xfer_set_stall ,
usbd_xfer_set_timeout ,
usbd_xfer_softc ,
usbd_xfer_state ,
usbd_xfer_status —
Universal Serial Bus driver programming interface
SYNOPSIS#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
usb_error_t
void
void
void
void
DESCRIPTIONThe Universal Serial Bus (USB) driver programming interface provides USB peripheral drivers with a host controller independent API for controlling and communicating with USB peripherals. Theusb module
supports both USB Host and USB Device side mode.
USB TRANSFER MANAGEMENT FUNCTIONSThe USB standard defines four types of USB transfers. Control transfers, Bulk transfers, Interrupt transfers and Isochronous transfers. All the transfer types are managed using the following five functions:
USB TRANSFER CALLBACKThe USB callback has three states. USB_ST_SETUP, USB_ST_TRANSFERRED and USB_ST_ERROR. USB_ST_SETUP is the initial state. After the callback has been called with this state it will always be called back at a later stage in one of the other two states. The USB callback should not restart the USB transfer in case the error cause is USB_ERR_CANCELLED. The USB callback is protected from recursion. That means one can start and stop whatever transfer from the callback of another transfer one desires. Also the transfer that is currently called back. Recursion is handled like this that when the callback that wants to recurse returns it is called one more time.
void usb_default_callback(struct usb_xfer *xfer, usb_error_t error) { int actlen; usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); switch (USB_GET_STATE(xfer)) { case USB_ST_SETUP: /* * Setup xfer frame lengths/count and data */ usbd_transfer_submit(xfer); break; case USB_ST_TRANSFERRED: /* * Read usb frame data, if any. * "actlen" has the total length for all frames * transferred. */ break; default: /* Error */ /* * Print error message and clear stall * for example. */ break; } /* * Here it is safe to do something without the private * USB mutex locked. */ return; } USB CONTROL TRANSFERSAn USB control transfer has three parts. First the SETUP packet, then DATA packet(s) and then a STATUS packet. The SETUP packet is always pointed to by frame 0 and the length is set byusbd_xfer_frame_len ()
also if there should not be sent any SETUP packet! If an USB control transfer
has no DATA stage, then the number of frames should be set to 1. Else the
default number of frames is 2.
Example1: SETUP + STATUS usbd_xfer_set_frames(xfer, 1); usbd_xfer_set_frame_len(xfer, 0, 8); usbd_transfer_submit(xfer); Example2: SETUP + DATA + STATUS usbd_xfer_set_frames(xfer, 2); usbd_xfer_set_frame_len(xfer, 0, 8); usbd_xfer_set_frame_len(xfer, 1, 1); usbd_transfer_submit(xfer); Example3: SETUP + DATA + STATUS - split 1st callback: usbd_xfer_set_frames(xfer, 1); usbd_xfer_set_frame_len(xfer, 0, 8); usbd_transfer_submit(xfer); 2nd callback: /* IMPORTANT: frbuffers[0] must still point at the setup packet! */ usbd_xfer_set_frames(xfer, 2); usbd_xfer_set_frame_len(xfer, 0, 0); usbd_xfer_set_frame_len(xfer, 1, 1); usbd_transfer_submit(xfer); Example4: SETUP + STATUS - split 1st callback: usbd_xfer_set_frames(xfer, 1); usbd_xfer_set_frame_len(xfer, 0, 8); usbd_xfer_set_flag(xfer, USB_MANUAL_STATUS); usbd_transfer_submit(xfer); 2nd callback: usbd_xfer_set_frames(xfer, 1); usbd_xfer_set_frame_len(xfer, 0, 0); usbd_xfer_clr_flag(xfer, USB_MANUAL_STATUS); usbd_transfer_submit(xfer); USB TRANSFER CONFIGTo simply the search for endpoints theusb module
defines a USB config structure where it is possible to specify the
characteristics of the wanted endpoint.
struct usb_config { bufsize, callback direction, endpoint, frames, index flags, interval, timeout, type, }; type field selects the USB pipe type. Valid values are: UE_INTERRUPT, UE_CONTROL, UE_BULK, UE_ISOCHRONOUS. The special value UE_BULK_INTR will select BULK and INTERRUPT pipes. This field is mandatory. endpoint field selects the USB endpoint number. A value of 0xFF, "-1" or "UE_ADDR_ANY" will select the first matching endpoint. This field is mandatory. direction field selects the USB endpoint direction. A value of "UE_DIR_ANY" will select the first matching endpoint. Else valid values are: "UE_DIR_IN" and "UE_DIR_OUT". "UE_DIR_IN" and "UE_DIR_OUT" can be binary OR'ed by "UE_DIR_SID" which means that the direction will be swapped in case of USB_MODE_DEVICE. Note that "UE_DIR_IN" refers to the data transfer direction of the "IN" tokens and "UE_DIR_OUT" refers to the data transfer direction of the "OUT" tokens. This field is mandatory. interval field selects the interrupt interval. The value of this field is given in milliseconds and is independent of device speed. Depending on the endpoint type, this field has different meaning:
timeout field, if non-zero, will set the transfer timeout in milliseconds. If the "timeout" field is zero and the transfer type is ISOCHRONOUS a timeout of 250ms will be used. frames field sets the maximum number of frames. If zero is specified it will yield the following results:
ep_index field allows you to give a number, in case more endpoints match the description, that selects which matching "ep_index" should be used. if_index field allows you to select which of the interface numbers in the "ifaces" array parameter passed to "usbd_transfer_setup" that should be used when setting up the given USB transfer. flags field has type "struct usb_xfer_flags" and allows one to set initial flags an USB transfer. Valid flags are:
bufsize field sets the total buffer size in bytes. If this field is zero, "wMaxPacketSize" will be used, multiplied by the "frames" field if the transfer type is ISOCHRONOUS. This is useful for setting up interrupt pipes. This field is mandatory. NOTE: For control transfers "bufsize" includes the length of the request structure. callback pointer sets the USB callback. This field is mandatory. USB LINUX COMPAT LAYERTheusb module supports the Linux USB API.
SEE ALSOlibusb(3), usb(4), usbconfig(8)STANDARDSTheusb module complies with the USB 2.0 standard.
HISTORYTheusb module has been inspired by the NetBSD USB stack
initially written by Lennart Augustsson. The usb
module was written by Hans Petter Selasky
<hselasky@FreeBSD.org>.
Visit the GSP FreeBSD Man Page Interface. |