Purpose of "Stop" method?
lardom
Posts: 1,659
I ran into a problem trying to find a way to 'restart' a cog after I used cogstop(1). The only way I could get the repeat loop to run was to comment out the "Stop" method call. Why is this?
Parent object:
Child object:
Parent object:
OBJ ct : "CognewTest" PUB main dira[11]~~ repeat ct.Start waitcnt(clkfreq + cnt) cogstop(1) waitcnt(clkfreq + cnt)
Child object:
VAR long stack[6] byte cog PUB Start : success ' Stop 'remove the cogstop command to restart the cog success := cog := cognew(main, @stack + 1) PUB Stop if cog cogstop(cog~ - 1) Pub main dira[11]~~ repeat 200 outa[11]~~ waitcnt(clkfreq/10 + cnt) outa[11]~ waitcnt(clkfreq/10 + cnt)
Comments
Normally, the bootloader uses cog 0, then starts the program using the same cog with all other cogs stopped. If, for some reason, you use some other mechanism to start up your program, like loading it from an SD card using some kind of other loader, all bets are off. Your program could start up in any cog. For most situations, they're all identical.
@Mike Green, I replaced cogstop(1) with cogstop(ct.Start) and cogstop(ct.main) but that did not stop the cog. I see the danger of resource conflicts. (I did not try cogstop(ct.Stop) but I'm not through experimenting.)
In the modified code below, which works, I subtracted "1". I'm assuming the remainder will always equal cogid. I'm going to test it by restarting several cogs.
(BTW, I did admit I was dense!)