SingingCat 0
application
ringbuffer.h
1#ifndef RINGBUFFER_H
2#define RINGBUFFER_H
3#include "stdint.h"
4typedef struct ringbuffer {
5 char buf[1024];
6 uint16_t readptr;
7 uint16_t volatile writeptr; // point to next position to write
8 uint32_t volatile bytes; // number of bytes readable
10
11/* \brief add a byte to the ringbuffer, if buffer is full, overwrites oldest byte */
12void ringbuffer_add_byte(struct ringbuffer *r, uint8_t b);
13
14/* \brief return a byte. if return value is >255, no value is available */
15uint16_t ringbuffer_get_byte(struct ringbuffer *r);
16
17void ringbuffer_init(struct ringbuffer *r);
18/*
19 *\brief get upto a delimiter, return number of chars.
20 */
21int ringbuffer_get_to_delimiter(struct ringbuffer *r, char delimiter, char *outbuf, int outbufsize);
22
23#endif