<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>S32K中的主题 Re: How is the CAN ID filtering logic implemented?</title>
    <link>https://community.nxp.com/t5/S32K/How-is-the-CAN-ID-filtering-logic-implemented/m-p/1063040#M7176</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Strictly speaking CAN ID filtering doesn't support contiguous ranges of ID's. Mask_bit_n=1 means that corresponding ID_bit_n has to match filter_bit_n setting to pass the filter. Mask_bit_n=0 means that corresponding ID_bit_n is don't care, could be either 0 or 1 and still pass the filter. If all bits from 0 to N fulfil above requirements then message is accepted.&amp;nbsp;Usually you can set up more than one filter. Message has to pass just single filter to be accepted. Hardware ID filters may check not only ID bits, but as well they may check some special message bits like IDE or RTR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="" style="color: #000000; background: #f5f2f0; border: 0px; margin: 0.5em 0px; padding: 1em 1em 1em 3.8em;"&gt;&lt;CODE style="border: 0px; font-weight: inherit;"&gt;bool &lt;SPAN class="" style="color: #d74444; border: 0px; font-weight: inherit;"&gt;is_id_valid&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;uint16_t id&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;return&lt;/SPAN&gt; &lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;id &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;"&gt;&amp;amp;&lt;/SPAN&gt; MAILBOX_MASK&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt; &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;"&gt;==&lt;/SPAN&gt; &lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;ACCEPTED_ID &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;"&gt;&amp;amp;&lt;/SPAN&gt; MAILBOX_MASK&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;}&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Yes, your pseudocode is correct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I your case of contiguous 0x404 to 0x407 ID's, only bits 0 and 1 are changing. Mask 0x7FC has bits 0 ant 1 in "don't care" state and all other 11-2 bits in "check it" state. Just single filter and range of ID's perfectly filtered! But you couldn't repeat such success story for ID range like 0x403 to 0x407. Either more filters are needed (for ID 0x403) or you need to accept ID's 0x400..0x407 using single filter and then filter out not our ID's 0x400..0x402 in software.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edward&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 19 Jul 2020 06:22:18 GMT</pubDate>
    <dc:creator>kef2</dc:creator>
    <dc:date>2020-07-19T06:22:18Z</dc:date>
    <item>
      <title>How is the CAN ID filtering logic implemented?</title>
      <link>https://community.nxp.com/t5/S32K/How-is-the-CAN-ID-filtering-logic-implemented/m-p/1063039#M7175</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to improve my understanding of the CAN message ID filtering with the S32K SDK.&lt;BR /&gt;More specifically, I want to understand how to&amp;nbsp;only accept a range of IDs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks to the table &lt;A _jive_internal="true" href="https://community.nxp.com/thread/500761" rel="nofollow noopener noreferrer" target="_blank"&gt;in this answer&lt;/A&gt;, I know that to only accept a range of message ID from 0x404 to 0x407, I need to configure the mailbox as follows:&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="property macro token"&gt;#define ACCEPTED_ID   0x404&lt;/SPAN&gt;
&lt;SPAN class="property macro token"&gt;#define MAILBOX_MASK  0x7FC&lt;/SPAN&gt;

&lt;SPAN class="token function"&gt;CAN_ConfigRxBuff&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="comment token"&gt;/* Other parameters */&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; ACCEPTED_ID&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token function"&gt;CAN_SetRxFilter&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="comment token"&gt;/* Other parameters */&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;  MAILBOX_MASK&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To be honest, I don't fully understand what is happening inside the CAN peripheral.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For learning purposes, here's my attempt&amp;nbsp;at describing the ID filtering logic with C pseudo-code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;// This is how the CAN peripherals filters the RX message ID.&lt;/SPAN&gt;
bool &lt;SPAN class="token function"&gt;is_id_valid&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;uint16_t id&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;id &lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt; MAILBOX_MASK&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ACCEPTED_ID &lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt; MAILBOX_MASK&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Would you agree with this masking logic?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Gabriel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jul 2020 17:51:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/How-is-the-CAN-ID-filtering-logic-implemented/m-p/1063039#M7175</guid>
      <dc:creator>gberthiaume</dc:creator>
      <dc:date>2020-07-17T17:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: How is the CAN ID filtering logic implemented?</title>
      <link>https://community.nxp.com/t5/S32K/How-is-the-CAN-ID-filtering-logic-implemented/m-p/1063040#M7176</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Strictly speaking CAN ID filtering doesn't support contiguous ranges of ID's. Mask_bit_n=1 means that corresponding ID_bit_n has to match filter_bit_n setting to pass the filter. Mask_bit_n=0 means that corresponding ID_bit_n is don't care, could be either 0 or 1 and still pass the filter. If all bits from 0 to N fulfil above requirements then message is accepted.&amp;nbsp;Usually you can set up more than one filter. Message has to pass just single filter to be accepted. Hardware ID filters may check not only ID bits, but as well they may check some special message bits like IDE or RTR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="" style="color: #000000; background: #f5f2f0; border: 0px; margin: 0.5em 0px; padding: 1em 1em 1em 3.8em;"&gt;&lt;CODE style="border: 0px; font-weight: inherit;"&gt;bool &lt;SPAN class="" style="color: #d74444; border: 0px; font-weight: inherit;"&gt;is_id_valid&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;uint16_t id&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;return&lt;/SPAN&gt; &lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;id &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;"&gt;&amp;amp;&lt;/SPAN&gt; MAILBOX_MASK&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt; &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;"&gt;==&lt;/SPAN&gt; &lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;ACCEPTED_ID &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;"&gt;&amp;amp;&lt;/SPAN&gt; MAILBOX_MASK&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;}&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Yes, your pseudocode is correct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I your case of contiguous 0x404 to 0x407 ID's, only bits 0 and 1 are changing. Mask 0x7FC has bits 0 ant 1 in "don't care" state and all other 11-2 bits in "check it" state. Just single filter and range of ID's perfectly filtered! But you couldn't repeat such success story for ID range like 0x403 to 0x407. Either more filters are needed (for ID 0x403) or you need to accept ID's 0x400..0x407 using single filter and then filter out not our ID's 0x400..0x402 in software.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edward&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Jul 2020 06:22:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/How-is-the-CAN-ID-filtering-logic-implemented/m-p/1063040#M7176</guid>
      <dc:creator>kef2</dc:creator>
      <dc:date>2020-07-19T06:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: How is the CAN ID filtering logic implemented?</title>
      <link>https://community.nxp.com/t5/S32K/How-is-the-CAN-ID-filtering-logic-implemented/m-p/1063041#M7177</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks; this is exactly the answer I was looking for.&lt;/P&gt;&lt;P&gt;Your examples were great.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards,&lt;/P&gt;&lt;P&gt;Gabriel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Jul 2020 18:18:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/How-is-the-CAN-ID-filtering-logic-implemented/m-p/1063041#M7177</guid>
      <dc:creator>gberthiaume</dc:creator>
      <dc:date>2020-07-20T18:18:43Z</dc:date>
    </item>
  </channel>
</rss>

