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

📄 usb_drv.lst

📁 基于uCOS/II制作的MP3
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.50   USB_DRV                                                               06/03/2006 10:32:51 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE USB_DRV
OBJECT MODULE PLACED IN usb_drv.obj
COMPILER INVOKED BY: C:\Program Files\keil\C51\BIN\C51.EXE lib_mcu\usb\usb_drv.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.
                    -\usb_drv.lst) OBJECT(usb_drv.obj)

line level    source

   1          /*C**************************************************************************
   2          * NAME:         usb_drv.c
   3          *----------------------------------------------------------------------------
   4          * Copyright (c) 2003 Atmel.
   5          *----------------------------------------------------------------------------
   6          * RELEASE:      snd1c-refd-nf-4_0_3      
   7          * REVISION:     1.12     
   8          *----------------------------------------------------------------------------
   9          * PURPOSE: 
  10          * This file contains the USB driver routines
  11          *
  12          * NOTES:
  13          * Driver Configuration (see config.h):
  14          *   - VENDOR_ID               enum vendor ID delivered by USB organisation 
  15          *   - PRODUCT_ID              enum product number
  16          *   - RELEASE_NUMBER          enum release number
  17          *   - USB_MANUFACTURER_NAME   mass storage manufacturer string (unicode)
  18          *   - USB_MN_LENGTH           mass storage manufacturer string length
  19          *   - USB_PRODUCT_NAME        mass storage product name string (unicode)
  20          *   - USB_PN_LENGTH           mass storage product name string length
  21          *   - USB_SERIAL_NUMBER       mass storage product serial nb string (unicode)
  22          *   - USB_SN_LENGTH           mass storage product serial nb string length
  23          *****************************************************************************/
  24          
  25          /*_____ I N C L U D E S ____________________________________________________*/
  26          
  27          #include "config.h"                         /* system configuration */
  28          #include "usb_drv.h"                        /* usb driver definition */
  29          
  30          
  31          /*_____ M A C R O S ________________________________________________________*/
  32          
  33          
  34          /*_____ D E F I N I T I O N ________________________________________________*/
  35          
  36          code struct usb_st_device_descriptor usb_device_descriptor =
  37            {
  38              sizeof(usb_device_descriptor), DEVICE, 0x1001, 0, 0, 0, EP_CONTROL_LENGTH,
  39              VENDOR_ID, PRODUCT_ID, RELEASE_NUMBER, MAN_INDEX, PROD_INDEX, SN_INDEX, 1
  40            };
  41          
  42          code struct usb_st_manufacturer usb_manufacturer =
  43            {
  44              sizeof(usb_manufacturer), STRING,
  45              USB_MANUFACTURER_NAME
  46            };
  47          
  48          code struct usb_st_product usb_product =
  49            {
  50              sizeof(usb_product), STRING,
  51              USB_PRODUCT_NAME
  52            };
  53          
  54          code struct usb_st_serial_number usb_serial_number =
