1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/include/ringbuffer.h

50 lines
1.2 KiB
C
Raw Normal View History

2013-06-22 17:58:19 +02:00
/**
* Ringbuffer header
2013-06-22 17:58:19 +02:00
*
* Copyright (C) 2013 Freie Universität Berlin
* Copyright (C) 2013 INRIA
*
2013-11-22 20:47:05 +01:00
* This file is subject to the terms and conditions of the GNU Lesser General
2013-06-22 17:58:19 +02:00
* Public License. See the file LICENSE in the top level directory for more
* details.
*
* @ingroup sys_lib
* @{
* @file ringbuffer.h
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author René Kijewski <rene.kijewski@fu-berlin.de>
2013-06-22 17:58:19 +02:00
* @}
*/
2010-09-22 17:25:19 +02:00
#ifndef __RINGBUFFER_H
2013-06-22 17:58:19 +02:00
#define __RINGBUFFER_H
2010-09-22 17:25:19 +02:00
typedef struct ringbuffer {
2010-09-24 13:53:22 +02:00
char *buf;
2010-09-22 17:25:19 +02:00
unsigned int start;
unsigned int end;
unsigned int size;
unsigned int avail;
2011-03-08 11:17:57 +01:00
} ringbuffer_t;
2010-09-22 17:25:19 +02:00
2013-06-22 17:58:19 +02:00
void ringbuffer_init(ringbuffer_t *rb, char *buffer, unsigned int bufsize);
void ringbuffer_add_one(ringbuffer_t *rb, char c);
void ringbuffer_add(ringbuffer_t *rb, char *buf, int n);
int ringbuffer_get_one(ringbuffer_t *rb);
int ringbuffer_get(ringbuffer_t *rb, char *buf, int n);
2010-09-22 17:25:19 +02:00
static inline int ringbuffer_empty(ringbuffer_t *rb)
{
return rb->avail == 0;
}
static inline int ringbuffer_full(ringbuffer_t *rb)
{
return rb->avail == rb->size;
}
int ringbuffer_peek_one(ringbuffer_t *rb);
int ringbuffer_peek(ringbuffer_t *rb, char *buf, unsigned n);
2010-09-22 17:25:19 +02:00
#endif /* __RINGBUFFER_H */