<?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>nRF24LE1, example PRX in nRFgo SDK, why not volatile global array?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/18824/nrf24le1-example-prx-in-nrfgo-sdk-why-not-volatile-global-array</link><description>Hello everybody,
I study transceiver nrf24LE1.
I&amp;#39;m trying to understand example of PRX in nRFgo SDK
(Enhanced_shockburst_examples): 
 /

 / Global variables
 uint8_t payload [3];
 &amp;#160;
 // Radio interrupt
 NRF_ISR () // #define NRF_ISR () void</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 07 Jan 2017 15:10:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/18824/nrf24le1-example-prx-in-nrfgo-sdk-why-not-volatile-global-array" /><item><title>RE: nRF24LE1, example PRX in nRFgo SDK, why not volatile global array?</title><link>https://devzone.nordicsemi.com/thread/72693?ContentTypeID=1</link><pubDate>Sat, 07 Jan 2017 15:10:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce87d822-f419-4a4d-90ab-3408b128e983</guid><dc:creator>Artem Kolesnikov</dc:creator><description>&lt;p&gt;Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF24LE1, example PRX in nRFgo SDK, why not volatile global array?</title><link>https://devzone.nordicsemi.com/thread/72692?ContentTypeID=1</link><pubDate>Sat, 07 Jan 2017 11:46:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2411db16-3185-49bd-a428-446f9450306f</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;What do you mean &amp;#39;address this issue&amp;#39;? If you want to put volatile on it, put volatile on it. It won&amp;#39;t hurt, it may make your code ever so slightly less efficient but apart from that it&amp;#39;s not going to do a lot apart from give you peace of mind that the compiler will always read from the memory and not assume the contents doesn&amp;#39;t change during the course of a function call. Volatile isn&amp;#39;t going to affect whether or not the buffer is optimised out (it&amp;#39;s not) nor whether the compiler assumes the contents don&amp;#39;t change across function calls (it doesn&amp;#39;t assume that).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF24LE1, example PRX in nRFgo SDK, why not volatile global array?</title><link>https://devzone.nordicsemi.com/thread/72689?ContentTypeID=1</link><pubDate>Sat, 07 Jan 2017 10:53:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5ec58a2-1948-47ba-a2e1-7dfd8d27c596</guid><dc:creator>Artem Kolesnikov</dc:creator><description>&lt;p&gt;Thank you very much! I really need to address this issue. Could it be, that appeal to the array is always associated with memory access, so &amp;quot;volatile&amp;quot; does not apply?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF24LE1, example PRX in nRFgo SDK, why not volatile global array?</title><link>https://devzone.nordicsemi.com/thread/72691?ContentTypeID=1</link><pubDate>Sat, 07 Jan 2017 02:37:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1732081-dbdd-42be-88a6-f1cf17f06ccb</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Since it&amp;#39;s used in the interrupt handler the optimiser won&amp;#39;t throw it out however it&amp;#39;s defined, as long as the interrupt routine is compiled in. Volatile, as a keyword, isn&amp;#39;t particularly well-defined and does different things between compilers. Technically if you want to be sure that every read access goes back to the array to re-read the data incase it&amp;#39;s changed you could declare it volatile, in practice, it makes very little difference.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF24LE1, example PRX in nRFgo SDK, why not volatile global array?</title><link>https://devzone.nordicsemi.com/thread/72690?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2017 20:53:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f252c66a-c089-4869-a2b4-7fafdc230332</guid><dc:creator>Artem Kolesnikov</dc:creator><description>&lt;p&gt;Thank you very much for your participation in my question.
I thought that the payload [3] is a global variable that is changed in the interrupt handler, and is available in the main loop. And due to the fact that in the main loop is no reference to this variable, the optimizer will throw it. I thought that all these variables have to be volatile. If I add in the main loop to use (read) payload [3], should I declare it volatile? Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF24LE1, example PRX in nRFgo SDK, why not volatile global array?</title><link>https://devzone.nordicsemi.com/thread/72688?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2017 16:23:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb74599d-6ab0-4ff9-bac3-e7b1b1f73cee</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Artem,&lt;/p&gt;
&lt;p&gt;Could you explain a little bit more why you think volatile is needed ? My understanding is that we are not using the payload anywhere outside of the interrupt handler. hal_nrf_read_rx_payload () simply read the RX buffer and put into the payload array. We have no dependency on the payload value in main loop for example.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>