<?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: ROM Resident Routines, disables Interrupts in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/ROM-Resident-Routines-disables-Interrupts/m-p/162255#M9922</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Felix,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, your observation is correct that the ERARNGE sub-routine does disable interrupts.&amp;nbsp; Your extra code is the best way if the previous interrupt enable state is unknown prior to the call.&amp;nbsp; If interrupts are known to be enabled, you might alternatively use &lt;FONT face="courier new,courier"&gt;__asm cli;&lt;/FONT&gt; following the call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To simplify coding, you might even create some macros within an appropriate header file -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#ifndef critical&lt;BR /&gt;#define critical&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm tpa; __asm psha; __asm sei&lt;BR /&gt;#define critical_restore&amp;nbsp; __asm pula; __asm tap&lt;BR /&gt;#endif&lt;/FONT&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;If you intend writing to flash immediately following the page erase, leave the restoration of the interrupt state until after the write.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 14 Mar 2009 07:53:23 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2009-03-14T07:53:23Z</dc:date>
    <item>
      <title>ROM Resident Routines, disables Interrupts</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/ROM-Resident-Routines-disables-Interrupts/m-p/162254#M9921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am using a AP32, and comunicating to a VDrive (from Vinculum) through the SCI port with Interrupts enabled.&lt;/P&gt;&lt;P&gt;Then I needed to store some variables to flash, and used the ROM Resident Routines.&lt;/P&gt;&lt;P&gt;Once read application note AN28741 and modified the RAM and ROM segments in the proyect.rpm file I had them up and running.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But then, when i wanted to make work both things together, it didn't. Saving and loading data from/into Flash worked fine, but SCI communication didn't. The problem was that the ROM Resident Routines disabled interrupts by setting the Interrupt Mask (I) in the CCR register.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So to avoid interrupts to be disabled i added the code in red to the example code from AN28741:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void FLASHErase(void)&lt;BR /&gt;{&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; asm(TPA);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // CCR to register A&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; asm(PSHA);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Push A onto Stack&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; asm(LDHX FILE_PTR); // Load address of RAM Data Block to H:X&lt;BR /&gt;&amp;nbsp; asm(JSR ERARNGE);&amp;nbsp;&amp;nbsp;&amp;nbsp; // Call ERARNGE ROM Subroutine&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; asm(PULA);&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Pull A from Stack&lt;BR /&gt;&amp;nbsp; asm(TAP);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // A to CCR to restore Interrupt mask as it were.&lt;BR /&gt;&lt;/SPAN&gt;}&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For now it is working fine, but my question is if this is the best way of doing it. Is there a better way? Maybe I just neet to config some reg and i wont need the extra code. But i didn't fine anything in the forum. Any ideas?&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;SPAN&gt;Felix&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Mar 2009 06:40:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/ROM-Resident-Routines-disables-Interrupts/m-p/162254#M9921</guid>
      <dc:creator>nfxs</dc:creator>
      <dc:date>2009-03-14T06:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: ROM Resident Routines, disables Interrupts</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/ROM-Resident-Routines-disables-Interrupts/m-p/162255#M9922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Felix,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, your observation is correct that the ERARNGE sub-routine does disable interrupts.&amp;nbsp; Your extra code is the best way if the previous interrupt enable state is unknown prior to the call.&amp;nbsp; If interrupts are known to be enabled, you might alternatively use &lt;FONT face="courier new,courier"&gt;__asm cli;&lt;/FONT&gt; following the call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To simplify coding, you might even create some macros within an appropriate header file -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#ifndef critical&lt;BR /&gt;#define critical&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm tpa; __asm psha; __asm sei&lt;BR /&gt;#define critical_restore&amp;nbsp; __asm pula; __asm tap&lt;BR /&gt;#endif&lt;/FONT&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;If you intend writing to flash immediately following the page erase, leave the restoration of the interrupt state until after the write.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Mar 2009 07:53:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/ROM-Resident-Routines-disables-Interrupts/m-p/162255#M9922</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-03-14T07:53:23Z</dc:date>
    </item>
  </channel>
</rss>

