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

📄 usb_drv.lst

📁 串口小程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.02a   USB_DRV                                                              09/13/2007 11:53:01 PAGE 1   


C51 COMPILER V7.02a, COMPILATION OF MODULE USB_DRV
OBJECT MODULE PLACED IN usb_drv.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lib_mcu\usb\usb_drv.c OPTIMIZE(7,SPEED) BROWSE INCDIR(.\modules\system;.\;.
                    -\;.\lib_refd) DEFINE(KEIL) DEBUG OBJECTEXTEND PRINT(.\usb_drv.lst) OBJECT(usb_drv.obj)

stmt 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.02a   USB_DRV                                                              09/13/2007 11:53:01 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.02a   USB_DRV                                                              09/13/2007 11:53:01 PAGE 3   

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

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

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

⌨️ 快捷键说明

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