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

📄 usb_9602.lst

📁 USB9602 source code for C 8051
💻 LST
📖 第 1 页 / 共 5 页
字号:
 331   3              case 5:
 332   3                bitset(EPC5,STALL);
 333   3                SETBIT(stalld,BIT5);
 334   3                break;
 335   3              case 6:
 336   3                bitset(EPC6,STALL);
 337   3                SETBIT(stalld,BIT6);
 338   3                break;
 339   3              default:
 340   3                break;
 341   3             }
 342   2            break;
 343   2      
 344   2          default:                        /*UNDEFINED               */
 345   2            break;
 346   2         }
 347   1      }
 348          
 349          /**********************************************************************/
 350          /* The SET_CONFIGURATION request is done here                         */
 351          /**********************************************************************/
 352          void setconfiguration(void)
 353          {
 354   1        usb_cfg = usb_buf[2];               /*set the configuration # */
C51 COMPILER V5.50,  USB_9602                                                              02/12/99  16:05:13  PAGE 15  

 355   1        if (usb_buf[2]!=0)                  /*set the configuration   */
 356   1         {
 357   2           dtapid = 0;                     /*FIRST PID is DATA0      */
 358   2           stalld = 0;                     /*nothing stalled         */
 359   2      
 360   2           FLUSHTX1;                       /*flush  TX1 and disable  */
 361   2           write_usb(EPC1,EP_EN+01);       /*enable EP1 at adr 1     */
 362   2      
 363   2           FLUSHRX1;                       /*flush  RX1 and disable  */
 364   2           write_usb(EPC2,EP_EN+02);       /*enable EP2 at adr 2     */
 365   2           write_usb(RXC1,RX_EN);          /*enable RX1              */
 366   2      
 367   2           FLUSHTX3;                       /*flush  TX1 and disable  */
 368   2           write_usb(EPC5,EP_EN+05);       /*enable EP5 at adr 5     */
 369   2      
 370   2           FLUSHRX3;                       /*flush  RX3 and disable  */
 371   2           write_usb(EPC6,EP_EN+06);       /*enable EP6 at adr 6     */
 372   2           write_usb(RXC3,RX_EN);          /*enable RX3              */
 373   2         }
 374   1        else                                /*unconfigure the device  */
 375   1         {
 376   2           write_usb(EPC1,0);              /*disable EP1             */
 377   2           write_usb(EPC2,0);              /*disable EP2             */
 378   2           write_usb(EPC5,0);              /*disable EP5             */
 379   2           write_usb(EPC6,0);              /*disable EP6             */
 380   2         }
 381   1      }
 382          
 383          /**********************************************************************/
 384          /* This subroutine loads a byte from a descriptor or report into the  */
 385          /* endpoint 0 fifo.                                                   */
 386          /**********************************************************************/
 387          void mlti_pkt(void)
 388          {
 389   1      unsigned char pckt_dta;
 390   1      
 391   1        if(desc_sze>0)
 392   1         {
 393   2          if(TSTBIT(status,GETDESC))
 394   2            switch (desc_typ)             /*descriptor **************/
 395   2             {
 396   3              case DEVICE:
 397   3                pckt_dta=DEV_DESC[desc_idx];
 398   3                break;
 399   3      
 400   3              case CONFIGURATION:
 401   3                pckt_dta=CFG_DESC[desc_idx];
 402   3                break;
 403   3      
 404   3              case XSTRING:
 405   3                pckt_dta=STR_DATA[desc_idx];
 406   3                break;
 407   3      
 408   3              case HID:
 409   3                pckt_dta=CFG_DESC[desc_idx];
 410   3                break;
 411   3      
 412   3              case HIDREPORT:
 413   3                pckt_dta=ReportDescriptor[desc_idx];
 414   3                break;
 415   3      
 416   3              default:                  /*UNDEFINED               */
 417   3                pckt_dta=0;
 418   3                break;
 419   3             }
 420   2          else
C51 COMPILER V5.50,  USB_9602                                                              02/12/99  16:05:13  PAGE 16  

 421   2            switch (desc_typ)             /*report ******************/
 422   2             {
 423   3              default:                  /*UNDEFINED               */
 424   3                pckt_dta=0;
 425   3                break;
 426   3             }
 427   2      
 428   2          write_usb(TXD0,pckt_dta);       /*send data to the FIFO   */
 429   2          desc_sze--;                     /*decriment size          */
 430   2          desc_idx++;                     /*increment index         */
 431   2         }
 432   1      }
 433          
 434          /**********************************************************************/
 435          /* The CLEAR_FEATURE request is done here                             */
 436          /**********************************************************************/
 437          void clrfeature(void)
 438          {
 439   1        switch (usb_buf[0]&0x03)          /*find request target     */
 440   1         {
 441   2          case 0:                         /*DEVICE                  */
 442   2            break;
 443   2      
 444   2          case 1:                         /*INTERFACE               */
 445   2            break;
 446   2      
 447   2          case 2:                         /*ENDPOINT                */
 448   2            switch (usb_buf[4]&0x0F)      /*find specific endpoint  */
 449   2             {                           /*  (strip off dir. bit)  */
 450   3              case 0:
 451   3                bitclr(EPC0,STALL);
 452   3                CLRBIT(stalld,BIT0);
 453   3                break;
 454   3              case 1:
 455   3                bitclr(EPC1,STALL);
 456   3                CLRBIT(stalld,BIT1);
 457   3                break;
 458   3              case 2:
 459   3                bitclr(EPC2,STALL);
 460   3                CLRBIT(stalld,BIT2);
 461   3                break;
 462   3              case 3:
 463   3                bitclr(EPC3,STALL);
 464   3                CLRBIT(stalld,BIT3);
 465   3                break;
 466   3              case 4:
 467   3                bitclr(EPC4,STALL);
 468   3                CLRBIT(stalld,BIT4);
 469   3                break;
 470   3              case 5:
 471   3                bitclr(EPC5,STALL);
 472   3                CLRBIT(stalld,BIT5);
 473   3                break;
 474   3              case 6:
 475   3                bitclr(EPC6,STALL);
 476   3                CLRBIT(stalld,BIT6);
 477   3                break;
 478   3              default:
 479   3                break;
 480   3             }
 481   2            break;
 482   2      
 483   2          default:                        /*UNDEFINED               */
 484   2            break;
 485   2         }
 486   1      }
