<?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>CodeWarrior for MCUのトピックDetecting IRQ pin state in C</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179200#M5961</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the MC9S08GT32A in conjunction with CW 6.3.&amp;nbsp; This device has a dedicated IRQ pin that is not shared with any GPIO.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within a C program, I need to detect the current state of the IRQ pin, without generating an interrupt.&amp;nbsp;&amp;nbsp;Using assembly code, I have the BIH and BIL instructions available, which might potentially be used within inline assembly code, But at this moment I am not sure how this would be accomplished.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder if there might be a simpler method, or perhaps an existing library function or macro&amp;nbsp;within CW.&lt;/P&gt;&lt;P&gt;Any suggestions would be welcome.&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;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Jan 2011 12:56:15 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2011-01-27T12:56:15Z</dc:date>
    <item>
      <title>Detecting IRQ pin state in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179200#M5961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the MC9S08GT32A in conjunction with CW 6.3.&amp;nbsp; This device has a dedicated IRQ pin that is not shared with any GPIO.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within a C program, I need to detect the current state of the IRQ pin, without generating an interrupt.&amp;nbsp;&amp;nbsp;Using assembly code, I have the BIH and BIL instructions available, which might potentially be used within inline assembly code, But at this moment I am not sure how this would be accomplished.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder if there might be a simpler method, or perhaps an existing library function or macro&amp;nbsp;within CW.&lt;/P&gt;&lt;P&gt;Any suggestions would be welcome.&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jan 2011 12:56:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179200#M5961</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-01-27T12:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting IRQ pin state in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179201#M5962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps my previous post was a little premature.&amp;nbsp; I was able to evolve the following function to return the current IRQ&amp;nbsp;state.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;byte get_IRQ( void){   __asm {      clra      bil B0      incaB0:   rts   }   return 0;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final &lt;FONT face="courier new,courier"&gt;return 0;&lt;/FONT&gt; &lt;FONT face="arial,helvetica,sans-serif"&gt;does not generate any code because it is never reached.&amp;nbsp; It is there only&amp;nbsp;to avoid a compiler warning about there being no return value (the return value is actually the accumulator value).&amp;nbsp; This method seems quite efficient in that it avoids the need for defining a local variable on the stack.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would still like to hear of other ideas, and any comments.&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>Thu, 29 Oct 2020 09:28:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179201#M5962</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2020-10-29T09:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting IRQ pin state in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179202#M5963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's dedicated intrinsic function for this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* returns the state of the external interrupt pin */&lt;BR /&gt;char __isflag_int(void);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You need to #include &amp;lt;intrinsics_hc08.h&amp;gt;, which can be found&amp;nbsp;here&lt;/P&gt;&lt;P&gt;&amp;lt;CW 6.x root&amp;gt;\lib\hc08c\include\intrinsics_hc08.h&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jan 2011 15:24:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179202#M5963</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-01-27T15:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting IRQ pin state in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179203#M5964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Kef,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the input.&amp;nbsp; I did vaguely recall that I had previously seen functions that returned the state of some of the CCR flags, but did not realize that the IRQ pin was amongst them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For simple functions like these, I usually like to check out the code that they generate, to determine bytes and cycles.&amp;nbsp; In this case, the source code would have been a macro rather than a function (as there is no JSR and RTS generated).&amp;nbsp; The method used is somewhat unorthodox, to say the least.&amp;nbsp; The following would be the equivalent assembly code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    bih  B1    clra    dcb  0x65B1: lda  #01&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How does it work when the branch is not taken?&amp;nbsp; The 0x65 value is an opcode for &lt;FONT face="courier new,courier"&gt;cphx #&lt;/FONT&gt;, so the instruction becomes&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;cphx&amp;nbsp;#0xA601&lt;/FONT&gt;.&amp;nbsp; This does nothing except potentially change some CCR flags.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How is it possible to implement a branch within a macro?&amp;nbsp; Can the equivalent of &lt;FONT face="courier new,courier"&gt;bih&amp;nbsp;*+4;&lt;/FONT&gt; be done with inline code?&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:28:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179203#M5964</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2020-10-29T09:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting IRQ pin state in C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179204#M5965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;CPHX opcode works here as a skip 2 bytes of code. Disassemble shows&amp;nbsp;&amp;nbsp; SKIP2 L8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Clearly you assigned&amp;nbsp;return value&amp;nbsp;to variable. Using it as&lt;/P&gt;&lt;P&gt;if ( __isrflag__int() )&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;won't generate those extra lda skip2 etc. Just BIH/BIL over {} block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is not a macro, it is compiler predefined inline function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jan 2011 05:03:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Detecting-IRQ-pin-state-in-C/m-p/179204#M5965</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-01-28T05:03:04Z</dc:date>
    </item>
  </channel>
</rss>

