|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
#include "putil.h"
|
|
|
|
|
#include <PCircularBuffer.h>
|
|
|
|
|
|
|
|
|
|
// Error handler used for debugging only
|
|
|
|
@ -7,73 +8,20 @@ static void handle_status(const char *func, PB_CB_STATUS status_code)
|
|
|
|
|
{
|
|
|
|
|
if (status_code != PB_CB_GOOD)
|
|
|
|
|
{
|
|
|
|
|
printf("%s failed: error code: %d\r\n", func, status_code);
|
|
|
|
|
PDEBUG("%s failed: error code: %d\r\n", func, status_code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Prototypes -- uint8_t
|
|
|
|
|
#if PB_CB_U8
|
|
|
|
|
static PB_CB_STATUS p_cb_u8_push(p_cb_u8 *cbuffer, uint8_t value);
|
|
|
|
|
static PB_CB_STATUS p_cb_u8_empty(p_cb_u8 *cbuffer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Prototypes -- uint16_t
|
|
|
|
|
#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_empty(p_cb_double *cbuffer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Prototypes -- uint32_t
|
|
|
|
|
#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_empty(p_cb_double *cbuffer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Prototypes -- uint64_t
|
|
|
|
|
#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_empty(p_cb_double *cbuffer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Prototypes -- int8_t
|
|
|
|
|
#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_empty(p_cb_double *cbuffer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Prototypes -- int16_t
|
|
|
|
|
#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_empty(p_cb_double *cbuffer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Prototypes -- int32_t
|
|
|
|
|
#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_empty(p_cb_double *cbuffer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Prototypes -- int64_t
|
|
|
|
|
#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_empty(p_cb_double *cbuffer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Prototypes -- 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_empty(p_cb_double *cbuffer);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Prototypes -- 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_empty(p_cb_double *cbuffer);
|
|
|
|
|
#endif
|
|
|
|
|
// serial_pkt
|
|
|
|
|
static PB_CB_STATUS p_cb_serial_pkt_push(p_cb_serial_pkt_t *cbuffer, serial_pkt_t value);
|
|
|
|
|
static PB_CB_STATUS p_cb_serial_pkt_empty(p_cb_serial_pkt_t *cbuffer);
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Definitions -- uint8_t
|
|
|
|
|
#if PB_CB_U8
|
|
|
|
|
PB_CB_STATUS p_cb_u8_init(p_cb_u8 *circ_buffer, uint8_t *buff, uint32_t max_length)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
@ -123,6 +71,7 @@ PB_CB_STATUS p_cb_u8_push(p_cb_u8 *cbuffer, uint8_t value)
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PB_CB_STATUS p_cb_u8_empty(p_cb_u8 *cbuffer)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
@ -153,214 +102,9 @@ PB_CB_STATUS p_cb_u8_empty(p_cb_u8 *cbuffer)
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
// Circular Buffer Definitions -- uint16_t
|
|
|
|
|
#if PB_CB_U16
|
|
|
|
|
PB_CB_STATUS p_cb_u16_init(p_cb_u16 *circ_buffer, uint16_t *buff, uint32_t max_length)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
// Make sure the buffer isn't bad (null)
|
|
|
|
|
if (!buff)
|
|
|
|
|
{
|
|
|
|
|
ret = PB_CB_NULL_BUFFER;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the max buffer is a useable size
|
|
|
|
|
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
|
|
|
|
|
{
|
|
|
|
|
ret = PB_CB_BAD_BUFFER_SIZE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PB_CB_STATUS p_cb_u16_push(p_cb_double *cbuffer, uint16_t value)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
PB_CB_STATUS p_cb_u16_empty(p_cb_double *cbuffer)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Definitions -- uint32_t
|
|
|
|
|
#if PB_CB_U32
|
|
|
|
|
PB_CB_STATUS p_cb_u32_init(p_cb_u32 *circ_buffer, uint32_t *buff, uint32_t max_length)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
// Make sure the buffer isn't bad (null)
|
|
|
|
|
if (!buff)
|
|
|
|
|
{
|
|
|
|
|
ret = PB_CB_NULL_BUFFER;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the max buffer is a useable size
|
|
|
|
|
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
|
|
|
|
|
{
|
|
|
|
|
ret = PB_CB_BAD_BUFFER_SIZE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
PB_CB_STATUS p_cb_u32_push(p_cb_double *cbuffer, uint32_t value)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
PB_CB_STATUS p_cb_u32_empty(p_cb_double *cbuffer)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Definitions -- uint64_t
|
|
|
|
|
#if PB_CB_U64
|
|
|
|
|
PB_CB_STATUS p_cb_u64_init(p_cb_u64 *circ_buffer, uint64_t *buff, uint32_t max_length)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
// Make sure the buffer isn't bad (null)
|
|
|
|
|
if (!buff)
|
|
|
|
|
{
|
|
|
|
|
ret = PB_CB_NULL_BUFFER;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the max buffer is a useable size
|
|
|
|
|
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
|
|
|
|
|
{
|
|
|
|
|
ret = PB_CB_BAD_BUFFER_SIZE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
PB_CB_STATUS p_cb_u64_push(p_cb_double *cbuffer, uint64_t value)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
PB_CB_STATUS p_cb_u64_empty(p_cb_double *cbuffer)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if PB_CB_FLOAT
|
|
|
|
|
PB_CB_STATUS p_cb_float_init(p_cb_float *circ_buffer, float *buff, uint32_t max_length)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
// Make sure the buffer isn't bad (null)
|
|
|
|
|
if (!buff)
|
|
|
|
|
{
|
|
|
|
|
ret = PB_CB_NULL_BUFFER;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the max buffer is a useable size
|
|
|
|
|
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
|
|
|
|
|
{
|
|
|
|
|
ret = PB_CB_BAD_BUFFER_SIZE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
PB_CB_STATUS p_cb_float_push(p_cb_double *cbuffer, float value)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
PB_CB_STATUS p_cb_float_empty(p_cb_double *cbuffer)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
// Debugging
|
|
|
|
|
#ifdef PB_CB_DEBUG
|
|
|
|
|
handle_status(__func__, ret);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Circular Buffer Definitions -- double
|
|
|
|
|
#if PB_CB_DOUBLE
|
|
|
|
|
PB_CB_STATUS p_cb_double_init(p_cb_double *circ_buffer, double *buff, uint32_t max_length)
|
|
|
|
|
// Circular Buffer Definitions -- uint8_t
|
|
|
|
|
PB_CB_STATUS p_cb_serial_pkt_init(p_cb_serial_pkt_t *inst, serial_pkt_t *buff, uint32_t max_length)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
do
|
|
|
|
@ -378,12 +122,6 @@ PB_CB_STATUS p_cb_double_init(p_cb_double *circ_buffer, double *buff, uint32_t m
|
|
|
|
|
ret = PB_CB_BAD_BUFFER_SIZE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
circ_buffer->buffer = buff;
|
|
|
|
|
circ_buffer->max_len = (uint16_t)max_length;
|
|
|
|
|
circ_buffer->head = 0;
|
|
|
|
|
circ_buffer->push = p_cb_double_push;
|
|
|
|
|
circ_buffer->empty = p_cb_double_empty;
|
|
|
|
|
circ_buffer->empty(circ_buffer);
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
// Debugging
|
|
|
|
@ -394,7 +132,7 @@ PB_CB_STATUS p_cb_double_init(p_cb_double *circ_buffer, double *buff, uint32_t m
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PB_CB_STATUS p_cb_double_push(p_cb_double *cbuffer, double value)
|
|
|
|
|
PB_CB_STATUS p_cb_serial_pkt_push(p_cb_serial_pkt_t *cbuffer, serial_pkt_t value)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
|
|
|
|
@ -415,7 +153,8 @@ PB_CB_STATUS p_cb_double_push(p_cb_double *cbuffer, double value)
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
PB_CB_STATUS p_cb_double_empty(p_cb_double *cbuffer)
|
|
|
|
|
|
|
|
|
|
PB_CB_STATUS p_cb_serial_pkt_empty(p_cb_serial_pkt_t *cbuffer)
|
|
|
|
|
{
|
|
|
|
|
PB_CB_STATUS ret = PB_CB_GOOD;
|
|
|
|
|
|
|
|
|
@ -432,7 +171,7 @@ PB_CB_STATUS p_cb_double_empty(p_cb_double *cbuffer)
|
|
|
|
|
ret = PB_CB_NULL_BUFFER;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
memset(cbuffer->buffer, 0, sizeof(double) * cbuffer->max_len);
|
|
|
|
|
memset(cbuffer->buffer, 0, sizeof(serial_pkt_t) * cbuffer->max_len);
|
|
|
|
|
cbuffer->head = 0;
|
|
|
|
|
cbuffer->b_empty = true;
|
|
|
|
|
cbuffer->b_filled = false;
|
|
|
|
@ -445,4 +184,3 @@ PB_CB_STATUS p_cb_double_empty(p_cb_double *cbuffer)
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|