io-how-to-write-a-driver.html
字号:
></P
><DL
><DT
><CODE
CLASS="PARAMETER"
>l</CODE
></DT
><DD
><P
>The "C" label for this structure.</P
></DD
><DT
><CODE
CLASS="PARAMETER"
>funs</CODE
></DT
><DD
><P
>The set of interface functions (see below).</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>dev_priv</CODE
></DT
><DD
><P
>A placeholder for any device specific data for
this channel.</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>baud</CODE
></DT
><DD
><P
>The initial baud rate value
(<SPAN
CLASS="TYPE"
>cyg_serial_baud_t</SPAN
>).</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>stop</CODE
></DT
><DD
><P
>The initial stop bits value
(<SPAN
CLASS="TYPE"
>cyg_serial_stop_bits_t</SPAN
>).</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>parity</CODE
></DT
><DD
><P
>The initial parity mode value
(<SPAN
CLASS="TYPE"
>cyg_serial_parity_t</SPAN
>).</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>word_length</CODE
></DT
><DD
><P
>The initial word length value
(<SPAN
CLASS="TYPE"
>cyg_serial_word_length_t</SPAN
>).</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>flags</CODE
></DT
><DD
><P
>The initial driver flags value.</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>out_buf</CODE
></DT
><DD
><P
>Pointer to the output
buffer. <TT
CLASS="LITERAL"
>NULL</TT
> if none required.</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>out_buflen</CODE
></DT
><DD
><P
>The length of the output buffer.</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>in_buf</CODE
></DT
><DD
><P
>pointer to the input
buffer. <TT
CLASS="LITERAL"
>NULL</TT
> if none required.</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>in_buflen</CODE
></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 <CODE
CLASS="STRUCTFIELD"
>funs</CODE
> table.
This is defined by the macro:</P
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN5823"
>Serial Functions Structure</A
></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
><CODE
CLASS="STRUCTFIELD"
>l</CODE
></DT
><DD
><P
>The "C" label for this structure.</P
></DD
><DT
><CODE
CLASS="STRUCTFIELD"
>putc</CODE
></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
><CODE
CLASS="STRUCTFIELD"
>getc</CODE
></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
><CODE
CLASS="STRUCTFIELD"
>set_config</CODE
></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
><CODE
CLASS="PARAMETER"
>start_xmit</CODE
></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
><CODE
CLASS="PARAMETER"
>stop_xmit</CODE
></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="AEN5872"
>Callbacks</A
></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 <CODE
CLASS="FUNCTION"
>putc</CODE
>
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 <CODE
CLASS="FUNCTION"
>xmt_char()</CODE
> to get a single
character for transmission at a time, the driver should call
<CODE
CLASS="FUNCTION"
>data_xmt_req()</CODE
> in a loop, requesting character
blocks for transfer. Call with a <CODE
CLASS="PARAMETER"
>space</CODE
> 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
<CODE
CLASS="PARAMETER"
>chars_avail</CODE
> characters from
<CODE
CLASS="PARAMETER"
>chars</CODE
> 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 <CODE
CLASS="FUNCTION"
>data_xmt_done()</CODE
>.</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 <CODE
CLASS="FUNCTION"
>rcv_char()</CODE
> with a single
character at a time, the driver should call
<CODE
CLASS="FUNCTION"
>data_rcv_req()</CODE
> in a loop, requesting space to
unload the FIFO to. <CODE
CLASS="PARAMETER"
>avail</CODE
> 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
<CODE
CLASS="PARAMETER"
>space_avail</CODE
> characters to
<CODE
CLASS="PARAMETER"
>space</CODE
>. </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
<CODE
CLASS="FUNCTION"
>data_rcv_done()</CODE
>.</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 + -