Implementation of a Ringbuffer to store chunks of data.
More...
Implementation of a Ringbuffer to store chunks of data.
|
#define | CONFIG_CHUNK_NUM_MAX (4) |
| The maximum number of chunks that can be stored in a Chunked Ringbuffer.
|
|
|
void | crb_init (chunk_ringbuf_t *rb, void *buffer, size_t len) |
| Initialize a Chunked Ringbuffer.
|
|
bool | crb_end_chunk (chunk_ringbuf_t *rb, bool valid) |
| Close the current chunk.
|
|
static bool | crb_start_chunk (chunk_ringbuf_t *rb) |
| Start a new chunk on the ringbuffer.
|
|
static bool | crb_add_byte (chunk_ringbuf_t *rb, uint8_t b) |
| Insert a byte into the current chunk.
|
|
bool | crb_add_bytes (chunk_ringbuf_t *rb, const void *data, size_t len) |
| Insert a number of bytes into the current chunk.
|
|
bool | crb_add_chunk (chunk_ringbuf_t *rb, const void *data, size_t len) |
| Add a complete chunk to the Ringbuffer.
|
|
bool | crb_get_chunk_size (chunk_ringbuf_t *rb, size_t *len) |
| Get the size of the first valid chunk.
|
|
bool | crb_peek_bytes (chunk_ringbuf_t *rb, void *dst, size_t offset, size_t len) |
| Get a number of bytes from the first valid chunk without consuming it.
|
|
bool | crb_consume_chunk (chunk_ringbuf_t *rb, void *dst, size_t len) |
| Remove a chunk from the valid chunk array.
|
|
bool | crb_chunk_foreach (chunk_ringbuf_t *rb, crb_foreach_callback_t func, void *ctx) |
| Execute a callback for each byte in the first valid chunk The callback function may be called twice if the chunk is non-continuous.
|
|
◆ CONFIG_CHUNK_NUM_MAX
#define CONFIG_CHUNK_NUM_MAX (4) |
The maximum number of chunks that can be stored in a Chunked Ringbuffer.
Definition at line 39 of file chunked_ringbuffer.h.
◆ crb_foreach_callback_t
typedef void(* crb_foreach_callback_t) (void *ctx, uint8_t *bytes, size_t len) |
◆ crb_add_byte()
Insert a byte into the current chunk.
- Note
- This function is expected to be called in ISR context / with interrupts disabled.
- Precondition
- A new chunk has been started with crb_start_chunk
- Parameters
-
[in] | rb | The Ringbuffer to work on |
[in] | b | The byte to write |
- Returns
- true If the byte could be written
-
false If the ringbuffer is full
Definition at line 138 of file chunked_ringbuffer.h.
◆ crb_add_bytes()
Insert a number of bytes into the current chunk.
- Note
- This function is expected to be called in ISR context / with interrupts disabled.
- Precondition
- A new chunk has been started with crb_start_chunk
- Parameters
-
[in] | rb | The Ringbuffer to work on |
[in] | data | The data to write |
[in] | len | Size of data |
- Returns
- true If the bytes could be written
-
false If the ringbuffer is full
◆ crb_add_chunk()
Add a complete chunk to the Ringbuffer.
- Note
- This function is expected to be called in ISR context / with interrupts disabled.
This is a convenience function that combines crb_start_chunk, crb_add_bytes and crb_end_chunk
- Parameters
-
[in] | rb | The Ringbuffer to work on |
[in] | data | The data to write |
[in] | len | Size of data |
- Returns
- true If the chunk could be added to the valid chunk array
-
false There was not enough space and the chunk was discarded
◆ crb_chunk_foreach()
Execute a callback for each byte in the first valid chunk The callback function may be called twice if the chunk is non-continuous.
This function will not consume the chunk.
- Parameters
-
[in] | rb | The Ringbuffer to work on |
[in] | func | The function to call for each byte |
[in] | ctx | Optional function argument |
- Returns
- true If a valid chunk exits on which the function was executed
-
false If no valid chunk exists
◆ crb_consume_chunk()
Remove a chunk from the valid chunk array.
- Parameters
-
[in] | rb | The Ringbuffer to work on |
[out] | dst | Destination where the chunk contents should be copied to. May be NULL, then the chunk is just discarded. |
[in] | len | Max number of bytes to read. If there are bytes left in the chunk beyond that, they will be discarded |
- Returns
- true If a chunk was consumed
-
false If no valid chunk did exist
◆ crb_end_chunk()
Close the current chunk.
- Note
- This function is expected to be called in ISR context / with interrupts disabled.
- Parameters
-
[in] | rb | The Ringbuffer to work on |
[in] | valid | True if the chunk is valid and should be stored False if the current chunk should be discarded |
- Returns
- true If the chunk could be stored in the valid chunk array
-
false If there is no more space in the valid chunk array
◆ crb_get_chunk_size()
Get the size of the first valid chunk.
- Parameters
-
[in] | rb | The Ringbuffer to work on |
[out] | len | Pointer to store the size of the first valid chunk |
- Returns
- true If a valid chunk exists and
size
was written
-
false If no valid chunk exists
◆ crb_init()
Initialize a Chunked Ringbuffer.
- Parameters
-
[in] | rb | The Ringbuffer to work on |
| buffer | The Ringbuffer work area |
| len | Size of the Ringbuffer work area |
◆ crb_peek_bytes()
bool crb_peek_bytes |
( |
chunk_ringbuf_t * |
rb, |
|
|
void * |
dst, |
|
|
size_t |
offset, |
|
|
size_t |
len |
|
) |
| |
Get a number of bytes from the first valid chunk without consuming it.
- Parameters
-
[in] | rb | The Ringbuffer to work on |
[out] | dst | Destination buffer |
[in] | offset | Offset to the start of the chunk |
[in] | len | Number of bytes to read |
- Returns
- true If the data could be read
-
false If no valid chunk exists or the bytes could not be read
◆ crb_start_chunk()
Start a new chunk on the ringbuffer.
If an unfinished chunk already exists, it will be discarded.
- Note
- This function is expected to be called in ISR context / with interrupts disabled.
- Parameters
-
[in] | rb | The Ringbuffer to work on |
- Returns
- true If a new chunk could be started
-
false If the ringbuffer is full
Definition at line 103 of file chunked_ringbuffer.h.