Contiki-NG
Loading...
Searching...
No Matches

Data Structures

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

Functions

static void ringbuf_init (struct ringbuf *r, uint8_t *a, uint8_t size_power_of_two)
 Initialize a ring buffer.
 
int ringbuf_put (struct ringbuf *r, uint8_t c)
 Insert a byte into the ring buffer.
 
int ringbuf_get (struct ringbuf *r)
 Get a byte from the ring buffer.
 
int ringbuf_size (struct ringbuf *r)
 Get the size of a ring buffer.
 
int ringbuf_elements (struct ringbuf *r)
 Get the number of elements currently in the ring buffer.
 

Detailed Description

The ring buffer library implements ring (circular) buffer where bytes can be read and written independently. A ring buffer is particularly useful in device drivers where data can come in through interrupts.

Function Documentation

◆ ringbuf_elements()

int ringbuf_elements ( struct ringbuf * r)

Get the number of elements currently in the ring buffer.

Parameters
rA pointer to a struct ringbuf to hold the state of the ring buffer
Returns
The number of elements in the buffer.

Definition at line 110 of file ringbuf.c.

◆ ringbuf_get()

int ringbuf_get ( struct ringbuf * r)

Get a byte from the ring buffer.

Parameters
rA pointer to a struct ringbuf to hold the state of the ring buffer
Returns
The data from the buffer, or -1 if the buffer was empty
        This function removes a byte from the ring buffer. It
        is safe to call this function from an interrupt
        handler.

Definition at line 71 of file ringbuf.c.

References CC_ACCESS_NOW.

◆ ringbuf_init()

static void ringbuf_init ( struct ringbuf * r,
uint8_t * a,
uint8_t size_power_of_two )
inlinestatic

Initialize a ring buffer.

Parameters
rA pointer to a struct ringbuf to hold the state of the ring buffer
aA pointer to an array to hold the data in the buffer
size_power_of_twoThe size of the ring buffer, which must be a power of two
        This function initiates a ring buffer. The data in the
        buffer is stored in an external array, to which a
        pointer must be supplied. The size of the ring buffer
        must be a power of two and cannot be larger than 128
        bytes.

Definition at line 90 of file ringbuf.h.

Referenced by uart0_init(), and uart1_init().

◆ ringbuf_put()

int ringbuf_put ( struct ringbuf * r,
uint8_t c )

Insert a byte into the ring buffer.

Parameters
rA pointer to a struct ringbuf to hold the state of the ring buffer
cThe byte to be written to the buffer
Returns
Non-zero if there data could be written, or zero if the buffer was full.
        This function inserts a byte into the ring buffer. It
        is safe to call this function from an interrupt
        handler.

Definition at line 44 of file ringbuf.c.

References CC_ACCESS_NOW.

Referenced by serial_line_input_byte().

◆ ringbuf_size()

int ringbuf_size ( struct ringbuf * r)

Get the size of a ring buffer.

Parameters
rA pointer to a struct ringbuf to hold the state of the ring buffer
Returns
The size of the buffer.

Definition at line 104 of file ringbuf.c.