Shop OBEX P1 Docs P2 Docs Learn Events
Weird cog starting issue — Parallax Forums

Weird cog starting issue

Gregg HarringtonGregg Harrington Posts: 16
edited 2011-01-09 10:50 in Propeller 1
Hello everyone,

I have found a problem (and the solution), but don't understand what is going on. I am writing a system that uses multiple cogs to manage some state. I start these cogs in the beginning and go about my business. However, I noticed one of the cogs was not starting (using a blinking LED in each cog method for testing).

After hours of testing poking and proding, trying different propellers, different code files I finally found out the problem to be a var section in my code. Here is the var section that works:

VAR
byte mode
byte newModeRequest
byte file_buf [13]
byte file_content[128]
byte xbeeCog
byte xbeeMonitorStack[500]

This one does not work and the cog fails to start entirely!

VAR
byte mode
byte newModeRequest
byte file_buf [13]
byte file_content[128]
byte xbeeMonitorStack[500]
byte xbeeCog

Please note: the only different between these two sections (and weather or not it works or doesn't) is the order of my last two variable declares.

I tried to reproduce this other ways, but as long as the variables were in the right order, it worked.

Anyone every run into something like this?

Thanks,

Gregg

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2011-01-08 16:07
    My guess is that you are putting more than 500 bytes in xbeeMonitorStack and stepping on xbeeCog.

    John Abshier
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-08 17:05
    Looks like an alignment problem for me. Stacks are LONG and you should define it as long! If you fire up the COG with a stack-address that's not long alligned, the variable(s) in front of the stack will be the stack base.
    So in your case the xbeeCOG and the really used stack-address are the same. My guess is that you do something like

    xbeeCOG := COGNEW( xxx, @xbeeMonitorStack ) + 1

    So, as xbeeCOG is equal to the first position of the stack this assignment will overwrite your stack. Don't know what this means for the new COG.
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-09 01:57
    PS: In bed I had the following idea to proof my theory. Use the not working order of VARs and change the COGNEW which uses the xbeeMonitorStack like this

    .. COGNEW( ..., @xbeeMonitorStack + 3 )
  • Gregg HarringtonGregg Harrington Posts: 16
    edited 2011-01-09 10:50
    MagIO2, wonderful! Thank you, I truly thought I was going crazy! I was totally confused there for a while!!! That makes total sense now.

    Cheers,

    Gregg
Sign In or Register to comment.