Shop OBEX P1 Docs P2 Docs Learn Events
cognew(spin-method, stack-pointer) ? — Parallax Forums

cognew(spin-method, stack-pointer) ?

Steve NelickSteve Nelick Posts: 25
edited 2006-09-29 10:53 in Propeller 1
When you use the cognew instruction, does the spin-method have to be a local method? When I wrote:

· cognew(OBJ2.SomeMethod, @Stack)

the program compiled, but the program did not work!

To get my program to work I had to add a local method:

· cognew(Method1, @Stack)

PRI Method1
· OBJ2.SomeMethod·


·

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-09-29 05:38
    Yes the Spin method must be local. There is an undocumented feature involving a spin function returning the address of assembly section to be loaded, and this is why an exception isn't thrown by the compiler. I will ask more about this feature tomorrow and share it's details.

    In regards to starting new Spin cogs, only peer level methods may be launched in adherence of the OO concept of encapsulation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Steve NelickSteve Nelick Posts: 25
    edited 2006-09-29 10:53
    Paul, thanks for the information. Following your advice, I moved the cognew instruction from the top-object file to the referenced object file, and that worked. The LED is blinking!

    ________


    {{ TestCognew.spin }}

    OBJ
    OBJ2 : "TestCognewObj"

    PUB Main
    outa[noparse][[/noparse]16]~~
    dira[noparse][[/noparse]16]~~
    OBJ2.Start
    repeat
    !outa[noparse][[/noparse]16]
    waitcnt(12_000_000 + cnt)

    ________

    {{ TestCognewObj.spin }}

    VAR
    long Stack[noparse][[/noparse]10]

    PUB Start
    cognew(SomeMethod, @Stack)

    PUB SomeMethod | n
    repeat
    n++

    ________
Sign In or Register to comment.