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

📄 usb_drv.lst

📁 at89c5132,at89c51snd1的usb与keyboard驱动程序。
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   USB_DRV                                                               01/29/2008 10:59:25 PAGE 1   


C51 COMPILER V7.06, 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 LARGE OPTIMIZE(9,SPEED) INCDIR(.\;.\;.\) 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:      c5131-usb-kbd-light-1_0_2      
   7          * REVISION:     1.3     
   8          *----------------------------------------------------------------------------
   9          * PURPOSE: 
  10          * This file contains the USB driver routines.
  11          *****************************************************************************/
  12          
  13          /*_____ I N C L U D E S ____________________________________________________*/
  14          
  15          #include "config.h"
  16          #include "usb_drv.h"
  17          
  18          /*_____ M A C R O S ________________________________________________________*/
  19          
  20          
  21          /*_____ D E F I N I T I O N ________________________________________________*/
  22          /* --------------------------------------------------------------------------------------------------
  23          |Xtal frequency  ||  6 MHz |  8 MHz | 12 MHz | 16 MHz | 20 MHz | 24 MHz | 32 MHz | 40 MHz | 48 MHz |
  24           --------------------------------------------------------------------------------------------------
  25          |Pll % value (n) ||   1    |   1    |   1    |   1    |   5    |   1    |   2    |   10   |disabled|
  26          |Pll x value (r) ||   8    |   6    |   4    |   3    |   12   |   2    |   3    |   12   |disabled|
  27          |PLLDIV value    ||  70h   |  50h   |  30h   |  20  h |  B4h   |  10h   |  21h   |  B9h   |disabled|
  28          |  [r,n]         ||        |        |        |        |        |        |        |        |        |
  29           --------------------------------------------------------------------------------------------------
  30          |Timer load X1   ||   600  |   800  |  1200  |  1600  |  2000  |  2400  |  3200  |  4000  |  4800  |
  31          |Timer TH0-TH1 X1|| FD-A7h | FC-DFh | FB-4Fh | F9-BFh | F8-2Fh | F6-9Fh | F3-7Fh | F0-5Fh | ED-3Fh |
  32          |Timer load X2   ||  1200  |  1600  |  2400  |  3200  |  4000  |  4800  |   na   |   na   |   na   |
  33          |Timer TH0-TH1 X2|| FB-4Fh | F9-BFh | F6-9Fh | F3-7Fh | F0-5Fh | ED-3Fh |   na   |   na   |   na   |   
  34           --------------------------------------------------------------------------------------------------
  35          */
  36          #if FOSC == 0000
                code char pll_value[8] = {0x70,0x50,0x30,0x20,0xB4,0x10,0x21,0xB9};
                code char TH0_value[9] = {0xFD,0xFC,0xFB,0xF9,0xF8,0xF6,0xF3,0xF0,0xED};
                code char TL0_value[9] = {0xA7,0xDF,0x4F,0xBF,0x2F,0x9F,0x7F,0x5F,0x3F};
              #endif
  41          /*_____ D E C L A R A T I O N ______________________________________________*/
  42          
  43          /*F**************************************************************************
  44          * NAME: usb_configure_endpoint 
  45          *----------------------------------------------------------------------------
  46          * PARAMS:
  47          * ep_num:   Number of the endpoint to configure
  48          * ep_type:  Type to configure
  49          *           The possible types are:
  50          *                CONTROL
  51          *                BULK_IN
  52          *                BULK_OUT
  53          *                INTERRUPT_IN
  54          *                INTERRUPT_OUT
C51 COMPILER V7.06   USB_DRV                                                               01/29/2008 10:59:25 PAGE 2   

  55          *                ISOCHRONOUS_IN
  56          *                ISOCHRONOUS_OUT
  57          * return:   none
  58          *----------------------------------------------------------------------------
  59          * PURPOSE: 
  60          * This function configures an endpoint with the selected type.
  61          *----------------------------------------------------------------------------
  62          * EXAMPLE:
  63          * usb_configure_endpoint(0,CONTROL);
  64          *----------------------------------------------------------------------------
  65          * NOTE:
  66          * The endpoint 0 shall always be configured in CONTROL type.
  67          *----------------------------------------------------------------------------
  68          * REQUIREMENTS: 
  69          *****************************************************************************/
  70          void usb_configure_endpoint (Uchar ep_num, Uchar ep_type)
  71          {
  72   1        Usb_select_ep(ep_num);
  73   1        Usb_configure_ep_type(ep_type); 
  74   1      }
  75          
  76          /*F**************************************************************************
  77          * NAME: usb_select_endpoint_interrupt
  78          *----------------------------------------------------------------------------
  79          * PARAMS:
  80          * return:   endpoint number
  81          *----------------------------------------------------------------------------
  82          * PURPOSE: 
  83          * This function select the endpoint where an event occurs and returns the
  84          * number of this endpoint. If no event occurs on the endpoints, this
  85          * function returns 0.
  86          *----------------------------------------------------------------------------
  87          * EXAMPLE:
  88          *----------------------------------------------------------------------------
  89          * NOTE:
  90          *----------------------------------------------------------------------------
  91          * REQUIREMENTS: 
  92          *****************************************************************************/
  93          Uchar usb_select_enpoint_interrupt(void)
  94          {
  95   1        if (EP0INT)       { Usb_select_ep(0); }
  96   1        else if (EP1INT)  { Usb_select_ep(1); }
  97   1        else if (EP2INT)  { Usb_select_ep(2); }
  98   1        else if (EP3INT)  { Usb_select_ep(3); }
  99   1        else if (EP4INT)  { Usb_select_ep(4); }
 100   1        else if (EP5INT)  { Usb_select_ep(5); }
 101   1        else if (EP6INT)  { Usb_select_ep(6); }
 102   1      
 103   1        return (UEPNUM);
 104   1      }
 105          
 106          
 107          /*F**************************************************************************
 108          * NAME: usb_get_nb_byte 
 109          *----------------------------------------------------------------------------
 110          * PARAMS:
 111          * return:   number of byte stored in the currently selected endpoint
 112          *----------------------------------------------------------------------------
 113          * PURPOSE: 
 114          * This function returns the number of byte stored in the currently selected
 115          * endpoint.
 116          *----------------------------------------------------------------------------
C51 COMPILER V7.06   USB_DRV                                                               01/29/2008 10:59:25 PAGE 3   

 117          * EXAMPLE:
 118          *----------------------------------------------------------------------------
 119          * NOTE:
 120          * This function shall be launched only for OUT endpoints after each receipt
 121          * and before any other operation.
 122          * This function shall not be used if the declared FIFO size is more than
 123          * 255 bytes. In this case, use the usb_get_nb_byte_epw function.  
 124          *----------------------------------------------------------------------------
 125          * REQUIREMENTS: 
 126          *****************************************************************************/
 127          Uchar usb_get_nb_byte (void)
 128          {
 129   1        return (UBYCTLX);
 130   1      }
 131          
 132          /*F**************************************************************************
 133          * NAME: usb_get_nb_byte_epw 
 134          *----------------------------------------------------------------------------
 135          * PARAMS:
 136          * return:   number of byte stored in the endpoint .
 137          *----------------------------------------------------------------------------
 138          * PURPOSE: 
 139          * This function returns the number of byte stored in the endpoint 6.
 140          *----------------------------------------------------------------------------
 141          * EXAMPLE:
 142          *----------------------------------------------------------------------------
 143          * NOTE:
 144          * This function shall be launched only for OUT endpoints after each receipt
 145          * and before any other operation.
 146          * This function shall be used if the declared FIFO size is more than
 147          * 255 bytes.
 148          *----------------------------------------------------------------------------
 149          * REQUIREMENTS:
 150          *****************************************************************************/
 151          Uint16 usb_get_nb_byte_epw (void)
 152          {
 153   1        return ((((Uint16)UBYCTHX)<<8)|(UBYCTLX)); 
 154   1      }
 155          
 156          /*F**************************************************************************
 157          * NAME: usb_send_ep0_packet
 158          *----------------------------------------------------------------------------
 159          * PARAMS:
 160          * *tbuf:        address of the first data to send
 161          * data_length:  number of bytes to send
 162          * return:       address of the next Ucharto send
 163          *----------------------------------------------------------------------------
 164          * PURPOSE: 
 165          * This function moves the data pointed by tbuf to the default Control
 166          * endpoint fifo and sends it through the USB.
 167          *----------------------------------------------------------------------------
 168          * EXAMPLE:
 169          * usb_send_ep0_packet(&first_data,0x20);  // send packet
 170          * while(!(Usb_tx_complete));              // wait packet ACK'ed by the Host
 171          * Usb_clear_tx_complete();                     // acknowledge the transmit
 172          *----------------------------------------------------------------------------
 173          * NOTE: 
 174          * tbuf is incremented of 'data_length'.
 175          *----------------------------------------------------------------------------
 176          * REQUIREMENTS: 
 177          *****************************************************************************/
 178          Uchar* usb_send_ep0_packet (Uchar* tbuf, Uchar data_length)
