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

📄 usbhw.lst

📁 USB高性能读卡器源码。可灵活增删功能。
💻 LST
📖 第 1 页 / 共 5 页
字号:
ARM COMPILER V2.51a,  usbhw                                                                16/08/06  09:38:29  PAGE 1   


ARM COMPILER V2.51a, COMPILATION OF MODULE usbhw
OBJECT MODULE PLACED IN usbhw.OBJ
COMPILER INVOKED BY: D:\Program Files\ARM\BIN\CA.exe usbhw.c THUMB DEBUG PRINT(.\LST\USBHW.LST) TABS(4) 

stmt  level    source

    1          /*----------------------------------------------------------------------------
    2           *      U S B  -  K e r n e l
    3           *----------------------------------------------------------------------------
    4           *      Name:    USBHW.C
    5           *      Purpose: USB Hardware Layer Module for Atmel AT91SAM7S
    6           *      Version: V1.10
    7           *----------------------------------------------------------------------------
    8           *      This file is part of the uVision/ARM development tools.
    9           *      Copyright (c) 2005-2006 Keil Software. All rights reserved.
   10           *      This software may only be used under the terms of a valid, current,
   11           *      end user licence from KEIL for a compatible version of KEIL software
   12           *      development tools. Nothing else gives you the right to use it.
   13           *---------------------------------------------------------------------------*/
   14          
   15          #include <AT91SAM7S64.H>                    /* AT91SAM7S64 definitions */
   16          
   17          #include "type.h"
   18          
   19          #include "usb.h"
   20          #include "usbcfg.h"
   21          #include "usbhw.h"
   22          #include "usbuser.h"
   23          
   24          
   25          const BYTE  DualBankEP = 0x06;              /* Dual Bank Endpoint Bit Mask */
   26          
   27          const DWORD RX_DATA_BK[2] = {
   28            AT91C_UDP_RX_DATA_BK0,
   29            AT91C_UDP_RX_DATA_BK1
   30          };
   31          
   32          
   33          AT91PS_UDP pUDP = AT91C_BASE_UDP;           /* Global UDP Pointer */
   34          
   35          BYTE  RxDataBank[USB_EP_NUM];
   36          BYTE  TxDataBank[USB_EP_NUM];
   37          
   38          
   39          /*
   40           *  USB Initialize Function
   41           *   Called by the User to initialize USB
   42           *    Return Value:    None
   43           */
   44          
   45          void USB_Init (void) {
   46   1      
   47   1        /* Enables the 48MHz USB Clock UDPCK and System Peripheral USB Clock */
   48   1        AT91C_BASE_PMC->PMC_SCER = AT91C_PMC_UDP;
   49   1        AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_UDP);
   50   1      
   51   1        /* Global USB Interrupt: Mode and Vector with Highest Priority and Enable */
   52   1        AT91C_BASE_AIC->AIC_SMR[AT91C_ID_UDP] = AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED |
   53   1                                                AT91C_AIC_PRIOR_HIGHEST;
   54   1        AT91C_BASE_AIC->AIC_SVR[AT91C_ID_UDP] = (unsigned long) USB_ISR;
   55   1        AT91C_BASE_AIC->AIC_IECR = (1 << AT91C_ID_UDP);
   56   1      
   57   1        /* UDP PullUp (USB_DP_PUP): PA16 Pin */
   58   1        /*   Configure as Output and Set to disable Pull-up Resistor */
   59   1        AT91C_BASE_PIOA->PIO_PER  = AT91C_PIO_PA16;
