EVE 1.0
Ring buffer
Collaboration diagram for Ring buffer:

Data Structures

struct  rbuf_t
 Structure that holds the state of a ring buffer. More...
 

Functions

void rbuf_init (struct rbuf_t *r, uint8_t *a, uint32_t size)
 Initialize a ring buffer. More...
 
uint32_t rbuf_size (struct rbuf_t *r)
 Get the size of a ring buffer. More...
 
uint32_t rbuf_used (struct rbuf_t *r)
 Get the number of bytes currently used in the ring buffer. More...
 
uint32_t rbuf_contused (struct rbuf_t *r, uint8_t **ptr)
 Get the length of a continuous used part of the buffer and a pointer to its beginning. More...
 
void rbuf_commitread (struct rbuf_t *r, uint32_t l)
 Advance the read pointer of the buffer after direct read. Note that length cannot be larger than the value returned by rbuf_contused() More...
 
uint32_t rbuf_free (struct rbuf_t *r)
 Get the number of free bytes currently in the ring buffer. More...
 
uint32_t rbuf_contfree (struct rbuf_t *r, uint8_t **ptr)
 Get the length of a continuous free part of the buffer and a pointer to its beginning. More...
 
void rbuf_commitwrite (struct rbuf_t *r, uint32_t l)
 Advance the write pointer of the buffer after direct write. Note that length cannot be larger than the value returned by rbuf_contfree() More...
 
bool rbuf_push (struct rbuf_t *r, const uint8_t *a, uint32_t l)
 Put an array of bytes to the ring buffer. More...
 
bool rbuf_pull (struct rbuf_t *r, uint8_t *a, uint32_t l)
 Get an array of bytes from the ring buffer. More...
 

Detailed Description

Function Documentation

void rbuf_init ( struct rbuf_t r,
uint8_t *  a,
uint32_t  size 
)

Initialize a ring buffer.

Parameters
rA pointer to a struct rbuf_t to hold the state of the ring buffer
aA pointer to an array to hold the data in the buffer
sizeThe size of the ring buffer
        This function initiates a ring buffer. The data in the
        buffer is stored in an external array, to which a
        pointer must be supplied.
uint32_t rbuf_size ( struct rbuf_t r)

Get the size of a ring buffer.

Parameters
rA pointer to a struct rbuf_t to hold the state of the ring buffer
Returns
The size of the buffer.
uint32_t rbuf_used ( struct rbuf_t r)

Get the number of bytes currently used in the ring buffer.

Parameters
rA pointer to a struct rbuf_t to hold the state of the ring buffer
Returns
The number of elements in the buffer.
uint32_t rbuf_contused ( struct rbuf_t r,
uint8_t **  ptr 
)

Get the length of a continuous used part of the buffer and a pointer to its beginning.

Parameters
rA pointer to a struct rbuf_t to hold the state of the ring buffer
[out]ptrPointer to the pointer to the beginning of a continuous used part
Returns
The length of a continuous used part of the buffer
void rbuf_commitread ( struct rbuf_t r,
uint32_t  l 
)

Advance the read pointer of the buffer after direct read. Note that length cannot be larger than the value returned by rbuf_contused()

Parameters
rA pointer to a struct rbuf_t to hold the state of the ring buffer
lNumber of bytes read
uint32_t rbuf_free ( struct rbuf_t r)

Get the number of free bytes currently in the ring buffer.

Parameters
rA pointer to a struct rbuf_t to hold the state of the ring buffer
Returns
The number of free bytes in the buffer.
uint32_t rbuf_contfree ( struct rbuf_t r,
uint8_t **  ptr 
)

Get the length of a continuous free part of the buffer and a pointer to its beginning.

Parameters
rA pointer to a struct rbuf_t to hold the state of the ring buffer
[out]ptrPointer to the pointer to the beginning of a continuous free part
Returns
The length of a continuous free part of the buffer
void rbuf_commitwrite ( struct rbuf_t r,
uint32_t  l 
)

Advance the write pointer of the buffer after direct write. Note that length cannot be larger than the value returned by rbuf_contfree()

Parameters
rA pointer to a struct rbuf_t to hold the state of the ring buffer
lNumber of bytes written
bool rbuf_push ( struct rbuf_t r,
const uint8_t *  a,
uint32_t  l 
)

Put an array of bytes to the ring buffer.

Parameters
rA pointer to a struct rbuf_t to hold the state of the ring buffer
aA pointer to an array to copy data from
lNumber of bytes to put
Returns
true on success, false if there is not enough free space in the buffer
bool rbuf_pull ( struct rbuf_t r,
uint8_t *  a,
uint32_t  l 
)

Get an array of bytes from the ring buffer.

Parameters
rA pointer to a struct rbuf_t to hold the state of the ring buffer
aA pointer to an array to copy data to
lNumber of bytes to get
Returns
true on success, false if there is not enough bytes in the buffer