PatchworkOS  dbbdc99
A non-POSIX operating system.
Loading...
Searching...
No Matches
FIFO Buffer

First-in first-out buffer. More...

Collaboration diagram for FIFO Buffer:

Detailed Description

First-in first-out buffer.

Data Structures

struct  fifo_t
 FIFO Buffer. More...
 

Macros

#define FIFO_CREATE(_buf, _size)   {.buffer = (uint8_t*)(_buf), .size = (_size), .head = 0, .tail = 0}
 Create a fifo buffer initializer.
 
#define FIFO_DEFINE(_name, _size)
 Define and initialize a fifo buffer.
 

Functions

static void fifo_init (fifo_t *fifo, uint8_t *buffer, size_t size)
 Initialize a fifo buffer.
 
static void fifo_reset (fifo_t *fifo)
 Reset a fifo buffer.
 
static size_t fifo_bytes_readable (const fifo_t *fifo)
 Return the number of bytes available for reading in a fifo buffer.
 
static size_t fifo_bytes_writeable (const fifo_t *fifo)
 Return the number of bytes available for writing in a fifo buffer.
 
static size_t fifo_read (fifo_t *fifo, void *buffer, size_t count)
 Read data from a fifo buffer at a specific offset.
 
static size_t fifo_write (fifo_t *fifo, const void *buffer, size_t count)
 Write data to the fifo buffer.
 
static void fifo_advance_head (fifo_t *fifo, size_t count)
 Advance the head of the fifo buffer.
 
static void fifo_advance_tail (fifo_t *fifo, size_t count)
 Advance the tail of the fifo buffer.
 

Macro Definition Documentation

◆ FIFO_CREATE

#define FIFO_CREATE (   _buf,
  _size 
)    {.buffer = (uint8_t*)(_buf), .size = (_size), .head = 0, .tail = 0}

Create a fifo buffer initializer.

Parameters
_bufPointer to the buffer memory.
_sizeThe size of the buffer in bytes.

Definition at line 33 of file fifo.h.

◆ FIFO_DEFINE

#define FIFO_DEFINE (   _name,
  _size 
)
Value:
uint8_t _name##_buffer[_size]; \
fifo_t _name = FIFO_CREATE(_name##_buffer, _size)
#define FIFO_CREATE(_buf, _size)
Create a fifo buffer initializer.
Definition fifo.h:33
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
FIFO Buffer.
Definition fifo.h:20

Define and initialize a fifo buffer.

Helps define a fifo buffer with a backing buffer.

Parameters
_nameThe name of the fifo buffer.
_sizeThe size of the fifo buffer in bytes.

Definition at line 43 of file fifo.h.

Function Documentation

◆ fifo_init()

static void fifo_init ( fifo_t fifo,
uint8_t buffer,
size_t  size 
)
inlinestatic

Initialize a fifo buffer.

Parameters
fifoPointer to the fifo buffer structure.
bufferPointer to the buffer memory.
sizeThe size of the buffer in bytes.

Definition at line 54 of file fifo.h.

Here is the caller graph for this function:

◆ fifo_reset()

static void fifo_reset ( fifo_t fifo)
inlinestatic

Reset a fifo buffer.

Parameters
fifoPointer to the fifo buffer structure.

Definition at line 67 of file fifo.h.

◆ fifo_bytes_readable()

static size_t fifo_bytes_readable ( const fifo_t fifo)
inlinestatic

Return the number of bytes available for reading in a fifo buffer.

Parameters
fifoPointer to the fifo buffer structure.
Returns
The number of bytes used.

Definition at line 79 of file fifo.h.

Here is the caller graph for this function:

◆ fifo_bytes_writeable()

static size_t fifo_bytes_writeable ( const fifo_t fifo)
inlinestatic

Return the number of bytes available for writing in a fifo buffer.

Parameters
fifoPointer to the fifo buffer structure.
Returns
The number of bytes available for writing.

Definition at line 95 of file fifo.h.

Here is the caller graph for this function:

◆ fifo_read()

static size_t fifo_read ( fifo_t fifo,
void *  buffer,
size_t  count 
)
inlinestatic

Read data from a fifo buffer at a specific offset.

Parameters
fifoThe fifo buffer structure.
bufferThe destination buffer.
countThe number of bytes to read.
Returns
The number of bytes read.

Definition at line 113 of file fifo.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fifo_write()

static size_t fifo_write ( fifo_t fifo,
const void *  buffer,
size_t  count 
)
inlinestatic

Write data to the fifo buffer.

Will write up to the available space.

Parameters
fifoPointer to the fifo buffer structure.
bufferThe source buffer.
countThe number of bytes to write.
Returns
The number of bytes written.

Definition at line 155 of file fifo.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fifo_advance_head()

static void fifo_advance_head ( fifo_t fifo,
size_t  count 
)
inlinestatic

Advance the head of the fifo buffer.

Parameters
fifoPointer to the fifo buffer structure.
countThe number of bytes to advance the head by.

Definition at line 188 of file fifo.h.

◆ fifo_advance_tail()

static void fifo_advance_tail ( fifo_t fifo,
size_t  count 
)
inlinestatic

Advance the tail of the fifo buffer.

Parameters
fifoPointer to the fifo buffer structure.
countThe number of bytes to advance the tail by.

Definition at line 199 of file fifo.h.