ubinos
cirbuf.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Sung Ho Park
3  Contact: ubinos.org@gmail.com
4 
5  This file is part of the itf_ubinos component of the Ubinos.
6 
7  GNU General Public License Usage
8  This file may be used under the terms of the GNU
9  General Public License version 3.0 as published by the Free Software
10  Foundation and appearing in the file license_gpl3.txt included in the
11  packaging of this file. Please review the following information to
12  ensure the GNU General Public License version 3.0 requirements will be
13  met: http://www.gnu.org/copyleft/gpl.html.
14 
15  GNU Lesser General Public License Usage
16  Alternatively, this file may be used under the terms of the GNU Lesser
17  General Public License version 2.1 as published by the Free Software
18  Foundation and appearing in the file license_lgpl.txt included in the
19  packaging of this file. Please review the following information to
20  ensure the GNU Lesser General Public License version 2.1 requirements
21  will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 
23  Commercial Usage
24  Alternatively, licensees holding valid commercial licenses may
25  use this file in accordance with the commercial license agreement
26  provided with the software or, alternatively, in accordance with the
27  terms contained in a written agreement between you and rightful owner.
28  */
29 
30 #ifndef UBICLIB_CIRBUF_H_
31 #define UBICLIB_CIRBUF_H_
32 
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
46 #include <ubinos_config.h>
47 #include <ubinos/type.h>
48 
50 #define CIRBUF_OPT__NOOVERWRITE 0x0001
51 
53 #define CIRBUF_OPT__MTPROTECTION 0x0002
54 
56 typedef struct _cirbuf_t
57 {
58  unsigned char * head;
59  unsigned char * tail;
60  unsigned int size;
62  unsigned int overflowcount :16;
64  unsigned int mtprotection :1;
65  unsigned int overwrite :1;
66  unsigned int reserved :14;
68  unsigned int maxsize;
69  unsigned char * buf;
70 } cirbuf_t;
71 
73 typedef cirbuf_t * cirbuf_pt;
74 
82 #define cirbuf_init(cirbuf, maxsize) \
83 { \
84  (cirbuf)->maxsize = maxsize; \
85  (cirbuf)->buf = (unsigned char *) ((unsigned int) cirbuf + sizeof(cirbuf_t)); \
86  \
87  (cirbuf)->head = (cirbuf)->buf; \
88  (cirbuf)->tail = (cirbuf)->buf; \
89  (cirbuf)->size = 0; \
90  \
91  (cirbuf)->overflowcount = 0; \
92  (cirbuf)->mtprotection = 0; \
93  (cirbuf)->overwrite = 0; \
94  (cirbuf)->reserved = 0; \
95 }
96 
109 int cirbuf_create(cirbuf_pt * cirbuf_p, unsigned int maxsize);
110 
126 int cirbuf_create_ext(cirbuf_pt * cirbuf_p, unsigned int maxsize,
127  unsigned int option);
128 
140 int cirbuf_delete(cirbuf_pt * cirbuf_p);
141 
158 int cirbuf_write(cirbuf_pt cirbuf, unsigned char * buf, unsigned int size,
159  unsigned int * written_p);
160 
177 int cirbuf_read(cirbuf_pt cirbuf, unsigned char * buf, unsigned int size,
178  unsigned int * read_p);
179 
190 int cirbuf_clear(cirbuf_pt cirbuf);
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif /* UBICLIB_CIRBUF_H_ */
_cirbuf_t::head
unsigned char * head
Definition: cirbuf.h:58
cirbuf_delete
int cirbuf_delete(cirbuf_pt *cirbuf_p)
_cirbuf_t::size
unsigned int size
Definition: cirbuf.h:60
cirbuf_create
int cirbuf_create(cirbuf_pt *cirbuf_p, unsigned int maxsize)
_cirbuf_t::tail
unsigned char * tail
Definition: cirbuf.h:59
cirbuf_clear
int cirbuf_clear(cirbuf_pt cirbuf)
cirbuf_read
int cirbuf_read(cirbuf_pt cirbuf, unsigned char *buf, unsigned int size, unsigned int *read_p)
type.h
ubinos basic data type
cirbuf_pt
cirbuf_t * cirbuf_pt
Definition: cirbuf.h:73
_cirbuf_t::overflowcount
unsigned int overflowcount
Definition: cirbuf.h:62
_cirbuf_t::reserved
unsigned int reserved
Definition: cirbuf.h:66
_cirbuf_t::mtprotection
unsigned int mtprotection
Definition: cirbuf.h:64
cirbuf_create_ext
int cirbuf_create_ext(cirbuf_pt *cirbuf_p, unsigned int maxsize, unsigned int option)
_cirbuf_t
Definition: cirbuf.h:56
cirbuf_write
int cirbuf_write(cirbuf_pt cirbuf, unsigned char *buf, unsigned int size, unsigned int *written_p)
cirbuf_t
struct _cirbuf_t cirbuf_t
_cirbuf_t::overwrite
unsigned int overwrite
Definition: cirbuf.h:65
_cirbuf_t::maxsize
unsigned int maxsize
Definition: cirbuf.h:68
_cirbuf_t::buf
unsigned char * buf
Definition: cirbuf.h:69