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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [usb/] [slave/] [current/] [doc/] [usbs-start-tx.html] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
<!-- Copyright (C) 2002 Free Software Foundation, 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
>Sending Data to the Host</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="Receiving Data from the Host"
26
HREF="usbs-start-rx.html"><LINK
27
REL="NEXT"
28
TITLE="Halted Endpoints"
29
HREF="usbs-halt.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="usbs-start-rx.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-halt.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-START-TX"
80
>Sending Data to the Host</A
81
></H1
82
><DIV
83
CLASS="REFNAMEDIV"
84
><A
85
NAME="AEN349"
86
></A
87
><H2
88
>Name</H2
89
><TT
90
CLASS="FUNCTION"
91
>usbs_start_tx_buffer</TT
92
>&nbsp;--&nbsp;Sending Data to the Host</DIV
93
><DIV
94
CLASS="REFSYNOPSISDIV"
95
><A
96
NAME="AEN353"
97
></A
98
><H2
99
>Synopsis</H2
100
><DIV
101
CLASS="FUNCSYNOPSIS"
102
><A
103
NAME="AEN354"
104
></A
105
><P
106
></P
107
><TABLE
108
BORDER="0"
109
BGCOLOR="#E0E0E0"
110
WIDTH="100%"
111
><TR
112
><TD
113
><PRE
114
CLASS="FUNCSYNOPSISINFO"
115
>#include &lt;cyg/io/usb/usbs.h&gt;</PRE
116
></TD
117
></TR
118
></TABLE
119
><P
120
><CODE
121
><CODE
122
CLASS="FUNCDEF"
123
>void usbs_start_tx_buffer</CODE
124
>(usbs_tx_endpoint* ep, const unsigned char* buffer, int length, void (*)(void*,int) complete_fn, void * complete_data);</CODE
125
></P
126
><P
127
><CODE
128
><CODE
129
CLASS="FUNCDEF"
130
>void usbs_start_tx</CODE
131
>(usbs_tx_endpoint* ep);</CODE
132
></P
133
><P
134
></P
135
></DIV
136
></DIV
137
><DIV
138
CLASS="REFSECT1"
139
><A
140
NAME="AEN374"
141
></A
142
><H2
143
><TT
144
CLASS="FUNCTION"
145
>Description</TT
146
></H2
147
><P
148
><TT
149
CLASS="FUNCTION"
150
>usbs_start_tx_buffer</TT
151
> is a USB-specific function
152
to transfer data from peripheral to host. It can be used for bulk,
153
interrupt or isochronous transfers, but not for control messages;
154
instead those involve manipulating the <A
155
HREF="usbs-control.html"
156
><SPAN
157
CLASS="STRUCTNAME"
158
>usbs_control_endpoint</SPAN
159
></A
160
>
161
data structure directly. The function takes five arguments:</P
162
><P
163
></P
164
><OL
165
TYPE="1"
166
><LI
167
><P
168
>The first argument identifies the specific endpoint that should be
169
used. Different USB devices will support different sets of endpoints
170
and the device driver will provide appropriate data structures. The
171
device driver's documentation should be consulted for details of which
172
endpoints are available.</P
173
></LI
174
><LI
175
><P
176
>The <TT
177
CLASS="PARAMETER"
178
><I
179
>buffer</I
180
></TT
181
> and <TT
182
CLASS="PARAMETER"
183
><I
184
>length</I
185
></TT
186
>
187
arguments control the actual transfer. USB device drivers are not
188
allowed to modify the buffer during the transfer, so the data can
189
reside in read-only memory. The transfer will be for all the data
190
specified, and it is the responsibility of higher-level code to make
191
sure that the host is expecting this amount of data. For isochronous
192
transfers the USB specification imposes an upper bound of 1023 bytes,
193
but a smaller limit may be set in the <A
194
HREF="usbs-enum.html#AEN142"
195
>enumeration data</A
196
>. Interrupt
197
transfers have an upper bound of 64 bytes or less, as per the
198
enumeration data. Bulk transfers are more complicated because they can
199
involve multiple 64-byte packets plus a terminating packet of less
200
than 64 bytes, so the basic USB specification does not impose an upper
201
limit on the total transfer size. Instead it is left to higher-level
202
protocols to specify an appropriate upper bound. If the peripheral
203
attempts to send more data than the host is willing to accept then the
204
resulting behaviour is undefined and may well depend on the specific
205
host operating system being used.</P
206
><P
207
>For bulk transfers, the USB device driver or the underlying hardware
208
will automatically split the transfer up into the appropriate number
209
of full-size 64-byte packets plus a single terminating packet, which
210
may be 0 bytes.</P
211
></LI
212
><LI
213
><P
214
><TT
215
CLASS="FUNCTION"
216
>usbs_start_tx_buffer</TT
217
> is non-blocking. It merely
218
starts the transmit operation, and does not wait for completion. At
219
some later point the USB device driver will invoke the completion
220
function parameter with two arguments: the completion data defined by
221
the last parameter, and a result field. This result will be either an
222
error code &lt; <TT
223
CLASS="LITERAL"
224
>0</TT
225
>, or the amount of data
226
transferred which should correspond to the
227
<TT
228
CLASS="PARAMETER"
229
><I
230
>length</I
231
></TT
232
> argument. The most likely errors are
233
<TT
234
CLASS="LITERAL"
235
>-EPIPE</TT
236
> to indicate that the connection between the
237
host and the target has been broken, and <TT
238
CLASS="LITERAL"
239
>-EAGAIN</TT
240
>
241
for when the endpoint has been <A
242
HREF="usbs-halt.html"
243
>halted</A
244
>. Specific USB device drivers may
245
define additional error conditions.</P
246
></LI
247
></OL
248
><P
249
>The normal sequence of events is that the USB device driver will
250
update the appropriate hardware registers. At some point after that
251
the host will attempt to fetch data by transmitting an IN token. Since
252
a transmit operation is now in progress the peripheral can send a
253
packet of data, and the host will generate an ACK. At this point the
254
USB hardware will generate an interrupt, and the device driver will
255
service this interrupt and arrange for a DSR to be called. Isochronous
256
and interrupt transfers involve just a single packet. However, bulk
257
transfers may involve multiple packets so the device driver has to
258
check whether there is more data to send and set things up for the
259
next packet. When the device driver DSR detects a complete transfer it
260
will inform higher-level code by invoking the supplied completion
261
function.</P
262
><P
263
>This means that the completion function will normally be invoked by a
264
DSR and not in thread context - although some USB device drivers may
265
have a different implementation. Therefore the completion function is
266
restricted in what it can do, in particular it must not make any
267
calls that will or may block such as locking a mutex or allocating
268
memory. The kernel documentation should be consulted for more details
269
of DSR's and interrupt handling generally.</P
270
><P
271
>It is possible that the completion function will be invoked before
272
<TT
273
CLASS="FUNCTION"
274
>usbs_start_tx_buffer</TT
275
> returns. Such an event would
276
be unusual because the transfer cannot happen until the next time the
277
host tries to fetch data from this peripheral, but it may happen if,
278
for example, another interrupt happens and a higher priority thread is
279
scheduled to run. Also, if the endpoint is currently halted then the
280
completion function will be invoked immediately with
281
<TT
282
CLASS="LITERAL"
283
>-EAGAIN</TT
284
>: typically this will happen in the current
285
thread rather than in a separate DSR. The completion function is
286
allowed to start another transfer immediately by calling
287
<TT
288
CLASS="FUNCTION"
289
>usbs_start_tx_buffer</TT
290
> again.</P
291
><P
292
>USB device drivers are not expected to perform any locking. It is the
293
responsibility of higher-level code to ensure that there is only one
294
transmit operation for a given endpoint in progress at any one time.
295
If there are concurrent calls to
296
<TT
297
CLASS="FUNCTION"
298
>usbs_start_tx_buffer</TT
299
> then the resulting behaviour
300
is undefined. For typical USB applications this does not present any
301
problems because only piece of code will access a given endpoint at
302
any particular time.</P
303
><P
304
>The following code fragment illustrates a very simple use of
305
<TT
306
CLASS="FUNCTION"
307
>usbs_start_tx_buffer</TT
308
> to implement a blocking
309
transmit, using a semaphore to synchronise between the foreground
310
thread and the DSR. For a simple example like this no completion data
311
is needed.</P
312
><TABLE
313
BORDER="0"
314
BGCOLOR="#E0E0E0"
315
WIDTH="100%"
316
><TR
317
><TD
318
><PRE
319
CLASS="PROGRAMLISTING"
320
>static int error_code = 0;
321
static cyg_sem_t completion_wait;
322
 
