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

📄 usbhw.lst

📁 NXP产品LPC23XX的开发板的源文件
💻 LST
📖 第 1 页 / 共 5 页
字号:
ARM COMPILER V2.53,  usbhw                                                                 05/09/06  14:20:49  PAGE 1   


ARM COMPILER V2.53, COMPILATION OF MODULE usbhw
OBJECT MODULE PLACED IN .\Obj\usbhw.obj
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe usbhw.c THUMB DEBUG PRINT(.\LST\USBHW.LST) TABS(4) OBJECT(.\Obj\usbhw.obj) 

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 Philips LPC214x
    6           *      Version: V1.10
    7           *----------------------------------------------------------------------------
    8           *      This software is supplied "AS IS" without any warranties, express,
    9           *      implied or statutory, including but not limited to the implied
   10           *      warranties of fitness for purpose, satisfactory quality and
   11           *      noninfringement. Keil extends you a royalty-free right to reproduce
   12           *      and distribute executable files created using this software for use
   13           *      on Philips LPC2xxx microcontroller devices only. Nothing else gives
   14           *      you the right to use this software.
   15           *
   16           *      Copyright (c) 2005-2006 Keil Software.
   17           *---------------------------------------------------------------------------*/
   18          
   19          #include <LPC214X.H>                        /* LPC214x definitions */
   20          
   21          #include "type.h"
   22          
   23          #include "usb.h"
   24          #include "usbcfg.h"
   25          #include "usbreg.h"
   26          #include "usbhw.h"
   27          #include "usbcore.h"
   28          #include "usbuser.h"
   29          
   30          
   31          #define EP_MSK_CTRL 0x0001      /* Control Endpoint Logical Address Mask */
   32          #define EP_MSK_BULK 0xC924      /* Bulk Endpoint Logical Address Mask */
   33          #define EP_MSK_INT  0x4492      /* Interrupt Endpoint Logical Address Mask */
   34          #define EP_MSK_ISO  0x1248      /* Isochronous Endpoint Logical Address Mask */
   35          
   36          
   37          #if USB_DMA
               
               DWORD UDCA[USB_EP_NUM] __at USB_RAM_ADR;    /* UDCA in USB RAM */
               DWORD udca[USB_EP_NUM];                     /* UDCA saved values */
               
               DWORD DDMemMap[2];                          /* DMA Descriptor Memory Usage */
               
               #endif
   45          
   46          
   47          /*
   48           *  Get Endpoint Physical Address
   49           *    Parameters:      EPNum: Endpoint Number
   50           *                       EPNum.0..3: Address
   51           *                       EPNum.7:    Dir
   52           *    Return Value:    Endpoint Physical Address
   53           */
   54          
   55          DWORD EPAdr (DWORD EPNum) {
   56   1        DWORD val;
   57   1      
   58   1        val = (EPNum & 0x0F) << 1;
   59   1        if (EPNum & 0x80) {
ARM COMPILER V2.53,  usbhw                                                                 05/09/06  14:20:49  PAGE 2   

   60   2          val += 1;
   61   2        }
   62   1        return (val);
   63   1      }
   64          
   65          
   66          /*
   67           *  Write Command
   68           *    Parameters:      cmd:   Command
   69           *    Return Value:    None
   70           */
   71          
   72          void WrCmd (DWORD cmd) {
   73   1      
   74   1        DEV_INT_CLR = CCEMTY_INT;
   75   1        CMD_CODE = cmd;
   76   1        while ((DEV_INT_STAT & CCEMTY_INT) == 0);
   77   1      }
   78          
   79          
   80          /*
   81           *  Write Command Data
   82           *    Parameters:      cmd:   Command
   83           *                     val:   Data
   84           *    Return Value:    None
   85           */
   86          
   87          void WrCmdDat (DWORD cmd, DWORD val) {
   88   1      
   89   1        DEV_INT_CLR = CCEMTY_INT;
   90   1        CMD_CODE = cmd;
   91   1        while ((DEV_INT_STAT & CCEMTY_INT) == 0);
   92   1        DEV_INT_CLR = CCEMTY_INT;
   93   1        CMD_CODE = val;
   94   1        while ((DEV_INT_STAT & CCEMTY_INT) == 0);
   95   1      }
   96          
   97          
   98          /*
   99           *  Read Command Data
  100           *    Parameters:      cmd:   Command
  101           *    Return Value:    Data Value
  102           */
  103          
  104          DWORD RdCmdDat (DWORD cmd) {
  105   1      
  106   1        DEV_INT_CLR = CCEMTY_INT | CDFULL_INT;
  107   1        CMD_CODE = cmd;
  108   1        while ((DEV_INT_STAT & CDFULL_INT) == 0);
  109   1        return (CMD_DATA);
  110   1      }
  111          
  112          
  113          /*
  114           *  USB Initialize Function
  115           *   Called by the User to initialize USB
  116           *    Return Value:    None
  117           */
  118          
  119          void USB_Init (void) {
  120   1      
  121   1        PINSEL1 &= ~0xC000C000;
  122   1        PINSEL1 |=  0x40004000;                   /* Select USB Link, VBUS */
  123   1      
  124   1        PCONP |= 0x80000000;                      /* Turn On USB PCLK */
  125   1      
ARM COMPILER V2.53,  usbhw                                                                 05/09/06  14:20:49  PAGE 3   

  126   1        /* Configure 48MHz USB Clock;  FOsc = 12MHz, M = 4, P = 2 */
  127   1        PLL48CFG  = 0x23;                         /* M = 4, P = 2 */
  128   1        PLL48CON  = PLLCON_PLLE;                  /* PLL Enable */
  129   1        PLL48FEED = 0xAA;                         /* Feed Sequence 1 */
  130   1        PLL48FEED = 0x55;                         /* Feed Sequence 2 */
  131   1      
  132   1        while ((PLL48STAT & PLLSTAT_PLOCK) == 0); /* Wait for PLL Lock */
  133   1      
  134   1        PLL48CON  = PLLCON_PLLE | PLLCON_PLLC;    /* PLL Enable & Connect */
  135   1        PLL48FEED = 0xAA;                         /* Feed Sequence 1 */
  136   1        PLL48FEED = 0x55;                         /* Feed Sequence 2 */
  137   1      
  138   1        VICVectAddr0 = (unsigned long)USB_ISR;    /* USB Interrupt -> Vector 0 */
  139   1        VICVectCntl0 = 0x20 | 22;                 /* USB Interrupt -> IRQ Slot 0 */
  140   1        VICIntEnable = 1 << 22;                   /* Enable USB Interrupt */
  141   1      
  142   1        DEV_INT_EN = DEV_STAT_INT;                /* Enable Device Status Interrupt */
  143   1      
  144   1      #if 1 /* Partial Manual Reset since Automatic Bus Reset is not working */
  145   1        USB_Reset();
  146   1        USB_SetAddress(0);
  147   1      #endif
  148   1      }
  149          
  150          
  151          /*
  152           *  USB Connect Function
  153           *   Called by the User to Connect/Disconnect USB
  154           *    Parameters:      con:   Connect/Disconnect
  155           *    Return Value:    None
  156           */
  157          
  158          void USB_Connect (BOOL con) {
  159   1        WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(con ? DEV_CON : 0));
  160   1      }
  161          
  162          
  163          /*
  164           *  USB Reset Function
  165           *   Called automatically on USB Reset
  166           *    Return Value:    None
  167           */
  168          
  169          void USB_Reset (void) {
  170   1      #if USB_DMA
                 DWORD n;
               #endif
  173   1      
  174   1        EP_INDEX = 0;
  175   1        MAXPACKET_SIZE = USB_MAX_PACKET0;
  176   1        EP_INDEX = 1;
  177   1        MAXPACKET_SIZE = USB_MAX_PACKET0;
  178   1        while ((DEV_INT_STAT & EP_RLZED_INT) == 0);
  179   1      
  180   1        EP_INT_CLR  = 0xFFFFFFFF;
  181   1        EP_INT_EN   = 0xFFFFFFFF ^ USB_DMA_EP;
  182   1        DEV_INT_CLR = 0xFFFFFFFF;
  183   1        DEV_INT_EN  = DEV_STAT_INT    | EP_SLOW_INT    |
  184   1                     (USB_SOF_EVENT   ? FRAME_INT : 0) |
  185   1                     (USB_ERROR_EVENT ? ERR_INT   : 0);
  186   1      
  187   1      #if USB_DMA
                 UDCA_HEAD   = USB_RAM_ADR;
                 DMA_REQ_CLR = 0xFFFFFFFF;
                 EP_DMA_DIS  = 0xFFFFFFFF;
                 EP_DMA_EN   = USB_DMA_EP;
ARM COMPILER V2.53,  usbhw                                                                 05/09/06  14:20:49  PAGE 4   

                 EOT_INT_CLR = 0xFFFFFFFF;
                 NDD_REQ_INT_CLR = 0xFFFFFFFF;
                 SYS_ERR_INT_CLR = 0xFFFFFFFF;
                 DMA_INT_EN  = 0x00000007;
                 DDMemMap[0] = 0x00000000;
                 DDMemMap[1] = 0x00000000;
                 for (n = 0; n < USB_EP_NUM; n++) {
                   udca[n] = 0;
                   UDCA[n] = 0;
                 }
               #endif
  203   1      }
  204          
  205          
  206          /*
  207           *  USB Suspend Function
  208           *   Called automatically on USB Suspend
  209           *    Return Value:    None
  210           */
  211          
  212          void USB_Suspend (void) {
  213   1        /* Performed by Hardware */
  214   1      }
  215          
  216          
  217          /*
  218           *  USB Resume Function
  219           *   Called automatically on USB Resume
  220           *    Return Value:    None
  221           */
  222          
  223          void USB_Resume (void) {
  224   1        /* Performed by Hardware */
  225   1      }
  226          
  227          
  228          /*
  229           *  USB Remote Wakeup Function
  230           *   Called automatically on USB Remote Wakeup
  231           *    Return Value:    None
  232           */
  233          
  234          void USB_WakeUp (void) {
  235   1      
  236   1        if (USB_DeviceStatus & USB_GETSTATUS_REMOTE_WAKEUP) {
  237   2          WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(DEV_CON));
  238   2        }
  239   1      }
  240          
  241          
  242          /*
  243           *  USB Remote Wakeup Configuration Function
  244           *    Parameters:      cfg:   Enable/Disable
  245           *    Return Value:    None
  246           */
  247          
  248          void USB_WakeUpCfg (BOOL cfg) {
  249   1        cfg;  /* Not needed */
  250   1      }
  251          
  252          
  253          /*
  254           *  USB Set Address Function
  255           *    Parameters:      adr:   USB Address
  256           *    Return Value:    None
  257           */
