From 1e15396abf51c580e290bd997c38e1fd6cba7d20 Mon Sep 17 00:00:00 2001 From: Nidan Date: Fri, 13 Jan 2012 22:29:18 +0100 Subject: [PATCH] adapting to new ringbuffer --- gg.c | 6 ++---- ringbuf_small.c | 17 +++++------------ ringbuf_small.h | 10 +++++----- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/gg.c b/gg.c index 64a095f..4788a54 100644 --- a/gg.c +++ b/gg.c @@ -32,8 +32,8 @@ uint32_t mmc_position;/* current reading position on mmc */ uint8_t overflows = 1;/* remaining counter overflows until next sample */ #define SAMPLE_BITS 11 -#define BUFFER_SIZE 64 -uint8_t buffer[BUFFER_SIZE];/* buffer for mmc data */ +#define BUFFER_SIZE 32 +uint16_t buffer[BUFFER_SIZE];/* buffer for mmc data */ ISR(TIMER1_OVF1_vect, ISR_NAKED) { @@ -51,8 +51,6 @@ ISR(TIMER1_OVF1_vect, ISR_NAKED) reti(); } - - int main(void) __attribute__((noreturn)); int main(void) { diff --git a/ringbuf_small.c b/ringbuf_small.c index 360d3e9..9be5caa 100644 --- a/ringbuf_small.c +++ b/ringbuf_small.c @@ -10,11 +10,11 @@ * - reading of pointers allowed at any time * - volatile not really necessary, unless you really need the functions to * react to freespace/newdata while they're running - * + * * PUT AND GET ARE NOT REENTRANT! */ -void ringbuf_init(ringbuf_t *rb, uint16_t * buf, uint8_t size){ +void ringbuf_init(ringbuf_t *rb, uint16_t *buf, uint8_t size){ rb->startptr = buf; rb->size = size; rb->readpos = 0; @@ -41,9 +41,9 @@ uint8_t ringbuf_put(ringbuf_t *rb, uint16_t value){ } /* gets a value from the ringbuffer - * returns 0 on success, -1 on buffer empty + * returns 0 on success, 1 on buffer empty */ -int8_t ringbuf_get(ringbuf_t *rb, uint16_t* data){ +uint8_t ringbuf_get(ringbuf_t *rb, uint16_t *data){ //uint16_t value; uint8_t next; // calculate next ptr pos @@ -53,16 +53,9 @@ int8_t ringbuf_get(ringbuf_t *rb, uint16_t* data){ } //check for empty if(rb->readpos == rb->writepos){ - return(-1); + return(1); } *data = *(rb->startptr + rb->readpos); rb->readpos = next; return(0); } - - - - - - - diff --git a/ringbuf_small.h b/ringbuf_small.h index 220c43f..9c3bf5e 100644 --- a/ringbuf_small.h +++ b/ringbuf_small.h @@ -5,14 +5,14 @@ typedef struct { uint16_t* startptr; - uint16_t size; - uint16_t readpos; - uint16_t writepos; + uint8_t size; + uint8_t readpos; + uint8_t writepos; } ringbuf_t; -void ringbuf_init(ringbuf_t* rb, uint16_t* buf, uint8_t size); +void ringbuf_init(ringbuf_t* rb, uint16_t *buf, uint8_t size); uint8_t ringbuf_put(ringbuf_t *rb, uint16_t value); -int8_t ringbuf_get(ringbuf_t *rb, uint16_t* data); +uint8_t ringbuf_get(ringbuf_t *rb, uint16_t *data); #endif