]> git.zerfleddert.de Git - fnordlicht-mini/blame - firmware/fnordlicht-firmware/fifo.c
fix config.mk file header comment
[fnordlicht-mini] / firmware / fnordlicht-firmware / fifo.c
CommitLineData
ec1bef8e 1/* vim:ts=4 sts=4 et tw=80
2 *
3 * fnordlicht firmware
4 *
5 * for additional information please
6 * see http://lochraster.org/fnordlichtmini
7 *
8 * (c) by Alexander Neumann <alexander@bumpern.de>
9 * Lars Noschinski <lars@public.noschinski.de>
10 *
11 * This program is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 3 as published by
13 * the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#include "fifo.h"
25
26void fifo_init(fifo_t *f)
27{
28 f->read = 0;
29 f->write = 0;
30}
31
32void fifo_enqueue(fifo_t *f, fifo_content_t data)
33{
34 f->buffer[f->write] = data;
35 f->write = (f->write + 1) % CONFIG_FIFO_SIZE;
36}
37
38fifo_content_t fifo_dequeue(fifo_t *f)
39{
40 fifo_content_t data = f->buffer[f->read];
41 f->read = (f->read + 1) % CONFIG_FIFO_SIZE;
42 return data;
43}
44
45fifo_size_t fifo_fill(fifo_t *f)
46{
47 if (f->write >= f->read)
48 return f->write - f->read;
49 else
50 return CONFIG_FIFO_SIZE - (f->read - f->write);
51}
52
53bool fifo_empty(fifo_t *f)
54{
55 return f->read == f->write;
56}
57
58bool fifo_full(fifo_t *f)
59{
60 return fifo_fill(f) == CONFIG_FIFO_SIZE-1;
61}
Impressum, Datenschutz