StructRingBuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019, 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_StructRingBuf__include
34 #define ti_drivers_utils_StructRingBuf__include
35 
36 #include <stdint.h>
37 #include <stddef.h>
38 #include <stdbool.h>
39 #include <string.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 typedef struct {
46  uint8_t *buffer;
47  size_t length;
48  size_t count;
49  size_t head;
50  size_t tail;
51  size_t maxCount;
52  size_t structSize;
54 
68 void StructRingBuf_construct(StructRingBuf_Handle object, void *bufPtr,
69  size_t bufSize, size_t structSize);
70 
85 int StructRingBuf_get(StructRingBuf_Handle object, void *data);
86 
96 int StructRingBuf_getCount(StructRingBuf_Handle object);
97 
106 bool StructRingBuf_isFull(StructRingBuf_Handle object);
107 
115 int StructRingBuf_getMaxCount(StructRingBuf_Handle object);
116 
133 int StructRingBuf_peek(StructRingBuf_Handle object, void **data);
134 
146 int StructRingBuf_put(StructRingBuf_Handle object, const void *data);
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 
152 #endif /* ti_drivers_utils_StructRingBuf__include */
size_t maxCount
Definition: StructRingBuf.h:51
void StructRingBuf_construct(StructRingBuf_Handle object, void *bufPtr, size_t bufSize, size_t structSize)
Initialize circular buffer.
int StructRingBuf_put(StructRingBuf_Handle object, const void *data)
Put an unsigned char into the end of the circular buffer.
bool StructRingBuf_isFull(StructRingBuf_Handle object)
Function to determine if the circular buffer is full or not.
int StructRingBuf_getCount(StructRingBuf_Handle object)
Get the number of unsigned chars currently stored on the circular buffer.
size_t length
Definition: StructRingBuf.h:47
uint8_t * buffer
Definition: StructRingBuf.h:46
Definition: StructRingBuf.h:45
int StructRingBuf_peek(StructRingBuf_Handle object, void **data)
Get an unsigned char from the end of the circular buffer without remove it.
size_t structSize
Definition: StructRingBuf.h:52
size_t head
Definition: StructRingBuf.h:49
struct StructRingBuf_Object * StructRingBuf_Handle
int StructRingBuf_getMaxCount(StructRingBuf_Handle object)
A high-water mark indicating the largest number of unsigned chars stored on the circular buffer since...
size_t tail
Definition: StructRingBuf.h:50
int StructRingBuf_get(StructRingBuf_Handle object, void *data)
Get an unsigned char from the end of the circular buffer and remove it.
size_t count
Definition: StructRingBuf.h:48
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale