<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Inverted Radio Notification</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/16413/inverted-radio-notification</link><description>I have observed that the Radio Notification from ble_radio_notification.c becomes inverted sometimes. I saw this post about the same problem: 
 devzone.nordicsemi.com/.../ 
 In that post the inverted value was caused by a long-running high-prio interrupt</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 16 Sep 2016 13:22:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/16413/inverted-radio-notification" /><item><title>RE: Inverted Radio Notification</title><link>https://devzone.nordicsemi.com/thread/62829?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2016 13:22:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21db86bc-e065-44c7-94e9-79f515d5d6a9</guid><dc:creator>Anders Westrup</dc:creator><description>&lt;p&gt;Thanks, I will try your suggested solution!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inverted Radio Notification</title><link>https://devzone.nordicsemi.com/thread/62828?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2016 12:52:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73010c6b-108a-4919-8f01-810c02611d26</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;You should never use priority 0 in your code as this is reserved for the SoftDevice. I just updated the answer with a possible solution to not disable the radio notification interrupt when entering critical section. Also edited the answer to be more correct (can have one pending interrupt while in critical section).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inverted Radio Notification</title><link>https://devzone.nordicsemi.com/thread/62827?ContentTypeID=1</link><pubDate>Thu, 15 Sep 2016 13:50:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fbcfb39-5193-45bb-9afc-63086b473f0b</guid><dc:creator>Anders Westrup</dc:creator><description>&lt;p&gt;Thanks for the info. I thought that CRITICAL_REGION_ENTER only disabled APP_IRQ_PRIORITY_LOW. Is there a way to only disable APP_IRQ_PRIORITY_LOW? Or is it safe to set ble_radio_notification to use IRQ priority 0 - or is that also disabled by CRITICAL_REGION_ENTER? (I think I tried to use priority 0, but still got inverted values, but I can try that again)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inverted Radio Notification</title><link>https://devzone.nordicsemi.com/thread/62826?ContentTypeID=1</link><pubDate>Thu, 15 Sep 2016 13:14:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e806827-69fe-42c6-bd33-7d54a3c6e268</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;CRITICAL_REGION_ENTER will disable application interrupts including the radio notification interrupt, so this is probably the problem. You can still have one pending interrupt. If you are in a critical region and two (or a multiple of two) radio notification interrupts triggers, then the radio notification will be inverted.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 2016.09.16:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can make your own critical region enter that only disables low priority interrupts. Below is code that will do this on 51. The SWI1 interrupt is added to the SD interrupts. All other interrupts than SD interrupts and SWI1 interrupts will be disabled when calling sd_nvic_critical_region_enter_app_low. Add more interrupts to the __NRF_NVIC_APP_HIGH_IRQS_0 group if they are not to be disabled. Note that this code is not thoroughly tested so there may be issues (for example when mixing the original sd_nvic_critical_region_enter and this).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**@brief Interrupts used by app_high. */
#define __NRF_NVIC_APP_HIGH_IRQS_0 ((uint32_t)( \
    (1U &amp;lt;&amp;lt; (uint32_t)SWI1_IRQn) \
))

/**@brief Interrupts available for app_low. */
#define __NRF_NVIC_APP_LOW_IRQS_0 ( ~(__NRF_NVIC_SD_IRQS_0 | __NRF_NVIC_APP_HIGH_IRQS_0) )

static inline uint32_t sd_nvic_critical_region_enter_app_low(uint8_t * p_is_nested_critical_region)
{
  int was_masked = __sd_nvic_irq_disable();
  if (!nrf_nvic_state.__cr_flag)
  {
    nrf_nvic_state.__cr_flag = 1;
    nrf_nvic_state.__irq_masks[0] = ( NVIC-&amp;gt;ICER[0] &amp;amp; __NRF_NVIC_APP_IRQS_0 );
    NVIC-&amp;gt;ICER[0] = __NRF_NVIC_APP_LOW_IRQS_0;
    *p_is_nested_critical_region = 0;
  }
  else
  {
    *p_is_nested_critical_region = 1;
  }
  if (!was_masked)
  {
    __sd_nvic_irq_enable();
  }
  return NRF_SUCCESS;
}

static inline uint32_t sd_nvic_critical_region_exit_app_low(uint8_t is_nested_critical_region)
{
  if (nrf_nvic_state.__cr_flag &amp;amp;&amp;amp; (is_nested_critical_region == 0))
  {
    int was_masked = __sd_nvic_irq_disable();
    NVIC-&amp;gt;ISER[0] = nrf_nvic_state.__irq_masks[0];
    nrf_nvic_state.__cr_flag = 0;
    if (!was_masked)
    {
      __sd_nvic_irq_enable();
    }
  }

  return NRF_SUCCESS;
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>