1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/** @defgroup usb_defines USB Controller
*
* @brief <b>Defined Constants and Types for the LM4F USB Controller</b>
*
* @ingroup LM4Fxx_defines
*
* @version 1.0.0
*
* @author @htmlonly © @endhtmlonly 2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
*
* @date 15 May 2013
*
* LGPL License Terms @ref lgpl_license
*/
#ifndef LIBOPENCM3_LM4F_USB_H
#define LIBOPENCM3_LM4F_USB_H
/**@{*/
#include <libopencm3/lm4f/memorymap.h>
#include <libopencm3/cm3/common.h>
/* ============================================================================
* USB registers
* --------------------------------------------------------------------------*/
/* USB Device Functional Address */
#define USB_FADDR MMIO8(USB_BASE + 0x00)
/* USB Power */
#define USB_POWER MMIO8(USB_BASE + 0x01)
/* USB Transmit Interrupt Status */
#define USB_TXIS MMIO16(USB_BASE + 0x02)
/* USB Receive Interrupt Status */
#define USB_RXIS MMIO16(USB_BASE + 0x04)
/* USB Transmit Interrupt Enable */
#define USB_TXIE MMIO16(USB_BASE + 0x06)
/* USB Receive Interrupt Enable */
#define USB_RXIE MMIO16(USB_BASE + 0x08)
/* USB General Interrupt Status */
#define USB_IS MMIO8(USB_BASE + 0x0A)
/* USB Interrupt Enable */
#define USB_IE MMIO8(USB_BASE + 0x0B)
/* USB Frame Value */
#define USB_FRAME MMIO16(USB_BASE + 0x0C)
/* USB Endpoint Index */
#define USB_EPIDX MMIO8(USB_BASE + 0x0E)
/* USB Test Mode */
#define USB_TEST MMIO8(USB_BASE + 0x0F)
/* USB FIFO Endpoint [0-7] */
#define USB_FIFO8(n) MMIO8(USB_BASE + 0x20 + n*0x04)
#define USB_FIFO16(n) MMIO16(USB_BASE + 0x20 + n*0x04)
#define USB_FIFO32(n) MMIO32(USB_BASE + 0x20 + n*0x04)
/* USB Transmit Dynamic FIFO Sizing */
#define USB_TXFIFOSZ MMIO8(USB_BASE + 0x62)
/* USB Receive Dynamic FIFO Sizing */
#define USB_RXFIFOSZ MMIO8(USB_BASE + 0x63)
/* USB Transmit FIFO Start Address */
#define USB_TXFIFOADD MMIO16(USB_BASE + 0x64)
/* USB Receive FIFO Start Address */
#define USB_RXFIFOADD MMIO16(USB_BASE + 0x66)
/* USB Connect Timing */
#define USB_CONTIM MMIO8(USB_BASE + 0x7A)
/* USB Full-Speed Last Transaction to End of Frame Timing */
#define USB_FSEOF MMIO8(USB_BASE + 0x7D)
/* USB Low-Speed Last Transaction to End of Frame Timing */
#define USB_LSEOF MMIO8(USB_BASE + 0x7E)
/* USB Control and Status Endpoint 0 Low */
#define USB_CSRL0 MMIO8(USB_BASE + 0x102)
/* USB Control and Status Endpoint 0 High */
#define USB_CSRH0 MMIO8(USB_BASE + 0x103)
/* USB Receive Byte Count Endpoint 0 */
#define USB_COUNT0 MMIO8(USB_BASE + 0x108)
/* USB Maximum Transmit Data Endpoint [1-7] */
#define USB_TXMAXP(n) MMIO16(USB_BASE + 0x100 + (n)*0x10)
/* USB Transmit Control and Status Endpoint [1-7] Low */
#define USB_TXCSRL(n) MMIO8(USB_BASE + 0x102 + (n)*0x10)
/* USB Transmit Control and Status Endpoint [1-7] High */
#define USB_TXCSRH(n) MMIO8(USB_BASE + 0x103 + (n)*0x10)
/* USB Maximum Receive Data Endpoint [1-7] */
#define USB_RXMAXP(n) MMIO16(USB_BASE + 0x104 + (n)*0x10)
/* USB Receive Control and Status Endpoint [1-7] Low */
#define USB_RXCSRL(n) MMIO8(USB_BASE + 0x106 + (n)*0x10)
/* USB Receive Control and Status Endpoint [1-7] High */
#define USB_RXCSRH(n) MMIO8(USB_BASE + 0x107 + (n)*0x10)
/* USB Receive Byte Count Endpoint [1-7] */
#define USB_RXCOUNT(n) MMIO16(USB_BASE + 0x108 + (n)*0x10)
/* USB Receive Double Packet Buffer Disable */
#define USB_RXDPKTBUFDIS MMIO16(USB_BASE + 0x340)
/* USB Transmit Double Packet Buffer Disable */
#define USB_TXDPKTBUFDIS MMIO16(USB_BASE + 0x342)
/* USB Device RESUME Raw Interrupt Status */
#define USB_DRRIS MMIO32(USB_BASE + 0x410)
/* USB Device RESUME Interrupt Mask */
#define USB_DRIM MMIO32(USB_BASE + 0x414)
/* USB Device RESUME Interrupt Status and Clear */
#define USB_DRISC MMIO32(USB_BASE + 0x418)
/* USB DMA Select */
#define USB_DMASEL MMIO32(USB_BASE + 0x450)
/* USB Peripheral Properties */
#define USB_PP MMIO32(USB_BASE + 0xFC0)
/* =============================================================================
* USB_FADDR values
* ---------------------------------------------------------------------------*/
/** Function Address */
#define USB_FADDR_FUNCADDR_MASK (0x3f << 0)
/* =============================================================================
* USB_POWER values
* ---------------------------------------------------------------------------*/
/** Isochronous Update */
#define USB_POWER_ISOUP (1 << 7)
/** Soft Connect/Disconnect */
#define USB_POWER_SOFTCONN (1 << 6)
/** RESET signaling */
#define USB_POWER_RESET (1 << 3)
/** RESUME signaling */
#define USB_POWER_RESUME (1 << 2)
/** SUSPEND mode */
#define USB_POWER_SUSPEND (1 << 1)
/** Power down PHY */
#define USB_POWER_PWRDNPHY (1 << 0)
/* =============================================================================
* Endpoint bitmasks for interrupt status and control registers
* Applies to USB_TXIS, USB_RXIS, USB_TXIE, USB_RXIE, USB_RXDPKTBUFDIS,
* USB_TXDPKTBUFDIS
* ---------------------------------------------------------------------------*/
#define USB_EP7 (1 << 7)
#define USB_EP6 (1 << 6)
#define USB_EP5 (1 << 5)
#define USB_EP4 (1 << 4)
#define USB_EP3 (1 << 3)
#define USB_EP2 (1 << 2)
#define USB_EP1 (1 << 1)
#define USB_EP0 (1 << 0)
/* =============================================================================
* USB interrupt mask values
*
* These are interchangeable across USB_IS, and USB_IE registers.
* ---------------------------------------------------------------------------*/
/** USB disconnect interrupt */
#define USB_IM_DISCON (1 << 5)
/** Start of frame */
#define USB_IM_SOF (1 << 3)
/** RESET signaling detected */
#define USB_IM_RESET (1 << 2)
/** RESUME signaling detected */
#define USB_IM_RESUME (1 << 1)
/** SUSPEND signaling detected */
#define USB_IM_SUSPEND (1 << 0)
/* =============================================================================
* USB_FRAME values
* ---------------------------------------------------------------------------*/
/** Frame number */
#define USB_FRAME_MASK (0x03FF)
/* =============================================================================
* USB_IDX values
* ---------------------------------------------------------------------------*/
/** Endpoint Index */
#define USB_EPIDX_MASK (0x0F)
/* =============================================================================
* USB_TEST values
* ---------------------------------------------------------------------------*/
/** FIFO access */
#define USB_TEST_FIFOACC (1 << 6)
/** Force full-speed mode */
#define USB_TEST_FORCEFS (1 << 5)
/* =============================================================================
* USB_TXFIFOSZ and USB_RXFIFOSZ values
* ---------------------------------------------------------------------------*/
/** Double packet buffer support */
#define USB_FIFOSZ_DPB (1 << 4)
/* USB Transmit Dynamic FIFO Sizing */
#define USB_FIFOSZ_SIZE_MASK (0x0F << 0)
#define USB_FIFOSZ_SIZE_8 (0x00 << 0)
#define USB_FIFOSZ_SIZE_16 (0x01 << 0)
#define USB_FIFOSZ_SIZE_32 (0x02 << 0)
#define USB_FIFOSZ_SIZE_64 (0x03 << 0)
#define USB_FIFOSZ_SIZE_128 (0x04 << 0)
#define USB_FIFOSZ_SIZE_256 (0x05 << 0)
#define USB_FIFOSZ_SIZE_512 (0x06 << 0)
#define USB_FIFOSZ_SIZE_1024 (0x07 << 0)
#define USB_FIFOSZ_SIZE_2048 (0x08 << 0)
/* =============================================================================
* USB_CONTIM values
* ---------------------------------------------------------------------------*/
/** Connect wait */
#define USB_CONTIM_WTCON_MASK (0x0F << 4)
/** Wait ID */
#define USB_CONTIM_WTID_MASK (0x0F << 0)
/* =============================================================================
* USB_CSRL0 values
* ---------------------------------------------------------------------------*/
/** Setup End Clear */
#define USB_CSRL0_SETENDC (1 << 7)
/** RXRDY Clear */
#define USB_CSRL0_RXRDYC (1 << 6)
/** Send Stall */
#define USB_CSRL0_STALL (1 << 5)
/** Setup End */
#define USB_CSRL0_SETEND (1 << 4)
/** Data End */
#define USB_CSRL0_DATAEND (1 << 3)
/** Endpoint Stalled */
#define USB_CSRL0_STALLED (1 << 2)
/** Transmit Packet Ready */
#define USB_CSRL0_TXRDY (1 << 1)
/** Receive Packet Ready */
#define USB_CSRL0_RXRDY (1 << 0)
/* =============================================================================
* USB_CSRH0 values
* ---------------------------------------------------------------------------*/
/** Flush FIFO */
#define USB_CSRH0_FLUSH (1 << 0)
/* =============================================================================
* USB_TXCSRLx values
* ---------------------------------------------------------------------------*/
/** Clear data toggle */
#define USB_TXCSRL_CLRDT (1 << 6)
/** Endpoint Stalled */
#define USB_TXCSRL_STALLED (1 << 5)
/** Send Stall */
#define USB_TXCSRL_STALL (1 << 4)
/** Flush FIFO */
#define USB_TXCSRL_FLUSH (1 << 3)
/** Underrun */
#define USB_TXCSRL_UNDRN (1 << 2)
/** FIFO not empty */
#define USB_TXCSRL_FIFONE (1 << 1)
/** Transmit Packet Ready */
#define USB_TXCSRL_TXRDY (1 << 0)
/* =============================================================================
* USB_TXCSRHx values
* ---------------------------------------------------------------------------*/
/** Auto set */
#define USB_TXCSRH_AUTOSET (1 << 7)
/** Isochronous transfers */
#define USB_TXCSRH_ISO (1 << 6)
/** Mode */
#define USB_TXCSRH_MODE (1 << 5)
/** DMA request enable */
#define USB_TXCSRH_DMAEN (1 << 4)
/** Force data toggle */
#define USB_TXCSRH_FDT (1 << 3)
/** DMA request mode */
#define USB_TXCSRH_DMAMOD (1 << 2)
/* =============================================================================
* USB_RXCSRLx values
* ---------------------------------------------------------------------------*/
/** Clear data toggle */
#define USB_RXCSRL_CLRDT (1 << 7)
/** Endpoint Stalled */
#define USB_RXCSRL_STALLED (1 << 6)
/** Send Stall */
#define USB_RXCSRL_STALL (1 << 5)
/** Flush FIFO */
#define USB_RXCSRL_FLUSH (1 << 4)
/** Data error */
#define USB_RXCSRL_DATAERR (1 << 2)
/** Overrun */
#define USB_RXCSRL_OVER (1 << 2)
/** FIFO full */
#define USB_RXCSRL_FULL (1 << 1)
/** Receive Packet Ready */
#define USB_RXCSRL_RXRDY (1 << 0)
/* =============================================================================
* USB_RXCSRHx values
* ---------------------------------------------------------------------------*/
/** Auto clear */
#define USB_RXCSRH_AUTOCL (1 << 7)
/** Isochronous transfers */
#define USB_RXCSRH_ISO (1 << 6)
/** DMA request enable */
#define USB_RXCSRH_DMAEN (1 << 5)
/** Disable NYET / PID error */
#define USB_RXCSRH_PIDERR (1 << 4)
/** DMA request mode */
#define USB_RXCSRH_DMAMOD (1 << 3)
/* =============================================================================
* USB_DRRIS values
* ---------------------------------------------------------------------------*/
/** RESUME interrupt status */
#define USB_DRRIS_RESUME (1 << 0)
/* =============================================================================
* USB_DRIM values
* ---------------------------------------------------------------------------*/
/** RESUME interrupt mask */
#define USB_DRIM_RESUME (1 << 0)
/* =============================================================================
* USB_DRISC values
* ---------------------------------------------------------------------------*/
/** RESUME interrupt status and clear */
#define USB_DRISC_RESUME (1 << 0)
/* =============================================================================
* USB_PP values
* ---------------------------------------------------------------------------*/
/** Endpoint count */
#define USB_PP_ECNT_MASK (0xFF << 8)
/** USB capability */
#define USB_PP_USB_MASK (0x03 << 6)
#define USB_PP_USB_NA (0x00 << 6)
#define USB_PP_USB_DEVICE (0x01 << 6)
#define USB_PP_USB_HOST (0x02 << 6)
#define USB_PP_USB_OTG (0x03 << 6)
/** PHY present */
#define USB_PP_PHY (1 << 4)
/** Controller type */
#define USB_PP_TYPE_MASK (0x0F << 0)
/* =============================================================================
* Convenience enums
* ---------------------------------------------------------------------------*/
enum usb_interrupt {
USB_INT_DISCON = USB_IM_DISCON,
USB_INT_SOF = USB_IM_SOF,
USB_INT_RESET = USB_IM_RESET,
USB_INT_RESUME = USB_IM_RESUME,
USB_INT_SUSPEND = USB_IM_SUSPEND,
};
enum usb_ep_interrupt {
USB_EP0_INT = USB_EP0,
USB_EP1_INT = USB_EP1,
USB_EP2_INT = USB_EP2,
USB_EP3_INT = USB_EP3,
USB_EP4_INT = USB_EP4,
USB_EP5_INT = USB_EP5,
USB_EP6_INT = USB_EP6,
USB_EP7_INT = USB_EP7,
};
/* =============================================================================
* Function prototypes
* ---------------------------------------------------------------------------*/
BEGIN_DECLS
void usb_enable_interrupts(enum usb_interrupt ints,
enum usb_ep_interrupt rx_ints,
enum usb_ep_interrupt tx_ints);
void usb_disable_interrupts(enum usb_interrupt ints,
enum usb_ep_interrupt rx_ints,
enum usb_ep_interrupt tx_ints);
END_DECLS
/**@}*/
#endif /* LIBOPENCM3_LM4F_USB_H */
|