📄 usbhw.lst
字号:
ARM COMPILER V2.42b, usbhw 02/01/06 23:45:15 PAGE 1
ARM COMPILER V2.42b, 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.04
7 *----------------------------------------------------------------------------
8 * This file is part of the uVision/ARM development tools.
9 * Copyright (c) 2005 Keil Software. All rights reserved.
10 *---------------------------------------------------------------------------*/
11
12 #include <LPC214X.H> /* LPC214x definitions */
13
14 #include "type.h"
15
16 #include "usb.h"
17 #include "usbcfg.h"
18 #include "usbreg.h"
19 #include "usbhw.h"
20 #include "usbcore.h"
21 #include "usbuser.h"
22
23
24 #define EP_MSK_CTRL 0x0001 /* Control Endpoint Logical Address Mask */
25 #define EP_MSK_BULK 0xC924 /* Bulk Endpoint Logical Address Mask */
26 #define EP_MSK_INT 0x4492 /* Interrupt Endpoint Logical Address Mask */
27 #define EP_MSK_ISO 0x1248 /* Isochronous Endpoint Logical Address Mask */
28
29
30 #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
38
39
40 /*
41 * Get Endpoint Physical Address
42 * Parameters: EPNum: Endpoint Number
43 * EPNum.0..3: Address
44 * EPNum.7: Dir
45 * Return Value: Endpoint Physical Address
46 */
47
48 DWORD EPAdr (DWORD EPNum) {
49 1 DWORD val;
50 1
51 1 val = (EPNum & 0x0F) << 1;
52 1 if (EPNum & 0x80) {
53 2 val += 1;
54 2 }
55 1 return (val);
56 1 }
57
58
59 /*
ARM COMPILER V2.42b, usbhw 02/01/06 23:45:15 PAGE 2
60 * Write Command
61 * Parameters: cmd: Command
62 * Return Value: None
63 */
64
65 void WrCmd (DWORD cmd) {
66 1
67 1 CMD_CODE = cmd;
68 1 while ((DEV_INT_STAT & CCEMTY_INT) == 0);
69 1 DEV_INT_CLR = CCEMTY_INT;
70 1 }
71
72
73 /*
74 * Write Command Data
75 * Parameters: cmd: Command
76 * val: Data
77 * Return Value: None
78 */
79
80 void WrCmdDat (DWORD cmd, DWORD val) {
81 1
82 1 CMD_CODE = cmd;
83 1 while ((DEV_INT_STAT & CCEMTY_INT) == 0);
84 1 DEV_INT_CLR = CCEMTY_INT;
85 1 CMD_CODE = val;
86 1 while ((DEV_INT_STAT & CCEMTY_INT) == 0);
87 1 DEV_INT_CLR = CCEMTY_INT;
88 1 }
89
90
91 /*
92 * Read Command Data
93 * Parameters: cmd: Command
94 * Return Value: Data Value
95 */
96
97 DWORD RdCmdDat (DWORD cmd) {
98 1 DWORD val;
99 1
100 1 DEV_INT_CLR = CDFULL_INT;
101 1 CMD_CODE = cmd;
102 1 while ((DEV_INT_STAT & CCEMTY_INT) == 0);
103 1 DEV_INT_CLR = CCEMTY_INT;
104 1 while ((DEV_INT_STAT & CDFULL_INT) == 0);
105 1 val = CMD_DATA;
106 1 DEV_INT_CLR = CDFULL_INT;
107 1 return (val);
108 1 }
109
110
111 /*
112 * USB Initialize Function
113 * Called by the User to initialize USB
114 * Return Value: None
115 */
116
117 void USB_Init (void) {
118 1
119 1 PCONP |= 0x80000000; /* Turn On USB PCLK */
120 1
121 1 /* Configure 48MHz USB Clock; FOsc = 12MHz, M = 4, P = 2 */
122 1 PLL48CFG = 0x23; /* M = 4, P = 2 */
123 1 PLL48CON = PLLCON_PLLE; /* PLL Enable */
124 1 PLL48FEED = 0xAA; /* Feed Sequence 1 */
125 1 PLL48FEED = 0x55; /* Feed Sequence 2 */
ARM COMPILER V2.42b, usbhw 02/01/06 23:45:15 PAGE 3
126 1
127 1 while ((PLL48STAT & PLLSTAT_PLOCK) == 0); /* Wait for PLL Lock */
128 1
129 1 PLL48CON = PLLCON_PLLE | PLLCON_PLLC; /* PLL Enable & Connect */
130 1 PLL48FEED = 0xAA; /* Feed Sequence 1 */
131 1 PLL48FEED = 0x55; /* Feed Sequence 2 */
132 1
133 1 VICVectAddr0 = (unsigned long)USB_ISR; /* USB Interrupt -> Vector 0 */
134 1 VICVectCntl0 = 0x20 | 22; /* USB Interrupt -> IRQ Slot 0 */
135 1 VICIntEnable = 1 << 22; /* Enable USB Interrupt */
136 1
137 1 DEV_INT_EN = DEV_STAT_INT; /* Enable Device Status Interrupt */
138 1
139 1 #if 1 /* Partial Manual Reset since Automatic Bus Reset is not working */
140 1 USB_Reset();
141 1 USB_SetAddress(0);
142 1 #endif
143 1 }
144
145
146 /*
147 * USB Connect Function
148 * Called by the User to Connect/Disconnect USB
149 * Parameters: con: Connect/Disconnect
150 * Return Value: None
151 */
152
153 void USB_Connect (BOOL con) {
154 1 WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(con ? DEV_CON : 0));
155 1 }
156
157
158 /*
159 * USB Reset Function
160 * Called automatically on USB Reset
161 * Return Value: None
162 */
163
164 void USB_Reset (void) {
165 1 #if USB_DMA
DWORD n;
#endif
168 1
169 1 EP_INDEX = 0;
170 1 MAXPACKET_SIZE = USB_MAX_PACKET0;
171 1 EP_INDEX = 1;
172 1 MAXPACKET_SIZE = USB_MAX_PACKET0;
173 1 while ((DEV_INT_STAT & EP_RLZED_INT) == 0);
174 1
175 1 EP_INT_CLR = 0xFFFFFFFF;
176 1 EP_INT_EN = 0xFFFFFFFF ^ USB_DMA_EP;
177 1 DEV_INT_CLR = 0xFFFFFFFF;
178 1 DEV_INT_EN = DEV_STAT_INT | EP_SLOW_INT |
179 1 (USB_SOF_EVENT ? FRAME_INT : 0) |
180 1 (USB_ERROR_EVENT ? ERR_INT : 0);
181 1
182 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;
ARM COMPILER V2.42b, usbhw 02/01/06 23:45:15 PAGE 4
DDMemMap[1] = 0x00000000;
for (n = 0; n < USB_EP_NUM; n++) {
udca[n] = 0;
UDCA[n] = 0;
}
#endif
198 1 }
199
200
201 /*
202 * USB Suspend Function
203 * Called automatically on USB Suspend
204 * Return Value: None
205 */
206
207 void USB_Suspend (void) {
208 1 /* Performed by Hardware */
209 1 }
210
211
212 /*
213 * USB Resume Function
214 * Called automatically on USB Resume
215 * Return Value: None
216 */
217
218 void USB_Resume (void) {
219 1 /* Performed by Hardware */
220 1 }
221
222
223 /*
224 * USB Remote Wakeup Function
225 * Called automatically on USB Remote Wakeup
226 * Return Value: None
227 */
228
229 void USB_WakeUp (void) {
230 1
231 1 if (USB_DeviceStatus & USB_GETSTATUS_REMOTE_WAKEUP) {
232 2 WrCmdDat(CMD_SET_DEV_STAT, DAT_WR_BYTE(DEV_CON));
233 2 }
234 1 }
235
236
237 /*
238 * USB Remote Wakeup Configuration Function
239 * Parameters: cfg: Enable/Disable
240 * Return Value: None
241 */
242
243 void USB_WakeUpCfg (BOOL cfg) {
244 1 cfg; /* Not needed */
245 1 }
246
247
248 /*
249 * USB Set Address Function
250 * Parameters: adr: USB Address
251 * Return Value: None
252 */
253
254 void USB_SetAddress (DWORD adr) {
255 1 WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /* Don't wait for next */
256 1 WrCmdDat(CMD_SET_ADDR, DAT_WR_BYTE(DEV_EN | adr)); /* Setup Status Phase */
257 1 }
ARM COMPILER V2.42b, usbhw 02/01/06 23:45:15 PAGE 5
258
259
260 /*
261 * USB Configure Function
262 * Parameters: cfg: Configure/Deconfigure
263 * Return Value: None
264 */
265
266 void USB_Configure (BOOL cfg) {
267 1
268 1 WrCmdDat(CMD_CFG_DEV, DAT_WR_BYTE(cfg ? CONF_DVICE : 0));
269 1
270 1 REALIZE_EP = 0x00000003;
271 1 while ((DEV_INT_STAT & EP_RLZED_INT) == 0);
272 1 DEV_INT_CLR = EP_RLZED_INT;
273 1 }
274
275
276 /*
277 * Configure USB Endpoint according to Descriptor
278 * Parameters: pEPD: Pointer to Endpoint Descriptor
279 * Return Value: None
280 */
281
282 void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD) {
283 1 DWORD num;
284 1
285 1 num = EPAdr(pEPD->bEndpointAddress);
286 1 REALIZE_EP |= (1 << num);
287 1 EP_INDEX = num;
288 1 MAXPACKET_SIZE = pEPD->wMaxPacketSize;
289 1 while ((DEV_INT_STAT & EP_RLZED_INT) == 0);
290 1 DEV_INT_CLR = EP_RLZED_INT;
291 1 }
292
293
294 /*
295 * Set Direction for USB Control Endpoint
296 * Parameters: dir: Out (dir == 0), In (dir <> 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -