⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io-can-runtime-cfg.html

📁 ecos3.0 beta 的官方文档,html格式
💻 HTML
📖 第 1 页 / 共 3 页
字号:
the config key <CODE
CLASS="VARNAME"
>CYG_IO_SET_CONFIG_CAN_MSGBUF</CODE
>. Once
the buffer is initialized, the CAN data can be changed at any time by
the application.</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>typedef struct cyg_can_msgbuf_cfg_st
{
    cyg_can_msgbuf_cfg_id cfg_id; // configuration id 
    cyg_can_msgbuf_handle handle; // handle to message buffer
    cyg_can_message msg;          // CAN message - for configuration of buffer
} cyg_can_remote_buf;</PRE
></TD
></TR
></TABLE
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><SPAN
CLASS="TYPE"
>cyg_can_msgbuf_cfg_id</SPAN
> <CODE
CLASS="VARNAME"
>cfg_id</CODE
></DT
><DD
><P
>The <CODE
CLASS="VARNAME"
>cfg_id</CODE
> field contains the configuration ID that tells the driver what to do with 
a message buffer (<CODE
CLASS="VARNAME"
>CYGNUM_CAN_MSGBUF_REMOTE_BUF_ADD</CODE
> or 
<CODE
CLASS="VARNAME"
>CYGNUM_CAN_MSGBUF_REMOTE_BUF_WRITE</CODE
>).
          </P
></DD
><DT
><SPAN
CLASS="TYPE"
>cyg_can_msgbuf_handle</SPAN
> <CODE
CLASS="VARNAME"
>handle</CODE
></DT
><DD
><P
>If there is no buffer initialized for this data, the value of the handle field need to be set to 
<CODE
CLASS="VARNAME"
>CYGNUM_CAN_MSGBUF_INIT</CODE
>. After the call to <CODE
CLASS="FUNCTION"
>cyg_io_set_config()</CODE
> 
the handle field contains a valid remote buffer handle ( &gt;= 0) or the value 
<CODE
CLASS="VARNAME"
>CYGNUM_CAN_MSGBUF_NA</CODE
> ( &lt; 0) if no free buffer is available.
          </P
></DD
><DT
><SPAN
CLASS="TYPE"
>cyg_can_message</SPAN
> <CODE
CLASS="VARNAME"
>msg</CODE
></DT
><DD
><P
>The CAN frame that should be transmitted in response to a remote frame.
          </P
></DD
></DL
></DIV
><P
>Example code for setting up a remote response buffer:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cyg_can_remote_buf rtr_buf;

// prepare the remote response buffer
rtr_buf.cfg_id  = CYGNUM_CAN_MSGBUF_REMOTE_BUF_ADD;
rtr_buf.handle  = CYGNUM_CAN_MSGBUF_INIT;
rtr_buf.msg.id  = 0x7FF;
rtr_buf.msg.ext = CYGNUM_CAN_ID_STD;
rtr_buf.msg.rtr = CYGNUM_CAN_FRAME_DATA;
rtr_buf.msg.dlc = 1;
rtr_buf.msg.data[0] = 0xAB;

len = sizeof(rtr_buf);
if (ENOERR != cyg_io_set_config(hDrvFlexCAN,
                                CYG_IO_SET_CONFIG_CAN_MSGBUF,
                                &amp;rtr_buf, &amp;len))
{
    // handle configuration error
}

if (rtr_buf.handle == CYGNUM_CAN_MSGBUF_NA)
{
    // no free message buffer available - handle this problem here
}


// change CAN data for a buffer that is already initialized
rtr_buf.cfg_id = CYGNUM_CAN_MSGBUF_REMOTE_BUF_WRITE;
rtr_buf.msg.data[0] = 0x11;

