<?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: &amp;quot;Soft resetting&amp;quot; to initialized state using an interrupt on MC9S12XEP100? in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/quot-Soft-resetting-quot-to-initialized-state-using-an-interrupt/m-p/731585#M14902</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After some trial and error, I was able to achieve what I wanted with Assembly.&lt;/P&gt;&lt;P&gt;I made a function called standbySP_PCstore();, that stores the SP to a fixed RAM address, when it is executed. The PC&amp;nbsp;in the beginning of&amp;nbsp;standbySP_PCstore(); is stored already earlier like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Store PC value for CMD_STANDBY to jump to&lt;BR /&gt; *(unsigned int *__far)(STANDBY_PC_ADDR) = ((unsigned long) ((unsigned long *__far) standbySP_PCstore)) &amp;gt;&amp;gt; 8;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;standbySP_PCstore() is defined as:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;static void standbySP_PCstore(void){ 
 asm {
 MOVB STANDBY_SP_ADDR_GPAGE,GPAGE ; //Select GPAGE for global address
 GSTS STANDBY_SP_ADDR_BYTE ; //Store Stack Pointer
 }
}
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;standbySP_PCstore() is placed just before the for-loop in the main function and when the STANDBY command is called, it will clear the I bit in CCR, set Interrupt Priority Level 0, set SP to what it was inside&amp;nbsp;standbySP_PCstore() and finally jump inside standbySP_PCstore() with the following Assembly subroutine:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt; //Force CPU back to just befor main function's for-loop and forget any other subroutines which were executing
 asm {
 MOVB #0x0F, GPAGE ; //Select GPAGE for global address 
 GLDS STANDBY_SP_ADDR_BYTE ; //Load Stack Pointer from RAM
 LDAA #0x00 ; //Load bitmask for clearing IPL
 TFR A,CCRH ; //Clear IPL in CCRH
 CLI ; //Clear interrupt flag from CCR
 MOVB #0x0F, GPAGE ; //Select GPAGE for global address
 GLDX STANDBY_PC_ADDR_BYTE ; //Load address for JMP instruction from RAM to index register X 
 JMP 0,X ; //Jump to address in index register X
 } 
}
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I hope this might be of help to someone wrestling with a similar problem in the future. &lt;IMG alt="Smiley Happy" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="https://community.nxp.com/i/smilies/16x16_smiley-happy.png" title="Smiley Happy" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Nov 2020 14:03:26 GMT</pubDate>
    <dc:creator>utwig</dc:creator>
    <dc:date>2020-11-02T14:03:26Z</dc:date>
    <item>
      <title>"Soft resetting" to initialized state using an interrupt on MC9S12XEP100?</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/quot-Soft-resetting-quot-to-initialized-state-using-an-interrupt/m-p/731584#M14901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;In my S12X code I have implemented an interrupt service routine that I call STANDBY. The point of STANDBY is to "softly" stop any ongoing operation and return to a state resembling the state after running the startup code.&lt;BR /&gt;Currently, STANDBY disables bunch of PIT timers and initializes&amp;nbsp;most important&amp;nbsp;variables and then returns to the execution of the code. Usually, my program will successfully return to the for-loop inside the main function and the variables are correctly initialized. But sometimes, probably due to bad luck with timing, the ISR returns inside a function that will modify the variables that were just initialized with STANDBY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I am looking for a way to return from my STANDBY ISR to the for-loop inside the main function, without running any of the code that was executing while STANDBY was issued.&lt;BR /&gt;Does anyone have any suggestions or examples how to achieve this? I guess one option would be to somehow clear the call stack and then use the goto command to jump into the main function. But I do not have any idea how to safely modify the call stack...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS. I already have implemented a "REBOOT" command, that causes the MCU to reset by writing an invalid value to the ARMCOP register. But I would like to have also this faster and softer&amp;nbsp;STANDBY command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Timo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: After discussing about this problem with a colleague, we have an idea how this could be achieved by a couple of assembly instructions:&lt;BR /&gt;The plan is to somehow capture the Program Counter (PC) and Stack Pointer (SP) values in the beginning of the for-loop where I want to force the CPU. Ideally this is somehow done in the compiler, or then this will be stored in memory during run-time.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;In the end of the STANDBY ISR the SP will be modified to point to the same value as in the beginning of the main function's for-loop. I am considering using the GLDS instruction for this. Then, the PC will be updated to the desired value with JMP instruction.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess I will have to also call CLI just before JMP, or the future interrupts will stay disabled? Is there anything else that I should do before the JMP instruction? E.g. something with the IPL?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will try the above idea in practice and let you know what happens.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 May 2018 15:53:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/quot-Soft-resetting-quot-to-initialized-state-using-an-interrupt/m-p/731584#M14901</guid>
      <dc:creator>utwig</dc:creator>
      <dc:date>2018-05-07T15:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: "Soft resetting" to initialized state using an interrupt on MC9S12XEP100?</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/quot-Soft-resetting-quot-to-initialized-state-using-an-interrupt/m-p/731585#M14902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After some trial and error, I was able to achieve what I wanted with Assembly.&lt;/P&gt;&lt;P&gt;I made a function called standbySP_PCstore();, that stores the SP to a fixed RAM address, when it is executed. The PC&amp;nbsp;in the beginning of&amp;nbsp;standbySP_PCstore(); is stored already earlier like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Store PC value for CMD_STANDBY to jump to&lt;BR /&gt; *(unsigned int *__far)(STANDBY_PC_ADDR) = ((unsigned long) ((unsigned long *__far) standbySP_PCstore)) &amp;gt;&amp;gt; 8;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;standbySP_PCstore() is defined as:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;static void standbySP_PCstore(void){ 
 asm {
 MOVB STANDBY_SP_ADDR_GPAGE,GPAGE ; //Select GPAGE for global address
 GSTS STANDBY_SP_ADDR_BYTE ; //Store Stack Pointer
 }
}
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;standbySP_PCstore() is placed just before the for-loop in the main function and when the STANDBY command is called, it will clear the I bit in CCR, set Interrupt Priority Level 0, set SP to what it was inside&amp;nbsp;standbySP_PCstore() and finally jump inside standbySP_PCstore() with the following Assembly subroutine:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt; //Force CPU back to just befor main function's for-loop and forget any other subroutines which were executing
 asm {
 MOVB #0x0F, GPAGE ; //Select GPAGE for global address 
 GLDS STANDBY_SP_ADDR_BYTE ; //Load Stack Pointer from RAM
 LDAA #0x00 ; //Load bitmask for clearing IPL
 TFR A,CCRH ; //Clear IPL in CCRH
 CLI ; //Clear interrupt flag from CCR
 MOVB #0x0F, GPAGE ; //Select GPAGE for global address
 GLDX STANDBY_PC_ADDR_BYTE ; //Load address for JMP instruction from RAM to index register X 
 JMP 0,X ; //Jump to address in index register X
 } 
}
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I hope this might be of help to someone wrestling with a similar problem in the future. &lt;IMG alt="Smiley Happy" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="https://community.nxp.com/i/smilies/16x16_smiley-happy.png" title="Smiley Happy" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 14:03:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/quot-Soft-resetting-quot-to-initialized-state-using-an-interrupt/m-p/731585#M14902</guid>
      <dc:creator>utwig</dc:creator>
      <dc:date>2020-11-02T14:03:26Z</dc:date>
    </item>
  </channel>
</rss>

