APM:Libraries
|
Simple circular buffer. More...
#include "hal_types.h"
Go to the source code of this file.
Classes | |
struct | ring_buffer |
Typedefs | |
typedef struct ring_buffer | ring_buffer |
Functions | |
static void | rb_init (ring_buffer *rb, uint16_t size, uint8_t *buf) |
static uint16_t | rb_full_count (ring_buffer *rb) |
Return the number of elements stored in the ring buffer. More... | |
static int | rb_is_full (ring_buffer *rb) |
Returns true if and only if the ring buffer is full. More... | |
static int | rb_is_empty (ring_buffer *rb) |
Returns true if and only if the ring buffer is empty. More... | |
static void | rb_insert (ring_buffer *rb, uint8_t element) |
static uint8_t | rb_remove (ring_buffer *rb) |
Remove and return the first item from a ring buffer. More... | |
static int16_t | rb_safe_remove (ring_buffer *rb) |
Attempt to remove the first item from a ring buffer. More... | |
static int | rb_safe_insert (ring_buffer *rb, uint8_t element) |
Attempt to insert an element into a ring buffer. More... | |
static int | rb_push_insert (ring_buffer *rb, uint8_t element) |
Append an item onto the end of a non-full ring buffer. More... | |
static void | rb_reset (ring_buffer *rb) |
Discard all items from a ring buffer. More... | |
Simple circular buffer.
This implementation is not thread-safe. In particular, none of these functions is guaranteed re-entrant.
Definition in file ring_buffer.h.
typedef struct ring_buffer ring_buffer |
Ring buffer type.
The buffer is empty when head == tail.
The buffer is full when the head is one byte in front of the tail, modulo buffer length.
One byte is left free to distinguish empty from full.
|
inlinestatic |
Return the number of elements stored in the ring buffer.
rb | Buffer whose elements to count. |
Definition at line 84 of file ring_buffer.h.
Referenced by F4Light::UART_PPM::available(), usart_data_available(), usart_txfifo_freebytes(), and usart_txfifo_nbytes().
|
inlinestatic |
Initialise a ring buffer.
rb | Instance to initialise |
size | Number of items in buf. The ring buffer will always leave one element unoccupied, so the maximum number of elements it can store will be size - 1. Thus, size must be at least 2. |
buf | Buffer to store items into |
Definition at line 73 of file ring_buffer.h.
Referenced by F4Light::UART_PPM::UART_PPM(), usart_setup(), and VCP_Init().
|
inlinestatic |
Append element onto the end of a ring buffer.
rb | Buffer to append onto. |
element | Value to append. |
Definition at line 118 of file ring_buffer.h.
Referenced by rb_push_insert(), rb_safe_insert(), and usart_tx().
|
inlinestatic |
Returns true if and only if the ring buffer is empty.
rb | Buffer to test. |
Definition at line 109 of file ring_buffer.h.
Referenced by rb_safe_remove(), and usart_tx_irq().
|
inlinestatic |
Returns true if and only if the ring buffer is full.
rb | Buffer to test. |
Definition at line 99 of file ring_buffer.h.
Referenced by rb_push_insert(), rb_safe_insert(), and usart_tx().
|
inlinestatic |
Append an item onto the end of a non-full ring buffer.
If the buffer is full, removes its first item, then inserts the new element at the end.
rb | Ring buffer to insert into. |
element | Value to insert into ring buffer. |
Definition at line 173 of file ring_buffer.h.
Referenced by usart_rx_irq().
|
inlinestatic |
Remove and return the first item from a ring buffer.
rb | Buffer to remove from, must contain at least one element. |
Definition at line 128 of file ring_buffer.h.
Referenced by rb_push_insert(), rb_safe_remove(), F4Light::UART_PPM::read(), usart_getc(), and usart_tx_irq().
|
inlinestatic |
Discard all items from a ring buffer.
rb | Ring buffer to discard all items from. |
Definition at line 186 of file ring_buffer.h.
Referenced by usart_reset_rx(), usart_reset_tx(), usb_ioctl(), and usb_reset_rx().
|
inlinestatic |
Attempt to insert an element into a ring buffer.
rb | Buffer to insert into. |
element | Value to insert into rb. If rb is not full, appends element onto buffer. |
Definition at line 154 of file ring_buffer.h.
Referenced by F4Light::UART_PPM::putch(), and usart_rx_irq().
|
inlinestatic |
Attempt to remove the first item from a ring buffer.
If the ring buffer is nonempty, removes and returns its first item. If it is empty, does nothing and returns a negative value.
rb | Buffer to attempt to remove from. |
Definition at line 143 of file ring_buffer.h.