summaryrefslogtreecommitdiff
path: root/ecos/packages/io/usb/slave/current/doc/usbs-devtab.html
blob: e501954c8cd2c434d0138bbcdfccc472f69b9422 (plain)
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<!-- Copyright (C) 2002 Red Hat, Inc.                                -->
<!-- This material may be distributed only subject to the terms      -->
<!-- and conditions set forth in the Open Publication License, v1.0  -->
<!-- or later (the latest version is presently available at          -->
<!-- http://www.opencontent.org/openpub/).                           -->
<!-- Distribution of substantively modified versions of this         -->
<!-- document is prohibited without the explicit permission of the   -->
<!-- copyright holder.                                               -->
<!-- Distribution of the work or derivative of the work in any       -->
<!-- standard (paper) book form is prohibited unless prior           -->
<!-- permission is obtained from the copyright holder.               -->
<HTML
><HEAD
><TITLE
>Devtab Entries</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
"><LINK
REL="HOME"
TITLE="eCos USB Slave Support"
HREF="io-usb-slave.html"><LINK
REL="PREVIOUS"
TITLE="Starting up a USB Device"
HREF="usbs-start.html"><LINK
REL="NEXT"
TITLE="Receiving Data from the Host"
HREF="usbs-start-rx.html"></HEAD
><BODY
CLASS="REFENTRY"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>eCos USB Slave Support</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="usbs-start.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="usbs-start-rx.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="USBS-DEVTAB"
>Devtab Entries</A
></H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN200"
></A
><H2
>Name</H2
>Devtab Entries&nbsp;--&nbsp;Data endpoint data structure</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN203"
></A
><H2
>Synopsis</H2
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="SYNOPSIS"
>/dev/usb0c
/dev/usb1r
/dev/usb2w</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN205"
></A
><H2
>Devtab Entries</H2
><P
>USB device drivers provide two ways of transferring data between host
and peripheral. The first involves USB-specific functionality such as
<A
HREF="usbs-start-rx.html"
><TT
CLASS="FUNCTION"
>usbs_start_rx_buffer</TT
></A
>.
This provides non-blocking I/O: a transfer is started, and some time
later the device driver will call a supplied completion function. The
second uses the conventional I/O model: there are entries in the
device table corresponding to the various endpoints. Standard calls
such as <TT
CLASS="FUNCTION"
>open</TT
> can then be used to get a suitable
handle. Actual I/O happens via blocking <TT
CLASS="FUNCTION"
>read</TT
> and
<TT
CLASS="FUNCTION"
>write</TT
> calls. In practice the blocking operations
are simply implemented using the underlying non-blocking
functionality.</P
><P
>Each endpoint will have its own devtab entry. The exact names are
controlled by the device driver package, but typically the root will
be <TT
CLASS="LITERAL"
>/dev/usb</TT
>. This is followed by one or more
decimal digits giving the endpoint number, followed by
<TT
CLASS="LITERAL"
>c</TT
> for a control endpoint, <TT
CLASS="LITERAL"
>r</TT
> for
a receive endpoint (host to peripheral), and <TT
CLASS="LITERAL"
>w</TT
> for
a transmit endpoint (peripheral to host). If the target hardware
involves more than one USB device then different roots should be used,
for example <TT
CLASS="LITERAL"
>/dev/usb0c</TT
> and
<TT
CLASS="LITERAL"
>/dev/usb1_0c</TT
>. This may require explicit
manipulation of device driver configuration options by the application
developer.</P
><P
>At present the devtab entry for a control endpoint does not support
any I/O operations. </P
><DIV
CLASS="REFSECT2"
><A
NAME="AEN221"
></A
><H3
><TT
CLASS="FUNCTION"
>write</TT
> operations</H3
><P
><TT
CLASS="FUNCTION"
>cyg_io_write</TT
> and similar functions in
higher-level packages can be used to perform a transfer from
peripheral to host. Successive write operations will not be coalesced.
For example, when doing a 1000 byte write to an endpoint that uses the
bulk transfer protocol this will involve 15 full-size 64-byte packets
and a terminating 40-byte packet. USB device drivers are not expected
to do any locking, and if higher-level code performs multiple
concurrent write operations on a single endpoint then the resulting
behaviour is undefined.</P
><P
>A USB <TT
CLASS="FUNCTION"
>write</TT
> operation will never transfer less
data than specified. It is the responsibility of higher-level code to
ensure that the amount of data being transferred is acceptable to the
host-side code. Usually this will be defined by a higher-level
protocol. If an attempt is made to transfer more data than the host
expects then the resulting behaviour is undefined.</P
><P
>There are two likely error conditions. <TT
CLASS="LITERAL"
>EPIPE</TT
>
indicates that the connection between host and target has been broken.
<TT
CLASS="LITERAL"
>EAGAIN</TT
> indicates that the endpoint has been
stalled, either at the request of the host or by other activity
inside the peripheral.</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN231"
></A
><H3
><TT
CLASS="FUNCTION"
>read</TT
> operations</H3
><P
><TT
CLASS="FUNCTION"
>cyg_io_read</TT
> and similar functions in higher-level
packages can be used to perform a transfer from host to peripheral.
This should be a complete transfer: higher-level protocols should
define an upper bound on the amount of data being transferred, and the
<TT
CLASS="FUNCTION"
>read</TT
> operation should involve at least this
amount of data. The return value will indicate the actual transfer
size, which may be less than requested.</P
><P
>Some device drivers may support partial reads, but USB device drivers
are not expected to perform any buffering because that involves both
memory and code overheads. One technique that may work for bulk
transfers is to exploit the fact that such transfers happen in 64-byte
packets. It is possible to <TT
CLASS="FUNCTION"
>read</TT
> an initial 64
bytes, corresponding to the first packet in the transfer. These 64
bytes can then be examined to determine the total transfer size, and
the remaining data can be transferred in another
<TT
CLASS="FUNCTION"
>read</TT
> operation. This technique is not guaranteed
to work with all USB hardware. Also, if the delay between accepting
the first packet and the remainder of the transfer is excessive then
this could cause timeout problems for the host-side software. For
these reasons the use of partial reads should be avoided.</P
><P
>There are two likely error conditions. <TT
CLASS="LITERAL"
>EPIPE</TT
>
indicates that the connection between host and target has been broken.
<TT
CLASS="LITERAL"
>EAGAIN</TT
> indicates that the endpoint has been
stalled, either at the request of the host or by other activity
inside the peripheral.</P
><P
>USB device drivers are not expected to do any locking. If higher-level
code performs multiple concurrent read operations on a single endpoint
then the resulting behaviour is undefined.</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN244"
></A
><H3
><TT
CLASS="FUNCTION"
>select</TT
> operations</H3
><P
>Typical USB device drivers will not provide any support for
<TT
CLASS="FUNCTION"
>select</TT
>. Consider bulk transfers from the host to
the peripheral. At the USB device driver level there is no way of
knowing in advance how large a transfer will be, so it is not feasible
for the device driver to buffer the entire transfer. It may be
possible to buffer part of the transfer, for example the first 64-byte
packet, and copy this into application space at the start of a
<TT
CLASS="FUNCTION"
>read</TT
>, but this adds code and memory overheads.
Worse, it means that there is an unknown but potentially long delay
between a peripheral accepting the first packet of a transfer and the
remaining packets, which could confuse or upset the host-side
software.</P
><P
>With some USB hardware it may be possible for the device driver to
detect OUT tokens from the host without actually accepting the data,
and this would indicate that a  <TT
CLASS="FUNCTION"
>read</TT
> is likely to
succeed. However, it would not be reliable since the host-side I/O
operation could time out. A similar mechanism could be used to
implement <TT
CLASS="FUNCTION"
>select</TT
> for outgoing data, but again
this would not be reliable.</P
><P
>Some device drivers may provide partial support for
<TT
CLASS="FUNCTION"
>select</TT
> anyway, possibly under the control of a
configuration option. The device driver's documentation should be
consulted for further information. It is also worth noting that the
USB-specific non-blocking API can often be used as an alternative to
<TT
CLASS="FUNCTION"
>select</TT
>.</P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN256"
></A
><H3
><TT
CLASS="FUNCTION"
>get_config</TT
> and
<TT
CLASS="FUNCTION"
>set_config</TT
> operations</H3
><P
>There are no <TT
CLASS="FUNCTION"
>set_config</TT
> or
<TT
CLASS="FUNCTION"
>get_config</TT
> (also known as
<TT
CLASS="FUNCTION"
>ioctl</TT
>) operations defined for USB devices.
Some device drivers may provide hardware-specific facilities this way. </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>Currently the USB-specific functions related to <A
HREF="usbs-halt.html"
>halted endpoints</A
> cannot be accessed readily
via devtab entries. This functionality should probably be made
available via <TT
CLASS="FUNCTION"
>set_config</TT
> and
<TT
CLASS="FUNCTION"
>get_config</TT
>. It may also prove useful to provide
a <TT
CLASS="FUNCTION"
>get_config</TT
> operation that maps from the
devtab entries to the underlying endpoint data structures.</P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="AEN270"
></A
><H3
>Presence</H3
><P
>The devtab entries are optional. If the USB device is accessed
primarily by class-specific code such as the USB-ethernet package and
that package uses the USB-specific API directly, the devtab entries
are redundant. Even if application code does need to access the USB
device, the non-blocking API may be more convenient than the blocking
I/O provided via the devtab entries. In these cases the devtab entries
serve no useful purpose, but they still impose a memory overhead. It
is possible to suppress the presence of these entries by disabling the
configuration option
<TT
CLASS="LITERAL"
>CYGGLO_IO_USB_SLAVE_PROVIDE_DEVTAB_ENTRIES</TT
>.</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="usbs-start.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="io-usb-slave.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="usbs-start-rx.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Starting up a USB Device</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Receiving Data from the Host</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>