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

📄 sl811.lst

📁 51单片机读写U盘
💻 LST
📖 第 1 页 / 共 5 页
字号:
 629          void speed_detect(void) 
 630          {
 631                  //pNumPort      = 0;                                    // zero no. of downstream ports
 632                  bXXGFlags.bits.SLAVE_FOUND      = FALSE;                                // Clear USB device found flag
 633                  //bXXGFlags.bits.FULL_SPEED  = TRUE;                                    // Assume full speed device
 634                  //HUB_DEVICE  = FALSE;                          // not HUB device
 635                  bXXGFlags.bits.DATA_STOP        = FALSE;                                //
 636           
 637                  SL811Write(cSOFcnt,0xAE);               // Set SOF high counter, no change D+/D-, host mode
 638                  SL811Write(CtrlReg,0x08);               // Reset USB engine, full-speed setup, suspend disable
 639                  DelayMs(10);                                    // Delay for HW stablize
 640                  SL811Write(CtrlReg,0x00);               // Set to normal operation
 641                  SL811Write(IntEna,0x61);                // USB-A, Insert/Remove, USB_Resume.
 642                  SL811Write(IntStatus,INT_CLEAR);        // Clear Interrupt enable status
 643                  DelayMs(10);                                    // Delay for HW stablize
 644          
 645                  if(SL811Read(IntStatus)&USB_RESET)
 646                  {                                                                       // test for USB reset
 647                          SL811Write(IntStatus,INT_CLEAR);// Clear Interrupt enable status
 648                          DelayMs(30);                            // Blink LED - waiting for slave USB plug-in
 649                          //OUTB ^= ACTIVE_BLINK;                 // Blink Active LED
 650                          //OUTA |= PORTX_LED;                            // clear debug LEDs
 651                          return ;                                                // exit speed_detect()
 652                  }
 653          
 654                  //if((SL811Read(IntStatus)&USB_DPLUS)==0)       // Checking full or low speed   
 655                  //{                                                                     // ** Low Speed is detected ** //
 656                  //      SL811Write(cSOFcnt,0xEE);       // Set up host and low speed direct and SOF cnt
 657                  //      SL811Write(cDATASet,0xE0);              // SOF Counter Low = 0xE0; 1ms interval
 658                  //      SL811Write(CtrlReg,0x21);               // Setup 6MHz and EOP enable         
 659                          //uHub.bPortSpeed[1] = 1;                       // low speed for Device #1
 660                  //      bXXGFlags.bits.FULL_SPEED = FALSE;                              // low speed device flag
 661                  //}
 662                  //else  
 663                  {                                                                       // ** Full Speed is detected ** //
 664                          SL811Write(cSOFcnt,0xAE);       // Set up host & full speed direct and SOF cnt
 665                          SL811Write(cDATASet,0xE0);      // SOF Counter Low = 0xE0; 1ms interval
 666                          SL811Write(CtrlReg,0x05);       // Setup 48MHz and SOF enable
 667                          //uHub.bPortSpeed[1] = 0;                       // full speed for Device #1
 668                  }
 669          
 670                  //OUTB |= ACTIVE_BLINK;                         // clear Active LED
 671                  //bXXGFlags.bits.SLAVE_FOUND = TRUE;                                    // Set USB device found flag
 672                  bXXGFlags.bits.SLAVE_ENUMERATED = FALSE;                        // no slave device enumeration
 673          
 674                  SL811Write(EP0Status,0x50);             // Setup SOF Token, EP0
 675                  SL811Write(EP0Counter,0x00);            // reset to zero count
 676                  SL811Write(EP0Control,0x01);            // start generate SOF or EOP
 677          
 678                  DelayMs(25);                                    // Hub required approx. 24.1mS
 679                  SL811Write(IntStatus,INT_CLEAR);        // Clear Interrupt status
 680                  //return 0;                                             // exit speed_detect();
 681          }
 682          */
 683          //*****************************************************************************************
 684          // Detect USB Device
