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

📄 f326_usb0_interruptserviceroutine.lst

📁 基于F326单片机的RS232转USB程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
 420   2            ReportHandler_OUT (OUT_BUFFER.Ptr[0]);
 421   2      
 422   2            POLL_WRITE_BYTE (EOUTCSR1, 0);   // Clear Out Packet ready bit
 423   2         }
 424   1      }
 425          
 426          //-----------------------------------------------------------------------------
 427          // Usb_Suspend
C51 COMPILER V7.50   F326_USB0_INTERRUPTSERVICEROUTINE                                     12/29/2007 16:03:22 PAGE 8   

 428          //-----------------------------------------------------------------------------
 429          // Enter suspend mode after suspend signalling is present on the bus
 430          //
 431          void Usb_Suspend (void)
 432          {
 433   1         volatile int k;
 434   1         k++;
 435   1      }
 436          
 437          //-----------------------------------------------------------------------------
 438          // Fifo_Read
 439          //-----------------------------------------------------------------------------
 440          //
 441          // Return Value : None
 442          // Parameters   :
 443          //                1) BYTE addr : target address
 444          //                2) unsigned int uNumBytes : number of bytes to unload
 445          //                3) BYTE * pData : read data destination
 446          //
 447          // Read from the selected endpoint FIFO
 448          //
 449          //-----------------------------------------------------------------------------
 450          void Fifo_Read (unsigned char addr, unsigned int uNumBytes,
 451                         unsigned char * pData)
 452          {
 453   1         int i;
 454   1      
 455   1         if (uNumBytes)                      // Check if >0 bytes requested,
 456   1         {
 457   2            USB0ADR = (addr);                // Set address
 458   2            USB0ADR |= 0xC0;                 // Set auto-read and initiate
 459   2                                             // first read
 460   2      
 461   2            // Unload <NumBytes> from the selected FIFO
 462   2            for(i=0;i< (uNumBytes);i++)
 463   2            {
 464   3               while (USB0ADR & 0x80);       // Wait for BUSY->'0' (data ready)
 465   3               pData[i] = USB0DAT;           // Copy data byte
 466   3            }
 467   2      
 468   2            //while(USB0ADR & 0x80);         // Wait for BUSY->'0' (data ready)
 469   2            USB0ADR = 0;                     // Clear auto-read
 470   2         }
 471   1      }
 472          
 473          //-----------------------------------------------------------------------------
 474          // Fifo_Write
 475          //-----------------------------------------------------------------------------
 476          //
 477          // Return Value : None
 478          // Parameters   :
 479          //                1) BYTE addr : target address
 480          //                2) unsigned int uNumBytes : number of bytes to unload
 481          //                3) BYTE * pData : location of source data
 482          //
 483          // Write to the selected endpoint FIFO
 484          //
 485          // Fifo_Write_Foreground is used for function calls made in the foreground routines,
 486          // and Fifo_Write_InterruptServiceRoutine is used for calls made in an ISR.
 487          
 488          //-----------------------------------------------------------------------------
 489          
