EasyManua.ls Logo

Espressif ESP32-S2 - Page 967

Espressif ESP32-S2
1695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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 xRingbufferCreate() and xRing-
bufferSend() to create a ring buffer and then send an item to it.
#include "freertos/ringbuf.h"
static char tx_item[] = "test_item";
...
//Create ring buffer
RingbufHandle_t buf_handle;
buf_handle = xRingbufferCreate(1028, RINGBUF_TYPE_NOSPLIT);
if (buf_handle == NULL) {
printf("Failed to create ring buffer\n");
}
//Send an item
UBaseType_t res = xRingbufferSend(buf_handle, tx_item, sizeof(tx_item), pdMS_
,TO_TICKS(1000));
if (res != pdTRUE) {
printf("Failed to send item\n");
}
The following example demonstrates the usage of xRingbufferSendAcquire() and xRingbufferSend-
Complete() instead of xRingbufferSend() to acquire memory on the ring buffer (of type RING-
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 when
,we copy
dma_item_t item;
UBaseType_t res = xRingbufferSendAcquire(buf_handle,
&item, DMA_ITEM_SIZE(buffer_size), pdMS_TO_TICKS(1000));
if (res != pdTRUE) {
printf("Failed to acquire memory for item\n");
}
item->dma_desc = (lldesc_t) {
.size = buffer_size,
.length = buffer_size,
.eof = 0,
.owner = 1,
.buf = &item->buf,
};
(continues on next page)
Espressif Systems 956
Submit Document Feedback
Release v4.4

Table of Contents