323
static void
324
completion_fn(void* data, int result)
325
{
326
    error_code = result;
327
    cyg_semaphore_post(&amp;completion_wait);
328
}
329
 
330
int
331
blocking_transmit(usbs_tx_endpoint* ep, const unsigned char* buf, int len)
332
{
333
    error_code = 0;
334
    usbs_start_tx_buffer(ep, buf, len, &amp;completion_fn, NULL);
335
    cyg_semaphore_wait(&amp;completion_wait);
336
    return error_code;
337
}</PRE
338
></TD
339
></TR
340
></TABLE
341
><P
342
>There is also a utility function <TT
343
CLASS="FUNCTION"
344
>usbs_start</TT
345
>. This
346
can be used by code that wants to manipulate <A
347
HREF="usbs-data.html"
348
>data endpoints</A
349
> directly, specifically the
350
<TT
351
CLASS="STRUCTFIELD"
352
><I
353
>complete_fn</I
354
></TT
355
>,
356
<TT
357
CLASS="STRUCTFIELD"
358
><I
359
>complete_data</I
360
></TT
361
>,
362
<TT
363
CLASS="STRUCTFIELD"
364
><I
365
>buffer</I
366
></TT
367
> and
368
<TT
369
CLASS="STRUCTFIELD"
370
><I
371
>buffer_size</I
372
></TT
373
> fields.
374
<TT
375
CLASS="FUNCTION"
376
>usbs_start_tx</TT
377
> just calls a function supplied by
378
the device driver.</P
379
></DIV
380
><DIV
381
CLASS="NAVFOOTER"
382
><HR
383
ALIGN="LEFT"
384
WIDTH="100%"><TABLE
385
WIDTH="100%"
386
BORDER="0"
387
CELLPADDING="0"
388
CELLSPACING="0"
389
><TR
390
><TD
391
WIDTH="33%"
392
ALIGN="left"
393
VALIGN="top"
394
><A
395
HREF="usbs-start-rx.html"
396
>Prev</A
397
></TD
398
><TD
399
WIDTH="34%"
400
ALIGN="center"
401
VALIGN="top"
402
><A
403
HREF="io-usb-slave.html"
404
>Home</A
405
></TD
406
><TD
407
WIDTH="33%"
408
ALIGN="right"
409
VALIGN="top"
410
><A
411
HREF="usbs-halt.html"
412
>Next</A
413
></TD
414
></TR
415
><TR
416
><TD
417
WIDTH="33%"
418
ALIGN="left"
419
VALIGN="top"
420
>Receiving Data from the Host</TD
421
><TD
422
WIDTH="34%"
423
ALIGN="center"
424
VALIGN="top"
425
>&nbsp;</TD
426
><TD
427
WIDTH="33%"
428
ALIGN="right"
429
VALIGN="top"
430
>Halted Endpoints</TD
431
></TR
432
></TABLE
433
></DIV
434
></BODY
435
></HTML
436
>

powered by: WebSVN 2.1.0

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