freertos/ringbuf: Added an API xRingbufferCreateNoSplit()

This is a wrapper API for creating a Ring Buffer, which ensures that
the ringbuffer can hold the given number of items, each item being of the
same given length.

Signed-off-by: Piyush Shah <piyush@espressif.com>
This commit is contained in:
Piyush Shah 2017-11-23 15:39:17 +05:30
parent 3c199b0de6
commit 91968ef464
2 changed files with 19 additions and 0 deletions

View file

@ -77,6 +77,19 @@ typedef enum {
*/
RingbufHandle_t xRingbufferCreate(size_t buf_length, ringbuf_type_t type);
/**
* @brief Create a ring buffer of type RINGBUF_TYPE_NOSPLIT for a fixed item_size
*
* This API is similar to xRingbufferCreate(), but it will internally allocate
* additional space for the headers.
*
* @param item_size Size of each item to be put into the ring buffer
* @param num_item Maximum number of items the buffer needs to hold simultaneously
*
* @return A RingbufHandle_t handle to the created ringbuffer, or NULL in case of error.
*/
RingbufHandle_t xRingbufferCreateNoSplit(size_t item_size, size_t num_item);
/**
* @brief Delete a ring buffer
*

View file

@ -541,6 +541,12 @@ err:
return NULL;
}
RingbufHandle_t xRingbufferCreateNoSplit(size_t item_size, size_t num_item)
{
size_t aligned_size = (item_size+3)&~3;
return xRingbufferCreate((aligned_size + sizeof(buf_entry_hdr_t)) * num_item, RINGBUF_TYPE_NOSPLIT);
}
void vRingbufferDelete(RingbufHandle_t ringbuf) {
ringbuf_t *rb=(ringbuf_t *)ringbuf;
if (rb) {