OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [usb/] [slave/] [v2_0/] [doc/] [usbs-intro.html] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
<!-- Copyright (C) 2002 Red Hat, Inc.                                -->
2
<!-- This material may be distributed only subject to the terms      -->
3
<!-- and conditions set forth in the Open Publication License, v1.0  -->
4
<!-- or later (the latest version is presently available at          -->
5
<!-- http://www.opencontent.org/openpub/).                           -->
6
<!-- Distribution of substantively modified versions of this         -->
7
<!-- document is prohibited without the explicit permission of the   -->
8
<!-- copyright holder.                                               -->
9
<!-- Distribution of the work or derivative of the work in any       -->
10
<!-- standard (paper) book form is prohibited unless prior           -->
11
<!-- permission is obtained from the copyright holder.               -->
12
<HTML
13
><HEAD
14
><TITLE
15
>Introduction</TITLE
16
><meta name="MSSmartTagsPreventParsing" content="TRUE">
17
<META
18
NAME="GENERATOR"
19
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
20
"><LINK
21
REL="HOME"
22
TITLE="eCos USB Slave Support"
23
HREF="io-usb-slave.html"><LINK
24
REL="PREVIOUS"
25
TITLE="eCos USB Slave Support"
26
HREF="io-usb-slave.html"><LINK
27
REL="NEXT"
28
TITLE="USB Enumeration Data"
29
HREF="usbs-enum.html"></HEAD
30
><BODY
31
CLASS="REFENTRY"
32
BGCOLOR="#FFFFFF"
33
TEXT="#000000"
34
LINK="#0000FF"
35
VLINK="#840084"
36
ALINK="#0000FF"
37
><DIV
38
CLASS="NAVHEADER"
39
><TABLE
40
WIDTH="100%"
41
BORDER="0"
42
CELLPADDING="0"
43
CELLSPACING="0"
44
><TR
45
><TH
46
COLSPAN="3"
47
ALIGN="center"
48
>eCos USB Slave Support</TH
49
></TR
50
><TR
51
><TD
52
WIDTH="10%"
53
ALIGN="left"
54
VALIGN="bottom"
55
><A
56
HREF="io-usb-slave.html"
57
>Prev</A
58
></TD
59
><TD
60
WIDTH="80%"
61
ALIGN="center"
62
VALIGN="bottom"
63
></TD
64
><TD
65
WIDTH="10%"
66
ALIGN="right"
67
VALIGN="bottom"
68
><A
69
HREF="usbs-enum.html"
70
>Next</A
71
></TD
72
></TR
73
></TABLE
74
><HR
75
ALIGN="LEFT"
76
WIDTH="100%"></DIV
77
><H1
78
><A
79
NAME="USBS-INTRO"
80
>Introduction</A
81
></H1
82
><DIV
83
CLASS="REFNAMEDIV"
84
><A
85
NAME="AEN6"
86
></A
87
><H2
88
>Name</H2
89
>Introduction&nbsp;--&nbsp;eCos support for USB slave devices</DIV
90
><DIV
91
CLASS="REFSECT1"
92
><A
93
NAME="AEN9"
94
></A
95
><H2
96
>Introduction</H2
97
><P
98
>The eCos USB slave support allows developers to produce USB
99
peripherals. It consists of a number of different eCos packages:</P
100
><P
101
></P
102
><OL
103
TYPE="1"
104
><LI
105
><P
106
>Device drivers for specific implementations of USB slave hardware, for
107
example the on-chip USB Device Controller provided by the Intel SA1110
108
processor. A typical USB peripheral will only provide one USB slave
109
port and therefore only one such device driver package will be needed.
110
Usually the device driver package will be loaded automatically when
111
you create an eCos configuration for target hardware that has a USB
112
slave device. If you select a target which does have a USB slave
113
device but no USB device driver is loaded, this implies that no such
114
device driver is currently available.</P
115
></LI
116
><LI
117
><P
118
>The common USB slave package. This serves two purposes. It defines the
119
API that specific device drivers should implement. It also provides
120
various utilities that will be needed by most USB device drivers and
121
applications, such as handlers for standard control messages.
122
Usually this package will be loaded automatically at the same time as
123
the USB device driver.</P
124
></LI
125
><LI
126
><P
127
>The common USB package. This merely provides some information common
128
to both the host and slave sides of USB, such as details of the
129
control protocol. It is also used to place the other USB-related
130
packages appropriately in the overall configuration hierarchy. Usually
131
this package will be loaded at the same time as the USB device driver.</P
132
></LI
133
><LI
134
><P
135
>Class-specific USB support packages. These make it easier to develop
136
specific classes of USB peripheral, such as a USB-ethernet device. If
137
no suitable package is available for a given class of peripheral then
138
the USB device driver can instead be accessed directly from
139
application code. Such packages will never be loaded automatically
140
since the configuration system has no way of knowing what class of USB
141
peripheral is being developed. Instead developers have to add the
142
appropriate package or packages explicitly.</P
143
></LI
144
></OL
145
><P
146
>These packages only provide support for developing USB peripherals,
147
not USB hosts.</P
148
></DIV
149
><DIV
150
CLASS="REFSECT1"
151
><A
152
NAME="AEN22"
153
></A
154
><H2
155
>USB Concepts</H2
156
><P
157
>Information about USB can be obtained from a number of sources
158
including the <A
159
HREF="http://www.usb.org/"
160
TARGET="_top"
161
>USB Implementers Forum
162
web site</A
163
>. Only a brief summary is provided here.</P
164
><P
165
>A USB network is asymmetrical: it consists of a single host, one or
166
more slave devices, and possibly some number of intermediate hubs. The
167
host side is significantly more complicated than the slave side.
168
Essentially, all operations are initiated by the host. For example, if
169
the host needs to receive some data from a particular USB peripheral
170
then it will send an IN token to that peripheral; the latter should
171
respond with either a NAK or with appropriate data. Similarly, when
172
the host wants to transmit data to a peripheral it will send an OUT
173
token followed by the data; the peripheral will return a NAK if it is
174
currently unable to receive more data or if there was corruption,
175
otherwise it will return an ACK. All transfers are check-summed and
176
there is a clearly-defined error recovery process. USB peripherals can
177
only interact with the host, not with each other.</P
178
><P
179
>USB supports four different types of communication: control messages,
180
interrupt transfers, isochronous transfers, and bulk transfers.
181
Control messages are further subdivided into four categories:
182
standard, class, vendor and a reserved category. All USB peripherals
183
must respond to certain standard control messages, and usually this
184
will be handled by the common USB slave package (for complicated
185
peripherals, application support will be needed). Class and vendor
186
control messages may be handled by an class-specific USB support
187
package, for example the USB-ethernet package will handle control
188
messages such as getting the MAC address or enabling/disabling
189
promiscuous mode. Alternatively, some or all of these messages will
190
have to be handled by application code.</P
191
><P
192
>Interrupt transfers are used for devices which need to be polled
193
regularly. For example, a USB keyboard might be polled once every
194
millisecond. The host will not poll the device more frequently than
195
this, so interrupt transfers are best suited to peripherals that
196
involve a relatively small amount of data. Isochronous transfers are
197
intended for multimedia-related peripherals where typically a large
198
amount of video or audio data needs to be exchanged continuously.
199
Given appropriate host support a USB peripheral can reserve some of
200
the available bandwidth. Isochronous transfers are not reliable; if a
201
particular packet is corrupted then it will just be discarded and
202
software is expected to recover from this. Bulk transfers are used for
203
everything else: after taking care of any pending control, isochronous
204
and interrupt transfers the host will use whatever bandwidth remains
205
for bulk transfers. Bulk transfers are reliable.</P
206
><P
207
>Transfers are organized into USB packets, with the details depending
208
on the transfer type. Control messages always involve an initial
209
8-byte packet from host to peripheral, optionally followed by some
210
additional packets; in theory these additional packets can be up to 64
211
bytes, but hardware may limit it to 8 bytes. Interrupt transfers
212
involve a single packet of up to 64 bytes. Isochronous transfers
213
involve a single packet of up to 1024 bytes. Bulk transfers involve
214
multiple packets. There will be some number, possibly zero, of 64-byte
215
packets. The transfer is terminated by a single packet of less than 64
216
bytes. If the transfer involves an exact multiple of 64 bytes than the
217
final packet will be 0 bytes, consisting of just a header and checksum
218
which typically will be generated by the hardware. There is no
219
pre-defined limit on the size of a bulk transfer. Instead higher-level
220
protocols are expected to handle this, so for a USB-ethernet
221
peripheral the protocol could impose a limit of 1514 bytes of data
222
plus maybe some additional protocol overhead.</P
223
><P
224
>Transfers from the host to a peripheral are addressed not just to that
225
peripheral but to a specific endpoint within that peripheral.
226
Similarly, the host requests incoming data from a specific endpoint
227
rather than from the peripheral as a whole. For example, a combined
228
keyboard/touchpad device could provide the keyboard events on endpoint
229
1 and the mouse events on endpoint 2. A given USB peripheral can have
230
up to 16 endpoints for incoming data and another 16 for outgoing data.
231
However, given the comparatively high speed of USB I/O this endpoint
232
addressing is typically implemented in hardware rather than software,
233
and the hardware will only implement a small number of endpoints.
234
Endpoint 0 is generally used only for control messages.</P
235
><P
236
>In practice, many of these details are irrelevant to application code
237
or to class packages. Instead, such higher-level code usually just
238
performs blocking <TT
239
CLASS="FUNCTION"
240
>read</TT
241
> and
242
<TT
243
CLASS="FUNCTION"
244
>write</TT
245
>, or non-blocking USB-specific calls, to
246
transfer data between host and target via a specific endpoint. Control
247
messages are more complicated but are usually handled by existing
248
code.</P
249
><P
250
>When a USB peripheral is plugged into the host there is an initial
251
enumeration and configuration process. The peripheral provides
252
information such as its class of device (audio, video, etc.), a
253
vendor id, which endpoints should be used for what kind of data, and
254
so on. The host OS uses this information to identify a suitable host
255
device driver. This could be a generic driver for a class of
256
peripherals, or it could be a vendor-specific driver. Assuming a
257
suitable driver is installed the host will then activate the USB
258
peripheral and perform additional application-specific initialisation.
259
For example for a USB-ethernet device this would involve obtaining an
260
ethernet MAC address. Most USB peripherals will be fairly simple, but
261
it is possible to build multifunction peripherals with multiple
262
configurations, interfaces, and alternate interface settings.</P
263
><P
264
>It is not possible for any of the eCos packages to generate all the
265
enumeration data automatically. Some of the required information such
266
as the vendor id cannot be supplied by generic packages; only by the
267
application developer. Class support code such as the USB-ethernet
268
package could in theory supply some of the information automatically,
269
but there are also hardware dependencies such as which endpoints get
270
used for incoming and outgoing ethernet frames. Instead it is the
271
responsibility of the application developer to provide all the
272
enumeration data and perform some additional initialisation. In
273
addition, the common USB slave package can handle all the standard
274
control messages for a simple USB peripheral, but for something like a
275
multifunction peripheral additional application support is needed.</P
276
><DIV
277
CLASS="NOTE"
278
><BLOCKQUOTE
279
CLASS="NOTE"
280
><P
281
><B
282
>Note: </B
283
>The initial implementation of the eCos USB slave packages involved
284
hardware that only supported control and bulk transfers, not
285
isochronous or interrupt. There may be future changes to the USB
286
code and API to allow for isochronous and interrupt transfers,
287
especially the former. Other changes may be required to support
288
different USB devices. At present there is no support for USB remote
289
wakeups, since again it is not supported by the hardware.</P
290
></BLOCKQUOTE
291
></DIV
292
></DIV
293
><DIV
294
CLASS="REFSECT1"
295
><A
296
NAME="AEN38"
297
></A
298
><H2
299
>eCos USB I/O Facilities</H2
300
><P
301
>For protocols other than control messages, eCos provides two ways of
302
performing USB I/O. The first involves device table or devtab entries such
303
as <A
304
HREF="usbs-devtab.html"
305
><TT
306
CLASS="LITERAL"
307
>/dev/usb1r</TT
308
></A
309
>,
310
with one entry per endpoint per USB device. It is possible to
311
<TT
312
CLASS="FUNCTION"
313
>open</TT
314
> these devices and use conventional blocking
315
I/O functions such as <TT
316
CLASS="FUNCTION"
317
>read</TT
318
> and
319
<TT
320
CLASS="FUNCTION"
321
>write</TT
322
> to exchange data between host and
323
peripheral.</P
324
><P
325
>There is also a lower-level USB-specific API, consisting of functions
326
such as <A
327
HREF="usbs-start-rx.html"
328
><TT
329
CLASS="FUNCTION"
330
>usbs_start_rx_buffer</TT
331
></A
332
>.
333
A USB device driver will supply a data structure for each endpoint,
334
for example a <A
335
HREF="usbs-data.html"
336
><SPAN
337
CLASS="STRUCTNAME"
338
>usbs_rx_endpoint</SPAN
339
></A
340
>
341
structure for every receive endpoint. The first argument to
342
<TT
343
CLASS="FUNCTION"
344
>usbs_start_rx_buffer</TT
345
> should be a pointer to such
346
a data structure. The USB-specific API is non-blocking: the initial
347
call merely starts the transfer; some time later, once the transfer
348
has completed or has been aborted, the device driver will invoke a
349
completion function.</P
350
><P
351
>Control messages are different. With four different categories of
352
control messages including application and vendor specific ones, the
353
conventional
354
<TT
355
CLASS="FUNCTION"
356
>open</TT
357
>/<TT
358
CLASS="FUNCTION"
359
>read</TT
360
>/<TT
361
CLASS="FUNCTION"
362
>write</TT
363
>
364
model of I/O cannot easily be applied. Instead, a USB device driver
365
will supply a <A
366
HREF="usbs-control.html"
367
><SPAN
368
CLASS="STRUCTNAME"
369
>usbs_control_endpoint</SPAN
370
></A
371
>
372
data structure which can be manipulated appropriately. In practice the
373
standard control messages will usually be handled by the common USB
374
slave package, and other control messages will be handled by
375
class-specific code such as the USB-ethernet package. Typically,
376
application code remains responsible for supplying the <A
377
HREF="usbs-enum.html"
378
>enumeration data</A
379
> and for actually <A
380
HREF="usbs-start.html"
381
>starting</A
382
> up the USB device.</P
383
></DIV
384
><DIV
385
CLASS="REFSECT1"
386
><A
387
NAME="AEN60"
388
></A
389
><H2
390
>Enabling the USB code</H2
391
><P
392
>If the target hardware contains a USB slave device then the
393
appropriate USB device driver and the common packages will typically
394
be loaded into the configuration automatically when that target is
395
selected (assuming a suitable device driver exists). However, the
396
driver will not necessarily be active. For example a processor might
397
have an on-chip USB device, but not all applications using that
398
processor will want to use USB functionality. Hence by default the USB
399
device is disabled, ensuring that applications do not suffer any
400
memory or other penalties for functionality that is not required.</P
401
><P
402
>If the application developer explicitly adds a class support package
403
such as the USB-ethernet one then this implies that the USB device is
404
actually needed, and the device will be enabled automatically.
405
However, if no suitable class package is available and the USB device
406
will instead be accessed by application code, it is necessary to
407
enable the USB device manually. Usually the easiest way to do this is
408
to enable the configuration option
409
<TT
410
CLASS="LITERAL"
411
>CYGGLO_IO_USB_SLAVE_APPLICATION</TT
412
>, and the USB device
413
driver and related packages will adjust accordingly. Alternatively,
414
the device driver may provide some configuration options to provide
415
more fine-grained control.</P
416
></DIV
417
><DIV
418
CLASS="NAVFOOTER"
419
><HR
420
ALIGN="LEFT"
421
WIDTH="100%"><TABLE
422
WIDTH="100%"
423
BORDER="0"
424
CELLPADDING="0"
425
CELLSPACING="0"
426
><TR
427
><TD
428
WIDTH="33%"
429
ALIGN="left"
430
VALIGN="top"
431
><A
432
HREF="io-usb-slave.html"
433
>Prev</A
434
></TD
435
><TD
436
WIDTH="34%"
437
ALIGN="center"
438
VALIGN="top"
439
><A
440
HREF="io-usb-slave.html"
441
>Home</A
442
></TD
443
><TD
444
WIDTH="33%"
445
ALIGN="right"
446
VALIGN="top"
447
><A
448
HREF="usbs-enum.html"
449
>Next</A
450
></TD
451
></TR
452
><TR
453
><TD
454
WIDTH="33%"
455
ALIGN="left"
456
VALIGN="top"
457
>eCos USB Slave Support</TD
458
><TD
459
WIDTH="34%"
460
ALIGN="center"
461
VALIGN="top"
462
>&nbsp;</TD
463
><TD
464
WIDTH="33%"
465
ALIGN="right"
466
VALIGN="top"
467
>USB Enumeration Data</TD
468
></TR
469
></TABLE
470
></DIV
471
></BODY
472
></HTML
473
>

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.