<?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>CodeWarrior for MCU中的主题 Re: CW doesn't seem to compile Far functions properly</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/CW-doesn-t-seem-to-compile-Far-functions-properly/m-p/148778#M3485</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;- Make sure you do not have an imlicit parameter declaration (header not included or prototype not visible for whatever reason).&lt;/P&gt;&lt;P&gt;-A RTS can also occur for calls internal to the function. Hmm. Given your description, this may really be your issue. The compiler does build subfunctions inside of functions for repeated code patterns and those are called with JSR and end with RTS. For those cases the function call and the call target are inside of the same function only and therefore never cross a page boundary.&lt;/P&gt;&lt;P&gt;Using -onf switches of the optimization (should not be necessary, just to verify that this is the origin of the RTS).&lt;/P&gt;&lt;P&gt;- Note that the final return for a function does not have to be at the end. The "real" RTC maybe somewhere in the middle before the internal subfunctions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 24 Oct 2009 10:42:32 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2009-10-24T10:42:32Z</dc:date>
    <item>
      <title>CW doesn't seem to compile Far functions properly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/CW-doesn-t-seem-to-compile-Far-functions-properly/m-p/148777#M3484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using CW 4.7 (with patch 4.7.1), target: 9S12XDT512&lt;BR /&gt;&lt;BR /&gt;Application is TCP-IP stack implemented as a ROM library installed in processor memory, prior to installing an application program. ROM library is located in a far code segment and banked model is being used to construct the library as a project in its own right. Customised application programs will be built as separate projects that can call functions from the common firmware library.&lt;BR /&gt;&lt;BR /&gt;I have written most functions for a module called UDPIP, based loosely on Freescale AN2304. This module covers Layer 3 of the OSI protocol stack: Ethernet driver below it, a TCP module above it, and an HTTP module above that. The 'middle layer' primarily implements IP, but with UDP and ICMP thrown in.&lt;BR /&gt;&lt;BR /&gt;So far I have written and (mostly) tested and debugged the following functions:&lt;BR /&gt;&lt;BR /&gt;Sending:&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG style=": ; font-family: 'courier new,courier';"&gt;UDP_Write()&lt;/STRONG&gt; : invoked by higher layer when UDP protocol req'd - mainly for DHCP client&lt;BR /&gt;&lt;STRONG style=": ; font-family: 'courier new,courier';"&gt;IP_Write()&lt;/STRONG&gt; : invoked by UDP_Write() and - when I get to it - TCP_Write()&lt;BR /&gt;&lt;BR /&gt;Receiving:&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG style=": ; font-family: 'courier new,courier';"&gt;IP_Receive()&lt;/STRONG&gt; : invoked as a callback from lower layer&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new,courier';"&gt;&lt;STRONG&gt;ICMP_Receive()&lt;/STRONG&gt;&lt;/SPAN&gt; : invoked by IP_Receive() if protocol is ICMP - generates Echo Reply to a Ping&lt;BR /&gt;&lt;STRONG style=": ; font-family: 'courier new,courier';"&gt;UDP_Handler()&lt;/STRONG&gt; : invoked by IP_Receive() if protocol is ICMP&lt;BR /&gt;&amp;nbsp;- others to follow&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="text-decoration: underline;"&gt;Problem&lt;/SPAN&gt;:&lt;BR /&gt;&lt;BR /&gt;The compiler INSISTS on treating UDP_Write() as the subject of a near function call - assembly code shows RTS at the end, whereas all others show RTC. I've tried the following:&lt;BR /&gt;&lt;BR /&gt;- naming the code segment with and without the __FAR qualifier&lt;BR /&gt;- including and not including the __far prefix with the UDP_Write() prototype (and with the function name in the source code)&lt;BR /&gt;- messing about with linker segments and placements&lt;/P&gt;&lt;P&gt;- looking through past 12 months of posts on this board&lt;BR /&gt;- tearing hair out&lt;BR /&gt;- etc&lt;BR /&gt;&lt;BR /&gt;The only difference between UDP_Write() and other functions in this module is that it has a dependency (IP_Write()) in the same module; this situation may change in due course, as more of the module and other modules are written.&lt;BR /&gt;&lt;BR /&gt;UDP_Write() calls IP_Write() using a far call, as you'd expect with the banked model and without pragmas to override. But UDP_Write() in general would be called from another module, and possibly from another page of code memory. It is essential that, in general, this function be called using a far call. But the compiler insists it is a near function, while all the others are allowed to be far functions.&lt;BR /&gt;&lt;BR /&gt;What could be special about a function in a far segment that makes the compiler treat it as a near 'callee', and put an RTS at the end instead of RTC?&lt;BR /&gt;&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by bottom_down_programmer on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-10-23&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;09:38 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Oct 2009 02:36:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/CW-doesn-t-seem-to-compile-Far-functions-properly/m-p/148777#M3484</guid>
      <dc:creator>bottom_down_pro</dc:creator>
      <dc:date>2009-10-24T02:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: CW doesn't seem to compile Far functions properly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/CW-doesn-t-seem-to-compile-Far-functions-properly/m-p/148778#M3485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;- Make sure you do not have an imlicit parameter declaration (header not included or prototype not visible for whatever reason).&lt;/P&gt;&lt;P&gt;-A RTS can also occur for calls internal to the function. Hmm. Given your description, this may really be your issue. The compiler does build subfunctions inside of functions for repeated code patterns and those are called with JSR and end with RTS. For those cases the function call and the call target are inside of the same function only and therefore never cross a page boundary.&lt;/P&gt;&lt;P&gt;Using -onf switches of the optimization (should not be necessary, just to verify that this is the origin of the RTS).&lt;/P&gt;&lt;P&gt;- Note that the final return for a function does not have to be at the end. The "real" RTC maybe somewhere in the middle before the internal subfunctions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Oct 2009 10:42:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/CW-doesn-t-seem-to-compile-Far-functions-properly/m-p/148778#M3485</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2009-10-24T10:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: CW doesn't seem to compile Far functions properly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/CW-doesn-t-seem-to-compile-Far-functions-properly/m-p/148779#M3486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Daniel - you fully deserve the title 'CompilerGuru'!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The last point you made turns out to be the answer - the last few lines of the assembler listing are just a subroutine within a subroutine, the "real" RTC is, indeed, further back.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this project there is also a low-level firmware library containing hardware dependent functions (eg to SPI ports with tricky interfaces to other sections of the board) and I wrote much of that library as assembly language routines. I'm a bit of an 'assembler buff' anyway (though I don't attempt to write Windows applications in assembly language, which I believe some freaks do). I don't normally put subroutines within subroutines, but I'm aware that a compiler will often do that, depending on the optimization rules it is using. It just didn't enter my head that that's what I was looking at in the assembler listing of the C function library.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, many thanks for your advice. It's a relief to know that the compiler isn't up the chute&amp;nbsp; - only me!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Neil&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Oct 2009 02:48:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/CW-doesn-t-seem-to-compile-Far-functions-properly/m-p/148779#M3486</guid>
      <dc:creator>bottom_down_pro</dc:creator>
      <dc:date>2009-10-25T02:48:06Z</dc:date>
    </item>
  </channel>
</rss>

