These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbhw.h Source File

usbhw.h

00001 /*----------------------------------------------------------------------------
00002  *      U S B  -  K e r n e l
00003  *----------------------------------------------------------------------------
00004  *      Name:    USBHW.H
00005  *      Purpose: USB Hardware Layer Definitions
00006  *      Version: V1.10
00007  *----------------------------------------------------------------------------
00008  *      This software is supplied "AS IS" without any warranties, express,
00009  *      implied or statutory, including but not limited to the implied
00010  *      warranties of fitness for purpose, satisfactory quality and
00011  *      noninfringement. Keil extends you a royalty-free right to reproduce
00012  *      and distribute executable files created using this software for use
00013  *      on NXP Semiconductors LPC family microcontroller devices only. Nothing 
00014  *      else gives you the right to use this software.
00015  *
00016  *      Copyright (c) 2005-2009 Keil Software.
00017  *---------------------------------------------------------------------------*/
00018 
00019 #ifndef __USBHW_H__
00020 #define __USBHW_H__
00021 
00022 
00023 /* USB RAM Definitions */
00024 #define USB_RAM_ADR     0x20080000  /* USB RAM Start Address */
00025 #define USB_RAM_SZ      0x00004000  /* USB RAM Size (4kB) */
00026 
00027 /* DMA Endpoint Descriptors */
00028 #define DD_NISO_CNT             16  /* Non-Iso EP DMA Descr. Count (max. 32) */
00029 #define DD_ISO_CNT               8  /* Iso EP DMA Descriptor Count (max. 32) */
00030 #define DD_NISO_SZ    (DD_NISO_CNT * 16)    /* Non-Iso DMA Descr. Size */
00031 #define DD_ISO_SZ     (DD_ISO_CNT  * 20)    /* Iso DMA Descriptor Size */
00032 #define DD_NISO_ADR   (USB_RAM_ADR + 128)   /* Non-Iso DMA Descr. Address */
00033 #define DD_ISO_ADR    (DD_NISO_ADR + DD_NISO_SZ) /* Iso DMA Descr. Address */
00034 #define DD_SZ                 (128 + DD_NISO_SZ + DD_ISO_SZ) /* Descr. Size */
00035 
00036 /* DMA Buffer Memory Definitions */
00037 #define DMA_BUF_ADR   (USB_RAM_ADR + DD_SZ) /* DMA Buffer Start Address */
00038 #define DMA_BUF_SZ    (USB_RAM_SZ  - DD_SZ) /* DMA Buffer Size */
00039 
00040 /* USB Error Codes */
00041 #define USB_ERR_PID         0x0001  /* PID Error */
00042 #define USB_ERR_UEPKT       0x0002  /* Unexpected Packet */
00043 #define USB_ERR_DCRC        0x0004  /* Data CRC Error */
00044 #define USB_ERR_TIMOUT      0x0008  /* Bus Time-out Error */
00045 #define USB_ERR_EOP         0x0010  /* End of Packet Error */
00046 #define USB_ERR_B_OVRN      0x0020  /* Buffer Overrun */
00047 #define USB_ERR_BTSTF       0x0040  /* Bit Stuff Error */
00048 #define USB_ERR_TGL         0x0080  /* Toggle Bit Error */
00049 
00050 /* USB DMA Status Codes */
00051 #define USB_DMA_INVALID     0x0000  /* DMA Invalid - Not Configured */
00052 #define USB_DMA_IDLE        0x0001  /* DMA Idle - Waiting for Trigger */
00053 #define USB_DMA_BUSY        0x0002  /* DMA Busy - Transfer in progress */
00054 #define USB_DMA_DONE        0x0003  /* DMA Transfer Done (no Errors)*/
00055 #define USB_DMA_OVER_RUN    0x0004  /* Data Over Run */
00056 #define USB_DMA_UNDER_RUN   0x0005  /* Data Under Run (Short Packet) */
00057 #define USB_DMA_ERROR       0x0006  /* Error */
00058 #define USB_DMA_UNKNOWN     0xFFFF  /* Unknown State */
00059 
00060 /* USB DMA Descriptor */
00061 typedef struct _USB_DMA_DESCRIPTOR {
00062   uint32_t BufAdr;                     /* DMA Buffer Address */
00063   uint16_t  BufLen;                     /* DMA Buffer Length */
00064   uint16_t  MaxSize;                    /* Maximum Packet Size */
00065   uint32_t InfoAdr;                    /* Packet Info Memory Address */
00066   union {                           /* DMA Configuration */
00067     struct {
00068       uint32_t Link   : 1;             /* Link to existing Descriptors */
00069       uint32_t IsoEP  : 1;             /* Isonchronous Endpoint */
00070       uint32_t ATLE   : 1;             /* ATLE (Auto Transfer Length Extract) */
00071       uint32_t Rsrvd  : 5;             /* Reserved */
00072       uint32_t LenPos : 8;             /* Length Position (ATLE) */
00073     } Type;
00074     uint32_t Val;
00075   } Cfg;
00076 } USB_DMA_DESCRIPTOR;
00077 
00078 /* USB Hardware Functions */
00079 extern void  USB_Init       (void);
00080 extern void  USB_Connect    (uint32_t  con);
00081 extern void  USB_Reset      (void);
00082 extern void  USB_Suspend    (void);
00083 extern void  USB_Resume     (void);
00084 extern void  USB_WakeUp     (void);
00085 extern void  USB_WakeUpCfg  (uint32_t  cfg);
00086 extern void  USB_SetAddress (uint32_t adr);
00087 extern void  USB_Configure  (uint32_t  cfg);
00088 extern void  USB_ConfigEP   (USB_ENDPOINT_DESCRIPTOR *pEPD);
00089 extern void  USB_DirCtrlEP  (uint32_t dir);
00090 extern void  USB_EnableEP   (uint32_t EPNum);
00091 extern void  USB_DisableEP  (uint32_t EPNum);
00092 extern void  USB_ResetEP    (uint32_t EPNum);
00093 extern void  USB_SetStallEP (uint32_t EPNum);
00094 extern void  USB_ClrStallEP (uint32_t EPNum);
00095 extern uint32_t USB_ReadEP     (uint32_t EPNum, uint8_t *pData);
00096 extern uint32_t USB_WriteEP    (uint32_t EPNum, uint8_t *pData, uint32_t cnt);
00097 extern uint32_t  USB_DMA_Setup  (uint32_t EPNum, USB_DMA_DESCRIPTOR *pDD);
00098 extern void  USB_DMA_Enable (uint32_t EPNum);
00099 extern void  USB_DMA_Disable(uint32_t EPNum);
00100 extern uint32_t USB_DMA_Status (uint32_t EPNum);
00101 extern uint32_t USB_DMA_BufAdr (uint32_t EPNum);
00102 extern uint32_t USB_DMA_BufCnt (uint32_t EPNum);
00103 extern uint32_t USB_GetFrame   (void);
00104 extern void  USB_IRQHandler (void);
00105 
00106 
00107 #endif  /* __USBHW_H__ */