<?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 with Ring Buffer Implementation</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/123821/help-with-ring-buffer-implementation</link><description>Hello Nordic Support Team, 
 I am trying to implement a ring buffer of structs. 
 Even though my consumer runs much more frequently than my producer, the buffer becomes full just a few moments after starting my code. 
 I suspect the issue might be related</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 17 Sep 2025 07:10:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/123821/help-with-ring-buffer-implementation" /><item><title>RE: Help with Ring Buffer Implementation</title><link>https://devzone.nordicsemi.com/thread/548966?ContentTypeID=1</link><pubDate>Wed, 17 Sep 2025 07:10:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74b9052b-f936-4cf1-aee8-48af218ca937</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Ah okay. Thanks for letting me know!&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&amp;nbsp;Even though that wasn&amp;#39;t on my list of suggestions I hope you&amp;#39;ll let us know if there is anything else you need help with in the future.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help with Ring Buffer Implementation</title><link>https://devzone.nordicsemi.com/thread/548929?ContentTypeID=1</link><pubDate>Tue, 16 Sep 2025 17:37:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb359d31-498f-4c4e-ae63-8f76042a9544</guid><dc:creator>Luis Santos</dc:creator><description>&lt;p data-start="101" data-end="140"&gt;Sorry for the late response, Elfving.&lt;/p&gt;
&lt;p data-start="142" data-end="270"&gt;I think the issue was related to the length of my struct. Once I decreased the struct length, I stopped having those problems.&lt;/p&gt;
&lt;p data-start="272" data-end="304"&gt;Thanks a lot for your support!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help with Ring Buffer Implementation</title><link>https://devzone.nordicsemi.com/thread/546477?ContentTypeID=1</link><pubDate>Fri, 22 Aug 2025 13:29:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9555fd02-2ec8-4e1e-9faa-265d835cf194</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hi again,&lt;/p&gt;
&lt;p&gt;since you haven&amp;#39;t replied I assume you figured it out?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help with Ring Buffer Implementation</title><link>https://devzone.nordicsemi.com/thread/546229?ContentTypeID=1</link><pubDate>Wed, 20 Aug 2025 15:03:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0ee4160-00c4-457e-8d18-7837590b1320</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello Luis,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll have to get back to you on this later this week, though I see you already have some pointers here. Another thing to make sure is that you are &lt;a href="https://docs.zephyrproject.org/latest/doxygen/html/group__ring__buffer__apis.html#ga6cb71d7c1a36b6e142b251f08ed40599"&gt;feeding the right data item to&amp;nbsp;ring_buf_item_put&lt;/a&gt;(), and that you are not mixing up item and data mode. You can &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/kernel/data_structures/ring_buffers.html#data_item_mode"&gt;see more&lt;/a&gt; here.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Help with Ring Buffer Implementation</title><link>https://devzone.nordicsemi.com/thread/546097?ContentTypeID=1</link><pubDate>Tue, 19 Aug 2025 17:25:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82fa770c-cb48-4e41-bb1f-1ff21922b4d7</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;At first sight it looks like &lt;em&gt;put&lt;/em&gt; and &lt;em&gt;get&lt;/em&gt; applies to a single element queue&amp;nbsp;&lt;em&gt;filterSrvRingBuffer&lt;/em&gt; instead of&amp;nbsp;&lt;em&gt;filterSrvBufferStorage&lt;/em&gt;; that single-element queue would fill up pretty quickly.&amp;nbsp;There is also (perhaps benign) alignment issue between bytes and struct; I would suggest something like:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Align of size of largest struct field, probably 32-bit but use 64-bit:
static uint8_t filterSrvBufferStorage[FILTER_SRV_BUFFER_SIZE_BYTES] __attribute__((section(&amp;quot;.bss&amp;quot;), aligned(8), used));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I would personally order the struct and then compact to reduce storage and get/put overhead, although that can slow access to individual fields within the struct outside of the queue:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#pragma pack(1) //ensure byte by byte struct packing
typedef struct
{
    uint16_t addr;
    uint8_t valid_addr;        /// &amp;lt;&amp;lt;== move all known odd-byte fields to end of struct
    filterSrvSensorType_t analyzing_type;
    emaFilterContext_t ema_context;
    temaFilterContext_t tema_context;
    kalmanFilterContext_t kalman_context;
    filterSrvSensorContext_t ble_sensor_context;
    filterSrvSensorContext_t lora_sensor_context;
} filterSrvContext_t;
#pragma pack()
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The underlying queue uses 32-bit values so best to ensure the struct has overall n*4 bytes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>