<?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>topic Re: Hi,   I'm converting over from using the IAR compiler for... in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204129#M7804</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello Phil,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In this case, you would need to place the restore macro just prior to each return statement.&amp;nbsp; Or perhaps create another macro that provides both the restore and return process.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#define _critical&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm&amp;nbsp; pshc;&amp;nbsp;_&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;_asm&amp;nbsp; sei;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#define _critical_return(x)&amp;nbsp;__asm&amp;nbsp; pulc; return(x);&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Obviously not quite as convenient as having a special compiler specific keyword available.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Mar 2008 09:50:15 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2008-03-20T09:50:15Z</dc:date>
    <item>
      <title>Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204125#M7800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'm converting over from using the IAR compiler for the HCS12.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have found that CodeWarrior does not support a nifty function generation attribute called "__monitor".&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This attribute causes the function to generate code to, on entry,&amp;nbsp;save the current interrupt enable status &amp;amp; disable interrupts; then, on exit, restore the saved interrupt enable status.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This is a really useful tool.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Does anyone know of an implementation work around for CodeWarrior or whether Freescale intends to support this functionality?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;regards&lt;/DIV&gt;&lt;DIV&gt;PhilW&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2008 10:40:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204125#M7800</guid>
      <dc:creator>electropw</dc:creator>
      <dc:date>2008-03-18T10:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204126#M7801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;If you mean the global interrupt enable/disable (the "I" bit in the condition code register), this is done by the hardware.&lt;BR /&gt;&lt;BR /&gt;If you mean the cause of the interrupt, there is no support for it as far as I know. There is no big deal looking it up yourself, since you need to know how every interrupt work anyway. They all tend to be somewhat different, and so is the way to clear the interrupt flags.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2008 14:30:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204126#M7801</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2008-03-18T14:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204127#M7802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;Hello Phil,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am not sure whether this provides what you require -&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;void func( void)&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;{&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; __asm&amp;nbsp; pshc;&amp;nbsp; // Save current CCR state&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; __asm&amp;nbsp; sei;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Disable interrupts&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; /* Function code here */&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; __asm&amp;nbsp; pulc;&amp;nbsp; //&amp;nbsp; Restore previous CCR state&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;}&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2008 16:59:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204127#M7802</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-03-18T16:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204128#M7803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Mac,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks for your reply. Yes I tried this, created a coupla macros to do it.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Unfortunately it is not versatile enough unless you have a simple function that falls straight through or you write your code specifically to support the macro insertions.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For example you may try&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;char function ( a,b )&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; SaveIEstatusDisableI;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; return a + b;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; RestoreIEStatus;&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This will not work since the compiler automatically generates the return code in the return statement and then inserts the macro code following it, and it will never be executed.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The beauty of the IAR __monitor keyword is that it does the IE status saving and resoration automatically, no matter how many return statements you may have within your function.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;regards&lt;/DIV&gt;&lt;DIV&gt;Phil&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 08:11:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204128#M7803</guid>
      <dc:creator>electropw</dc:creator>
      <dc:date>2008-03-20T08:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204129#M7804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello Phil,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;In this case, you would need to place the restore macro just prior to each return statement.&amp;nbsp; Or perhaps create another macro that provides both the restore and return process.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#define _critical&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm&amp;nbsp; pshc;&amp;nbsp;_&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;_asm&amp;nbsp; sei;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#define _critical_return(x)&amp;nbsp;__asm&amp;nbsp; pulc; return(x);&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Obviously not quite as convenient as having a special compiler specific keyword available.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 09:50:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204129#M7804</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-03-20T09:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204130#M7805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Mac,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Good idea.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'll try it.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks again.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 10:57:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204130#M7805</guid>
      <dc:creator>electropw</dc:creator>
      <dc:date>2008-03-20T10:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204131#M7806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Mac,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Bugger!!!!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;will not work either, very close though.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Will depend in what you are doing in the code as to how you would implement the use.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;To explain, One of the uses I had in mind was to protect a global variables value whilst reading it or writing it, either in an IRQ or in a background access.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;int read_x( int x )&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x;&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This produces code, LDD x; RTS.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;With our solution&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;int read_x( int x )&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _critical&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _critical_return (x)&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;produces&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PSHC&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SEI&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PULC&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDD x&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RTS&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;A pointless operation huh!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;We would have to try and maybe load a local with x and return the local and then ensure the compiler&lt;/DIV&gt;&lt;DIV&gt;does not optimize out our uae of the local.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have contacted CodeWarrior and they tell me they will look at it and put it on the requested functionality&lt;/DIV&gt;&lt;DIV&gt;list. So no immediate nice solution, if there ever will be.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I might try and see if I can do some sort of&amp;nbsp; macro function call and embedd our solution in there, maybe!!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;regards&lt;/DIV&gt;&lt;DIV&gt;Phil&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 11:27:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204131#M7806</guid>
      <dc:creator>electropw</dc:creator>
      <dc:date>2008-03-20T11:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204132#M7807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello Phil,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The LDD&amp;nbsp;x instruction would represent the compiler output&amp;nbsp;corresponding with&amp;nbsp;the return(x); statement, for a 16-bit return value.&amp;nbsp; So the&amp;nbsp;assembly code&amp;nbsp;is what might be expected.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Passing the current value of a global variable to the function, via the parameter x will simply result in the return of that value, independent of what a subsequent interrupt may do to the contents of the global variable.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If you needed to prevent the occurrence of an interrupt altering a global variable whilst a function manipulates its value, and then to return the newly modified value, the following approach&amp;nbsp;might work -&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;int g_var1;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;int func( int y)&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;{&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; _critical;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; g_var1 += y;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;y = g_var1;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; _critical_return(y);&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;}&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You could not use the statement &lt;FONT face="Courier New"&gt;_critical_return(g_var1);&lt;/FONT&gt; since an interrupt might possibly&amp;nbsp;occur between the PULC and the LDD instructions.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-03-20&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;04:22 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 12:18:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204132#M7807</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-03-20T12:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204133#M7808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Mac,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Exactly what I was trying to say above.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I also know that the IAR compiler is, I imagine also CW to be also, smart enough to optimise out the y=g_var1; statement and just return g_var1. This effectively nulifies what we were trying to do.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Please note that my sample was simply that, a sample. Just shown to simply describe the compiler operation. I know in real life with the HC12 that there is no need to protect int sized variables in such operations since it is a single instruction operation and therefore cannot be corrupted by an interrupt occuring during the access. The ones of concern are the variables &amp;gt; 2 bytes in size.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;regards&lt;/DIV&gt;&lt;DIV&gt;Phil&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 12:38:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204133#M7808</guid>
      <dc:creator>electropw</dc:creator>
      <dc:date>2008-03-20T12:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204134#M7809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello Phil,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It might be sufficient to declare the global variable as -&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;volatile int g_var1;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;to prevent that sort of optimisation by the compiler.&amp;nbsp; I guess all global variables that are referenced within ISRs should normally be declared as volatile.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 13:47:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204134#M7809</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-03-20T13:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Hi,   I'm converting over from using the IAR compiler for...</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204135#M7810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello again Phil,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I adapted the macros for HC08 MCU (which I am more familiar with) and then tested the following function to return the value of a long variable -&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;long g_var1 = 10000L;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;long getlong( volatile long *ptr)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; long temp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; _critical;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; temp = *ptr;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; _critical_return(temp);&lt;BR /&gt;}&lt;BR /&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;long b;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;b = getlong( &amp;amp;g_var1);&lt;BR /&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;There didn't appear to be optimisation by the compiler in the manner that you suggested.&amp;nbsp; I also tried a similar function to return a short value, which is also critical for an 8-bit device, with similar results.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-03-20&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;07:46 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 15:43:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Hi-I-m-converting-over-from-using-the-IAR-compiler-for/m-p/204135#M7810</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-03-20T15:43:44Z</dc:date>
    </item>
  </channel>
</rss>

