-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathuArmRingBuffer.cpp
More file actions
65 lines (45 loc) · 954 Bytes
/
uArmRingBuffer.cpp
File metadata and controls
65 lines (45 loc) · 954 Bytes
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
/**
******************************************************************************
* @file uArmRingBuffer.cpp
* @author David.Long
* @email xiaokun.long@ufactory.cc
* @date 2016-12-08
******************************************************************************
*/
#include "uArmRingBuffer.h"
uArmRingBuffer::uArmRingBuffer()
{
}
void uArmRingBuffer::init(uint8_t *data_buf, uint32_t buf_size)
{
head = 0;
tail = 0;
data = data_buf;
buffer_size = buf_size;
}
uint32_t uArmRingBuffer::put(uint8_t value)
{
if (isFull())
{
return 0;
}
data[tail] = value;
tail = (tail + 1) % buffer_size;
return 1;
}
uint32_t uArmRingBuffer::get(uint8_t *value)
{
if (isEmpty())
return 0;
*value = data[head];
head = (head + 1) % buffer_size;
return 1;
}
uint32_t uArmRingBuffer::isFull()
{
return ((tail + 1) % buffer_size) == head ? 1 : 0;
}
uint32_t uArmRingBuffer::isEmpty()
{
return head == tail ? 1 : 0;
}