Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Ring buffer

This is a generic ring buffer that can be used for data storage e.g.

for communication peripherals like the UART.

Dependencies

This ring buffer does not depend on other modules.

Data Structures

struct  ring_buffer
 Struct for holding the ring buffer. More...
 

Functions

static uint8_t get_next (uint8_t cur_offset, uint8_t size)
 Function to get the next offset in a ring buffer. More...
 
static uint8_t ring_buffer_get (struct ring_buffer *ring)
 Function for getting one byte from the ring buffer. More...
 
static uint8_t ring_buffer_get_next_read (const struct ring_buffer *ring)
 Function to get the next read offset in a ring buffer. More...
 
static uint8_t ring_buffer_get_next_write (const struct ring_buffer *ring)
 Function to get the next write offset in a ring buffer. More...
 
static struct ring_buffer ring_buffer_init (uint8_t *buffer, uint8_t size)
 Function for initializing a ring buffer. More...
 
static bool ring_buffer_is_empty (const struct ring_buffer *ring)
 Function for checking if the ring buffer is empty. More...
 
static bool ring_buffer_is_full (const struct ring_buffer *ring)
 Function for checking if the ring buffer is full. More...
 
static void ring_buffer_put (struct ring_buffer *ring, uint8_t data)
 Function for putting a data byte in the ring buffer. More...
 

static uint8_t get_next ( uint8_t  cur_offset,
uint8_t  size 
)
inlinestatic

Function to get the next offset in a ring buffer.

Parameters
cur_offsetthe current offset in the ring buffer
sizethe size of the ring buffer in bytes
Returns
next offset or 0 if we are wrapping

Referenced by ring_buffer_get_next_read(), and ring_buffer_get_next_write().

static uint8_t ring_buffer_get ( struct ring_buffer ring)
inlinestatic

Function for getting one byte from the ring buffer.

Call this function to get a byte of data from the ring buffer. Make sure buffer is not empty (using ring_buffer_is_empty) before calling this function.

Parameters
ringpointer to a struct of type ring_buffer
Returns
next data byte in buffer

References Assert, ring_buffer::buffer, data, ring_buffer::read_offset, ring_buffer_get_next_read(), and ring_buffer_is_empty().

Referenced by ISR(), and uart_getchar().

static uint8_t ring_buffer_get_next_read ( const struct ring_buffer ring)
inlinestatic

Function to get the next read offset in a ring buffer.

Parameters
ringpointer to a struct of type ring_buffer
Returns
the next read offset in the ring buffer

References get_next(), ring_buffer::read_offset, and ring_buffer::size.

Referenced by ring_buffer_get().

static uint8_t ring_buffer_get_next_write ( const struct ring_buffer ring)
inlinestatic

Function to get the next write offset in a ring buffer.

Parameters
ringpointer to a struct of type ring_buffer
Returns
the next write offset in the ring buffer

References get_next(), ring_buffer::size, and ring_buffer::write_offset.

Referenced by ring_buffer_is_full(), and ring_buffer_put().

static struct ring_buffer ring_buffer_init ( uint8_t *  buffer,
uint8_t  size 
)
static

Function for initializing a ring buffer.

Parameters
bufferpointer to the buffer to use as a ring buffer
sizethe size of the ring buffer
Return values
structring_buffer a struct containing the ring buffer

References ring_buffer::buffer, ring_buffer::read_offset, ring_buffer::size, and ring_buffer::write_offset.

Referenced by uart_init().

static bool ring_buffer_is_empty ( const struct ring_buffer ring)
inlinestatic

Function for checking if the ring buffer is empty.

Parameters
ringpointer to a struct of type ring_buffer
Return values
trueif the buffer is empty
falseif there is still data in the buffer

References ring_buffer::read_offset, and ring_buffer::write_offset.

Referenced by ISR(), ring_buffer_get(), uart_char_waiting(), and uart_putchar().

static bool ring_buffer_is_full ( const struct ring_buffer ring)
inlinestatic

Function for checking if the ring buffer is full.

Parameters
ringpointer to a struct of type ring_buffer
Return values
trueif the buffer is full
falseif there is space available in the ring buffer

References ring_buffer::read_offset, and ring_buffer_get_next_write().

Referenced by ring_buffer_put().

static void ring_buffer_put ( struct ring_buffer ring,
uint8_t  data 
)
inlinestatic

Function for putting a data byte in the ring buffer.

Call this function to put a byte of data in the ring buffer. Make sure buffer is not full (using ring_buffer_is_full) before calling this function.

Parameters
ringpointer to a struct of type ring_buffer
datathe byte to put to the buffer

References Assert, ring_buffer::buffer, data, ring_buffer_get_next_write(), ring_buffer_is_full(), and ring_buffer::write_offset.

Referenced by ISR(), and uart_putchar().