Weird cog starting issue
Gregg Harrington
Posts: 16
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
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 Abshier
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.
.. COGNEW( ..., @xbeeMonitorStack + 3 )
Cheers,
Gregg