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

📄 f3xx_usb0_interruptserviceroutine.lst

📁 101259367USB_Mouse_Example.rar
💻 LST
📖 第 1 页 / 共 3 页
字号:
 213   1      
 214   1         if (ControlReg & rbSUEND)           // If last SETUP transaction was
 215   1         {                                   // ended prematurely then set
 216   2            POLL_WRITE_BYTE (E0CSR, rbDATAEND);
 217   2            // Serviced SETUP End bit and return EP0
 218   2            POLL_WRITE_BYTE (E0CSR, rbSSUEND);
 219   2            EP_STATUS[0] = EP_IDLE;          // to idle state
 220   2         }
 221   1      
 222   1         if (EP_STATUS[0] == EP_IDLE)        // If Endpoint 0 is in idle mode
 223   1         {
 224   2            if (ControlReg & rbOPRDY)        // Make sure that EP 0 has an Out Packet
 225   2            {                                // ready from host although if EP0
 226   3                                             // is idle, this should always be the
 227   3                                             // case
 228   3               Fifo_Read (FIFO_EP0, 8, (unsigned char *)&SETUP);
 229   3                                             // Get SETUP Packet off of Fifo,
 230   3                                             // it is currently Big-Endian
 231   3      
 232   3                                             // Compiler Specific - these next three
 233   3                                             // statements swap the bytes of the
 234   3                                             // SETUP packet words to Big Endian so
 235   3                                             // they can be compared to other 16-bit
 236   3                                             // values elsewhere properly
 237   3               SETUP.wValue.i = SETUP.wValue.c[MSB] + 256*SETUP.wValue.c[LSB];
 238   3               SETUP.wIndex.i = SETUP.wIndex.c[MSB] + 256*SETUP.wIndex.c[LSB];
 239   3               SETUP.wLength.i = SETUP.wLength.c[MSB] + 256*SETUP.wLength.c[LSB];
 240   3      
 241   3                      // Intercept HID class-specific requests
C51 COMPILER V7.06   F3XX_USB0_INTERRUPTSERVICEROUTINE                                     09/12/2006 16:12:58 PAGE 5   

 242   3                      if( (SETUP.bmRequestType & ~0x80) == DSC_HID) {
 243   4                              switch (SETUP.bRequest) {
 244   5                                      case GET_REPORT:
 245   5                                              Get_Report ();
 246   5                                              break;
 247   5                                      case SET_REPORT:
 248   5                                              Set_Report ();
 249   5                                              break;
 250   5                                      case GET_IDLE:
 251   5                                              Get_Idle ();
 252   5                                              break;
 253   5                                      case SET_IDLE:
 254   5                                              Set_Idle ();
 255   5                                              break;
 256   5                                      case GET_PROTOCOL:
 257   5                                              Get_Protocol ();
 258   5                                              break;
 259   5                                      case SET_PROTOCOL:
 260   5                                              Set_Protocol ();
 261   5                                              break;
 262   5                          default:
 263   5                        Force_Stall ();      // Send stall to host if invalid
 264   5                          break;                 // request
 265   5                              }
 266   4                      } else
 267   3      
 268   3               switch (SETUP.bRequest)       // Call correct subroutine to handle
 269   3               {                             // each kind of standard request
 270   4                  case GET_STATUS:
 271   4                     Get_Status ();
 272   4                     break;
 273   4                  case CLEAR_FEATURE:
 274   4                     Clear_Feature ();
 275   4                     break;
 276   4                  case SET_FEATURE:
 277   4                     Set_Feature ();
 278   4                     break;
 279   4                  case SET_ADDRESS:
 280   4                     Set_Address ();
 281   4                     break;
 282   4                  case GET_DESCRIPTOR:
 283   4                     Get_Descriptor ();
 284   4                     break;
 285   4                  case GET_CONFIGURATION:
 286   4                     Get_Configuration ();
 287   4                     break;
 288   4                  case SET_CONFIGURATION:
 289   4                     Set_Configuration ();
 290   4                     break;
 291   4                  case GET_INTERFACE:
 292   4                     Get_Interface ();
 293   4                     break;
 294   4                  case SET_INTERFACE:
 295   4                     Set_Interface ();
 296   4                     break;
 297   4                  default:
 298   4                     Force_Stall ();         // Send stall to host if invalid request
 299   4                     break;
 300   4               }
 301   3            }
 302   2         }
 303   1      
