Chapter 2. API Reference
...
//Receive data from byte buffer
size_t item_size;
char *item = (char *)xRingbufferReceiveUpTo(buf_handle, &item_size, pdMS_TO_
,→TICKS(1000), sizeof(tx_item));
//Check received data
if (item != NULL) {
//Print item
for (int i = 0; i < item_size; i++) {
printf("%c", item[i]);
}
printf("\n");
//Return Item
vRingbufferReturnItem(buf_handle, (void *)item);
} else {
//Failed to receive item
printf("Failed to receive item\n");
}
For ISR safe versions of the functions used above, call xRingbufferSendFromISR(), xRing-
bufferReceiveFromISR(), xRingbufferReceiveSplitFromISR(), xRingbufferReceive-
UpToFromISR(), and vRingbufferReturnItemFromISR()
Note: Two calls to RingbufferReceive[UpTo][FromISR]() are required if the bytes wraps around the end of the
ring buffer.
Sending to Ring Buffer The following diagrams illustrate the differences between No-Split and Allow-Split buffers
as compared to byte buffers with regard to sending items/data. The diagrams assume that three items of sizes 18, 3,
and 27 bytes are sent respectively to a buffer of 128 bytes.
Fig. 30: Sending items to No-Split or Allow-Split ring buffers
For No-Split and Allow-Split buffers, a header of 8 bytes precedes every data item. Furthermore, the space occu-
pied by each item is rounded up to the nearest 32-bit aligned size in order to maintain overall 32-bit alignment.
However, the true size of the item is recorded inside the header which will be returned when the item is retrieved.
Referring to the diagram above, the 18, 3, and 27 byte items are rounded up to 20, 4, and 28 bytes respectively.
An 8 byte header is then added in front of each item.
Byte buffers treat data as a sequence of bytes and does not incur any overhead (no headers). As a result, all data sent
to a byte buffer is merged into a single item.
Referring to the diagram above, the 18, 3, and 27 byte items are sequentially written to the byte buffer and merged
into a single item of 48 bytes.
Using SendAcquire and SendComplete Items in No-Split buffers are acquired (by SendAcquire) in strict
FIFO order and must be sent to the buffer by SendComplete for the data to be accessible by the consumer.
Espressif Systems 958
Submit Document Feedback
Release v4.4