📄 io-can-api-details.html
字号:
the call will not return until one single CAN event has been read.
In non-blocking mode, if there is no CAN event in buffer, the call
returns immediately with <CODE
CLASS="VARNAME"
>-EAGAIN</CODE
> and the caller must
try again.</P
><P
>It is possible to configure the write call to be non-blocking with timeout.
None-blocking mode with timeout requires the configuration option
<CODE
CLASS="VARNAME"
>CYGOPT_IO_CAN_SUPPORT_NONBLOCKING</CODE
> and
<CODE
CLASS="VARNAME"
>CYGOPT_IO_CAN_SUPPORT_TIMEOUTS</CODE
> to be enabled,
requires the eCos kernel package to be included and the specific device
to be set to non-blocking mode for reads (see
<CODE
CLASS="FUNCTION"
>cyg_io_set_config()</CODE
>). In non-blocking mode with timeouts,
if there is no CAN event in receive buffer, the driver waits a certain amount
of time (the timeout time) for a CAN event to arrive. If there is still no
CAN event in buffer after expiration of the timeout time, <CODE
CLASS="VARNAME"
>-EINTR</CODE
>
is returned and the caller must try again.</P
><P
>If a event was sucessfully received, the function returns <CODE
CLASS="VARNAME"
>ENOERR</CODE
>. </P
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN9163"
>CAN Events</A
></H2
><P
>The CAN driver uses <CODE
CLASS="STRUCTNAME"
>cyg_can_event</CODE
> structures to
pass events from hardware device driver to the generic CAN driver.
A <CODE
CLASS="STRUCTNAME"
>cyg_can_event</CODE
> provides a generic device
independent type for handling CAN events that may occur.</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>typedef struct cyg_can_event_st
{
cyg_uint32 timestamp;
cyg_can_message msg;
cyg_uint16 flags;
} cyg_can_event;</PRE
></TD
></TR
></TABLE
><P
>The structure contains the following fields:</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><SPAN
CLASS="TYPE"
>cyg_uint32</SPAN
> <CODE
CLASS="VARNAME"
>timestamp</CODE
></DT
><DD
><P
>If the hardware CAN device driver supports timestamps then this field may
contain a timestamp value for an event that occured.
</P
></DD
><DT
><SPAN
CLASS="TYPE"
>cyg_can_message</SPAN
> <CODE
CLASS="VARNAME"
>msg</CODE
></DT
><DD
><P
>CAN message. The msg field contains a CAN message if an RX or TX event
occured. If another type of event occured,
the <CODE
CLASS="STRUCTFIELD"
>data</CODE
> field of
the <CODE
CLASS="STRUCTFIELD"
>msg</CODE
> may contain additional event
specific data.
</P
></DD
><DT
><SPAN
CLASS="TYPE"
>cyg_uint16</SPAN
> <CODE
CLASS="VARNAME"
>flags</CODE
></DT
><DD
><P
>Event flags. The <CODE
CLASS="VARNAME"
>flags</CODE
> field contains 16 bits that
indicate which kind of events occured.
</P
></DD
></DL
></DIV
><P
>The following events are supported and after receiving an event the
application should check the flag field against these values:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>typedef enum
{
CYGNUM_CAN_EVENT_RX = 0x0001, // message received
CYGNUM_CAN_EVENT_TX = 0x0002, // message transmitted
CYGNUM_CAN_EVENT_WARNING_RX = 0x0004, // (TEC) reached warning level (>96)
CYGNUM_CAN_EVENT_WARNING_TX = 0x0008, // (REC) reached warning level (>96)
CYGNUM_CAN_EVENT_ERR_PASSIVE = 0x0010, // CAN "error passive" occured
CYGNUM_CAN_EVENT_BUS_OFF = 0x0020, // CAN "bus off" error occured
CYGNUM_CAN_EVENT_OVERRUN_RX = 0x0040, // overrun in RX queue or hardware
CYGNUM_CAN_EVENT_OVERRUN_TX = 0x0080, // overrun in TX queue occured
CYGNUM_CAN_EVENT_CAN_ERR = 0x0100, // a CAN bit or frame error occured
CYGNUM_CAN_EVENT_LEAVING_STANDBY = 0x0200, // CAN hardware leaves standby
CYGNUM_CAN_EVENT_ENTERING_STANDBY = 0x0400, // CAN hardware enters standby
CYGNUM_CAN_EVENT_ARBITRATION_LOST = 0x0800, // arbitration lost
CYGNUM_CAN_EVENT_FILTER_ERR = 0x1000, // CAN message filter / acceptance filter error
CYGNUM_CAN_EVENT_PHY_FAULT = 0x2000, // General failure of physical layer
CYGNUM_CAN_EVENT_PHY_H = 0x4000, // Fault on CAN-H (Low Speed CAN)
CYGNUM_CAN_EVENT_PHY_L = 0x8000, // Fault on CAN-L (Low Speed CAN)
} cyg_can_event_flags;</PRE
></TD
></TR
></TABLE
><P
>Often the flags field will contain only one single set flag. But it is
possible that a number of flags is set and so the flag field should always
be checked by a receiver. I.e. if the <CODE
CLASS="VARNAME"
>CYGNUM_CAN_EVENT_RX</CODE
>
is set then also the <CODE
CLASS="VARNAME"
>CYGNUM_CAN_EVENT_OVERRUN_RX</CODE
>
may be set if the received message caused an RX overrun.</P
><P
>The internal receive buffers of the CAN device driver are circular buffers.
That means that even if the buffers are completely filled new messages
will be received. In this case the newest message will always overwrite
the oldest message in receive buffer. If this happens the
<CODE
CLASS="VARNAME"
>CYGNUM_CAN_EVENT_OVERRUN_RX</CODE
> flag will be set for this
new message that caused overwriting of the old one. The
<CODE
CLASS="VARNAME"
>CYGNUM_CAN_EVENT_OVERRUN_RX</CODE
> flag will be set also if
a overrun occures in hardware message buffers of the CAN device.</P
><P
>Example code for receiving one single CAN event:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cyg_can_event rx_event;
cyg_uint32 len;
Cyg_ErrNo ret;
len = sizeof(rx_event);
ret = cyg_io_read(hDrvCAN, &rx_event, &len);
if (ENOERR == ret)
{
if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
{
// handle RX event
}
if (rx_event.flags & ~CYGNUM_CAN_EVENT_RX)
{
// handle other events
}
}
else if (-EINTR == ret)
{
// handle timeout
}</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN9202"
>cyg_io_get_config</A
></H2
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cyg_io_get_config(handle, key, buf, len)</PRE
></TD
></TR
></TABLE
><P
>This function is used to obtain run-time configuration about a device.
The type of information retrieved is specified by the <CODE
CLASS="PARAMETER"
>key</CODE
>.
The data will be returned in the given buffer. The value of
<CODE
CLASS="PARAMETER"
>*len</CODE
> should contain the amount of data requested,
which must be at least as large as the size appropriate to the selected
<CODE
CLASS="PARAMETER"
>key</CODE
>. The actual size of data retrieved is placed
in <CODE
CLASS="PARAMETER"
>*len</CODE
>. The appropriate key values are all listed
in the file <TT
CLASS="FILENAME"
><cyg/io/config_keys.h></TT
>. </P
><P
>The following config keys are currently supported:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>CYG_IO_GET_CONFIG_READ_BLOCKING
CYG_IO_GET_CONFIG_WRITE_BLOCKING
CYG_IO_GET_CONFIG_CAN_INFO
CYG_IO_GET_CONFIG_CAN_BUFFER_INFO
CYG_IO_GET_CONFIG_CAN_MSGBUF_INFO
CYG_IO_GET_CONFIG_CAN_TIMEOUT
CYG_IO_GET_CONFIG_CAN_HDI
CYG_IO_GET_CONFIG_CAN_STATE</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN9213"
>cyg_io_set_config</A
></H2
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cyg_io_set_config(handle, key, buf, len)</PRE
></TD
></TR
></TABLE
><P
>This function is used to manipulate or change the run-time configuration
of a device. The type of information is specified by the <CODE
CLASS="PARAMETER"
>key</CODE
>.
The data will be obtained from the given buffer. The value of
<CODE
CLASS="PARAMETER"
>*len</CODE
> should contain the amount of data provided,
which must match the size appropriate to the selected <CODE
CLASS="PARAMETER"
>key</CODE
>.
The appropriate key values are all listed in the file
<TT
CLASS="FILENAME"
><cyg/io/config_keys.h></TT
>. </P
><P
>The following config keys are currently supported:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>CYG_IO_SET_CONFIG_READ_BLOCKING
CYG_IO_SET_CONFIG_WRITE_BLOCKING
CYG_IO_SET_CONFIG_CAN_INFO
CYG_IO_SET_CONFIG_CAN_OUTPUT_DRAIN
CYG_IO_SET_CONFIG_CAN_OUTPUT_FLUSH
CYG_IO_SET_CONFIG_CAN_INPUT_FLUSH
CYG_IO_SET_CONFIG_CAN_TIMEOUT
CYG_IO_SET_CONFIG_CAN_MSGBUF
CYG_IO_SET_CONFIG_CAN_MODE
CYG_IO_SET_CONFIG_CAN_ABORT
CYG_IO_SET_CONFIG_CAN_CALLBACK</PRE
></TD
></TR
></TABLE
></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-can-driver-details.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-can-runtime-cfg.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>CAN driver details</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="io-can-driver-details.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Runtime Configuration</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -