Shop OBEX P1 Docs P2 Docs Learn Events
Using unused IOpins as flags — Parallax Forums

Using unused IOpins as flags

GennadyGennady Posts: 34
edited 2007-08-10 21:17 in Propeller 1
I would like to get an opinion on using unused pins as a method for inter-cog communication / synchronization.

According to the Prop's IO structure, if pin is set·as an output in one cog, other cogs (where this pin is set as an input) can read this pin's output state. This provides a convenient way of·communication on flag (bit) level.
I've tried it, and it works fine.

The question is:·are there any dangers (warnings) in using this method I am not aware of ? I don't want to face it when I will implement it.

Gennady··

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-08 22:54
    There are no hidden dangers. Make sure to set the pin as an output in one cog before you start to check it as an input in another cog, just because of the "floating input pin" issue. You can always use a pullup or pulldown to avoid that.
  • HarleyHarley Posts: 997
    edited 2007-08-08 23:01
    Gennady,

    Mike beat me to it, but I've used such before. Useful for providing a 'scope sync for triggering on I/O signalling, providing a simulated temporary timing signal for input(s) to other parts of one's program, for triggering a timer, etc. Try it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
    h.a.s. designn
  • rjo_rjo_ Posts: 1,825
    edited 2007-08-09 18:07
    AND by using counters to do you your monitoring... it is fully clocked and almost free!!!!
  • Marc GebauerMarc Gebauer Posts: 60
    edited 2007-08-09 18:11
    Could you use locks for flags? Aren't locks just flags anyways?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-09 18:16
    You can use EVERYTHING as flags smile.gif
    Just kidding - it depends on the time scale you are interested in.

    You can very effctively sync using the CNT register - just set a "proposed" time into a preconcerted HUB cell and use WAITCNT to sync to it... But give your partner time to read it....

    Post Edited (deSilva) : 8/9/2007 6:21:54 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-09 18:21
    You can use locks as flags. They have the special property that you test them and set them to a known value all at the same time. No other instruction can get to them between the test and the set. In the case of the Propeller, there's also a pool of 8 of them that can be shared among the 8 cogs and the hardware takes care of allocating them on demand.
  • SteelSteel Posts: 313
    edited 2007-08-09 21:53
    I would just use a variable...and pass the address of that variable down to the cog so the cog always has access to read that variable.
  • potatoheadpotatohead Posts: 10,260
    edited 2007-08-10 05:37
    I'm interested in the idea of the locks as flags.

    Someone have a brief example?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-10 05:39
    It's not complicated. Try the examples in the Propeller manual.
  • potatoheadpotatohead Posts: 10,260
    edited 2007-08-10 05:42
    Didn't know they were in there!

    Thanks!

    Edit: Got it. ( I think!)

    One cog allocates a lock and distributes it's id to the other cogs involved. The lock is then shared and ready for use.

    From there, the cogs then try to set the state of the lock, with success or failure being the actual state indicator, not the actual value set. Unsetting the lock essentially then, means: "I'm done, your turn." Successfully setting the lock means: "I see you are done, my turn."

    The real value being one cannot clear a lock, one did not set. This is differentiated from a software flag, where the value is the flag, instead of the action being the flag. One process could lie about it's state, set the flag and hose things up. That behavior forces some logic, not otherwise required with a value only flag.

    This is one of those, "I'll read it later because I think I don't need it right now." things, that gets passed over way too easily!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Post Edited (potatohead) : 8/10/2007 2:27:29 PM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-10 20:03
    I repeat: EVERTHING can be a flag.... and no longer kidding!

    A semaphore (or a "lock") has no magical features. Everyone can clear or set a lock at will.
    The difference is that the state the "lock" was in is returned!

    This is not possible to accomplish with standard HUB instructions, as you will need two, and there is a fair chance of beeing interceptet by another COG.

    Within one COG you can of course use any read-modify-write instruction; but there is no need for "locking" within a COG due to missing parallism.
  • RinksCustomsRinksCustoms Posts: 531
    edited 2007-08-10 21:02
    i could have sworn there was a way to reference or access (R/W) a variable or piece of data within another object, but i can't find it in the manual now.· I'm not reffering to·object.method(parameters).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    E3 = Thought

    http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-10 21:17
    RinksCustoms,
    You have to pass the address of the piece of data from the object where it's defined to the object where it's to be used. For example:
    ' object 1
    VAR byte piece
    
    OBJ used : "something"
    
    PUB pass_it
       used.use_it(@piece)
    
    

    ' object "something"
    PUB use_it(address)
       if byte[noparse][[/noparse]address] == 0
    '   do something
       byte[noparse][[/noparse]address] := 1
    
    


    The address passing can go the other way from "something" to "object 1" if the piece is defined in "something". You just need a PUB method that returns the address of the item when it's called.
Sign In or Register to comment.