len = sizeof(rtr_buf);
if (ENOERR != cyg_io_set_config(hDrvFlexCAN,
                                CYG_IO_SET_CONFIG_CAN_MSGBUF,
                                &amp;rtr_buf, &amp;len))
{
    // handle configuration error
} </PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="AEN9523"
>Message filter configuration</A
></H2
><P
>If message filtering is done by hardware the number of received CAN
messages decreases and so also the time for processing received CAN
messages and the memory required for buffering received messages
decreases.  This saves valuable memory and processing time. The eCos
CAN driver supports a generic way of adding message filters. By
default the CAN driver is configured for reception of any kind of CAN
standard and extended frames. As soon as a message filter is added,
the CAN driver will only receive the CAN frames with the identifier of
the CAN filter. By adding a number of message filters it is possible
for the CAN hardware to receive an number of different CAN messages.</P
><P
>Adding message filters is only possible if driver is not configured
for reception of all available CAN messages. If the driver is
configured for reception of all CAN messages then message buffers need
to be reset before adding single message filters.</P
><P
>In order to add a message filter, a message buffer need to be
initialized. This is achieved by
exchanging <SPAN
CLASS="TYPE"
>cyg_can_filter</SPAN
> data structures with the driver
via the <CODE
CLASS="FUNCTION"
>cyg_io_set_config()</CODE
> function using the
config key <CODE
CLASS="VARNAME"
>CYG_IO_SET_CONFIG_CAN_MSGBUF</CODE
>. Once the
buffer is initialized, the CAN hardware can receive messages with the
identifier of the filter.</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 
typedef struct cyg_can_msgbox_cfg_st
{
    cyg_can_msgbuf_cfg_id cfg_id;
    cyg_can_msgbuf_handle handle;
    cyg_can_message       msg;
} cyg_can_filter;</PRE
></TD
></TR
></TABLE
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><SPAN
CLASS="TYPE"
>cyg_can_msgbuf_cfg_id</SPAN
> <CODE
CLASS="VARNAME"
>cfg_id</CODE
></DT
><DD
><P
>The <CODE
CLASS="VARNAME"
>cfg_id</CODE
> field contains the configuration ID that tells the driver what to do with 
a message buffer.
          </P
></DD
><DT
><SPAN
CLASS="TYPE"
>cyg_can_msgbuf_handle</SPAN
> <CODE
CLASS="VARNAME"
>handle</CODE
></DT
><DD
><P
>After the call to <CODE
CLASS="FUNCTION"
>cyg_io_set_config()</CODE
> the handle field contains a valid value 
( &gt;= 0) or the value <CODE
CLASS="VARNAME"
>CYGNUM_CAN_MSGBUF_NA</CODE
> ( &lt; 0) if no free buffer is available. 
          </P
></DD
><DT
><SPAN
CLASS="TYPE"
>cyg_can_message</SPAN
> <CODE
CLASS="VARNAME"
>msg</CODE
></DT
><DD
><P
>The fields <CODE
CLASS="STRUCTFIELD"
>id</CODE
> and <CODE
CLASS="STRUCTFIELD"
>ext</CODE
> of the <CODE
CLASS="STRUCTFIELD"
>msg</CODE
>
configure the type of message to receive by a certain message filter.
          </P
></DD
></DL
></DIV
><P
>Before adding message filters the device should be stopped and after
configuration it should be set into operational mode again.</P
><P
>Example code for setting up a message filter:   </P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 
cyg_can_msgbuf_cfg msgbox_cfg;
cyg_can_filter rx_filter;

// reset all message buffers
msgbox_cfg.cfg_id = CYGNUM_CAN_MSGBUF_RESET_ALL;
len = sizeof(msgbox_cfg);
if (ENOERR != cyg_io_set_config(hDrvFlexCAN, 
                                CYG_IO_SET_CONFIG_CAN_MSGBUF,
                                &amp;msgbox_cfg, &amp;len))
{
    // handle configuration error
}

// prepare the message filter
rx_filter.cfg_id = CYGNUM_CAN_MSGBUF_RX_FILTER_ADD
rx_filter.msg.id  = 0x800;
rx_filter.msg.ext = CYGNUM_CAN_ID_EXT;