ARM COMPILER V2.51a,  usbhw                                                                16/08/06  09:38:29  PAGE 2   

   60   1        AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA16;
   61   1        AT91C_BASE_PIOA->PIO_OER  = AT91C_PIO_PA16;
   62   1      }
   63          
   64          
   65          /*
   66           *  USB Connect Function
   67           *   Called by the User to Connect/Disconnect USB
   68           *    Parameters:      con:   Connect/Disconnect
   69           *    Return Value:    None
   70           */
   71          
   72          void USB_Connect (BOOL con) {
   73   1      
   74   1        if (con) {
   75   2          /* Enable UDP PullUp (USB_DP_PUP) */
   76   2          AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA16;
   77   2        } else {
   78   2          /* Disable UDP PullUp (USB_DP_PUP) */
   79   2          AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA16;
   80   2        }
   81   1      }
   82          
   83          
   84          /*
   85           *  USB Reset Function
   86           *   Called automatically on USB Reset
   87           *    Return Value:    None
   88           */
   89          
   90          void USB_Reset (void) {
   91   1        DWORD n;
   92   1      
   93   1        /* Global USB Reset */
   94   1        pUDP->UDP_GLBSTATE &= ~(AT91C_UDP_FADDEN | AT91C_UDP_CONFG | AT91C_UDP_RMWUPE);
   95   1        pUDP->UDP_FADDR     =  AT91C_UDP_FEN;
   96   1        pUDP->UDP_ICR       =  0xFFFFFFFF;
   97   1      
   98   1        /* Reset & Disable USB Endpoints */
   99   1        for (n = 0; n < USB_EP_NUM; n++) {
  100   2          pUDP->UDP_CSR[n] = 0;
  101   2          RxDataBank[n] = 0;
  102   2          TxDataBank[n] = 0;
  103   2        }
  104   1        pUDP->UDP_RSTEP = 0xFFFFFFFF;
  105   1        pUDP->UDP_RSTEP = 0;
  106   1      
  107   1        /* Setup USB Interrupts */
  108   1        pUDP->UDP_IER = AT91C_UDP_RXSUSP | AT91C_UDP_RXRSM | AT91C_UDP_EXTRSM |
  109   1                        AT91C_UDP_SOFINT | (2^USB_EP_NUM - 1);
  110   1      
  111   1        /* Setup Control Endpoint 0 */
  112   1        pUDP->UDP_CSR[0] = AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_CTRL;
  113   1      }
  114          
  115          
  116          /*
  117           *  USB Suspend Function
  118           *   Called automatically on USB Suspend
  119           *    Return Value:    None
  120           */
  121          
  122          void USB_Suspend (void) {
  123   1        /* Performed by Hardware */
  124   1      }
  125          
