Zephyr API Documentation
2.7.0-rc2
A Scalable Open Source RTOS
|
Macros | |
#define | RING_BUF_ITEM_DECLARE_POW2(name, pow) |
Define and initialize a high performance ring buffer. More... | |
#define | RING_BUF_ITEM_DECLARE_SIZE(name, size32) |
Define and initialize a standard ring buffer. More... | |
#define | RING_BUF_DECLARE(name, size8) |
Define and initialize a ring buffer for byte data. More... | |
Functions | |
static void | ring_buf_init (struct ring_buf *buf, uint32_t size, void *data) |
Initialize a ring buffer. More... | |
int | ring_buf_is_empty (struct ring_buf *buf) |
Determine if a ring buffer is empty. More... | |
static void | ring_buf_reset (struct ring_buf *buf) |
Reset ring buffer state. More... | |
uint32_t | ring_buf_space_get (struct ring_buf *buf) |
Determine free space in a ring buffer. More... | |
static uint32_t | ring_buf_capacity_get (struct ring_buf *buf) |
Return ring buffer capacity. More... | |
uint32_t | ring_buf_size_get (struct ring_buf *buf) |
Determine used space in a ring buffer. More... | |
int | ring_buf_item_put (struct ring_buf *buf, uint16_t type, uint8_t value, uint32_t *data, uint8_t size32) |
Write a data item to a ring buffer. More... | |
int | ring_buf_item_get (struct ring_buf *buf, uint16_t *type, uint8_t *value, uint32_t *data, uint8_t *size32) |
Read a data item from a ring buffer. More... | |
uint32_t | ring_buf_put_claim (struct ring_buf *buf, uint8_t **data, uint32_t size) |
Allocate buffer for writing data to a ring buffer. More... | |
int | ring_buf_put_finish (struct ring_buf *buf, uint32_t size) |
Indicate number of bytes written to allocated buffers. More... | |
uint32_t | ring_buf_put (struct ring_buf *buf, const uint8_t *data, uint32_t size) |
Write (copy) data to a ring buffer. More... | |
uint32_t | ring_buf_get_claim (struct ring_buf *buf, uint8_t **data, uint32_t size) |
Get address of a valid data in a ring buffer. More... | |
int | ring_buf_get_finish (struct ring_buf *buf, uint32_t size) |
Indicate number of bytes read from claimed buffer. More... | |
uint32_t | ring_buf_get (struct ring_buf *buf, uint8_t *data, uint32_t size) |
Read data from a ring buffer. More... | |
uint32_t | ring_buf_peek (struct ring_buf *buf, uint8_t *data, uint32_t size) |
Peek at data from a ring buffer. More... | |
#define RING_BUF_DECLARE | ( | name, | |
size8 | |||
) |
#include <include/sys/ring_buffer.h>
Define and initialize a ring buffer for byte data.
This macro establishes a ring buffer of an arbitrary size.
The ring buffer can be accessed outside the module where it is defined using:
name | Name of the ring buffer. |
size8 | Size of ring buffer (in bytes). |
#define RING_BUF_ITEM_DECLARE_POW2 | ( | name, | |
pow | |||
) |
#include <include/sys/ring_buffer.h>
Define and initialize a high performance ring buffer.
This macro establishes a ring buffer whose size must be a power of 2; that is, the ring buffer contains 2^pow 32-bit words, where pow is the specified ring buffer size exponent. A high performance ring buffer doesn't require the use of modulo arithmetic operations to maintain itself.
The ring buffer can be accessed outside the module where it is defined using:
name | Name of the ring buffer. |
pow | Ring buffer size exponent. |
#define RING_BUF_ITEM_DECLARE_SIZE | ( | name, | |
size32 | |||
) |
#include <include/sys/ring_buffer.h>
Define and initialize a standard ring buffer.
This macro establishes a ring buffer of an arbitrary size. A standard ring buffer uses modulo arithmetic operations to maintain itself.
The ring buffer can be accessed outside the module where it is defined using:
name | Name of the ring buffer. |
size32 | Size of ring buffer (in 32-bit words). |
#include <include/sys/ring_buffer.h>
Return ring buffer capacity.
buf | Address of ring buffer. |
#include <include/sys/ring_buffer.h>
Read data from a ring buffer.
This routine reads data from a ring buffer buf.
buf | Address of ring buffer. |
data | Address of the output buffer. Can be NULL to discard data. |
size | Data size (in bytes). |
Number | of bytes written to the output buffer. |
#include <include/sys/ring_buffer.h>
Get address of a valid data in a ring buffer.
With this routine, memory copying can be reduced since internal ring buffer can be used directly by the user. Once data is processed it can be freed using ring_buf_get_finish.
[in] | buf | Address of ring buffer. |
[out] | data | Pointer to the address. It is set to a location within ring buffer. |
[in] | size | Requested size (in bytes). |
#include <include/sys/ring_buffer.h>
Indicate number of bytes read from claimed buffer.
buf | Address of ring buffer. |
size | Number of bytes that can be freed. |
0 | Successful operation. |
-EINVAL | Provided size exceeds valid bytes in the ring buffer. |
#include <include/sys/ring_buffer.h>
Initialize a ring buffer.
This routine initializes a ring buffer, prior to its first use. It is only used for ring buffers not defined using RING_BUF_DECLARE, RING_BUF_ITEM_DECLARE_POW2 or RING_BUF_ITEM_DECLARE_SIZE.
Setting size to a power of 2 establishes a high performance ring buffer that doesn't require the use of modulo arithmetic operations to maintain itself.
buf | Address of ring buffer. |
size | Ring buffer size (in 32-bit words or bytes). |
data | Ring buffer data area (uint32_t data[size] or uint8_t data[size] for bytes mode). |
int ring_buf_is_empty | ( | struct ring_buf * | buf | ) |
#include <include/sys/ring_buffer.h>
Determine if a ring buffer is empty.
buf | Address of ring buffer. |
int ring_buf_item_get | ( | struct ring_buf * | buf, |
uint16_t * | type, | ||
uint8_t * | value, | ||
uint32_t * | data, | ||
uint8_t * | size32 | ||
) |
#include <include/sys/ring_buffer.h>
Read a data item from a ring buffer.
This routine reads a data item from ring buffer buf. The data item is an array of 32-bit words (up to 1020 bytes in length), coupled with a 16-bit type identifier and an 8-bit integer value.
buf | Address of ring buffer. |
type | Area to store the data item's type identifier. |
value | Area to store the data item's integer value. |
data | Area to store the data item. Can be NULL to discard data. |
size32 | Size of the data item storage area (number of 32-bit chunks). |
0 | Data item was fetched; size32 now contains the number of 32-bit words read into data area data. |
-EAGAIN | Ring buffer is empty. |
-EMSGSIZE | Data area data is too small; size32 now contains the number of 32-bit words needed. |
int ring_buf_item_put | ( | struct ring_buf * | buf, |
uint16_t | type, | ||
uint8_t | value, | ||
uint32_t * | data, | ||
uint8_t | size32 | ||
) |
#include <include/sys/ring_buffer.h>
Write a data item to a ring buffer.
This routine writes a data item to ring buffer buf. The data item is an array of 32-bit words (from zero to 1020 bytes in length), coupled with a 16-bit type identifier and an 8-bit integer value.
buf | Address of ring buffer. |
type | Data item's type identifier (application specific). |
value | Data item's integer value (application specific). |
data | Address of data item. |
size32 | Data item size (number of 32-bit words). |
0 | Data item was written. |
-EMSGSIZE | Ring buffer has insufficient free space. |
#include <include/sys/ring_buffer.h>
Peek at data from a ring buffer.
This routine reads data from a ring buffer buf without removal.
size
.buf | Address of ring buffer. |
data | Address of the output buffer. Cannot be NULL. |
size | Data size (in bytes). |
Number | of bytes written to the output buffer. |
#include <include/sys/ring_buffer.h>
Write (copy) data to a ring buffer.
This routine writes data to a ring buffer buf.
buf | Address of ring buffer. |
data | Address of data. |
size | Data size (in bytes). |
Number | of bytes written. |
#include <include/sys/ring_buffer.h>
Allocate buffer for writing data to a ring buffer.
With this routine, memory copying can be reduced since internal ring buffer can be used directly by the user. Once data is written to allocated area number of bytes written can be confirmed (see ring_buf_put_finish).
[in] | buf | Address of ring buffer. |
[out] | data | Pointer to the address. It is set to a location within ring buffer. |
[in] | size | Requested allocation size (in bytes). |
#include <include/sys/ring_buffer.h>
Indicate number of bytes written to allocated buffers.
buf | Address of ring buffer. |
size | Number of valid bytes in the allocated buffers. |
0 | Successful operation. |
-EINVAL | Provided size exceeds free space in the ring buffer. |
#include <include/sys/ring_buffer.h>
Determine used space in a ring buffer.
buf | Address of ring buffer. |
#include <include/sys/ring_buffer.h>
Determine free space in a ring buffer.
buf | Address of ring buffer. |