RingBuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-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_uart_RingBuf__include
34 #define ti_drivers_uart_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  unsigned char *buffer;
46  size_t length;
47  size_t count;
48  size_t head;
49  size_t tail;
50  size_t maxCount;
52 
64 void RingBuf_construct(RingBuf_Handle object, unsigned char *bufPtr,
65  size_t bufSize);
66 
81 int RingBuf_get(RingBuf_Handle object, unsigned char *data);
82 
92 int RingBuf_getCount(RingBuf_Handle object);
93 
102 bool RingBuf_isFull(RingBuf_Handle object);
103 
111 int RingBuf_getMaxCount(RingBuf_Handle object);
112 
129 int RingBuf_peek(RingBuf_Handle object, unsigned char *data);
130 
143 int RingBuf_put(RingBuf_Handle object, unsigned char data);
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif /* ti_drivers_uart_RingBuf__include */
void RingBuf_construct(RingBuf_Handle object, unsigned char *bufPtr, size_t bufSize)
Initialize circular buffer.
unsigned char * buffer
Definition: RingBuf.h:45
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:49
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:47
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:48
size_t maxCount
Definition: RingBuf.h:50
Definition: RingBuf.h:44
size_t length
Definition: RingBuf.h:46
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale