<?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>8-bit MicrocontrollersのトピックRe: HCS08C: Software watchdog and detecting last routine</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205656#M17227</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;For me, the main thing about that version is not that it's using a struct to show all the stack context or that it is using HLI to define the access. It is to separate all the code which could cause that the compiler generates a stack frame which could interfere with the PC retrieval.&lt;BR /&gt;For both the C and Macs version, one of the "setting for a given set of conditions" is all the C code in the same function. And as the original poster already found out, all the other C code in the same function is part of those conditions, I would add the exact compiler version and the options used to compile it too (-or and more locals end up in registers). So the main proposal was to move all the "custom" code into its own function and to let little (?) left for the compiler which could cause the code not to work as expected on a S08.&lt;BR /&gt;About the compiler dependency, to my understanding every version to get the PC is compiler dependent.&lt;BR /&gt;I agree that the OFFSET version easier to port to other architectures, but given the nature of the problem I would protect this function with some #ifdef's not to compile it on architectures/compilers I did not test/adapt the OFFSET for. And for a gcc version of it, I would actually use the gcc things:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Return-Address.html" target="test_blank"&gt;http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Return-Address.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The initial thought why I used the struct was to explicitly show where the offset to the PC comes from.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;BR /&gt;PS2: Ups, the RTI is indeed not necessary, can be dropped or a #pragma NO_RETURN could be added just as bigmac noticed. I did somehow forget that &lt;SPAN&gt;&lt;/SPAN&gt;#pragma NO_EXIT does not drop the return on its own.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Mar 2008 08:01:49 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2008-03-28T08:01:49Z</dc:date>
    <item>
      <title>HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205630#M17201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'm using software watchdog&amp;nbsp;method and internal COP unit.&lt;/DIV&gt;&lt;DIV&gt;I want to detect when the reset was occured (which line of my main routine) without using BDM.&lt;/DIV&gt;&lt;DIV&gt;I'm not sure this is possible for COP but I thing it is possible for software watchdog.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;void main(void){&amp;nbsp; ..&amp;nbsp; ..&amp;nbsp; while(1) // main loop&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; SOFTWARE_WATCHDOG = 0; // clear soft watchdog&amp;nbsp;&amp;nbsp;&amp;nbsp; func1();&amp;nbsp;&amp;nbsp;&amp;nbsp; func2();&amp;nbsp;&amp;nbsp;&amp;nbsp; func3();&amp;nbsp;&amp;nbsp;&amp;nbsp; func4();&amp;nbsp;&amp;nbsp;&amp;nbsp; func5();&amp;nbsp; }}interrupt VectorNumber_Vtpm1ovf void intTPM1OVF(void){&amp;nbsp; TPM1SC_TOF = 0;&amp;nbsp;&amp;nbsp; // software watchdog for 5sec&amp;nbsp; if(++SOFTWARE_WATCHDOG &amp;gt; 200) asm("dcb 0x8D"); // illegal opcode&amp;nbsp; ...}&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Can I save interrupt return address to a register before executing illegal opcode? How can I obtain this address in interrupt routine?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Is there any way to detect similar address&amp;nbsp;that COP reset was occured?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;BP.&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 13:46:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205630#M17201</guid>
      <dc:creator>BasePointer</dc:creator>
      <dc:date>2008-03-24T13:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205631#M17202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello BP,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I assume that you wish to store the previous PC address reached prior to the ISR being entered.&amp;nbsp; This is directly available from the stack.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;word PC_location @0x0100;&amp;nbsp; // Non-initialised global variable&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#pragma NO_ENTRY&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#pragma NO_EXIT&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;#pragma NO_FRAME&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;interrupt VectorNumber_Vtpm1ovf void intTPM1OVF(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; __asm pshh;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; TPM1SC_TOF = 0;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; // software watchdog for 5sec&lt;BR /&gt;&amp;nbsp; if(++SOFTWARE_WATCHDOG &amp;gt; 200) {&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm ldhx 5,sp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Return address on stack&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm sthx PC_location;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm ("dcb 0x8D" ); // Illegal opcode reset&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; }&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; __asm pulh;&lt;BR /&gt;}&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Note that the global variable must &lt;U&gt;not&lt;/U&gt; undergo ANSI initialisation.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This method relies on the TPM module remaining operational.&amp;nbsp; If this were to cease for any reason, the COP timeout would fail.&amp;nbsp; Perhaps you might additionally use the normal COP module to protect against this event, and&amp;nbsp;add a COP reset&amp;nbsp;within the ISR.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by bigmac on &lt;SPAN class="date_text"&gt;2008-03-24&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;08:55 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 16:30:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205631#M17202</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-03-24T16:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205632#M17203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello Mac,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Once the reset has occured, I feel PC_location @0x0100 would be reset to 0x00&amp;nbsp; since its in the RAM.To save Program Counter content &amp;nbsp;before a reset (SW reset- before ilegal opcode), I feel one can write into non-volatile memory rather than in RAM space.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Denn.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 17:43:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205632#M17203</guid>
      <dc:creator>Denn</dc:creator>
      <dc:date>2008-03-24T17:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205633#M17204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi Mac,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;That is exactly what I want to do.&lt;/DIV&gt;&lt;DIV&gt;I will store PC_Counter in NO_INIT area to prevent ansi-c initialization at start-up. This is OK.&lt;/DIV&gt;&lt;DIV&gt;Actually, my timer1 overflow interrupt routine is a little bit more complex than I implemented before.&lt;/DIV&gt;&lt;DIV&gt;If I declare a new local variables in the ISR routine, will your implementation change?&lt;/DIV&gt;&lt;DIV&gt;I didn't understand assembler codes that you used at all. Isn't there a C way?&lt;/DIV&gt;&lt;DIV&gt;I also wonder about your pragma directives NO_ENTRY, NO_EXIT, NO_FRAME. They may be a problem for my routine?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;interrupt VectorNumber_Vtpm1ovf void intTPM1OVF(void){  char tmp_button_menu, tmp_button;    TPM1SC_TOF = 0;    ++counter_25ms;  ++seq_timeout;    if(++SOFTWARE_WATCHDOG &amp;gt; 200) asm("dcb 0x8D"); // illegal opcode  ...  ...  func1();  func5(&amp;amp;ptr, func2());  ...  ...}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;I'm also using COP module as additional to soft method.&amp;nbsp;But not using it like you suggested.&lt;/DIV&gt;&lt;DIV&gt;It seems as if it was more functional than my method. I will think it.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;10x,&lt;/DIV&gt;&lt;DIV&gt;BP.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 18:48:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205633#M17204</guid>
      <dc:creator>BasePointer</dc:creator>
      <dc:date>2008-03-24T18:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205634#M17205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi BP,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;interrupt VectorNumber_Vtpm1ovf void intTPM1OVF(void){  __asm pshh;  TPM1SC_TOF = 0;  // software watchdog for 5sec  if(++SOFTWARE_WATCHDOG &amp;gt; 200) {    __asm ldhx 5,sp;     // Return address on stack    __asm sthx PC_location;    __asm ("dcb 0x8D" ); // Illegal opcode reset  }  __asm pulh;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;Macs ISR is right.&amp;nbsp;Once the ISR is entered Stack Pointer is decremented by&amp;nbsp;5 counts(5 bytes automatically pushed by MCU in the order of PCL,PCH,Index Reg- X,Accumulator and finally Condition Code Register CCR. Refer figure&amp;nbsp;"Interrupt stack frame" in datasheet&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You can see he is pushing Index Reg- H. Its necessary because the CPU register H contents will be lost if not saved after it starts executing the code after returning from ISR.Normally compilers take care of pushing H register .If its not doing then programmer has to do it.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;SP(afetr interrupt)--&amp;gt; SP(&amp;nbsp;before interrupt)+6 after this push H&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Since you wanted the address of the code in main function to be stored&amp;nbsp;before the reset he is taking the contents of PC&amp;nbsp;from the stack.It is located in location SP(&amp;nbsp;before interrupt)-1 location&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm ldhx 5,sp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Return address on stack&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;here he is loading H:X register with the contents of location pointed by [SP+5] which is nothing but&amp;nbsp;&amp;nbsp; PCH : PCL in the stack.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm sthx PC_location;&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;Next he is storing the contents of H:X to the location&lt;EM&gt;&lt;STRONG&gt;PC_location&lt;/STRONG&gt;&lt;/EM&gt;.Now PC_location contains the PC value(16 bit program memory address executed&amp;nbsp;just before the interrupt has come)&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;BasePointer wrote:&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;If I declare a new local variables in the ISR routine, will your implementation change?&lt;/DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;Yes it will change in terms of stack usage. You need to change line&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; __asm ldhx 5,sp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Return address on stack&lt;/EM&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;If you are using 2 local variables then offset in the above line is incremented by 2&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;EM&gt;i.e. __asm ldhx 7,sp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thats all.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I really doubt you can implement these on C because here one needs to touch CPU registers and that could be done only by assembly language.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Denn.&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 20:26:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205634#M17205</guid>
      <dc:creator>Denn</dc:creator>
      <dc:date>2008-03-24T20:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205635#M17206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;You should have no troubles doing this in "C".&lt;BR /&gt;Make the local variable static, so it is just in ram, not on the stack.&lt;BR /&gt;This is not a re-entrant routine so this should not be a problem.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 22:16:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205635#M17206</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2008-03-24T22:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205636#M17207</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello BP,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;With the method that I proposed, this requires that the address be read directly from the contents of the stack.&amp;nbsp; Therefore the exact position of the address&amp;nbsp;on the stack needs to be totally predictable.&amp;nbsp; The purposed of the pragmas is to prevent the compiler from manipulating the stack of its own accord, which would affect the stack position read if it were to do so.&amp;nbsp; I don't know of any alternative to the use of inline assembly.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Any variables referenced by the ISR should be either global or static so that they will not utilize the stack.&amp;nbsp; Even if local variables were to be declared after the address value was read, the presence of the pragmas would mean that the stack pointer would require to&amp;nbsp;be manually adjusted at the conclusion of the ISR.&amp;nbsp; To avoid this complication is is better to use variables that do not&amp;nbsp;use the stack.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I would&amp;nbsp;probably do the timeout test first, when the ISR was first entered, and then continue with the other requirements of the ISR.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 02:05:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205636#M17207</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-03-25T02:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205637#M17208</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello Jim,&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;JimDon wrote:&lt;BR /&gt;You should have no troubles doing this in "C".&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;How will you read the contents of stack (we are interested in Program counter -PC values )in &lt;STRONG&gt;"C"&lt;/STRONG&gt; ?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;DIV&gt;JimDon wrote:&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;Make the local variable static, so it is just in ram, not on the stack.&lt;BR /&gt;This is not a re-entrant routine so this should not be a problem.&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;When one can acheive the objective by using local variables, why try&amp;nbsp; unnessarily put variables in RAM by making it as static.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;All one needs to do is increment the offset by the number of local variables used in the ISR.&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;EM&gt;__asm ldhx &lt;U&gt;offset&lt;/U&gt;,sp; // offset=5+(number of local variables used in ISR.)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;EM&gt;In our case Offset=5+2=7&lt;/EM&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Hello Mac,&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Isn't storing the contents of PC to non-volatile memory location(flash or any other nonvolatile memory) necessary rather than RAM (0x100)before reset ?&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Denn.&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Edit- Bold font size&lt;BR /&gt;&lt;BR /&gt;Message Edited by Denn*** on &lt;SPAN class="date_text"&gt;2008-03-25&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;05:48 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 12:35:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205637#M17208</guid>
      <dc:creator>Denn</dc:creator>
      <dc:date>2008-03-25T12:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205638#M17209</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I would just use Macs routine as it is, with all the #pragmas ahead and add a single function call to a C-only routine after the return address has been assigned in inline assembly.&lt;BR /&gt;Probably counting the locals and adding that as offset works too, but you can never be really sure, as the compiler will eventually not allocate some locals if they are not actually accessed on the stack, and the compiler may also allocate more space for temporaries. So placing the C code into a function of their own avoids all such problems. Using statics instead of locals causes that the memory of those variables is not shared, also I prefer to use stack space even for such special functions (or main, or functions which do not return, or..).&lt;BR /&gt;Anyway, what is best probably also depends on how much else there is to do in C and if you can do that in assembly too.&lt;BR /&gt;If you are storing the found PC in RAM or in flash depends on what you do with it. Storing it in a variable allocated in a NO_INIT segment is good enough to have it available after the next reset. If it has to be&amp;nbsp; available even after unplugging the power, then&amp;nbsp; store it in flash, but I doubt that this is really necessary.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 14:10:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205638#M17209</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-03-25T14:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205639#M17210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello Mac,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Sorry !!! The RAM data is lost only after POR/LVD resets.&amp;nbsp;We are looking for PC values stored(in RAM)&amp;nbsp;after an &amp;nbsp;illegal opcode reset.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Datasheet says "&lt;FONT face="Times-Roman"&gt;At power-on, the contents of RAM are uninitialized. RAM data is unaffected by any reset provided that the supply voltage does not drop below the minimum value for RAM retention."&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Times-Roman"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Times-Roman"&gt;Hello Daniel,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Times-Roman"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Times-Roman"&gt;You are right when you say unused local variables doesnot get stored in stack.They are simply ignored by the compiler.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Times-Roman"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Times-Roman"&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;DIV&gt;CompilerGuru wrote:&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;the compiler may also allocate more space for temporaries.&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;But why do compiler assign more memory in stack&amp;nbsp;in case of local variable ?&amp;nbsp;I think the memory allocated for locals is deteministic.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Best Regards,&lt;/DIV&gt;&lt;DIV&gt;Denn&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 16:01:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205639#M17210</guid>
      <dc:creator>Denn</dc:creator>
      <dc:date>2008-03-25T16:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205640#M17211</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I found the PC return address in stack by debuging it. If I add or remove&amp;nbsp;a local variable to the routine, place of the address is changing. I have to take care that, before changing the routine.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;interrupt VectorNumber_Vtpm1ovf void intTPM1OVF(void){  // timer1 overflow interrupt routine  char val1, val2;    TPM1SC_TOF = 0;    ++counter_25ms;  ++seq_timeout;    if(++SOFTWARE_WATCHDOG &amp;gt; 200)   {    NV.Statistic.LAST_PROGRAM_COUNTER = &lt;STRONG&gt;*&lt;/STRONG&gt;(unsigned int&lt;STRONG&gt;*&lt;/STRONG&gt;)(&lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;val2 + &lt;STRONG&gt;6&lt;/STRONG&gt;);    asm("dcb 0x8D"); // illegal opcode  }...&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;Thank you so much for the helps!&lt;/DIV&gt;&lt;DIV&gt;BP.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 16:06:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205640#M17211</guid>
      <dc:creator>BasePointer</dc:creator>
      <dc:date>2008-03-25T16:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205641#M17212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello BP,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Glad to see that you fixed the problem.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;But make sure that Index register is pushed to the stack at the entry of ISR(similarly popped from stack at exit of ISR) by the compiler.If itsnot doing then you need to do that manually as in Mac's ISR.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I feel the compiler is pushing [H] register by its own. Now the stack is something like this in increasing address order&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Val2&lt;/DIV&gt;&lt;DIV&gt;Val1&lt;/DIV&gt;&lt;DIV&gt;[H]&lt;/DIV&gt;&lt;DIV&gt;[CCR]&lt;/DIV&gt;&lt;DIV&gt;[Accumulator]&lt;/DIV&gt;&lt;DIV&gt;[X]&lt;/DIV&gt;&lt;DIV&gt;PCH&lt;/DIV&gt;&lt;DIV&gt;PCL&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;(&amp;amp;&lt;/STRONG&gt;val2 + &lt;STRONG&gt;6&lt;/STRONG&gt;) =location where PCH is stored.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Then you read two bytes since typecasted to int and hence entire PC value (16 bits)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Denn.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 16:28:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205641#M17212</guid>
      <dc:creator>Denn</dc:creator>
      <dc:date>2008-03-25T16:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205642#M17213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hello BP,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Instead of reading address of 2nd local variable, I would suggest you to read address of 1st local variable and hence the adding/ removing local variables has no effect on your routine.The only necessity is that you shouldn't remove the 1st local (i.e. routine without locals) and it should be used somewhere in the routine.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;(&amp;amp;&lt;/STRONG&gt;val1 + &lt;STRONG&gt;5&lt;/STRONG&gt;) =location where PCH is stored.&amp;nbsp;&amp;nbsp;&amp;nbsp;// here 1st local is used&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Denn.&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by Denn*** on &lt;SPAN class="date_text"&gt;2008-03-25&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;09:35 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 16:34:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205642#M17213</guid>
      <dc:creator>Denn</dc:creator>
      <dc:date>2008-03-25T16:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205643#M17214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Denn,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If I use val2, here is the stack list:&lt;/DIV&gt;&lt;DIV&gt;[val2]&lt;/DIV&gt;&lt;DIV&gt;[val1]&lt;/DIV&gt;&lt;DIV&gt;[H]&lt;/DIV&gt;&lt;DIV&gt;[CCR]&lt;/DIV&gt;&lt;DIV&gt;[Accumulator]&lt;/DIV&gt;&lt;DIV&gt;[X]&lt;/DIV&gt;&lt;DIV&gt;[PCH]&lt;/DIV&gt;&lt;DIV&gt;[PCL]&lt;/DIV&gt;&lt;DIV&gt;--------------------------------------------&lt;/DIV&gt;&lt;DIV&gt;If I use val1 instead of val2 and, (&amp;amp;val1+5), I think the compiler optimizing the code and changes stack list: &lt;IMG alt=":smileyindifferent:" class="emoticon emoticon-smileyindifferent" id="smileyindifferent" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-indifferent.gif" title="Smiley Indifferent" /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;[val1]&lt;/DIV&gt;&lt;DIV&gt;[val2]&lt;/DIV&gt;&lt;DIV&gt;[H]&lt;/DIV&gt;&lt;DIV&gt;[CCR]&lt;/DIV&gt;&lt;DIV&gt;[Accumulator]&lt;/DIV&gt;&lt;DIV&gt;[X]&lt;/DIV&gt;&lt;DIV&gt;[PCH]&lt;/DIV&gt;&lt;DIV&gt;[PCL]&lt;/DIV&gt;&lt;DIV&gt;So, (&amp;amp;val1+6) and (&amp;amp;val2+6) are working, others not.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;10x,&lt;/DIV&gt;&lt;DIV&gt;BP.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 16:55:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205643#M17214</guid>
      <dc:creator>BasePointer</dc:creator>
      <dc:date>2008-03-25T16:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205644#M17215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi BP,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Have changed the order&amp;nbsp;of local's declaration&amp;nbsp; from First case &lt;STRONG&gt;char val1, val2&lt;/STRONG&gt;;&amp;nbsp;&amp;nbsp;to &lt;STRONG&gt;char val2, val1;&lt;/STRONG&gt;&amp;nbsp;the second case.&lt;/DIV&gt;&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Denn.&lt;/P&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 17:01:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205644#M17215</guid>
      <dc:creator>Denn</dc:creator>
      <dc:date>2008-03-25T17:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205645#M17216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;No, of course I&amp;nbsp;have not&amp;nbsp;&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt; But the compiler changed the stack list.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 17:10:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205645#M17216</guid>
      <dc:creator>BasePointer</dc:creator>
      <dc:date>2008-03-25T17:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205646#M17217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Interesting !!!!&lt;IMG alt=":smileyindifferent:" class="emoticon emoticon-smileyindifferent" id="smileyindifferent" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-indifferent.gif" title="Smiley Indifferent" /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 17:16:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205646#M17217</guid>
      <dc:creator>Denn</dc:creator>
      <dc:date>2008-03-25T17:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205647#M17218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi Denn,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The compiler may place first used variable to the top of stack. If I use &amp;amp;val1, it places first. If I use &amp;amp;val2, it places first. If I add more variables, it will be more complex to handle.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;So if there were a way to make it independent from the local variables in the code like you suggested, it would be excellent. But if it is not possible, the code above is also working for me. I placed a note to the code as a reminder that if you have to change the code here in the future, take care for stack list to obtain program counter and check it with BDM.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;BP.&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by BasePointer on &lt;SPAN class="date_text"&gt;2008-03-25&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;12:36 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 17:35:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205647#M17218</guid>
      <dc:creator>BasePointer</dc:creator>
      <dc:date>2008-03-25T17:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205648#M17219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The compiler reorders locals so that often used ones can be more efficiently accessed, for example the top of stack one can be accessed with 0,X offset (after a TSX). Don't count on the order of locals. For this case I would suggest to place the C code into its own function and read the pc from a pure HLI method (as Macs) calling the C function afterwards.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 21:45:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205648#M17219</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-03-25T21:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: HCS08C: Software watchdog and detecting last routine</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205649#M17220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Even used variables may not get allocated on the stack if the compiler only needs them in a register ever. Not very often, but this happens.&lt;BR /&gt;Also for normal C code the compiler does sometimes need some storage to store intermediate values, he usually allocates them by just decreasing the SP, but sometimes the intermediate has to live a bit longer and then he can also use "static spills", the space for those is allocated like the space for locals in the entry code. In the end, if you are only using simple C code snippets, then you probably do not see this often, but it does exist.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2008 21:50:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HCS08C-Software-watchdog-and-detecting-last-routine/m-p/205649#M17220</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-03-25T21:50:44Z</dc:date>
    </item>
  </channel>
</rss>

