Indeterminate cog termination with asm
BradC
Posts: 2,601
Have a _very_ simple program below that toggles a pin on 5 sec intervals in its own cog.
If I leave out the cogid and cogstop commands, it leaves the output pin enabled and set high.
I guess the space after the compiled program is being loaded with indeterminate data and the program gets stuck somewhere now allowing the cog to terminate.
Trap for young players.. (ie. me)
Anyone had a crack at low speed USB on the Prop yet? I'm beating my head against a a wall, but I'll get there unless someone beats me to it.
PUB Start : OK
OK := cognew(@enablecog, 0)
DAT
enablecog org
cogid cog
mov dira, #4
mov outa, #4
mov loop, #5
mov delay, cnt
add delay, Second
eloop waitcnt delay, Second
mov outa, #0
waitcnt delay, Second
mov outa, #4
djnz loop, #eloop
cogstop cog
loop long 5
Second long $17D78400
delay res 1
cog res 1
If I leave out the cogid and cogstop commands, it leaves the output pin enabled and set high.
I guess the space after the compiled program is being loaded with indeterminate data and the program gets stuck somewhere now allowing the cog to terminate.
Trap for young players.. (ie. me)
Anyone had a crack at low speed USB on the Prop yet? I'm beating my head against a a wall, but I'll get there unless someone beats me to it.
PUB Start : OK
OK := cognew(@enablecog, 0)
DAT
enablecog org
cogid cog
mov dira, #4
mov outa, #4
mov loop, #5
mov delay, cnt
add delay, Second
eloop waitcnt delay, Second
mov outa, #0
waitcnt delay, Second
mov outa, #4
djnz loop, #eloop
cogstop cog
loop long 5
Second long $17D78400
delay res 1
cog res 1
Comments
[noparse][[/noparse] code]
and
[noparse][[/noparse] /code]
The COGID/COGSTOP combination is the best because it makes the cog available for others to use. You can put a "jump to self" which lets the cog run at full speed or you can do a WAITCNT in a loop so the cog spends most of its time in a low power mode.
For many practical uses, the cog is left to periodically check HUB memory for a command from some other part of the program so it looks for something new to do. Many of the I/O drivers work this way. They run mostly continuously looking for something to do whether an I/O pin change or some data left in a buffer for it to process.
Having thought (there it is again!) about it a little harder I guess that only relates to spin. Asm is going to keep on grinding until you stop it.
I don't often stop cogs actually, most of mine are kept pretty busy shuffling bits around, but in this case I'm debugging something and after 5 attempts (the "pull the pin high for 5 seconds") I decided to stop harassing the host and give it a rest. Rather than loop for eternity I thought I'd try and stop the cog. Mission accomplished.
I can see I'm going to need to try some of the scope objects for this so I can see what is actually going on. I'm only using 3 cogs at the moment in any case.