C51 COMPILER V7.50   USB_DRV                                                               06/03/2006 10:32:51 PAGE 2   

  55            {
  56              sizeof(usb_serial_number), STRING,
  57              USB_SERIAL_NUMBER
  58            };
  59          
  60          code struct usb_st_language_descriptor usb_language =
  61            {
  62              sizeof(usb_language), STRING, 0x0904
  63            };
  64          
  65          code struct  
  66            {
  67              struct usb_st_configuration_descriptor  cfg;
  68              struct usb_st_interface_descriptor      ifc;
  69              struct usb_st_endpoint_descriptor       ep1;
  70              struct usb_st_endpoint_descriptor       ep2;
  71            }
  72            usb_configuration =
  73              {
  74                { 9, CONFIGURATION, sizeof(usb_configuration) << 8, 1, 1, 0, USB_CONFIG_BUSPOWERED, 0x32},
  75                { 9, INTERFACE, 0, 0, 2, 0x08, 0x06, 0x50, 0 },
  76                { 7, ENDPOINT, 0x81, 0x02, EP_IN_LENGTH << 8, 0 },
  77                { 7, ENDPOINT, 0x02, 0x02, EP_OUT_LENGTH << 8, 0 }
  78              };
  79          
  80          static  bdata bit     zlp;
  81          static  idata Byte    endpoint_status[3];
  82          
  83          static  idata Byte    *pbuffer;
  84          static  idata Byte    bmRequestType;
  85          
  86          /*_____ D E C L A R A T I O N ______________________________________________*/
  87          
  88          extern  void    usb_mass_storage_reset (void);
  89          extern  void    usb_mass_storage_get_lun (void);
  90          
  91          static  void    usb_get_descriptor (void);
  92          static  Byte*   send_ep0_packet (Byte *, Byte);
  93          static  void    usb_read_request (void);
  94          static  void    usb_set_address (void);
  95          static  void    usb_set_configuration (void);
  96          static  void    usb_clear_feature (void);
  97          static  void    usb_set_feature (void);
  98          static  void    usb_get_status (void);
  99          static  void    usb_get_configuration (void);
 100          
 101          
 102          /*F**************************************************************************
 103          * NAME: usb_init
 104          *----------------------------------------------------------------------------
 105          * PARAMS:
 106          *
 107          * return:
 108          *----------------------------------------------------------------------------
 109          * PURPOSE: 
 110          * This function initializes the USB controller and resets the endpoints FIFOs.
 111          *----------------------------------------------------------------------------
 112          * EXAMPLE:
 113          *----------------------------------------------------------------------------
 114          * NOTE: 
 115          *----------------------------------------------------------------------------
 116          * REQUIREMENTS: 
C51 COMPILER V7.50   USB_DRV                                                               06/03/2006 10:32:51 PAGE 3   

 117          *****************************************************************************/
 118          void usb_init (void)
 119          {
 120   1        Usb_enable();                             /* enable USB */
 121   1        UEPRST = 0x07;                            /* Reset EP 0, 1 and 2 */
 122   1        UEPRST = 0x00;
 123   1        endpoint_status[EP_CONTROL] = 0x00;
 124   1        endpoint_status[EP_IN] = 0x00;
 125   1        endpoint_status[EP_OUT] = 0x00;
 126   1        Usb_select_ep(EP_CONTROL);                /* control endpoint config */
 127   1        UEPCONX = CONTROL;
 128   1      }
 129          
 130          
 131          /*F**************************************************************************
 132          * NAME: usb_ep_init
 133          *----------------------------------------------------------------------------
 134          * PARAMS:
 135          *
 136          * return:
 137          *----------------------------------------------------------------------------
 138          * PURPOSE: 
 139          * This function configures the endpoints.
 140          *----------------------------------------------------------------------------
 141          * EXAMPLE:
 142          *----------------------------------------------------------------------------
 143          * NOTE: 
 144          *----------------------------------------------------------------------------
 145          * REQUIREMENTS: 
 146          *****************************************************************************/
 147          void usb_ep_init (void)
 148          {
 149   1        Usb_select_ep(EP_CONTROL);
 150   1        UEPCONX = CONTROL;
 151   1        Usb_select_ep(EP_IN);                     /* endpoints configuration */
 152   1        UEPCONX = BULK_IN ;
 153   1        Usb_select_ep(EP_OUT);
 154   1        UEPCONX = BULK_OUT;
 155   1        UEPRST = 0x07;
 156   1        UEPRST = 0x00;
 157   1      }
 158          
 159          
 160          /*F**************************************************************************
 161          * NAME: usb_send_ep0_packet
 162          *----------------------------------------------------------------------------
 163          * PARAMS:
 164          * *tbuf:        address of the first data to send
 165          * data_length:  number of bytes to send
 166          *
 167          * return:       address of the next byte to send
 168          *----------------------------------------------------------------------------
 169          * PURPOSE: 
 170          * This function sends the data over the default control endpoint.
 171          *----------------------------------------------------------------------------
 172          * EXAMPLE:
 173          *----------------------------------------------------------------------------
 174          * NOTE: 
 175          *----------------------------------------------------------------------------
 176          * REQUIREMENTS: 
 177          *****************************************************************************/
 178          Byte* send_ep0_packet (Byte *tbuf, Byte data_length)
