pelib  2.0.0
include/pelib/fifo.h File Reference
#include <stddef.h>
#include <pelib/template.h>
#include <pelib/structure.h>
Include dependency graph for fifo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define cfifo(elem)   PELIB_CONCAT_2(cfifo_, elem)
#define cfifo_t(elem)   PELIB_CONCAT_2(cfifo(elem), _t)
#define pelib_cfifo_push(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _push)
#define pelib_cfifo_fill(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _fill)
#define pelib_cfifo_pop(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _pop)
#define pelib_cfifo_discard(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _discard)
#define pelib_cfifo_peek(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _peek)
#define pelib_cfifo_last(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _last)
#define pelib_cfifo_is_full(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _is_full)
#define pelib_cfifo_is_empty(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _is_empty)
#define pelib_cfifo_string_content(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _string_content)
#define pelib_cfifo_printf_content(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _printf_content)
#define pelib_cfifo_pushmem(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _pushmem)
#define pelib_cfifo_popmem(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _popmem)
#define pelib_cfifo_peekmem(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _peekmem)
#define pelib_cfifo_peekaddr(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _peekaddr)
#define pelib_cfifo_writeaddr(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _writeaddr)
#define pelib_cfifo_popfifo(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _popfifo)
#define pelib_cfifo_length(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _length)
#define pelib_cfifo_last(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _last)
#define pelib_cfifo_capacity(elem)   PELIB_CONCAT_3(pelib_, cfifo(elem), _capacity)
#define STRUCT_T   cfifo_t(CFIFO_T)
#define PELIB_FIFO_ELEM_MAX_CHAR   11

Typedefs

typedef enum pelib_fifo_operation pelib_fifo_operation_t

Enumerations

enum  pelib_fifo_operation { PELIB_CFIFO_PUSH, PELIB_CFIFO_POP }

Functions

struct cfifo (CFIFO_T)
int pelib_cfifo_push() CFIFO_T (cfifo_t(CFIFO_T)*, CFIFO_T)
size_t pelib_cfifo_fill() CFIFO_T (cfifo_t(CFIFO_T)*, size_t n)
CFIFO_T pelib_cfifo_pop() CFIFO_T (cfifo_t(CFIFO_T)*)
CFIFO_T *pelib_cfifo_peekaddr() CFIFO_T (cfifo_t(CFIFO_T)*, size_t offset, size_t *num, CFIFO_T **remaining)
CFIFO_T *pelib_cfifo_writeaddr() CFIFO_T (cfifo_t(CFIFO_T)*, size_t *num, CFIFO_T **remaining)
size_t pelib_cfifo_pushmem() CFIFO_T (cfifo_t(CFIFO_T)*, CFIFO_T *addr, size_t n)
size_t pelib_cfifo_peekmem() CFIFO_T (cfifo_t(CFIFO_T)*, CFIFO_T *, size_t n, size_t offset)
size_t pelib_cfifo_popfifo() CFIFO_T (cfifo_t(CFIFO_T)*, cfifo_t(CFIFO_T)*dest, size_t n)

Define Documentation

#define cfifo (   elem)    PELIB_CONCAT_2(cfifo_, elem)

Definition at line 42 of file fifo.h.

#define cfifo_t (   elem)    PELIB_CONCAT_2(cfifo(elem), _t)

Definition at line 43 of file fifo.h.

#define pelib_cfifo_capacity (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _capacity)

Definition at line 63 of file fifo.h.

#define pelib_cfifo_discard (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _discard)

Definition at line 48 of file fifo.h.

#define pelib_cfifo_fill (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _fill)

Definition at line 46 of file fifo.h.

#define pelib_cfifo_is_empty (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _is_empty)

Definition at line 52 of file fifo.h.

#define pelib_cfifo_is_full (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _is_full)

Definition at line 51 of file fifo.h.

#define pelib_cfifo_last (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _last)

Definition at line 62 of file fifo.h.

#define pelib_cfifo_last (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _last)

Definition at line 62 of file fifo.h.

#define pelib_cfifo_length (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _length)

Definition at line 61 of file fifo.h.

#define pelib_cfifo_peek (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _peek)

Definition at line 49 of file fifo.h.

#define pelib_cfifo_peekaddr (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _peekaddr)

Definition at line 58 of file fifo.h.

#define pelib_cfifo_peekmem (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _peekmem)

Definition at line 57 of file fifo.h.

#define pelib_cfifo_pop (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _pop)

Definition at line 47 of file fifo.h.

