KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bytefifo.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2012-2015 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : bytefifo.c
11  * Created : 10 mrt. 2015
12  * Author : Vincent van Beveren
13  */
14 
15 #include "coll/bytefifo.h"
16 
17 bool bfWrite(ByteFifo * const bf, uint8_t b)
18 {
19  if (bfFull(bf)) return false;
20  bf->buf[bf->wp] = b;
21  bf->wp = ( bf->wp + 1 ) % bf->cap;
22  bf->len++;
23  return true;
24 }
25 
26 
27 
28 bool bfRead(ByteFifo * const bf, uint8_t * const b)
29 {
30  if (bfEmpty(bf)) return false;
31  bf->rp = ( bf->rp + 1 ) % bf->cap;
32  *b = bf->buf[bf->rp];
33  bf->len--;
34  return true;
35 }
static bool bfEmpty(ByteFifo *const bf)
Returns whether or not the byte-fifo is empty.
Definition: bytefifo.h:72
bool bfWrite(ByteFifo *const bf, uint8_t b)
Writes a byte to the byte-fifo.
Definition: bytefifo.c:17
static bool bfFull(ByteFifo *const bf)
Returns whether or not the byte-fifo is full.
Definition: bytefifo.h:60
Implements a simple byte-orientated Fifo with a maximum size of 255 bytes.
bool bfRead(ByteFifo *const bf, uint8_t *const b)
Reads a byte from the byte-fifo.
Definition: bytefifo.c:28