Comtrol eCos User Manual

Page 736

Advertising
background image

USB-ethernet Data Transfers

Both

usbs_eth_start_tx

and

usbs_eth_start_rx

are asynchronous: the transfer is started and, some time

later, a completion function will be invoked. The third and fourth arguments to both

usbs_eth_start_tx

and

usbs_eth_start_rx

supply the completion function and an argument to that function respectively. The comple-

tion function will be invoked with three arguments: a pointer to the usbs_eth data structure, usually

usbs_eth0

;

the supplied completion data ; and a return code field. A negative value indicates that an error occurred, for ex-
ample

-EPIPE

if the connection between USB host and peripheral has been broken, or

-EAGAIN

if an endpoint

has been halted. A positive value indicates the total size of the transfer, which should correspond to the size in the
USB-ethernet header plus an additional two bytes for the header itself.

If the data transfer is succesful then the completion function will typically be invoked in DSR context rather than
in thread context, although this depends on the implementation of the underlying USB device driver. Therefore the
completion function is restricted in what it can do; in particular, it must not make any calls that will or may block
such as locking a mutex or allocating memory. The kernel documentation should be consulted for more details of
DSR’s and interrupt handling generally. Note that if the transfer finishes quickly then the completion function may
be invoked before

usbs_eth_start_rx

or

usbs_eth_start_tx

returns. This is especially likely to happen if the

current thread is descheduled after starting the data transfer but before returning from these functions.

For transmit operations, it is possible for

usbs_eth_start_tx

to invoke the completion function immediately.

If there is no current connection between host and target then the transmit will fail immediately with

-EPIPE

. In

addition the USB-ethernet package will check the destination MAC address and make sure that the ethernet frame
really is intended for the host: either it must be for the address specified in the initialization call

usbs_eth_init

,

or it must be a broadcast packet, or the host must have enabled promiscuous mode.

632

Advertising