Added volatile qualifier to ringbuffer library to be interrupt safe.
This commit is contained in:
@@ -46,8 +46,8 @@ struct ring_buffer_t {
|
|||||||
volatile uint8_t * buffer; /* block of memory or array of data */
|
volatile uint8_t * buffer; /* block of memory or array of data */
|
||||||
unsigned element_size; /* how many bytes for each chunk */
|
unsigned element_size; /* how many bytes for each chunk */
|
||||||
unsigned element_count; /* number of chunks of data */
|
unsigned element_count; /* number of chunks of data */
|
||||||
volatile unsigned head; /* where the writes go */
|
volatile unsigned head; /* where the writes go */
|
||||||
volatile unsigned tail; /* where the reads come from */
|
volatile unsigned tail; /* where the reads come from */
|
||||||
};
|
};
|
||||||
typedef struct ring_buffer_t RING_BUFFER;
|
typedef struct ring_buffer_t RING_BUFFER;
|
||||||
|
|
||||||
@@ -55,21 +55,21 @@ typedef struct ring_buffer_t RING_BUFFER;
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
unsigned Ringbuf_Count(
|
unsigned Ringbuf_Count (
|
||||||
RING_BUFFER const *b);
|
RING_BUFFER const *b);
|
||||||
bool Ringbuf_Full(
|
bool Ringbuf_Full (
|
||||||
RING_BUFFER const *b);
|
RING_BUFFER const *b);
|
||||||
bool Ringbuf_Empty(
|
bool Ringbuf_Empty(
|
||||||
RING_BUFFER const *b);
|
RING_BUFFER const *b);
|
||||||
uint8_t *Ringbuf_Get_Front(
|
volatile uint8_t *Ringbuf_Get_Front(
|
||||||
RING_BUFFER const *b);
|
RING_BUFFER const *b);
|
||||||
uint8_t *Ringbuf_Pop_Front(
|
volatile uint8_t *Ringbuf_Pop_Front(
|
||||||
RING_BUFFER * b);
|
RING_BUFFER * b);
|
||||||
bool Ringbuf_Put(
|
bool Ringbuf_Put(
|
||||||
RING_BUFFER * b, /* ring buffer structure */
|
RING_BUFFER * b, /* ring buffer structure */
|
||||||
uint8_t * data_element); /* one element to add to the ring */
|
volatile uint8_t *data_element); /* one element to add to the ring */
|
||||||
uint8_t *Ringbuf_Alloc(
|
volatile uint8_t *Ringbuf_Alloc(
|
||||||
RING_BUFFER * b);
|
RING_BUFFER *b);
|
||||||
/* Note: element_count must be a power of two */
|
/* Note: element_count must be a power of two */
|
||||||
void Ringbuf_Init(
|
void Ringbuf_Init(
|
||||||
RING_BUFFER * b, /* ring buffer structure */
|
RING_BUFFER * b, /* ring buffer structure */
|
||||||
|
|||||||
+11
-11
@@ -47,7 +47,7 @@
|
|||||||
* ALGORITHM: none
|
* ALGORITHM: none
|
||||||
* NOTES: none
|
* NOTES: none
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
unsigned Ringbuf_Count(
|
unsigned Ringbuf_Count (
|
||||||
RING_BUFFER const *b)
|
RING_BUFFER const *b)
|
||||||
{
|
{
|
||||||
unsigned head, tail; /* used to avoid volatile decision */
|
unsigned head, tail; /* used to avoid volatile decision */
|
||||||
@@ -67,7 +67,7 @@ unsigned Ringbuf_Count(
|
|||||||
* ALGORITHM: none
|
* ALGORITHM: none
|
||||||
* NOTES: none
|
* NOTES: none
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
bool Ringbuf_Full(
|
bool Ringbuf_Full (
|
||||||
RING_BUFFER const *b)
|
RING_BUFFER const *b)
|
||||||
{
|
{
|
||||||
return (b ? (Ringbuf_Count(b) == b->element_count) : true);
|
return (b ? (Ringbuf_Count(b) == b->element_count) : true);
|
||||||
@@ -91,10 +91,10 @@ bool Ringbuf_Empty(
|
|||||||
* ALGORITHM: none
|
* ALGORITHM: none
|
||||||
* NOTES: none
|
* NOTES: none
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
uint8_t *Ringbuf_Get_Front(
|
volatile uint8_t *Ringbuf_Get_Front(
|
||||||
RING_BUFFER const *b)
|
RING_BUFFER const *b)
|
||||||
{
|
{
|
||||||
uint8_t *data_element = NULL; /* return value */
|
volatile uint8_t *data_element = NULL; /* return value */
|
||||||
|
|
||||||
if (!Ringbuf_Empty(b)) {
|
if (!Ringbuf_Empty(b)) {
|
||||||
data_element = b->buffer;
|
data_element = b->buffer;
|
||||||
@@ -110,10 +110,10 @@ uint8_t *Ringbuf_Get_Front(
|
|||||||
* ALGORITHM: none
|
* ALGORITHM: none
|
||||||
* NOTES: none
|
* NOTES: none
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
uint8_t *Ringbuf_Pop_Front(
|
volatile uint8_t *Ringbuf_Pop_Front(
|
||||||
RING_BUFFER * b)
|
RING_BUFFER * b)
|
||||||
{
|
{
|
||||||
uint8_t *data_element = NULL;
|
volatile uint8_t *data_element = NULL;
|
||||||
|
|
||||||
if (!Ringbuf_Empty(b)) {
|
if (!Ringbuf_Empty(b)) {
|
||||||
data_element = b->buffer;
|
data_element = b->buffer;
|
||||||
@@ -132,10 +132,10 @@ uint8_t *Ringbuf_Pop_Front(
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
bool Ringbuf_Put(
|
bool Ringbuf_Put(
|
||||||
RING_BUFFER * b, /* ring buffer structure */
|
RING_BUFFER * b, /* ring buffer structure */
|
||||||
uint8_t *data_element)
|
volatile uint8_t *data_element)
|
||||||
{ /* one element to add to the ring */
|
{ /* one element to add to the ring */
|
||||||
bool status = false; /* return value */
|
bool status = false; /* return value */
|
||||||
uint8_t *ring_data = NULL; /* used to help point ring data */
|
volatile uint8_t *ring_data = NULL; /* used to help point ring data */
|
||||||
unsigned i; /* loop counter */
|
unsigned i; /* loop counter */
|
||||||
|
|
||||||
if (b && data_element) {
|
if (b && data_element) {
|
||||||
@@ -160,10 +160,10 @@ bool Ringbuf_Put(
|
|||||||
* ALGORITHM: none
|
* ALGORITHM: none
|
||||||
* NOTES: none
|
* NOTES: none
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
uint8_t *Ringbuf_Alloc(
|
volatile uint8_t *Ringbuf_Alloc(
|
||||||
RING_BUFFER * b)
|
RING_BUFFER *b)
|
||||||
{
|
{
|
||||||
uint8_t *ring_data = NULL; /* used to help point ring data */
|
volatile uint8_t *ring_data = NULL; /* used to help point ring data */
|
||||||
|
|
||||||
if (b) {
|
if (b) {
|
||||||
/* limit the amount of elements that we accept */
|
/* limit the amount of elements that we accept */
|
||||||
|
|||||||
Reference in New Issue
Block a user