RingBuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2020, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef ti_drivers_utils_RingBuf__include
34 #define ti_drivers_utils_RingBuf__include
35 
36 #include <stdint.h>
37 #include <stddef.h>
38 #include <stdbool.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 typedef struct
45 {
46  unsigned char *buffer;
47  size_t length;
48  size_t count;
49  size_t head;
50  size_t tail;
51  size_t maxCount;
53 
65 void RingBuf_construct(RingBuf_Handle object, unsigned char *bufPtr, size_t bufSize);
66 
73 void RingBuf_flush(RingBuf_Handle object);
74 
89 int RingBuf_get(RingBuf_Handle object, unsigned char *data);
90 
104 int RingBuf_getConsume(RingBuf_Handle object, size_t size);
105 
115 int RingBuf_getCount(RingBuf_Handle object);
116 
124 int RingBuf_getMaxCount(RingBuf_Handle object);
125 
141 int RingBuf_getn(RingBuf_Handle object, unsigned char *data, size_t n);
142 
159 int RingBuf_getPointer(RingBuf_Handle object, unsigned char **data);
160 
169 bool RingBuf_isFull(RingBuf_Handle object);
170 
187 int RingBuf_peek(RingBuf_Handle object, unsigned char *data);
188 
201 int RingBuf_put(RingBuf_Handle object, unsigned char data);
202 
216 int RingBuf_putAdvance(RingBuf_Handle object, size_t size);
217 
232 int RingBuf_putn(RingBuf_Handle object, unsigned char *data, size_t n);
233 
249 int RingBuf_putPointer(RingBuf_Handle object, unsigned char **data);
250 
262 static inline size_t RingBuf_space(RingBuf_Handle object)
263 {
264  return (object->length - object->count);
265 }
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 
271 #endif /* ti_drivers_utils_RingBuf__include */
void RingBuf_construct(RingBuf_Handle object, unsigned char *bufPtr, size_t bufSize)
Initialize circular buffer.
int RingBuf_getn(RingBuf_Handle object, unsigned char *data, size_t n)
Get one or more unsigned chars from the end of the circular buffer and remove them.
int RingBuf_getPointer(RingBuf_Handle object, unsigned char **data)
Get a pointer reference to the next chunk of linear memory available for accessing data in the buffer...
void RingBuf_flush(RingBuf_Handle object)
Flush all the data from the buffer.
static size_t RingBuf_space(RingBuf_Handle object)
Return the number of unsigned characters that the buffer has space for. This function should normally...
Definition: RingBuf.h:262
unsigned char * buffer
Definition: RingBuf.h:46
int RingBuf_put(RingBuf_Handle object, unsigned char data)
Put an unsigned char into the end of the circular buffer.
struct RingBuf_Object * RingBuf_Handle
size_t tail
Definition: RingBuf.h:50
int RingBuf_peek(RingBuf_Handle object, unsigned char *data)
Get an unsigned char from the end of the circular buffer without removing it.
int RingBuf_getMaxCount(RingBuf_Handle object)
A high-water mark indicating the largest number of unsigned chars stored on the circular buffer since...
int RingBuf_get(RingBuf_Handle object, unsigned char *data)
Get an unsigned char from the end of the circular buffer and remove it.
size_t count
Definition: RingBuf.h:48
int RingBuf_getConsume(RingBuf_Handle object, size_t size)
Advance the get index and decrement the buffer count. This function should normally be called from a ...
int RingBuf_getCount(RingBuf_Handle object)
Get the number of unsigned chars currently stored on the circular buffer.
bool RingBuf_isFull(RingBuf_Handle object)
Function to determine if the circular buffer is full or not.
size_t head
Definition: RingBuf.h:49
size_t maxCount
Definition: RingBuf.h:51
int RingBuf_putAdvance(RingBuf_Handle object, size_t size)
Advance the committed put index and increment the buffer count. This function should normally be call...
Definition: RingBuf.h:44
int RingBuf_putn(RingBuf_Handle object, unsigned char *data, size_t n)
Put one or more unsigned chars into the end of the circular buffer.
int RingBuf_putPointer(RingBuf_Handle object, unsigned char **data)
Get a pointer reference to the next chunk of linear memory available for adding data to the buffer...
size_t length
Definition: RingBuf.h:47
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale