-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathping_pong_buffer.h
More file actions
66 lines (53 loc) · 1.48 KB
/
Copy pathping_pong_buffer.h
File metadata and controls
66 lines (53 loc) · 1.48 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @brief simple ping-pong buffer implementation
*/
#ifndef PING_PONG_BUFFER_H_
#define PING_PONG_BUFFER_H_
#include <stdbool.h>
/* ping pong buffer control structure */
typedef struct {
unsigned char *buffer_data;
unsigned char ping;
unsigned char pong;
int buffer_size;
int put_index;
int get_index;
bool full_signal;
}ppbuf_t;
/**
* @brief insert on active buffer
*/
int ppbuf_insert_active(ppbuf_t *p, void *data, int size);
/**
* @brief remove from inactive buffer
*/
int ppbuf_remove_inactive(ppbuf_t *p, void *data, int size);
/**
* @brief USE WITH DMA ONLY! get the current active buffer address
*/
unsigned char *ppbuf_dma_get_active_addr(ppbuf_t* p, int *size);
/**
* @brief USE WITH DMA ONLY! get the current inactive buffer address
*/
unsigned char *ppbuf_dma_get_inactive_addr(ppbuf_t* p, int *size);
/**
* @brief USE WITH DMA ONLY! force full signaling to next buffer become available
*/
int ppbuf_dma_force_swap(ppbuf_t* p);
/**
* @brief get full signal
*/
bool ppbuf_get_full_signal(ppbuf_t *p, bool consume);
/* instantiate a fully initialized and static ping-pong buffer */
#define PPBUF_DECLARE(name,size) \
unsigned char ppbuf_mem_##name[size * 2] = {0}; \
ppbuf_t name = { \
.buffer_data = &ppbuf_mem_##name[0], \
.ping = 1, \
.pong = 0, \
.buffer_size = size, \
.put_index = 0, \
.get_index = 0, \
.full_signal = false \
}
#endif /* PING_PONG_BUFFER_H_ */