ubinos
cirbuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Sung Ho Park
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef UBICLIB_CIRBUF_H_
8 #define UBICLIB_CIRBUF_H_
9 
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14 
23 #include <ubinos_config.h>
24 #include <ubinos/type.h>
25 
27 #define CIRBUF_OPT__NOOVERWRITE 0x0001
28 
30 #define CIRBUF_OPT__MTPROTECTION 0x0002
31 
33 typedef struct _cirbuf_t
34 {
35  unsigned char * head;
36  unsigned char * tail;
37  unsigned int size;
39  unsigned int overflowcount :16;
41  unsigned int mtprotection :1;
42  unsigned int overwrite :1;
43  unsigned int reserved :14;
45  unsigned int maxsize;
46  unsigned char * buf;
48 
50 typedef cirbuf_t * cirbuf_pt;
51 
59 #define cirbuf_init(cirbuf, maxsize) \
60 { \
61  (cirbuf)->maxsize = maxsize; \
62  (cirbuf)->buf = (unsigned char *) ((unsigned int) cirbuf + sizeof(cirbuf_t)); \
63  \
64  (cirbuf)->head = (cirbuf)->buf; \
65  (cirbuf)->tail = (cirbuf)->buf; \
66  (cirbuf)->size = 0; \
67  \
68  (cirbuf)->overflowcount = 0; \
69  (cirbuf)->mtprotection = 0; \
70  (cirbuf)->overwrite = 0; \
71  (cirbuf)->reserved = 0; \
72 }
73 
86 int cirbuf_create(cirbuf_pt * cirbuf_p, unsigned int maxsize);
87 
103 int cirbuf_create_ext(cirbuf_pt * cirbuf_p, unsigned int maxsize,
104  unsigned int option);
105 
117 int cirbuf_delete(cirbuf_pt * cirbuf_p);
118 
135 int cirbuf_write(cirbuf_pt cirbuf, unsigned char * buf, unsigned int size,
136  unsigned int * written_p);
137 
154 int cirbuf_read(cirbuf_pt cirbuf, unsigned char * buf, unsigned int size,
155  unsigned int * read_p);
156 
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif /* UBICLIB_CIRBUF_H_ */
int cirbuf_create_ext(cirbuf_pt *cirbuf_p, unsigned int maxsize, unsigned int option)
int cirbuf_create(cirbuf_pt *cirbuf_p, unsigned int maxsize)
int cirbuf_read(cirbuf_pt cirbuf, unsigned char *buf, unsigned int size, unsigned int *read_p)
int cirbuf_clear(cirbuf_pt cirbuf)
cirbuf_t * cirbuf_pt
Definition: cirbuf.h:50
int cirbuf_write(cirbuf_pt cirbuf, unsigned char *buf, unsigned int size, unsigned int *written_p)
struct _cirbuf_t cirbuf_t
int cirbuf_delete(cirbuf_pt *cirbuf_p)
Definition: cirbuf.h:34
unsigned int mtprotection
Definition: cirbuf.h:41
unsigned int size
Definition: cirbuf.h:37
unsigned int maxsize
Definition: cirbuf.h:45
unsigned int overwrite
Definition: cirbuf.h:42
unsigned char * head
Definition: cirbuf.h:35
unsigned int overflowcount
Definition: cirbuf.h:39
unsigned int reserved
Definition: cirbuf.h:43
unsigned char * buf
Definition: cirbuf.h:46
unsigned char * tail
Definition: cirbuf.h:36
ubinos basic data type