PASM Question: best practice for cog-to-cog data sharing
Wossname
Posts: 174
I'm beginning to learn assembly language programming for the Propeller chip.
My aim is to have one Cog periodically reading a set of 8 switches and writing those 8 bits to a byte in Cog ram. Then another Cog will periodically read this byte and act upon it accordingly (initially it will just display these bits on 8 LEDs, but later on it will do something more useful).
How do I decide what hub ram address would be appropriate for storing the data? I'm not sure what the syntax should be for declaring the address value and what that numerical value ought to be.
My aim is to have one Cog periodically reading a set of 8 switches and writing those 8 bits to a byte in Cog ram. Then another Cog will periodically read this byte and act upon it accordingly (initially it will just display these bits on 8 LEDs, but later on it will do something more useful).
How do I decide what hub ram address would be appropriate for storing the data? I'm not sure what the syntax should be for declaring the address value and what that numerical value ought to be.
Comments
The usual way is to use HUB-RAM with the commands WRLONG and RDLONG
There are some more methods to interchange data between cogs but they are more sophisticated.
Therefore both cogs have to know which HUB-RAM-adress.
Here is the actual end of my knowledge. @the PASM-experts How do you tell a cog started from another cog running PASM a HUB-RAM-adress?
My first idea is to use a fixed and - through a hardcoded value adressable HUB-RAM-long at the upper end of the HUB-RAM.
keep the questions coming
best regards
Stefan
thank you very much for direct answering me this - even if - me myself - sometimes emphasise on others "info can be found at ...." or just writing guiding questions.
best regards
Stefan
I'm still having a bit of trouble making this work though.
This will be difficult to explain but I'd be grateful if someone could glance over my code and see if they can spot some obvious mistakes I've made...
The shift register control code works well, I'm happy that it's showing the values it should be. However the wdbyte and rdbyte usage is probably broken and I'm not sure how.
Also the loop in the ShiftIn routine doesn't do what I expect. I'd expect it to continually increment valueIN... 0, 1, 2, 3, 4, etc etc, but the LEDs on my shift register just flash 1 all the time, and it never changes from 1.
I'm unsure about the usage of "@" in all this business.
Any ideas guys?
The res must stay after the delayIN long. As you have it now, the shiftDataIN gets the value 3_000_000 and not the delayIN register.
Andy
After loading the code into PASD. PASD right away mentioned the bug in the status line
at the bottom of the PASD-window and even marking the buggy line pink
keep the questions coming
best regards
Stefan
@Stefan, I've had a look at the PASD software you mentioned and it has confused me a bit. It's complaining that the "timeOUT" declaration should be at the bottom. But surely if I put it at the bottom then it won't be loaded into COG 0 (if the code was a lot longer for example). Or am I wrong about that? (I'm still getting to grips with this language so let me know if I'm talking rubbish ).
Looks like a good tool though, it came up with my code almost without my noticing it had loaded it. Then I realised that it had scanned for the Propeller Tool's open file. Pretty cool stuff.
Thank you to everyone who posted, I've learned some interesting things in this thread.
Parallax's forums are great, friendly folks all around.
Thanks again everyone.
the message "res section must be at end to correspond with assembler alignement" is meant exactly how ariba showed it
all PASM-commands and longs have to be before any res.
the order of the res do't play a role. You can order them as you like the names of each res gets calculated by the compiler but the calculation is only correct if the res start behind
commands and behind longs
Though I don't know what happends if you have code for more than one cog in a DAT-section and put the res-(erved) longs at the end.
The code must fit into the COGs RAM which means there is room for 496 longs. If your code extends that only the first 496 longs get loaded
and I guess if res)erved longs are behind that they are just not there making the code not working.
Maybe the PASM-experts can chime in.
Would I create a separate DAT-section for each cogs code?
Would I use separate spin-file for each PASM-code?
keep the questions coming
best regards
Stefan
http://wardyprojects.blogspot.com/2011/08/propeller-plus-input-and-output-shift.html
You are using coginit. One of the rare situations where coginit should be used is if you want to restart a certain cog for executing PASM-code that is actually executing SPIN-code.
As long as you do not run out of cogs use cognew. If you use cognew the propeller-chip takes care which cog will be used. If you start using coginit you the user are responsible for
starting and stopping the right cogs.
A short time ago there was a thread about this restart a certain SPIN-cog with PASM-thread.
keep the questions coming
best regards
Stefan
Otherwise it may rise up and overthrow it's puny human masters etc. etc.etc...
If all eight cogs are in use you get e feedback about this.
If you use coginit you force the cog to start or to restart. Now imagine you want to start cog 4 thinking it is free but it isn't. With coginit you force the already running cog to terminate its actual task
and start it with your new task. When using coginit the propeller hands over the full responsibility which cog to start, stop or restart to you. And I guess in most cases this is a source of bugs that could be avoided through using cognew consequently.
For stopping code-actions I used to make the execution of critcical parts conditionally to a central variable.
pseudo-code if MyAbortVar = zero ....
Whenever something strange happens regardless of what it is (in your example pen hits end of his moving range) MyAbortVar is st to a non-zero value indicationg an error.
if really all critical things are condiational to if MyAbortVar = zero .... everything stops as soon as possible. For using this across cogs it has to be a shared HUB-RAM-long.
I used this while programming in delphi for PC_based industrial controls.
Anyway something like pen hitting the border of his range or real emergency things I would hardwire in a serial of normally closed switches. Operates only as long as all switches are closed.
Whenever one switch opens or a wire gets cutted the thing stops without the need of the MCU checking it.
keep the questions coming
best regards
Stefan