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

📄 fw.lst

📁 FPGA与USB通信的测试代码
💻 LST
📖 第 1 页 / 共 2 页
字号:
 190   1         // is not necessary but doesn't hurt anything
 191   1         USBCS &=~bmDISCON;
 192   1      
 193   1         CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)
 194   1      
 195   1         // clear the Sleep flag.
 196   1         Sleep = FALSE;
 197   1      
 198   1         // Task Dispatcher
 199   1         while(TRUE)               // Main Loop
 200   1         {
 201   2            if(GotSUD)            // Wait for SUDAV
 202   2            {
 203   3               SetupCommand();          // Implement setup command
 204   3                 GotSUD = FALSE;            // Clear SUDAV flag
 205   3            }
 206   2      
 207   2            // Poll User Device
 208   2            // NOTE: Idle mode stops the processor clock.  There are only two
 209   2            // ways out of idle mode, the WAKEUP pin, and detection of the USB
 210   2            // resume state on the USB bus.  The timers will stop and the
 211   2            // processor will not wake up on any other interrupts.
 212   2            if (Sleep)
 213   2                {
 214   3                if(TD_Suspend())
 215   3                    { 
 216   4                    Sleep = FALSE;            // Clear the "go to sleep" flag.  Do it here to prevent any race c
             -ondition between wakeup and the next sleep.
 217   4                    do
 218   4                        {
 219   5                          EZUSB_Susp();         // Place processor in idle mode.
 220   5                        }
 221   4                      while(!Rwuen && EZUSB_EXTWAKEUP());
 222   4                      // Must continue to go back into suspend if the host has disabled remote wakeup
 223   4                      // *and* the wakeup was caused by the external wakeup pin.
 224   4                      
 225   4                   // 8051 activity will resume here due to USB bus or Wakeup# pin activity.
 226   4                   EZUSB_Resume();   // If source is the Wakeup# pin, signal the host to Resume.      
 227   4                   TD_Resume();
 228   4                    }   
 229   3                }
 230   2            TD_Poll();
 231   2         }
 232   1      }
 233          
 234          // Device request parser
 235          void SetupCommand(void)
 236          {
 237   1         void   *dscr_ptr;
 238   1      
 239   1         switch(SETUPDAT[1])
 240   1         {
C51 COMPILER V7.50   FW                                                                    11/03/2006 09:42:15 PAGE 5   

 241   2            case SC_GET_DESCRIPTOR:                  // *** Get Descriptor
 242   2               if(DR_GetDescriptor())
 243   2                  switch(SETUPDAT[3])         
 244   2                  {
 245   3                     case GD_DEVICE:            // Device
 246   3                        SUDPTRH = MSB(pDeviceDscr);
 247   3                        SUDPTRL = LSB(pDeviceDscr);
 248   3                        break;
 249   3                     case GD_DEVICE_QUALIFIER:            // Device Qualifier
 250   3                        SUDPTRH = MSB(pDeviceQualDscr);
 251   3                        SUDPTRL = LSB(pDeviceQualDscr);
 252   3                        break;
 253   3                     case GD_CONFIGURATION:         // Configuration
 254   3                        SUDPTRH = MSB(pConfigDscr);
 255   3                        SUDPTRL = LSB(pConfigDscr);
 256   3                        break;
 257   3                     case GD_OTHER_SPEED_CONFIGURATION:  // Other Speed Configuration
 258   3                        SUDPTRH = MSB(pOtherConfigDscr);
 259   3                        SUDPTRL = LSB(pOtherConfigDscr);
 260   3                        break;
 261   3                     case GD_STRING:            // String
 262   3                        if(dscr_ptr = (void *)EZUSB_GetStringDscr(SETUPDAT[2]))
 263   3                        {
 264   4                           SUDPTRH = MSB(dscr_ptr);
 265   4                           SUDPTRL = LSB(dscr_ptr);
 266   4                        }
 267   3                        else 
 268   3                           EZUSB_STALL_EP0();   // Stall End Point 0
 269   3                        break;
 270   3                     default:            // Invalid request
 271   3                        EZUSB_STALL_EP0();      // Stall End Point 0
 272   3                  }
 273   2               break;
 274   2            case SC_GET_INTERFACE:                  // *** Get Interface
 275   2               DR_GetInterface();
 276   2               break;
 277   2            case SC_SET_INTERFACE:                  // *** Set Interface
 278   2               DR_SetInterface();
 279   2               break;
 280   2            case SC_SET_CONFIGURATION:               // *** Set Configuration
 281   2               DR_SetConfiguration();
 282   2               break;
 283   2            case SC_GET_CONFIGURATION:               // *** Get Configuration
 284   2               DR_GetConfiguration();
 285   2               break;
 286   2            case SC_GET_STATUS:                  // *** Get Status
 287   2               if(DR_GetStatus())
 288   2                  switch(SETUPDAT[0])
 289   2                  {
 290   3                     case GS_DEVICE:            // Device
 291   3                        EP0BUF[0] = ((BYTE)Rwuen << 1) | (BYTE)Selfpwr;
 292   3                        EP0BUF[1] = 0;
 293   3                        EP0BCH = 0;
 294   3                        EP0BCL = 2;
 295   3                        break;
 296   3                     case GS_INTERFACE:         // Interface
 297   3                        EP0BUF[0] = 0;
 298   3                        EP0BUF[1] = 0;
 299   3                        EP0BCH = 0;
 300   3                        EP0BCL = 2;
 301   3                        break;
 302   3                     case GS_ENDPOINT:         // End Point
C51 COMPILER V7.50   FW                                                                    11/03/2006 09:42:15 PAGE 6   

 303   3                        EP0BUF[0] = *(BYTE xdata *) epcs(SETUPDAT[4]) & bmEPSTALL;
 304   3                        EP0BUF[1] = 0;
 305   3                        EP0BCH = 0;
 306   3                        EP0BCL = 2;
 307   3                        break;
 308   3                     default:            // Invalid Command
 309   3                        EZUSB_STALL_EP0();      // Stall End Point 0
 310   3                  }
 311   2               break;
 312   2            case SC_CLEAR_FEATURE:                  // *** Clear Feature
 313   2               if(DR_ClearFeature())
 314   2                  switch(SETUPDAT[0])
 315   2                  {
 316   3                     case FT_DEVICE:            // Device
 317   3                        if(SETUPDAT[2] == 1)
 318   3                           Rwuen = FALSE;       // Disable Remote Wakeup
 319   3                        else
 320   3                           EZUSB_STALL_EP0();   // Stall End Point 0
 321   3                        break;
 322   3                     case FT_ENDPOINT:         // End Point
 323   3                        if(SETUPDAT[2] == 0)
 324   3                        {
 325   4                           *(BYTE xdata *) epcs(SETUPDAT[4]) &= ~bmEPSTALL;
 326   4                           EZUSB_RESET_DATA_TOGGLE( SETUPDAT[4] );
 327   4                        }
 328   3                        else
 329   3                           EZUSB_STALL_EP0();   // Stall End Point 0
 330   3                        break;
 331   3                  }
 332   2               break;
 333   2            case SC_SET_FEATURE:                  // *** Set Feature
 334   2               if(DR_SetFeature())
 335   2                  switch(SETUPDAT[0])
 336   2                  {
 337   3                     case FT_DEVICE:            // Device
 338   3                        if(SETUPDAT[2] == 1)
 339   3                           Rwuen = TRUE;      // Enable Remote Wakeup
 340   3                        else if(SETUPDAT[2] == 2)
 341   3                           // Set Feature Test Mode.  The core handles this request.  However, it is
 342   3                           // necessary for the firmware to complete the handshake phase of the
 343   3                           // control transfer before the chip will enter test mode.  It is also
 344   3                           // necessary for FX2 to be physically disconnected (D+ and D-)
 345   3                           // from the host before it will enter test mode.
 346   3                           break;
 347   3                        else
 348   3                           EZUSB_STALL_EP0();   // Stall End Point 0
 349   3                        break;
 350   3                     case FT_ENDPOINT:         // End Point
 351   3                        *(BYTE xdata *) epcs(SETUPDAT[4]) |= bmEPSTALL;
 352   3                        break;
 353   3                  }
 354   2               break;
 355   2            default:                     // *** Invalid Command
 356   2               if(DR_VendorCmnd())
 357   2                  EZUSB_STALL_EP0();            // Stall End Point 0
 358   2         }
 359   1      
 360   1         // Acknowledge handshake phase of device request
 361   1         EP0CS |= bmHSNAK;
 362   1      }
 363          
 364          // Wake-up interrupt handler
C51 COMPILER V7.50   FW                                                                    11/03/2006 09:42:15 PAGE 7   

 365          void resume_isr(void) interrupt WKUP_VECT
 366          {
 367   1         EZUSB_CLEAR_RSMIRQ();
 368   1      }
 369          
 370          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    915    ----
   CONSTANT SIZE    =     10    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     14      16
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      4    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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