C51 COMPILER V7.06   USB_DRV                                                               01/29/2008 10:59:25 PAGE 4   

 179          {
 180   1      Uchar i;
 181   1      
 182   1        Usb_select_ep(0);
 183   1      
 184   1        for (i = data_length; i != 0 ; i--, tbuf++)  { Usb_write_byte(*tbuf); }
 185   1        Usb_set_tx_ready();
 186   1      
 187   1        return tbuf;
 188   1      }
 189          
 190          
 191          /*F**************************************************************************
 192          * NAME: usb_send_packet
 193          *----------------------------------------------------------------------------
 194          * PARAMS:
 195          * ep_num:       number of the addressed endpoint
 196          * *tbuf:        address of the first data to send
 197          * data_length:  number of bytes to send
 198          * return:       address of the next Uchar to send
 199          *----------------------------------------------------------------------------
 200          * PURPOSE: 
 201          * This function moves the data pointed by tbuf to the selected endpoint fifo 
 202          * and sends it through the USB.
 203          *----------------------------------------------------------------------------
 204          * EXAMPLE:
 205          * usb_send_packet(3,&first_data,0x20);    // send packet on the endpoint #3
 206          * while(!(Usb_tx_complete));              // wait packet ACK'ed by the Host
 207          * Usb_clear_tx_complete();                     // acknowledge the transmit
 208          *----------------------------------------------------------------------------
 209          * NOTE:
 210          * tbuf is incremented of 'data_length'.
 211          *----------------------------------------------------------------------------
 212          * REQUIREMENTS: 
 213          *****************************************************************************/
 214          Uchar* usb_send_packet (Uchar ep_num, Uchar* tbuf, Uchar data_length)
 215          {
 216   1      Uchar i;
 217   1      
 218   1        Usb_select_ep(ep_num);
 219   1      
 220   1        for (i = data_length; i != 0 ; i--, tbuf++)  { Usb_write_byte(*tbuf); }
 221   1        Usb_set_tx_ready();
 222   1      
 223   1        return tbuf;
 224   1      }
 225          
 226          /*F**************************************************************************
 227          * NAME: usb_read_packet
 228          *----------------------------------------------------------------------------
 229          * PARAMS:
 230          * ep_num:       number of the addressed endpoint
 231          * *rbuf:        address of the first data to write with the USB data

⌨️ 快捷键说明

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