Chapter 2. API Reference
Note: Each item stored in No-Split or Allow-Split buffers will require an additional 8 bytes for a header. Item
sizes will also be rounded up to a 32-bit aligned size (multiple of 4 bytes), however the true item size is recorded
within the header. The sizes of No-Split and Allow-Split buffers will also be rounded up when created.
Usage
The following example demonstrates the usage of
bufferSend()
to create a ring buffer and then send an item to it.
#include
"freertos/ringbuf.h"
static
char
tx_item[]
...
//Create ring buffer
RingbufHandle_t buf_handle;
buf_handle
=
xRingbufferCreate(1028, RINGBUF_TYPE_NOSPLIT);
if
(buf_handle
==
printf("Failed to create ring
}
//Send an item
UBaseType_t res
TO_TICKS(1000));
→
if
(res
!=
pdTRUE) {
printf("Failed to send
}
The following example demonstrates the usage of
Complete()
instead of
BUF_TYPE_NOSPLIT) and then send an item to it. This adds one more step, but allows getting the address of
the memory to write to, and writing to the memory yourself.
#include
"freertos/ringbuf.h"
#include
"soc/lldesc.h"
typedef struct
{
lldesc_t dma_desc;
uint8_t
buf[1];
} dma_item_t;
#define DMA_ITEM_SIZE(N) (sizeof(lldesc_t)+(((N)+3)&(~3)))
...
//Retrieve space for DMA descriptor and corresponding data buffer
//This has to be done with SendAcquire, or the address may be different
we copy
→
dma_item_t item;
UBaseType_t res
if
(res
!=
pdTRUE) {
printf("Failed to acquire memory for
}
item->dma_desc
=
.size
=
buffer_size,
.length
=
buffer_size,
.eof
=
0,
.owner
=
1,
.buf
=
&item->buf,
};
Espressif Systems
=
"test_item";
NULL) {
buffer\n");
=
xRingbufferSend(buf_handle, tx_item, sizeof(tx_item), pdMS_
item\n");
xRingbufferSendAcquire()
xRingbufferSend()
=
xRingbufferSendAcquire(buf_handle,
&item, DMA_ITEM_SIZE(buffer_size), pdMS_TO_TICKS(1000));
(lldesc_t) {
Submit Document Feedback
xRingbufferCreate()
to acquire memory on the ring buffer (of type RING-
item\n");
956
and
xRing-
and
xRingbufferSend-
when␣
(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