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

📄 f34x_usb_isr.lst

📁 支持USB2.0 BULK传输范例
💻 LST
📖 第 1 页 / 共 3 页
字号:
 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 V8.08   F34X_USB_ISR                                                          06/23/2008 15:53:52 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 V8.08   F34X_USB_ISR                                                          06/23/2008 15:53:52 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 V8.08   F34X_USB_ISR                                                          06/23/2008 15:53:52 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               // Read updated status register
 465   3               //UWRITE_BYTE(INDEX, pEpOutStatus->bEp); // Index to current endpoint
 466   3               //UREAD_BYTE(EOUTCSRL, bCsrL);
 467   3            }
 468   2         }
 469   1      }
 470          
 471          //-----------------------------------------------------------------------------
 472          // BulkOrInterruptIn
 473          //-----------------------------------------------------------------------------
 474          //
 475          // Return Value : None
 476          // Parameters   :
 477          // 1) PEP_STATUS pEpOutStatus
 478          // 2) BYTE * DataToWrite
 479          // 3) UINT NumBytes
 480          //
 481          // - Places DataToWrite on the IN FIFO
 482          // - Sets Packet Ready Bit
 483          //-----------------------------------------------------------------------------
 484          void BulkOrInterruptIn (PEP_STATUS pEpInStatus, BYTE * DataToWrite,
 485                                  UINT NumBytes)
 486          {
 487   1         BYTE bCsrL, bCsrH;
 488   1      
 489   1         UWRITE_BYTE(INDEX, pEpInStatus->bEp);  // Index to current endpoint
C51 COMPILER V8.08   F34X_USB_ISR                                                          06/23/2008 15:53:52 PAGE 9   

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

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

⌨️ 快捷键说明

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