C51 COMPILER V5.50,  USB_9602                                                              02/12/99  16:05:13  PAGE 17  

 487          
 488          /**********************************************************************/
 489          /* The GET_DESCRIPTOR request is done here.                           */
 490          /**********************************************************************/
 491          void getdescriptor(void)
 492          {
 493   1        SET_GETDESC;                        /*enter GETDESC mode      */
 494   1        desc_typ = usb_buf[3];              /*store the type requested*/
 495   1      
 496   1            /*select descriptor size and starting index                     */
 497   1        switch (desc_typ)
 498   1         {
 499   2          case DEVICE:
 500   2            desc_idx = 0;
 501   2            desc_sze = DEV_DESC_SIZE;
 502   2            break;
 503   2      
 504   2          case CONFIGURATION:
 505   2            desc_idx = 0;
 506   2            desc_sze = CFG_DESC_SIZE;
 507   2            break;
 508   2      
 509   2          case XSTRING:
 510   2            desc_idx = usb_buf[2];
 511   2            desc_sze = STR_DATA[desc_idx];
 512   2            break;
 513   2      
 514   2          case HID:
 515   2                /*valid if we have only one int: revisit if this changes  */
 516   2            desc_idx = CFG_LENGTH+INT_LENGTH;
 517   2            desc_sze = CFG_DESC[(CFG_LENGTH+INT_LENGTH)];
 518   2            break;
 519   2      
 520   2          case HIDREPORT:
 521   2            desc_idx = 0;
 522   2            desc_sze = RPT_DESC_SIZE;
 523   2            break;
 524   2      
 525   2          default:                        /*UNDEFINED               */
 526   2            desc_idx = 0;
 527   2            desc_sze = 0;
 528   2            break;
 529   2         }
 530   1      
 531   1            /*adjust size, if the host has asked for less than we want to   */
 532   1            /*send.  Note that we only check the low order byte of the      */
 533   1            /*wlength field.  If we ever need to send back descriptors      */
 534   1            /*longer than 256 bytes, we'll need to revisit this             */
 535   1        if (usb_buf[7]==0)                  /*if less than 256 req'd  */
 536   1        if (desc_sze > usb_buf[6]) desc_sze = usb_buf[6];
 537   1      
 538   1            /*send the first data chunk back                                */
 539   1        mlti_pkt(); mlti_pkt(); mlti_pkt(); mlti_pkt();
 540   1        mlti_pkt(); mlti_pkt(); mlti_pkt(); mlti_pkt();
 541   1      }
 542          
 543          /**********************************************************************/
 544          /* The GET_STATUS request is done here                                */
 545          /**********************************************************************/
 546          void getstatus(void)
 547          {
 548   1        switch (usb_buf[0]&0x03)            /*find request target     */
 549   1         {
 550   2          case 0:                         /*DEVICE                  */
 551   2            write_usb(TXD0,0);            /*first  byte is reserved */
 552   2            break;
C51 COMPILER V5.50,  USB_9602                                                              02/12/99  16:05:13  PAGE 18  

 553   2      
 554   2     

⌨️ 快捷键说明

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