⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 host_811.lst

📁 完整的usb_host_device源代码直接在keil下编译
💻 LST
📖 第 1 页 / 共 5 页
字号:
 643          int EnumUsbDev(BYTE usbaddr)
 644          {  
 645   1              int i;                                                                                  // always reset USB transfer address 
 646   1              xdata BYTE uAddr = 0;                                                   // for enumeration to Address #0
 647   1              xdata BYTE epLen;
 648   1              xdata WORD strLang;
 649   1      
 650   1              //------------------------------------------------
 651   1              // Reset only Slave device attached directly
 652   1              //------------------------------------------------
 653   1              uDev[0].wPayLoad[0] = 64;                                               // default 64-byte payload of Endpoint 0, address #0
 654   1              if(usbaddr == 1)                                                                // bus reset for the device attached to SL811HS only
 655   1                      USBReset();                                                                     // that will always have the USB address = 0x01 (for a hub)
 656   1          EZUSB_Delay(25);
 657   1      
 658   1              //------------------------------------------------
 659   1              // Get USB Device Descriptors on EP0 & Addr 0
 660   1              // with default 64-byte payload
 661   1              //------------------------------------------------
 662   1              pDev =(pDevDesc)DBUF;                                                   // ask for 64 bytes on Addr #0
 663   1              if (!GetDesc(uAddr,DEVICE,0,18,DBUF))                   // and determine the wPayload size
 664   1                      return FALSE;                                                           // get correct wPayload of Endpoint 0
 665   1              uDev[usbaddr].wPayLoad[0]=pDev->bMaxPacketSize0;// on current non-zero USB address
 666   1      
 667   1              //------------------------------------------------
 668   1              // Set Slave USB Device Address
 669   1              //------------------------------------------------
 670   1              if (!SetAddress(usbaddr))                                               // set to specific USB address
 671   1                      return FALSE;                                                           //
 672   1              uAddr = usbaddr;                                                                // transfer using this new address
 673   1      
 674   1              //------------------------------------------------
C51 COMPILER V7.50   HOST_811                                                              10/27/2005 20:00:37 PAGE 12  

 675   1              // Get USB Device Descriptors on EP0 & Addr X
 676   1              //------------------------------------------------
 677   1              if (!GetDesc(uAddr,DEVICE,0,(pDev->bLength),DBUF))      
 678   1                      return FALSE;                                                           // For this current device:
 679   1              uDev[usbaddr].wVID       = pDev->idVendor;                      // save VID
 680   1              uDev[usbaddr].wPID       = pDev->idProduct;                     // save PID
 681   1              uDev[usbaddr].iMfg       = pDev->iManufacturer;         // save Mfg Index
 682   1              uDev[usbaddr].iPdt       = pDev->iProduct;                      // save Product Index
 683   1      
 684   1              //------------------------------------------------
 685   1              // Get String Descriptors
 686   1              //------------------------------------------------
 687   1              pStr = (pStrDesc)DBUF;  
 688   1              if (!GetDesc(uAddr,STRING,0,4,DBUF))                    // Get string language
 689   1                      return FALSE;                                                           
 690   1              strLang = pStr->wLang;                                                  // get iManufacturer String length
 691   1              if (!GetDesc(uAddr,(WORD)(uDev[usbaddr].iMfg<<8)|STRING,strLang,4,DBUF))                
 692   1                      return FALSE;                                                           // get iManufacturer String descriptors
 693   1              if (!GetDesc(uAddr,(WORD)(uDev[usbaddr].iMfg<<8)|STRING,strLang,pStr->bLength,DBUF))            
 694   1                      return FALSE;                   
 695   1      
 696   1              //------------------------------------------------
 697   1              // Get Slave USB Configuration Descriptors
 698   1              //------------------------------------------------
 699   1              pCfg = (pCfgDesc)DBUF;                                                                  
 700   1              if (!GetDesc(uAddr,CONFIGURATION,0,8,DBUF))             
 701   1                      return FALSE;                                                                           
 702   1              if (!GetDesc(uAddr,CONFIGURATION,0,WordSwap(pCfg->wLength),DBUF))       
 703   1                      return FALSE;           
 704   1      
 705   1              pIfc = (pIntfDesc)(DBUF + 9);                                   // point to Interface Descp
 706   1              uDev[usbaddr].bClass    = pIfc->iClass;                 // update to class type
 707   1              uDev[usbaddr].bNumOfEPs = (pIfc->bEndPoints <= MAX_EP) ? pIfc->bEndPoints : MAX_EP;
 708   1      
 709   1              //------------------------------------------------
 710   1              // Set configuration (except for HUB device)
 711   1              //------------------------------------------------
 712   1              if (uDev[usbaddr].bClass!=HUBCLASS)                             // enumerating a FS/LS non-hub device
 713   1                      if (!Set_Configuration(uAddr,DEVICE))           // connected directly to SL811HS
 714   1                                      return FALSE;
 715   1      
 716   1              //------------------------------------------------
 717   1              // For each slave endpoints, get its attributes
 718   1              // Excluding endpoint0, only data endpoints
 719   1              //------------------------------------------------
 720   1              epLen = 0;
 721   1              for (i=1; i<=uDev[usbaddr].bNumOfEPs; i++)                              // For each data endpoint
 722   1              {
 723   2                      pEnp = (pEPDesc)(DBUF + 9 + 9 + epLen);                         // point to Endpoint Descp(non-HID)
 724   2                      if(pIfc->iClass == HIDCLASS)    
 725   2                              pEnp = (pEPDesc)(DBUF + 9 + 9 + 9 + epLen);             // update pointer to Endpoint(HID)
 726   2                      uDev[usbaddr].bEPAddr[i]        = pEnp->bEPAdd;                 // Ep address and direction
 727   2                      uDev[usbaddr].bAttr[i]          = pEnp->bAttr;                  // Attribute of Endpoint
 728   2                      uDev[usbaddr].wPayLoad[i]       = pEnp->wPayLoad;               // Payload of Endpoint
 729   2                      uDev[usbaddr].bInterval[i]      = pEnp->bInterval;              // Polling interval
 730   2                  uDev[usbaddr].bData1[i] = 0;                                    // init data toggle
 731   2                      epLen += 7;
 732   2              }
 733   1      
 734   1              //------------------------------------------------
 735   1              // Get Hid Report Descriptors
 736   1              //------------------------------------------------
C51 COMPILER V7.50   HOST_811                                                              10/27/2005 20:00:37 PAGE 13  

 737   1              if(pIfc->iClass == HIDCLASS)
 738   1              {       
 739   2                      pHid = (pHidDesc)(DBUF + 9 + 9);                                        // point to HID-CLASS descp
 740   2                      if (!GetHid_Desc(uAddr,HID_REPORT,pHid->wItemLength,DBUF))
 741   2                              return FALSE;
 742   2              }
 743   1      
 744   1              //------------------------------------------------
 745   1              // Get HUB Class Specific Descriptor (per port switching)
 746   1              //------------------------------------------------
 747   1              if(uDev[usbaddr].bClass==HUBCLASS)
 748   1          {                                                                                                           // enumerating a HUB device             
 749   2                      pHub =(pHubDesc)DBUF;                                                           // Ask for 71 bytes ???
 750   2                  if (!GetHubDesc(uAddr,0x00,0x47,DBUF))
 751   2                              return FALSE;                                                                   // Get Hub Desriptor
 752   2                      if (!GetStatus(uAddr,STATUS)) 
 753   2                              return FALSE;                                                                   // Get Status
 754   2                      if (!Set_Configuration(uAddr,DEVICE))
 755   2                              return FALSE;                                                                   // Set configuration
 756   2      
 757   2                      pNumPort = pHub->bNbrPort;                                                      // save no. of ports available
 758   2                      for(i=1; i<=pNumPort; i++)                                                      // ClearPortFeature: C_PORT_CONNECTION off
 759   2                          if(!PortFeature(uAddr,CLEAR_FEATURE, C_PORT_CONNECTION,i))  
 760   2                                      return FALSE;
 761   2      
 762   2                      for(i=1; i<=pNumPort; i++)                                                      // SetPortFeature: PORT_POWER on
 763   2                      {
 764   3                          if(!PortFeature(uAddr,SET_FEATURE, PORT_POWER, i))  
 765   3                                      return FALSE;                                                           
 766   3                      }
 767   2      
 768   2                      for(i=1; i<=pHub->bNbrPort; i++)                                        // GetPortStatus(wHubStatus,wHubChange)
 769   2                         if( !GetPortStatus(uAddr,i,STATUS) )                         //
 770   2                                      return FALSE;                                                           //
 771   2      
 772   2                      for(i=2;i<=pNumPort+1;i++)                                                      // clear port present status
 773   2                      {                                                                                                       // address #2..#5 only
 774   3                              uHub.bPortPresent[i] = 0;                                               // clear status
 775   3                              uHub.bPortNumber[i] = 0;                                                //
 776   3                      }
 777   2                      HUB_DEVICE = TRUE;                                                                      // Set Hub flag, as long as a hub is attached 
 778   2              }                                                                                                               // directly to the HUB_DEVICE will be set
 779   1      
 780   1              return TRUE;
 781   1      }
 782          
 783          //*****************************************************************************************
 784          // Full-speed and low-speed detect - Device atttached directly to SL811HS
 785          //*****************************************************************************************
 786          int speed_detect() 
 787          {
 788   1              pNumPort        = 0;                                    // zero no. of downstream ports
 789   1              SLAVE_FOUND     = FALSE;                                // Clear USB device found flag
 790   1              FULL_SPEED  = TRUE;                                     // Assume full speed device
 791   1              HUB_DEVICE  = FALSE;                            // not HUB device
 792   1              DATA_STOP       = FALSE;                                //
 793   1       
 794   1              SL811Write(cSOFcnt,0xAE);               // Set SOF high counter, no change D+/D-, host mode
 795   1              SL811Write(CtrlReg,0x08);               // Reset USB engine, full-speed setup, suspend disable
 796   1              EZUSB_Delay(10);                                        // Delay for HW stablize
 797   1              SL811Write(CtrlReg,0x00);               // Set to normal operation
 798   1              SL811Write(IntEna,0x61);                // USB-A, Insert/Remove, USB_Resume.
C51 COMPILER V7.50   HOST_811                                                              10/27/2005 20:00:37 PAGE 14  

 799   1              SL811Write(IntStatus,INT_CLEAR);        // Clear Interrupt enable status
 800   1              EZUSB_Delay(10);                                        // Delay for HW stablize
 801   1      
 802   1              if(SL811Read(IntStatus)&USB_RESET)
 803   1              {                                                                       // test for USB reset
 804   2                      SL811Write(IntStatus,INT_CLEAR);// Clear In

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -