Shop OBEX P1 Docs P2 Docs Learn Events
sd card buffer — Parallax Forums

sd card buffer

OwenOwen Posts: 100
edited 2008-01-13 04:00 in Propeller 1
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

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2008-01-13 01:10
    search for RINGBUFFER, one or two recent threads by Nick Mueller
  • OwenOwen Posts: 100
    edited 2008-01-13 02:40
    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 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
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-13 04:00
    I see - this is a special synchronious use. You would need something like these equally simple constructs
    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 := TRUE
    



    When you want to call these routines from different COGs you would need LOCKs however..
Sign In or Register to comment.