C51 COMPILER V7.50   USB_DRV                                                               06/03/2006 10:32:51 PAGE 4   

 179          {
 180   1      Byte i;
 181   1      
 182   1        Usb_select_ep(EP_CONTROL);
 183   1        for (i = data_length; i != 0 ; i--, tbuf++)
 184   1        {
 185   2          Usb_write_byte(*tbuf); 
 186   2        }
 187   1        Usb_set_TXRDY();                          /* Send packet */
 188   1        return tbuf;
 189   1      }
 190          
 191          
 192          /*F**************************************************************************
 193          * NAME: usb_enumeration_process
 194          *----------------------------------------------------------------------------
 195          * PARAMS:
 196          *
 197          * return:
 198          *----------------------------------------------------------------------------
 199          * PURPOSE: 
 200          * This function manages the enumeration process
 201          *----------------------------------------------------------------------------
 202          * EXAMPLE:
 203          *----------------------------------------------------------------------------
 204          * NOTE: 
 205          *----------------------------------------------------------------------------
 206          * REQUIREMENTS: 
 207          *****************************************************************************/
 208          void usb_enumeration_process (void)
 209          { 
 210   1        Usb_select_ep(EP_CONTROL);
 211   1        usb_read_request();
 212   1      }
 213          
 214          
 215          /*F**************************************************************************
 216          * NAME: usb_read_request
 217          *----------------------------------------------------------------------------
 218          * PARAMS:
 219          *
 220          * return:
 221          *----------------------------------------------------------------------------
 222          * PURPOSE: 
 223          * This function reads the SETUP request sent to the default control endpoint
 224          * and  the appropriate function. When exiting of the usb_read_request
 225          * function, the device is ready to manage the next request.
 226          *----------------------------------------------------------------------------
 227          * EXAMPLE:
 228          *----------------------------------------------------------------------------
 229          * NOTE: list of supported requests:
 230          *               GET_DESCRIPTOR
 231          *               GET_CONFIGURATION
 232          *               SET_ADDRESS
 233          *               SET_CONFIGURATION
 234          *               CLEAR_FEATURE
 235          *               SET_FEATURE
 236          *               GET_STATUS
 237          *               GET_MAX_LUN
 238          *               MASS_STORAGE_RESET
 239          *----------------------------------------------------------------------------
 240          * REQUIREMENTS: 
C51 COMPILER V7.50   USB_DRV                                                               06/03/2006 10:32:51 PAGE 5   

 241          *****************************************************************************/
 242          void usb_read_request (void)
 243          { 
 244   1        bmRequestType = Usb_read_byte();          /* read bmRequestType */
 245   1      
 246   1        switch (Usb_read_byte())                  /* test the bRequest value */
 247   1        {
 248   2          case GET_DESCRIPTOR:
 249   2            usb_get_descriptor();
 250   2            break;
 251   2          case GET_CONFIGURATION:
 252   2            usb_get_configuration();
 253   2            break;
 254   2          case SET_ADDRESS:
 255   2            usb_set_address();
 256   2            break;
 257   2          case SET_CONFIGURATION:
 258   2            usb_set_configuration();
 259   2            break;
 260   2          case CLEAR_FEATURE:
 261   2            usb_clear_feature();
 262   2            break;
 263   2          case SET_FEATURE:
 264   2            usb_set_feature();
 265   2            break;
 266   2          case GET_STATUS:
 267   2            usb_get_status();
 268   2            break;
 269   2          case GET_MAX_LUN:
 270   2            usb_mass_storage_get_lun();
 271   2            break;

⌨️ 快捷键说明

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