<?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>Classic/Legacy CodeWarrior中的主题 Bit-Fields not working - CW10.2 - K10</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Bit-Fields-not-working-CW10-2-K10/m-p/148780#M1946</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following union in my code. The intent was that the incoming data packet could be stuffed into&amp;nbsp;WEB_MSG__config_unit.data and then each piece of the packet could be individually extracted using something like this WEB_MSG__config_unit.param.UNIT_INFO__FIRMWARE_VERSION.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;union&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; struct { u8&amp;nbsp; MESSAGE_CODE : 8; u8&amp;nbsp; MESSAGE_LENGTH : 8; u8&amp;nbsp; PACKET_NUMBER : 8; u16 UNIT_INFO__FIRMWARE_VERSION : 16; u32 UNIT_INFO__TIMESTAMP : 32; ... u8&amp;nbsp; CHECKSUM : 8; } param;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8 data[64];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } WEB_MSG__config_unit; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I fill the WEB_MSG__config_unit.data with values 1 through 10, like this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://dl.dropbox.com/u/438946/Elecsys/data.png" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank"&gt;&lt;IMG alt="data" border="0" height="250" src="http://dl.dropbox.com/u/438946/Elecsys/data.png" width="394" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;WEB_MSG__config_unit.param shows up like this...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://dl.dropbox.com/u/438946/Elecsys/param.png" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank"&gt;&lt;IMG alt="param" border="0" height="121" src="http://dl.dropbox.com/u/438946/Elecsys/param.png" width="397" /&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would expect UNIT_INFO__FIRMWARE_VERSION to be 0x403, but it appears that the 4th byte (value 0x03) is skipped so that the 16-bit UNIT_INFO__FIRMWARE_VERSION value can start at a new byte boundary.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I fix this to work the way I want?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 08:50:34 GMT</pubDate>
    <dc:creator>ignisuti</dc:creator>
    <dc:date>2020-10-29T08:50:34Z</dc:date>
    <item>
      <title>Bit-Fields not working - CW10.2 - K10</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Bit-Fields-not-working-CW10-2-K10/m-p/148780#M1946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following union in my code. The intent was that the incoming data packet could be stuffed into&amp;nbsp;WEB_MSG__config_unit.data and then each piece of the packet could be individually extracted using something like this WEB_MSG__config_unit.param.UNIT_INFO__FIRMWARE_VERSION.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;union&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; struct { u8&amp;nbsp; MESSAGE_CODE : 8; u8&amp;nbsp; MESSAGE_LENGTH : 8; u8&amp;nbsp; PACKET_NUMBER : 8; u16 UNIT_INFO__FIRMWARE_VERSION : 16; u32 UNIT_INFO__TIMESTAMP : 32; ... u8&amp;nbsp; CHECKSUM : 8; } param;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8 data[64];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } WEB_MSG__config_unit; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I fill the WEB_MSG__config_unit.data with values 1 through 10, like this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://dl.dropbox.com/u/438946/Elecsys/data.png" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank"&gt;&lt;IMG alt="data" border="0" height="250" src="http://dl.dropbox.com/u/438946/Elecsys/data.png" width="394" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;WEB_MSG__config_unit.param shows up like this...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://dl.dropbox.com/u/438946/Elecsys/param.png" rel="nofollow noopener noreferrer noopener noreferrer" target="_blank"&gt;&lt;IMG alt="param" border="0" height="121" src="http://dl.dropbox.com/u/438946/Elecsys/param.png" width="397" /&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would expect UNIT_INFO__FIRMWARE_VERSION to be 0x403, but it appears that the 4th byte (value 0x03) is skipped so that the 16-bit UNIT_INFO__FIRMWARE_VERSION value can start at a new byte boundary.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I fix this to work the way I want?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:50:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Bit-Fields-not-working-CW10-2-K10/m-p/148780#M1946</guid>
      <dc:creator>ignisuti</dc:creator>
      <dc:date>2020-10-29T08:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Bit-Fields not working - CW10.2 - K10</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Bit-Fields-not-working-CW10-2-K10/m-p/148781#M1947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Most likely UNIT_INFO__FIRMWARE_VERSION is word aligne, relative to the start of param struct. C compiler is allowed to do that to improve performance. Also some architectures may not allow word accesses to misaligned address, and even restart when this happens.&lt;/P&gt;&lt;P&gt;1) The best would be to make code portable and not rely on struct packing.&lt;/P&gt;&lt;P&gt;2) add padding byte between .._NUMBER and .._VERSION fields&lt;/P&gt;&lt;P&gt;3) Check compiler manual, maybe it is possible to turn off word alignment ir change struct packing rules. (I'm not familiar with Kinetis).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Mar 2012 23:54:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Bit-Fields-not-working-CW10-2-K10/m-p/148781#M1947</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2012-03-26T23:54:15Z</dc:date>
    </item>
  </channel>
</rss>

