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

📄 usb_isr.lst

📁 采用USB单片机开发的TMS320C6701/C6201系统的在线升级模块
💻 LST
📖 第 1 页 / 共 2 页
字号:
 205   4      			                            // Break Data into multiple packets if larger than Max Packet
 206   4                  if (DataSize >= EP0_PACKET_SIZE)
 207   4                  {
 208   5                     Fifo_Write(FIFO_EP0, EP0_PACKET_SIZE, (BYTE *)DataPtr);// Put Data on Fifo
 209   5                     DataPtr  += EP0_PACKET_SIZE;                           // Advance data pointer
 210   5                     DataSize -= EP0_PACKET_SIZE;                           // Decrement data size
 211   5                     DataSent += EP0_PACKET_SIZE;                           // Increment data sent counter
 212   5                  }
 213   4      			else                        // If data is less than Max Packet size or zero
 214   4                  {
 215   5                     Fifo_Write(FIFO_EP0, DataSize, (BYTE *)DataPtr);       // Put Data on Fifo
 216   5                     TempReg |= rbDATAEND;                                  // Add Data End bit to bitmask
 217   5                     Ep_Status[0] = EP_IDLE;                                // Return EP 0 to idle state
 218   5                  }
 219   4                  if (DataSent == Setup.wLength.i)
 220   4      			                            // This case exists when the host requests an even multiple of
 221   4                                              // your endpoint zero max packet size, and you need to exit
 222   4                                              // transmit mode without sending a zero length packet
 223   4                  {
 224   5                     TempReg |= rbDATAEND;    // Add Data End bit to mask
 225   5                     Ep_Status[0] = EP_IDLE;  // and return Endpoint 0 to an idle state
 226   5                  }
 227   4                  POLL_WRITE_BYTE(E0CSR, TempReg);                          // Write mask to E0CSR
 228   4               }
 229   3            }
 230   2         }
 231   1      }
 232          
 233          //-------------------------
 234          // Handle_In1
 235          //-------------------------
 236          // - This routine loads the current value from In_Packet on the Endpoint 1 fifo, after 
 237          // an interrupt is received from the last packet being transmitted
 238          void Handle_In1()
 239          {
 240   1         BYTE ControlReg;
C51 COMPILER V6.12  USB_ISR                                                                06/09/2004 15:44:26 PAGE 5   

 241   1      
 242   1         POLL_WRITE_BYTE(INDEX, 1);           // Set index to endpoint 1 registers
 243   1         POLL_READ_BYTE(EINCSR1, ControlReg); // Read contol register for EP 1
 244   1      
 245   1         if (Ep_Status[1] == EP_HALT)         // If endpoint is currently halted, send a stall
 246   1         {
 247   2            POLL_WRITE_BYTE(EINCSR1, rbInSDSTL);
 248   2         }
 249   1      
 250   1         else                                 // Otherwise send last updated data to host
 251   1         {
 252   2            if (ControlReg & rbInSTSTL)       // Clear sent stall if last packet returned a stall
 253   2            {
 254   3               POLL_WRITE_BYTE(EINCSR1, rbInCLRDT);
 255   3            }
 256   2      
 257   2            if (ControlReg & rbInUNDRUN)      // Clear underrun bit if it was set
 258   2            {
 259   3               POLL_WRITE_BYTE(EINCSR1, 0x00);
 260   3            }
 261   2      
 262   2                                              // Put new data on Fifo
 263   2            Fifo_Write(FIFO_EP1, EP1_PACKET_SIZE, (BYTE *)IN_PACKET);
 264   2            POLL_WRITE_BYTE(EINCSR1, rbInINPRDY);   
 265   2                                              // Set In Packet ready bit, indicating fresh data
 266   2         }                                    // on Fifo 1
 267   1      }
 268          
 269          //-------------------------
 270          // Handle_Out2
 271          //-------------------------
 272          // Take the received packet from the host off the fifo and put it into the Out_Packet array
 273          //
 274          void Handle_Out2()
 275          {
 276   1         BYTE Count = 0;
 277   1         BYTE ControlReg;
 278   1      
 279   1         POLL_WRITE_BYTE(INDEX, 2);           // Set index to endpoint 2 registers
 280   1         POLL_READ_BYTE(EOUTCSR1, ControlReg);
 281   1      
 282   1         if (Ep_Status[2] == EP_HALT)         // If endpoint is halted, send a stall
 283   1         {
 284   2            POLL_WRITE_BYTE(EOUTCSR1, rbOutSDSTL);
 285   2         }
 286   1      
 287   1         else                                 // Otherwise read received packet from host
 288   1         {
 289   2            if (ControlReg & rbOutSTSTL)      // Clear sent stall bit if last packet was a stall
 290   2            {
 291   3               POLL_WRITE_BYTE(EOUTCSR1, rbOutCLRDT);
 292   3            }
 293   2      	g_ucCount = 0;
 294   2      	    POLL_READ_BYTE(EOUTCNTL, g_ucCount);		  
 295   2      //      POLL_READ_BYTE(EOUTCNTL, Count);
 296   2      /*      if (Count != EP2_PACKET_SIZE)     // If host did not send correct packet size, flush buffer
 297   2            {
 298   2               POLL_WRITE_BYTE(EOUTCNTL, rbOutFLUSH); 
 299   2            }
 300   2            else                              // Otherwise get the data packet
 301   2            {
 302   2               Fifo_Read(FIFO_EP2, EP2_PACKET_SIZE, (BYTE*)OUT_PACKET);
C51 COMPILER V6.12  USB_ISR                                                                06/09/2004 15:44:26 PAGE 6   

 303   2            }
 304   2      */
 305   2      		if(g_ucCount <= 0)
 306   2      		{
 307   3      			POLL_WRITE_BYTE(EOUTCNTL, rbOutFLUSH);	
 308   3      		}
 309   2      		else
 310   2      		{
 311   3      			Fifo_Read(FIFO_EP2, g_ucCount, g_ucUsbGData);
 312   3      		}
 313   2            POLL_WRITE_BYTE(EOUTCSR1, 0);     // Clear Out Packet ready bit
 314   2         }
 315   1      }
 316          
 317          //-------------------------
 318          // Usb_Suspend
 319          //-------------------------
 320          // Enter suspend mode after suspend signalling is present on the bus
 321          //
 322          void Usb_Suspend(void)
 323          {                                         // Add power-down features here if you wish to 
 324   1         volatile int k;                        // reduce power consumption during suspend mode
 325   1         k++;
 326   1      }
 327          
 328          //----------------------------------
 329          //  FIFO Read
 330          //----------------------------------
 331          //
 332          // Read from the selected endpoint FIFO
 333          //
 334          // Inputs:
 335          // addr: target address
 336          // uNumBytes: number of bytes to unload
 337          // pData: read data destination
 338          //
 339          void Fifo_Read(BYTE addr, unsigned int uNumBytes, BYTE * pData)
 340          {
 341   1         int i;
 342   1      
 343   1         if (uNumBytes)                         // Check if >0 bytes requested,
 344   1         {      
 345   2            USB0ADR = (addr);                   // Set address
 346   2            USB0ADR |= 0xC0;                    // Set auto-read and initiate 
 347   2                                                // first read      
 348   2      
 349   2            // Unload <NumBytes> from the selected FIFO
 350   2            for(i=0;i<uNumBytes;i++)
 351   2            {         
 352   3               while(USB0ADR & 0x80);           // Wait for BUSY->'0' (data ready)
 353   3               pData[i] = USB0DAT;              // Copy data byte
 354   3            }
 355   2      
 356   2         USB0ADR = 0;                           // Clear auto-read
 357   2         }
 358   1      }
 359          
 360          //----------------------------------
 361          //  FIFO Write
 362          //----------------------------------
 363          //
 364          // Write to the selected endpoint FIFO
