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

📄 f3xx_usb0_interruptserviceroutine.lst

📁 hid to rs232 usb_hid 转 串口程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
 434   2            // In systems with Report Descriptors that do not define report IDs,
 435   2            // the host will still format OUT packets with a prefix byte
 436   2            // of '0x00'.
 437   2      
 438   2            ReportHandler_OUT (OUT_BUFFER.Ptr[0]);
 439   2      
 440   2            if (UART_OUTPUT_SIZE < UART_OUTPUT_OVERFLOW_BOUNDARY)
 441   2            {
 442   3               POLL_WRITE_BYTE (EOUTCSR1, 0);   // Clear Out Packet ready bit
 443   3            }
 444   2            else
 445   2            {
 446   3               USB_OUT_SUSPENDED = 1;
 447   3            }
 448   2         }
 449   1      }
 450          
 451          //-----------------------------------------------------------------------------
 452          // Usb_Suspend
 453          //-----------------------------------------------------------------------------
 454          // Enter suspend mode after suspend signalling is present on the bus
 455          //
 456          void Usb_Suspend (void)
 457          {
 458   1         volatile int k;
 459   1         k++;
 460   1      }
 461          
 462          //-----------------------------------------------------------------------------
 463          // Fifo_Read
 464          //-----------------------------------------------------------------------------
 465          //
 466          // Return Value : None
 467          // Parameters   :
 468          //                1) BYTE addr : target address
 469          //                2) unsigned int uNumBytes : number of bytes to unload
 470          //                3) BYTE * pData : read data destination
 471          //
 472          // Read from the selected endpoint FIFO
 473          //
 474          //-----------------------------------------------------------------------------
 475          void Fifo_Read (unsigned char addr, unsigned int uNumBytes,
 476                         unsigned char * pData)
 477          {
 478   1         int i;
 479   1      
 480   1         if (uNumBytes)                      // Check if >0 bytes requested,
 481   1         {
 482   2            USB0ADR = (addr);                // Set address
 483   2            USB0ADR |= 0xC0;                 // Set auto-read and initiate
 484   2                                             // first read
 485   2      
 486   2            // Unload <NumBytes> from the selected FIFO
 487   2            for(i=0;i< (uNumBytes);i++)
 488   2            {
 489   3               while (USB0ADR & 0x80);       // Wait for BUSY->'0' (data ready)
C51 COMPILER V8.17   F3XX_USB0_INTERRUPTSERVICEROUTINE                                     03/18/2009 09:55:18 PAGE 9   

 490   3               pData[i] = USB0DAT;           // Copy data byte
 491   3            }
 492   2      
 493   2            //while(USB0ADR & 0x80);         // Wait for BUSY->'0' (data ready)
 494   2            USB0ADR = 0;                     // Clear auto-read
 495   2         }
 496   1      }
 497          
 498          //-----------------------------------------------------------------------------
 499          // Fifo_Write
 500          //-----------------------------------------------------------------------------
 501          //
 502          // Return Value : None
 503          // Parameters   :
 504          //                1) BYTE addr : target address
 505          //                2) unsigned int uNumBytes : number of bytes to unload
 506          //                3) BYTE * pData : location of source data
 507          //
 508          // Write to the selected endpoint FIFO
 509          //
 510          // Fifo_Write_Foreground is used for function calls made in the foreground routines,
 511          // and Fifo_Write_InterruptServiceRoutine is used for calls made in an ISR.
 512          
 513          //-----------------------------------------------------------------------------
 514          
 515          void Fifo_Write_Foreground (unsigned char addr, unsigned int uNumBytes,
 516                              unsigned char * pData)
 517          {
 518   1         int i;
 519   1      
 520   1         // If >0 bytes requested,
 521   1         if (uNumBytes)
 522   1         {
 523   2            while (USB0ADR & 0x80);          // Wait for BUSY->'0'
 524   2                                             // (register available)
 525   2            USB0ADR = (addr);                // Set address (mask out bits7-6)
 526   2      
 527   2            // Write <NumBytes> to the selected FIFO
 528   2            for(i=0;i<uNumBytes;i++)
 529   2            {
 530   3               USB0DAT = pData[i];
 531   3               while (USB0ADR & 0x80);       // Wait for BUSY->'0' (data ready)
 532   3            }
 533   2         }
 534   1      }
 535          
 536          void Fifo_Write_InterruptServiceRoutine (unsigned char addr,
 537                                                   unsigned int uNumBytes,
 538                                                   unsigned char * pData)
 539          {
 540   1         int i;
 541   1      
 542   1         // If >0 bytes requested,
 543   1         if (uNumBytes)
 544   1         {
 545   2            while (USB0ADR & 0x80);          // Wait for BUSY->'0'
 546   2                                             // (register available)
 547   2            USB0ADR = (addr);                // Set address (mask out bits7-6)
 548   2      
 549   2            // Write <NumBytes> to the selected FIFO
 550   2            for (i=0; i<uNumBytes; i++)
 551   2            {
C51 COMPILER V8.17   F3XX_USB0_INTERRUPTSERVICEROUTINE                                     03/18/2009 09:55:18 PAGE 10  

 552   3               USB0DAT = pData[i];
 553   3               while (USB0ADR & 0x80);       // Wait for BUSY->'0' (data ready)
 554   3            }
 555   2         }
 556   1      }
 557          
 558          //-----------------------------------------------------------------------------
 559          // Force_Stall
 560          //-----------------------------------------------------------------------------
 561          //
 562          // Return Value : None
 563          // Parameters   : None
 564          //
 565          // Force a procedural stall to be sent to the host
 566          //
 567          //-----------------------------------------------------------------------------
 568          
 569          void Force_Stall (void)
 570          {
 571   1         POLL_WRITE_BYTE (INDEX, 0);
 572   1         POLL_WRITE_BYTE (E0CSR, rbSDSTL);   // Set the send stall bit
 573   1         EP_STATUS[0] = EP_STALL;            // Put the endpoint in stall status
 574   1      }
 575          
 576          
 577          //-----------------------------------------------------------------------------
 578          // SendPacket
 579          //-----------------------------------------------------------------------------
 580          //
 581          // Return Value - None
 582          // Parameters - Report ID that's used to call the appropriate IN handler
 583          //
 584          // This function can be called by other routines to force an IN packet
 585          // transmit.  It takes as an input the Report ID of the packet to be
 586          // transmitted.
 587          //-----------------------------------------------------------------------------
 588          
 589          void SendPacket (unsigned char ReportID)
 590          {
 591   1      //   bit EAState;
 592   1         unsigned char ControlReg;
 593   1      
 594   1         EA = 0;
 595   1         SendPacketBusy = 1;
 596   1      
 597   1         // Read contol register for EP 2
 598   1         POLL_READ_BYTE (EINCSR1, ControlReg);
 599   1      
 600   1         if (EP_STATUS[2] == EP_HALT)        // If endpoint is currently halted,
 601   1                                             // send a stall
 602   1         {
 603   2            POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
 604   2         }
 605   1      
 606   1         else if(EP_STATUS[2] == EP_IDLE)
 607   1         {
 608   2            // the state will be updated inside the ISR handler
 609   2            EP_STATUS[2] = EP_TX;
 610   2      
 611   2            if (ControlReg & rbInSTSTL)      // Clear sent stall if last
 612   2                                             // packet returned a stall
 613   2            {
C51 COMPILER V8.17   F3XX_USB0_INTERRUPTSERVICEROUTINE                                     03/18/2009 09:55:18 PAGE 11  

 614   3               POLL_WRITE_BYTE (EINCSR1, rbInCLRDT);
 615   3            }
 616   2      
 617   2            if (ControlReg & rbInUNDRUN)     // Clear underrun bit if it was set
 618   2            {
 619   3               POLL_WRITE_BYTE (EINCSR1, 0x00);
 620   3            }
 621   2            EA = 1;
 622   2      
 623   2            ReportHandler_IN_Foreground (ReportID);
 624   2      
 625   2            // Put new data on Fifo
 626   2            // Disable USB interrupts
 627   2            EIE1 &= ~0x02;                       // Disable USB0 Interrupts
 628   2      
 629   2            Fifo_Write_Foreground (FIFO_EP2, IN_BUFFER.Length,
 630   2                          (unsigned char *)IN_BUFFER.Ptr);
 631   2            POLL_WRITE_BYTE (EINCSR1, rbInINPRDY);
 632   2                                             // Set In Packet ready bit,
 633   2                                             // indicating fresh data on FIFO 2
 634   2            EIE1 |= 0x02;                       // Enable USB0 Interrupts
 635   2         }                                   
 636   1      
 637   1         EA = 1;
 638   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1279    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     19      22
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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