ARM COMPILER V2.51a,  usbhw                                                                16/08/06  09:38:29  PAGE 3   

  126          
  127          /*
  128           *  USB Resume Function
  129           *   Called automatically on USB Resume
  130           *    Return Value:    None
  131           */
  132          
  133          void USB_Resume (void) {
  134   1        /* Performed by Hardware */
  135   1      }
  136          
  137          
  138          /*
  139           *  USB Remote Wakeup Function
  140           *   Called automatically on USB Remote Wakeup
  141           *    Return Value:    None
  142           */
  143          
  144          void USB_WakeUp (void) {
  145   1        /* Performed by Hardware */
  146   1      }
  147          
  148          
  149          /*
  150           *  USB Remote Wakeup Configuration Function
  151           *    Parameters:      cfg:   Enable/Disable
  152           *    Return Value:    None
  153           */
  154          
  155          void USB_WakeUpCfg (BOOL cfg) {
  156   1      
  157   1        if (cfg) {
  158   2          pUDP->UDP_GLBSTATE |=  AT91C_UDP_RMWUPE;
  159   2        } else {
  160   2          pUDP->UDP_GLBSTATE &= ~AT91C_UDP_RMWUPE;
  161   2        }
  162   1      }
  163          
  164          
  165          /*
  166           *  USB Set Address Function
  167           *    Parameters:      adr:   USB Address
  168           *    Return Value:    None
  169           */
  170          
  171          void USB_SetAddress (DWORD adr) {
  172   1      
  173   1        pUDP->UDP_FADDR = AT91C_UDP_FEN | adr;
  174   1        if (adr) {
  175   2          pUDP->UDP_GLBSTATE |=  AT91C_UDP_FADDEN;
  176   2        } else {
  177   2          pUDP->UDP_GLBSTATE &= ~AT91C_UDP_FADDEN;
  178   2        }
  179   1      }
  180          
  181          
  182          /*
  183           *  USB Configure Function
  184           *    Parameters:      cfg:   Configure/Deconfigure
  185           *    Return Value:    None
  186           */
  187          
  188          void USB_Configure (BOOL cfg) {
  189   1      
  190   1        if (cfg) {
  191   2          pUDP->UDP_GLBSTATE |=  AT91C_UDP_CONFG;
ARM COMPILER V2.51a,  usbhw                                                                16/08/06  09:38:29  PAGE 4   

  192   2        } else {
  193   2          pUDP->UDP_GLBSTATE &= ~AT91C_UDP_CONFG;
  194   2        }
  195   1      }
  196          
  197          
  198          /*
  199           *  Configure USB Endpoint according to Descriptor
  200           *    Parameters:      pEPD:  Pointer to Endpoint Descriptor
  201           *    Return Value:    None
  202           */
  203          
  204          void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD) {
  205   1        DWORD num, dir;
  206   1      
  207   1        num = pEPD->bEndpointAddress & 0x0F;
  208   1        dir = pEPD->bEndpointAddress & USB_ENDPOINT_DIRECTION_MASK;
  209   1      
  210   1        switch (pEPD->bmAttributes & USB_ENDPOINT_TYPE_MASK) {
  211   2          case USB_ENDPOINT_TYPE_CONTROL:
  212   2            pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_CTRL;
  213   2            break;
  214   2          case USB_ENDPOINT_TYPE_ISOCHRONOUS:
  215   2            if (dir) {
  216   3              pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_ISO_IN;
  217   3            } else {
  218   3              pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_ISO_OUT;
  219   3            }
  220   2            break;
  221   2          case USB_ENDPOINT_TYPE_BULK:
  222   2            if (dir) {
  223   3              pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_BULK_IN;
  224   3            } else {
  225   3              pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_BULK_OUT;
  226   3            }
  227   2            break;
  228   2          case USB_ENDPOINT_TYPE_INTERRUPT:
  229   2            if (dir) {
  230   3              pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_INT_IN;
  231   3            } else {
  232   3              pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_INT_OUT;
  233   3            }
  234   2            break;
  235   2          default:
  236   2            pUDP->UDP_CSR[num] = 0;
  237   2            break;
  238   2        }
  239   1      }
  240          
  241          
  242          /*
  243           *  Set Direction for USB Control Endpoint
  244           *    Parameters:      dir:   Out (dir == 0), In (dir <> 0)
  245           *    Return Value:    None
  246           */
  247          
  248          void USB_DirCtrlEP (DWORD dir) {
  249   1      
  250   1        if (dir ) {
  251   2          pUDP->UDP_CSR[0] |=  AT91C_UDP_DIR;
  252   2        } else {
  253   2          pUDP->UDP_CSR[0] &= ~AT91C_UDP_DIR;
  254   2        }
  255   1        pUDP->UDP_CSR[0] &= ~AT91C_UDP_RXSETUP;
  256   1      }
  257          
ARM COMPILER V2.51a,  usbhw                                                                16/08/06  09:38:29  PAGE 5   

  258          
  259          /*
  260           *  Enable USB Endpoint
  261           *    Parameters:      EPNum: Endpoint Number
  262           *                       EPNum.0..3: Address
  263           *                       EPNum.7:    Dir
  264           *    Return Value:    None
  265           */
  266          
  267          void USB_EnableEP (DWORD EPNum) {
  268   1        pUDP->UDP_CSR[EPNum & 0x0F] |=  AT91C_UDP_EPEDS;
  269   1      }
  270          
  271          
  272          /*
  273           *  Disable USB Endpoint
  274           *    Parameters:      EPNum: Endpoint Number
  275           *                       EPNum.0..3: Address
  276           *                       EPNum.7:    Dir
  277           *    Return Value:    None
  278           */
  279          
  280          void USB_DisableEP (DWORD EPNum) {
  281   1        pUDP->UDP_CSR[EPNum & 0x0F] &= ~AT91C_UDP_EPEDS;
  282   1      }
  283          
  284          
  285          #define AT91C_UDP_STALLSENT AT91C_UDP_ISOERROR
  286          
  287          
  288          /*
  289           *  Reset USB Endpoint
  290           *    Parameters:      EPNum: Endpoint Number
  291           *                       EPNum.0..3: Address
  292           *                       EPNum.7:    Dir
  293           *    Return Value:    None
  294           */
  295          
  296          void USB_ResetEP (DWORD EPNum) {
  297   1      
  298   1        EPNum &= 0x0F;
  299   1        pUDP->UDP_CSR[EPNum] &= ~(AT91C_UDP_TXCOMP      | AT91C_UDP_RXSETUP      |

⌨️ 快捷键说明

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