diff options
author | Christian Pointner <equinox@mur.at> | 2012-06-13 21:02:54 +0000 |
---|---|---|
committer | Christian Pointner <equinox@mur.at> | 2012-06-13 21:02:54 +0000 |
commit | c03bd36a1fa5dbbaac88c6200a6a598485aa71ae (patch) | |
tree | 673d9dfd4b8a660f5c9979395a8e709aeb4e3de1 /tools/idm-ringbuffer/ringbuffer.c | |
parent | better handling if stdin=file (diff) |
better but not there yet..
git-svn-id: https://svn.spreadspace.org/mur.sat@527 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'tools/idm-ringbuffer/ringbuffer.c')
-rw-r--r-- | tools/idm-ringbuffer/ringbuffer.c | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/tools/idm-ringbuffer/ringbuffer.c b/tools/idm-ringbuffer/ringbuffer.c index 53e9365..5fd65b4 100644 --- a/tools/idm-ringbuffer/ringbuffer.c +++ b/tools/idm-ringbuffer/ringbuffer.c @@ -54,42 +54,33 @@ char* bufferEnd = &(picRam[BUFFER_END - 1]); char* writePtr = 0; char* readPtr = 0; BOOL overrun = FALSE; -BOOL overrunForReader = FALSE; BOOL underrun = TRUE; BOOL currentByteLoaded = FALSE; char spiData = 0; void incrementWriteIdx() { - if (!underrun && (writePtr == readPtr)) { - overrun = TRUE; - overrunForReader = TRUE; - } else { - if (!overrun) { - writePtr++; - writePtr = writePtr > bufferEnd ? bufferStart : writePtr; - } - overrun = FALSE; - overrunForReader = FALSE; + if (!overrun) { + writePtr++; + writePtr = writePtr > bufferEnd ? bufferStart : writePtr; underrun = FALSE; + if(writePtr == readPtr) { + overrun = TRUE; + } } } void incrementReadIdx() { - if (!overrunForReader && (readPtr == writePtr)) { - underrun = TRUE; - } else { + if(!underrun) { readPtr++; readPtr = readPtr > bufferEnd ? bufferStart : readPtr; - underrun = FALSE; - overrunForReader = FALSE; - // overrun = FALSE; + overrun = FALSE; + if(readPtr == writePtr) { + underrun = TRUE; + } } } void beginRead() { - if (!currentByteLoaded) { - incrementReadIdx(); - } if (!underrun) { spiData = *readPtr; printf("SPI out: %02x\n", (int)spiData); @@ -99,13 +90,14 @@ void beginRead() { void endRead() { currentByteLoaded = FALSE; + incrementReadIdx(); } void storeSample() { static char value = 0; - incrementWriteIdx(); if (!overrun) { *writePtr = ++value; + incrementWriteIdx(); } } |