adapting to new ringbuffer

master
Nidan 14 years ago
parent a71bc1f5b6
commit 1e15396abf

@ -32,8 +32,8 @@ uint32_t mmc_position;/* current reading position on mmc */
uint8_t overflows = 1;/* remaining counter overflows until next sample */ uint8_t overflows = 1;/* remaining counter overflows until next sample */
#define SAMPLE_BITS 11 #define SAMPLE_BITS 11
#define BUFFER_SIZE 64 #define BUFFER_SIZE 32
uint8_t buffer[BUFFER_SIZE];/* buffer for mmc data */ uint16_t buffer[BUFFER_SIZE];/* buffer for mmc data */
ISR(TIMER1_OVF1_vect, ISR_NAKED) ISR(TIMER1_OVF1_vect, ISR_NAKED)
{ {
@ -51,8 +51,6 @@ ISR(TIMER1_OVF1_vect, ISR_NAKED)
reti(); reti();
} }
int main(void) __attribute__((noreturn)); int main(void) __attribute__((noreturn));
int main(void) int main(void)
{ {

@ -10,11 +10,11 @@
* - reading of pointers allowed at any time * - reading of pointers allowed at any time
* - volatile not really necessary, unless you really need the functions to * - volatile not really necessary, unless you really need the functions to
* react to freespace/newdata while they're running * react to freespace/newdata while they're running
* *
* PUT AND GET ARE NOT REENTRANT! * 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->startptr = buf;
rb->size = size; rb->size = size;
rb->readpos = 0; rb->readpos = 0;
@ -41,9 +41,9 @@ uint8_t ringbuf_put(ringbuf_t *rb, uint16_t value){
} }
/* gets a value from the ringbuffer /* 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; //uint16_t value;
uint8_t next; uint8_t next;
// calculate next ptr pos // calculate next ptr pos
@ -53,16 +53,9 @@ int8_t ringbuf_get(ringbuf_t *rb, uint16_t* data){
} }
//check for empty //check for empty
if(rb->readpos == rb->writepos){ if(rb->readpos == rb->writepos){
return(-1); return(1);
} }
*data = *(rb->startptr + rb->readpos); *data = *(rb->startptr + rb->readpos);
rb->readpos = next; rb->readpos = next;
return(0); return(0);
} }

@ -5,14 +5,14 @@
typedef struct { typedef struct {
uint16_t* startptr; uint16_t* startptr;
uint16_t size; uint8_t size;
uint16_t readpos; uint8_t readpos;
uint16_t writepos; uint8_t writepos;
} ringbuf_t; } 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); 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 #endif

Loading…
Cancel
Save