master
adragott 5 years ago
parent 3b75d1609b
commit e91fc41591

@ -1,9 +1,7 @@
CC=gcc CC=gcc
CFLAGS=-std=c99 -Wall -Wextra CFLAGS=-std=c99 -Wall -Wextra
#-Werror -Wshadow -Wdouble-promotion \
-Wformat=2 -Wformat-truncation -fno-common -fstack-usage -Wconversion -Os \
-Werror=unused-function
BIN=./bin BIN=./bin
SRC=./src SRC=./src

Binary file not shown.

@ -34,6 +34,7 @@
*/ */
#include <stdio.h>
int main() int main()
{ {

@ -4,7 +4,7 @@
Penguin's Circular Buffer -- a simple floating queue designed for low memory usage (mainly for embedded) Penguin's Circular Buffer -- a simple floating queue designed for low memory usage (mainly for embedded)
This is a ring buffer with limited capabilities. It is meant as a container for moving data. This is a ring buffer with limited capabilities. It is meant as a container for moving data.
Normally included features such checks to see if the buffer is full or empty have been omitted Normally included features such as checks to see if the buffer is full or empty have been omitted
because this type of buffer is being implemented mainly for sensor data usage. Data is almost never read individually, because this type of buffer is being implemented mainly for sensor data usage. Data is almost never read individually,
and even if it is, it isn't meant to be cleared on read. It is a simple moving buffer that automatically and even if it is, it isn't meant to be cleared on read. It is a simple moving buffer that automatically
writes over old data for the purpose of keeping track of the most up to date data. writes over old data for the purpose of keeping track of the most up to date data.
@ -29,10 +29,11 @@
#ifndef _PCIRCULARBUFFER_H_ #ifndef _PCIRCULARBUFFER_H_
#define _PCIRCULARBUFFER_H_ #define _PCIRCULARBUFFER_H_
#include <inttypes.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
// comment this out for release builds // comment this out for release builds
#define PB_CB_DEBUG //#define PB_CB_DEBUG
// Making these PB_EN/DIS rather than just ENABLE/DISABLE because // Making these PB_EN/DIS rather than just ENABLE/DISABLE because
// some enable/disable definition might already exist that is // some enable/disable definition might already exist that is
@ -54,12 +55,12 @@
// Disable or Enable types needed here // Disable or Enable types needed here
// We can save code size this way // We can save code size this way
// While there are better ways to do this, this is the most accessible for anyone imo // While there are better ways to do this, this is the most accessible for anyone imo
#define PB_CB_FLOAT PB_ENABLE #define PB_CB_FLOAT PB_DISABLE
#define PB_CB_DOUBLE PB_ENABLE #define PB_CB_DOUBLE PB_ENABLE
#define PB_CB_U8 PB_ENABLE #define PB_CB_U8 PB_DISABLE
#define PB_CB_U16 PB_ENABLE #define PB_CB_U16 PB_DISABLE
#define PB_CB_U32 PB_ENABLE #define PB_CB_U32 PB_DISABLE
#define PB_CB_U64 PB_ENABLE #define PB_CB_U64 PB_DISABLE
#define PB_CB_I8 PB_DISABLE #define PB_CB_I8 PB_DISABLE
#define PB_CB_I16 PB_DISABLE #define PB_CB_I16 PB_DISABLE
#define PB_CB_I32 PB_DISABLE #define PB_CB_I32 PB_DISABLE
@ -73,7 +74,7 @@ typedef enum PB_CB_STATUS
PB_CB_NULL_BUFFER = 3, PB_CB_NULL_BUFFER = 3,
PB_CB_NULL_CBUFFER = 4 PB_CB_NULL_CBUFFER = 4
}PB_CB_STATUS; }PB_CB_STATUS;
#if PB_CB_U8 #if PB_CB_U8
typedef struct p_cb_u8 typedef struct p_cb_u8

