Can you use a cog to....
Newzed
Posts: 2,503
Is it possible to have a program running, then start a new cog with COGINIT, have that cog run an entirely different program, than at some point stop itself with COGSTOP and return to the original program?· Sort of like using the banks in a BS2E.
If it is possible, could someone show me how to do it?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
If it is possible, could someone show me how to do it?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Comments
Then both run absolutely independently.
Each of them can stop. by either running out of SPIN or explicitely be COGSTOP(COGID)
Even #1 can stop #2 or #2 can stop #1
There is no such thing as a "return" with COGs!
When you want to stop #2 and start it with a new program from #1, this should be straightforward.
When you want it (i.e. #2) to stop itself, and COG #1 to substitute a new program, then it (i.e. #2) has to set a communication variable before, to be read by #1, so it (i.e. #1) knows that #2 has terminated.
I think this is a rather complete description of the situation...
Post Edited (deSilva) : 10/10/2007 10:08:54 PM GMT
Thanks
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
PUB menu
· text.dec(COGID)
· WAITCNT(CLKFREQ*2 + CNT)
· z := 0
· repeat
··· text.out(0)
··· text.out(13)
··· key.clearkeys
··· y := y + 1
··· text.dec(y)
··· readadc
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
There is no forground, the cogs are independant processors so if you start a cog from another cog then you end up with both running at the same time. What you need to do is put the cog that starts the second cog in a loop waiting for the second cog to do it's business and finish.
So you just need a flag that the second variable can set to say it is finished before doing its cogstop (or the end of the code), the first cog detects it has finished and moves on from the waiting loop.
Graham
Myself I've wanted to know how many cogs my two Props are using. So....
Since I'm using a TV monitor with TV_text to view variables during debugging I've included a heading for each Prop which, from the source of each, includes the text with date, Prop version#, and also post id value for each (see attached). This has changed recently, but illustrates what I'm describing. Also helped me learn a bit more about working with the Prop. Props communicate at 115200 baud.
Since I've been using ViewPort and PASD for debugging I didn't like counting cogs each time I changed setups. Running near to 8 cogs in each Prop at times.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
PUB menu
· z := 0
· text.str(string("CogID is "))
· text.dec(cogid)
· waitcnt(clkfreq*5 + cnt)
and the screen said:
CogID = 0
Can that be right?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Graham
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
One could also just use two displays at once! Connect two displays, and just let both COGs do their thing. This consumes pins and is limited by the amount of RAM.
Or, if you are using one display, you could have any of the cogs write to the display buffer. In this case, you've one COG building the display for the monitor, and other COGs writing to the display buffer. The only real limitation here is making sure those writes make sense, through inter-COG coordination. If you are drawing lots of stuff, then performing writes during the vertical blank interval is a good idea to cut tearing and flicker on moving objects. Menus and such can ignore this.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
I can see what you want to do but personally I would try to keep the menus at in one cog even if the programs they control are in other cogs otherwise you could be heading for much complexity.
Graham
Someday, just in case, I need to find out how to start a new cog and display its ID.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
So why do you not use this obvious program to do what - according to how I interpret your question - you probably want to do... though I am not sure...
2. Have the code COGINIT to reload it's own COG with new code
3. Access COG-specific data from a buffer used by multiple COGs.
I used #3 in my (badly broken) multi-COG NTSC driver.· Multiple COGs were started using the same code block, but each COG needed to know whether it was the first, second, or Nth COG so it could properly synchronize with the other COGs.
cogid0num[noparse]/noparse was towards the end of the 496 longs loaded
·
I agree that it is a little bit more comfortable to learn that number from the hardware ( by the result of COGNEW at the main COG and by COGID at the slave COG)
Using COG-IDs can be helpful when you start multiple instances of the same code, trying to simplify the management of those COGs.
The main reason why you generally do not need the COG-ID is that there is ONLY ONE operation that requires it: COGSTOP.
Yes, I noticed #2, but this is what I should call "one of a few cases"
But I do not want to split hairs...
Post Edited (deSilva) : 10/12/2007 9:33:12 PM GMT