-
Notifications
You must be signed in to change notification settings - Fork 44
/
ringBuf.h
38 lines (29 loc) · 850 Bytes
/
ringBuf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef RING_BUF_H
#define RING_BUF_H
#include <inttypes.h>
/*
* Change this size according to your needs
*/
#define RING_BUF_SIZE 64
#define RING_BUF_MASK (RING_BUF_SIZE - 1)
typedef struct
{
uint16_t buf[RING_BUF_SIZE];
volatile uint8_t head;
volatile uint8_t tail;
} ringBuf_t;
#ifdef __cplusplus
extern "C" {
#endif
void rBufInit (ringBuf_t *_this);
void rBufFlush (ringBuf_t *_this);
void rBufPushFront (ringBuf_t *_this, uint16_t data);
void rBufPopBack (ringBuf_t *_this, uint16_t *data);
void rBufPeekBack (ringBuf_t *_this, uint16_t *data);
uint8_t rBufIsEmpty (ringBuf_t *_this);
uint8_t rBufIsFull (ringBuf_t *_this);
uint8_t rBufElemCount (ringBuf_t *_this);
#ifdef __cplusplus
}
#endif
#endif /* RING_BUF_H */