spinn_common 7.1.1
Support code for SpiNNaker applications.
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
circular_buffer.h File Reference

Fast circular buffer. More...

#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  _circular_buffer
 Implementation of a circular buffer. More...
 

Typedefs

typedef _circular_buffercircular_buffer
 The public interface type is a pointer to the implementation.
 

Functions

static uint32_t _circular_buffer_next (circular_buffer buffer, uint32_t current)
 Get the index of the next position in the buffer from the given value.
 
static bool _circular_buffer_not_empty (circular_buffer buffer)
 Get whether the buffer is not empty.
 
static bool _circular_buffer_not_full (circular_buffer buffer, uint32_t next)
 Get whether the buffer is able to accept more values.
 
circular_buffer circular_buffer_initialize (uint32_t size)
 Create a new FIFO circular buffer of at least the given size. For efficiency, the buffer can be bigger than requested.
 
static bool circular_buffer_add (circular_buffer buffer, uint32_t item)
 Add an item to an existing buffer.
 
static bool circular_buffer_get_next (circular_buffer buffer, uint32_t *item)
 Get the next item from an existing buffer.
 
static bool circular_buffer_advance_if_next_equals (circular_buffer buffer, uint32_t item)
 Advance the buffer if the next item is equal to the given value.
 
static uint32_t circular_buffer_size (circular_buffer buffer)
 Get the size of the buffer.
 
static uint32_t circular_buffer_get_n_buffer_overflows (circular_buffer buffer)
 Get the number of overflows that have occurred when adding to the buffer.
 
static void circular_buffer_clear (circular_buffer buffer)
 Clear the circular buffer.
 
void circular_buffer_print_buffer (circular_buffer buffer)
 Print the contents of the buffer.
 
static uint32_t circular_buffer_input (circular_buffer buffer)
 Get the input index.
 
static uint32_t circular_buffer_output (circular_buffer buffer)
 Get the output index.
 
static uint32_t circular_buffer_real_size (circular_buffer buffer)
 Get the buffer size.
 
static uint32_t circular_buffer_value_at_index (circular_buffer buffer, uint32_t index)
 Get the buffer contents at a particular index.
 

Detailed Description

Fast circular buffer.


Data Structure Documentation

◆ _circular_buffer

struct _circular_buffer

Implementation of a circular buffer.

Data Fields
uint32_t buffer_size The size of the buffer. One less than a power of two.
uint32_t output The index of the next position in the buffer to read from.
uint32_t input The index of the next position in the buffer to write to.
uint32_t overflows The number of times an insertion has failed due to the buffer being full.
uint32_t buffer[] The buffer itself.

Function Documentation

◆ _circular_buffer_next()

static uint32_t _circular_buffer_next ( circular_buffer  buffer,
uint32_t  current 
)
inlinestatic

Get the index of the next position in the buffer from the given value.

Parameters
[in]bufferThe buffer.
[in]currentThe index to get the next one after.
Returns
The next index after the given one.

◆ _circular_buffer_not_empty()

static bool _circular_buffer_not_empty ( circular_buffer  buffer)
inlinestatic

Get whether the buffer is not empty.

Parameters
[in]bufferThe buffer.
Returns
Whether the buffer has anything in it.

◆ _circular_buffer_not_full()

static bool _circular_buffer_not_full ( circular_buffer  buffer,
uint32_t  next 
)
inlinestatic

Get whether the buffer is able to accept more values.

Parameters
[in]bufferThe buffer.
[in]nextThe next position in the buffer
Returns
Whether the buffer has room to take another value.

◆ circular_buffer_initialize()

circular_buffer circular_buffer_initialize ( uint32_t  size)

Create a new FIFO circular buffer of at least the given size. For efficiency, the buffer can be bigger than requested.

Parameters
[in]sizeThe minimum number of elements in the buffer to be created
Returns
A reference to the created buffer.

◆ circular_buffer_add()

static bool circular_buffer_add ( circular_buffer  buffer,
uint32_t  item 
)
inlinestatic

Add an item to an existing buffer.

Parameters
[in]bufferThe buffer struct to add to
[in]itemThe item to add.
Returns
Whether the item was added (it fails if the buffer is full).

◆ circular_buffer_get_next()

static bool circular_buffer_get_next ( circular_buffer  buffer,
uint32_t *  item 
)
inlinestatic

Get the next item from an existing buffer.

Parameters
[in]bufferThe buffer to get the next item from.
[out]itemThe retrieved item.
Returns
Whether an item was retrieved.

◆ circular_buffer_advance_if_next_equals()

static bool circular_buffer_advance_if_next_equals ( circular_buffer  buffer,
uint32_t  item 
)
inlinestatic

Advance the buffer if the next item is equal to the given value.

Parameters
[in]bufferThe buffer to advance
[in]itemThe item to check
Returns
Whether the buffer was advanced.

◆ circular_buffer_size()

static uint32_t circular_buffer_size ( circular_buffer  buffer)
inlinestatic

Get the size of the buffer.

Parameters
[in]bufferThe buffer to get the size of
Returns
The number of elements currently in the buffer

◆ circular_buffer_get_n_buffer_overflows()

static uint32_t circular_buffer_get_n_buffer_overflows ( circular_buffer  buffer)
inlinestatic

Get the number of overflows that have occurred when adding to the buffer.

Parameters
[in]bufferThe buffer to check for overflows
Returns
The number of times add was called and returned False

◆ circular_buffer_clear()

static void circular_buffer_clear ( circular_buffer  buffer)
inlinestatic

Clear the circular buffer.

Parameters
[in]bufferThe buffer to clear

◆ circular_buffer_print_buffer()

void circular_buffer_print_buffer ( circular_buffer  buffer)

Print the contents of the buffer.

Do not use if the sark IO_BUF is being used for binary data.

Parameters
[in]bufferThe buffer to print

◆ circular_buffer_input()

static uint32_t circular_buffer_input ( circular_buffer  buffer)
inlinestatic

Get the input index.

Parameters
[in]bufferThe buffer.
Returns
The index that the next value to be put into the buffer will be placed at.

◆ circular_buffer_output()

static uint32_t circular_buffer_output ( circular_buffer  buffer)
inlinestatic

Get the output index.

Parameters
[in]bufferThe buffer.
Returns
The index that the next value to be removed from the buffer is/will be at.

◆ circular_buffer_real_size()

static uint32_t circular_buffer_real_size ( circular_buffer  buffer)
inlinestatic

Get the buffer size.

Parameters
[in]bufferThe buffer.
Returns
The real size of the buffer.

◆ circular_buffer_value_at_index()

static uint32_t circular_buffer_value_at_index ( circular_buffer  buffer,
uint32_t  index 
)
inlinestatic

Get the buffer contents at a particular index.

Parameters
[in]bufferThe buffer.
[in]indexThe index to use. Note that the index is not limited to the size of the buffer.
Returns
The contents of the buffer at a particular index.