kBuffer  1.1
kBuffer.h
Go to the documentation of this file.
1 
9 #ifndef KBUFFER_H
10 #define KBUFFER_H
11 
12 #ifdef __cplusplus
13 extern "C"{
14 #endif
15 
16 #include <stdint.h>
17 
22 #ifndef bufferDatatype
23  #define bufferDatatype uint16_t
24 #endif
25 
33 #define BUFFER_ENABLE_MEAN
34 
39 typedef struct{
41  uint8_t isInitialized;
43  uint16_t writePointer;
45  uint16_t readPointer;
47  uint16_t length;
49  uint8_t elementLength;
51  uint16_t datacount;
54 }buffer_t;
55 
60 typedef enum{
62  bufferOK = 0,
74 
75 
76 //Function declearations
77 
78 bufferStatus_t bufferInit(buffer_t* buffer, uint16_t bufferSize);
79 bufferStatus_t bufferInitStatic(buffer_t* buffer, uint16_t bufferSize, bufferDatatype* bufferArray);
80 bufferStatus_t bufferWriteToIndex(buffer_t* buffer, uint16_t index, bufferDatatype data);
81 bufferStatus_t bufferReadFromIndex(buffer_t* buffer, uint16_t index, bufferDatatype* data);
82 uint8_t bufferIsEmpty(buffer_t* buffer);
83 uint8_t bufferIsFull(buffer_t* buffer);
84 bufferStatus_t bufferWrite(buffer_t* buffer, bufferDatatype data);
85 bufferStatus_t bufferWriteOverwrite(buffer_t* buffer, bufferDatatype data);
86 bufferStatus_t bufferRead(buffer_t* buffer, bufferDatatype* data);
87 bufferStatus_t bufferPeek(buffer_t* buffer, bufferDatatype* data);
88 bufferStatus_t bufferFill(buffer_t* buffer, bufferDatatype data, uint8_t silent);
89 bufferStatus_t bufferAvailable(buffer_t* buffer, uint16_t* available);
90 
91 #ifdef BUFFER_ENABLE_MEAN
92 bufferStatus_t bufferMean(buffer_t* buffer, bufferDatatype* meanOut);
93 bufferStatus_t bufferMeanRMS(buffer_t* buffer, bufferDatatype* meanOut);
94 #endif
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif
Definition: kBuffer.h:68
uint16_t length
The number of elements in the buffer.
Definition: kBuffer.h:47
bufferStatus_t bufferAvailable(buffer_t *buffer, uint16_t *available)
return, how many elements are stored and available in the buffer
Definition: kBuffer.c:386
Definition: kBuffer.h:72
bufferDatatype * data
A pointer to the first element of the buffer. Length * elementLength bytes of memory are allocated af...
Definition: kBuffer.h:53
bufferStatus_t bufferFill(buffer_t *buffer, bufferDatatype data, uint8_t silent)
fill the whole buffer with given dummy data.
Definition: kBuffer.c:359
bufferStatus_t bufferMeanRMS(buffer_t *buffer, bufferDatatype *meanOut)
take the root mean square of the whole buffer
Definition: kBuffer.c:452
uint16_t readPointer
The read pointer of the buffer. At a read procedure, data gets read and the pointer is incremented...
Definition: kBuffer.h:45
bufferStatus_t bufferMean(buffer_t *buffer, bufferDatatype *meanOut)
take the average of the whole buffer
Definition: kBuffer.c:424
bufferStatus_t bufferWrite(buffer_t *buffer, bufferDatatype data)
add data to the end of the ringbuffer
Definition: kBuffer.c:286
uint8_t isInitialized
is 0 if the buffer is not initialized
Definition: kBuffer.h:41
bufferStatus_t bufferPeek(buffer_t *buffer, bufferDatatype *data)
have a look at the next element in the buffer, but do not increase the read pointer ...
Definition: kBuffer.c:404
Struct for buffer handling. If you need a ringbuffer in your software, you should instantiate a buffe...
Definition: kBuffer.h:39
bufferStatus_t bufferWriteOverwrite(buffer_t *buffer, bufferDatatype data)
Add data to the end of the ringbuffer. If the buffer is full, overwrite the first data...
Definition: kBuffer.c:309
bufferStatus_t bufferReadFromIndex(buffer_t *buffer, uint16_t index, bufferDatatype *data)
read data from a specifig index of the buffer WARNING: Take care when using this function, it is against the main concept of a ringbuffer
Definition: kBuffer.c:236
uint16_t datacount
A variable which is increased by one when new data gets written and decremented by one when data is r...
Definition: kBuffer.h:51
bufferStatus_t bufferInit(buffer_t *buffer, uint16_t bufferSize)
init a new buffer This function inits a new buffer_t.
Definition: kBuffer.c:158
bufferStatus_t bufferRead(buffer_t *buffer, bufferDatatype *data)
read data from the beginning of the buffer
Definition: kBuffer.c:335
Definition: kBuffer.h:64
uint8_t elementLength
The number of bytes of one buffer element. The total memory consumption in Bytes is equal to length *...
Definition: kBuffer.h:49
Definition: kBuffer.h:70
uint16_t writePointer
The write pointer of the buffer. At a write procedure, data gets written and the pointer is increment...
Definition: kBuffer.h:43
bufferStatus_t
buffer function return codes
Definition: kBuffer.h:60
bufferStatus_t bufferInitStatic(buffer_t *buffer, uint16_t bufferSize, bufferDatatype *bufferArray)
init a new buffer This function inits a new buffer_t, but doesn&#39;t allocate the memory dynamically Yo...
Definition: kBuffer.c:187
Definition: kBuffer.h:66
uint8_t bufferIsEmpty(buffer_t *buffer)
Checks, wheter the buffer is empty.
Definition: kBuffer.c:255
bufferStatus_t bufferWriteToIndex(buffer_t *buffer, uint16_t index, bufferDatatype data)
write data to a specific index of the buffer. WARNING: Take care when using this function, it is against the main concept of a ringbuffer
Definition: kBuffer.c:212
uint8_t bufferIsFull(buffer_t *buffer)
Checks, wheter the buffer is full.
Definition: kBuffer.c:269
Definition: kBuffer.h:62
#define bufferDatatype
The datatype of one buffer element. As default, it is an 16 bit unsigned integer. Feel free to change...
Definition: kBuffer.h:23