Added some volatile keywords to make it interrupt safe.

This commit is contained in:
skarg
2011-10-18 02:24:44 +00:00
parent 78fb95bb63
commit 4a779febca
2 changed files with 32 additions and 20 deletions
+4 -4
View File
@@ -43,11 +43,11 @@
#include <stdbool.h>
struct ring_buffer_t {
uint8_t *data; /* block of memory or array of data */
uint8_t * volatile buffer; /* block of memory or array of data */
unsigned element_size; /* how many bytes for each chunk */
unsigned element_count; /* number of chunks of data */
unsigned head; /* where the writes go */
unsigned tail; /* where the reads come from */
volatile unsigned head; /* where the writes go */
volatile unsigned tail; /* where the reads come from */
};
typedef struct ring_buffer_t RING_BUFFER;
@@ -73,7 +73,7 @@ extern "C" {
/* Note: element_count must be a power of two */
void Ringbuf_Init(
RING_BUFFER * b, /* ring buffer structure */
uint8_t * data, /* data block or array of data */
uint8_t * volatile buffer, /* data block or array of data */
unsigned element_size, /* size of one element in the data block */
unsigned element_count); /* number of elements in the data block */