Devtab entries – Comtrol eCos User Manual
Page 713

Writing a USB Device Driver
Note: Giving a buffer size of 0 bytes a special meaning is problematical because it prevents transfers of that
size. Such transfers are allowed by the USB protocol, consisting of just headers and acknowledgements and
an empty data phase, although rarely useful. A future modification of the device driver specification will address
this issue, although care has to be taken that the functionality remains accessible through devtab entries as
well as via low-level accesses.
Devtab Entries
For some applications or higher-level packages it may be more convenient to use traditional open/read/write I/O
calls rather than the non-blocking USB I/O calls. To support this the device driver can provide a devtab entry for
each endpoint, for example:
#ifdef CYGVAR_DEVS_USB_SA11X0_EP1_DEVTAB_ENTRY
static CHAR_DEVIO_TABLE(usbs_sa11x0_ep1_devtab_functions,
&cyg_devio_cwrite,
&usbs_devtab_cread,
&cyg_devio_bwrite,
&cyg_devio_bread,
&cyg_devio_select,
&cyg_devio_get_config,
&cyg_devio_set_config);
static CHAR_DEVTAB_ENTRY(usbs_sa11x0_ep1_devtab_entry,
CYGDAT_DEVS_USB_SA11X0_DEVTAB_BASENAME "1r",
0,
&usbs_sa11x0_ep1_devtab_functions,
&usbs_sa11x0_devtab_dummy_init,
0,
(void*) &usbs_sa11x0_ep1);
#endif
Again care must be taken to avoid name clashes. This can be achieved by having a configuration option to control
the base name, with a default value of e.g.
/dev/usbs
, and appending an endpoint-specific string. This gives the
application developer sufficient control to eliminate any name clashes. The common USB slave package provides
functions
usbs_devtab_cwrite
and
usbs_devtab_cread
, which can be used in the function tables for transmit
and receive endpoints respectively. The private field
priv
of the devtab entry should be a pointer to the underlying
endpoint data structure.
Because devtab entries are never accessed directly, only indirectly, they would usually be eliminated by the linker.
To avoid this the devtab entries should normally be defined in a separate source file which ends up the special
library
libextras.a
rather than in the default library
libtarget.a
.
Not all applications or higher-level packages will want to use the devtab entries and the blocking I/O facilities. It
may be appropriate for the device driver to provide additional configuration options that control whether or not any
or all of the devtab entries should be provided, to avoid unnecessary memory overheads.
609