Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Dec 5th, 2012  |  syntax: None  |  size: 1.64 KB  |  hits: 32  |  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. void udc_tick_task(void)
  2. {
  3.     uint32_t dev_info = DEV_INFO;
  4.     static struct usb_ctrlrequest req_addr, req_conf;
  5.     static bool set_address = false;
  6.     static bool set_configuration = false;
  7.  
  8.     /* This tick task polls for DEV_EN bit set in DEV_INFO  register
  9.      * as well as tracks current requested configuration
  10.      * (DEV_INFO [11:8]). On state change it notifies usb stack
  11.      * about it.
  12.      *
  13.      * It is registered on usb connection and removed on usb
  14.      * extraction.
  15.      */
  16.  
  17.     /* SET ADDRESS request */
  18.     if (set_address == false)
  19.         if ((dev_info & 0x7f))
  20.         {
  21.             udc_conn = (dev_info & 0x7f);
  22.             set_address = true;
  23.  
  24.             req_addr.bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
  25.             req_addr.bRequest = USB_REQ_SET_ADDRESS;
  26.             req_addr.wValue = (dev_info & 0x7f);
  27.             req_addr.wIndex = 0;
  28.             req_addr.wLength = 0;
  29.  
  30.             logf("udc_tick_task() ctrl req=%x",req_addr.bRequest);
  31.             usb_core_control_request(&req_addr);
  32.         }
  33.  
  34.     /* SET CONFIGURATION request */
  35.     if (set_configuration == false)
  36.     if (dev_info & DEV_EN)
  37.     {
  38.         set_configuration = true;
  39.  
  40.         req_conf.bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
  41.         req_conf.bRequest = USB_REQ_SET_CONFIGURATION;
  42.         req_conf.wValue = ((dev_info >> 8) & 0x0f) + 1;
  43.         req_conf.wIndex = 0;
  44.         req_conf.wLength = 0;
  45.  
  46.         /* Notify usb stack somehow */
  47.         usb_core_control_request(&req_conf);
  48.  
  49.         tick_remove_task(udc_tick_task);
  50.  
  51.         set_address = false;    
  52.     }
  53. }