Explanation of Cog processor working in parallel
guili_23
Posts: 11
Hi,
Could anybody explain me the basic function of Cogs working in parallel ?? I have read the propeller manual but when I tried to make a simple Spin application with two Cogs it didn´t work.
1.- Why this code doesn´t work properly:
And this code does:
I read that the I/O registers are common for the Cogs, Why should I define the I/O every time I start a Cog ???
2.- Other question, when I add a combination of Spin and Assembly code it doesn´t work in the way I want it to work, for example:
it stops running when I call to the new Cog.
I think that is something related to the memory space between Cogs and Main RAM but I can´t understand it very well.
Thanks in advance.
Could anybody explain me the basic function of Cogs working in parallel ?? I have read the propeller manual but when I tried to make a simple Spin application with two Cogs it didn´t work.
1.- Why this code doesn´t work properly:
CON LED=21 VAR long Stack[10] PUB Main dira[LED]~~ outa[LED]~ <more code> cognew(Test, @Stack) <more code> PUB Test repeat Delay(1_000) 'Delay of one second !outa[LED]
And this code does:
CON LED=21 VAR long Stack[10] PUB Main <more code> cognew(Test, @Stack) <more code> PUB Test dira[LED]~~ repeat Delay(1_000) 'Delay of one second !outa[LED]
I read that the I/O registers are common for the Cogs, Why should I define the I/O every time I start a Cog ???
2.- Other question, when I add a combination of Spin and Assembly code it doesn´t work in the way I want it to work, for example:
<definition of CON and VAR> PUB Main <code> cognew(@mfmWordReader, @mfmWord) <more code> <definition of others PUBs> DAT org 0 mfmWordReader <assembly code>
it stops running when I call to the new Cog.
I think that is something related to the memory space between Cogs and Main RAM but I can´t understand it very well.
Thanks in advance.
Comments
You need to set the I/O mode in the cog that sets the sense (low / high) of the I/O pin.
2) How do you want the Spin / Assembler combination to work? What you wrote should start up another cog with the assembly routine you wrote and pass it the address of mfmWord.
thank you for your response.
Regarding the second point I will try to explain a little better.
In the Main PUB (Cog 0) I define the I/O of the Propeller. One of these Inputs defined in Main (called INDEX) will be used to increment a counter of NEGEDGE monitored by other Cog (Cog 1)
But when I call to the new Cog (1) the programs stops (I realise through the visualization of a led).
Here is the code, Could you find where the error is ??
Once things are initialized, you do the first WAITPEQ which waits for I/O pin 1 to be high (1), then the second WAITPEQ waits for I/O pin 1 to be low (0). It then writes PHSB to mfmWord and who knows what happens next? The program will begin to execute the data that follows the WRLONG most of which is zeros which won't do anything, but it's anyone's guess what will happen once it finishes executing the zero stored in the state location.
I suggest you put something like "hangHere JMP #hangHere" after the WRLONG to make the cog hang there or a " COGID temp" followed by a " COGSTOP temp" to make the cog stop (and reset it).
Some simplifying hints:
I often declare a "Zero LONG 0" in my programs, then use " WAITPEQ Zero,IOmask" or " WAITPNE Zero,IOmask" to wait for a zero or one respectively. To me this is clearer than putting anything else in the destination field and it doesn't matter which I/O pin I'm using.
You can use PAR in the source field of both a WRxxxx and RDxxxx. If you're only passing a single value, this is much easier than moving PAR to a temporary location, then using that.
the hints were very helpfull !!
Best Regards
The wrlong on its own doesn't do what you think it does. If phsx is used in the destination slot of an instruction its shadow location is used (not the counter register). So at least move the counter value to the shadow location (red) then store the value.
Also, you use mov temp, PINCON_IN but all this does is assign register $001 to temp. What you want is the immediate value of that constant, i.e. mov temp, #PINCON_IN. That said, you could do the whole counter setup including pin assignment like this
After cognew returns the main cog exits (LED switches off). If you want to keep it alive you have to take action (endless loop, infinite wait etc).