Shop OBEX P1 Docs P2 Docs Learn Events
Understanding the memory of the Propeller — Parallax Forums

Understanding the memory of the Propeller

lassethomsenlassethomsen Posts: 46
edited 2007-04-29 23:08 in Propeller 1
Hi.

Im trying the get my head fixed on the memory on the Propeller chip.

On every Cog there is 2Kb RAM so for Cog RAM there is a total og 16kb.
Besides the Cog RAM there is the Hub RAM.

But which data i stored in the Cog RAM and which in the Hub RAM?

How can i store data in Cog RAM?
How can i store data in Hub RAM?

If i store data in Hub RAM, can i then share it with other parts of the system? With something like at "data"object, that is a sort of singleton?

Post Edited (lassethomsen) : 4/29/2007 6:52:50 PM GMT

Comments

  • lassethomsenlassethomsen Posts: 46
    edited 2007-04-29 18:53
    If i create a variable in my software like this:

    leg3home = 1200

    What size is the variable? Type? It cant be a byte since max value for a byte is 255, so then what is it?

    BTW im using SPIN.

    I have been looking in the propeller manual for these things but i just cant seem to find it.
  • KC8DKTKC8DKT Posts: 76
    edited 2007-04-29 21:26
    As you have it "leg3home = 1200" would be a CON not a VAR. If you need a var then it would be


    Var
    · word leg3home

    Pub
    · leg3home := 1200


    Check out the "Propeller Programming Tutorial" in the manual.·· Exercide 2 starts working with CONs and gives you ALL of the "Block Designators"

    Post Edited (KC8DKT) : 4/29/2007 9:32:23 PM GMT
  • lassethomsenlassethomsen Posts: 46
    edited 2007-04-29 21:44
    Exc 2. dosnt tell me what the size of the constant is.

    CON
    PIN = 16

    Pub
    'do something with PIN

    So i would like to now what default type the constant is, if i dont specify word/byte/etc. Same with VAR. and the local variables defined in the functions scope, do they have a default size/type?
    And where in the memory is my PIN constant saved etc. They are calling it local / global variables, but that dosnt imply to me that they are placed in Cog ram og Hub Ram.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-04-29 21:59
    For a constant very instance of pin would be changed to 16 as if you had done it manually so it is within the program itself.

    Var are global and are in the hub ram because that can be accessed by all cogs.

    Local variables are in cog ram as are those defined in the DAT block.

    Graham
  • lassethomsenlassethomsen Posts: 46
    edited 2007-04-29 22:01
    thanks.

    if have have code like this:

    pub function(ipin) | pin
    pin := ipin

    Then what size would pin be? Because i could pass a value that was a large as a long and as small as a byte. So my guess would be that its a long, just to make sure there is enough room for my data.
  • CJCJ Posts: 470
    edited 2007-04-29 22:03
    constants are 32 bit and they are resolved at compile time, the value of the constant is put wherever the constant is used

    CON
    pin = 16

    PUB
    outa[noparse][[/noparse]pin]~~ 'set the output for the pin high
    dira[noparse][[/noparse]pin]~~ 'set the pin direction to output

    Variables are declared using the byte/word/long keywords
    VAR
    byte cog 'declare a byte sized variable named cog
    word servo1 'word sized named servo1
    long egg 'long sized named egg

    these are all located in hub ram


    the only way to store anything in cog ram is as part of an assembly program that is launched into the cog
    a copy of the assembly program resides in hub ram

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • lassethomsenlassethomsen Posts: 46
    edited 2007-04-29 22:04
    So to sum it up, and make sure i have understood it.

    DAT block and local variables like the | pin is stored in Cog ram.

    CON VAR and OBJ is stored in Hub ram.

    If i have something stored in a VAR block, how can i then access from outside the object?
  • CJCJ Posts: 470
    edited 2007-04-29 22:13
    you would pass the address of the var using the "@" operator

    someprocedure(@variable)

    then in that method, you would use the address with a variant of the long/word/byte keyword in the place you would use the variable

    someprocedure(var_addr)
    long[noparse][[/noparse]var_addr] := 56 ' just an example

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • mirrormirror Posts: 322
    edited 2007-04-29 22:15
    CJ said...


    Variables are declared using the byte/word/long keywords
    VAR
    byte cog 'declare a byte sized variable named cog
    word servo1 'word sized named servo1
    long egg 'long sized named egg

    these are all located in hub ram

    Just watch out for the warning in the manual about this though. The sequence as given will be compiled into memory as:
    VAR
    · long egg
    · word serve1
    · byte cog

    The long are placed first, then the words, then the bytes. This is so that the longs are longs are longword aligned.

    While all this wont matter if you're just accessing the variables, it will make a MASSIVE amount of difference if you pass the address of "servo1" to an assembly routine, and in that assembly routine try and access "egg" by adding 2 to the passed in memory pointer.

    ·
  • CJCJ Posts: 470
    edited 2007-04-29 22:21
    everything is stored in hub ram, only when an assembly program is launched, data is copied to cog ram and run.

    CONs are really just aliases for values, so you can use them for settings that are used throughout, and make easy and clean changes to them without having to go through the entire code listing changing each and every instance of it

    edit: good catch, Mirror

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • lassethomsenlassethomsen Posts: 46
    edited 2007-04-29 22:32
    Ok, so to sum it up.

    Only when using af assembly program, stuff goes into Cog Ram.

    In the Propeller manual i says that the DAT block can be combined with assembly stuff, so will DAT blocks always go into Cog ram, or will it be in Cog ram if it includes assembly.
    Or doe the entire program has to be written in assembly to be stored in Cog ram?
  • CJCJ Posts: 470
    edited 2007-04-29 22:55
    DAT is probably the most flexible and can end up being the most complicated section. here's a rundown of what can be done in DAT

    data tables, strings, etc

    assembly programs, when launched into a cog, 496 longs starting at the address specified in the cogXXX() command are copied to the cog and it starts running

    (advanced) global space for use with arrays of one object, VARs are duplicated for each instance, DAT is not



    assembly programs are generally used for low level drivers that need speed/tight timing, rather than whole applications.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • lassethomsenlassethomsen Posts: 46
    edited 2007-04-29 23:01
    Thats very interresting, so if i in my object has a DAT section it can act as a static for this object, hence shared across objects of the same class.

    But if i make a driver in 90% assembly and 10% SPIN (interface proberly) would the hole driver be placed in cog ram or just the 90% of it ?
  • CJCJ Posts: 470
    edited 2007-04-29 23:08
    just the assembly portion, why don't you look at my N64 and Gamecube controller drivers in the object exchange as an example

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
Sign In or Register to comment.