<?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>ColdFire/68K Microcontrollers and Processors中的主题 Problems with the value returned from a function - MCF52233</title>
    <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Problems-with-the-value-returned-from-a-function-MCF52233/m-p/158961#M4881</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;I am having problems with a function that should return a pointer if it find free memory (it is calloc1, in the Interniche Lite Stack). The problem is that when it returns a valid memory, it returns a correct result, but when it should return NULL, then it returns something but NULL. I am having problems also with tcp_pkalloc, having exactly the same behaviour.&lt;/P&gt;&lt;P&gt;I have been looking at the ASM code, and realized that when they return an address, they use A0, but when they return the NULL, both functions put a zero in D0,&amp;nbsp;NOT in A0,&amp;nbsp;but the caller function (in both cases) takes A0 as the register where is the result, resulting in malfunction only when result is NULL.&lt;/P&gt;&lt;P&gt;I have got this functions in a pre-compiled&amp;nbsp;library using Standard Parameter Passing, that is the same I am using in my application.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using MCF52233 and&amp;nbsp;CodeWarrior for ColdFire V 6.3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am absolutely lost on this.&amp;nbsp; Any help is welcomed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Rubén&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by RValls on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-12-02&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;12:58 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 Dec 2009 20:56:54 GMT</pubDate>
    <dc:creator>RValls</dc:creator>
    <dc:date>2009-12-02T20:56:54Z</dc:date>
    <item>
      <title>Problems with the value returned from a function - MCF52233</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Problems-with-the-value-returned-from-a-function-MCF52233/m-p/158961#M4881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;I am having problems with a function that should return a pointer if it find free memory (it is calloc1, in the Interniche Lite Stack). The problem is that when it returns a valid memory, it returns a correct result, but when it should return NULL, then it returns something but NULL. I am having problems also with tcp_pkalloc, having exactly the same behaviour.&lt;/P&gt;&lt;P&gt;I have been looking at the ASM code, and realized that when they return an address, they use A0, but when they return the NULL, both functions put a zero in D0,&amp;nbsp;NOT in A0,&amp;nbsp;but the caller function (in both cases) takes A0 as the register where is the result, resulting in malfunction only when result is NULL.&lt;/P&gt;&lt;P&gt;I have got this functions in a pre-compiled&amp;nbsp;library using Standard Parameter Passing, that is the same I am using in my application.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using MCF52233 and&amp;nbsp;CodeWarrior for ColdFire V 6.3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am absolutely lost on this.&amp;nbsp; Any help is welcomed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Rubén&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by RValls on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-12-02&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;12:58 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Dec 2009 20:56:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Problems-with-the-value-returned-from-a-function-MCF52233/m-p/158961#M4881</guid>
      <dc:creator>RValls</dc:creator>
      <dc:date>2009-12-02T20:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with the value returned from a function - MCF52233</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Problems-with-the-value-returned-from-a-function-MCF52233/m-p/158962#M4882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rubén&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check in your header files (particularly in mwerks.h) for the pragma #pragma pointers_in_A0&lt;/P&gt;&lt;P&gt;If this is set it means that addresses are returned in the register A0. Non-addresses will be returned in D0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You need to ensure that your libraries (like the one with malloc() in is compiled with the same setting otherwise things can go wrong).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By removing the pragma all returns are in D0. (but again the library must have been built with the same setting)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.uTasker.com" rel="nofollow" target="_self"&gt;www.uTasker.com&lt;/A&gt;&lt;BR /&gt;- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "&lt;EM&gt;Embedding it better...&lt;/EM&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by mjbcswitzerland on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-12-03&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;12:16 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Dec 2009 07:15:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Problems-with-the-value-returned-from-a-function-MCF52233/m-p/158962#M4882</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2009-12-03T07:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with the value returned from a function - MCF52233</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Problems-with-the-value-returned-from-a-function-MCF52233/m-p/158963#M4883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark! Thanks a lot for your answer, both for the quickly reply and for the solution!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have searched that file, "mwerks.h" but I haven't got it included.&amp;nbsp;then I&amp;nbsp;searched for "pointers_" and I found that the pragma "#pragma pointers_in_D0" was defined in "cw.h".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The file where I have this functions (calloc1 is in "memio.c") hasn't got "cw.h" as an #include, so the pragma doesn't affect it.&lt;/P&gt;&lt;P&gt;I suppose (I have not checked it nor&amp;nbsp;found it in the "ColdFire_Build_Tools_Reference") that by default the compiler&amp;nbsp;may use "#pragma pointers_in_A0", so I am having this behaviour. Otherwhise, my project would work fine...&lt;/P&gt;&lt;P&gt;To solve this, I made a new file "options.h" where I defined "#pragma pointers_in_D0", and included it in all files through the "C/C++ Preprocessor" and "ColdFire Assembler" pannels in the library's project options.&lt;/P&gt;&lt;P&gt;I have done the same in the application's project options, and now it works fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for the solution.&lt;/P&gt;&lt;P&gt;Regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rubén&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Dec 2009 16:49:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/Problems-with-the-value-returned-from-a-function-MCF52233/m-p/158963#M4883</guid>
      <dc:creator>RValls</dc:creator>
      <dc:date>2009-12-03T16:49:47Z</dc:date>
    </item>
  </channel>
</rss>

