📄 io.sgml
字号:
</SECTION><!-- }}} --><!-- {{{ TTY Drivers --><SECTION id="io-tty-driver"><TITLE> TTY driver</TITLE><PARA>Use the include file <filename><cyg/io/ttyio.h></filename> forthis driver.</PARA><PARA>This <!-- <index></index> -->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.</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_uint32 tty_out_flags; cyg_uint32 tty_in_flags;} cyg_tty_info_t;</PROGRAMLISTING><PARA>The field <structfield><!-- <index></index> -->tty_out_flags</structfield>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<literal>CYG_TTY_OUT_FLAGS_xxx</literal> values below. </PARA><PROGRAMLISTING>#define CYG_TTY_OUT_FLAGS_CRLF 0x0001 // Map '\n' => '\r\n' on output</PROGRAMLISTING><PARA>If this bit is set in <structfield>tty_out_flags</structfield>,any occurrence of the character "\n" willbe replaced by the sequence "\r\n" beforebeing sent to the device.</PARA><PARA>The field <structfield><!-- <index></index> -->tty_in_flags</structfield>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<literal>CYG_TTY_IN_FLAGS_xxx</literal> values below. </PARA><PROGRAMLISTING>#define CYG_TTY_IN_FLAGS_CR 0x0001 // Map '\r' => '\n' on input</PROGRAMLISTING><PARA>If this bit is set in <structfield>tty_in_flags</structfield>, thecharacter "\r" (“return” or “enter” onmost keyboards) will be mapped to "\n".</PARA><PROGRAMLISTING>#define CYG_TTY_IN_FLAGS_CRLF 0x0002 // Map '\r\n' => '\n' on input</PROGRAMLISTING><PARA>If this bit is set in <structfield>tty_in_flags</structfield>, thecharacter sequence "\r\n" (often sent by DOS/Windowsbased terminals) will be mapped to "\n". </PARA><PROGRAMLISTING>#define CYG_TTY_IN_FLAGS_BINARY 0x0004 // No input processing</PROGRAMLISTING><PARA>If this bit is set in <structfield>tty_in_flags</structfield>, theinput will not be manipulated in any way before being placed inthe user’s buffer. </PARA><PROGRAMLISTING>#define CYG_TTY_IN_FLAGS_ECHO 0x0008 // Echo characters as processed</PROGRAMLISTING><PARA>If this bit is set in <structfield>tty_in_flags</structfield>, characterswill be echoed back to the serial port as they are processed. </PARA></SECTION><!-- }}} --><!-- {{{ API Details --><SECTION><TITLE><!-- <index></index> -->API details</TITLE><PROGRAMLISTING>cyg_io_read(handle, buf, len)</PROGRAMLISTING><PARA>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. </PARA><NOTE><PARA>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.</PARA></NOTE><PROGRAMLISTING> cyg_io_write(handle, buf, len)</PROGRAMLISTING><PARA>This function is used to send data to the device. In the defaultcase, the end-of-line character "\n" is replaced by thesequence "\r\n". </PARA><PROGRAMLISTING>cyg_io_get_config(handle, key, buf, len)</PROGRAMLISTING><PARA>This function is used to get information about the channel’sconfiguration at runtime. </PARA><VARIABLELIST> <VARLISTENTRY> <TERM><literal>CYG_IO_GET_CONFIG_TTY_INFO</literal></TERM> <LISTITEM> <variablelist> <VARLISTENTRY> <TERM>Buf type:</TERM> <LISTITEM> <PARA>cyg_tty_info_t</PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>Function:</TERM> <LISTITEM> <PARA>This function retrieves the current state of the driver. </PARA> </listitem> </varlistentry> </variablelist> </listitem> </varlistentry></variablelist><PARA>Serial driver keys (see above) may also be specifiedin which case the call is passed directly to the serialdriver. </PARA><PROGRAMLISTING>cyg_io_set_config(handle, key, buf, len)</PROGRAMLISTING><PARA>This function is used to modify the channel’s configurationat runtime. </PARA><VARIABLELIST> <VARLISTENTRY> <TERM><literal>CYG_IO_SET_CONFIG_TTY_INFO</literal></term> <LISTITEM> <VARIABLELIST> <VARLISTENTRY> <TERM>Buf type:</TERM> <LISTITEM> <PARA>cyg_tty_info_t</PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>Function: </TERM> <LISTITEM> <PARA>This function changes the current state of the driver.</PARA> </LISTITEM> </VARLISTENTRY> </variablelist> </LISTITEM> </VARLISTENTRY></VARIABLELIST><PARA>Serial driverkeys (see above) may also be specified in which case thecall is passed directly to the serial driver. </PARA></SECTION><!-- }}} --></SECTION><!-- }}} --><!-- {{{ DSP Driver --><!-- }}} --></CHAPTER><!-- }}} --><!-- {{{ How to Write a Driver --><CHAPTER id="io-how-to-write-a-driver"><TITLE>How to Write a Driver</TITLE><!-- {{{ Intro --><PARA>A <!-- <index></index> -->device driver is nothing more than anamed entity that supports the basic I/O functions - read, write, getconfig, and set config. Typically a device driver also uses andmanages interrupts from the device. While the interface is generic anddevice driver independent, the actual driver implementation iscompletely up to the device driver designer. </PARA><PARA>That said, the reason for using a device driver is to provideaccess to a device from application code in as general purpose afashion as reasonable. Most driver writers are also concerned withmaking this access as simple as possible while being as efficientas possible. </PARA><PARA>Most device drivers are concerned with the movement of information,for example data bytes along a serial interface, or packets in anetwork. In order to make the most efficient use of system resources,interrupts are used. This will allow other application processingto take place while the data transfers are under way, with interruptsused to indicate when various events have occurred. For example,a serial port typically generates an interrupt after a characterhas been sent “down the wire” and the interfaceis ready for another. It makes sense to allow further applicationprocessing while the data is being sent since this can take quitea long time. The interrupt can be used to allow the driver to senda character as soon as the current one is complete, without anyactive participation by the application code. </PARA><PARA>The main building blocks for device drivers are found in theinclude file: <filename><cyg/io/devtab.h></filename></PARA><PARA>All device drivers in <EMPHASIS>eCos</EMPHASIS> are describedby a device table entry, using the <type>cyg_devtab_entry_t</type> type.The entry should be created using the <FUNCTION>DEVTAB_ENTRY()</FUNCTION> macro,like this:</PARA><PROGRAMLISTING><function>DEVTAB_ENTRY</function>(l, name, dep_name, handlers, init, lookup, priv)</PROGRAMLISTING><variablelist><title>Arguments</title> <varlistentry> <term><parameter>l</parameter></term> <listitem><para>The "C" label for this device table entry.</para></listitem> </varlistentry> <varlistentry> <term><parameter>name</parameter></term> <listitem><para>The "C" string name for the device.</para></listitem> </varlistentry> <varlistentry> <term><parameter>dep_name</parameter></term> <listitem><para>For a layered device, the "C" string name of the device this device is built upon.</para></listitem> </varlistentry> <varlistentry> <term><parameter>handlers</parameter></term> <listitem><para>A pointer to the I/O function "handlers" (see below).</para></listitem> </varlistentry> <varlistentry> <term><parameter>init</parameter></term> <listitem><para>A function called when eCos is initialized. This function can query the device, setup hardware, etc.</para></listitem> </varlistentry> <varlistentry> <term><parameter>lookup</parameter></term> <listitem><para>A function called when <function>cyg_io_lookup()</function> is called for this device. </para></listitem> </varlistentry> <varlistentry> <term><parameter>priv</parameter></term> <listitem><para>A placeholder for any device specific data required by the driver.</para></listitem> </varlistentry></variablelist><PARA>The interface to the driver is through the <structfield><!--<index></index> -->handlers</structfield> field. This is a pointer toa set of functions which implement the various <function>cyg_io_XXX()</function>routines. This table is defined by the macro:</PARA><PROGRAMLISTING>DEVIO_TABLE(l, write, read, get_config, set_config)</PROGRAMLISTING><variablelist><title>Arguments</title> <varlistentry> <term><parameter>l</parameter></term> <listitem><para>The "C" label for this table of handlers.</para></listitem> </varlistentry> <varlistentry> <term>write</term> <listitem><para>The function called as a result of <function>cyg_io_write()</function>.</para></listitem> </varlistentry> <varlistentry> <term>read</term> <listitem><para>The function called as a result of <function>cyg_io_read()</function>. </para></listitem> </varlistentry> <varlistentry> <term>get_config</term> <listitem><para>The function called as a result of <function>cyg_io_get_config()</function>.</para></listitem> </varlistentry> <varlistentry> <term>set_config</term> <listitem><para>The function called as a result of <function>cyg_io_set_config()</function>. </para></listitem> </varlistentry></variablelist><PARA>When <EMPHASIS>eCos</EMPHASIS> is initialized (sometimes called“boot” time), the <function>init()</function> function is calledfor all devices in the system. The <function>init()</function> function isallowed to return an error in which case the device will be placed“off line” and all I/O requests to that device will beconsidered in error.</PARA><PARA>The <function>lookup()</function> function is called wheneverthe <FUNCTION>cyg_io_lookup()</FUNCTION> functionis called with this device name. The lookup function may cause the deviceto come “on line” which would then allow I/Ooperations to proceed. Future versions of the I/O systemwill allow for other states, including power saving modes,etc.</PARA><!-- }}} --><!-- {{{ How to Write a Serial Hardware Interface Driver --><SECTION id="io-how-to-write-serial-interface-driver"><TITLE>How to Write a Serial Hardware Interface Driver</TITLE><PARA>The standard serial driver supplied with<EMPHASIS>eCos</EMPHASIS> is structured as a hardware independentportion and a hardware dependent interface module. To add support fora new serial port, the user should be able to use the existinghardware independent portion and just add their own <!--<index></index> -->interface driver which handles the details of theactual device. The user should have no need to change the hardwareindependent portion. </PARA><PARA>The interfaces used by the serial driver and serial implementationmodules are contained in the file <filename><cyg/io/serial.h></filename></PARA><NOTE><PARA>In the sections below we use the notation <<xx>> tomean a module specific value, referred to as “xx” below.</PARA></NOTE><!-- {{{ DevTab Entry --><section><title>DevTab Entry</title><PARA>The interface module contains the devtab entry (or entriesif a single module supports more than one interface). This entryshould have the form: </PARA><PROGRAMLISTING>DEVTAB_ENTRY(<<module_name>>, <<device_name>>, 0, &serial_devio, <<module_init>>, <<module_lookup>>, &<<serial_channel>> );</PROGRAMLISTING><variablelist><title>Arguments</title> <varlistentry> <term><parameter>module_name</parameter></term>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -