[U-Boot] [PATCH 2/8] USB add macros for debugging usb device setup.

Tom Rix
2009-09-04T20:12:44Z

When developing usb device features, it is useful to print out
common usb structures.

Signed-off-by: Tom Rix <Tom.Rix@windriver.com>
---
include/usbdescriptors.h | 31 +++++++++++++
include/usbdevice.h | 105 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 136 insertions(+), 0 deletions(-)

diff --git a/include/usbdescriptors.h b/include/usbdescriptors.h
index ea05672..f4e33b6 100644
--- a/include/usbdescriptors.h
+++ b/include/usbdescriptors.h
@@ -510,4 +510,35 @@ struct usb_class_descriptor {

} __attribute__ ((packed));

+#ifdef DEBUG
+#define PRINT_DEVICE_DESCRIPTOR(d) \
+do { \
+ serial_printf("usb device descriptor \n"); \
+ serial_printf("\tbLength %2.2x\n", (d)->bLength); \
+ serial_printf("\tbDescriptorType %2.2x\n", \
+ (d)->bDescriptorType); \
+ serial_printf("\tbcdUSB %4.4x\n", (d)->bcdUSB); \
+ serial_printf("\tbDeviceClass %2.2x\n", (d)->bDeviceClass); \
+ serial_printf("\tbDeviceSubClass %2.2x\n", \
+ (d)->bDeviceSubClass); \
+ serial_printf("\tbDeviceProtocol %2.2x\n", \
+ (d)->bDeviceProtocol); \
+ serial_printf("\tbMaxPacketSize0 %2.2x\n", \
+ (d)->bMaxPacketSize0); \
+ serial_printf("\tidVendor %4.4x\n", (d)->idVendor); \
+ serial_printf("\tidProduct %4.4x\n", (d)->idProduct); \
+ serial_printf("\tbcdDevice %4.4x\n", (d)->bcdDevice); \
+ serial_printf("\tiManufacturer %2.2x\n", (d)->iManufacturer); \
+ serial_printf("\tiProduct %2.2x\n", (d)->iProduct); \
+ serial_printf("\tiSerialNumber %2.2x\n", (d)->iSerialNumber); \
+ serial_printf("\tbNumConfigurations %2.2x\n", \
+ (d)->bNumConfigurations); \
+} while (0)
+
+#else
+
+/* stubs */
+#define PRINT_DEVICE_DESCRIPTOR(d)
+
+#endif /* DEBUG */
#endif
diff --git a/include/usbdevice.h b/include/usbdevice.h
index 206dbbc..0b7961f 100644
--- a/include/usbdevice.h
+++ b/include/usbdevice.h
@@ -663,4 +663,109 @@ 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);