len = sizeof(rx_filter);
if (ENOERR != cyg_io_set_config(hDrvFlexCAN,
                                CYG_IO_SET_CONFIG_CAN_MSGBUF,
                                &amp;rx_filter, &amp;len))
{
    // handle configuration error;
}
else if (CYGNUM_CAN_MSGBUF_NA == rx_filter.handle)
{
    // no free message buffer available - handle this problem here
}</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="CAN-MSGFILT-DEACT"
>Message filter deactivation</A
></H2
><P
>After startup of your device the CAN driver is configured for
reception of all available CAN messages.  If you change this
configuration by adding single message filters then you can reset this
default state with the configuration ID:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 
CYGNUM_CAN_MSGBUF_RX_FILTER_ALL</PRE
></TD
></TR
></TABLE
><P
>This message buffer configuration id will clear all message filters
and remote buffers and prepares the CAN hardware for reception of any
kind of CAN standard and extended frames. It is not necessary to reset
the message buffer configuration before this configuration step is
executed because this should be done by device driver.</P
><P
>Example code for deactivation of message filtering:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 
cyg_can_filter rx_filter;

// now setup a RX all configuration
rx_filter.cfg_id = CYGNUM_CAN_MSGBUF_RX_FILTER_ALL;
len = sizeof(rx_filter);
if (ENOERR != cyg_io_set_config(hDrvFlexCAN,
                                CYG_IO_SET_CONFIG_CAN_MSGBUF,
                                &amp;rx_filter, &amp;len))
{
    CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
}</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECTION"
><H2
CLASS="SECTION"
><A
NAME="CAN-EVENT-CALLBACK"
>Configuring a callback on events</A
></H2
><P
>By default application cannot get information about an event arriving
in the RX buffer until it calls
the <CODE
CLASS="FUNCTION"
>cyg_io_read()</CODE
>.  Usually this leads applications
to use accessory threads to wait for new CAN events.</P
><P
>The CDL option <CODE
CLASS="VARNAME"
>CYGOPT_IO_CAN_SUPPORT_CALLBACK</CODE
>
allows application to use a callback on event arrival. It is
configured by passing a <CODE
CLASS="STRUCTNAME"
>cyg_can_callback_cfg</CODE
>
data structure to the driver via
the <CODE
CLASS="FUNCTION"
>cyg_io_set_config()</CODE
> function using the config
key
<CODE
CLASS="VARNAME"
>CYG_IO_SET_CONFIG_CAN_CALLBACK</CODE
>.</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>CYG_IO_SET_CONFIG_CAN_CALLBACK</PRE
></TD
></TR
></TABLE
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>typedef void (*cyg_can_event_cb_t)(cyg_uint16, CYG_ADDRWORD);

typedef struct cyg_can_callback_cfg_st
{
    cyg_can_event_cb_t callback_func;   // callback function
    cyg_uint16  flag_mask;              // flags mask
    CYG_ADDRWORD data;                  // data passed to callback
} cyg_can_callback_cfg;</PRE
></TD
></TR
></TABLE
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><SPAN
CLASS="TYPE"
>cyg_can_event_cb_t</SPAN
> <CODE
CLASS="VARNAME"
>callback_func</CODE
></DT
><DD
><P
> 
Pointer to the callback function. The function will be called from DSR context so
you should be careful to only call API functions that are safe in DSR
context.  The First parameter is a combination of event flags for events that have 
occurred. Second parameter is a user defined data pointer or value.
          </P
></DD
><DT
><SPAN
CLASS="TYPE"
>CYG_ADDRWORD</SPAN
> <CODE
CLASS="VARNAME"
>data</CODE
></DT
><DD
><P
>Additional user data that will be passed to callback function as a second parameter.
          </P
></DD
><DT
><SPAN
CLASS="TYPE"
>cyg_uint16</SPAN
> <CODE
CLASS="VARNAME"
>flag_mask</CODE
></DT
><DD
><P
>Should be set with a combination
of <CODE
CLASS="VARNAME"
>CYGNUM_CAN_EVENT_*</CODE
> flags.  If one of these
events happens, the callback function will be called, with the
actually event flags passed as a parameter.  To disable the callback
function from being called set <CODE
CLASS="VARNAME"
>flag_mask</CODE
> to 0.
          </P
></DD
></DL
></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-can-api-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-configuration.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>API 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"
>Configuration</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>

⌨️ 快捷键说明

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