Shop OBEX P1 Docs P2 Docs Learn Events
fifo OBJ ? — Parallax Forums

fifo OBJ ?

janbjanb Posts: 74
edited 2007-08-04 03:00 in Propeller 1
<!--StartFragment -->Hi,
In my SPIN project there is a commands-source process and command-sink process· running on 2 separate cogs·<!--StartFragment --> asynchronously. Execution time of a command by the sink-process may vary.· I need sort of· FIFO buffer to allow for smooth operation of the source. Did anyone perhaps wrote a FIFO-object to store· longs?
Jan

Comments

  • Chad GeorgeChad George Posts: 138
    edited 2007-08-03 00:10
    Thats funny, I just posted one here http://forums.parallax.com/showthread.php?p=665226

    Use the LockQueue object. It is already setup to be a LONG queue but its pretty easy to change to a WORD or BYTE queue if needed.

    The Push/Pop functions will act like a FIFO. But of course it could also be a stack by using either Pop/PushHead or Push/PopTail.
  • janbjanb Posts: 74
    edited 2007-08-04 01:06
    <!--StartFragment -->·Hi,
    Thanks a lot - the use of semaphores looks very interesting.
    Do you mind I ask you about some details:

    1)
    how the code behaves if 2 independent cogs request push(x)
    at the same time to the common· LockQueue OBJ?

    I see push() requests a lock:
    ·repeat until not LockSet(SemID)
    Does it mean the 2nd cog will be paused until first one will not free the lock?

    2) You have foreseen this BlockShift, but it is used only on Count() method which is passive - what for is it needed?

    3) Have you considered to pass BlockSize as the 3rd variable in Initialize() ?
    Would it work? If so one would not need to have separate OBJ for byte,word, and long memory storage.

    In any case I like your code a lot and will start to use it in my project
    Thanks for sharing
    Jan
  • Chad GeorgeChad George Posts: 138
    edited 2007-08-04 01:42
    janb said...

    see push() requests a lock:
    ·repeat until not LockSet(SemID)
    Does it mean the 2nd cog will be paused until first one will not free the lock?
    yes, all calls into the public members of the queue will lock. The exception is a special version of the Peek and PeekTail functions that don't lock and always return immediately (IPeek, IPeekTail)
    janb said...
    You have foreseen this BlockShift, but it is used only on Count() method which is passive - what for is it needed?
    sorry, I don't get the question. I use BlockShift to convert the address range between head and tail pointers into a count of blocks in the queue. Maybe division byte block size would have been more straightforward, but ...
    janb said...
    3) Have you considered to pass BlockSize as the 3rd variable in Initialize() ?
    Would it work? If so one would not need to have separate OBJ for byte,word, and long memory storage.
    Yes, I considered it. I actually did a similar change to the LockPool object after I wrote the first version, but for the LockQueue it doesn't make as much sense. It would be more complicated to have a block size that isn't a BYTE, WORD or LONG.

    It would certainly work though, just move the constants into the DAT section and initialize them appropriately.

    But I intentially did this so that we remember we need DIFFERENT object files if we are going to create a seperate queue. Every instance of the same named object will refer to the same queue, so using constants requires you to do it right if you want to have a BYTE queue and a LONG queue in the same application. But this is a personal preference not functionally critical.


    I hope the code works well for you. Let me know how it goes. I'm going to be using the object myself here shortly so I'm very interested in getting it right if you find a bug.

    -Chad
  • janbjanb Posts: 74
    edited 2007-08-04 03:00
    Hi,
    I'm using more and more of yor FIFO methods.
    Could you double check PeakTail() - it seems to return only $FFFFFF.
    PeakHead() is working fine.
    What is the difference between IPeakHead() & PeakHead() ?
    Thanks
    Jan·
Sign In or Register to comment.