<?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: S12X Function pointers to paged flash. in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212668#M8375</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If possible avoid the conversions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The plain global to paged conversion can is done by the compiler when assigning a global (__far) data pointer to a paged data pointer, see the code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that no conversion is done from or to function pointers and in addition function pointers use a different byte ordering so when using data pointers the bytes have to be swapped before used as function pointer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why do you have to convert a global to a __far function pointer?&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
void* __far far_ptr;void* __pptr p_ptr;long long_log_addr;long far_adr = 0x701234;long long_log_addr2;void main(void) {  far_ptr = (void* __far)0x701234;  p_ptr = (void* __pptr)far_ptr;  long_log_addr = (long)p_ptr;  long_log_addr2 = (long) (void* __pptr) (void* __far) far_adr;    for(;;) {}}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&amp;nbsp;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 Sep 2009 10:57:06 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2009-09-02T10:57:06Z</dc:date>
    <item>
      <title>S12X Function pointers to paged flash.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212664#M8371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I'm trying to store a long/far address in a variable, cast and then jump to that specific address. with the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;uint32_t appl_start_address;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;appl_start_address = 0x701234;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;((void(*_far) (void))(appl_start_address))();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in the debugger, it does the FCALL, but the PC seems to only go to 7012, and the PPAGE is set to 34.&lt;/P&gt;&lt;P&gt;Shouldn't the Program at least jump to address 0x347012?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially i would like to jump and run program at address 0x701234. however, so i'm doing something majorly wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Quasio&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2009 15:28:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212664#M8371</guid>
      <dc:creator>quasio</dc:creator>
      <dc:date>2009-08-31T15:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: S12X Function pointers to paged flash.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212665#M8372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;quasio,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd suggest you to use logical addresses in this case since global addresses can be used to access data only (not call subroutines).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Banked function pointer allocation expects page pointer located at third position. So if you change the application start address to &lt;SPAN style="font-family: courier new,courier"&gt;0x9234C0&lt;/SPAN&gt; it should work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="font-family: courier new,courier"&gt;appl_start_address =&amp;nbsp; 0x9234C0; // 0xC0_9234'L = 0x701234'G;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier"&gt;((void(* far) (void))(appl_start_address))();&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stanish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2009 17:48:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212665#M8372</guid>
      <dc:creator>stanish</dc:creator>
      <dc:date>2009-08-31T17:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: S12X Function pointers to paged flash.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212666#M8373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah that worked well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So whats the best way to convert global addresses to logical addresses during runtime?&lt;/P&gt;&lt;P&gt;Is there a macro or a function i can use?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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 quasio on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-09-01&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;02:29 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Sep 2009 08:28:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212666#M8373</guid>
      <dc:creator>quasio</dc:creator>
      <dc:date>2009-09-01T08:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: S12X Function pointers to paged flash.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212667#M8374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT size="2"&gt;You may use this&amp;nbsp;macro&amp;nbsp;to convert from global appl_start_address to PPAGE banked appl_start_address:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;#define GLOBAL2LOGICAL(x) (((x &amp;amp; 0x3FFFul | 0x8000) &amp;lt;&amp;lt; 8) | ((x &amp;gt;&amp;gt; 14) &amp;amp; 0xFF))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;PPAGE&amp;nbsp;= global_address / size_of_ppage_window &amp;amp; 0xFF&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;PPAGE offset = global_address % size_of_ppage_window + start_of_ppage_window(=0x8000)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Sep 2009 16:45:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212667#M8374</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-09-01T16:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: S12X Function pointers to paged flash.</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212668#M8375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If possible avoid the conversions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The plain global to paged conversion can is done by the compiler when assigning a global (__far) data pointer to a paged data pointer, see the code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that no conversion is done from or to function pointers and in addition function pointers use a different byte ordering so when using data pointers the bytes have to be swapped before used as function pointer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why do you have to convert a global to a __far function pointer?&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
void* __far far_ptr;void* __pptr p_ptr;long long_log_addr;long far_adr = 0x701234;long long_log_addr2;void main(void) {  far_ptr = (void* __far)0x701234;  p_ptr = (void* __pptr)far_ptr;  long_log_addr = (long)p_ptr;  long_log_addr2 = (long) (void* __pptr) (void* __far) far_adr;    for(;;) {}}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&amp;nbsp;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Sep 2009 10:57:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/S12X-Function-pointers-to-paged-flash/m-p/212668#M8375</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2009-09-02T10:57:06Z</dc:date>
    </item>
  </channel>
</rss>

