Initial commit
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
#include "circ_buf.h"
|
||||
|
||||
void buffer_init(volatile circular_buffer_t* b){
|
||||
b->count = 0;
|
||||
b->head = 0;
|
||||
b->tail = 0;
|
||||
}
|
||||
|
||||
uint8_t buffer_is_full(volatile circular_buffer_t* b){
|
||||
return b->count == BUFFER_SIZE;
|
||||
}
|
||||
|
||||
uint8_t buffer_is_empty(volatile circular_buffer_t* b){
|
||||
return b->count == 0;
|
||||
}
|
||||
|
||||
uint8_t buffer_enqueue(volatile circular_buffer_t* b, char c){
|
||||
if(buffer_is_full(b))
|
||||
return 0;
|
||||
b->data[b->head] = c;
|
||||
b->head = (b->head+1)%BUFFER_SIZE;
|
||||
b->count++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t buffer_dequeue(volatile circular_buffer_t* b, char* c){
|
||||
if(buffer_is_empty(b))
|
||||
return 0;
|
||||
*c = b->data[b->tail];
|
||||
b->tail = (b->tail+1)%BUFFER_SIZE;
|
||||
b->count--;
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user