This is a generic ring buffer that can be used for data storage e.g.
for communication peripherals like the UART.
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... | |
|
inlinestatic |
Function to get the next offset in a ring buffer.
cur_offset | the current offset in the ring buffer |
size | the size of the ring buffer in bytes |
Referenced by ring_buffer_get_next_read(), and ring_buffer_get_next_write().
|
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.
ring | pointer to a struct of type ring_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().
|
inlinestatic |
Function to get the next read offset in a ring buffer.
ring | pointer to a struct of type ring_buffer |
References get_next(), ring_buffer::read_offset, and ring_buffer::size.
Referenced by ring_buffer_get().
|
inlinestatic |
Function to get the next write offset in a ring buffer.
ring | pointer to a struct of type ring_buffer |
References get_next(), ring_buffer::size, and ring_buffer::write_offset.
Referenced by ring_buffer_is_full(), and ring_buffer_put().
|
static |
Function for initializing a ring buffer.
buffer | pointer to the buffer to use as a ring buffer |
size | the size of the ring buffer |
struct | ring_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().
|
inlinestatic |
Function for checking if the ring buffer is empty.
ring | pointer to a struct of type ring_buffer |
true | if the buffer is empty |
false | if 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().
|
inlinestatic |
Function for checking if the ring buffer is full.
ring | pointer to a struct of type ring_buffer |
true | if the buffer is full |
false | if there is space available in the ring buffer |
References ring_buffer::read_offset, and ring_buffer_get_next_write().
Referenced by ring_buffer_put().
|
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.
ring | pointer to a struct of type ring_buffer |
data | the 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().