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

📄 sl811.lst

📁 本程序是基于单片机C8051F020上使用SL811 USB 总线接口实现检测U 盘的功能。插上U 盘
💻 LST
📖 第 1 页 / 共 5 页
字号:
 569   1                                                              // get iManufacturer String descriptors
 570   1              if (!GetDesc())                 
 571   1                      return FALSE;                   
 572   1              */
 573   1              //------------------------------------------------
 574   1              // Get Slave USB Configuration Descriptors
 575   1              //------------------------------------------------
 576   1              
 577   1              pCfg = (pCfgDesc)DBUF;  
 578   1              
 579   1              usbstack.usbaddr=uAddr;
 580   1              usbstack.setup.wValue=CONFIGURATION;
 581   1              usbstack.setup.wIndex=0;
 582   1              usbstack.setup.wLength=64;
 583   1              usbstack.buffer=DBUF;   
 584   1              if (!GetDesc())                 
 585   1                      return FALSE;   
 586   1              /*      
 587   1              usbstack.usbaddr=uAddr;
 588   1              usbstack.setup.wValue=CONFIGURATION;
 589   1              usbstack.setup.wIndex=0;
 590   1              usbstack.setup.wLength=WordSwap(pCfg->wLength);
 591   1              
 592   1              usbstack.buffer=DBUF;   
 593   1              if (!GetDesc())         
 594   1                      return FALSE;           
 595   1              */
 596   1              
 597   1              pIfc = (pIntfDesc)(DBUF + 9);                                   // point to Interface Descp
 598   1              uDev.bClass     = pIfc->iClass;                 // update to class type
 599   1              uDev.bNumOfEPs = (pIfc->bEndPoints <= MAX_EP) ? pIfc->bEndPoints : MAX_EP;
 600   1              
 601   1              if(uDev.bClass==8) //mass storage device
 602   1                      bXXGFlags.bits.bMassDevice=TRUE;
 603   1              //------------------------------------------------
 604   1              // Set configuration (except for HUB device)
 605   1              //------------------------------------------------
 606   1              usbstack.usbaddr=uAddr;
 607   1              usbstack.setup.wValue=DEVICE;
 608   1              //if (uDev[usbaddr].bClass!=HUBCLASS)                           // enumerating a FS/LS non-hub device
 609   1                      if (!Set_Configuration())               // connected directly to SL811HS
 610   1                                      return FALSE;
 611   1      
