Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 17th, 2012  |  syntax: Diff  |  size: 5.84 KB  |  views: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff --git a/utils/imxtools/hwemul/dev/main.c b/utils/imxtools/hwemul/dev/main.c
  2. index 09bb6c7..328dd2c 100644
  3. --- a/utils/imxtools/hwemul/dev/main.c
  4. +++ b/utils/imxtools/hwemul/dev/main.c
  5. @@ -154,8 +154,8 @@ static inline void imx233_enable_pin_pullup_mask(unsigned bank, uint32_t pin_msk
  6.   */
  7.  
  8.  #define USB_BASE            0x80080000
  9. -#define USB_NUM_ENDPOINTS   2
  10. -#define MAX_PKT_SIZE        1024
  11. +#define USB_NUM_ENDPOINTS   3
  12. +#define MAX_PKT_SIZE_DFLT   64
  13.  #define MAX_PKT_SIZE_EP0    64
  14.  
  15.  /* USB device mode registers (Little Endian) */
  16. @@ -427,6 +427,19 @@ static int usb_drv_port_speed(void)
  17.      return (REG_PORTSC1 & 0x08000000) ? 1 : 0;
  18.  }
  19.  
  20. +static int usb_drv_max_packet_size(bool hs, int type)
  21. +{
  22. +    switch(type)
  23. +    {
  24. +        case USB_ENDPOINT_XFER_BULK:
  25. +            return hs ? 512 : 64;
  26. +        case USB_ENDPOINT_XFER_INT:
  27. +            return hs ? 1024 : 64;
  28. +        default:
  29. +            return 0;
  30. +    }
  31. +}
  32. +
  33.  static void usb_drv_stall(int endpoint, bool stall, bool in)
  34.  {
  35.      int ep_num = EP_NUM(endpoint);
  36. @@ -1018,17 +1031,18 @@ static void handle_std_dev_desc(struct usb_ctrlrequest *req)
  37.          case USB_DT_OTHER_SPEED_CONFIG:
  38.          case USB_DT_CONFIG:
  39.          {
  40. -            int max_packet_size;
  41. -
  42. +            int bulk_max_packet_size, int_max_packet_size;
  43.              /* config desc */
  44. -            if((req->wValue >> 8) ==USB_DT_CONFIG)
  45. +            if((req->wValue >> 8) == USB_DT_CONFIG)
  46.              {
  47. -                max_packet_size = (usb_drv_port_speed() ? 512 : 64);
  48. +                bulk_max_packet_size = usb_drv_max_packet_size(usb_drv_port_speed(), USB_ENDPOINT_XFER_BULK);
  49. +                int_max_packet_size = usb_drv_max_packet_size(usb_drv_port_speed(), USB_ENDPOINT_XFER_INT);
  50.                  config_descriptor.bDescriptorType = USB_DT_CONFIG;
  51.              }
  52.              else
  53.              {
  54. -                max_packet_size=(usb_drv_port_speed() ? 64 : 512);
  55. +                bulk_max_packet_size = usb_drv_max_packet_size(!usb_drv_port_speed(), USB_ENDPOINT_XFER_BULK);
  56. +                int_max_packet_size = usb_drv_max_packet_size(!usb_drv_port_speed(), USB_ENDPOINT_XFER_INT);
  57.                  config_descriptor.bDescriptorType = USB_DT_OTHER_SPEED_CONFIG;
  58.              }
  59.              size = sizeof(struct usb_config_descriptor);
  60. @@ -1040,21 +1054,22 @@ static void handle_std_dev_desc(struct usb_ctrlrequest *req)
  61.              /* endpoint 1: bulk out */
  62.              endpoint_descriptor.bEndpointAddress = EP_BULK | USB_DIR_OUT;
  63.              endpoint_descriptor.bmAttributes = USB_ENDPOINT_XFER_BULK;
  64. -            endpoint_descriptor.wMaxPacketSize = 512;
  65. +            endpoint_descriptor.wMaxPacketSize = bulk_max_packet_size;
  66.              memcpy(usb_buffer + size, (void *)&endpoint_descriptor,
  67.                  sizeof(endpoint_descriptor));
  68.              size += sizeof(endpoint_descriptor);
  69.              /* endpoint 2: bulk in */
  70.              endpoint_descriptor.bEndpointAddress = EP_BULK | USB_DIR_IN;
  71.              endpoint_descriptor.bmAttributes = USB_ENDPOINT_XFER_BULK;
  72. -            endpoint_descriptor.wMaxPacketSize = 512;
  73. +            endpoint_descriptor.wMaxPacketSize = bulk_max_packet_size;
  74.              memcpy(usb_buffer + size, (void *)&endpoint_descriptor,
  75.                  sizeof(endpoint_descriptor));
  76.              size += sizeof(endpoint_descriptor);
  77.              /* endpoint 3: int in */
  78.              endpoint_descriptor.bEndpointAddress = EP_INT | USB_DIR_IN;
  79.              endpoint_descriptor.bmAttributes = USB_ENDPOINT_XFER_INT;
  80. -            endpoint_descriptor.wMaxPacketSize = 1024;
  81. +            endpoint_descriptor.wMaxPacketSize = int_max_packet_size;
  82. +            endpoint_descriptor.bInterval = 32;
  83.              memcpy(usb_buffer + size, (void *)&endpoint_descriptor,
  84.                  sizeof(endpoint_descriptor));
  85.              size += sizeof(endpoint_descriptor);
  86. @@ -1367,6 +1382,7 @@ void main(uint32_t arg)
  87.      /* reset the controller */
  88.      REG_USBCMD |= USBCMD_CTRL_RESET;
  89.      while (REG_USBCMD & USBCMD_CTRL_RESET);
  90. +    //REG_PORTSC1 |= PORTSCX_PORT_FORCE_FULL_SPEED;
  91.      /* put it in device mode */
  92.      REG_USBMODE = USBMODE_CTRL_MODE_DEVICE;
  93.      /* reset address */
  94. @@ -1374,17 +1390,33 @@ void main(uint32_t arg)
  95.      /* prepare qh array */
  96.      qh_array[0].max_pkt_length = 1 << 29 | MAX_PKT_SIZE_EP0 << 16;
  97.      qh_array[1].max_pkt_length = 1 << 29 | MAX_PKT_SIZE_EP0 << 16;
  98. -    qh_array[2].max_pkt_length = 1 << 29 | MAX_PKT_SIZE << 16;
  99. -    qh_array[3].max_pkt_length = 1 << 29 | MAX_PKT_SIZE << 16;
  100. +    qh_array[2].max_pkt_length = 1 << 29 | MAX_PKT_SIZE_DFLT << 16;
  101. +    qh_array[3].max_pkt_length = 1 << 29 | MAX_PKT_SIZE_DFLT << 16;
  102. +    qh_array[4].max_pkt_length = 1 << 29 | MAX_PKT_SIZE_DFLT << 16;
  103. +    qh_array[5].max_pkt_length = 1 << 29 | MAX_PKT_SIZE_DFLT << 16;
  104.      /* setup qh */
  105.      REG_ENDPOINTLISTADDR = (unsigned int)qh_array;
  106.      /* clear setup status */
  107.      REG_ENDPTSETUPSTAT = EPSETUP_STATUS_EP0;
  108.      /* run! */
  109.      REG_USBCMD |= USBCMD_RUN;
  110. -    
  111. +
  112. +    int speed = -1;
  113.      while(1)
  114.      {
  115. +        if(speed != usb_drv_port_speed())
  116. +        {
  117. +            speed = usb_drv_port_speed();
  118. +            qh_array[2].max_pkt_length = 1 << 29 |
  119. +            usb_drv_max_packet_size(speed, USB_ENDPOINT_XFER_BULK) << 16;
  120. +            qh_array[3].max_pkt_length = 1 << 29 |
  121. +                usb_drv_max_packet_size(speed, USB_ENDPOINT_XFER_BULK) << 16;
  122. +            qh_array[4].max_pkt_length = 1 << 29 |
  123. +                usb_drv_max_packet_size(speed, USB_ENDPOINT_XFER_INT) << 16;
  124. +            qh_array[5].max_pkt_length = 1 << 29 |
  125. +                usb_drv_max_packet_size(speed, USB_ENDPOINT_XFER_INT) << 16;
  126. +            logf("connected in %s speed mode\n", speed ? "high" : "full");
  127. +        }
  128.          /* wait for setup */
  129.          while(!(REG_ENDPTSETUPSTAT & EPSETUP_STATUS_EP0))
  130.              ;