<?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 XGATE semaphore question in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/XGATE-semaphore-question/m-p/2195354#M20770</link>
    <description>&lt;P&gt;MC9S12XEP100, CW Special Edition, USBDM, XGATE in RAM, coding in relocatable assembler.&lt;/P&gt;&lt;P&gt;I have a project that was written in absolute assembler which uses a lot of interrupts. It runs just fine now, but I want to incorporate XGATE to handle most, if not all of the interrupts. Why? Probably just to see if I can. To that end, I have been able to convert the project to relocatable assembler, (which wasn't easy for me) but it seems to work.&lt;/P&gt;&lt;P&gt;Anyway, I spend a lot of time studying the reference manuals and AN2685, but I 'm still not quite clear on the basics of XGATE semaphores.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I change an interrupt service routine to be serviced by XGATE instead of the CPU, I have read that semaphores need to be involved, but I m not clear under just what circumstances.&lt;/P&gt;&lt;P&gt;Do they need to be used just when a variable is modified within an ISR serviced by XGATE, and, modified by an ISR service by the CPU?&lt;/P&gt;&lt;P&gt;Or.&lt;/P&gt;&lt;P&gt;Also, when a variable is modified within an ISR serviced by XGATE, but it is only used by the CPU, but not modified?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Robert&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Oct 2025 01:34:00 GMT</pubDate>
    <dc:creator>roberthiebert</dc:creator>
    <dc:date>2025-10-30T01:34:00Z</dc:date>
    <item>
      <title>XGATE semaphore question</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/XGATE-semaphore-question/m-p/2195354#M20770</link>
      <description>&lt;P&gt;MC9S12XEP100, CW Special Edition, USBDM, XGATE in RAM, coding in relocatable assembler.&lt;/P&gt;&lt;P&gt;I have a project that was written in absolute assembler which uses a lot of interrupts. It runs just fine now, but I want to incorporate XGATE to handle most, if not all of the interrupts. Why? Probably just to see if I can. To that end, I have been able to convert the project to relocatable assembler, (which wasn't easy for me) but it seems to work.&lt;/P&gt;&lt;P&gt;Anyway, I spend a lot of time studying the reference manuals and AN2685, but I 'm still not quite clear on the basics of XGATE semaphores.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I change an interrupt service routine to be serviced by XGATE instead of the CPU, I have read that semaphores need to be involved, but I m not clear under just what circumstances.&lt;/P&gt;&lt;P&gt;Do they need to be used just when a variable is modified within an ISR serviced by XGATE, and, modified by an ISR service by the CPU?&lt;/P&gt;&lt;P&gt;Or.&lt;/P&gt;&lt;P&gt;Also, when a variable is modified within an ISR serviced by XGATE, but it is only used by the CPU, but not modified?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Robert&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2025 01:34:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/XGATE-semaphore-question/m-p/2195354#M20770</guid>
      <dc:creator>roberthiebert</dc:creator>
      <dc:date>2025-10-30T01:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: XGATE semaphore question</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/XGATE-semaphore-question/m-p/2195763#M20771</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Semaphores are needed &lt;STRONG&gt;only when both cores (S12X and XGATE) access the same shared resource&lt;/STRONG&gt;, typically a variable in RAM. The are needed to avoid simultaneous R/W from both cores. For example, CPU writes some data in one or two steps and XGATE reads them at the same moment. Data consistency is not guaranteed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Use semaphores when:&lt;/STRONG&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRONG&gt;A variable is modified by both XGATE and S12X ISRs.&lt;/STRONG&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Example: A status flag or counter updated by both cores. Or writing to a port.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRONG&gt;A variable is modified by one core and read by the other&lt;/STRONG&gt;, and the read must be consistent.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Example: A buffer index updated by XGATE and read by S12X in a loop.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;You do &lt;EM&gt;not&lt;/EM&gt; need semaphores when:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;A variable is &lt;STRONG&gt;only modified by XGATE&lt;/STRONG&gt;, and &lt;STRONG&gt;only read by S12X&lt;/STRONG&gt;, and &lt;STRONG&gt;consistency is not critical&lt;/STRONG&gt; (e.g., occasional stale reads are acceptable).&lt;/LI&gt;
&lt;LI&gt;A variable is &lt;STRONG&gt;only accessed by one core&lt;/STRONG&gt; (either read or write).&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note, I found in my old code following. It is probably not important for some mask sets but better to implement to be sure it works everywhere.&lt;/P&gt;
&lt;P&gt;....&amp;nbsp; *.cxgate module&lt;/P&gt;
&lt;P&gt;interrupt void PIT0isr(void)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //--- Protected software region starts&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // AN2685.pdf&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;//-----------------------------------------&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; // use this&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; asm LOOP1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; asm SSEM #0 // try to lock semaphore 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; asm SSEM #0 // try to lock semaphore 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // once more due to internal silicon bug&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; asm BCC LOOP1 // retry if locked&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //-----------------------------------------&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //or this&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //asm SSEM #0 // try to lock semaphore 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //asm SSEM #0 // try to lock semaphore 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // once more due to internal silicon bug&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //asm BCC PIT0isr_RTI // return without flag clearing to enable service of an interrupt with higher priority&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //-----------------------------------------&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; .....&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //-----------------------------------------&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; asm CSEM #0 // release semaphore&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //-----------------------------------------&lt;/P&gt;
&lt;P&gt;asm PIT0isr_RTI:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; //-----------------------------------------&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; PITTF = 0x01; // clear interrupt flag of PIT0isr&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Ladislav&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2025 10:41:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/XGATE-semaphore-question/m-p/2195763#M20771</guid>
      <dc:creator>lama</dc:creator>
      <dc:date>2025-10-30T10:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: XGATE semaphore question</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/XGATE-semaphore-question/m-p/2195950#M20772</link>
      <description>&lt;P&gt;Hi Ladislav,&lt;/P&gt;&lt;P&gt;Thanks for the clarification. That's how I thought it should work, but I wasn't sure.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Robert&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2025 15:44:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/XGATE-semaphore-question/m-p/2195950#M20772</guid>
      <dc:creator>roberthiebert</dc:creator>
      <dc:date>2025-10-30T15:44:21Z</dc:date>
    </item>
  </channel>
</rss>