C51 COMPILER V7.20   SL811                                                                 12/13/2005 15:28:02 PAGE 14  

 685          //*****************************************************************************************
 686          /*
 687          void slave_detect(void)
 688          {
 689                  //int retDataRW = FALSE;
 690                  
 691                  //-------------------------------------------------------------------------
 692                  // Wait for EZUSB enumeration
 693                  //-------------------------------------------------------------------------
 694                  //if(!CONFIG_DONE)                      // start SL811H after EZ-USB is configured
 695                  //      return;
 696          
 697                  //-------------------------------------------------------------------------
 698                  // Wait for SL811HS enumeration
 699                  //-------------------------------------------------------------------------
 700                  if(!bXXGFlags.bits.SLAVE_ENUMERATED)                                    // only if slave is not configured
 701                  {
 702                          speed_detect();                                         // wait for an USB device to be inserted to 
 703                          if(bXXGFlags.bits.SLAVE_FOUND)                                          // the SL811HST host
 704                          {
 705                                  if(EnumUsbDev(1))                               // enumerate USB device, assign USB address = #1
 706                                  {
 707                                          bXXGFlags.bits.SLAVE_ENUMERATED = TRUE; // Set slave USB device enumerated flag
 708                                          //uHub.bPortPresent[1] = 1;     // set device addr #1 present
 709                                          Set_ezDEV(1);                           // inform master of new attach/detach
 710                                  }       
 711                          }
 712                  }
 713          
 714                  //-------------------------------------------------------------------------
 715                  // SL811HS enumerated, proceed accordingly
 716                  //-------------------------------------------------------------------------
 717                  else                                                                    
 718                  {                                                                                                       
 719                          //OUTB &= ~ACTIVE_BLINK;                                // Turn on Active LED, indicate successful slave enum
 720                          if(Slave_Detach())                                      // test for slave device detach ???
 721                                  return;                                         // exit now.
 722                          //----------------------------------------------
 723                          // HUB DEVICE Polling (Addr #1, EndPt #1)               
 724                          //----------------------------------------------
 725                          // Polling of Hub deivce Endpoint #1 for any Port Attachement
 726                          // for onboard HUB device, after enumeration, start to
 727                          // transfer IN token to check for ports attachment
 728                          // wLen = wPayload = 1 byte, always use USB address #1
 729                          // if return is TRUE, a data pkt was ACK, data in HubChange
 730                          // else is a NAK, no data was received 
 731                  } // end of else
 732          
 733                  return ;
 734          }
 735          */
 736          //*****************************************************************************************
 737          // Slave_Detach
 738          //*****************************************************************************************
 739          /*
 740          unsigned char Slave_Detach(void)
 741          {
 742                  if( (SL811Read(IntStatus)&INSERT_REMOVE) || (SL811Read(IntStatus)&USB_RESET) )
 743                  {                                                                                               // Test USB detached?
 744                          bXXGFlags.bits.SLAVE_ENUMERATED = FALSE;                                        // return to un-enumeration
 745                          //uHub.bPortPresent[1] = 0;                                     // Device #1 not present
 746          
C51 COMPILER V7.20   SL811                                                                 12/13/2005 15:28:02 PAGE 15  

 747                          Set_ezDEV(1);                                                           // inform master of slave detach
 748                          SL811Write(IntStatus,INT_CLEAR);                        // clear interrupt status
 749                          return TRUE;                                                            // exit now !!!
 750                  }
 751          
 752                  return FALSE;
 753          }
 754          */
 755          //*****************************************************************************************
 756          // Indicate to EZUSB's endpoint #2 IN of a new device attach/detach
 757          //*****************************************************************************************
 758          /*
 759          void Set_ezDEV(BYTE chg)
 760          {
 761                  //if( (dsPoll) && (!(IN2CS & bmEPBUSY)) )
 762                  //{
 763                  //      IN2BUF[0] = chg;        // Arm endpoint #2, inform EZUSB host of attach/detatch
 764                  //      IN2BC = 1;
 765                  //}
 766          }
 767          */
 768          ///////////////////////////////////////////////////////////////////////////////////////////
 769          void SL811_Init(void)
 770          {       
 771   1              //int i;
 772   1      
 773   1              //for(i=0;i<MAX_DEV;i++)
 774   1              //{
 775   1              //      uHub.bPortPresent[i] = 0;
 776   1              //      uHub.bPortNumber[i] = 0;
 777   1              //}
 778   1      
 779   1              //SL811H_DATA = 0x00;
 780   1              //SL811H_ADDR = 0x00;
 781   1              //pNumPort      = 0x00;                 
 782   1      
 783   1              //bXXGFlags.bits.FULL_SPEED = TRUE;     
 784   1              //HUB_DEVICE = FALSE;
 785   1              bXXGFlags.bits.SLAVE_ONLINE = FALSE;
 786   1              bXXGFlags.bits.SLAVE_FOUND = FALSE;
 787   1              bXXGFlags.bits.SLAVE_REMOVED=FALSE;
 788   1              
 789   1              bXXGFlags.bits.SLAVE_ENUMERATED = FALSE;
 790   1              bXXGFlags.bits.SLAVE_IS_ATTACHED = FALSE;
 791   1              
 792   1              //bXXGFlags.bits.BULK_OUT_DONE = FALSE;
 793   1              //DESC_XFER = FALSE;
 794   1              //DATA_XFER = FALSE;
 795   1              //DATA_XFER_OUT = FALSE;
 796   1              //DATA_INPROCESS = FALSE;
 797   1              //pLS_HUB = FALSE;
 798   1              //IN2BUF[0] = 0;
 799   1      
 800   1              //dsPoll = 1;                               // poll downstream port conections
 801   1      
 802   1              //----------------------------
 803   1              // SL811H + EZUSB I/Os setup
 804   1              //----------------------------
 805   1              //PORTBCFG &= 0xAC;                     // Select i/o function for PB6, PB4, PB1, PB0
 806   1              //OEB      |= 0x43;                     // Set  PB6(Output), PB4(Input), PB1(Output), PB0(Output) 
 807   1              //OUTB     |= 0x43;                     // Default output high
 808   1      
C51 COMPILER V7.20   SL811                                                                 12/13/2005 15:28:02 PAGE 16  

 809   1              //PORTACFG &= 0x0F;                     // Select i/o function for PA7~PA4
 810   1              //OEA      |= 0xF0;                     // Set PA7~PA4(Output)
 811   1              //OUTA     |= 0xF0;                     // Default output high
 812   1      
 813   1              //----------------------------
 814   1              // Debug Monitor I/Os setup
 815   1              //----------------------------
 816   1              //PORTBCFG |= 0x0C;              

⌨️ 快捷键说明

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