Shop OBEX P1 Docs P2 Docs Learn Events
Quick Basic Question — Parallax Forums

Quick Basic Question

steprogsteprog Posts: 227
edited 2014-03-22 14:24 in Propeller 1
Hi anyone,
I have been away from using props for a while, but I wanted to run some code in another cog, but I don't want to run in assembly. When you start a new cog all the samples I quickly looked at go to assembly. Any that just point to spin language? any examples out there?
Sorry, in a hurry to finish a project.
Thanks for any help
Greg

Comments

  • r.daneelr.daneel Posts: 96
    edited 2014-03-22 13:57
    Take a look at COGINIT and COGNEW in the Spin manual (pp76-80 in v1.2 of the manual). Both start Spin or Assembly code. There are examples in the manual.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-03-22 14:13
    Here's an example of starting a new cog from code I'm working on.
      result := cognew(ModbusTestCogInit, @modbusTestStack)
    
    
    

    The method "ModbusTestCogInit" starts a continuous loop.

    The variable "result" (it's a "free" local variable in each method) contains the cog's ID number. You could display this number to see which cog was launched (though you don't really have to keep track of this).

    If, in this example, the value of "return" were "-1", then I'd know there weren't any available cogs and the cog had not been successfully launched.

    The array "modbusTestStack" is defined in the VAR section like this.
    VAR  
    
    
      long modbusTestStack[100]
    
    
    

    A stack of 100 is larger than will likely be needed.

    There's discussion and code to determine stack space needed in this thread.

    I personally like my technique of finding stack space better than the alternatives I've seen.

    BTW, Only use cognew. Don't use coginit unless you have a really good reason to do so and really need it. I've never used coginit and I've written a lot of Propeller code.
  • steprogsteprog Posts: 227
    edited 2014-03-22 14:24
    Thanks, got it now.
    Greg
Sign In or Register to comment.