Shop OBEX P1 Docs P2 Docs Learn Events
multiple cognew command problem — Parallax Forums

multiple cognew command problem

fireman508fireman508 Posts: 19
edited 2011-01-09 17:04 in Propeller 1
Hello,

I'm having a problem with the cognew command. Every time I run my code below, only the first cog (temp.main) initializes and none of the code following it is run. The code is supposed to start a new cog and then display a number to confirm that it started. I'm not sure if this is simply how the cognew function works or if my coding is wrong, but I ran it once in the past and all 5 cogs started no problem. Any help or advice would be greatly appreciated. Thanks!


CON

_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

pin = 9
baud = 19_200
lines = 2

VAR

LONG TEMP0[9]
LONG PRESS0[9]
LONG CLOCK0[9]
LONG USB0[9]
LONG CAM0[9]
LONG JAR0[9]

BYTE START0
BYTE START1
BYTE START2
BYTE START3
BYTE START4
BYTE START5

OBJ

LCD : "Serial_Lcd.spin"
TEMP : "TEMP.spin"
PRESS : "PRESS.spin"
USB : "USB.spin"
CAM : "CAM.spin"
JAR : "JAR.spin"
CLOCK : "CLOCK.spin"

PUB MAIN

LCD.start(pin, baud, lines)
waitcnt(clkfreq / 100 + cnt)
LCD.backlight(1)
LCD.cursor(3)
LCD.cls
LCD.STR(STRING("STARTING COGS..."))
LCD.NEWLINE

START0 := COGNEW(TEMP.MAIN(1), @TEMP0)

IF START0
LCD.PUTC(9)
LCD.DEC(0)
START1 := COGNEW(PRESS.MAIN, @PRESS0)

IF START1
LCD.PUTC(9)
LCD.DEC(1)
START2 := COGNEW(CLOCK.MAIN(1), @CLOCK0)

IF START2
LCD.PUTC(9)
LCD.DEC(2)
START3 := COGNEW(USB.MAIN(1), @USB0)

IF START3
LCD.PUTC(9)
LCD.DEC(3)
START4 := COGNEW(CAM.MAIN, @CAM0)

IF START4
LCD.PUTC(9)
LCD.DEC(4)
START5 := COGNEW(JAR.MAIN, @JAR0)

IF START5
LCD.PUTC(9)
LCD.DEC(5)
LCD.STOP

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-01-04 20:01
    You can't start spin methods in a new cog by using cognew(object.method, stackAddress). Valid/acceptable methods have to be in the same SPIN file. The above call will start a PASM cog whose code block address is the return value of the object.method call.

    So you're better off embedding the cognew inside the relevant main methods.

    Also, readability is improved by embedding your code sample in [noparse]
    
    [/noparse] tags.                        
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-05 02:56
    Same answer, only in other words:

    All your objects should have a start method which contains the COGNEW.
    The main you posted here would simply call these start methods instead of doing the COGNEW.
    I'd also shift the stack to the object as you can then maintain it's size in case you do changes in the object (for example calling additional PRI functions)
    TEMP.SPIN:
    ...
    VAR
      long myStack[9]
    PUB start( par1 )
      return COGNEW( main( par1 ), @myStack )
    ...
    
    Your main:
    ....
    START0 := TEMP.start( 1 )
    ...
    
  • fireman508fireman508 Posts: 19
    edited 2011-01-09 17:04
    Thanks for the info! I finally managed to get it to work!
Sign In or Register to comment.