+/* These are macros used in debugging */
+#ifdef DEBUG
+#define PRINT_URB(u) \
+do { \
+ serial_printf("urb %p\n", (u)); \
+ serial_printf("\tendpoint %p\n", (u)->endpoint); \
+ serial_printf("\tdevice %p\n", (u)->device); \
+ serial_printf("\tbuffer %p\n", (u)->buffer); \
+ serial_printf("\tbuffer_length %d\n", (u)->buffer_length); \
+ serial_printf("\tactual_length %d\n", (u)->actual_length); \
+ serial_printf("\tstatus %d\n", (u)->status); \
+ serial_printf("\tdata %d\n", (u)->data); \
+} while (0) \
+
+#define PRINT_USB_DEVICE_REQUEST(r) \
+do { \
+ serial_printf("usb request\n"); \
+ serial_printf("\tbmRequestType 0x%2.2x\n", (r)->bmRequestType); \
+ if (0 == ((r)->bmRequestType & USB_REQ_DIRECTION_MASK)) \
+ serial_printf("\t\tDirection : To device\n"); \
+ else \
+ serial_printf("\t\tDirection : To host\n"); \
+ if (USB_TYPE_STANDARD == \
+ ((r)->bmRequestType & USB_TYPE_STANDARD)) \
+ serial_printf("\t\tType : Standard\n"); \
+ if (USB_TYPE_CLASS == ((r)->bmRequestType & USB_TYPE_CLASS)) \
+ serial_printf("\t\tType : Standard\n"); \
+ if (USB_TYPE_VENDOR == ((r)->bmRequestType & USB_TYPE_VENDOR)) \
+ serial_printf("\t\tType : Standard\n"); \
+ if (USB_TYPE_RESERVED == \
+ ((r)->bmRequestType & USB_TYPE_RESERVED)) \
+ serial_printf("\t\tType : Standard\n"); \
+ if (USB_REQ_RECIPIENT_DEVICE == \
+ ((r)->bmRequestType & USB_REQ_RECIPIENT_MASK)) \
+ serial_printf("\t\tRecipient : Device\n"); \
+ if (USB_REQ_RECIPIENT_INTERFACE == \
+ ((r)->bmRequestType & USB_REQ_RECIPIENT_MASK)) \
+ serial_printf("\t\tRecipient : Interface\n"); \
+ if (USB_REQ_RECIPIENT_ENDPOINT == \
+ ((r)->bmRequestType & USB_REQ_RECIPIENT_MASK)) \
+ serial_printf("\t\tRecipient : Endpoint\n"); \
+ if (USB_REQ_RECIPIENT_OTHER == \
+ ((r)->bmRequestType & USB_REQ_RECIPIENT_MASK)) \
+ serial_printf("\t\tRecipient : Other\n"); \
+ serial_printf("\tbRequest 0x%2.2x\n", (r)->bRequest); \
+ if ((r)->bRequest == USB_REQ_GET_STATUS) \
+ serial_printf("\t\tGET_STATUS\n"); \
+ else if ((r)->bRequest == USB_REQ_SET_ADDRESS) \
+ serial_printf("\t\tSET_ADDRESS\n"); \
+ else if ((r)->bRequest == USB_REQ_SET_FEATURE) \
+ serial_printf("\t\tSET_FEATURE\n"); \
+ else if ((r)->bRequest == USB_REQ_GET_DESCRIPTOR) \
+ serial_printf("\t\tGET_DESCRIPTOR\n"); \
+ else if ((r)->bRequest == USB_REQ_SET_CONFIGURATION) \
+ serial_printf("\t\tSET_CONFIGURATION\n"); \
+ else if ((r)->bRequest == USB_REQ_SET_INTERFACE) \
+ serial_printf("\t\tUSB_REQ_SET_INTERFACE\n"); \
+ else \
+ serial_printf("\tUNKNOWN %d\n", (r)->bRequest); \
+ serial_printf("\twValue 0x%4.4x\n", (r)->wValue); \
+ if ((r)->bRequest == USB_REQ_GET_DESCRIPTOR) { \
+ switch ((r)->wValue >> 8) { \
+ case USB_DESCRIPTOR_TYPE_DEVICE: \
+ serial_printf("\tDEVICE\n"); \
+ break; \
+ case USB_DESCRIPTOR_TYPE_CONFIGURATION: \
+ serial_printf("\tCONFIGURATION\n"); \
+ break; \
+ case USB_DESCRIPTOR_TYPE_STRING: \
+ serial_printf("\tSTRING\n"); \
+ break; \
+ case USB_DESCRIPTOR_TYPE_INTERFACE: \
+ serial_printf("\tINTERFACE\n"); \
+ break; \
+ case USB_DESCRIPTOR_TYPE_ENDPOINT: \
+ serial_printf("\tENDPOINT\n"); \
+ break; \
+ case USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER: \
+ serial_printf("\tDEVICE_QUALIFIER\n"); \
+ break; \
+ case USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION: \
+ serial_printf("\tOTHER_SPEED_CONFIGURATION\n"); \
+ break; \
+ case USB_DESCRIPTOR_TYPE_INTERFACE_POWER: \
+ serial_printf("\tINTERFACE_POWER\n"); \
+ break; \
+ case USB_DESCRIPTOR_TYPE_HID: \
+ serial_printf("\tHID\n"); \
+ break; \
+ case USB_DESCRIPTOR_TYPE_REPORT: \
+ serial_printf("\tREPORT\n"); \
+ break; \
+ default: \
+ serial_printf("\tUNKNOWN TYPE\n"); \
+ break; \
+ } \
+ } \
+ serial_printf("\twIndex 0x%4.4x\n", (r)->wIndex); \
+ serial_printf("\twLength 0x%4.4x\n", (r)->wLength); \
+} while (0)
+#else
+/* stubs */
+#define PRINT_URB(u)
+#define PRINT_USB_DEVICE_REQUEST(r)
+#endif /* DEBUG */
#endif
--
1.6.0.4