C51 COMPILER V7.06   F3XX_USB0_INTERRUPTSERVICEROUTINE                                     09/12/2006 16:12:58 PAGE 6   

 304   1         if (EP_STATUS[0] == EP_TX)          // See if endpoint should transmit
 305   1         {
 306   2            if (!(ControlReg & rbINPRDY) )   // Don't overwrite last packet
 307   2            {
 308   3               // Read control register
 309   3               POLL_READ_BYTE (E0CSR, ControlReg);
 310   3      
 311   3               // Check to see if SETUP End or Out Packet received, if so do not put
 312   3               // any new data on FIFO
 313   3               if ((!(ControlReg & rbSUEND)) || (!(ControlReg & rbOPRDY)))
 314   3               {
 315   4                  // Add In Packet ready flag to E0CSR bitmask
 316   4                  ControlReg = rbINPRDY;
 317   4                  if (DATASIZE >= EP0_PACKET_SIZE)
 318   4                  {
 319   5                     // Break Data into multiple packets if larger than Max Packet
 320   5                     Fifo_Write_InterruptServiceRoutine (FIFO_EP0, EP0_PACKET_SIZE,
 321   5                                                                                        (unsigned char*)DATAPTR);
 322   5                     // Advance data pointer
 323   5                     DATAPTR  += EP0_PACKET_SIZE;
 324   5                     // Decrement data size
 325   5                     DATASIZE -= EP0_PACKET_SIZE;
 326   5                     // Increment data sent counter
 327   5                     DATASENT += EP0_PACKET_SIZE;
 328   5                  }
 329   4                  else
 330   4                  {
 331   5                     // If data is less than Max Packet size or zero
 332   5                     Fifo_Write_InterruptServiceRoutine (FIFO_EP0, DATASIZE,
 333   5                                                                                        (unsigned char*)DATAPTR);
 334   5                     ControlReg |= rbDATAEND;// Add Data End bit to bitmask
 335   5                     EP_STATUS[0] = EP_IDLE; // Return EP 0 to idle state
 336   5                  }
 337   4                  if (DATASENT == SETUP.wLength.i)
 338   4                  {
 339   5                     // This case exists when the host requests an even multiple of
 340   5                     // your endpoint zero max packet size, and you need to exit
 341   5                     // transmit mode without sending a zero length packet
 342   5                     ControlReg |= rbDATAEND;// Add Data End bit to mask
 343   5                     EP_STATUS[0] = EP_IDLE; // Return EP 0 to idle state
 344   5                  }
 345   4                  // Write mask to E0CSR
 346   4                  POLL_WRITE_BYTE(E0CSR, ControlReg);
 347   4               }
 348   3            }
 349   2         }
 350   1      
 351   1         if (EP_STATUS[0] == EP_RX)          // See if endpoint should transmit
 352   1         {
 353   2            // Read control register
 354   2            POLL_READ_BYTE (E0CSR, ControlReg);
 355   2            if (ControlReg & rbOPRDY)        // Verify packet was received
 356   2            {
 357   3               ControlReg = rbSOPRDY;
 358   3                      if (DATASIZE >= EP0_PACKET_SIZE)
 359   3                      {
 360   4                  Fifo_Read(FIFO_EP0, EP0_PACKET_SIZE, (unsigned char*)DATAPTR);
 361   4                  // Advance data pointer
 362   4                  DATAPTR  += EP0_PACKET_SIZE;
 363   4                  // Decrement data size
 364   4                  DATASIZE -= EP0_PACKET_SIZE;
 365   4                  // Increment data sent counter
C51 COMPILER V7.06   F3XX_USB0_INTERRUPTSERVICEROUTINE                                     09/12/2006 16:12:58 PAGE 7   

 366   4                  DATASENT += EP0_PACKET_SIZE;
 367   4                      }
 368   3                      else
 369   3                      {
 370   4                  // read bytes from FIFO
 371   4                  Fifo_Read (FIFO_EP0, DATASIZE, (unsigned char*) DATAPTR);
 372   4      
 373   4                  ControlReg |= rbDATAEND;   // signal end of data
 374   4                  EP_STATUS[0] = EP_IDLE;    // set Endpoint to IDLE
 375   4                      }
 376   3                      if (DATASENT == SETUP.wLength.i)
 377   3                      {
 378   4                              ControlReg |= rbDATAEND;
 379   4                              EP_STATUS[0] = EP_IDLE;
 380   4                      }
 381   3               // if EP_RX mode was entered through a SET_REPORT request,
 382   3               // call the ReportHandler_OUT function and pass the Report
 383   3               // ID, which is the first by the of DATAPTR's buffer
 384   3               if ( (EP_STATUS[0] == EP_IDLE) && (SETUP.bRequest == SET_REPORT) )
 385   3               {
 386   4                  ReportHandler_OUT (*DATAPTR);
 387   4               }
 388   3      
 389   3               if (EP_STATUS[0] != EP_STALL) POLL_WRITE_BYTE (E0CSR, ControlReg);
 390   3            }
 391   2         }
 392   1      
 393   1      }
 394          
 395          //-----------------------------------------------------------------------------
 396          // Handle_In1
 397          //-----------------------------------------------------------------------------
 398          //
 399          // Handler will be entered after the endpoint's buffer has been
 400          // transmitted to the host.  In1_StateMachine is set to Idle, which
 401          // signals the foreground routine SendPacket that the Endpoint
 402          // is ready to transmit another packet.
 403          //-----------------------------------------------------------------------------
 404          void Handle_In1 ()
 405          {
 406   1            EP_STATUS[1] = EP_IDLE;
 407   1      }
 408          
 409          //-----------------------------------------------------------------------------
 410          // Handle_Out1
 411          //-----------------------------------------------------------------------------
 412          // Take the received packet from the host off the fifo and put it into
 413          // the Out_Packet array.
 414          //
 415          //-----------------------------------------------------------------------------
 416          void Handle_Out1 ()
 417          {
 418   1      
 419   1         unsigned char Count = 0;
 420   1         unsigned char ControlReg;
 421   1      
 422   1         POLL_WRITE_BYTE (INDEX, 1);         // Set index to endpoint 2 registers
 423   1         POLL_READ_BYTE (EOUTCSR1, ControlReg);
 424   1      
 425   1         if (EP_STATUS[1] == EP_HALT)        // If endpoint is halted, send a stall
 426   1         {
 427   2            POLL_WRITE_BYTE (EOUTCSR1, rbOutSDSTL);
C51 COMPILER V7.06   F3XX_USB0_INTERRUPTSERVICEROUTINE                                     09/12/2006 16:12:58 PAGE 8   

 428   2         }
 429   1      
 430   1         else                                // Otherwise read received packet
 431   1                                             // from host

⌨️ 快捷键说明

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