@ -16,80 +16,60 @@ static void handle_status(const char* func, PB_CB_STATUS status_code)
#if PB_CB_U8 #if PB_CB_U8
static PB_CB_STATUS p_cb_u8_push(p_cb_double* cbuffer, uint8_t value); static PB_CB_STATUS p_cb_u8_push(p_cb_double* cbuffer, uint8_t value);
static PB_CB_STATUS p_cb_u8_empty(p_cb_double* cbuffer); static PB_CB_STATUS p_cb_u8_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u8_is_full(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u8_is_empty(p_cb_double* cbuffer);
#endif #endif
// Circular Buffer Prototypes -- uint16_t // Circular Buffer Prototypes -- uint16_t
#if PB_CB_U16 #if PB_CB_U16
static PB_CB_STATUS p_cb_u16_push(p_cb_double* cbuffer, uint16_t value); static PB_CB_STATUS p_cb_u16_push(p_cb_double* cbuffer, uint16_t value);
static PB_CB_STATUS p_cb_u16_empty(p_cb_double* cbuffer); static PB_CB_STATUS p_cb_u16_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u16_is_full(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u16_is_empty(p_cb_double* cbuffer);
#endif #endif
// Circular Buffer Prototypes -- uint32_t // Circular Buffer Prototypes -- uint32_t
#if PB_CB_U32 #if PB_CB_U32
static PB_CB_STATUS p_cb_u32_push(p_cb_double* cbuffer, uint32_t value); static PB_CB_STATUS p_cb_u32_push(p_cb_double* cbuffer, uint32_t value);
static PB_CB_STATUS p_cb_u32_empty(p_cb_double* cbuffer); static PB_CB_STATUS p_cb_u32_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u32_is_full(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u32_is_empty(p_cb_double* cbuffer);
#endif #endif
// Circular Buffer Prototypes -- uint64_t // Circular Buffer Prototypes -- uint64_t
#if PB_CB_U64 #if PB_CB_U64
static PB_CB_STATUS p_cb_u64_push(p_cb_double* cbuffer, uint64_t value); static PB_CB_STATUS p_cb_u64_push(p_cb_double* cbuffer, uint64_t value);
static PB_CB_STATUS p_cb_u64_empty(p_cb_double* cbuffer); static PB_CB_STATUS p_cb_u64_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u64_is_full(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u64_is_empty(p_cb_double* cbuffer);
#endif #endif
// Circular Buffer Prototypes -- int8_t // Circular Buffer Prototypes -- int8_t
#if PB_CB_I8 #if PB_CB_I8
static PB_CB_STATUS p_cb_i8_push(p_cb_double* cbuffer, int8_t value); static PB_CB_STATUS p_cb_i8_push(p_cb_double* cbuffer, int8_t value);
static PB_CB_STATUS p_cb_i8_empty(p_cb_double* cbuffer); static PB_CB_STATUS p_cb_i8_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i8_is_full(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i8_is_empty(p_cb_double* cbuffer);
#endif #endif
// Circular Buffer Prototypes -- int16_t // Circular Buffer Prototypes -- int16_t
#if PB_CB_I16 #if PB_CB_I16
static PB_CB_STATUS p_cb_i16_push(p_cb_double* cbuffer, int16_t value); static PB_CB_STATUS p_cb_i16_push(p_cb_double* cbuffer, int16_t value);
static PB_CB_STATUS p_cb_i16_empty(p_cb_double* cbuffer); static PB_CB_STATUS p_cb_i16_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i16_is_full(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i16_is_empty(p_cb_double* cbuffer);
#endif #endif
// Circular Buffer Prototypes -- int32_t // Circular Buffer Prototypes -- int32_t
#if PB_CB_I32 #if PB_CB_I32
static PB_CB_STATUS p_cb_i32_push(p_cb_double* cbuffer, int32_t value); static PB_CB_STATUS p_cb_i32_push(p_cb_double* cbuffer, int32_t value);
static PB_CB_STATUS p_cb_i32_empty(p_cb_double* cbuffer); static PB_CB_STATUS p_cb_i32_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i32_is_full(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i32_is_empty(p_cb_double* cbuffer);
#endif #endif
// Circular Buffer Prototypes -- int64_t // Circular Buffer Prototypes -- int64_t
#if PB_CB_I64 #if PB_CB_I64
static PB_CB_STATUS p_cb_i64_push(p_cb_double* cbuffer, int64_t value); static PB_CB_STATUS p_cb_i64_push(p_cb_double* cbuffer, int64_t value);
static PB_CB_STATUS p_cb_i64_empty(p_cb_double* cbuffer); static PB_CB_STATUS p_cb_i64_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i64_is_full(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i64_is_empty(p_cb_double* cbuffer);
#endif #endif
// Circular Buffer Prototypes -- Float // Circular Buffer Prototypes -- Float
#if PB_CB_FLOAT #if PB_CB_FLOAT
static PB_CB_STATUS p_cb_float_push(p_cb_double* cbuffer, float value); static PB_CB_STATUS p_cb_float_push(p_cb_double* cbuffer, float value);
static PB_CB_STATUS p_cb_float_empty(p_cb_double* cbuffer); static PB_CB_STATUS p_cb_float_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_float_is_full(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_float_is_empty(p_cb_double* cbuffer);
#endif #endif
// Circular Buffer Prototypes -- Double // Circular Buffer Prototypes -- Double
#if PB_CB_DOUBLE #if PB_CB_DOUBLE
static PB_CB_STATUS p_cb_double_push(p_cb_double* cbuffer, double value); static PB_CB_STATUS p_cb_double_push(p_cb_double* cbuffer, double value);
static PB_CB_STATUS p_cb_double_empty(p_cb_double* cbuffer); static PB_CB_STATUS p_cb_double_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_double_is_full(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_double_is_empty(p_cb_double* cbuffer);
#endif #endif
// Circular Buffer Definitions -- uint8_t // Circular Buffer Definitions -- uint8_t
@ -354,7 +334,6 @@ PB_CB_STATUS p_cb_double_init(p_cb_double* circ_buffer, double* buff, uint32_t m
ret = PB_CB_BAD_BUFFER_SIZE; ret = PB_CB_BAD_BUFFER_SIZE;
break; break;
} }
printf("init\r\n");
circ_buffer->buffer = buff; circ_buffer->buffer = buff;
circ_buffer->max_len = (uint16_t)max_length; circ_buffer->max_len = (uint16_t)max_length;
circ_buffer->head = 0; circ_buffer->head = 0;

@ -1,5 +1,4 @@
#include <stdio.h> #include <stdio.h>
#include <inttypes.h>
#include <PCircularBuffer.h> #include <PCircularBuffer.h>
int main() int main()
{ {

Loading…
Cancel
Save