?? usbhw.lst
字號:
ARM COMPILER V2.53, usbhw 02/11/07 08:22:50 PAGE 1
ARM COMPILER V2.53, COMPILATION OF MODULE usbhw
OBJECT MODULE PLACED IN usbhw.OBJ
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe usbhw.c THUMB DEBUG PRINT(.\LST\USBHW.LST) TABS(4)
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 Atmel AT91SAM7S
6 * Version: V1.10
7 *----------------------------------------------------------------------------
8 * This file is part of the uVision/ARM development tools.
9 * Copyright (c) 2005-2006 Keil Software. All rights reserved.
10 * This software may only be used under the terms of a valid, current,
11 * end user licence from KEIL for a compatible version of KEIL software
12 * development tools. Nothing else gives you the right to use it.
13 *---------------------------------------------------------------------------*/
14
15 #include <AT91SAM7S64.H> /* AT91SAM7S64 definitions */
16
17 #include "type.h"
18
19 #include "usb.h"
20 #include "usbcfg.h"
21 #include "usbhw.h"
22 #include "usbuser.h"
23
24
25 const BYTE DualBankEP = 0x06; /* Dual Bank Endpoint Bit Mask */
26
27 const DWORD RX_DATA_BK[2] = {AT91C_UDP_RX_DATA_BK0,
28 AT91C_UDP_RX_DATA_BK1 };
29
30 AT91PS_UDP pUDP = AT91C_BASE_UDP; /* Global UDP Pointer */
31
32 BYTE RxDataBank[USB_EP_NUM];
33 BYTE TxDataBank[USB_EP_NUM];
34
35
36 /*
37 * USB Initialize Function
38 * Called by the User to initialize USB
39 * Return Value: None
40 */
41
42 void USB_Init (void) {
43 1
44 1 /* Enables the 48MHz USB Clock UDPCK and System Peripheral USB Clock */
45 1 AT91C_BASE_PMC->PMC_SCER = AT91C_PMC_UDP;
46 1 AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_UDP);
47 1
48 1 /* Global USB Interrupt: Mode and Vector with Highest Priority and Enable */
49 1 AT91C_BASE_AIC->AIC_SMR[AT91C_ID_UDP] = AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED |
50 1 AT91C_AIC_PRIOR_HIGHEST;
51 1 AT91C_BASE_AIC->AIC_SVR[AT91C_ID_UDP] = (unsigned long) USB_ISR;
52 1 AT91C_BASE_AIC->AIC_IECR = (1 << AT91C_ID_UDP);
53 1
54 1 /* UDP PullUp (USB_DP_PUP): PA16 Pin */
55 1 /* Configure as Output and Set to disable Pull-up Resistor */
56 1 AT91C_BASE_PIOA->PIO_PER = AT91C_PIO_PA16;
57 1 AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA16;
58 1 AT91C_BASE_PIOA->PIO_OER = AT91C_PIO_PA16;
59 1 }
ARM COMPILER V2.53, usbhw 02/11/07 08:22:50 PAGE 2
60
61
62 /*
63 * USB Connect Function
64 * Called by the User to Connect/Disconnect USB
65 * Parameters: con: Connect/Disconnect
66 * Return Value: None
67 */
68
69 void USB_Connect (BOOL con) {
70 1
71 1 if (con) {
72 2 /* Enable UDP PullUp (USB_DP_PUP) */
73 2 AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA16;
74 2 } else {
75 2 /* Disable UDP PullUp (USB_DP_PUP) */
76 2 AT91C_BASE_PIOA->PIO_SODR = AT91C_PIO_PA16;
77 2 }
78 1 }
79
80
81 /*
82 * USB Reset Function
83 * Called automatically on USB Reset
84 * Return Value: None
85 */
86
87 void USB_Reset (void) {
88 1 DWORD n;
89 1
90 1 /* Global USB Reset */
91 1 pUDP->UDP_GLBSTATE &= ~(AT91C_UDP_FADDEN | AT91C_UDP_CONFG | AT91C_UDP_RMWUPE);
92 1 pUDP->UDP_FADDR = AT91C_UDP_FEN;
93 1 pUDP->UDP_ICR = 0xFFFFFFFF;
94 1
95 1 /* Reset & Disable USB Endpoints */
96 1 for (n = 0; n < USB_EP_NUM; n++) {
97 2 pUDP->UDP_CSR[n] = 0;
98 2 RxDataBank[n] = 0;
99 2 TxDataBank[n] = 0;
100 2 }
101 1 pUDP->UDP_RSTEP = 0xFFFFFFFF;
102 1 pUDP->UDP_RSTEP = 0;
103 1
104 1 /* Setup USB Interrupts */
105 1 pUDP->UDP_IER = AT91C_UDP_RXSUSP | AT91C_UDP_RXRSM | AT91C_UDP_EXTRSM |
106 1 AT91C_UDP_SOFINT | (2^USB_EP_NUM - 1);
107 1
108 1 /* Setup Control Endpoint 0 */
109 1 pUDP->UDP_CSR[0] = AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_CTRL;
110 1 }
111
112 /*
113 * USB Suspend Function
114 * Called automatically on USB Suspend
115 * Return Value: None
116 */
117
118 void USB_Suspend (void) {
119 1 /* Performed by Hardware */
120 1 }
121
122 /*
123 * USB Resume Function
124 * Called automatically on USB Resume
125 * Return Value: None
ARM COMPILER V2.53, usbhw 02/11/07 08:22:50 PAGE 3
126 */
127
128 void USB_Resume (void) {
129 1 /* Performed by Hardware */
130 1 }
131
132 /*
133 * USB Remote Wakeup Function
134 * Called automatically on USB Remote Wakeup
135 * Return Value: None
136 */
137
138 void USB_WakeUp (void) {
139 1 /* Performed by Hardware */
140 1 }
141
142 /*
143 * USB Remote Wakeup Configuration Function
144 * Parameters: cfg: Enable/Disable
145 * Return Value: None
146 */
147
148 void USB_WakeUpCfg (BOOL cfg) {
149 1
150 1 if (cfg) {
151 2 pUDP->UDP_GLBSTATE |= AT91C_UDP_RMWUPE;
152 2 } else {
153 2 pUDP->UDP_GLBSTATE &= ~AT91C_UDP_RMWUPE;
154 2 }
155 1 }
156
157
158 /*
159 * USB Set Address Function
160 * Parameters: adr: USB Address
161 * Return Value: None
162 */
163
164 void USB_SetAddress (DWORD adr) {
165 1
166 1 pUDP->UDP_FADDR = AT91C_UDP_FEN | adr;
167 1 if (adr) {
168 2 pUDP->UDP_GLBSTATE |= AT91C_UDP_FADDEN;
169 2 } else {
170 2 pUDP->UDP_GLBSTATE &= ~AT91C_UDP_FADDEN;
171 2 }
172 1 }
173
174
175 /*
176 * USB Configure Function
177 * Parameters: cfg: Configure/Deconfigure
178 * Return Value: None
179 */
180
181 void USB_Configure (BOOL cfg) {
182 1
183 1 if (cfg) {
184 2 pUDP->UDP_GLBSTATE |= AT91C_UDP_CONFG;
185 2 } else {
186 2 pUDP->UDP_GLBSTATE &= ~AT91C_UDP_CONFG;
187 2 }
188 1 }
189
190
191 /*
ARM COMPILER V2.53, usbhw 02/11/07 08:22:50 PAGE 4
192 * Configure USB Endpoint according to Descriptor
193 * Parameters: pEPD: Pointer to Endpoint Descriptor
194 * Return Value: None
195 */
196
197 void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR *pEPD) {
198 1 DWORD num, dir;
199 1
200 1 num = pEPD->bEndpointAddress & 0x0F;
201 1 dir = pEPD->bEndpointAddress & USB_ENDPOINT_DIRECTION_MASK;
202 1
203 1 switch (pEPD->bmAttributes & USB_ENDPOINT_TYPE_MASK) {
204 2 case USB_ENDPOINT_TYPE_CONTROL:
205 2 pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_CTRL;
206 2 break;
207 2 case USB_ENDPOINT_TYPE_ISOCHRONOUS:
208 2 if (dir) {
209 3 pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_ISO_IN;
210 3 } else {
211 3 pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_ISO_OUT;
212 3 }
213 2 break;
214 2 case USB_ENDPOINT_TYPE_BULK:
215 2 if (dir) {
216 3 pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_BULK_IN;
217 3 } else {
218 3 pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_BULK_OUT;
219 3 }
220 2 break;
221 2 case USB_ENDPOINT_TYPE_INTERRUPT:
222 2 if (dir) {
223 3 pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_INT_IN;
224 3 } else {
225 3 pUDP->UDP_CSR[num] = AT91C_UDP_EPTYPE_INT_OUT;
226 3 }
227 2 break;
228 2 default:
229 2 pUDP->UDP_CSR[num] = 0;
230 2 break;
231 2 }
232 1 }
233 /*
234 * Set Direction for USB Control Endpoint
235 * Parameters: dir: Out (dir == 0), In (dir <> 0)
236 * Return Value: None
237 */
238
239 void USB_DirCtrlEP (DWORD dir) {
240 1
241 1 if (dir ) {
242 2 pUDP->UDP_CSR[0] |= AT91C_UDP_DIR;
243 2 } else {
244 2 pUDP->UDP_CSR[0] &= ~AT91C_UDP_DIR;
245 2 }
246 1 pUDP->UDP_CSR[0] &= ~AT91C_UDP_RXSETUP;
247 1 }
248
249 /*
250 * Enable USB Endpoint
251 * Parameters: EPNum: Endpoint Number
252 * EPNum.0..3: Address
253 * EPNum.7: Dir
254 * Return Value: None
255 */
256
257 void USB_EnableEP (DWORD EPNum) {
ARM COMPILER V2.53, usbhw 02/11/07 08:22:50 PAGE 5
258 1 pUDP->UDP_CSR[EPNum & 0x0F] |= AT91C_UDP_EPEDS;
259 1 }
260
261 /*
262 * Disable USB Endpoint
263 * Parameters: EPNum: Endpoint Number
264 * EPNum.0..3: Address
265 * EPNum.7: Dir
266 * Return Value: None
267 */
268
269 void USB_DisableEP (DWORD EPNum) {
270 1 pUDP->UDP_CSR[EPNum & 0x0F] &= ~AT91C_UDP_EPEDS;
271 1 }
272
273
274 #define AT91C_UDP_STALLSENT AT91C_UDP_ISOERROR
275
276 /*
277 * Reset USB Endpoint
278 * Parameters: EPNum: Endpoint Number
279 * EPNum.0..3: Address
280 * EPNum.7: Dir
281 * Return Value: None
282 */
283
284 void USB_ResetEP (DWORD EPNum) {
285 1
286 1 EPNum &= 0x0F;
287 1 pUDP->UDP_CSR[EPNum] &= ~(AT91C_UDP_TXCOMP | AT91C_UDP_RXSETUP |
288 1 AT91C_UDP_RX_DATA_BK0 | AT91C_UDP_RX_DATA_BK1 |
289 1 AT91C_UDP_TXPKTRDY | AT91C_UDP_FORCESTALL |
290 1 AT91C_UDP_STALLSENT);
291 1 pUDP->UDP_RSTEP |= 1 << EPNum;
292 1 pUDP->UDP_RSTEP &= ~(1 << EPNum);
293 1 RxDataBank[EPNum] = 0;
294 1 TxDataBank[EPNum] = 0;
295 1 }
296
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -