Using unused IOpins as flags
Gennady
Posts: 34
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··
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 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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
Someone have a brief example?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
E3 = Thought
http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.
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:
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.