asm coginit
Delus
Posts: 79
I'm some what new to prop asm and am trying to convert a spin program a wrote to asm.· Everything is working when i start all the cogs in spin but i can't seem to figure out how to get a cog to start in asm.· If anyone has an example of this it would be greatly apreciated.· I am starting each cog with a given id so i don't need to get the id of the started cog back.
Thanks in advance.
Thanks in advance.
Comments
If you're starting an assembly cog from Spin, use the COGNEW statement. There's an example on page 191 of the Propeller Manual.
If you're starting an assembly cog from assembly, use the COGINIT instruction with the NEW bit set in the operand (page 366).
sorry if this is a bit long winded and/or confusing I will post my code once I get back and clean it up a bit.
(changed to shifting by 14 and 2 bits but still no luck)
Post Edited (Delus) : 11/27/2008 6:47:14 PM GMT
cognr, cogaddr and cogpar are registers which saves the id, the startaddress and the parameter value to pass to the new cog.
cogaddr and cogpar must have the lower 2 bits cleared (long aligned addresses).
Andy
here's the code:
var
long waitTime
pub main
waitTime := 5_000_000
coginit(0, @mainEntry, @waittime)
'blinkTest
pri blinkTest
dira[noparse][[/noparse]12] := 1
repeat
if outa[noparse][[/noparse]12] == 0
outa[noparse][[/noparse]12] := 1
else
outa[noparse][[/noparse]12] := 0
waitcnt(5_000_000+cnt)
dat
org
mainEntry
mov parameter, par
mov cID, #1
mov cInitDest, #0
and parameter, Mask14Bit
shl Parameter, #14
or cInitDest, parameter
and BlinkEnt, Mask14Bit
shl BlinkEnt, #2
or cInitDest, BlinkEnt
or cInitDest, cID
coginit cInitDest
cInitDest res 1
parameter res 1
cID res 1
BlinkEnt long @blinkTestEntry
Mask14Bit long $00_00_FF_FC
org
blinkTestEntry
mov outpin, #1
shl outpin, #12
mov dira, outpin
rdlong delta, par
mov wait, cnt
add wait, delta
blinkLoop xor outa, outpin
waitcnt wait, delta
jmp #blinkLoop
outpin res 1
delta res 1
wait res 1
this seems to work for a few minutes then the led attached to pin 16 stops blinking and stays lit all the time.(actually after running it a few times it just stops blinking lit or unlit seems random)
ps how do you post code in a box as above?
Post Edited (Delus) : 11/27/2008 7:10:33 PM GMT
BlinkEnt long @blinkTestEntry
this is solved at compile time and gives not the right address for blinkTestEntry (only an object relativ offset)
You can add this to the Spin main routine, before the coginit:
BlinkEnt := @blinkTestEntry
then you have the right address in the BlinkEnt var when the cog is started.
Andy
Instead of
use
here's my current code
[noparse][[/noparse]code]
var
long waitTime
pub main
· waitTime := 5_000_000
· coginit(0, @mainEntry, @waittime)
· 'blinkTest
dat
······· org
mainEntry
······················· mov······ parameter, par
······················· mov······ cID, #1
······················· cogstop cID
······················· mov···· t1, #0
······················· mov···· t1,parameter·············· 'restart cog
······················· shl···· t1,#14
······················· or····· t1,BlinkEnt
······················· shl···· t1,#2
······················· or····· t1,cID
······················· coginit t1
······················· mov······ cID, #0
······················· cogstop·· cID
·············
············· mov······ cInitDest, #0
············· 'and······ parameter, Mask14Bit
············· shl······ Parameter, #14
············· or······· cInitDest, parameter
············· 'and······ BlinkEnt, Mask14Bit
············· shl······ BlinkEnt, #2
············· or······· cInitDest, BlinkEnt
············· or······· cInitDest, cID
············· coginit·· cInitDest
············· mov······ cID, #0
············· cogstop·· cID
····················
BlinkEnt····· long····· @blinkTestEntry
Mask14Bit···· long····· $00_00_FF_FC
t1··········· res 1···········
cInitDest···· res 1
parameter···· res 1···················
cID·········· res 1····································
············· org
blinkTestEntry
············· mov······ outpin, #1
············· shl······ outpin, #12
············· mov······ dira, outpin
············· mov······ wait, cnt
············· add······ wait, delta
blinkLoop···· xor······ outa, outpin
············· waitcnt·· wait, delta
············· jmp······ #blinkLoop
·············
delta········ long····· 5_000_000
outpin······· res 1·············
wait········· res 1
[noparse][[/noparse]/code]
Post Edited (Delus) : 11/27/2008 10:52:09 PM GMT
and i can't get the code box to work on this form arg!
1. Remove the cogstop instruction. As you stop #1 you're usually stopping yourself (spin starts on #0, so cognew will most likely run mainEntry in #1).
2. The current compiler miscalculates function addresses, use @Toggle + $10 instead.
3. If you want to toggle pin 16 use |< 16 not |< 12
4. Get used to not using absolute cog IDs [noparse]:)[/noparse]
Andy
only works for
coginit(2,@mainEntry,0) 'Launch new cog
and
coginit(3,@mainEntry,0) 'Launch new cog
i understand that 2 will restart the cog which launches the other cogs and thus only blinks one led but why do 0, 1, and 3-7 not work?
yes i know it's best practice to let the prop choose which cog to start but this is a curious outcome
Post Edited (Delus) : 12/21/2008 6:54:31 AM GMT
Why are you so keen about using cogINIT instead of cogNEW ?
all eight cogs are EXACTLY the same. So it does't matter which cog you use for what.
As Mike already mentioned it's more buggy to use coginit than cognew
best regards
Stefan
Well, bit 3 (%1000) makes all the difference. If set coginit becomes cognew (see prop manual p.366).