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

📄 sl811.lst

📁 用SL811USB接口芯片读写U盘FAT16固化程序(C51源代码)
💻 LST
📖 第 1 页 / 共 3 页
字号:
 371   1              return ep0Xfer();
 372   1      
 373   1      }
 374          
 375          //*****************************************************************************************
 376          // Get Device Descriptor : Device, Configuration, String
 377          //*****************************************************************************************
 378          unsigned char GetDesc(void)
 379          { 
 380   1              
 381   1              usbstack.setup.bmRequest=0x80;
 382   1              usbstack.setup.bRequest=GET_DESCRIPTOR;
 383   1              usbstack.setup.wValue=WordSwap(usbstack.setup.wValue);  
 384   1              usbstack.wPayload=uDev.wPayLoad[0];
 385   1              
 386   1              return ep0Xfer();
 387   1      }
 388          
 389          //*****************************************************************************************
 390          // USB Device Enumeration Process
 391          // Support 1 confguration and interface #0 and alternate setting #0 only
 392          // Support up to 1 control endpoint + 4 data endpoint only
 393          //*****************************************************************************************
 394          unsigned char EnumUsbDev(BYTE usbaddr)
 395          {  
 396   1              unsigned char i;                                                                                        // always reset USB transfer address 
 397   1              unsigned char uAddr = 0;                                                        // for enumeration to Address #0
 398   1              unsigned char epLen;
 399   1                      
 400   1              //------------------------------------------------
 401   1              // Reset only Slave device attached directly
 402   1              //------------------------------------------------
 403   1              uDev.wPayLoad[0] = 64;  // default 64-byte payload of Endpoint 0, address #0
 404   1              if(usbaddr == 1)                // bus reset for the device attached to SL811HS only
 405   1                      USBReset();             // that will always have the USB address = 0x01 (for a hub)
 406   1              
 407   1              DelayMs(25);
 408   1              
 409   1              //------------------------------------------------
 410   1              // Get USB Device Descriptors on EP0 & Addr 0
 411   1              // with default 64-byte payload
 412   1              //------------------------------------------------
 413   1                      
 414   1              usbstack.usbaddr=uAddr;
 415   1              usbstack.setup.wValue=DEVICE;
 416   1              usbstack.setup.wIndex=0;
 417   1              usbstack.setup.wLength=18;
 418   1              usbstack.buffer=DBUF;
 419   1              
 420   1              if (!GetDesc())                 // and determine the wPayload size
 421   1                      return FALSE;                                                           // get correct wPayload of Endpoint 0
 422   1              uDev.wPayLoad[0]=DBUF[7];       // on current non-zero USB address
 423   1              //------------------------------------------------
 424   1              // Set Slave USB Device Address
 425   1              //------------------------------------------------
 426   1              if (!SetAddress(usbaddr))                                               // set to specific USB address
C51 COMPILER V7.06   SL811                                                                 09/18/2004 01:20:11 PAGE 8   

 427   1                      return FALSE;                                                           //
 428   1              uAddr = usbaddr;                                                                // transfer using this new address
 429   1      
 430   1              //------------------------------------------------
 431   1              // Get USB Device Descriptors on EP0 & Addr X
 432   1              //------------------------------------------------
 433   1              
 434   1      
 435   1              usbstack.usbaddr=uAddr; 
 436   1              usbstack.setup.wLength=DBUF[0]; 
 437   1              usbstack.setup.wValue=DEVICE;
 438   1              usbstack.setup.wIndex=0;        
 439   1              usbstack.buffer=DBUF;   
 440   1              if (!GetDesc())         
 441   1                      return FALSE;                                                           // For this current device:
 442   1              uDev.iMfg  = DBUF[14];  
 443   1              uDev.iPdt  = DBUF[15];
 444   1      
 445   1              //------------------------------------------------
 446   1              // Get Slave USB Configuration Descriptors
 447   1              //------------------------------------------------
 448   1              
 449   1              usbstack.usbaddr=uAddr;
 450   1              usbstack.setup.wValue=CONFIGURATION;
 451   1              usbstack.setup.wIndex=0;
 452   1              usbstack.setup.wLength=64;
 453   1              usbstack.buffer=DBUF;   
 454   1              if (!GetDesc())                 
 455   1                      return FALSE;   
 456   1      
 457   1              uDev.bClass     = DBUF[9+5];    // update to class type
 458   1              uDev.bNumOfEPs = (DBUF[9+4] <= MAX_EP) ? DBUF[9+4] : MAX_EP;
 459   1              if(uDev.bClass==8) //mass storage device
 460   1                      bFlags.bits.bMassDevice=TRUE;
 461   1              //------------------------------------------------
 462   1              // Set configuration (except for HUB device)
 463   1              //------------------------------------------------
 464   1              usbstack.usbaddr=uAddr;
 465   1              usbstack.setup.wValue=DEVICE;
 466   1                                              // enumerating a FS/LS non-hub device
 467   1                      if (!Set_Configuration())               // connected directly to SL811HS
 468   1                                      return FALSE;
 469   1      
 470   1              //------------------------------------------------
 471   1              // For each slave endpoints, get its attributes
 472   1              // Excluding endpoint0, only data endpoints
 473   1              //------------------------------------------------
 474   1              
 475   1              epLen = 0;
 476   1              for (i=1; i<=uDev.bNumOfEPs; i++)                               // For each data endpoint
 477   1              {
 478   2                      uDev.bEPAddr[i]         = DBUF[9 + 9 + epLen+2];        // Ep address and direction                             
 479   2                      uDev.bAttr[i]           = DBUF[9 + 9 + epLen+3];        // Attribute of Endpoint                        
 480   2                      uDev.wPayLoad[i]        = LSwapINT16(DBUF[9 + 9 + epLen+4],DBUF[9 + 9 + epLen+5]);      // Payload of Endpoint
 481   2                      uDev.bInterval[i]       = DBUF[9 + 9 + epLen+6];        // Polling interval
 482   2                  uDev.bData1[i] = 0;                             // init data toggle
 483   2                      epLen += 7;
 484   2                      //////////////////////////////
 485   2                      if(uDev.bAttr[i]==0x2)     //bulk transfer
 486   2                      {
 487   3                          if(uDev.bEPAddr[i]&0x80)
 488   3                              usbstack.epbulkin=uDev.bEPAddr[i];
C51 COMPILER V7.06   SL811                                                                 09/18/2004 01:20:11 PAGE 9   

 489   3                          else
 490   3                              usbstack.epbulkout=uDev.bEPAddr[i];
 491   3                      }
 492   2                      //////////////////////////////
 493   2              }
 494   1              
 495   1              return TRUE;
 496   1      }
 497          
 498          ///////////////////////////////////////////////////////////////////////////////////////////
 499          void SL811_Init(void)
 500          {       
 501   1              bFlags.bits.SLAVE_ONLINE = FALSE;
 502   1              bFlags.bits.SLAVE_FOUND = FALSE;
 503   1              bFlags.bits.SLAVE_REMOVED=FALSE;
 504   1              
 505   1              bFlags.bits.SLAVE_ENUMERATED = FALSE;
 506   1              bFlags.bits.SLAVE_IS_ATTACHED = FALSE;
 507   1              ///////////////////////////////////////////////////////
 508   1              SL811Write(CtrlReg,0x04);
 509   1              DelayMs(100);
 510   1              SL811Write(CtrlReg,0x01);
 511   1              
 512   1              SL811Write(cDATASet,0xe0);
 513   1              SL811Write(cSOFcnt,0xae);
 514   1                              
 515   1              SL811Write(EP0Status,0x50);
 516   1              SL811Write(EP0Counter,0);
 517   1              SL811Write(EP0Control,0x01);
 518   1                      
 519   1              SL811Write(IntEna,0x20);                // USB-A, Insert/Remove, USB_Resume.
 520   1              
 521   1              SL811Write(IntStatus,INT_CLEAR);        // Clear Interrupt enable status
 522   1      }
 523          
 524          void check_key_LED(void)
 525          {
 526   1              unsigned char xdata intr;
 527   1              
 528   1              intr=SL811Read(IntStatus);
 529   1              if(intr & 0x40)
 530   1                         {
 531   2                                      
 532   2                         if(bFlags.bits.SLAVE_ONLINE ==TRUE)
 533   2                              {bFlags.bits.SLAVE_REMOVED=TRUE;
 534   3                              bFlags.bits.SLAVE_ONLINE =FALSE;}
 535   2                         }
 536   1              else    {
 537   2                                      
 538   2                        if(bFlags.bits.SLAVE_ONLINE == FALSE)
 539   2                              {bFlags.bits.SLAVE_FOUND=TRUE;
 540   3                              bFlags.bits.SLAVE_ONLINE =TRUE;}
 541   2                         }    
 542   1              SL811Write(IntStatus,INT_CLEAR);
 543   1              SL811Write(IntStatus,INSERT_REMOVE);
 544   1                      
 545   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1478    ----
   CONSTANT SIZE    =   ----    ----
C51 COMPILER V7.06   SL811                                                                 09/18/2004 01:20:11 PAGE 10  

   XDATA SIZE       =   8237       1
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     19      26
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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