1 |
/*---------------------------------------------------------------------------- |
---|
2 |
* U S B - K e r n e l |
---|
3 |
*---------------------------------------------------------------------------- |
---|
4 |
* Name: USBHW.H |
---|
5 |
* Purpose: USB Hardware Layer Definitions |
---|
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 NXP LPC microcontroller devices only. Nothing else gives you |
---|
14 |
* the right to use this software. |
---|
15 |
* |
---|
16 |
* Copyright (c) 2005-2007 Keil Software. |
---|
17 |
*---------------------------------------------------------------------------*/ |
---|
18 |
|
---|
19 |
#ifndef __USBHW_H__ |
---|
20 |
#define __USBHW_H__ |
---|
21 |
|
---|
22 |
|
---|
23 |
/* USB RAM Definitions */ |
---|
24 |
#define USB_RAM_ADR 0x7FD00000 /* USB RAM Start Address */ |
---|
25 |
#define USB_RAM_SZ 0x00002000 /* USB RAM Size (8kB) */ |
---|
26 |
|
---|
27 |
/* DMA Endpoint Descriptors */ |
---|
28 |
#define DD_NISO_CNT 16 /* Non-Iso EP DMA Descr. Count (max. 32) */ |
---|
29 |
#define DD_ISO_CNT 8 /* Iso EP DMA Descriptor Count (max. 32) */ |
---|
30 |
#define DD_NISO_SZ (DD_NISO_CNT * 16) /* Non-Iso DMA Descr. Size */ |
---|
31 |
#define DD_ISO_SZ (DD_ISO_CNT * 20) /* Iso DMA Descriptor Size */ |
---|
32 |
#define DD_NISO_ADR (USB_RAM_ADR + 128) /* Non-Iso DMA Descr. Address */ |
---|
33 |
#define DD_ISO_ADR (DD_NISO_ADR + DD_NISO_SZ) /* Iso DMA Descr. Address */ |
---|
34 |
#define DD_SZ (128 + DD_NISO_SZ + DD_ISO_SZ) /* Descr. Size */ |
---|
35 |
|
---|
36 |
/* DMA Buffer Memory Definitions */ |
---|
37 |
#define DMA_BUF_ADR (USB_RAM_ADR + DD_SZ) /* DMA Buffer Start Address */ |
---|
38 |
#define DMA_BUF_SZ (USB_RAM_SZ - DD_SZ) /* DMA Buffer Size */ |
---|
39 |
|
---|
40 |
/* USB Error Codes */ |
---|
41 |
#define USB_ERR_PID 0x0001 /* PID Error */ |
---|
42 |
#define USB_ERR_UEPKT 0x0002 /* Unexpected Packet */ |
---|
43 |
#define USB_ERR_DCRC 0x0004 /* Data CRC Error */ |
---|
44 |
#define USB_ERR_TIMOUT 0x0008 /* Bus Time-out Error */ |
---|
45 |
#define USB_ERR_EOP 0x0010 /* End of Packet Error */ |
---|
46 |
#define USB_ERR_B_OVRN 0x0020 /* Buffer Overrun */ |
---|
47 |
#define USB_ERR_BTSTF 0x0040 /* Bit Stuff Error */ |
---|
48 |
#define USB_ERR_TGL 0x0080 /* Toggle Bit Error */ |
---|
49 |
|
---|
50 |
/* USB DMA Status Codes */ |
---|
51 |
#define USB_DMA_INVALID 0x0000 /* DMA Invalid - Not Configured */ |
---|
52 |
#define USB_DMA_IDLE 0x0001 /* DMA Idle - Waiting for Trigger */ |
---|
53 |
#define USB_DMA_BUSY 0x0002 /* DMA Busy - Transfer in progress */ |
---|
54 |
#define USB_DMA_DONE 0x0003 /* DMA Transfer Done (no Errors)*/ |
---|
55 |
#define USB_DMA_OVER_RUN 0x0004 /* Data Over Run */ |
---|
56 |
#define USB_DMA_UNDER_RUN 0x0005 /* Data Under Run (Short Packet) */ |
---|
57 |
#define USB_DMA_ERROR 0x0006 /* Error */ |
---|
58 |
#define USB_DMA_UNKNOWN 0xFFFF /* Unknown State */ |
---|
59 |
|
---|
60 |
/* USB DMA Descriptor */ |
---|
61 |
typedef struct _USB_DMA_DESCRIPTOR { |
---|
62 |
DWORD BufAdr; /* DMA Buffer Address */ |
---|
63 |
WORD BufLen; /* DMA Buffer Length */ |
---|
64 |
WORD MaxSize; /* Maximum Packet Size */ |
---|
65 |
DWORD InfoAdr; /* Packet Info Memory Address */ |
---|
66 |
union { /* DMA Configuration */ |
---|
67 |
struct { |
---|
68 |
DWORD Link : 1; /* Link to existing Descriptors */ |
---|
69 |
DWORD IsoEP : 1; /* Isonchronous Endpoint */ |
---|
70 |
DWORD ATLE : 1; /* ATLE (Auto Transfer Length Extract) */ |
---|
71 |
DWORD Rsrvd : 5; /* Reserved */ |
---|
72 |
DWORD LenPos : 8; /* Length Position (ATLE) */ |
---|
73 |
} Type; |
---|
74 |
DWORD Val; |
---|
75 |
} Cfg; |
---|
76 |
} USB_DMA_DESCRIPTOR; |
---|
77 |
|
---|
78 |
/* USB Hardware Functions */ |
---|
79 |
extern void USB_Init (void); |
---|
80 |
extern void USB_Connect (BOOL con); |
---|
81 |
extern void USB_Reset (void); |
---|
82 |
extern void USB_Suspend (void); |
---|
83 |
extern void USB_Resume (void); |
---|
84 |
extern void USB_WakeUp (void); |
---|
85 |
extern void USB_WakeUpCfg (BOOL cfg); |
---|
86 |
extern void USB_SetAddress (DWORD adr); |
---|
87 |
extern void USB_Configure (BOOL cfg); |
---|
88 |
extern void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD); |
---|
89 |
extern void USB_DirCtrlEP (DWORD dir); |
---|
90 |
extern void USB_EnableEP (DWORD EPNum); |
---|
91 |
extern void USB_DisableEP (DWORD EPNum); |
---|
92 |
extern void USB_ResetEP (DWORD EPNum); |
---|
93 |
extern void USB_SetStallEP (DWORD EPNum); |
---|
94 |
extern void USB_ClrStallEP (DWORD EPNum); |
---|
95 |
extern DWORD USB_ReadEP (DWORD EPNum, BYTE *pData); |
---|
96 |
//extern DWORD USB_WriteEP (DWORD EPNum, BYTE *pData, DWORD cnt); |
---|
97 |
extern DWORD __swi(8) USB_WriteEP (DWORD EPNum, BYTE *pData, DWORD cnt); |
---|
98 |
extern BOOL USB_DMA_Setup (DWORD EPNum, USB_DMA_DESCRIPTOR *pDD); |
---|
99 |
extern void USB_DMA_Enable (DWORD EPNum); |
---|
100 |
extern void USB_DMA_Disable(DWORD EPNum); |
---|
101 |
extern DWORD USB_DMA_Status (DWORD EPNum); |
---|
102 |
extern DWORD USB_DMA_BufAdr (DWORD EPNum); |
---|
103 |
extern DWORD USB_DMA_BufCnt (DWORD EPNum); |
---|
104 |
extern DWORD USB_GetFrame (void); |
---|
105 |
extern void USB_ISR (void) __irq; |
---|
106 |
|
---|
107 |
|
---|
108 |
#endif /* __USBHW_H__ */ |
---|