Chapter 2. API Reference
QueueSetHandle_t queue_set
//Add ring buffer to queue set
if
(xRingbufferAddToQueueSetRead(buf_handle, queue_set)
printf("Failed to add to queue
}
...
//Block on queue set
xQueueSetMemberHandle member
TICKS(1000));
→
//Check if member is ring buffer
if
(member
!=
NULL
//Member is ring buffer, receive item from ring buffer
size_t
item_size;
char
*item
=
//Handle item
...
}
else
{
...
}
Ring Buffers with Static Allocation
with specific memory requirements (such as a ring buffer being allocated in external RAM). All blocks of memory
used by a ring buffer must be manually allocated beforehand then passed to the
to be initialized as a ring buffer. These blocks include the following:
• The ring buffer's data structure of type
• The ring buffer's storage area of size xBufferSize. Note that xBufferSize must be 32-bit aligned
for No-Split and Allow-Split buffers.
The manner in which these blocks are allocated will depend on the users requirements (e.g. all blocks being statically
declared, or dynamically allocated with specific capabilities such as external RAM).
Note:
When deleting a ring buffer created via xRingbufferCreateStatic(), the function
bufferDelete()
will not free any of the memory blocks. This must be done manually by the user after
bufferDelete()
is called.
The code snippet below demonstrates a ring buffer being allocated entirely in external RAM.
#include
"freertos/ringbuf.h"
#include
"freertos/semphr.h"
#include
"esp_heap_caps.h"
#define BUFFER_SIZE
#define BUFFER_TYPE
...
//Allocate ring buffer data structure and storage area into external RAM
StaticRingbuffer_t *buffer_struct
malloc(sizeof(StaticRingbuffer_t), MALLOC_CAP_SPIRAM);
→
uint8_t
*buffer_storage
MALLOC_CAP_SPIRAM);
→
Espressif Systems
=
xQueueCreateSet(3);
set\n");
=
xQueueSelectFromSet(queue_set, pdMS_TO_
&&
xRingbufferCanRead(buf_handle, member)
(char
*)xRingbufferReceive(buf_handle, &item_size, 0);
The
xRingbufferCreateStatic()
StaticRingbuffer_t
400
//32-bit aligned size
RINGBUF_TYPE_NOSPLIT
=
(StaticRingbuffer_t *)heap_caps_
=
(uint8_t
*)heap_caps_malloc(sizeof(uint8_t)*BUFFER_SIZE,␣
Submit Document Feedback
xRingbufferCreateStatic()
962
(continued from previous page)
!=
pdTRUE) {
==
pdTRUE) {
can be used to create ring buffers
vRing-
vRing-
(continues on next page)
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?
Questions and answers