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

📄 usb_drv.lst

📁 该源码是基于atmel公司的89C51SND1C的mp3解决方案
💻 LST
📖 第 1 页 / 共 3 页
字号:
 271   2            break;
 272   2          case MASS_STORAGE_RESET:
 273   2            usb_mass_storage_reset();
 274   2            break;
 275   2          default:
 276   2            Usb_clear_RXSETUP();
 277   2            Usb_set_STALLRQ();
 278   2            while (!Usb_STALL_sent());
 279   2            Usb_clear_STALLRQ();
 280   2            Usb_clear_STALLED();
 281   2            break;
 282   2        }
 283   1      }
 284          
 285          
 286          /*F**************************************************************************
 287          * NAME: usb_set_address
 288          *----------------------------------------------------------------------------
 289          * PARAMS:
 290          *
 291          * return:
 292          *----------------------------------------------------------------------------
 293          * PURPOSE: 
 294          * This function manages the SET_ADDRESS request. The new address is stored
 295          * in the USBADDR register
 296          *----------------------------------------------------------------------------
 297          * EXAMPLE:
 298          *----------------------------------------------------------------------------
 299          * NOTE:
 300          *----------------------------------------------------------------------------
 301          * REQUIREMENTS: 
C51 COMPILER V7.00  USB_DRV                                                                04/28/2004 09:31:55 PAGE 6   

 302          *****************************************************************************/
 303          void usb_set_address (void)
 304          {
 305   1      Byte add;
 306   1      
 307   1        Usb_clear_DIR();
 308   1        add = Usb_read_byte();                    /* store the LSB of wValue = address */
 309   1        UEPRST = 0x01 ;
 310   1        UEPRST = 0x00 ;
 311   1        Usb_clear_RXSETUP();
 312   1        Usb_set_TXRDY();                          /* send a ZLP for STATUS phase */
 313   1        Usb_set_FADDEN();
 314   1        while (!(Usb_tx_complete()));
 315   1        Usb_clear_TXCMPL();
 316   1        Usb_configure_address(add);
 317   1      }
 318          
 319          
 320          /*F**************************************************************************
 321          * NAME: usb_set_configuration
 322          *----------------------------------------------------------------------------
 323          * PARAMS:
 324          *
 325          * return:
 326          *----------------------------------------------------------------------------
 327          * PURPOSE: 
 328          * This function manages the SET_CONFIGURATION request.
 329          *----------------------------------------------------------------------------
 330          * EXAMPLE:
 331          *----------------------------------------------------------------------------
 332          * NOTE:
 333          *----------------------------------------------------------------------------
 334          * REQUIREMENTS: 
 335          *****************************************************************************/
 336          void usb_set_configuration (void)
 337          {
 338   1      Uchar configuration_number;
 339   1      
 340   1        configuration_number = Usb_read_byte();
 341   1        Usb_clear_DIR();
 342   1        Usb_clear_RXSETUP();
 343   1        Usb_set_TXRDY();                          /* send a ZLP for STATUS phase */
 344   1        if (configuration_number == 0)
 345   1        {
 346   2          Usb_clear_CONFG();
 347   2        }
 348   1        else
 349   1        {
 350   2          Usb_set_CONFG();
 351   2        }
 352   1        while (!Usb_tx_complete());
 353   1        Usb_clear_TXCMPL();
 354   1        Usb_select_ep(EP_IN);                     /* endpoints configuration */
 355   1        UEPCONX = BULK_IN ;
 356   1        Usb_select_ep(EP_OUT);
 357   1        UEPCONX = BULK_OUT;
 358   1      }
 359          
 360          
 361          /*F**************************************************************************
 362          * NAME: usb_get_descriptor
 363          *----------------------------------------------------------------------------
C51 COMPILER V7.00  USB_DRV                                                                04/28/2004 09:31:55 PAGE 7   

 364          * PARAMS:
 365          *
 366          * return:
 367          *----------------------------------------------------------------------------
 368          * PURPOSE: 
 369          * This function manages the GET_DESCRIPTOR request.
 370          *----------------------------------------------------------------------------
 371          * EXAMPLE:
 372          *----------------------------------------------------------------------------
 373          * NOTE:
 374          *----------------------------------------------------------------------------
 375          * REQUIREMENTS: 
 376          *****************************************************************************/
 377          void usb_get_descriptor (void)
 378          {
 379   1      Byte    data_to_transfer;
 380   1      Uint16  wLength;
 381   1      Byte    descriptor_type;
 382   1      Byte    string_type;
 383   1      
 384   1        Usb_set_DIR();                            /* set out on EP0 */
 385   1        zlp = FALSE;                              /* no zero length packet */
 386   1      
 387   1        string_type = Usb_read_byte();            /* read LSB of wValue */
 388   1        descriptor_type = Usb_read_byte();        /* read MSB of wValue */
 389   1        switch (descriptor_type)
 390   1        {
 391   2          case DEVICE:
 392   2          {
 393   3            data_to_transfer = sizeof (usb_device_descriptor);
 394   3            pbuffer = &(usb_device_descriptor.bLength);
 395   3            break;
 396   3          }
 397   2      
 398   2          case CONFIGURATION:
 399   2          {
 400   3            data_to_transfer = sizeof (usb_configuration);
 401   3            pbuffer = &(usb_configuration.cfg.bLength);
 402   3            break;
 403   3          }
 404   2      
 405   2          case STRING:
 406   2          {
 407   3            switch (string_type)
 408   3            {
 409   4              case LANG_ID:
 410   4              {
 411   5                data_to_transfer = sizeof (usb_language);
 412   5                pbuffer = &(usb_language.bLength);
 413   5                break;
 414   5              }
 415   4              case MAN_INDEX:
 416   4              {
 417   5                data_to_transfer = sizeof (usb_manufacturer);
 418   5                pbuffer = &(usb_manufacturer.bLength);
 419   5                break;
 420   5              }
 421   4              case PROD_INDEX:
 422   4              {
 423   5                data_to_transfer = sizeof (usb_product);
 424   5                pbuffer = &(usb_product.bLength);
 425   5                break;
C51 COMPILER V7.00  USB_DRV                                                                04/28/2004 09:31:55 PAGE 8   

 426   5              }
 427   4              case SN_INDEX:
 428   4              {
 429   5                data_to_transfer = sizeof (usb_serial_number);
 430   5                pbuffer = &(usb_serial_number.bLength);
 431   5                break;
 432   5              }
 433   4              default:
 434   4              {
 435   5                Usb_clear_RXSETUP();
 436   5                while (!Usb_setup_received())
 437   5                {
 438   6                  Usb_set_STALLRQ();              /* send stall */
 439   6                  while ((!(Usb_STALL_sent())) && (Usb_setup_received()));
 440   6                  Usb_clear_STALLED();
 441   6                  Usb_clear_STALLRQ();
 442   6                }
 443   5                Usb_clear_DIR();                  /* set in on EP0 */
 444   5                return;
 445   5              }
 446   4            }
 447   3            break;
 448   3          }
 449   2      
 450   2          default:
 451   2          {
 452   3            Usb_clear_RXSETUP();
 453   3            while (!Usb_setup_received())
 454   3            {
 455   4              Usb_set_STALLRQ();                  /* send stall */
 456   4              while ((!(Usb_STALL_sent())) && (Usb_setup_received()));
 457   4              Usb_clear_STALLED();
 458   4              Usb_clear_STALLRQ();
 459   4            }
 460   3            Usb_clear_DIR();                      /* set in on EP0 */
 461   3            return;
 462   3          }
 463   2        }
 464   1      
 465   1        ACC = Usb_read_byte();                    /* don't care of wIndex field */
 466   1        ACC = Usb_read_byte();
 467   1        ((Byte*)&wLength)[1] = Usb_read_byte();   /* read wLength */
 468   1        ((Byte*)&wLength)[0] = Usb_read_byte();
 469   1        if (wLength > data_to_transfer)
 470   1        {
 471   2          if ((data_to_transfer % EP_CONTROL_LENGTH) == 0)
 472   2          {
 473   3            zlp = TRUE;                           /* send a zero length packet */
 474   3          }
 475   2          else
 476   2          {
 477   3            zlp = FALSE;                          /* no need of zero length packet */
 478   3          }
 479   2        }
 480   1        else
 481   1        {
 482   2          data_to_transfer = (Byte)wLength;       /* send only requested number of data */
 483   2        }
 484   1        Usb_clear_RXSETUP() ;                     /* clear the receive setup flag */
 485   1      
 486   1        while (data_to_transfer > EP_CONTROL_LENGTH)
 487   1        {
C51 COMPILER V7.00  USB_DRV                                                                04/28/2004 09:31:55 PAGE 9   

 488   2          pbuffer = send_ep0_packet(pbuffer, EP_CONTROL_LENGTH);
 489   2          data_to_transfer -= EP_CONTROL_LENGTH;
 490   2          while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
 491   2          if ((Usb_rx_complete()))                /* if no cancel from USB Host */
 492   2          {
 493   3            Usb_clear_RXOUT();
 494   3            return;
 495   3          }
 496   2          if (Usb_tx_complete())
 497   2          {
 498   3            Usb_clear_TXCMPL();
 499   3          }
 500   2        }
 501   1        /* send last data packet */
 502   1        pbuffer = send_ep0_packet(pbuffer, data_to_transfer);
 503   1        data_to_transfer = 0;
 504   1        while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
 505   1        if ((Usb_rx_complete()))                  /* if no cancel from USB Host */
 506   1        {
 507   2          Usb_clear_RXOUT();
 508   2          return;
 509   2        }
 510   1        if (Usb_tx_complete())
 511   1        {
 512   2          Usb_clear_TXCMPL();
 513   2        }
 514   1        if (zlp == TRUE)
 515   1        {
 516   2          send_ep0_packet(pbuffer, 0);
 517   2          while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
 518   2          if ((Usb_rx_complete()))              /* if no cancel from USB Host */
 519   2          {
 520   3            Usb_clear_RXOUT();
 521   3            return;
 522   3          }
 523   2          if (Usb_tx_complete())
 524   2          {
 525   3            Usb_clear_TXCMPL();
 526   3          }
 527   2        }
 528   1        while ((!(Usb_rx_complete())) && (!(Usb_setup_received())));
 529   1        if (Usb_setup_received())
 530   1        {
 531   2          return;
 532   2        }
 533   1      
 534   1        if (Usb_rx_complete())
 535   1        {
 536   2          Usb_clear_DIR();                        /* set in on EP0 */
 537   2          Usb_clear_RXOUT();
 538   2        }
 539   1      }
 540          
 541          
 542          /*F**************************************************************************
 543          * NAME: usb_get_configuration
 544          *----------------------------------------------------------------------------
 545          * PARAMS:
 546          *
 547          * return:
 548          *----------------------------------------------------------------------------
 549          * PURPOSE: 
C51 COMPILER V7.00  USB_DRV                                                                04/28/2004 09:31:55 PAGE 10  

⌨️ 快捷键说明

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