<?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>How do do parallel, concurrent operations?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10378/how-do-do-parallel-concurrent-operations</link><description>I am reading data over the duration of 3 seconds on SPI, but while I&amp;#39;m doing that, I need to send that data over RF using microESB library. 
 I need to make sure the read is not blocking RF send and vice versa. The reading is the most imporant. So I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 23 Nov 2015 12:36:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10378/how-do-do-parallel-concurrent-operations" /><item><title>RE: How do do parallel, concurrent operations?</title><link>https://devzone.nordicsemi.com/thread/38527?ContentTypeID=1</link><pubDate>Mon, 23 Nov 2015 12:36:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45e87831-b6fd-4ee9-9c68-6c29903cc287</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;With a SPI event handler i refer to a event handler that is run when a SPI transfer is completed. E.g. using the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v10.0.0/group__nrf__drv__spi__master.html?cp=4_1_0_6_6_23_1_2"&gt;SPI master deriver&lt;/a&gt; this is (optionally) supplied to the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v10.0.0/group__nrf__drv__spi__master.html?cp=4_1_0_6_6_23_1_2_10#ga6a5a24a4ccf990f95bc94bd99ea48e6f"&gt;&lt;code&gt;nrf_drv_spi_init()&lt;/code&gt;&lt;/a&gt; and the handler is called when a transfer initiated with &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v10.0.0/group__nrf__drv__spi__master.html?cp=4_1_0_6_6_23_1_2_11#gab022e003c9e5f0f946a5ecff0b455405"&gt;&lt;code&gt;nrf_drv_spi_transfer()&lt;/code&gt;&lt;/a&gt; is done.&lt;/p&gt;
&lt;p&gt;If you want something truly parallel, the closes you will get is using an RTOS, but it may be overkill in this case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do do parallel, concurrent operations?</title><link>https://devzone.nordicsemi.com/thread/38526?ContentTypeID=1</link><pubDate>Mon, 23 Nov 2015 12:10:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8038c7b-c4b3-4b5e-a1ed-c9f10d09a220</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;The SPI device actually has it&amp;#39;s own internal ring buffer, but smaller than I am going to send, so I think I will just use it&amp;#39;s interrupt to read the whole buffer in one go, reducing time.&lt;/p&gt;
&lt;p&gt;But what is an SPI event handler? Does it run in parallel? And running another function from my main loop will halt the main loop and possibly hang the &amp;quot;SPI Event Handler&amp;quot; also? Are there some truly parallel event handler / calls I can do here? I would love some function names! :)&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do do parallel, concurrent operations?</title><link>https://devzone.nordicsemi.com/thread/38525?ContentTypeID=1</link><pubDate>Mon, 23 Nov 2015 12:07:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5af40833-baf3-4987-89df-8cdae361ca5d</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;As there is only one core, you can not do more than one thing at the same time. However there are other ways to do multiple things in order to have seemingly concurrent threads.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can use interrupt routines (or event handlers) and use different priorities so that a high priority interrupt will be run even tough a low priority interrupt or main context code is being run.&lt;/li&gt;
&lt;li&gt;You can use flags to signal data between functions running in the interrupt context and main context (or use the &lt;a href="https://devzone.nordicsemi.com/tutorials/23/"&gt;scheduler&lt;/a&gt; or another synchronization mechanism).&lt;/li&gt;
&lt;li&gt;For some applications it may be sensible to use a RTOS (e.g. &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v10.0.0/freertos.html"&gt;FreeRTOS&lt;/a&gt;) which provide you with a simple way to create tasks (&amp;quot;threads&amp;quot;) at different priorities and communicate between tasks using message queues etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the scenario you have described you could do several other things. One possible way of doing this is something like this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;let a SPI event handler write data to a ring buffer.&lt;/li&gt;
&lt;li&gt;set a flag indicating that the buffer has been updated&lt;/li&gt;
&lt;li&gt;from your main loop you can check that flag, and run another function (call it &amp;quot;thread&amp;quot; if you like) responsible for sending data&lt;/li&gt;
&lt;li&gt;from the send-data function, read data from the ring-buffer and write it to the micro_esb library.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do do parallel, concurrent operations?</title><link>https://devzone.nordicsemi.com/thread/38524?ContentTypeID=1</link><pubDate>Fri, 20 Nov 2015 15:21:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b35d4e48-d096-4a3f-9e39-dd9d15aa0922</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;Yeah, well... Is there an example for this? Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do do parallel, concurrent operations?</title><link>https://devzone.nordicsemi.com/thread/38523?ContentTypeID=1</link><pubDate>Fri, 20 Nov 2015 15:20:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eec1b024-63de-489b-8d94-f109847654b2</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Make it interrupt driven?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do do parallel, concurrent operations?</title><link>https://devzone.nordicsemi.com/thread/38522?ContentTypeID=1</link><pubDate>Fri, 20 Nov 2015 14:29:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9962623-c73d-45ea-86d3-dc5ae246c2e6</guid><dc:creator>Emil</dc:creator><description>&lt;p&gt;But how can I create 2 concurrent &amp;quot;threads&amp;quot; where one is reading SPI and the other is sending?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do do parallel, concurrent operations?</title><link>https://devzone.nordicsemi.com/thread/38521?ContentTypeID=1</link><pubDate>Fri, 20 Nov 2015 14:28:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f90f453-03b4-42ea-b749-654b70ae0d1a</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Yes - you need a buffer.&lt;/p&gt;
&lt;p&gt;Probably a Ring buffer ...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>