Shop OBEX P1 Docs P2 Docs Learn Events
Scratch Pad Memory Managment — Parallax Forums

Scratch Pad Memory Managment

AA Posts: 22
edited 2007-05-27 15:19 in BASIC Stamp
Hello all,

I am wondering if anyone has done any work using the scratch pad ram. In particular I am wondering about using it as a memory buffer for wireless communication.· The scheme is to send a data packet.· if a reply and follwing data are recieved the transmitted data is not buffered.· if no reply I want to buffer the packet.· I know how to get the packets into the ram and retrieve them but am not sure how to manage the buffer.· I would like to send the oldest buffered data if a reply is recieved the sent data is removed from the buffer. Next I would like to then·shift the entire ram contents·to always keep the oldest buffered data at the bottom of the stack.· Mabey there is a better method??

Aaron

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2007-05-26 19:25
    The scratch pad memory (or any other memory for that matter) on the Stamps is not buffered.

    The easiest way to proceed is to use an external buffer chip. Both Proteus and Rhombus have chips that can buffer short strings and give you the flexibility you're looking for.

    You could perhaps use the Propeller and let one of the processor cogs be your communications handler.

    cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • AA Posts: 22
    edited 2007-05-26 19:43
    I realize that the memory itself is not buffered.· I want to turn the memory into a buffer.· I need code to effectvly manage the memory. perhaps the propeller is the way to go.· I just don't have the programming experince with that device.

    Thanks A
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-05-26 19:55
    Aaron,

    Shifting data around in scratchpad RAM can easily be accomplished with a sequence of GETs and PUTs. Just remember: if you're moving a block of data to a higher address, start at the end of the block and work your way down; if to a lower address, work from the beginning and work your way up. That way you won't write over data that hasn't yet been moved. You will also need to keep an array of pointers to the beginning of each data block, so you know where each begins.

    -Phil
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-26 21:56
    Rather than move the data, it is often easier to manage pair of pointers to a circular buffer. One pointer indicates the start, where the oldest datum is located, and the second pointer indicates the point in the buffer where the next new value will go in. When a value is sent, increment the oldValuePoint by one, modulo the length of the buffer. When a new value arrives, put it at the location newValuePoint, and then increment that pointer modulo the buffer size.
    The condition where both pointer equal means that the buffer is empty, so don't try to send. It can also mean that the buffer is full, and special consideration has to be given to the event of newValuePoint incrementing to become equal to oldValuePoint. Does it stop in favor of the old data, or does it overwrite the old data in favor of the most recent?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-05-26 22:23
    Tracy,

    You're right, of course. I was a little hung up on the fact that the data consisted of contiguous blocks, rather than discrete bytes, and a misperceived need to keep those blocks from being split up at the buffer boundaries. But with a properly-designed circular queue, this needn't be a concern, with the added bonus of not having to change the block pointers after queuing/dequeuing.

    -Phil
  • AA Posts: 22
    edited 2007-05-27 15:19
    Thanks for the great ideas.· I think i will tackle the circular approach.· In my app old data is favored over new.· The idea is to send each packet is to my wireless device. if the packet is recieved it is removed from the buffer. If my "buffer" becomes full the program stops its normal apps and continues to try sending the oldest data first.· Once room is available in the buffer the program will continue normal operation.

    Aaron
Sign In or Register to comment.