📄 io-tty-driver.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> TTY driver</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="Serial driver details"HREF="io-serial-driver-details.html"><LINKREL="PREVIOUS"TITLE="Serial driver details"HREF="io-serial-driver-details.html"><LINKREL="NEXT"TITLE="How to Write a Driver"HREF="io-how-to-write-a-driver.html"></HEAD><BODYCLASS="SECTION"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-serial-driver-details.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 16. Serial driver details</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="io-how-to-write-a-driver.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECTION"><H1CLASS="SECTION"><ANAME="IO-TTY-DRIVER">TTY driver</H1><P>Use the include file <TTCLASS="FILENAME"><cyg/io/ttyio.h></TT> forthis driver.</P><P>This driver is built on top of the simpleserial driver and is typically used for a device that interfaces withhumans such as a terminal. It provides some minimal formatting of dataon output and allows for line-oriented editing on input.</P><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN10715">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_uint32 tty_out_flags; cyg_uint32 tty_in_flags;} cyg_tty_info_t;</PRE></TD></TR></TABLE><P>The field <TTCLASS="STRUCTFIELD"><I>tty_out_flags</I></TT>is used to control what happens to data as it is send to the serialport. It contains a bitmap comprised of the bits as defined by the<TTCLASS="LITERAL">CYG_TTY_OUT_FLAGS_xxx</TT> values below. </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define CYG_TTY_OUT_FLAGS_CRLF 0x0001 // Map '\n' => '\n\r' on output</PRE></TD></TR></TABLE><P>If this bit is set in <TTCLASS="STRUCTFIELD"><I>tty_out_flags</I></TT>,any occurrence of the character "\n" willbe replaced by the sequence "\n\r" beforebeing sent to the device.</P><P>The field <TTCLASS="STRUCTFIELD"><I>tty_in_flags</I></TT>is used to control how data is handled as it comes from the serialport. It contains a bitmap comprised of the bits as defined by the<TTCLASS="LITERAL">CYG_TTY_IN_FLAGS_xxx</TT> values below. </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define CYG_TTY_IN_FLAGS_CR 0x0001 // Map '\r' => '\n' on input</PRE></TD></TR></TABLE><P>If this bit is set in <TTCLASS="STRUCTFIELD"><I>tty_in_flags</I></TT>, thecharacter "\r" (“return” or “enter” onmost keyboards) will be mapped to "\n".</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define CYG_TTY_IN_FLAGS_CRLF 0x0002 // Map '\n\r' => '\n' on input</PRE></TD></TR></TABLE><P>If this bit is set in <TTCLASS="STRUCTFIELD"><I>tty_in_flags</I></TT>, thecharacter sequence "\n\r" (often sent by DOS/Windowsbased terminals) will be mapped to "\n". </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define CYG_TTY_IN_FLAGS_BINARY 0x0004 // No input processing</PRE></TD></TR></TABLE><P>If this bit is set in <TTCLASS="STRUCTFIELD"><I>tty_in_flags</I></TT>, theinput will not be manipulated in any way before being placed inthe user’s buffer. </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define CYG_TTY_IN_FLAGS_ECHO 0x0008 // Echo characters as processed</PRE></TD></TR></TABLE><P>If this bit is set in <TTCLASS="STRUCTFIELD"><I>tty_in_flags</I></TT>, characterswill be echoed back to the serial port as they are processed. </P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN10742">API details</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_io_read(handle, buf, len)</PRE></TD></TR></TABLE><P>This function is used to read data from the device. In thedefault case, data is read until an end-of-line character ("\n"or "\r") is read. Additionally, the characters are echoedback to the [terminal] device. Minimal editingof the input is also supported. </P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>When connecting to a remote target via GDB it is not possibleto provide console input while GDB is connected. The GDB remoteprotocol does not support input. Users must disconnect from GDBif this functionality is required.</P></BLOCKQUOTE></DIV><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING"> cyg_io_write(handle, buf, len)</PRE></TD></TR></TABLE><P>This function is used to send data to the device. In the defaultcase, the end-of-line character "\n" is replaced by thesequence "\n\r". </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_io_get_config(handle, key, buf, len)</PRE></TD></TR></TABLE><P>This function is used to get information about the channel’sconfiguration at runtime. </P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="LITERAL">CYG_IO_GET_CONFIG_TTY_INFO</TT></DT><DD><P></P><DIVCLASS="VARIABLELIST"><DL><DT>Buf type:</DT><DD><P>cyg_tty_info_t</P></DD><DT>Function:</DT><DD><P>This function retrieves the current state of the driver. </P></DD></DL></DIV></DD></DL></DIV><P>Serial driver keys (see above) may also be specifiedin which case the call is passed directly to the serialdriver. </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_io_set_config(handle, key, buf, len)</PRE></TD></TR></TABLE><P>This function is used to modify the channel’s configurationat runtime. </P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="LITERAL">CYG_IO_SET_CONFIG_TTY_INFO</TT></DT><DD><P></P><DIVCLASS="VARIABLELIST"><DL><DT>Buf type:</DT><DD><P>cyg_tty_info_t</P></DD><DT>Function:</DT><DD><P>This function changes the current state of the driver.</P></DD></DL></DIV></DD></DL></DIV><P>Serial driverkeys (see above) may also be specified in which case thecall is passed directly to the serial driver. </P></DIV></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-serial-driver-details.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-how-to-write-a-driver.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Serial driver details</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-serial-driver-details.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">How to Write a Driver</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -