ring_buffer.h
Go to the documentation of this file.
1 /*
2  * ring_buffer.h
3  *
4  * Created on: May 5, 2011
5  * Author: waltj
6  */
7 
8 #ifndef _RING_BUFFER_H_
9 #define _RING_BUFFER_H_
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 
16 //_____ D E F I N I T I O N S ______________________________________________
17 
18 typedef struct
19 {
20  unsigned char *startPtr; // Pointer to buffer start (lowest address)
21  unsigned char *endPtr; // Pointer to one past buffer end (buffer start + sizeof(buf)).
22  unsigned char *rdPtr; // Buffer read pointer
23  unsigned char *wrPtr; // Buffer write pointer
24  int bufSize; // Byte size of buffer
25  int wordByteSize; // Byte size of a single element in the buffer
26 } ring_buf_t;
27 
28 
29 //_____ P R O T O T Y P E S ________________________________________________
30 
31 void ringBufInit(ring_buf_t *rbuf, unsigned char* buf, int bufSize, int wordSize);
32 int ringBufUsed(const ring_buf_t *rbuf);
33 int ringBufFree(const ring_buf_t *rbuf);
34 int ringBufWrite(ring_buf_t *rbuf, unsigned char *buf, int numBytes);
35 int ringBufRead(ring_buf_t *rbuf, unsigned char *buf, int len);
36 int ringBufPeek(const ring_buf_t *rbuf, unsigned char *buf, int len, int offset);
37 int ringBufReadToChar(ring_buf_t *rbuf, unsigned char *buf, int len, unsigned char character);
38 int ringBufReadToChar2(ring_buf_t *rbuf, unsigned char *buf, int len, unsigned char character1, unsigned char character2);
39 int ringBufFind(const ring_buf_t *rbuf, const unsigned char *str, int len);
40 int ringBufRemove(ring_buf_t *rbuf, int len);
41 int ringBufClear(ring_buf_t *rbuf);
42 int ringBufEmpty(const ring_buf_t *rbuf);
43 
44 
45 
46 #ifdef __cplusplus
47 }
48 #endif
49 
50 #endif // _RING_BUFFER_H_
void ringBufInit(ring_buf_t *rbuf, unsigned char *buf, int bufSize, int wordSize)
Initialize ring buffer pointers.
Definition: ring_buffer.c:29
int wordByteSize
Definition: ring_buffer.h:25
unsigned char * endPtr
Definition: ring_buffer.h:21
int ringBufReadToChar2(ring_buf_t *rbuf, unsigned char *buf, int len, unsigned char character1, unsigned char character2)
This function returns everything up to and including the first occurrence of a character. If the character is not found, then nothing (zero) is returned.
Definition: ring_buffer.c:306
unsigned char * startPtr
Definition: ring_buffer.h:20
int ringBufWrite(ring_buf_t *rbuf, unsigned char *buf, int numBytes)
This function writes data to the ring buffer.
Definition: ring_buffer.c:76
int ringBufPeek(const ring_buf_t *rbuf, unsigned char *buf, int len, int offset)
This function reads data from the ring buffer without removing any data. Same as ringBufPop without m...
Definition: ring_buffer.c:188
int ringBufRemove(ring_buf_t *rbuf, int len)
This function removes data from the ring buffer.
Definition: ring_buffer.c:432
int ringBufFind(const ring_buf_t *rbuf, const unsigned char *str, int len)
This function finds the index of the first matching string in the ring buffer. Returns -1 if not foun...
Definition: ring_buffer.c:387
int ringBufRead(ring_buf_t *rbuf, unsigned char *buf, int len)
This function reads data from the ring buffer.
Definition: ring_buffer.c:136
int ringBufReadToChar(ring_buf_t *rbuf, unsigned char *buf, int len, unsigned char character)
This function returns everything up to and including the first occurrence of a character. If the character is not found, then nothing (zero) is returned.
Definition: ring_buffer.c:288
int ringBufClear(ring_buf_t *rbuf)
Clear the entire buffer.
Definition: ring_buffer.c:467
int ringBufFree(const ring_buf_t *rbuf)
This function returns the number of bytes free in UART Rx buffer. Important: Buffer size is one less ...
Definition: ring_buffer.c:61
int ringBufUsed(const ring_buf_t *rbuf)
This function returns the number of bytes currently in ring buffer.
Definition: ring_buffer.c:43
int ringBufEmpty(const ring_buf_t *rbuf)
This function returns 1 if the buffer is empty, 0 if not empty.
Definition: ring_buffer.c:481
unsigned char * rdPtr
Definition: ring_buffer.h:22
unsigned char * wrPtr
Definition: ring_buffer.h:23


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58