Usage of COGs
S1976
Posts: 6
Hi all,
i have a basic question about the usage of Cogs loaded with assembly code within a SPIN program and i have difficulties to understand what´s going on. For example, i wortee some assembly code after a DAT statement and load it usual inside a PUB-Statement with Cognew. The main SPIN program itself shoud use the VGA_Text output driver, loaded here as an Object, for debugging purposes. Now i don´t understand how to tell the main program to override creating a new cog, loaded with assembly code
For example:
Same problem (no VGA-output) appears also within a single program only with the VGA_Text-Driver loaded within the OBJ-Line. As soon as a cognew-command appears, the main program stops. Is it because the main-Routine always tries to reload and restart the VGA-Driver / resetting the cog or what im doing wrong? Or does the SPIN-main program wait for a statement that the cog is ready?
Many thanks!
Stefan
i have a basic question about the usage of Cogs loaded with assembly code within a SPIN program and i have difficulties to understand what´s going on. For example, i wortee some assembly code after a DAT statement and load it usual inside a PUB-Statement with Cognew. The main SPIN program itself shoud use the VGA_Text output driver, loaded here as an Object, for debugging purposes. Now i don´t understand how to tell the main program to override creating a new cog, loaded with assembly code
For example:
con _clkmode=xtal1+pll16x _xinfreq=5_000_000 OBJ vg: "VGA_Text" ' the usual VGA_Text driver vl: "test" 'My assembly Code pub main vl.start 'calls the test.start Routine which consists of creating a new Cog and loading its ASM Code, usually the cog points then to "entry org....[noparse][[/noparse]ASM Code]" vg.start(16) 'should start the VGA driver vg.out("t") 'For testing, but it does nothing
Same problem (no VGA-output) appears also within a single program only with the VGA_Text-Driver loaded within the OBJ-Line. As soon as a cognew-command appears, the main program stops. Is it because the main-Routine always tries to reload and restart the VGA-Driver / resetting the cog or what im doing wrong? Or does the SPIN-main program wait for a statement that the cog is ready?
Many thanks!
Stefan
Comments
Try it with an empty repeat-loop after vg.out.
Makes sense, as usually each program has a main-loop.
By the way ... if you do PASM code ... you should always do a COGSTOP if your PASM code is not looping! Unlike SPIN a PASM code does not have an implicit return. PASM without a loop and without a COGSTOP can do anything ... for example variables will be executed like being instructions ... SPIN or PASM code following your PASM will be executed (in case the PASM section you started is smaller than 512 longs) ... Special function registers will be executed (for example whatever is currently found in INA ) ...
So, you can have lot's of fun when you don't keep the COG running inside of your code ... including destroying pins because they are switched from input to output.
That's not as serious as you make it sound. Instructions are fetched from the shadow location if applicable (which is unfortunate as fetching from phsx would be quite useful). So the most dangerous thing here is usually the dira/outa content.
INA ... ok ... same trap as usual ... shadow registers ... I wonder when I'll learn this lesson ;o)
We also don't know what his custom object does.
If I start VGA_Text in cog #0 and just return from the main method the VGA cog stays alive (i.e. I keep getting sync pulses on the demoboard).
Post Edited (kuroneko) : 3/30/2010 8:55:48 AM GMT