Understanding the memory of the Propeller
lassethomsen
Posts: 46
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
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
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.
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
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.
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
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.
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.
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?
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.
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.
·
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.
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?
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.
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 ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Parallax Forums - If you're ready to learn, we're ready to help.