io-how-to-write-a-driver.html

来自「有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等」· HTML 代码 · 共 1,154 行 · 第 1/2 页

HTML
1,154
字号
></DD><DT><TTCLASS="PARAMETER"><I>funs</I></TT></DT><DD><P>The set of interface functions (see below).</P></DD><DT><TTCLASS="STRUCTFIELD"><I>dev_priv</I></TT></DT><DD><P>A placeholder for any device specific data for    this channel.</P></DD><DT><TTCLASS="STRUCTFIELD"><I>baud</I></TT></DT><DD><P>The initial baud rate value    (<SPANCLASS="TYPE">cyg_serial_baud_t</SPAN>).</P></DD><DT><TTCLASS="STRUCTFIELD"><I>stop</I></TT></DT><DD><P>The initial stop bits value    (<SPANCLASS="TYPE">cyg_serial_stop_bits_t</SPAN>).</P></DD><DT><TTCLASS="STRUCTFIELD"><I>parity</I></TT></DT><DD><P>The initial parity mode value    (<SPANCLASS="TYPE">cyg_serial_parity_t</SPAN>).</P></DD><DT><TTCLASS="STRUCTFIELD"><I>word_length</I></TT></DT><DD><P>The initial word length value    (<SPANCLASS="TYPE">cyg_serial_word_length_t</SPAN>).</P></DD><DT><TTCLASS="STRUCTFIELD"><I>flags</I></TT></DT><DD><P>The initial driver flags value.</P></DD><DT><TTCLASS="STRUCTFIELD"><I>out_buf</I></TT></DT><DD><P>Pointer to the output    buffer. <TTCLASS="LITERAL">NULL</TT> if none required.</P></DD><DT><TTCLASS="STRUCTFIELD"><I>out_buflen</I></TT></DT><DD><P>The length of the output buffer.</P></DD><DT><TTCLASS="STRUCTFIELD"><I>in_buf</I></TT></DT><DD><P>pointer to the input    buffer. <TTCLASS="LITERAL">NULL</TT> if none required.</P></DD><DT><TTCLASS="STRUCTFIELD"><I>in_buflen</I></TT></DT><DD><P>The length of the input buffer. </P></DD></DL></DIV><P>If either buffer length is zero, no buffering will take placein that direction and only polled mode functions will be used.</P><P>The interface from the hardware independent driver into thehardware interface module is contained in the <TTCLASS="STRUCTFIELD"><I>funs</I></TT> table.This is defined by the macro:</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN10993">Serial Functions Structure</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">SERIAL_FUNS(l, putc, getc, set_config, start_xmit, stop_xmit)</PRE></TD></TR></TABLE><P></P><DIVCLASS="VARIABLELIST"><P><B>Arguments</B></P><DL><DT><TTCLASS="STRUCTFIELD"><I>l</I></TT></DT><DD><P>The "C" label for this structure.</P></DD><DT><TTCLASS="STRUCTFIELD"><I>putc</I></TT></DT><DD><P><TTCLASS="LITERAL">bool (*putc)(serial_channel *priv, unsigned char      c)</TT></P><P>      This function sends one character to the interface. It should      return <TTCLASS="LITERAL">true</TT> if the character is actually consumed. It should      return <TTCLASS="LITERAL">false</TT> if there is no space in the interface      </P></DD><DT><TTCLASS="STRUCTFIELD"><I>getc</I></TT></DT><DD><P><TTCLASS="LITERAL">unsigned char (*getc)(serial_channel *priv)</TT></P><P>      This function fetches one character from the interface. It will      be only called in a non-interrupt driven mode, thus it should      wait for a character by polling the device until ready.      </P></DD><DT><TTCLASS="STRUCTFIELD"><I>set_config</I></TT></DT><DD><P><TTCLASS="LITERAL">bool (*set_config)(serial_channel      *priv,cyg_serial_info_t *config)</TT></P><P>        This function is used to configure the port. It should return        <TTCLASS="LITERAL">true</TT> if the hardware is updated to match the desired        configuration. It should return <TTCLASS="LITERAL">false</TT> if the port cannot        support some parameter specified by the given        configuration. E.g. selecting 1.5 stop bits and 8 data bits is        invalid for most serial devices and should not be allowed.      </P></DD><DT><TTCLASS="PARAMETER"><I>start_xmit</I></TT></DT><DD><P><TTCLASS="LITERAL">void (*start_xmit)(serial_channel *priv)</TT></P><P>        In interrupt mode, turn on the transmitter and allow for        transmit interrupts.      </P></DD><DT><TTCLASS="PARAMETER"><I>stop_xmit</I></TT></DT><DD><P><TTCLASS="LITERAL">void (*stop_xmit)(serial_channel *priv)</TT></P><P>In interrupt mode, turn off the transmitter.</P></DD></DL></DIV></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN11042">Callbacks</H2><P>The device interface module can execute functions in thehardware independent driver via <TTCLASS="LITERAL">chan-&gt;callbacks</TT>.These functions are available:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">void (*serial_init)( serial_channel *chan )</PRE></TD></TR></TABLE><P>This function is used to initialize the serial channel. Itis only required if the channel is being used in interruptmode.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">void (*xmt_char)( serial_channel *chan )</PRE></TD></TR></TABLE><P>This function would be called from an interrupt handler after atransmit interrupt indicating that additional characters may besent. The upper driver will call the <TTCLASS="FUNCTION">putc</TT>function as appropriate to send more data to the device.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">void (*rcv_char)( serial_channel *chan, unsigned char c )</PRE></TD></TR></TABLE><P>This function is used to tell the driver that a character has arrivedat the interface. This function is typically called from the interrupthandler. </P><P>Furthermore, if the device has a FIFO it should require the hardwareindependent driver to provide block transfer functionality (driver CDLshould include &quot;implementsCYGINT_IO_SERIAL_BLOCK_TRANSFER&quot;).  In that case, the followingfunctions are available as well:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">bool (*data_xmt_req)(serial_channel *chan,                     int space,                     int* chars_avail,                     unsigned char** chars)void (*data_xmt_done)(serial_channel *chan)</PRE></TD></TR></TABLE><P>Instead of calling <TTCLASS="FUNCTION">xmt_char()</TT> to get a singlecharacter for transmission at a time, the driver should call<TTCLASS="FUNCTION">data_xmt_req()</TT> in a loop, requesting characterblocks for transfer. Call with a <TTCLASS="PARAMETER"><I>space</I></TT> argument of how much spacethere is available in the FIFO.</P><P>If the call returns <TTCLASS="LITERAL">true</TT>, the driver can read<TTCLASS="PARAMETER"><I>chars_avail</I></TT> characters from<TTCLASS="PARAMETER"><I>chars</I></TT> and copy them into the FIFO.</P><P>If the call returns <TTCLASS="LITERAL">false</TT>, there areno more buffered characters and the driver should continue withoutfilling up the FIFO.</P><P>When all data has been unloaded, thedriver must call <TTCLASS="FUNCTION">data_xmt_done()</TT>.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">bool (*data_rcv_req)(serial_channel *chan,                     int avail,                     int* space_avail,                     unsigned char** space)void (*data_rcv_done)(serial_channel *chan)</PRE></TD></TR></TABLE><P>Instead of calling <TTCLASS="FUNCTION">rcv_char()</TT> with a singlecharacter at a time, the driver should call<TTCLASS="FUNCTION">data_rcv_req()</TT> in a loop, requesting space tounload the FIFO to. <TTCLASS="PARAMETER"><I>avail</I></TT> is the number ofcharacters the driver wishes to unload.</P><P>If the call returns <TTCLASS="LITERAL">true</TT>, the driver can copy<TTCLASS="PARAMETER"><I>space_avail</I></TT> characters to<TTCLASS="PARAMETER"><I>space</I></TT>. </P><P>If the call returns <TTCLASS="LITERAL">false</TT>, the input buffer isfull. It is up to the driver to decide what to do in that case(callback functions for registering overflow are being planned forlater versions of the serial driver).</P><P>When all data has been unloaded, the driver must call<TTCLASS="FUNCTION">data_rcv_done()</TT>.</P></DIV></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-tty-driver.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-testing-with-serfilter.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">TTY driver</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Serial testing with ser_filter</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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