Newcomer Questions about Prop operation
demestav
Posts: 4
Hello all!
This is my first post here. Let me just tell you, this is one great community! Well done!
I am getting my feet wet with Prop and I have a beginner question.
About processing. I am reading the FullDuplexLibrary. I can see that in the DAT section the processing goes back and forth between the RECEIVE and TRANSMIT part of the code. Now this runs continuously on the cog. What I dont understand is what happens when a PUBlic function is called from another cog. For example what happens when the FullDuplexLibrary.rxflush is called? When will that part of the code be executed?
Thanks!
demestav
This is my first post here. Let me just tell you, this is one great community! Well done!
I am getting my feet wet with Prop and I have a beginner question.
About processing. I am reading the FullDuplexLibrary. I can see that in the DAT section the processing goes back and forth between the RECEIVE and TRANSMIT part of the code. Now this runs continuously on the cog. What I dont understand is what happens when a PUBlic function is called from another cog. For example what happens when the FullDuplexLibrary.rxflush is called? When will that part of the code be executed?
Thanks!
demestav
Comments
Just to complicate matters, you can have more than one cog executing a Spin interpreter by using COGNEW to start a new Spin interpreter that has its own stack area and starts with a specific method call (see the chapter in the Manual on COGNEW for details).
You do have two processors (COGs) running:
#1 is running the SPIN code. This *includes* the functions written in SPIN for the FDS-lib (for example rxflush)
#2 is running the assembler part (in the DAT-section). Most of the time, it sits and waits for work to come.
The rxflush-code (in SPIN) just manipulates a few values (rxhead, rxtail, ... out of my head) that are shared with #2. These values are in HUB-RAM.
The basic principle is to agree upon a communication protocol through some (or one) register in HUB-RAM. There is no way to *directly* influence a COG as soon as it is running. Only by setting flags / shared memory.
All this maybe sounds quite odd, but as soon as you've understood the principle, you will like it.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
ie,. the asm is always testing for a change in at least one variable to break out of the RX/TX loop to do something else. Otherwise, the asm cog would just be stuck in the TX/RX loop indefinitely until that cog was stopped.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Quicker answers in the #propeller chat channel on freenode.net. Don't know squat about IRC? Download Pigin! So easy a caveman could do it...
http://folding.stanford.edu/ - Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.
@Nick Mueller : So as you said, the DAT part is executed continuously on #2 cog and we have access on its memory variables through the #1 cog since they are located on the HUB memory. How do we define that the variables used in the DAT are stored in the HUB memory and not on the cog local memory?
Thanks again...
The above is true for assembly programs. For Spin programs, which are interpreted by a built-in assembly program, all variables are in the shared (HUB) memory. There is no access to the cog's memory (used by the Spin interpreter) except for some special registers (PHSA, FRQA, DIRA, OUTA, etc.)
1. For a single LONG (or array of LONGs), the PAR register is loaded with the second parameter from COGINIT/COGNEW;· i.e. COGNEW( @cogstart, @shvar)
2. The SPIN code may update the PASM code before invoking COGINIT/COGNEW as if it were any other variable; i.e. shvar1addr := @shvar1.· This should not be done if multiple cogs may be updating these PASM variables at the same time since there is only one instance of the PASM code in HUB RAM.
3. As a variation on #1 - the second parameter may be the address of a table of addresses.· i.e. shvaraddr[noparse][[/noparse]0] := @shvar1··COGNEW( @cogstart, @shvaraddr[noparse][[/noparse]0] );
(Note: depending on usage & structure of the shared variables, it may be necessary to also use LOCKs to prevent read/write conflicts.)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum
NTSC & PAL driver templates: ObEx Forum
OnePinTVText driver: ObEx Forum
Not wanting to contradict the other answers, but from a less detailed and higher POV:
Basically, you pass a pointer to some structure (your layout) to the COG at the moment you start it. Thats the PAR that is almost always referenced to in the first few lines of any ASM-code.
This pointer (plus offsets by your definition; pointer might also point to an array of pointers, as you want) is *the* key-element when starting any instance of some ASM-code in a COG.
Beware, I'm talking about ASM! SPIN is different.
There are other techniques, but this is the most obvious one. But ... well ... others might contradict.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
It's funny because as I was reading your answers, some other questions popped up in my head by they were finally answered through the rest of the thread.
I think I got some basic understanding of how prop works.
Can't wait to get my hands on a Prop...
Thanks again everyone.