📄 io-user-api.html
字号:
<!-- Copyright (C) 2003 Red Hat, Inc. --><!-- This material may be distributed only subject to the terms --><!-- and conditions set forth in the Open Publication License, v1.0 --><!-- or later (the latest version is presently available at --><!-- http://www.opencontent.org/openpub/). --><!-- Distribution of the work or derivative of the work in any --><!-- standard (paper) book form is prohibited unless prior --><!-- permission is obtained from the copyright holder. --><HTML><HEAD><TITLE>User API</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="I/O Package (Device Drivers)"HREF="io.html"><LINKREL="PREVIOUS"TITLE="Introduction"HREF="io-package-intro.html"><LINKREL="NEXT"TITLE="Serial driver details"HREF="io-serial-driver-details.html"></HEAD><BODYCLASS="CHAPTER"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="io-package-intro.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="io-serial-driver-details.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="IO-USER-API">Chapter 15. User API</H1><P>All functions, except <TTCLASS="FUNCTION">cyg_io_lookup()</TT>require an I/O “handle”.</P><P>All functions return a value of the type <SPANCLASS="TYPE">Cyg_ErrNo</SPAN>. If anerror condition is detected, this value will be negative and theabsolute value indicates the actual error, as specified in<TTCLASS="FILENAME">cyg/error/codes.h</TT>. The only other legal returnvalue will be <TTCLASS="VARNAME">ENOERR</TT>. All other function argumentsare pointers (references). This allows the drivers to pass informationefficiently, both into and out of the driver. The most strikingexample of this is the “length” value passed to the readand write functions. This parameter contains the desired length ofdata on input to the function and the actual transferred length onreturn.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">// Lookup a device and return its handle Cyg_ErrNo <TTCLASS="FUNCTION">cyg_io_lookup</TT>( const char <TTCLASS="PARAMETER"><I>*name</I></TT>, cyg_io_handle_t <TTCLASS="PARAMETER"><I>*handle</I></TT> )</PRE></TD></TR></TABLE><P>This function maps a device name onto an appropriate handle. If thenamed device is not in the system, then the error<TTCLASS="VARNAME">-ENOENT</TT> is returned. If the device is found, thenthe handle for the device is returned by way of the handle pointer<TTCLASS="PARAMETER"><I>*handle</I></TT>.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">// Write data to a device Cyg_ErrNo <TTCLASS="FUNCTION">cyg_io_write</TT>( cyg_io_handle_t <TTCLASS="PARAMETER"><I>handle</I></TT>, const void <TTCLASS="PARAMETER"><I>*buf</I></TT>, cyg_uint32 <TTCLASS="PARAMETER"><I>*len</I></TT> )</PRE></TD></TR></TABLE><P>This function sends data to a device. The size of data to send iscontained in <TTCLASS="PARAMETER"><I>*len</I></TT> and the actual size sent willbe returned in the same place.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">// Read data from a device Cyg_ErrNo <TTCLASS="FUNCTION">cyg_io_read</TT>( cyg_io_handle_t <TTCLASS="PARAMETER"><I>handle</I></TT>, void <TTCLASS="PARAMETER"><I>*buf</I></TT>, cyg_uint32 <TTCLASS="PARAMETER"><I>*len</I></TT> )</PRE></TD></TR></TABLE><P>This function receives data from a device. The desired size of data toreceive is contained in <TTCLASS="PARAMETER"><I>*len</I></TT> and the actualsize obtained will be returned in the same place.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">// Get the configuration of a device Cyg_ErrNo <TTCLASS="FUNCTION">cyg_io_get_config</TT>( cyg_io_handle_t <TTCLASS="PARAMETER"><I>handle</I></TT>, cyg_uint32 <TTCLASS="PARAMETER"><I>key</I></TT>, void *<TTCLASS="PARAMETER"><I>buf</I></TT>, cyg_uint32 *<TTCLASS="PARAMETER"><I>len</I></TT> )</PRE></TD></TR></TABLE><P>This function is used to obtain run-time configuration about adevice. The type of information retrieved is specified by the<TTCLASS="PARAMETER"><I>key</I></TT>. The data will be returned in the givenbuffer. The value of <TTCLASS="PARAMETER"><I>*len</I></TT> should contain theamount of data requested, which must be at least as large as the sizeappropriate to the selected key. The actual size of data retrieved isplaced in <TTCLASS="PARAMETER"><I> *len</I></TT>. The appropriate key valuesdiffer for each driver and are all listed in the file<TTCLASS="FILENAME"><cyg/io/config_keys.h></TT>.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">// Change the configuration of a device Cyg_ErrNo <TTCLASS="FUNCTION">cyg_io_set_config</TT>( cyg_io_handle_t <TTCLASS="PARAMETER"><I>handle</I></TT>, cyg_uint32 <TTCLASS="PARAMETER"><I>key</I></TT>, const void <TTCLASS="PARAMETER"><I>*buf</I></TT>, cyg_uint32 <TTCLASS="PARAMETER"><I>*len</I></TT> )</PRE></TD></TR></TABLE><P>This function is used to manipulate or change the run-timeconfiguration of a device. The type of information is specified by the<TTCLASS="PARAMETER"><I>key</I></TT>. The data will be obtained from the givenbuffer. The value of <TTCLASS="PARAMETER"><I>*len</I></TT> should contain theamount of data provided, which must match the size appropriate to theselected key. The appropriate key values differ for each driver andare all listed in the file<TTCLASS="FILENAME"><cyg/io/config_keys.h></TT>.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="io-package-intro.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="io-serial-driver-details.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Introduction</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Serial driver details</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -