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

📄 fw.lst

📁 实现ez-usb fx2的 自定义请求功能
💻 LST
📖 第 1 页 / 共 2 页
字号:
 194   1      
 195   1         CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)
 196   1      
 197   1         // clear the Sleep flag.
 198   1         Sleep = FALSE;
 199   1         memset(DispBuf,16,4);//无显示数据
 200   1         // Task Dispatcher
 201   1         while(TRUE)               // Main Loop
 202   1         {
 203   2            if(GotSUD)            // Wait for SUDAV
 204   2            {
 205   3               SetupCommand();          // Implement setup command
 206   3                 GotSUD = FALSE;            // Clear SUDAV flag
 207   3            }
 208   2      
 209   2            // Poll User Device
 210   2            // NOTE: Idle mode stops the processor clock.  There are only two
 211   2            // ways out of idle mode, the WAKEUP pin, and detection of the USB
 212   2            // resume state on the USB bus.  The timers will stop and the
 213   2            // processor will not wake up on any other interrupts.
 214   2            if (Sleep)
 215   2                {
 216   3                if(TD_Suspend())
 217   3                    { 
 218   4                    Sleep = FALSE;            // Clear the "go to sleep" flag.  Do it here to prevent any race c
             -ondition between wakeup and the next sleep.
 219   4                    do
 220   4                        {
 221   5                          EZUSB_Susp();         // Place processor in idle mode.
 222   5                        }
 223   4                      while(!Rwuen && EZUSB_EXTWAKEUP());
 224   4                      // Must continue to go back into suspend if the host has disabled remote wakeup
 225   4                      // *and* the wakeup was caused by the external wakeup pin.
 226   4                      
 227   4                   // 8051 activity will resume here due to USB bus or Wakeup# pin activity.
 228   4                   EZUSB_Resume();   // If source is the Wakeup# pin, signal the host to Resume.      
 229   4                   TD_Resume();
 230   4                    }   
 231   3                }
 232   2            TD_Poll();
 233   2                Led_Display();
 234   2                temp_data = OKey_RP_Scan();
 235   2                if(temp_data != 0xFF)
 236   2                {
 237   3                      OKey_Value = temp_data;
 238   3                }
 239   2         }
 240   1      }
C51 COMPILER V7.02b   FW                                                                   06/30/2004 15:13:17 PAGE 5   

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

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

 365   2                  EZUSB_STALL_EP0();            // Stall End Point 0
 366   2         }
 367   1      
 368   1         // Acknowledge handshake phase of device request
 369   1         EP0CS |= bmHSNAK;
 370   1      }
 371          
 372          // Wake-up interrupt handler
 373          void resume_isr(void) interrupt WKUP_VECT
 374          {
 375   1         EZUSB_CLEAR_RSMIRQ();
 376   1      }
 377          
 378          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1027    ----
   CONSTANT SIZE    =     10    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     14      17
   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 + -