-
Notifications
You must be signed in to change notification settings - Fork 4
/
tiny_mm.c
53 lines (47 loc) · 1.1 KB
/
tiny_mm.c
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
#include "tiny_mm.h"
/*
* @brief
* Arrange memory that could been use
* XXX: this buffer could only been used in specific situation
* @inputs
* @outputs
* @retval
*/
void recg_buf_arrange(struct st_recg_buf *recg_buf, uint8_t *buf, uint32_t n_bytes)
{
recg_buf->buf = buf;
recg_buf->max_len = n_bytes;
recg_buf->cur_len = 0;
}
/*
* @brief
* Arrange memory that could been use
* XXX: this buffer could only been used in specific situation
* @inputs
* @outputs
* @retval
*/
void *get_recg_buf(struct st_recg_buf *recg_buf, int n_bytes)
{
void *ret = (void *)0;
ret = recg_buf->buf + recg_buf->cur_len;
recg_buf->cur_len += n_bytes;
if (recg_buf->cur_len > recg_buf->max_len) {
recg_buf->cur_len -= n_bytes;
return (void *)0;
} else {
return ret;
}
}
/*
* @brief
* Arrange memory that could been use
* XXX: this buffer could only been used in specific situation
* @inputs
* @outputs
* @retval
*/
void put_recg_buf(struct st_recg_buf *recg_buf, int n_bytes)
{
recg_buf->cur_len -= n_bytes;
}