⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io.sgml

📁 eCos操作系统源码
💻 SGML
📖 第 1 页 / 共 5 页
字号:
<!-- {{{ Banner                         --><!-- =============================================================== --><!--                                                                 --><!--     io.sgml                                                     --><!--                                                                 --><!--     Generic I/O subsystem documentation                         --><!--                                                                 --><!-- =============================================================== --><!-- ####COPYRIGHTBEGIN####                                          --><!--                                                                 --><!-- =============================================================== --><!-- Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 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 obtained from the copyright holder                   --><!-- =============================================================== --><!--                                                                 -->      <!-- ####COPYRIGHTEND####                                            --><!-- =============================================================== --><!-- #####DESCRIPTIONBEGIN####                                       --><!--                                                                 --><!-- ####DESCRIPTIONEND####                                          --><!-- =============================================================== --><!-- }}} --><PART id="io"><TITLE>I/O Package (Device Drivers)</TITLE><!-- {{{ Intro --><CHAPTER id="io-package-intro"><TITLE>Introduction</TITLE><PARA>The I/O package is designed as a general purpose framework forsupporting device drivers. This includes all classes ofdrivers from simple serial to networking stacks and beyond.</PARA><PARA>Components of the I/O package, such as device drivers, areconfigured into the system just like all other components.Additionally, end users may add their own drivers to this set.</PARA><PARA>While the set of drivers (and the devices they represent) may beconsidered static, they must be accessed via an opaque&ldquo;handle&rdquo;. Each device in the system has a unique name andthe <FUNCTION>cyg_io_lookup()</FUNCTION> function is used to map thatname onto the handle for the device. This &ldquo;hiding&rdquo; of thedevice implementation allows for generic, named devices, as well asmore flexibility. Also, the <FUNCTION>cyg_io_lookup()</FUNCTION>function provides drivers the opportunity to initialize the devicewhen usage actually starts.</PARA><PARA>All devices have a name. The standard provided devices use names suchas <filename>&ldquo;/dev/console&rdquo;</filename> and<filename>&ldquo;/dev/serial0&rdquo;</filename>, where the<filename>&ldquo;/dev/&rdquo;</filename> prefix indicates that this isthe name of a device.</PARA><PARA>The entire I/O package API, as well as the standardset of provided drivers, is written in C. </PARA><PARA>Basic functions are provided to send data to and receive datafrom a device. The details of how this is done is left to the device [class] itself.For example, writing data to a block device like a disk drive mayhave different semantics than writing to a serial port. </PARA><PARA>Additional functions are provided to manipulate the stateof the driver and/or the actual device. These functionsare, by design, quite specific to the actual driver. </PARA><PARA>This driver model supports layering; in other words, a devicemay actually be created &ldquo;on top of&rdquo; another device.For example, the &ldquo;tty&rdquo; (terminal-like) devices arebuilt on top of simple serial devices. The upper layer then hasthe flexibility to add features and functions not found at the lowerlayers. In this case the &ldquo;tty&rdquo; device providesfor line buffering and editing not available from the simple serialdrivers.</PARA><PARA>Some drivers will support visibility of the layers they dependupon. The &ldquo;tty&rdquo; driver allows information aboutthe actual serial device to be manipulated by passing get/setconfig calls that use a serial driver &ldquo;key&rdquo; downto the serial driver itself. </PARA></CHAPTER><!-- }}} --><!-- {{{ User API --><CHAPTER id="io-user-api"><TITLE><!-- <index></index> -->User API</TITLE><PARA>All functions, except <FUNCTION>cyg_io_lookup()</FUNCTION>require an I/O &ldquo;<!-- <index></index> -->handle&rdquo;.</PARA><PARA>All functions return a value of the type <type>Cyg_ErrNo</type>. If anerror condition is detected, this value will be negative and theabsolute value indicates the actual error, as specified in<filename>cyg/error/codes.h</filename>. The only other legal returnvalue will be <varname>ENOERR</varname>. 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 &ldquo;length&rdquo; 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.</PARA><PROGRAMLISTING>// Lookup a device and return its handle   Cyg_ErrNo <FUNCTION><!-- <index></index> -->cyg_io_lookup</function>(     const char <parameter>*name</parameter>,    cyg_io_handle_t <parameter>*handle</parameter> )</PROGRAMLISTING><PARA>This function maps a device name onto an appropriate handle. If thenamed device is not in the system, then the error<varname>-ENOENT</varname> is returned. If the device is found, thenthe handle for the device is returned by way of the handle pointer<parameter>*handle</parameter>.</PARA><PROGRAMLISTING>// Write data to a device Cyg_ErrNo <FUNCTION><!-- <index></index> -->cyg_io_write</function>(     cyg_io_handle_t <parameter>handle</parameter>,    const void <parameter>*buf</parameter>,    cyg_uint32 <parameter>*len</parameter> )</PROGRAMLISTING><PARA>This function sends data to a device. The size of data to send iscontained in <parameter>*len</parameter> and the actual size sent willbe returned in the same place.</PARA><PROGRAMLISTING>// Read data from a device Cyg_ErrNo <!-- <index></index> --><function>cyg_io_read</function>(     cyg_io_handle_t <parameter>handle</parameter>,    void <parameter>*buf</parameter>,    cyg_uint32 <parameter>*len</parameter> )</PROGRAMLISTING><PARA>This function receives data from a device. The desired size of data toreceive is contained in <parameter>*len</parameter> and the actualsize obtained will be returned in the same place.</PARA><PROGRAMLISTING>// Get the configuration of a device Cyg_ErrNo <FUNCTION><!-- <index></index> -->cyg_io_get_config</FUNCTION>(     cyg_io_handle_t <parameter>handle</parameter>,    cyg_uint32 <parameter>key</parameter>,    void *<parameter>buf</parameter>,    cyg_uint32 *<parameter>len</parameter> )</PROGRAMLISTING><PARA>This function is used to obtain run-time configuration about adevice. The type of information retrieved is specified by the<parameter>key</parameter>. The data will be returned in the givenbuffer. The value of <parameter>*len</parameter> 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 <parameter> *len</parameter>. The appropriate key valuesdiffer for each driver and are all listed in the file<filename>&lt;cyg/io/config_keys.h&gt;</filename>.</PARA><PROGRAMLISTING>// Change the configuration of a device Cyg_ErrNo <!-- <index></index> --><function>cyg_io_set_config</function>(     cyg_io_handle_t <parameter>handle</parameter>,    cyg_uint32 <parameter>key</parameter>,    const void <parameter>*buf</parameter>,    cyg_uint32 <parameter>*len</parameter> )</PROGRAMLISTING><PARA>This function is used to manipulate or change the run-timeconfiguration of a device. The type of information is specified by the<parameter>key</parameter>. The data will be obtained from the givenbuffer. The value of <parameter>*len</parameter> 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<filename>&lt;cyg/io/config_keys.h&gt;</filename>.</PARA></CHAPTER><!-- }}} --><!-- {{{ Serial Drivers  --><CHAPTER id="io-serial-driver-details"><TITLE>Serial driver details</TITLE><PARA>Two different classes of serial drivers are provided as a standardpart of the eCos system. These are described as &ldquo;rawserial&rdquo; (serial) and &ldquo;tty-like&rdquo; (tty).</PARA><!-- {{{ Raw Serial Drivers --><SECTION id="io-simple-serial-driver"><TITLE>Raw Serial Driver</TITLE><PARA>Use the include file <FILENAME>&lt;cyg/io/serialio.h&gt;</FILENAME> forthis driver.</PARA><PARA>The <!-- <index></index> -->raw serial driver is capable of sendingand receiving blocks of raw data to a serial device. Controls areprovided to configure the actual hardware, but there is no manipulationof the data by this driver.</PARA><PARA>There may be many instances of this driver in a given system,one for each serial channel. Each channel corresponds to a physicaldevice and there will typically be a device module created for thispurpose. The device modules themselves are configurable, allowingspecification of the actual hardware details, as well as such detailsas whether the channel should be buffered by the serial driver,etc.</PARA><!-- {{{ Runtime Configuration --><SECTION><TITLE>Runtime Configuration</TITLE><para>Runtime configuration is achieved by exchanging data structures withthe driver via the <function>cyg_io_set_config()</function> and<function>cyg_io_get_config()</function> functions.</para><PROGRAMLISTING>typedef struct { cyg_serial_baud_rate_t baud; cyg_serial_stop_bits_t stop; cyg_serial_parity_t parity; cyg_serial_word_length_t word_length; cyg_uint32 flags;} cyg_serial_info_t;</PROGRAMLISTING><PARA>The field <structfield><!-- <index></index>-->word_length</structfield> contains the number of data bits per word(character). This must be one of the values:</PARA><PROGRAMLISTING> CYGNUM_SERIAL_WORD_LENGTH_5 CYGNUM_SERIAL_WORD_LENGTH_6 CYGNUM_SERIAL_WORD_LENGTH_7 CYGNUM_SERIAL_WORD_LENGTH_8</PROGRAMLISTING><PARA>The field <structfield><!-- <index></index>-->baud</structfield> contains a baud rate selection.  This must beone of the values:</PARA><PROGRAMLISTING> CYGNUM_SERIAL_BAUD_50 CYGNUM_SERIAL_BAUD_75 CYGNUM_SERIAL_BAUD_110 CYGNUM_SERIAL_BAUD_134_5 CYGNUM_SERIAL_BAUD_150 CYGNUM_SERIAL_BAUD_200 CYGNUM_SERIAL_BAUD_300 CYGNUM_SERIAL_BAUD_600 CYGNUM_SERIAL_BAUD_1200 CYGNUM_SERIAL_BAUD_1800 CYGNUM_SERIAL_BAUD_2400 CYGNUM_SERIAL_BAUD_3600 CYGNUM_SERIAL_BAUD_4800 CYGNUM_SERIAL_BAUD_7200 CYGNUM_SERIAL_BAUD_9600 CYGNUM_SERIAL_BAUD_14400 CYGNUM_SERIAL_BAUD_19200 CYGNUM_SERIAL_BAUD_38400 CYGNUM_SERIAL_BAUD_57600 CYGNUM_SERIAL_BAUD_115200 CYGNUM_SERIAL_BAUD_234000</PROGRAMLISTING><PARA>The field <structfield><!-- <index></index>-->stop</structfield> contains the number of stop bits. This must beone of the values:</PARA><PROGRAMLISTING> CYGNUM_SERIAL_STOP_1 CYGNUM_SERIAL_STOP_1_5 CYGNUM_SERIAL_STOP_2</PROGRAMLISTING><NOTE><title>Note</title><PARA>On most hardware, a selection of 1.5 stop bits is only validif the word (character) length is 5.</PARA></NOTE><PARA>The field <structfield><!-- <index></index>-->parity</structfield> contains the parity mode.  This must be one ofthe values: </PARA><PROGRAMLISTING> CYGNUM_SERIAL_PARITY_NONE CYGNUM_SERIAL_PARITY_EVEN CYGNUM_SERIAL_PARITY_ODD CYGNUM_SERIAL_PARITY_MARK CYGNUM_SERIAL_PARITY_SPACE</PROGRAMLISTING><PARA>The field <structfield><!-- <index></index>-->flags</structfield> is a bitmask which controls the behavior of theserial device driver. It should be built from the values<literal>CYG_SERIAL_FLAGS_xxx</literal> defined below:</PARA><PROGRAMLISTING>#define CYG_SERIAL_FLAGS_RTSCTS 0x0001</PROGRAMLISTING><PARA>If this bit is set then the port is placed in &ldquo;hardwarehandshake&rdquo; mode. In this mode, the CTS and RTS pins controlwhen data is allowed to be sent/received at the port. Thisbit is ignored if the hardware does not support this level ofhandshake.</PARA><PROGRAMLISTING>typedef struct {  cyg_int32 rx_bufsize;  cyg_int32 rx_count;  cyg_int32 tx_bufsize;  cyg_int32 tx_count;} cyg_serial_buf_info_t;     </PROGRAMLISTING><PARA>The field <structfield>rx_bufsize</structfield> containsthe total size of the incoming data buffer. This is set to zero ondevices that do not support buffering (i.e. polled devices).</PARA><PARA>The field <structfield>rx_count</structfield> contains thenumber of bytes currently occupied in the incoming data buffer.This is set to zero on devices that do not support buffering (i.e. polleddevices).</PARA><PARA>The field <structfield>tx_bufsize</structfield> contains thetotal size of the transmit data buffer. This is set to zero on devicesthat do not support buffering (i.e. polled devices).</PARA><PARA>The field <structfield>tx_count</structfield> contains thenumber of bytes currently occupied in the transmit data buffer.  Thisis set to zero on devices that do not support buffering (i.e. polleddevices).</PARA></SECTION><!-- }}} --><!-- {{{ API Details --><SECTION><TITLE><!-- <index></index> -->API Details</TITLE><!-- {{{ cyg_io_write -->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -