PDA

View Full Version : sd card buffer



Owen
01-13-2008, 09:05 AM
I hope this isn't too basic...
I'm having trouble trying to create an sd card buffer between two cogs. What I want to do is have one cog dump data into an array and have a second cog see the data and store it into the sd card. Despite searching the forums and the object exchange I haven't come across an example of explanation of how to do this. I don't now how to keep track of where in the array the sd cog should be reading and what array index the writing cog should write into. is there an easier, faster better way than using an array as the buffer?

thanks,
Owen

deSilva
01-13-2008, 09:10 AM
search for RINGBUFFER, one or two recent threads by Nick Mueller

Owen
01-13-2008, 10:40 AM
VAR
long ringBuffer[ 64 ]
long putPtr
long getPtr

PUB Main
putPtr := 0
getPtr := 40
repeat
ringBuffer[ putPtr++ ] := ReadAdc
putPtr &= $3F
WriteDac( ringBuffer[ getPtr++ ] )
getPtr &= $3F
WaitForTick

PRI ReadAdc : adc
adc := ?

PRI WriteDac( dac )
? := dac

PRI WaitForTick




I think this is from the thread you refer to but i'm a bit confused as to how you know when the buffer is full or empty. also i don't entirely understand the use of putPtr &= $3F is this creating a bit mask? how does this work/help? if I dont want a delay in the buffer am I right that putptr and getptr would both be initialized to 0? sorry for all the questions but the code has no comments so I'm still trying to understand.
thanks for the help

Owen

deSilva
01-13-2008, 12:00 PM
I see - this is a special synchronious use. You would need something like these equally simple constructs



VAR
long ringBuffer[ $3F+1 ]
long putPtr
long getPtr

PUB Main
putPtr := 0
getPtr := 0

REPEAT
...
? := getFromBuffer
....
IF checkBuffer
....
success := putToBuffer(?)

PUB checkBuffer: somethingToGet
somethingToGet := putPrt <> getPtr

PUB getFromBuffer: value
value := ringBuffer[getPtr]
IF getPtr <> putPtr
getPtr := (getPtr+1) & $3F

PUB putToBuffer(value):success
IF getPtr == (putPtr+1) & $3F
RETURN ' buffer is full
ringBuffer[putPtr] := value
putPtr := (putPtr+1) & $3F
success := TRUE



When you want to call these routines from different COGs you would need LOCKs however..