<?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>nRF52840 SDK16, S140 - Queue library vs Ring buffer library</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79114/nrf52840-sdk16-s140---queue-library-vs-ring-buffer-library</link><description>Hi everyone, 
 I write a firmware to read the values from a 6-axis IMU and some force sensors. I want to sample with a frequency of 100-200Hz, to store the data in a buffer and then transmit the buffer using notifications every second. Searching the SDK</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 14 Sep 2021 06:31:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79114/nrf52840-sdk16-s140---queue-library-vs-ring-buffer-library" /><item><title>RE: nRF52840 SDK16, S140 - Queue library vs Ring buffer library</title><link>https://devzone.nordicsemi.com/thread/329311?ContentTypeID=1</link><pubDate>Tue, 14 Sep 2021 06:31:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:468aa1bf-239e-4f34-94a5-60ea9098e6f5</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Nick&lt;/p&gt;
&lt;p&gt;You are totally correct, using the sizeof operator was&amp;nbsp;a mistake on my part.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The code without sizeof should work fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry for the confusion ;)&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16, S140 - Queue library vs Ring buffer library</title><link>https://devzone.nordicsemi.com/thread/329149?ContentTypeID=1</link><pubDate>Mon, 13 Sep 2021 07:48:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c477a86-5b0e-4773-b7f5-7f0bebed340b</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Hi ovrebek,&lt;/p&gt;
&lt;p&gt;I tried to follow your implementation but it doesn&amp;#39;t work&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;typedef struct 
{
    int16_t records[16];
} my_sensor_data_t;

NRF_QUEUE_DEF(sizeof(my_sensor_data_t), m_sensor_data_queue, 200, NRF_QUEUE_MODE_OVERFLOW);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I get the following error&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1631519203457v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;May should I do something like this?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;typedef struct
{
  int16_t records[16];
} my_sensor_data_t;

NRF_QUEUE_DEF(my_sensor_data_t, m_sensor_data_queue, 200, NRF_QUEUE_MODE_OVERFLOW);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Because the in the definition of&amp;nbsp;NRF_QUEUE_DEF() you calculate the size of data type&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1631526863473v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Any advice?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16, S140 - Queue library vs Ring buffer library</title><link>https://devzone.nordicsemi.com/thread/327861?ContentTypeID=1</link><pubDate>Thu, 02 Sep 2021 18:01:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2da942b6-4dff-4807-8c81-d2925c4cf766</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thank you for your detailed answer and the tips as well. You were very helpfull!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16, S140 - Queue library vs Ring buffer library</title><link>https://devzone.nordicsemi.com/thread/327843?ContentTypeID=1</link><pubDate>Thu, 02 Sep 2021 14:59:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ee7d777-87c3-4c4f-af1f-238bf9c56050</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The first parameter to NRF_QUEUE_DEF(..) is the size of each record, which in your case should be 32 bytes?&lt;/p&gt;
&lt;p&gt;The third parameter is how many items you want room for in the queue, which you need to scale according to how&amp;nbsp;many packets you need to be able to store before they are read out at the other end of the queue.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you sample at 200Hz and need to store the samples for a second you would need to store 200 items in the queue, but normally you want some overhead as well in order to handle communication slow downs.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A common way to set the size correctly is to define a struct for your sensor data, and refer to this later. Something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;typedef struct 
{
    int16_t records[16];
} my_sensor_data_t;

NRF_QUEUE_DEF(sizeof(my_sensor_data_t), m_sensor_data_queue, 200, NRF_QUEUE_MODE_OVERFLOW);&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Nikosant03"]What is the limitation for memory alocation (buffer size)?[/quote]
&lt;p&gt;The limitation is how much RAM you have accessible to the application. Each queue should occupy an amount of RAM roughly equal to record size * number of items (32 * 200 in the example above), and since this is static memory you should see the impact on RAM consumption as soon as you build the example.&amp;nbsp;&lt;/p&gt;
[quote user="Nikosant03"]The&amp;nbsp;&lt;span&gt;queue library is FIFO based?&lt;/span&gt;[/quote]
&lt;p&gt;Yes. &amp;#39;Queue&amp;#39; and &amp;#39;FIFO&amp;#39; is essentially the same thing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16, S140 - Queue library vs Ring buffer library</title><link>https://devzone.nordicsemi.com/thread/327670?ContentTypeID=1</link><pubDate>Wed, 01 Sep 2021 16:47:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f22a6901-6cb9-4ad2-b6c8-4954336ce2f6</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thank you for your answer ovrebekk!! So in case of queue library I could buffer like this?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_QUEUE_DEF(uint8_t, m_byte_queue, 32, NRF_QUEUE_MODE_OVERFLOW);

int16_t payload[]  = {var1,var2,var3,...,var16};
ret_code_t err_code = byte_queue_push(payload);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;What is the limitation for memory alocation (buffer size)?&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;&lt;span&gt;queue library is FIFO based?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SDK16, S140 - Queue library vs Ring buffer library</title><link>https://devzone.nordicsemi.com/thread/327520?ContentTypeID=1</link><pubDate>Wed, 01 Sep 2021 06:23:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f914cfd6-0b65-4bf4-a62a-78215653f58d</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Nick&lt;/p&gt;
&lt;p&gt;One of the main differences between the two is that the ring buffer library&amp;nbsp;is byte based, while the queue library operates on fixed size objects. In your case I think the latter is more useful, since you will be storing several 32 byte records.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is true that the queue library also allows you to overwrite the old data in the case of buffer overflow.&amp;nbsp;In a sensor application like yours this might be a sensible approach, as the data probably loses its usefulness&amp;nbsp;the older it gets.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the end each library could probably serve you well, but I think the queue library is the best option in your case.&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>