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

📄 f32x_usb_isr.lst

📁 C8051F320 SOURCE CODE 内容有: * USB Bulk Driver Example * USB Bulk Firmware Example * Host Ap
💻 LST
📖 第 1 页 / 共 3 页
字号:
 281   1         // Handle incoming packet
 282   1         if (bCsr1 & rbOPRDY)
 283   1         {
 284   2            // Read the 8-byte command from Endpoint0 FIFO
 285   2            FIFORead(0, 8, (BYTE*)&gEp0Command);
 286   2      
 287   2            // Byte-swap the wIndex field
 288   2            bTemp = gEp0Command.wIndex.c[1];
 289   2            gEp0Command.wIndex.c[1] = gEp0Command.wIndex.c[0];
 290   2            gEp0Command.wIndex.c[0] = bTemp;
 291   2      
 292   2            // Byte-swap the wValue field
 293   2            bTemp = gEp0Command.wValue.c[1];
 294   2            gEp0Command.wValue.c[1] = gEp0Command.wValue.c[0];
 295   2            gEp0Command.wValue.c[0] = bTemp;
 296   2      
 297   2            // Byte-swap the wLength field
 298   2            bTemp = gEp0Command.wLength.c[1];
 299   2            gEp0Command.wLength.c[1] = gEp0Command.wLength.c[0];
 300   2            gEp0Command.wLength.c[0] = bTemp;
 301   2      
 302   2            // Decode received command
 303   2            switch (gEp0Command.bmRequestType & CMD_MASK_COMMON)
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 6   

 304   2            {
 305   3               case  CMD_STD_DEV_OUT:           // Standard device requests
 306   3                  // Decode standard OUT request
 307   3                  switch (gEp0Command.bRequest)
 308   3                  {
 309   4                     case SET_ADDRESS:
 310   4                        SetAddressRequest();
 311   4                        break;
 312   4                     case SET_FEATURE:
 313   4                        SetFeatureRequest();
 314   4                        break;
 315   4                     case CLEAR_FEATURE:
 316   4                        ClearFeatureRequest();
 317   4                        break;
 318   4                     case SET_CONFIGURATION:
 319   4                        SetConfigurationRequest();
 320   4                        break;
 321   4                     case SET_INTERFACE:
 322   4                        SetInterfaceRequest();
 323   4                        break;
 324   4                     // All other OUT requests not supported
 325   4                     case SET_DESCRIPTOR:
 326   4                     default:
 327   4                        gEp0Status.bEpState = EP_ERROR;
 328   4                        break;
 329   4                  }
 330   3                  break;
 331   3      
 332   3               // Decode standard IN request
 333   3               case CMD_STD_DEV_IN:
 334   3                  switch (gEp0Command.bRequest)
 335   3                  {
 336   4                     case GET_STATUS:
 337   4                        GetStatusRequest();
 338   4                        break;
 339   4                     case GET_DESCRIPTOR:
 340   4                        GetDescriptorRequest();
 341   4                        break;
 342   4                     case GET_CONFIGURATION:
 343   4                        GetConfigurationRequest();
 344   4                        break;
 345   4                     case GET_INTERFACE:
 346   4                        GetInterfaceRequest();
 347   4                        break;
 348   4                     // All other IN requests not supported
 349   4                     case SYNCH_FRAME:
 350   4                     default:
 351   4                        gEp0Status.bEpState = EP_ERROR;
 352   4                        break;
 353   4                  }
 354   3                  break;
 355   3               // All other requests not supported
 356   3               default:
 357   3                  gEp0Status.bEpState = EP_ERROR;
 358   3            }
 359   2      
 360   2            // Write E0CSR according to the result of the serviced out packet
 361   2            bTemp = rbSOPRDY;
 362   2            if (gEp0Status.bEpState == EP_ERROR)
 363   2            {
 364   3               bTemp |= rbSDSTL;                // Error condition handled
 365   3                                                // with STALL
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 7   

 366   3               gEp0Status.bEpState = EP_IDLE;   // Reset state to idle
 367   3            }
 368   2      
 369   2            UWRITE_BYTE(E0CSR, bTemp);
 370   2         }
 371   1      
 372   1         bTemp = 0;                             // Reset temporary variable
 373   1      
 374   1         // If state is transmit, call transmit routine
 375   1         if (gEp0Status.bEpState == EP_TX)
 376   1         {
 377   2            // Check the number of bytes ready for transmit
 378   2            // If less than the maximum packet size, packet will
 379   2            // not be of the maximum size
 380   2            if (gEp0Status.uNumBytes <= EP0_MAXP)
 381   2            {
 382   3               uTxBytes = gEp0Status.uNumBytes;
 383   3               gEp0Status.uNumBytes = 0;        // update byte counter
 384   3               bTemp |= rbDATAEND;              // This will be the last
 385   3                                                // packet for this transfer
 386   3               gEp0Status.bEpState = EP_IDLE;   // Reset endpoint state
 387   3            }
 388   2      
 389   2            // Otherwise, transmit maximum-length packet
 390   2            else
 391   2            {
 392   3               uTxBytes = EP0_MAXP;
 393   3               gEp0Status.uNumBytes -= EP0_MAXP;// update byte counter
 394   3            }
 395   2      
 396   2            // Load FIFO
 397   2            FIFOWrite(0, uTxBytes, (BYTE*)gEp0Status.pData);
 398   2      
 399   2            // Update data pointer
 400   2            gEp0Status.pData = (BYTE*)gEp0Status.pData + uTxBytes;
 401   2      
 402   2            // Update Endpoint0 Control/Status register
 403   2            bTemp |= rbINPRDY;                  // Always transmit a packet
 404   2                                                // when this routine is called
 405   2                                                // (may be zero-length)
 406   2      
 407   2            UWRITE_BYTE(E0CSR, bTemp);          // Write to Endpoint0 Control/Status
 408   2         }
 409   1      
 410   1      }
 411          
 412          //-----------------------------------------------------------------------------
 413          // BulkOrInterruptOut
 414          //-----------------------------------------------------------------------------
 415          //
 416          // Return Value : None
 417          // Parameters   :
 418          // 1) PEP_STATUS pEpOutStatus
 419          //
 420          //-----------------------------------------------------------------------------
 421          void BulkOrInterruptOut(PEP_STATUS pEpOutStatus)
 422          {
 423   1         UINT uBytes;
 424   1         BYTE bTemp = 0;
 425   1         BYTE bCsrL, bCsrH;
 426   1      
 427   1         UWRITE_BYTE(INDEX, pEpOutStatus->bEp); // Index to current endpoint
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 8   

 428   1         UREAD_BYTE(EOUTCSRL, bCsrL);
 429   1         UREAD_BYTE(EOUTCSRH, bCsrH);
 430   1      
 431   1         // Make sure this endpoint is not halted
 432   1         if (pEpOutStatus->bEpState != EP_HALTED)
 433   1         {
 434   2            // Handle STALL condition sent
 435   2            if (bCsrL & rbOutSTSTL)
 436   2            {
 437   3               // Clear Send Stall, Sent Stall, and data toggle
 438   3               UWRITE_BYTE(EOUTCSRL, rbOutCLRDT);
 439   3            }
 440   2      
 441   2            // Read received packet
 442   2            if(bCsrL & rbOutOPRDY)
 443   2            {
 444   3               // Get packet length
 445   3               UREAD_BYTE(EOUTCNTL, bTemp);     // Low byte
 446   3               uBytes = (UINT)bTemp & 0x00FF;
 447   3      
 448   3               UREAD_BYTE(EOUTCNTH, bTemp);     // High byte
 449   3               uBytes |= (UINT)bTemp << 8;
 450   3      
 451   3               if (M_State == ST_IDLE_DEV) 
 452   3               {
 453   4                  FIFORead(0x02, uBytes, &Buffer);
 454   4               }                       
 455   3               else
 456   3               {
 457   4                  FIFORead(0x02, uBytes, (BYTE*)(&TempStorage[BlockIndex]));
 458   4               }
 459   3      
 460   3               // Clear out-packet-ready
 461   3               UWRITE_BYTE(INDEX, pEpOutStatus->bEp);
 462   3               UWRITE_BYTE(EOUTCSRL, 0);
 463   3      
 464   3            }
 465   2         }
 466   1      }
 467          
 468          //-----------------------------------------------------------------------------
 469          // BulkOrInterruptIn
 470          //-----------------------------------------------------------------------------
 471          //
 472          // Return Value : None
 473          // Parameters   :
 474          // 1) PEP_STATUS pEpOutStatus
 475          // 2) BYTE * DataToWrite
 476          // 3) UINT NumBytes
 477          //
 478          // - Places DataToWrite on the IN FIFO
 479          // - Sets Packet Ready Bit
 480          //-----------------------------------------------------------------------------
 481          void BulkOrInterruptIn (PEP_STATUS pEpInStatus, BYTE * DataToWrite,
 482                                  UINT NumBytes)
 483          {
 484   1         BYTE bCsrL, bCsrH;
 485   1      
 486   1         UWRITE_BYTE(INDEX, pEpInStatus->bEp);  // Index to current endpoint
 487   1         UREAD_BYTE(EINCSRL, bCsrL);
 488   1         UREAD_BYTE(EINCSRH, bCsrH);
 489   1      
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 9   

 490   1         // Make sure this endpoint is not halted
 491   1         if (pEpInStatus->bEpState != EP_HALTED)
 492   1         {
 493   2            // Handle STALL condition sent
 494   2            if (bCsrL & rbInSTSTL)
 495   2            {
 496   3               UWRITE_BYTE(EINCSRL, rbInCLRDT); // Clear Send Stall and Sent Stall,
 497   3                                                // and clear data toggle
 498   3            }
 499   2      
 500   2            // If a FIFO slot is open, write a new packet to the IN FIFO
 501   2            if (!(bCsrL & rbInINPRDY))
 502   2            {
 503   3               pEpInStatus->uNumBytes = NumBytes;
 504   3               pEpInStatus->pData = (BYTE*)DataToWrite;
 505   3      
 506   3               // Write <uNumBytes> bytes to the <bEp> FIFO
 507   3               FIFOWrite(pEpInStatus->bEp, pEpInStatus->uNumBytes,
 508   3                  (BYTE*)pEpInStatus->pData);
 509   3      
 510   3               BytesToWrite -= NumBytes;
 511   3               ReadIndex += NumBytes;
 512   3               BlocksWrote++;
 513   3      
 514   3               // Set Packet Ready bit (INPRDY)
 515   3               UWRITE_BYTE(EINCSRL, rbInINPRDY);
 516   3      
 517   3               // Check updated endopint status
 518   3               //UREAD_BYTE(EINCSRL, bCsrL);
 519   3      
 520   3            }
 521   2         }
 522   1      }
 523          
 524          
 525          //-----------------------------------------------------------------------------
 526          // USBReset
 527          //-----------------------------------------------------------------------------
 528          //
 529          // Return Value : None
 530          // Parameters   : None
 531          //
 532          // - Initialize the global Device Status structure (all zeros)
 533          // - Resets all endpoints
 534          //-----------------------------------------------------------------------------
 535          void USBReset ()
 536          {
 537   1         BYTE i, bPower = 0;
 538   1         BYTE * pDevStatus;
 539   1      
 540   1        // Reset device status structure to all zeros (undefined)
 541   1         pDevStatus = (BYTE *)&gDeviceStatus;
 542   1         for (i=0;i<sizeof(DEVICE_STATUS);i++)
 543   1         {
 544   2            *pDevStatus++ = 0x00;
 545   2         }
 546   1      
 547   1         // Set device state to default
 548   1         gDeviceStatus.bDevState = DEV_DEFAULT;
 549   1      
 550   1         // REMOTE_WAKEUP_SUPPORT and SELF_POWERED_SUPPORT
 551   1         // defined in file "usb_desc.h"
C51 COMPILER V7.06   F32X_USB_ISR                                                          07/16/2008 15:35:22 PAGE 10  

 552   1         gDeviceStatus.bRemoteWakeupSupport = REMOTE_WAKEUP_SUPPORT;
 553   1         gDeviceStatus.bSelfPoweredStatus = SELF_POWERED_SUPPORT;
 554   1      
 555   1         // Reset all endpoints
 556   1      
 557   1         // Reset Endpoint0
 558   1         gEp0Status.bEpState = EP_IDLE;         // Reset Endpoint0 state
 559   1         gEp0Status.bEp = 0;                    // Set endpoint number
 560   1         gEp0Status.uMaxP = EP0_MAXP;           // Set maximum packet size
 561   1      
 562   1         // Reset Endpoint1 IN
 563   1         gEp1InStatus.bEpState = EP_HALTED;     // Reset state
 564   1         gEp1InStatus.uNumBytes = 0;            // Reset byte counter
 565   1      
 566   1         // Reset Endpoint2 OUT
 567   1         gEp2OutStatus.bEpState = EP_HALTED;    // Reset state

⌨️ 快捷键说明

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