<?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>Migration to SD functions</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3700/migration-to-sd-functions</link><description>I have to update my non soft device source code to SD because now I will use Radio. 
 My question is if it is necessary to rewrite all functions which are in SD API. Like: 
 NVIC_SetPriority(ADC_IRQn, APP_IRQ_PRIORITY_LOW);
NVIC_ClearPendingIRQ(ADC_IRQn</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 04 Sep 2014 06:35:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3700/migration-to-sd-functions" /><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13428?ContentTypeID=1</link><pubDate>Thu, 04 Sep 2014 06:35:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:80f72950-376b-4dec-822a-f96fdc085dde</guid><dc:creator>Ck</dc:creator><description>&lt;p&gt;OK I was not sure about behaviour when IRQ will occure in this time sequence: while(flag_ms == 0) , &lt;em&gt;IRQ Handler process&lt;/em&gt; , sd_app_evt_wait(). Meaning when IRQ occurs after flag was checked and before sd_app_evt_wait() is called again, not when it was already called.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13427?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2014 15:32:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbecb89f-6e5f-4e50-9751-c2cb901650d4</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;You don&amp;#39;t need __SEV() with sd_app_evt_wait(), read its &lt;a href="https://devzone.nordicsemi.com/documentation/nrf51/6.0.0/s110/html/a01004.html#ga11d88d38ac99fb72cde74c9385d36433"&gt;description&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If an application interrupt has happened since the last time sd_app_evt_wait was called this function will return immediately and not go to sleep. This is to avoid race conditions that can occur when a flag is updated in the interrupt handler and processed in the main loop.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;BTW sd_app_evt_wait() automatically go to sleep mode until event will occure?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Yes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13426?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2014 14:20:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8c24dfe-097d-4f0e-9935-cc604ee005c7</guid><dc:creator>Ck</dc:creator><description>&lt;p&gt;Sample code for that:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void RTC1_IRQHandler(void)	/*lint !e765 !e714 */
{  
	/* Every 1ms */
	if (NRF_RTC1-&amp;gt;EVENTS_COMPARE[0] != 0)
  {
		NRF_RTC1-&amp;gt;EVENTS_COMPARE[0] = 0;
		NRF_RTC1-&amp;gt;TASKS_CLEAR = 1;  // Clear Counter		    
				    
    flag_ms = 1;
    /* to avoid race condition */
		__SEV(); /*lint !e718 !e746 */  // it&amp;#39;s in assembler
  }
}


volatile u8 flag_ms=0;

for(;;){
  while(flag_ms == 0) V_hw_WFE(); 
  flag_ms=0;
}



void V_hw_WFE(void)
{
	#ifdef NO_SD
		__WFE();
	#else     
		(void)sd_app_evt_wait();	
	#endif
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;BTW sd_app_evt_wait() automatically go to sleep mode until event will occure?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13425?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2014 13:59:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9704b7d2-ecd0-43fe-954d-c65923646fd4</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;Don&amp;#39;t quite understood the problem, can you give an example?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13424?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2014 13:40:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86cc07d4-2f0e-45eb-999e-164e55bab71c</guid><dc:creator>Ck</dc:creator><description>&lt;p&gt;Great. Now I&amp;#39;m not sure only with __SEV(); Can I use this instruction withih SD enabled? I&amp;#39;m using this in IRQ handler after event_flag is set to avoid race condition.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13423?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2014 13:26:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7570f7e5-1787-44e0-993b-03aee0429bce</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;Yes, for example, you want to send some data through UART and you send first byte by writing&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_UART0-&amp;gt;TXD = data[0]; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then go to low-power mode with sd_app_evt_wait() then you will return from sd_app_evt_wait() when UART will send data and generate TXDRDY event so you can handle it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Enter main loop.
for (;;)
{
    if (NRF_UART0-&amp;gt;EVENTS_TXDRDY == 1)
    {
        NRF_UART0-&amp;gt;EVENTS_TXDRDY = 0;
        NRF_UART0-&amp;gt;TXD = data[next_byte]; 
        ...
    }
    sd_app_evt_wait();
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13422?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2014 13:05:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04540c9f-3217-4fa3-909e-65b3018d041d</guid><dc:creator>Ck</dc:creator><description>&lt;p&gt;I search for &lt;em&gt;enum NRF_SOC_EVTS&lt;/em&gt; and that means that by &lt;code&gt;sd_app_evt_wait()&lt;/code&gt; system go sleep and wake up at &lt;strong&gt;ANY&lt;/strong&gt; generated event or interrupt, but &lt;code&gt;sd_evt_get(p_evt_id)&lt;/code&gt; can get only those events in enum NRF_SOC_EVTS, right? So for non SD events I still can use own flags set in appropriate IRQ handler to know that particular event has occured.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13431?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2014 11:16:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34ba2718-904f-44b3-b7db-57d498351ce4</guid><dc:creator>Ck</dc:creator><description>&lt;p&gt;Great, that document explains that very clear.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13432?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2014 08:09:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bbde302d-eb6e-4a40-97f0-65d5df89815f</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;The comment is only about SD_EVT_IRQn.&lt;/p&gt;
&lt;p&gt;You can read about it in nRF51 SDK_v6.0.0.43681\Nordic\Documentation\Introduction_to_the_S110_SoftDevice_v1.0.pdf &amp;quot;3 Handling events&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13430?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2014 07:40:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7cf88d1c-e208-49b8-ac88-08916a850711</guid><dc:creator>Ck</dc:creator><description>&lt;p&gt;Thanks for reply. &lt;br /&gt;
Now I&amp;#39;m confused with another thing. From SD examples i see this SD setup:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, 
                                             softdevice_assert_callback);
    APP_ERROR_CHECK(err_code);

    // Configure application-specific interrupts. Set application IRQ to lowest priority and enable 
    // application IRQ (triggered from ANT protocol stack).
    err_code = sd_nvic_SetPriority(SD_EVT_IRQn, NRF_APP_PRIORITY_LOW); 
    APP_ERROR_CHECK(err_code);
    err_code = sd_nvic_EnableIRQ(SD_EVT_IRQn);      
    APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What is SD_EVT_IRQn? &lt;br /&gt;
It&amp;#39;s not regular peripheral IRQ, I suppose it&amp;#39;s some kind of callback used by SD stack? But from comment it seems like it should set priority of my IRQ in app globally to lowest priority, so I don&amp;#39;t need to set individually priority by sd_nvic_SetPriority() ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13429?ContentTypeID=1</link><pubDate>Tue, 02 Sep 2014 23:07:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ba8b8dc-d4a1-484f-a34d-6b1d67b84f2e</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;If you are absolutely using only the interrupts, resources and priority levels (important) that you are allowed to use then in reality you can get away with using the NVIC_* calls, it ends up being the same thing. The sd_ calls just check the parameters and hardfault you if you, even accidentally, do something incorrect.&lt;/p&gt;
&lt;p&gt;I have mine #defined so I can switch between the two of them after going through dev testing if I want, it&amp;#39;s a bit quicker calling the NVIC ones directly as you don&amp;#39;t have to go through a SVC call. By the time I get to that point I&amp;#39;m pretty sure I&amp;#39;m doing the right thing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13421?ContentTypeID=1</link><pubDate>Tue, 02 Sep 2014 18:48:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f387aa9-ffb6-4e15-b070-fc778f64b54f</guid><dc:creator>Nikita</dc:creator><description>&lt;blockquote&gt;
&lt;p&gt;but I&amp;#39;m using IRQ handlers for non restrictred or blocked peripherals (I hope at least this is OK)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Yes, it&amp;#39;s ok, you only need to use sd_nvic_* instead of NVIC_*.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;BTW sd_app_evt_wait() is waiting for event or irq, what about if I want strictly wait for irq as it is done by __WFI()?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;There is no way to do it, softdevice has only this one function for both irq and events together. Softdevice handles both irq and events and after softdevice handles them first then softdevice will send software interrupt to the application.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13420?ContentTypeID=1</link><pubDate>Tue, 02 Sep 2014 18:03:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:061a31c9-d00b-4c16-afb9-8fb17120b7b6</guid><dc:creator>Ck</dc:creator><description>&lt;p&gt;I&amp;#39;m not using any peripheral used by SD, but I&amp;#39;m using IRQ handlers for non restrictred or blocked peripherals (I hope at least this is OK), various power modes and HF clock start/stop (so here I have to use alternate SD funcs). BTW sd_app_evt_wait() is waiting for event or irq, what about if I want strictly wait for irq as it is done by __WFI()?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Migration to SD functions</title><link>https://devzone.nordicsemi.com/thread/13419?ContentTypeID=1</link><pubDate>Tue, 02 Sep 2014 16:17:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:951063d0-fa8f-4dbf-ab78-95c2ba9559f4</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;You can see in S110_SoftDevice_Specification_v1 3.pdf there is a list of peripherals used by softdevice in &amp;quot;Table 23 Peripheral protection and usage by SoftDevice&amp;quot;.&lt;/p&gt;
&lt;p&gt;Any direct access to the protected resources while softdevice is enabled will generate hard fault by softdevice, so you must use softdevice calls to access to this resources.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>