![]() |
kBuffer
1.1
|
A universal ringbuffer library. More...
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | buffer_t |
Struct for buffer handling. If you need a ringbuffer in your software, you should instantiate a buffer_t, and run the neccessary functions with a pointer to your instance. More... | |
Macros | |
#define | bufferDatatype uint16_t |
The datatype of one buffer element. As default, it is an 16 bit unsigned integer. Feel free to change it to your needs. | |
#define | BUFFER_ENABLE_MEAN |
Enables mean/ averaging functions. If you uncomment this define, the following functions will be compiled. Only enable it, if bufferDatatype is some sort of numeric datatype (integer, float, ...) bufferMean(); bufferMeanRMS(); | |
Enumerations | |
enum | bufferStatus_t { bufferOK = 0, bufferMemoryAllocationFailed, bufferEmpty, bufferFull, bufferNotInitialized, bufferError } |
buffer function return codes More... | |
Functions | |
bufferStatus_t | bufferInit (buffer_t *buffer, uint16_t bufferSize) |
init a new buffer This function inits a new buffer_t. More... | |
bufferStatus_t | bufferInitStatic (buffer_t *buffer, uint16_t bufferSize, bufferDatatype *bufferArray) |
init a new buffer This function inits a new buffer_t, but doesn't allocate the memory dynamically You've to provide an array of the datatype and the required length when calling this function. This function might be useful, if you want to save the overhead of the malloc() function More... | |
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 More... | |
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 More... | |
uint8_t | bufferIsEmpty (buffer_t *buffer) |
Checks, wheter the buffer is empty. More... | |
uint8_t | bufferIsFull (buffer_t *buffer) |
Checks, wheter the buffer is full. More... | |
bufferStatus_t | bufferWrite (buffer_t *buffer, bufferDatatype data) |
add data to the end of the ringbuffer More... | |
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. More... | |
bufferStatus_t | bufferRead (buffer_t *buffer, bufferDatatype *data) |
read data from the beginning of the buffer More... | |
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 More... | |
bufferStatus_t | bufferFill (buffer_t *buffer, bufferDatatype data, uint8_t silent) |
fill the whole buffer with given dummy data. More... | |
bufferStatus_t | bufferAvailable (buffer_t *buffer, uint16_t *available) |
return, how many elements are stored and available in the buffer More... | |
bufferStatus_t | bufferMean (buffer_t *buffer, bufferDatatype *meanOut) |
take the average of the whole buffer More... | |
bufferStatus_t | bufferMeanRMS (buffer_t *buffer, bufferDatatype *meanOut) |
take the root mean square of the whole buffer More... | |
A universal ringbuffer library.
enum bufferStatus_t |
buffer function return codes
bufferStatus_t bufferAvailable | ( | buffer_t * | buffer, |
uint16_t * | available | ||
) |
return, how many elements are stored and available in the buffer
buffer | pointer to a buffer_t instance |
available | pointer to a variable where the number of available elements should be stored |
bufferOK | it worked as expected |
bufferNotInitialized | the buffer wasn't initialized |
bufferStatus_t bufferFill | ( | buffer_t * | buffer, |
bufferDatatype | data, | ||
uint8_t | silent | ||
) |
fill the whole buffer with given dummy data.
buffer | pointer buffer_t instance |
data | data to fill the buffer with |
silent | if this parameter is 1, the buffer will be filled with data, but the write pointer stays at its current position (usefull, if you take the mean but the buffer is not full yet. You can just prefill it, the mean will be taken with the prefilled values) |
bufferOK | it worked as expected |
bufferNotInitialized | the buffer wasn't initialized |
bufferStatus_t bufferInit | ( | buffer_t * | buffer, |
uint16_t | bufferSize | ||
) |
init a new buffer This function inits a new buffer_t.
buffer | Pointer (&) to a buffer_t object. |
bufferSize | desired size of the buffer, the total buffer size (e.g. length-of-datatype * bufferSize) may not exceed 2^16 bytes |
bufferMemoryAllocationFailed | The memory allocation with malloc failed. Make sure, you have enough memory available |
bufferOK | It seems, like everything went well |
bufferStatus_t bufferInitStatic | ( | buffer_t * | buffer, |
uint16_t | bufferSize, | ||
bufferDatatype * | bufferArray | ||
) |
init a new buffer This function inits a new buffer_t, but doesn't allocate the memory dynamically
You've to provide an array of the datatype and the required length when calling this function.
This function might be useful, if you want to save the overhead of the malloc() function
buffer | Pointer (&) to a buffer_t object. |
bufferSize | desired size of the buffer, the total buffer size (e.g. length-of-datatype * bufferSize) may not exceed 2^16 bytes |
bufferArray | pointer to a array of the type bufferDatatype, which is bufferSize elements long |
bufferOK | It seems, like everything went well |
uint8_t bufferIsEmpty | ( | buffer_t * | buffer | ) |
Checks, wheter the buffer is empty.
buffer | Pointer to a buffer_t instance |
1 | buffer is empty |
0 | buffer is not empty |
uint8_t bufferIsFull | ( | buffer_t * | buffer | ) |
Checks, wheter the buffer is full.
buffer | Pointer to a buffer_t instance |
1 | buffer is full |
0 | buffer is not full |
bufferStatus_t bufferMean | ( | buffer_t * | buffer, |
bufferDatatype * | meanOut | ||
) |
take the average of the whole buffer
buffer | pointer to a buffer_t instance |
meanOut | pointer to a variable, where the mean will be stored |
bufferOK | it worked as expected, the mean is stored at the given variable |
bufferNotInitialized | the buffer is not initialized |
bufferStatus_t bufferMeanRMS | ( | buffer_t * | buffer, |
bufferDatatype * | meanOut | ||
) |
take the root mean square of the whole buffer
buffer | pointer to a buffer_t instance |
meanOut | pointer to a variable, where the mean will be stored |
bufferOK | it worked as expected, the mean is stored at the given variable |
bufferNotInitialized | the buffer is not initialized |
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
buffer | pointer to a buffer_t instance |
data | pointer to a variable where data should be stored |
bufferOK | it worked as expected |
bufferNotInitialized | the bufferInit() method hasn't been called or failed before |
bufferEmpty | the buffer is empty an no more data can be read |
bufferStatus_t bufferRead | ( | buffer_t * | buffer, |
bufferDatatype * | data | ||
) |
read data from the beginning of the buffer
buffer | pointer to a buffer_t instance |
data | pointer to a variable where data should be stored |
bufferOK | it worked as expected |
bufferNotInitialized | the bufferInit() method hasn't been called or failed before |
bufferEmpty | the buffer is empty an no more data can be read |
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
buffer | Pointer to a buffer_t instance |
index | The index, where data should be written. It can be in range 0 to length - 1 |
data | Pointer to a variable where the read data should be written to. |
bufferOK | It went successfull |
bufferNotInitialized | The buffer is not initialized. You have to call bufferInit before (or the init failed before) |
bufferError | The desired data index is out of range |
bufferStatus_t bufferWrite | ( | buffer_t * | buffer, |
bufferDatatype | data | ||
) |
add data to the end of the ringbuffer
buffer | pointer to a buffer_t instance |
data | data which should be written |
bufferOK | it worked as expected |
bufferNotInitialized | the bufferInit() method hasn't been called or failed before |
bufferFull | the buffer is full an no more data can be written |
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.
buffer | pointer to a buffer_t instance |
data | data which should be written |
bufferOK | it worked as expected |
bufferNotInitialized | the bufferInit() method hasn't been called or failed before |
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
buffer | Pointer to a buffer_t instance |
index | The index, where data should be written. It can be in range 0 to length - 1 |
data | The actual data which should be written |
bufferOK | It went successfull |
bufferNotInitialized | The buffer is not initialized. You have to call bufferInit before (or the init failed before) |
bufferError | The desired data index is out of range |