commit | author | age
|
d6b4a7
|
1 |
/********************************************************************************* |
G |
2 |
* Copyright: (C) 2023 LingYun IoT System Studio. |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* Filename: ringbuf.h |
|
6 |
* Description: This file is common ring buffer API functions |
|
7 |
* |
|
8 |
* Version: 1.0.0(11/08/23) |
|
9 |
* Author: Guo Wenxue <guowenxue@gmail.com> |
|
10 |
* ChangeLog: 1, Release initial version on "11/08/23 16:18:43" |
|
11 |
* |
|
12 |
********************************************************************************/ |
|
13 |
|
|
14 |
#ifndef _RINGBUF_H_ |
|
15 |
#define _RINGBUF_H_ |
|
16 |
|
|
17 |
struct ring_buffer |
|
18 |
{ |
|
19 |
unsigned char *buffer; |
|
20 |
int wr_pointer; |
|
21 |
int rd_pointer; |
|
22 |
int size; |
|
23 |
}; |
|
24 |
|
|
25 |
|
|
26 |
/* Initial the ring buffer */ |
|
27 |
void rb_init (struct ring_buffer *ring, unsigned char *buff, int size) ; |
|
28 |
|
|
29 |
|
|
30 |
/* Description: Write $len bytes data in $buf into ring buffer $rb |
|
31 |
* Return Value: The actual written into ring buffer data size, if ring buffer |
|
32 |
* left space size small than $len, then only part of the data be written into. |
|
33 |
*/ |
|
34 |
int rb_write (struct ring_buffer *rb, unsigned char *buf, int len) ; |
|
35 |
|
|
36 |
|
|
37 |
/* Get ring buffer left free size */ |
|
38 |
int rb_free_size (struct ring_buffer *rb); |
|
39 |
|
|
40 |
|
|
41 |
/* Read $max bytes data from ring buffer $rb to $buf */ |
|
42 |
int rb_read (struct ring_buffer *rb, unsigned char *buf, int max); |
|
43 |
|
|
44 |
|
|
45 |
/* Read a specify $index byte data in ring buffer $rb */ |
|
46 |
unsigned char rb_peek(struct ring_buffer *rb, int index); |
|
47 |
|
|
48 |
|
|
49 |
/* Get data size in the ring buffer */ |
|
50 |
int rb_data_size (struct ring_buffer *rb); |
|
51 |
|
|
52 |
|
|
53 |
/* Clear the ring buffer data */ |
|
54 |
void rb_clear (struct ring_buffer *rb) ; |
|
55 |
|
|
56 |
#endif /* ----- #ifndef _RINGBUF_H_ ----- */ |
|
57 |
|