C51 COMPILER V7.50   F326_USB0_INTERRUPTSERVICEROUTINE                                     12/29/2007 16:03:22 PAGE 9   

 490          void Fifo_Write_Foreground (unsigned char addr, unsigned int uNumBytes,
 491                              unsigned char * pData)
 492          {
 493   1         int i;
 494   1      
 495   1         // If >0 bytes requested,
 496   1         if (uNumBytes)
 497   1         {
 498   2            while (USB0ADR & 0x80);          // Wait for BUSY->'0'
 499   2                                             // (register available)
 500   2            USB0ADR = (addr);                // Set address (mask out bits7-6)
 501   2      
 502   2            // Write <NumBytes> to the selected FIFO
 503   2            for(i=0;i<uNumBytes;i++)
 504   2            {
 505   3               USB0DAT = pData[i];
 506   3               while (USB0ADR & 0x80);       // Wait for BUSY->'0' (data ready)
 507   3            }
 508   2         }
 509   1      }
 510          
 511          void Fifo_Write_InterruptServiceRoutine (unsigned char addr,
 512                                                   unsigned int uNumBytes,
 513                                                   unsigned char * pData)
 514          {
 515   1         int i;
 516   1      
 517   1         // If >0 bytes requested,
 518   1         if (uNumBytes)
 519   1         {
 520   2            while (USB0ADR & 0x80);          // Wait for BUSY->'0'
 521   2                                             // (register available)
 522   2            USB0ADR = (addr);                // Set address (mask out bits7-6)
 523   2      
 524   2            // Write <NumBytes> to the selected FIFO
 525   2            for (i=0; i<uNumBytes; i++)
 526   2            {
 527   3               USB0DAT = pData[i];
 528   3               while (USB0ADR & 0x80);       // Wait for BUSY->'0' (data ready)
 529   3            }
 530   2         }
 531   1      }
 532          
 533          //-----------------------------------------------------------------------------
 534          // Force_Stall
 535          //-----------------------------------------------------------------------------
 536          //
 537          // Return Value : None
 538          // Parameters   : None
 539          //
 540          // Force a procedural stall to be sent to the host
 541          //
 542          //-----------------------------------------------------------------------------
 543          
 544          void Force_Stall (void)
 545          {
 546   1         POLL_WRITE_BYTE (INDEX, 0);
 547   1         POLL_WRITE_BYTE (E0CSR, rbSDSTL);   // Set the send stall bit
 548   1         EP_STATUS[0] = EP_STALL;            // Put the endpoint in stall status
 549   1      }
 550          
 551          
C51 COMPILER V7.50   F326_USB0_INTERRUPTSERVICEROUTINE                                     12/29/2007 16:03:22 PAGE 10  

 552          //-----------------------------------------------------------------------------
 553          // SendPacket
 554          //-----------------------------------------------------------------------------
 555          //
 556          // Return Value - None
 557          // Parameters - Report ID that's used to call the appropriate IN handler
 558          //
 559          // This function can be called by other routines to force an IN packet
 560          // transmit.  It takes as an input the Report ID of the packet to be
 561          // transmitted.
 562          //-----------------------------------------------------------------------------
 563          
 564          void SendPacket (unsigned char ReportID)
 565          {
 566   1         bit EAState;
 567   1         unsigned char ControlReg;
 568   1      
 569   1         EAState = EA;
 570   1         EA = 0;
 571   1      
 572   1         POLL_WRITE_BYTE (INDEX, 1);         // Set index to endpoint 1 registers
 573   1      
 574   1         // Read contol register for EP 1
 575   1          POLL_READ_BYTE (EINCSR1, ControlReg);
 576   1      
 577   1         if (EP_STATUS[1] == EP_HALT)        // If endpoint is currently halted,
 578   1                                             // send a stall
 579   1         {
 580   2            POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
 581   2         }
 582   1      
 583   1         else if(EP_STATUS[1] == EP_IDLE)
 584   1         {
 585   2            // the state will be updated inside the ISR handler
 586   2            EP_STATUS[1] = EP_TX;
 587   2      
 588   2            if (ControlReg & rbInSTSTL)      // Clear sent stall if last
 589   2                                             // packet returned a stall
 590   2            {
 591   3               POLL_WRITE_BYTE (EINCSR1, rbInCLRDT);
 592   3            }
 593   2      
 594   2            if (ControlReg & rbInUNDRUN)     // Clear underrun bit if it was set
 595   2            {
 596   3               POLL_WRITE_BYTE (EINCSR1, 0x00);
 597   3            }
 598   2      
 599   2            ReportHandler_IN_Foreground (ReportID);
 600   2      
 601   2                if(UartDataOK)
 602   2                {     
 603   3                // Put new data on Fifo
 604   3               Fifo_Write_Foreground (FIFO_EP1, IN_PACKET_SIZE,
 605   3                             (unsigned char *)IN_PACKET);
 606   3               POLL_WRITE_BYTE (EINCSR1, rbInINPRDY);
 607   3      
 608   3               UartDataOK=0;
 609   3                }
 610   2                                             // Set In Packet ready bit,
 611   2         }                                   // indicating fresh data on FIFO 1
 612   1      
 613   1         EA = EAState;
C51 COMPILER V7.50   F326_USB0_INTERRUPTSERVICEROUTINE                                     12/29/2007 16:03:22 PAGE 11  

 614   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 + -