ARM COMPILER V2.53,  usbhw                                                                 05/09/06  14:20:49  PAGE 5   

  258          
  259          void USB_SetAddress (DWORD adr) {
  260   1        WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /* Don't wait for next */
  261   1        WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /*  Setup Status Phase */
  262   1      }
  263          
  264          
  265          /*
  266           *  USB Configure Function
  267           *    Parameters:      cfg:   Configure/Deconfigure
  268           *    Return Value:    None
  269           */
  270          
  271          void USB_Configure (BOOL cfg) {
  272   1      
  273   1        WrCmdDat(CMD_CFG_DEV, DAT_WR_BYTE(cfg ? CONF_DVICE : 0));
  274   1      
  275   1        REALIZE_EP = 0x00000003;
  276   1        while ((DEV_INT_STAT & EP_RLZED_INT) == 0);
  277   1        DEV_INT_CLR = EP_RLZED_INT;
  278   1      }
  279          
  280          
  281          /*
  282           *  Configure USB Endpoint according to Descriptor
  283           *    Parameters:      pEPD:  Pointer to Endpoint Descriptor
  284           *    Return Value:    None
  285           */
  286          
  287          void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD) {
  288   1        DWORD num;
  289   1      
  290   1        num = EPAdr(pEPD->bEndpointAddress);
  291   1        REALIZE_EP |= (1 << num);
  292   1        EP_INDEX = num;
  293   1        MAXPACKET_SIZE = pEPD->wMaxPacketSize;
  294   1        while ((DEV_INT_STAT & EP_RLZED_INT) == 0);

⌨️ 快捷键说明

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