Shop OBEX P1 Docs P2 Docs Learn Events
How to impliment a queue — Parallax Forums

How to impliment a queue

groggorygroggory Posts: 205
edited 2008-04-08 03:29 in Propeller 1
I'm working on a wireless sensor system. Here's the gist of my system...
  • Many sensor objects on field
  • Each object can have up to 5 sensors on board
  • Sensor data capture is time sensitive (must timestamp at near actual time). Thus, each sensor has its own cog program watching it
  • Time is taken from a DS1388 time clock (good to .01s) via I2C
  • Data is written to an SD card (hooked up to propeller) in the FAT16 filesystem. File format it is written in has not been decided yet.
  • Data is passed back to a host computer via an XBee point to point (not mesh) network. XBee is connected to Propeller via a serial interface

Now with that said, the slowest part of most computer systems are the data links between systems. In this case the XBee wireless connection and the SD Card interface. For instance, you could have two (or more) sensors be tripped at the same time and take approximately the same time to process the data and be ready to time stamp and store it. Here is the procedure I would like for this
  • Sensor 1/2/3/4 is tripped
  • Sensor 1/2/3/4 polls the RTC until they each get a time. Because of this their timestamps will be slightly off as only one can control the I2C bus at a time. But as long as this is in the order of ~ <.01s, that's alright.
  • Near simeltaneously, they all want to send their data to be processed. Being processed means getting written to the SD Card, then the SD Card cog will send the data to the host computer when the host computer asks for it.

It is here that I'd like a queue object. I'm confident that I can create a queue object in SPIN. However, I don't know how to create a global queue object that any cog can access. In particular, I need the method 'object.push(data,time)' to be available to any cog. Does anyone know how I can create a global object? I know I can create a global list of say...longs...but a queue object would be so much more elegant.

If I couldn't make a global object, maybe I could create a global list of strings, a boolean lock variable, and a global int that keeps track of the current index on the list. If an object has new data for me to put on the SD Card, it would lock the list by setting the boolean true, grab the current index, put the data at that index, then set the boolean to false so someone else can put more data on.

Any thoughts on this. I've been reading alot and am working hard to make myself 'Think in Propeller'.

....Just a sidenote....Thank you to everyone who has contributed to all of the tutorials, tips and tricks, prop wiki's, sourcecode open resource section, and just been active on this forum. I couldn't have learned so much in so little time without this plethora of knowledge.

Thanks,

Greg

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-07 19:10
    You can create an object called Queue with no VAR space, only DAT space. Any variables declared in the DAT section are global to all instances of the object. This DAT section would have the queue elements and the pointers to the first and last elements of the queue as well as the pointer to the first element of the free list. There would be a global lock. In the object, you'd have a start method that would initialize everything and a stop method that would free the lock being used.

    You could include this object (OBJ) in any object that needs it and the compiler would allocate only one common data area. It would also use the same code for all instances of the object. Only your main program would call Queue.start or Queue.stop, but any object running in any cog could call the other methods (which would all use the lock).
  • jazzedjazzed Posts: 11,803
    edited 2008-04-08 01:08
    You can try this Queue object. I haven't had much time to test it, but I'll support it if you want to use it.
    It is built on a proprietary spin malloc and singly linked list. A stack object is also available using the same baseline code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    jazzed·... about·living in·http://en.wikipedia.org/wiki/Silicon_Valley

    Traffic is slow at times, but Parallax orders·always get here fast 8)
  • Stephen MoracoStephen Moraco Posts: 303
    edited 2008-04-08 03:29
    You can also find a queue.spin object posted within the MSCP2515 Engine object at the object exchange: http://obex.parallax.com/objects/227/
    I use two of these in my current propCAN project and they've been nicely stable. Simply move the VAR data to DAT as suggested in
    the earlier post above and that would work for you too. Queue.spin has built-in handling of the lock semaphore for multi-cog access, as well.

    It can at least serve as a working reference for you.

    Regards,
    Stephen, KZ0Q

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    ·
Sign In or Register to comment.