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

📄 usbhw.lst

📁 将LPC2148通过自带的USB口配置为USB存储设备.
💻 LST
📖 第 1 页 / 共 5 页
字号:
ARM COMPILER V2.50a,  usbhw                                                                04/04/06  11:13:56  PAGE 1   


ARM COMPILER V2.50a, 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.05
    7           *----------------------------------------------------------------------------*/
    8          #include <LPC214X.H>                        /* LPC214x definitions */
    9          
   10          #include "type.h"
   11          
   12          #include "usb.h"
   13          #include "usbcfg.h"
   14          #include "usbreg.h"
   15          #include "usbhw.h"
   16          #include "usbcore.h"
   17          #include "usbuser.h"
   18          
   19          
   20          #define EP_MSK_CTRL 0x0001      /* Control Endpoint Logical Address Mask */
   21          #define EP_MSK_BULK 0xC924      /* Bulk Endpoint Logical Address Mask */
   22          #define EP_MSK_INT  0x4492      /* Interrupt Endpoint Logical Address Mask */
   23          #define EP_MSK_ISO  0x1248      /* Isochronous Endpoint Logical Address Mask */
   24          
   25          
   26          #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
   34          
   35          
   36          /*
   37           *  Get Endpoint Physical Address
   38           *    Parameters:      EPNum: Endpoint Number
   39           *                       EPNum.0..3: Address
   40           *                       EPNum.7:    Dir
   41           *    Return Value:    Endpoint Physical Address
   42           */
   43          
   44          DWORD EPAdr (DWORD EPNum) {
   45   1        DWORD val;
   46   1      
   47   1        val = (EPNum & 0x0F) << 1;
   48   1        if (EPNum & 0x80) {
   49   2          val += 1;
   50   2        }
   51   1        return (val);
   52   1      }
   53          
   54          
   55          /*
   56           *  Write Command
   57           *    Parameters:      cmd:   Command
   58           *    Return Value:    None
   59           */
