Shop OBEX P1 Docs P2 Docs Learn Events
Need info on prop Stack/memory not quite sure I understand — Parallax Forums

Need info on prop Stack/memory not quite sure I understand

mikedivmikediv Posts: 825
edited 2008-12-17 21:19 in Propeller 1
Guys I am finishing up the methods and cogs class, but I am a bit confused about the stack, when assigning stack space for the cog methods is the stack actually memory space? say I use the cognew or coginit I want to do somehting really simple like turn on an led on P0 using one cog then P1 using a second cog and P3 using a 3 cog on so on why do they number it as Stack0, stack10, stack20 what is the meaning of 0,10,20??? and is the stack space you asine actually mean the ram you need for the program or method?? in its not the memory how do I setup the stack and how would I know how big to make it? if thats the right way to think of it. Second part
I am trying to figure out how to use the cogs in parallel to run some small programs to help me understand how to use the prop to run a bunch of programs all at once , the way I understand it the cogs are adresed serialy anyway right?
meaning the code runs linear cog,0,cog1,cog2 and so on or can they all run all at the same time reading and writing I/O
and not to complicate my questions but what if I have the cogs running I/O and 3 of the cogs will need to access P5 to read an input is this possible or am I complicating matters and confusing myself? Thanks guys.
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-17 18:50
    1) Each cog running the Spin interpreter (ie: running a Spin routine) requires a stack for return addresses for calls, temporary variables, local declared variables, etc. The COGNEW/COGINIT call passes the address of an area to be used for that stack. Sample programs have all sorts of naming conventions for these areas if there is more than one. The actual name doesn't matter. "foobah" will work just as well. A good starting point for the stack size is 20 longs. It all depends on what you're running and what routines that calls and what local variables those have.

    2) The cogs do run independently and at the same time (unless they're accessing the shared (hub) memory). Each cog gets one turn at accessing shared memory every hub cycle (once every 200ns at an 80MHz clock). If the program is written in Spin (as opposed to assembly language), there's nearly constant access to shared memory since that's where the Spin program and variables are located, so it's a little more complicated. Several cogs can refer to the same I/O pin at the same time and there's logic to sort that out. Output mode takes priority over input mode and output high takes priority over output low. If all cogs are using an I/O pin as an input (the default), they can all read it simultaneously.
  • mikedivmikediv Posts: 825
    edited 2008-12-17 21:08
    Thank you Mike, just to clarify beside assigning stack space long=32 right do I also assign memory space I know I only have 32K ram or do I just let the program take what it needs of the 32K this is where I am having trouble understanding stack space versus memory for the cog program.
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-17 21:19
    Look at the examples in the Propeller Manual for the COGNEW/COGINIT statements and at the examples in the Propeller Education Kit tutorials.· The stack area for the default cog is the shared memory space from the end of the program to the end of memory.· Other cogs have to have array variables declared which also is in the shared memory space, but within the area occupied by the program's other variables.· The address of the first long in the array for the stack is what is passed to the Spin interpreter in the new cog.
Sign In or Register to comment.