C51 COMPILER V7.06   SL811                                                                 04/30/2005 15:12:27 PAGE 11  

 612   1              //------------------------------------------------
 613   1              // For each slave endpoints, get its attributes
 614   1              // Excluding endpoint0, only data endpoints
 615   1              //------------------------------------------------
 616   1              
 617   1              epLen = 0;
 618   1              for (i=1; i<=uDev.bNumOfEPs; i++)                               // For each data endpoint
 619   1              {
 620   2                      pEnp = (pEPDesc)(DBUF + 9 + 9 + epLen);                         // point to Endpoint Descp(non-HID)
 621   2                      //if(pIfc->iClass == HIDCLASS)  
 622   2                      //      pEnp = (pEPDesc)(DBUF + 9 + 9 + 9 + epLen);             // update pointer to Endpoint(HID)
 623   2                      uDev.bEPAddr[i]         = pEnp->bEPAdd;                 // Ep address and direction
 624   2                      uDev.bAttr[i]           = pEnp->bAttr;                  // Attribute of Endpoint
 625   2                      uDev.wPayLoad[i]        = WordSwap(pEnp->wPayLoad);             // Payload of Endpoint
 626   2                      uDev.bInterval[i]       = pEnp->bInterval;              // Polling interval
 627   2                      uDev.bData1[i] = 0;                                 // init data toggle
 628   2                      epLen += 7;
 629   2                      //////////////////////////////
 630   2                      if(uDev.bAttr[i]==0x2)
 631   2                      {
 632   3                          if(uDev.bEPAddr[i]&0x80)
 633   3                              usbstack.epbulkin=uDev.bEPAddr[i];
 634   3                          else
 635   3                              usbstack.epbulkout=uDev.bEPAddr[i];
 636   3                      }
 637   2                      //////////////////////////////
 638   2              }
 639   1              
 640   1              return TRUE;
 641   1      }
 642          
 643          //*****************************************************************************************
 644          // Full-speed and low-speed detect - Device atttached directly to SL811HS
 645          //*****************************************************************************************
 646          
 647          void speed_detect(void) 
 648          {
 649   1              
 650   1       
 651   1              SL811Write(cSOFcnt,0xAE);               // Set SOF high counter, no change D+/D-, host mode
 652   1              SL811Write(CtrlReg,0x08);               // Reset USB engine, full-speed setup, suspend disable
 653   1              Delay_ms(10);                                   // Delay for HW stablize
 654   1              SL811Write(CtrlReg,0x00);               // Set to normal operation
 655   1              SL811Write(IntEna,0x61);                // USB-A, Insert/Remove, USB_Resume.
 656   1              SL811Write(IntStatus,INT_CLEAR);        // Clear Interrupt enable status
 657   1              Delay_ms(10);                                   // Delay for HW stablize
 658   1      
 659   1              if(SL811Read(IntStatus)&USB_RESET)
 660   1              {                                                                       // test for USB reset
 661   2                      SL811Write(IntStatus,INT_CLEAR);// Clear Interrupt enable status
 662   2                      DelayMs(30);                            // Blink LED - waiting for slave USB plug-in
 663   2                      //OUTB ^= ACTIVE_BLINK;                 // Blink Active LED
 664   2                      //OUTA |= PORTX_LED;                            // clear debug LEDs
 665   2                      return ;                                                // exit speed_detect()
 666   2              }
 667   1      
 668   1              //if((SL811Read(IntStatus)&USB_DPLUS)==0)       // Checking full or low speed   
 669   1              //{                                                                     // ** Low Speed is detected ** //
 670   1              //      SL811Write(cSOFcnt,0xEE);       // Set up host and low speed direct and SOF cnt
 671   1              //      SL811Write(cDATASet,0xE0);              // SOF Counter Low = 0xE0; 1ms interval
 672   1              //      SL811Write(CtrlReg,0x21);               // Setup 6MHz and EOP enable         
 673   1                      //uHub.bPortSpeed[1] = 1;                       // low speed for Device #1
C51 COMPILER V7.06   SL811                                                                 04/30/2005 15:12:27 PAGE 12  

 674   1              //      bXXGFlags.bits.FULL_SPEED = FALSE;                              // low speed device flag
 675   1              //}
 676   1              //else  
 677   1              {                                                                       // ** Full Speed is detected ** //
 678   2                      SL811Write(cSOFcnt,0xAE);       // Set up host & full speed direct and SOF cnt
 679   2                      SL811Write(cDATASet,0xE0);      // SOF Counter Low = 0xE0; 1ms interval
 680   2                      SL811Write(CtrlReg,0x05);       // Setup 48MHz and SOF enable
 681   2                      //uHub.bPortSpeed[1] = 0;                       // full speed for Device #1
 682   2              }
 683   1      
 684   1              SL811Write(EP0Status,0x50);             // Setup SOF Token, EP0
 685   1              SL811Write(EP0Counter,0x00);            // reset to zero count
 686   1              SL811Write(EP0Control,0x01);            // start generate SOF or EOP
 687   1      
 688   1              Delay_ms(25);                                   // Hub required approx. 24.1mS
 689   1              SL811Write(IntStatus,INT_CLEAR);        // Clear Interrupt status
 690   1              //return 0;                                             // exit speed_detect();
 691   1      }
 692          
 693          //*****************************************************************************************
 694          // Detect USB Device
 695          //*****************************************************************************************
 696          /*
 697          void slave_detect(void)
 698          {
 699                  //int retDataRW = FALSE;
 700                  
 701                  //-------------------------------------------------------------------------
 702                  // Wait for EZUSB enumeration
 703                  //-------------------------------------------------------------------------
 704                  //if(!CONFIG_DONE)                      // start SL811H after EZ-USB is configured
 705                  //      return;
 706          
 707                  //-------------------------------------------------------------------------
 708                  // Wait for SL811HS enumeration
 709                  //-------------------------------------------------------------------------
 710                  if(!bXXGFlags.bits.SLAVE_ENUMERATED)                                    // only if slave is not configured
 711                  {
 712                          speed_detect();                                         // wait for an USB device to be inserted to 
 713                          if(bXXGFlags.bits.SLAVE_FOUND)                                          // the SL811HST host
 714                          {
 715                                  if(EnumUsbDev(1))                               // enumerate USB device, assign USB address = #1
 716                                  {
 717                                          bXXGFlags.bits.SLAVE_ENUMERATED = TRUE; // Set slave USB device enumerated flag
 718                                          //uHub.bPortPresent[1] = 1;     // set device addr #1 present
 719                                          Set_ezDEV(1);                           // inform master of new attach/detach
 720                                  }       
 721                          }
 722                  }
 723          
 724                  //-------------------------------------------------------------------------
 725                  // SL811HS enumerated, proceed accordingly
 726                  //-------------------------------------------------------------------------
 727                  else                                                                    
 728                  {                                                                                                       
 729                          //OUTB &= ~ACTIVE_BLINK;                                // Turn on Active LED, indicate successful slave enum
 730                          if(Slave_Detach())                                      // test for slave device detach ???
 731                                  return;                                         // exit now.
 732                          //----------------------------------------------
 733                          // HUB DEVICE Polling (Addr #1, EndPt #1)               
 734                          //----------------------------------------------
 735                          // Polling of Hub deivce Endpoint #1 for any Port Attachement
C51 COMPILER V7.06   SL811                                                                 04/30/2005 15:12:27 PAGE 13  

 736                          // for onboard HUB device, after enumeration, start to
 737                          // transfer IN token to check for ports attachment
 738                          // wLen = wPayload = 1 byte, always use USB address #1
 739                          // if return is TRUE, a data pkt was ACK, data in HubChange
 740                          // else is a NAK, no data was received 
 741                  } // end of else
 742          
 743                  return ;
 744          }
 745          */
 746          //*****************************************************************************************
 747          // Slave_Detach
 748          //*****************************************************************************************
 749          /*
 750          unsigned char Slave_Detach(void)
 751          {
 752                  if( (SL811Read(IntStatus)&INSERT_REMOVE) || (SL811Read(IntStatus)&USB_RESET) )
 753                  {                                                                                               // Test USB detached?
 754                          bXXGFlags.bits.SLAVE_ENUMERATED = FALSE;                                        // return to un-enumeration
 755                          //uHub.bPortPresent[1] = 0;                                     // Device #1 not present
 756          
 757                          Set_ezDEV(1);                                                           // inform master of slave detach
 758                          SL811Write(IntStatus,INT_CLEAR);                        // clear interrupt status
 759                          return TRUE;                                                            // exit now !!!
 760                  }
 761          

⌨️ 快捷键说明

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