C51 COMPILER V6.12  USB_ISR                                                                06/09/2004 15:44:26 PAGE 7   

 365          //
 366          // Inputs:
 367          // addr: target address
 368          // uNumBytes: number of bytes to write
 369          // pData: location of source data
 370          //
 371          void Fifo_Write(BYTE addr, unsigned int uNumBytes, BYTE * pData)
 372          {
 373   1         int i;
 374   1                                                
 375   1         // If >0 bytes requested,
 376   1         if (uNumBytes) 
 377   1         {
 378   2            while(USB0ADR & 0x80);              // Wait for BUSY->'0'
 379   2                                                // (register available)
 380   2            USB0ADR = (addr);                   // Set address (mask out bits7-6)
 381   2      
 382   2            // Write <NumBytes> to the selected FIFO
 383   2            for(i=0;i<uNumBytes;i++)
 384   2            {  
 385   3               USB0DAT = pData[i];
 386   3               while(USB0ADR & 0x80);           // Wait for BUSY->'0' (data ready)
 387   3            }
 388   2         }
 389   1      }
 390          
 391          //-------------------------
 392          // Force_Stall
 393          //-------------------------
 394          // Force a procedural stall to be sent to the host
 395          //
 396          void Force_Stall(void)
 397          {
 398   1         POLL_WRITE_BYTE(INDEX, 0);
 399   1         POLL_WRITE_BYTE(E0CSR, rbSDSTL);       // Set the send stall bit
 400   1         Ep_Status[0] = EP_STALL;               // Put the endpoint in stall status
 401   1      }
 402          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    968    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     19      18
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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