BSPACM  20150113
Board Support Package for ARM Cortex-M Microcontrollers
Data Fields
sFIFO Struct Reference

#include <bspacm/internal/utility/fifo.h>

Data Fields

volatile uint16_t head
 
volatile uint16_t tail
 
const uint16_t size
 
volatile uint8_t cell []
 

Detailed Description

Data structure for a first-in-first-out circular buffer of arbitrary size, holding octet (uint8_t) values.

This struct uses the flexible array capability standardized in C99, along with the FIFO_DEFINE_ALLOCATION() and FIFO_FROM_ALLOCATION() macros, to avoid dynamic memory allocation while still allowing variation in size between instances of the data type.

Invariants and policies:

This data structure is intended to be shared between interrupt handlers and framework code. It probably should not be accessed directly by user code. The following operations are provided to help maintain the invariants above:

Although these inline functions perform common operations, for full efficiency it is sometimes necessary to manipulate the head and tail fields directly. The fields that are expected to be read and written by both interrupt handlers and framework code are marked volatile to ensure they are not cached inappropriately. Nonetheless, all changes to the volatile fields of this structure must be done in a context that inhibits external modifications. As an optimization, framework code executed with interrupts off may use local cached variables holding head or tail while performing operations that involve multiple cells of the buffer, so long as the final values are written back to the structure before interrupts are re-enabled. Be sure to satisfy the data structure invariants when writing such code.

Field Documentation

volatile uint8_t sFIFO::cell[]

The buffer of the FIFO holds the values currently in the FIFO.

volatile uint16_t sFIFO::head

The head of the FIFO is the cell into which the next value to be stored will be written (things enter the head, and leave the tail).

const uint16_t sFIFO::size

The size of the FIFO is the number of cells that can store values. The length of the FIFO is the number of cells that currently store values. The relationship between length and size is 0 <= length < size. A fifo is empty with length is zero (head == tail); it is full when length == size-1 (the next cell after head is tail).

volatile uint16_t sFIFO::tail

The tail of the FIFO is the cell holding the next value to be read.


The documentation for this struct was generated from the following file: