-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrbuf.h
81 lines (63 loc) · 2.97 KB
/
rbuf.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef _RBUF_H_
#define _RBUF_H_
/***********************************************************************************************************
Author: Nima Askari
Github: https://www.github.com/NimaLTD
LinkedIn: https://www.linkedin.com/in/nimaltd
Youtube: https://www.youtube.com/@nimaltd
Instagram: https://instagram.com/github.NimaLTD
Version: 2.2.0
History:
2.2.0
- Added RBUF_PushN(),RBUF_PopN() functions
2.1.0
- Added RBUF_Used(),RBUF_Format() functions
2.0.0
- Rewrite again
- Support STM32CubeMx Packet installer
***********************************************************************************************************/
#ifdef __cplusplus
extern "C"
{
#endif
/************************************************************************************************************
************** Include Headers
************************************************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
/************************************************************************************************************
************** Public Definitions
************************************************************************************************************/
// none
/************************************************************************************************************
************** Public struct/enum
************************************************************************************************************/
typedef struct
{
size_t ItemSize;
uint32_t Capacity;
uint32_t Head;
uint32_t Tail;
uint32_t Count;
void *Buffer;
} RBUF_HandleTypeDef;
/************************************************************************************************************
************** Public Functions
************************************************************************************************************/
RBUF_HandleTypeDef* RBUF_Init(size_t ItemSize, uint32_t Capacity);
void RBUF_DeInit(RBUF_HandleTypeDef *rbuf);
bool RBUF_IsFull(RBUF_HandleTypeDef *rbuf);
bool RBUF_IsEmpty(RBUF_HandleTypeDef *rbuf);
uint32_t RBUF_Available(RBUF_HandleTypeDef *rbuf);
uint32_t RBUF_Used(RBUF_HandleTypeDef *rbuf);
void RBUF_Format(RBUF_HandleTypeDef *rbuf);
bool RBUF_Push(RBUF_HandleTypeDef *rbuf, const void *data);
bool RBUF_PushN(RBUF_HandleTypeDef *rbuf, const void *data, uint32_t num);
bool RBUF_Pop(RBUF_HandleTypeDef *rbuf, void *data);
bool RBUF_PopN(RBUF_HandleTypeDef *rbuf, void *data, uint32_t num);
#ifdef __cplusplus
}
#endif
#endif