sd card buffer
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
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

Comments
VAR long ringBuffer[noparse][[/noparse] 64 ] long putPtr long getPtr PUB Main putPtr := 0 getPtr := 40 repeat ringBuffer[noparse][[/noparse] putPtr++ ] := ReadAdc putPtr &= $3F WriteDac( ringBuffer[noparse][[/noparse] getPtr++ ] ) getPtr &= $3F WaitForTick PRI ReadAdc : adc adc := ? PRI WriteDac( dac ) ? := dac PRI WaitForTickI 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
VAR long ringBuffer[noparse][[/noparse] $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[noparse][[/noparse]getPtr] IF getPtr <> putPtr getPtr := (getPtr+1) & $3F PUB putToBuffer(value):success IF getPtr == (putPtr+1) & $3F RETURN ' buffer is full ringBuffer[noparse][[/noparse]putPtr] := value putPtr := (putPtr+1) & $3F success := TRUEWhen you want to call these routines from different COGs you would need LOCKs however..