ARM COMPILER V2.50a,  usbhw                                                                04/04/06  11:13:56  PAGE 2   

   60          
   61          void WrCmd (DWORD cmd) {
   62   1      
   63   1        DEV_INT_CLR = CCEMTY_INT;
   64   1        CMD_CODE = cmd;
   65   1        while ((DEV_INT_STAT & CCEMTY_INT) == 0);
   66   1      }
   67          
   68          
   69          /*
   70           *  Write Command Data
   71           *    Parameters:      cmd:   Command
   72           *                     val:   Data
   73           *    Return Value:    None
   74           */
   75          
   76          void WrCmdDat (DWORD cmd, DWORD val) {
   77   1      
   78   1        DEV_INT_CLR = CCEMTY_INT;
   79   1        CMD_CODE = cmd;
   80   1        while ((DEV_INT_STAT & CCEMTY_INT) == 0);
   81   1        DEV_INT_CLR = CCEMTY_INT;
   82   1        CMD_CODE = val;
   83   1        while ((DEV_INT_STAT & CCEMTY_INT) == 0);
   84   1      }
   85          
   86          
   87          /*
   88           *  Read Command Data
   89           *    Parameters:      cmd:   Command
   90           *    Return Value:    Data Value
   91           */
   92          
   93          DWORD RdCmdDat (DWORD cmd) {
   94   1      
   95   1        DEV_INT_CLR = CCEMTY_INT | CDFULL_INT;
   96   1        CMD_CODE = cmd;
   97   1        while ((DEV_INT_STAT & CDFULL_INT) == 0);
   98   1        return (CMD_DATA);
   99   1      }
  100          
  101          
  102          /*
  103           *  USB Initialize Function
  104           *   Called by the User to initialize USB
  105           *    Return Value:    None
  106           */
  107          
  108          void USB_Init (void) {
  109   1      
  110   1        PINSEL1 &= ~0xC000C000;
  111   1        PINSEL1 |=  0x40004000;                   /* Select USB Link, VBUS */
  112   1      
  113   1        PCONP |= 0x80000000;                      /* Turn On USB PCLK */
  114   1      
  115   1        /* Configure 48MHz USB Clock;  FOsc = 12MHz, M = 4, P = 2 */
  116   1        PLL48CFG  = 0x23;                         /* M = 4, P = 2 */
  117   1        PLL48CON  = PLLCON_PLLE;                  /* PLL Enable */
  118   1        PLL48FEED = 0xAA;                         /* Feed Sequence 1 */
  119   1        PLL48FEED = 0x55;                         /* Feed Sequence 2 */
  120   1      
  121   1        while ((PLL48STAT & PLLSTAT_PLOCK) == 0); /* Wait for PLL Lock */
  122   1      
  123   1        PLL48CON  = PLLCON_PLLE | PLLCON_PLLC;    /* PLL Enable & Connect */
  124   1        PLL48FEED = 0xAA;                         /* Feed Sequence 1 */
  125   1        PLL48FEED = 0x55;                         /* Feed Sequence 2 */
ARM COMPILER V2.50a,  usbhw                                                                04/04/06  11:13:56  PAGE 3   

  126   1      
  127   1        VICVectAddr0 = (unsigned long)USB_ISR;    /* USB Interrupt -> Vector 0 */
  128   1        VICVectCntl0 = 0x20 | 22;                 /* USB Interrupt -> IRQ Slot 0 */
  129   1        VICIntEnable = 1 << 22;                   /* Enable USB Interrupt */
  130   1      
  131   1        DEV_INT_EN = DEV_STAT_INT;                /* Enable Device Status Interrupt */
  132   1      
  133   1      #if 1 /* Partial Manual Reset since Automatic Bus Reset is not working */
  134   1        USB_Reset();
  135   1        USB_SetAddress(0);
  136   1      #endif
  137   1      }
  138          
  139          
  140          /*
  141           *  USB Connect Function
  142           *   Called by the User to Connect/Disconnect USB
  143           *    Parameters:      con:   Connect/Disconnect
  144           *    Return Value:    None
  145           */
  146          
  147          void USB_Connect (BOOL con) {
  148   1        WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(con ? DEV_CON : 0));
  149   1      }
  150          
  151          
  152          /*
  153           *  USB Reset Function
  154           *   Called automatically on USB Reset
  155           *    Return Value:    None
  156           */
  157          
  158          void USB_Reset (void) {
  159   1      #if USB_DMA
                 DWORD n;
               #endif
  162   1      
  163   1        EP_INDEX = 0;
  164   1        MAXPACKET_SIZE = USB_MAX_PACKET0;
  165   1        EP_INDEX = 1;
  166   1        MAXPACKET_SIZE = USB_MAX_PACKET0;
  167   1        while ((DEV_INT_STAT & EP_RLZED_INT) == 0);
  168   1      
  169   1        EP_INT_CLR  = 0xFFFFFFFF;
  170   1        EP_INT_EN   = 0xFFFFFFFF ^ USB_DMA_EP;
  171   1        DEV_INT_CLR = 0xFFFFFFFF;
  172   1        DEV_INT_EN  = DEV_STAT_INT    | EP_SLOW_INT    |
  173   1                     (USB_SOF_EVENT   ? FRAME_INT : 0) |
  174   1                     (USB_ERROR_EVENT ? ERR_INT   : 0);
  175   1      
  176   1      #if USB_DMA
                 UDCA_HEAD   = USB_RAM_ADR;
                 DMA_REQ_CLR = 0xFFFFFFFF;
                 EP_DMA_DIS  = 0xFFFFFFFF;
                 EP_DMA_EN   = USB_DMA_EP;
                 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
ARM COMPILER V2.50a,  usbhw                                                                04/04/06  11:13:56  PAGE 4   

  192   1      }
  193          
  194          
  195          /*
  196           *  USB Suspend Function
  197           *   Called automatically on USB Suspend
  198           *    Return Value:    None
  199           */
  200          
  201          void USB_Suspend (void) {
  202   1        /* Performed by Hardware */
  203   1      }
  204          
  205          
  206          /*
  207           *  USB Resume Function
  208           *   Called automatically on USB Resume
  209           *    Return Value:    None
  210           */
  211          
  212          void USB_Resume (void) {
  213   1        /* Performed by Hardware */
  214   1      }
  215          
  216          
  217          /*
  218           *  USB Remote Wakeup Function
  219           *   Called automatically on USB Remote Wakeup
  220           *    Return Value:    None
  221           */
  222          
  223          void USB_WakeUp (void) {
  224   1      
  225   1        if (USB_DeviceStatus & USB_GETSTATUS_REMOTE_WAKEUP) {
  226   2          WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(DEV_CON));
  227   2        }
  228   1      }
  229          
  230          
  231          /*
  232           *  USB Remote Wakeup Configuration Function
  233           *    Parameters:      cfg:   Enable/Disable
  234           *    Return Value:    None
  235           */
  236          
  237          void USB_WakeUpCfg (BOOL cfg) {
  238   1        cfg;  /* Not needed */
  239   1      }
  240          
  241          
  242          /*
  243           *  USB Set Address Function
  244           *    Parameters:      adr:   USB Address
  245           *    Return Value:    None
  246           */
  247          
  248          void USB_SetAddress (DWORD adr) {
  249   1        WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /* Don't wait for next */
  250   1        WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /*  Setup Status Phase */
  251   1      }
  252          
  253          
  254          /*
  255           *  USB Configure Function
  256           *    Parameters:      cfg:   Configure/Deconfigure
  257           *    Return Value:    None
ARM COMPILER V2.50a,  usbhw                                                                04/04/06  11:13:56  PAGE 5   

  258           */
  259          
  260          void USB_Configure (BOOL cfg) {
  261   1      
  262   1        WrCmdDat(CMD_CFG_DEV, DAT_WR_BYTE(cfg ? CONF_DVICE : 0));
  263   1      
  264   1        REALIZE_EP = 0x00000003;
  265   1        while ((DEV_INT_STAT & EP_RLZED_INT) == 0);
  266   1        DEV_INT_CLR = EP_RLZED_INT;
  267   1      }
  268          
  269          
  270          /*
  271           *  Configure USB Endpoint according to Descriptor
  272           *    Parameters:      pEPD:  Pointer to Endpoint Descriptor
  273           *    Return Value:    None
  274           */
  275          
  276          void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD) {
  277   1        DWORD num;
  278   1      
  279   1        num = EPAdr(pEPD->bEndpointAddress);
  280   1        REALIZE_EP |= (1 << num);
  281   1        EP_INDEX = num;
  282   1        MAXPACKET_SIZE = pEPD->wMaxPacketSize;
  283   1        while ((DEV_INT_STAT & EP_RLZED_INT) == 0);
  284   1        DEV_INT_CLR = EP_RLZED_INT;
  285   1      }
  286          
  287          
  288          /*
  289           *  Set Direction for USB Control Endpoint
  290           *    Parameters:      dir:   Out (dir == 0), In (dir <> 0)
  291           *    Return Value:    None
  292           */
  293          
  294          void USB_DirCtrlEP (DWORD dir) {
  295   1        dir;  /* Not needed */
  296   1      }

⌨️ 快捷键说明

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