#define pelib_cfifo_popfifo (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _popfifo)

Definition at line 60 of file fifo.h.

#define pelib_cfifo_popmem (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _popmem)

Definition at line 56 of file fifo.h.

#define pelib_cfifo_printf_content (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _printf_content)

Definition at line 54 of file fifo.h.

#define pelib_cfifo_push (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _push)

Definition at line 45 of file fifo.h.

#define pelib_cfifo_pushmem (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _pushmem)

Definition at line 55 of file fifo.h.

#define pelib_cfifo_string_content (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _string_content)

Definition at line 53 of file fifo.h.

#define pelib_cfifo_writeaddr (   elem)    PELIB_CONCAT_3(pelib_, cfifo(elem), _writeaddr)

Definition at line 59 of file fifo.h.

#define PELIB_FIFO_ELEM_MAX_CHAR   11

Definition at line 79 of file fifo.h.

#define STRUCT_T   cfifo_t(CFIFO_T)

Definition at line 76 of file fifo.h.


Typedef Documentation

Definition at line 37 of file fifo.h.


Enumeration Type Documentation

Last operation performed on an instance of circular fifo

Enumerator:
PELIB_CFIFO_PUSH 
PELIB_CFIFO_POP 

Definition at line 32 of file fifo.h.


Function Documentation

struct cfifo ( CFIFO_T  ) [read]

generic circular fifo

index of the next element to read at the next pop operation

index of the next element able to receive new data at the next push operation

Last operation, push or pop, performed on this circular fifo. Set to PELIB_CFIFO_POP at fifo initialization

Maximum number of elements this fifo can hold at a given time

Pointer to the memory portion that hold the data

Definition at line 66 of file fifo.h.

Pushes a new element the tail of the fifo

Definition at line 305 of file fifo.c.

Assumes n elements have been written to the fifo and set the write structire member accordingly

Discards n elements from the head of the fifo

Reads the head element but doesn't set the hed to the next element

Parameters:
offsetSkip the first offset elements before reading

Returns the head of the fifo and set the head to the next element

Returns 0 if at least one push operation can be performed on the fifo

Returns 0 if there is at least one element stored in the fifo

Returns the number of elements available in the fifo

Returns the number that was last written in the fifo

Returns the maximum number of elements this fifo can contain

CFIFO_T* pelib_cfifo_peekaddr() CFIFO_T ( cfifo_t(CFIFO_T)*  ,
size_t  offset,
size_t num,
CFIFO_T **  remaining 
)

Returns an address that contains elements to be read. If num is not NULL and if there is at least one element available, writes the number of elements available in address pointer by num. If no element is available, returns NULL and writes nothing in other parameters. Note that *num may take a lower value than pelib_cfifo_length() if pelib_cfifo_length() >= 2. In this case, if remaining is not null, then remaining is set to point to the the rest of the data; otherwise it is set to NULL.

Definition at line 340 of file fifo.c.

CFIFO_T* pelib_cfifo_writeaddr() CFIFO_T ( cfifo_t(CFIFO_T)*  ,
size_t num,
CFIFO_T **  remaining 
)

Returns an address that can hold new elements. If num is not NULL and if there is at least one memory element available, writes the number of additional elements the fifo can store in address pointer by num. If no memory is available, returns NULL and writes nothing in other parameters. Note that *num may take a lower value than pelib_cifo_capacity() - pelib_cfifo_length(). In this case and if remaining is non-null, remaining points to the extra memory buffer. Otherwise, it is set to NULL.

Definition at line 382 of file fifo.c.

Pushes all n elements stored in some memory address and update

Parameters:
Addressof the first element to be pushed
nNumber of elements to push
Returns:
Number of elements that could be pushed. Lower than n if there is not enough space to write all elements

Pops n elements and copy them into memory pointed by addr and update the fifo head element

Parameters:
addrAddress where the first element popped is written
nNumber of elements to pop
Returns:
Number of elements actually popped. May be lower than n if there are not enough elemennts stored

Definition at line 481 of file fifo.c.

Copies the n first elements into addr but do not discard any element in the fifo

Parameters:
nNumber of elements to peek from fifo
offsetNumber of elements to skip before reading
Returns:
Number of elemetns that could actually be read

Definition at line 607 of file fifo.c.

Pops n elements from fifo and pushes them into fifo dest

Parameters:
destFifo that receives the elements popped
nnumber of elements to pop
Returns:
Number of elements actually pushed in fifo dest

Definition at line 699 of file fifo.c.