<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>Starting up a USB Device</TITLE
|
>Starting up a USB Device</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos Reference Manual"
|
TITLE="eCos Reference Manual"
|
HREF="ecos-ref.html"><LINK
|
HREF="ecos-ref.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="eCos USB Slave Support"
|
TITLE="eCos USB Slave Support"
|
HREF="io-usb-slave.html"><LINK
|
HREF="io-usb-slave.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="USB Enumeration Data"
|
TITLE="USB Enumeration Data"
|
HREF="usbs-enum.html"><LINK
|
HREF="usbs-enum.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="Devtab Entries"
|
TITLE="Devtab Entries"
|
HREF="usbs-devtab.html"></HEAD
|
HREF="usbs-devtab.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="REFENTRY"
|
CLASS="REFENTRY"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos Reference Manual</TH
|
>eCos Reference Manual</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="usbs-enum.html"
|
HREF="usbs-enum.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="usbs-devtab.html"
|
HREF="usbs-devtab.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><H1
|
><H1
|
><A
|
><A
|
NAME="USBS-START">Starting up a USB Device</H1
|
NAME="USBS-START">Starting up a USB Device</H1
|
><DIV
|
><DIV
|
CLASS="REFNAMEDIV"
|
CLASS="REFNAMEDIV"
|
><A
|
><A
|
NAME="AEN16210"
|
NAME="AEN16210"
|
></A
|
></A
|
><H2
|
><H2
|
>Name</H2
|
>Name</H2
|
><TT
|
><TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_start</TT
|
>usbs_start</TT
|
> -- Starting up a USB Device</DIV
|
> -- Starting up a USB Device</DIV
|
><DIV
|
><DIV
|
CLASS="REFSYNOPSISDIV"
|
CLASS="REFSYNOPSISDIV"
|
><A
|
><A
|
NAME="AEN16214"><H2
|
NAME="AEN16214"><H2
|
>Synopsis</H2
|
>Synopsis</H2
|
><DIV
|
><DIV
|
CLASS="FUNCSYNOPSIS"
|
CLASS="FUNCSYNOPSIS"
|
><A
|
><A
|
NAME="AEN16215"><P
|
NAME="AEN16215"><P
|
></P
|
></P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="FUNCSYNOPSISINFO"
|
CLASS="FUNCSYNOPSISINFO"
|
>#include <cyg/io/usb/usbs.h></PRE
|
>#include <cyg/io/usb/usbs.h></PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
><CODE
|
><CODE
|
><CODE
|
><CODE
|
CLASS="FUNCDEF"
|
CLASS="FUNCDEF"
|
>void usbs_start</CODE
|
>void usbs_start</CODE
|
>(usbs_control_endpoint* ep0);</CODE
|
>(usbs_control_endpoint* ep0);</CODE
|
></P
|
></P
|
><P
|
><P
|
></P
|
></P
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="REFSECT1"
|
CLASS="REFSECT1"
|
><A
|
><A
|
NAME="AEN16222"
|
NAME="AEN16222"
|
></A
|
></A
|
><H2
|
><H2
|
>Description</H2
|
>Description</H2
|
><P
|
><P
|
>Initializing a USB device requires some support from higher-level
|
>Initializing a USB device requires some support from higher-level
|
code, typically the application, in the form of enumeration data.
|
code, typically the application, in the form of enumeration data.
|
Hence it is not possible for the low-level USB driver to activate a
|
Hence it is not possible for the low-level USB driver to activate a
|
USB device itself. Instead the higher-level code has to take care of
|
USB device itself. Instead the higher-level code has to take care of
|
this by invoking <TT
|
this by invoking <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_start</TT
|
>usbs_start</TT
|
>. This function takes
|
>. This function takes
|
a pointer to a USB control endpoint data structure. USB device drivers
|
a pointer to a USB control endpoint data structure. USB device drivers
|
should provide exactly one such data structure for every USB device,
|
should provide exactly one such data structure for every USB device,
|
so the pointer uniquely identifies the device.</P
|
so the pointer uniquely identifies the device.</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>const usbs_enumeration_data usb_enum_data = {
|
>const usbs_enumeration_data usb_enum_data = {
|
…
|
…
|
};
|
};
|
|
|
int
|
int
|
main(int argc, char** argv)
|
main(int argc, char** argv)
|
{
|
{
|
usbs_sa11x0_ep0.enumeration_data = &usb_enum_data;
|
usbs_sa11x0_ep0.enumeration_data = &usb_enum_data;
|
…
|
…
|
usbs_start(&usbs_sa11x0_ep0);
|
usbs_start(&usbs_sa11x0_ep0);
|
…
|
…
|
}</PRE
|
}</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>The exact behaviour of <TT
|
>The exact behaviour of <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_start</TT
|
>usbs_start</TT
|
> depends on the
|
> depends on the
|
USB hardware and the device driver. A typical implementation would
|
USB hardware and the device driver. A typical implementation would
|
change the USB data pins from tristated to active. If the peripheral
|
change the USB data pins from tristated to active. If the peripheral
|
is already plugged into a host then the latter should detect this
|
is already plugged into a host then the latter should detect this
|
change and start interacting with the peripheral, including requesting
|
change and start interacting with the peripheral, including requesting
|
the enumeration data. Some of this may happen before
|
the enumeration data. Some of this may happen before
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_start</TT
|
>usbs_start</TT
|
> returns, but given that multiple
|
> returns, but given that multiple
|
interactions between USB host and peripheral are required it is likely
|
interactions between USB host and peripheral are required it is likely
|
that the function will return before the peripheral is fully
|
that the function will return before the peripheral is fully
|
configured. Control endpoints provide a <A
|
configured. Control endpoints provide a <A
|
HREF="usbs-control.html#AEN16552"
|
HREF="usbs-control.html#AEN16552"
|
>mechanism</A
|
>mechanism</A
|
> for informing
|
> for informing
|
higher-level code of USB state changes.
|
higher-level code of USB state changes.
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_start</TT
|
>usbs_start</TT
|
> will return even if the peripheral is
|
> will return even if the peripheral is
|
not currently connected to a host: it will not block until the
|
not currently connected to a host: it will not block until the
|
connection is established.</P
|
connection is established.</P
|
><P
|
><P
|
><TT
|
><TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_start</TT
|
>usbs_start</TT
|
> should only be called once for a given
|
> should only be called once for a given
|
USB device. There are no defined error conditions. Note that the
|
USB device. There are no defined error conditions. Note that the
|
function affects the entire USB device and not just the control
|
function affects the entire USB device and not just the control
|
endpoint: there is no need to start any data endpoints as well.</P
|
endpoint: there is no need to start any data endpoints as well.</P
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="usbs-enum.html"
|
HREF="usbs-enum.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-ref.html"
|
HREF="ecos-ref.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="usbs-devtab.html"
|
HREF="usbs-devtab.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>USB Enumeration Data</TD
|
>USB Enumeration Data</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="io-usb-slave.html"
|
HREF="io-usb-slave.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>Devtab Entries</TD
|
>Devtab Entries</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|