ubinos
cbuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Sung Ho Park and CSOS
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef UBICLIB_CBUF_H_
8 #define UBICLIB_CBUF_H_
9 
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14 
23 #include <ubinos_config.h>
24 #include <ubinos/type.h>
25 
27 typedef struct _cbuf_t
28 {
29  uint32_t head;
30  uint32_t tail;
31  uint32_t size;
32  uint8_t * buf;
34 
36 typedef cbuf_t * cbuf_pt;
37 
45 #define cbuf_def_init(_name, _size) \
46  uint8_t _name##_cbuf_buf[_size]; \
47  cbuf_t _name##_cbuf = { \
48  .head = 0, \
49  .tail = 0, \
50  .size = _size, \
51  .buf = _name##_cbuf_buf, \
52  }; \
53  cbuf_pt _name = &_name##_cbuf;
54 
64 ubi_st_t cbuf_create(cbuf_pt * cbuf_p, uint32_t size);
65 
75 
89 ubi_st_t cbuf_write(cbuf_pt cbuf, const uint8_t * buf, uint32_t len, uint32_t * written_p);
90 
104 ubi_st_t cbuf_read(cbuf_pt cbuf, uint8_t * buf, uint32_t len, uint32_t * read_p);
105 
119 ubi_st_t cbuf_view(cbuf_pt cbuf, uint8_t * buf, uint32_t len, uint32_t * read_p);
120 
129 
137 uint32_t cbuf_get_len(cbuf_pt cbuf);
138 
147 
155 uint8_t cbuf_is_full(cbuf_pt cbuf);
156 
164 uint8_t * cbuf_get_head_addr(cbuf_pt cbuf);
165 
173 uint8_t * cbuf_get_tail_addr(cbuf_pt cbuf);
174 
183 
192 
202 uint8_t cbuf_align_head(cbuf_pt cbuf, uint8_t align);
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 
208 #endif /* UBICLIB_CBUF_H_ */
209 
uint8_t cbuf_align_head(cbuf_pt cbuf, uint8_t align)
uint32_t cbuf_get_empty_len(cbuf_pt cbuf)
ubi_st_t cbuf_delete(cbuf_pt *cbuf_p)
ubi_st_t cbuf_view(cbuf_pt cbuf, uint8_t *buf, uint32_t len, uint32_t *read_p)
uint8_t * cbuf_get_tail_addr(cbuf_pt cbuf)
cbuf_t * cbuf_pt
Definition: cbuf.h:36
ubi_st_t cbuf_create(cbuf_pt *cbuf_p, uint32_t size)
uint32_t cbuf_get_len(cbuf_pt cbuf)
uint8_t * cbuf_get_head_addr(cbuf_pt cbuf)
struct _cbuf_t cbuf_t
ubi_st_t cbuf_clear(cbuf_pt cbuf)
ubi_st_t cbuf_read(cbuf_pt cbuf, uint8_t *buf, uint32_t len, uint32_t *read_p)
uint32_t cbuf_get_contig_empty_len(cbuf_pt cbuf)
uint32_t cbuf_get_contig_len(cbuf_pt cbuf)
ubi_st_t cbuf_write(cbuf_pt cbuf, const uint8_t *buf, uint32_t len, uint32_t *written_p)
uint8_t cbuf_is_full(cbuf_pt cbuf)
Definition: cbuf.h:28
uint32_t head
Definition: cbuf.h:29
uint32_t size
Definition: cbuf.h:31
uint32_t tail
Definition: cbuf.h:30
uint8_t * buf
Definition: cbuf.h:32
ubinos basic data type
ubi_st_t
Definition: type.h:140