<?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>Help me understand the operation of the NRF_RINGBUF module</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/34400/help-me-understand-the-operation-of-the-nrf_ringbuf-module</link><description>Hi! I&amp;#39;m trying to figure out the nrf_ringbuf module, and would really appreciate some advice about its intended use case. The api exposes the following functions: 
 
 This is my current flow of execution: 
 Ask for space with nrf_ringbuffer_alloc( p_ringbuf</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 25 Sep 2018 09:02:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/34400/help-me-understand-the-operation-of-the-nrf_ringbuf-module" /><item><title>RE: Help me understand the operation of the NRF_RINGBUF module</title><link>https://devzone.nordicsemi.com/thread/150195?ContentTypeID=1</link><pubDate>Tue, 25 Sep 2018 09:02:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:558ce541-f6e8-4665-8504-e12eeb55d46e</guid><dc:creator>Igor</dc:creator><description>&lt;p&gt;This works with SDK 15.2:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define MSG_LEN 20
#define BUFFER_SIZE 256 // 2^n !!!

NRF_RINGBUF_DEF(ring_buffer, BUFFER_SIZE); 

void initialize() {
    nrf_ringbuf_init(&amp;amp;ring_buffer);
}

void some_method() {
    uint8_t data_in[MSG_LEN];
    uint8_t data_out[MSG_LEN];
    size_t len_out = MSG_LEN;
    APP_ERROR_CHECK(nrf_ringbuf_cpy_put(&amp;amp;ring_buffer, data_in, ARRAY_SIZE(data_in)));
    // ...
    APP_ERROR_CHECK(nrf_ringbuf_cpy_get(&amp;amp;ring_buffer, data_out, &amp;amp;len_out));
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help me understand the operation of the NRF_RINGBUF module</title><link>https://devzone.nordicsemi.com/thread/132152?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2018 11:12:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:565f366a-9c63-4fb9-a685-9fe4e3dcdcd3</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;The devs says its fixed in 15.1, scheduled mid-late Q2.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help me understand the operation of the NRF_RINGBUF module</title><link>https://devzone.nordicsemi.com/thread/132151?ContentTypeID=1</link><pubDate>Thu, 05 Apr 2018 14:11:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:915551c4-e12a-42c7-8b7a-d192c507dfe7</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Hey Rares,&lt;/p&gt;
&lt;p&gt;No news I&amp;#39;m afraid :/&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I&amp;#39;ll poke the devs...&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Håkon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help me understand the operation of the NRF_RINGBUF module</title><link>https://devzone.nordicsemi.com/thread/132150?ContentTypeID=1</link><pubDate>Tue, 27 Mar 2018 21:28:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8048426f-9d2b-46f3-8cf2-32c016780489</guid><dc:creator>rgosman</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Håkon,&lt;br /&gt;Just wanted to follow up with you on this issue. I see that the change hasn&amp;#39;t been made in SDK15, which launched last week. Is there any word back from the developer?&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Rares&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help me understand the operation of the NRF_RINGBUF module</title><link>https://devzone.nordicsemi.com/thread/132149?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2018 09:48:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac362dc4-d8b3-4dcb-998b-41cfe35d2754</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I&amp;#39;ve reported the issue to the developers, but we might have to wait a while for a comment.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help me understand the operation of the NRF_RINGBUF module</title><link>https://devzone.nordicsemi.com/thread/132148?ContentTypeID=1</link><pubDate>Wed, 21 Feb 2018 20:06:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c98d4df7-e0bf-4794-ae53-dce7bdfa1043</guid><dc:creator>rgosman</dc:creator><description>&lt;p&gt;Hi Hakon,&lt;br /&gt;&lt;br /&gt;Thanks for the advice. I updated to SDK14.2 and kept running into the same issue. I realized it was a problem with the nrf_ringbuf_cpy_get() function. The syntax being used with memcpy() is incorrect. It is provided like so in the SDK:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    if (length &amp;gt; trail)
    {
        memcpy(&amp;amp;p_ringbuf-&amp;gt;p_buffer[masked_rd_idx], p_data, trail);
        length -= trail;
        masked_rd_idx = 0;
        p_data += trail;
    }
    memcpy(p_data, &amp;amp;p_ringbuf-&amp;gt;p_buffer[masked_rd_idx], length);
    p_ringbuf-&amp;gt;p_cb-&amp;gt;rd_idx += *p_length;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Since this is a get() function, it should be filling the user-provided p_data buffer with data from the ring buffer. However, in this section of the code, where it handles the wrap-around behavior, the first memcpy() call is copying blank data from p_data into the ring buffer, and overwriting valid data. Line 212&amp;nbsp;of &amp;quot;nrf_ringbuf.c&amp;quot; should be:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;memcpy&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;p_data&lt;/span&gt;&lt;span&gt;,&lt;/span&gt; &lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;p_ringbuf&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;p_buffer&lt;span&gt;[&lt;/span&gt;masked_rd_idx&lt;span&gt;]&lt;/span&gt;&lt;span&gt;,&lt;/span&gt; trail&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;On the other hand, the nrf_ringbuf_cpy_put() command is fine:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    if (length &amp;gt; trail)
    {
        memcpy(&amp;amp;p_ringbuf-&amp;gt;p_buffer[masked_wr_idx], p_data, trail);
        length -= trail;
        masked_wr_idx = 0;
        p_data += trail;
    }
    memcpy(&amp;amp;p_ringbuf-&amp;gt;p_buffer[masked_wr_idx], p_data, length);
    p_ringbuf-&amp;gt;p_cb-&amp;gt;wr_idx += *p_length;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Notice that both memcpy()&amp;nbsp;calls are being executed with the same order of&amp;nbsp;parameters, since the destination is the&amp;nbsp;ring buffer&amp;nbsp;in the event of a put()&amp;nbsp;command.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Please notify those in charge of this section of the SDK of this error. &lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Rares Gosman&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help me understand the operation of the NRF_RINGBUF module</title><link>https://devzone.nordicsemi.com/thread/132147?ContentTypeID=1</link><pubDate>Wed, 21 Feb 2018 14:33:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45283f7d-9598-4811-8bf1-e207dd8a5412</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Hey Rares,&lt;br /&gt;&lt;span&gt;I believe you are using the API correctly. The library is experimental, and I see there&amp;#39;s some changes between SDK14.0 and 14.2. Try 14.2 and see if that helps.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;The &amp;#39;copy&amp;#39; calls is used when you want the library to read and write directly to another buffer, instead of the one provided by the buffer allocation call.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Håkon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help me understand the operation of the NRF_RINGBUF module</title><link>https://devzone.nordicsemi.com/thread/132146?ContentTypeID=1</link><pubDate>Wed, 21 Feb 2018 01:00:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22965adb-e0ea-4362-b90e-da14843e7ad6</guid><dc:creator>rgosman</dc:creator><description>&lt;p&gt;Hello guys,&lt;br /&gt;&lt;br /&gt;Any updates?&lt;br /&gt;&lt;br /&gt;Cheers and all the best,&lt;br /&gt;Rares&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>