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

📄 f3xx_usb0_interruptserviceroutine.lst

📁 hid to rs232 usb_hid 转 串口程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
 214   2            {                                // ready from host although if EP0
 215   3                                             // is idle, this should always be the
 216   3                                             // case
 217   3               Fifo_Read (FIFO_EP0, 8, (unsigned char *)&SETUP);
 218   3                                             // Get SETUP Packet off of Fifo,
 219   3                                             // it is currently Big-Endian
 220   3      
 221   3                                             // Compiler Specific - these next three
 222   3                                             // statements swap the bytes of the
 223   3                                             // SETUP packet words to Big Endian so
 224   3                                             // they can be compared to other 16-bit
 225   3                                             // values elsewhere properly
 226   3               SETUP.wValue.i = SETUP.wValue.c[MSB] + 256*SETUP.wValue.c[LSB];
 227   3               SETUP.wIndex.i = SETUP.wIndex.c[MSB] + 256*SETUP.wIndex.c[LSB];
 228   3               SETUP.wLength.i = SETUP.wLength.c[MSB] + 256*SETUP.wLength.c[LSB];
 229   3      
 230   3                      // Intercept HID class-specific requests
 231   3                      if( (SETUP.bmRequestType & ~0x80) == DSC_HID) {
 232   4                              switch (SETUP.bRequest) {
 233   5                                      case GET_REPORT:
 234   5                                              Get_Report ();
 235   5                                              break;
 236   5                                      case SET_REPORT:
 237   5                                              Set_Report ();
 238   5                                              break;
 239   5                                      case GET_IDLE:
 240   5                                              Get_Idle ();
 241   5                                              break;
C51 COMPILER V8.17   F3XX_USB0_INTERRUPTSERVICEROUTINE                                     03/18/2009 09:55:18 PAGE 5   

 242   5                                      case SET_IDLE:
 243   5                                              Set_Idle ();
 244   5                                              break;
 245   5                                      case GET_PROTOCOL:
 246   5                                              Get_Protocol ();
 247   5                                              break;
 248   5                                      case SET_PROTOCOL:
 249   5                                              Set_Protocol ();
 250   5                                              break;
 251   5                          default:
 252   5                        Force_Stall ();      // Send stall to host if invalid
 253   5                          break;                  // request
 254   5                              }
 255   4                      } else
 256   3      
 257   3               switch (SETUP.bRequest)       // Call correct subroutine to handle
 258   3               {                             // each kind of standard request
 259   4                  case GET_STATUS:
 260   4                     Get_Status ();
 261   4                     break;
 262   4                  case CLEAR_FEATURE:
 263   4                     Clear_Feature ();
 264   4                     break;
 265   4                  case SET_FEATURE:
 266   4                     Set_Feature ();
 267   4                     break;
 268   4                  case SET_ADDRESS:
 269   4                     Set_Address ();
 270   4                     break;
 271   4                  case GET_DESCRIPTOR:
 272   4                     Get_Descriptor ();
 273   4                     break;
 274   4                  case GET_CONFIGURATION:
 275   4                     Get_Configuration ();
 276   4                     break;
 277   4                  case SET_CONFIGURATION:
 278   4                     Set_Configuration ();
 279   4                     break;
 280   4                  case GET_INTERFACE:
 281   4                     Get_Interface ();
 282   4                     break;
 283   4                  case SET_INTERFACE:
 284   4                     Set_Interface ();
 285   4                     break;
 286   4                  default:
 287   4                     Force_Stall ();         // Send stall to host if invalid request
 288   4                     break;
 289   4               }
 290   3            }
 291   2         }
 292   1      
 293   1         if (EP_STATUS[0] == EP_TX)          // See if endpoint should transmit
 294   1         {
 295   2            if (!(ControlReg & rbINPRDY) )   // Don't overwrite last packet
 296   2            {
 297   3               // Read control register
 298   3               POLL_READ_BYTE (E0CSR, ControlReg);
 299   3      
 300   3               // Check to see if SETUP End or Out Packet received, if so do not put
 301   3               // any new data on FIFO
 302   3               if ((!(ControlReg & rbSUEND)) || (!(ControlReg & rbOPRDY)))
 303   3               {
C51 COMPILER V8.17   F3XX_USB0_INTERRUPTSERVICEROUTINE                                     03/18/2009 09:55:18 PAGE 6   

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

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

 428   2      
 429   2            Setup_OUT_BUFFER ();             // Configure buffer to save
 430   2                                             // received data
 431   2            Fifo_Read(FIFO_EP2, OUT_BUFFER.Length, OUT_BUFFER.Ptr);
 432   2      
 433   2            // Process data according to received Report ID.

⌨️ 快捷键说明

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