📄 io-how-to-write-a-driver.html
字号:
></DD
><DT
><TT
CLASS="PARAMETER"
><I
>funs</I
></TT
></DT
><DD
><P
>The set of interface functions (see below).</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>dev_priv</I
></TT
></DT
><DD
><P
>A placeholder for any device specific data for
this channel.</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>baud</I
></TT
></DT
><DD
><P
>The initial baud rate value
(<SPAN
CLASS="TYPE"
>cyg_serial_baud_t</SPAN
>).</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>stop</I
></TT
></DT
><DD
><P
>The initial stop bits value
(<SPAN
CLASS="TYPE"
>cyg_serial_stop_bits_t</SPAN
>).</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>parity</I
></TT
></DT
><DD
><P
>The initial parity mode value
(<SPAN
CLASS="TYPE"
>cyg_serial_parity_t</SPAN
>).</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>word_length</I
></TT
></DT
><DD
><P
>The initial word length value
(<SPAN
CLASS="TYPE"
>cyg_serial_word_length_t</SPAN
>).</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>flags</I
></TT
></DT
><DD
><P
>The initial driver flags value.</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>out_buf</I
></TT
></DT
><DD
><P
>Pointer to the output
buffer. <TT
CLASS="LITERAL"
>NULL</TT
> if none required.</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>out_buflen</I
></TT
></DT
><DD
><P
>The length of the output buffer.</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>in_buf</I
></TT
></DT
><DD
><P
>pointer to the input
buffer. <TT
CLASS="LITERAL"
>NULL</TT
> if none required.</P
></DD
><DT
><TT
CLASS="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 place
in that direction and only polled mode functions will be used.</P
><P
>The interface from the hardware independent driver into the
hardware interface module is contained in the <TT
CLASS="STRUCTFIELD"
><I
>funs</I
></TT
> table.
This is defined by the macro:</P
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN10992">Serial Functions Structure</H2
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>SERIAL_FUNS(l, putc, getc, set_config, start_xmit, stop_xmit)</PRE
></TD
></TR
></TABLE
><P
></P
><DIV
CLASS="VARIABLELIST"
><P
><B
>Arguments</B
></P
><DL
><DT
><TT
CLASS="STRUCTFIELD"
><I
>l</I
></TT
></DT
><DD
><P
>The "C" label for this structure.</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>putc</I
></TT
></DT
><DD
><P
><TT
CLASS="LITERAL"
>bool (*putc)(serial_channel *priv, unsigned char
c)</TT
></P
><P
> This function sends one character to the interface. It should
return <TT
CLASS="LITERAL"
>true</TT
> if the character is actually consumed. It should
return <TT
CLASS="LITERAL"
>false</TT
> if there is no space in the interface
</P
></DD
><DT
><TT
CLASS="STRUCTFIELD"
><I
>getc</I
></TT
></DT
><DD
><P
><TT
CLASS="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
><TT
CLASS="STRUCTFIELD"
><I
>set_config</I
></TT
></DT
><DD
><P
><TT
CLASS="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
<TT
CLASS="LITERAL"
>true</TT
> if the hardware is updated to match the desired
configuration. It should return <TT
CLASS="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
><TT
CLASS="PARAMETER"
><I
>start_xmit</I
></TT
></DT
><DD
><P
><TT
CLASS="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
><TT
CLASS="PARAMETER"
><I
>stop_xmit</I
></TT
></DT
><DD
><P
><TT
CLASS="LITERAL"
>void (*stop_xmit)(serial_channel *priv)</TT
></P
><P
>In interrupt mode, turn off the transmitter.</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN11041">Callbacks</H2
><P
>The device interface module can execute functions in the
hardware independent driver via <TT
CLASS="LITERAL"
>chan->callbacks</TT
>.
These functions are available:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void (*serial_init)( serial_channel *chan )</PRE
></TD
></TR
></TABLE
><P
>This function is used to initialize the serial channel. It
is only required if the channel is being used in interrupt
mode.</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void (*xmt_char)( serial_channel *chan )</PRE
></TD
></TR
></TABLE
><P
>This function would be called from an interrupt handler after a
transmit interrupt indicating that additional characters may be
sent. The upper driver will call the <TT
CLASS="FUNCTION"
>putc</TT
>
function as appropriate to send more data to the device.</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="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 arrived
at the interface. This function is typically called from the interrupt
handler. </P
><P
>Furthermore, if the device has a FIFO it should require the hardware
independent driver to provide block transfer functionality (driver CDL
should include "implements
CYGINT_IO_SERIAL_BLOCK_TRANSFER"). In that case, the following
functions are available as well:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="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 <TT
CLASS="FUNCTION"
>xmt_char()</TT
> to get a single
character for transmission at a time, the driver should call
<TT
CLASS="FUNCTION"
>data_xmt_req()</TT
> in a loop, requesting character
blocks for transfer. Call with a <TT
CLASS="PARAMETER"
><I
>space</I
></TT
> argument of how much space
there is available in the FIFO.</P
><P
>If the call returns <TT
CLASS="LITERAL"
>true</TT
>, the driver can read
<TT
CLASS="PARAMETER"
><I
>chars_avail</I
></TT
> characters from
<TT
CLASS="PARAMETER"
><I
>chars</I
></TT
> and copy them into the FIFO.</P
><P
>If the call returns <TT
CLASS="LITERAL"
>false</TT
>, there are
no more buffered characters and the driver should continue without
filling up the FIFO.</P
><P
>When all data has been unloaded, the
driver must call <TT
CLASS="FUNCTION"
>data_xmt_done()</TT
>.</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="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 <TT
CLASS="FUNCTION"
>rcv_char()</TT
> with a single
character at a time, the driver should call
<TT
CLASS="FUNCTION"
>data_rcv_req()</TT
> in a loop, requesting space to
unload the FIFO to. <TT
CLASS="PARAMETER"
><I
>avail</I
></TT
> is the number of
characters the driver wishes to unload.</P
><P
>If the call returns <TT
CLASS="LITERAL"
>true</TT
>, the driver can copy
<TT
CLASS="PARAMETER"
><I
>space_avail</I
></TT
> characters to
<TT
CLASS="PARAMETER"
><I
>space</I
></TT
>. </P
><P
>If the call returns <TT
CLASS="LITERAL"
>false</TT
>, the input buffer is
full. It is up to the driver to decide what to do in that case
(callback functions for registering overflow are being planned for
later versions of the serial driver).</P
><P
>When all data has been unloaded, the driver must call
<TT
CLASS="FUNCTION"
>data_rcv_done()</TT
>.</P
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="io-tty-driver.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ecos-ref.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="io-serial-testing-with-serfilter.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>TTY driver</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="io.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Serial testing with ser_filter</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -