📄 usbdcore.h
字号:
#define USB_DESCRIPTOR_TYPE_DEVICE 0x01#define USB_DESCRIPTOR_TYPE_CONFIGURATION 0x02#define USB_DESCRIPTOR_TYPE_STRING 0x03#define USB_DESCRIPTOR_TYPE_INTERFACE 0x04#define USB_DESCRIPTOR_TYPE_ENDPOINT 0x05#define USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER 0x06#define USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION 0x07#define USB_DESCRIPTOR_TYPE_INTERFACE_POWER 0x08#define USB_DESCRIPTOR_TYPE_HID 0x21#define USB_DESCRIPTOR_TYPE_REPORT 0x22#define USBD_DEVICE_DESCRIPTORS(x) (((unsigned int)x <= USB_DESCRIPTOR_TYPE_INTERFACE_POWER) ? \ usbd_device_descriptors[x] : "UNKNOWN")/* * standard feature selectors */#define USB_ENDPOINT_HALT 0x00#define USB_DEVICE_REMOTE_WAKEUP 0x01#define USB_TEST_MODE 0x02/* USB Requests * */struct usb_device_request { u8 bmRequestType; u8 bRequest; u16 wValue; u16 wIndex; u16 wLength;} __attribute__ ((packed));/* USB Status * */typedef enum urb_send_status { SEND_IN_PROGRESS, SEND_FINISHED_OK, SEND_FINISHED_ERROR, RECV_READY, RECV_OK, RECV_ERROR} urb_send_status_t;/* * Device State (c.f USB Spec 2.0 Figure 9-1) * * What state the usb device is in. * * Note the state does not change if the device is suspended, we simply set a * flag to show that it is suspended. * */typedef enum usb_device_state { STATE_INIT, /* just initialized */ STATE_CREATED, /* just created */ STATE_ATTACHED, /* we are attached */ STATE_POWERED, /* we have seen power indication (electrical bus signal) */ STATE_DEFAULT, /* we been reset */ STATE_ADDRESSED, /* we have been addressed (in default configuration) */ STATE_CONFIGURED, /* we have seen a set configuration device command */ STATE_UNKNOWN, /* destroyed */} usb_device_state_t;#define USBD_DEVICE_STATE(x) (((unsigned int)x <= STATE_UNKNOWN) ? usbd_device_states[x] : "UNKNOWN")/* * Device status * * Overall state */typedef enum usb_device_status { USBD_OPENING, /* we are currently opening */ USBD_OK, /* ok to use */ USBD_SUSPENDED, /* we are currently suspended */ USBD_CLOSING, /* we are currently closing */} usb_device_status_t;#define USBD_DEVICE_STATUS(x) (((unsigned int)x <= USBD_CLOSING) ? usbd_device_status[x] : "UNKNOWN")/* * Device Events * * These are defined in the USB Spec (c.f USB Spec 2.0 Figure 9-1). * * There are additional events defined to handle some extra actions we need * to have handled. * */typedef enum usb_device_event { DEVICE_UNKNOWN, /* bi - unknown event */ DEVICE_INIT, /* bi - initialize */ DEVICE_CREATE, /* bi - */ DEVICE_HUB_CONFIGURED, /* bi - bus has been plugged int */ DEVICE_RESET, /* bi - hub has powered our port */ DEVICE_ADDRESS_ASSIGNED, /* ep0 - set address setup received */ DEVICE_CONFIGURED, /* ep0 - set configure setup received */ DEVICE_SET_INTERFACE, /* ep0 - set interface setup received */ DEVICE_SET_FEATURE, /* ep0 - set feature setup received */ DEVICE_CLEAR_FEATURE, /* ep0 - clear feature setup received */ DEVICE_DE_CONFIGURED, /* ep0 - set configure setup received for ?? */ DEVICE_BUS_INACTIVE, /* bi - bus in inactive (no SOF packets) */ DEVICE_BUS_ACTIVITY, /* bi - bus is active again */ DEVICE_POWER_INTERRUPTION, /* bi - hub has depowered our port */ DEVICE_HUB_RESET, /* bi - bus has been unplugged */ DEVICE_DESTROY, /* bi - device instance should be destroyed */ DEVICE_HOTPLUG, /* bi - a hotplug event has occured */ DEVICE_FUNCTION_PRIVATE, /* function - private */} usb_device_event_t;typedef struct urb_link { struct urb_link *next; struct urb_link *prev;} urb_link;/* USB Data structure - for passing data around. * * This is used for both sending and receiving data. * * The callback function is used to let the function driver know when * transmitted data has been sent. * * The callback function is set by the alloc_recv function when an urb is * allocated for receiving data for an endpoint and used to call the * function driver to inform it that data has arrived. */#define URB_BUF_SIZE 128 /* in linux we'd malloc this, but in u-boot we prefer static data */struct urb { struct usb_endpoint_instance *endpoint; struct usb_device_instance *device; struct usb_device_request device_request; /* contents of received SETUP packet */ struct urb_link link; /* embedded struct for circular doubly linked list of urbs */ u8* buffer; unsigned int buffer_length; unsigned int actual_length; urb_send_status_t status; int data; u16 buffer_data[URB_BUF_SIZE]; /* data received (OUT) or being sent (IN) */};/* Endpoint configuration * * Per endpoint configuration data. Used to track which function driver owns * an endpoint. * */struct usb_endpoint_instance { int endpoint_address; /* logical endpoint address */ /* control */ int status; /* halted */ int state; /* available for use by bus interface driver */ /* receive side */ struct urb_link rcv; /* received urbs */ struct urb_link rdy; /* empty urbs ready to receive */ struct urb *rcv_urb; /* active urb */ int rcv_attributes; /* copy of bmAttributes from endpoint descriptor */ int rcv_packetSize; /* maximum packet size from endpoint descriptor */ int rcv_transferSize; /* maximum transfer size from function driver */ int rcv_queue; /* transmit side */ struct urb_link tx; /* urbs ready to transmit */ struct urb_link done; /* transmitted urbs */ struct urb *tx_urb; /* active urb */ int tx_attributes; /* copy of bmAttributes from endpoint descriptor */ int tx_packetSize; /* maximum packet size from endpoint descriptor */ int tx_transferSize; /* maximum transfer size from function driver */ int tx_queue; int sent; /* data already sent */ int last; /* data sent in last packet XXX do we need this */};struct usb_alternate_instance { struct usb_interface_descriptor *interface_descriptor; int endpoints; int *endpoint_transfersize_array; struct usb_endpoint_descriptor **endpoints_descriptor_array;};struct usb_interface_instance { int alternates; struct usb_alternate_instance *alternates_instance_array;};struct usb_configuration_instance { int interfaces; struct usb_configuration_descriptor *configuration_descriptor; struct usb_interface_instance *interface_instance_array;};/* USB Device Instance * * For each physical bus interface we create a logical device structure. This * tracks all of the required state to track the USB HOST's view of the device. * * Keep track of the device configuration for a real physical bus interface, * this includes the bus interface, multiple function drivers, the current * configuration and the current state. * * This will show: * the specific bus interface driver * the default endpoint 0 driver * the configured function driver * device state * device status * endpoint list */struct usb_device_instance { /* generic */ char *name; struct usb_device_descriptor *device_descriptor; /* per device descriptor */ void (*event) (struct usb_device_instance *device, usb_device_event_t event, int data); /* bus interface */ struct usb_bus_instance *bus; /* which bus interface driver */ /* configuration descriptors */ int configurations; struct usb_configuration_instance *configuration_instance_array; /* device state */ usb_device_state_t device_state; /* current USB Device state */ usb_device_state_t device_previous_state; /* current USB Device state */ u8 address; /* current address (zero is default) */ u8 configuration; /* current show configuration (zero is default) */ u8 interface; /* current interface (zero is default) */ u8 alternate; /* alternate flag */ usb_device_status_t status; /* device status */ int urbs_queued; /* number of submitted urbs */ /* Shouldn't need to make this atomic, all we need is a change indicator */ unsigned long usbd_rxtx_timestamp; unsigned long usbd_last_rxtx_timestamp;};/* Bus Interface configuration structure * * This is allocated for each configured instance of a bus interface driver. * * The privdata pointer may be used by the bus interface driver to store private * per instance state information. */struct usb_bus_instance { struct usb_device_instance *device; struct usb_endpoint_instance *endpoint_array; /* array of available configured endpoints */ int max_endpoints; /* maximimum number of rx enpoints */ unsigned char maxpacketsize; unsigned int serial_number; char *serial_number_str; void *privdata; /* private data for the bus interface */};extern char *usbd_device_events[];extern char *usbd_device_states[];extern char *usbd_device_status[];extern char *usbd_device_requests[];extern char *usbd_device_descriptors[];void urb_link_init (urb_link * ul);void urb_detach (struct urb *urb);urb_link *first_urb_link (urb_link * hd);struct urb *first_urb (urb_link * hd);struct urb *first_urb_detached (urb_link * hd);void urb_append (urb_link * hd, struct urb *urb);struct urb *usbd_alloc_urb (struct usb_device_instance *device, struct usb_endpoint_instance *endpoint);void usbd_dealloc_urb (struct urb *urb);/* * usbd_device_event is used by bus interface drivers to tell the higher layers that * certain events have taken place. */void usbd_device_event_irq (struct usb_device_instance *conf, usb_device_event_t, int);void usbd_device_event (struct usb_device_instance *conf, usb_device_event_t, int);/* descriptors * * Various ways of finding descriptors based on the current device and any * possible configuration / interface / endpoint for it. */struct usb_configuration_descriptor *usbd_device_configuration_descriptor (struct usb_device_instance *, int, int);struct usb_function_instance *usbd_device_function_instance (struct usb_device_instance *, unsigned int);struct usb_interface_instance *usbd_device_interface_instance (struct usb_device_instance *, int, int, int);struct usb_alternate_instance *usbd_device_alternate_instance (struct usb_device_instance *, int, int, int, int);struct usb_interface_descriptor *usbd_device_interface_descriptor (struct usb_device_instance *, int, int, int, int);struct usb_endpoint_descriptor *usbd_device_endpoint_descriptor_index (struct usb_device_instance *, int, int, int, int, int);struct usb_class_descriptor *usbd_device_class_descriptor_index (struct usb_device_instance *, int, int, int, int, int);struct usb_class_report_descriptor *usbd_device_class_report_descriptor_index( struct usb_device_instance *, int , int , int , int , int );struct usb_endpoint_descriptor *usbd_device_endpoint_descriptor (struct usb_device_instance *, int, int, int, int, int);int usbd_device_endpoint_transfersize (struct usb_device_instance *, int, int, int, int, int);struct usb_string_descriptor *usbd_get_string (u8);struct usb_device_descriptor *usbd_device_device_descriptor (struct usb_device_instance *, int);int usbd_endpoint_halted (struct usb_device_instance *device, int endpoint);void usbd_rcv_complete(struct usb_endpoint_instance *endpoint, int len, int urb_bad);void usbd_tx_complete (struct usb_endpoint_instance *endpoint);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -