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

📄 io-serial-driver-details.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- 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>Serial driver details</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="User API"HREF="io-user-api.html"><LINKREL="NEXT"TITLE=" TTY driver"HREF="io-tty-driver.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-user-api.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="io-tty-driver.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="IO-SERIAL-DRIVER-DETAILS">Chapter 16. Serial driver details</H1><DIVCLASS="TOC"><DL><DT><B>Table of Contents</B></DT><DT><AHREF="io-serial-driver-details.html#IO-SIMPLE-SERIAL-DRIVER">Raw Serial Driver</A></DT><DT><AHREF="io-tty-driver.html">TTY driver</A></DT></DL></DIV><P>Two different classes of serial drivers are provided as a standardpart of the eCos system. These are described as &#8220;rawserial&#8221; (serial) and &#8220;tty-like&#8221; (tty).</P><DIVCLASS="SECTION"><H1CLASS="SECTION"><ANAME="IO-SIMPLE-SERIAL-DRIVER">Raw Serial Driver</H1><P>Use the include file <TTCLASS="FILENAME">&lt;cyg/io/serialio.h&gt;</TT> forthis driver.</P><P>The 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.</P><P>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.</P><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN10475">Runtime Configuration</H2><P>Runtime configuration is achieved by exchanging data structures withthe driver via the <TTCLASS="FUNCTION">cyg_io_set_config()</TT> and<TTCLASS="FUNCTION">cyg_io_get_config()</TT> functions.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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;</PRE></TD></TR></TABLE><P>The field <TTCLASS="STRUCTFIELD"><I>word_length</I></TT> contains the number of data bits per word(character). This must be one of the values:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING"> CYGNUM_SERIAL_WORD_LENGTH_5 CYGNUM_SERIAL_WORD_LENGTH_6 CYGNUM_SERIAL_WORD_LENGTH_7 CYGNUM_SERIAL_WORD_LENGTH_8</PRE></TD></TR></TABLE><P>The field <TTCLASS="STRUCTFIELD"><I>baud</I></TT> contains a baud rate selection.  This must beone of the values:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="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</PRE></TD></TR></TABLE><P>The field <TTCLASS="STRUCTFIELD"><I>stop</I></TT> contains the number of stop bits. This must beone of the values:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING"> CYGNUM_SERIAL_STOP_1 CYGNUM_SERIAL_STOP_1_5 CYGNUM_SERIAL_STOP_2</PRE></TD></TR></TABLE><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>On most hardware, a selection of 1.5 stop bits is only validif the word (character) length is 5.</P></BLOCKQUOTE></DIV><P>The field <TTCLASS="STRUCTFIELD"><I>parity</I></TT> contains the parity mode.  This must be one ofthe values: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING"> CYGNUM_SERIAL_PARITY_NONE CYGNUM_SERIAL_PARITY_EVEN CYGNUM_SERIAL_PARITY_ODD CYGNUM_SERIAL_PARITY_MARK CYGNUM_SERIAL_PARITY_SPACE</PRE></TD></TR></TABLE><P>The field <TTCLASS="STRUCTFIELD"><I>flags</I></TT> is a bitmask which controls the behavior of theserial device driver. It should be built from the values<TTCLASS="LITERAL">CYG_SERIAL_FLAGS_xxx</TT> defined below:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define CYG_SERIAL_FLAGS_RTSCTS 0x0001</PRE></TD></TR></TABLE><P>If this bit is set then the port is placed in &#8220;hardwarehandshake&#8221; 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.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">typedef struct {  cyg_int32 rx_bufsize;  cyg_int32 rx_count;  cyg_int32 tx_bufsize;  cyg_int32 tx_count;} cyg_serial_buf_info_t;     </PRE></TD></TR></TABLE><P>The field <TTCLASS="STRUCTFIELD"><I>rx_bufsize</I></TT> containsthe total size of the incoming data buffer. This is set to zero ondevices that do not support buffering (i.e. polled devices).</P><P>The field <TTCLASS="STRUCTFIELD"><I>rx_count</I></TT> 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).</P><P>The field <TTCLASS="STRUCTFIELD"><I>tx_bufsize</I></TT> contains thetotal size of the transmit data buffer. This is set to zero on devicesthat do not support buffering (i.e. polled devices).</P><P>The field <TTCLASS="STRUCTFIELD"><I>tx_count</I></TT> 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).</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN10510">API Details</H2><DIVCLASS="SECTION"><H3CLASS="SECTION"><ANAME="IO-SERIAL-CYG-IO-WRITE">cyg_io_write</H3><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_io_write(handle, buf, len)</PRE></TD></TR></TABLE><P>Send the data from <TTCLASS="PARAMETER"><I>buf</I></TT> to the device. Thedriver maintains a buffer to hold the data. The size of theintermediate buffer is configurable within the interface module. Thedata is not modified at all while it is being buffered. On return,<TTCLASS="PARAMETER"><I>*len</I></TT> contains the amount of characters actuallyconsumed .</P><P>It is possible to configure the write call to be blocking(default) or non-blocking. Non-blocking mode requires both the configurationoption <TTCLASS="LITERAL">CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING</TT>to be enabled, and the specific device to be set to non-blockingmode for writes (see <TTCLASS="FUNCTION">cyg_io_set_config()</TT>).</P><P>In blocking mode, the call will not return until there is space in thebuffer and the entire contents of <TTCLASS="PARAMETER"><I>buf</I></TT> have beenconsumed.</P><P>In non-blocking mode, as much as possible gets consumed from<TTCLASS="PARAMETER"><I>buf</I></TT>. If everything was consumed, the callreturns <TTCLASS="LITERAL">ENOERR</TT>. If only part of the<TTCLASS="PARAMETER"><I>buf</I></TT> contents was consumed,<TTCLASS="LITERAL">-EAGAIN</TT> is returned and the caller must tryagain. On return, <TTCLASS="PARAMETER"><I>*len</I></TT> contains the number of characters actuallyconsumed .</P><P>The call can also return <TTCLASS="LITERAL">-EINTR</TT> if interruptedvia the <TTCLASS="FUNCTION">cyg_io_get_config()</TT>/<TTCLASS="LITERAL">ABORT</TT> key.</P></DIV><DIVCLASS="SECTION"><H3CLASS="SECTION"><ANAME="IO-SERIAL-CYG-IO-READ">cyg_io_read</H3><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_io_read(handle, buf, len)</PRE></TD></TR></TABLE><P>Receive data into the buffer, <TTCLASS="PARAMETER"><I>buf</I></TT>, from thedevice. No manipulation of the data is performed before beingtransferred.  An interrupt driven interface module will support dataarriving when no read is pending by buffering the data in the serialdriver.  Again, this buffering is completely configurable. On return,<TTCLASS="PARAMETER"><I>*len</I></TT> contains the number of characters actuallyreceived.</P><P>It is possible to configure the read call to be blocking (default)or  non-blocking. Non-blocking mode requires both the configurationoption  <TT

⌨️ 快捷键说明

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