Memory class
Hi,
While trying to optimize some classes I realized I usually define some
abstract class and extending that class for SystemRam, SystemEeprom and
I2Ceeprom to support multiple memory types. This I did for many data
classes. I reduced the number of my classes by writing a memory class
http://groups.yahoo.com/group/javelinstamp/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/memory/
So instead of an abstract class plus extended classes per datatype, I can
now define a class, passing a memory object to its constructor. Only·one
extended memory class per memory type is required. Memory objects for
SystemRam, SystemEeprom and I2C memory chips are provided, plus a
BitArray class.
The second advantage is that I·can now easily use unions (as in C, same
memory space holds different datatypes at different times) by simply passing
a memory object to some class, based upon a·value at a known location in
the memory object that serves as an union· This is useful to reduce runtime
ram requirements and also to reuse memory.
regards peter
·
While trying to optimize some classes I realized I usually define some
abstract class and extending that class for SystemRam, SystemEeprom and
I2Ceeprom to support multiple memory types. This I did for many data
classes. I reduced the number of my classes by writing a memory class
http://groups.yahoo.com/group/javelinstamp/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/memory/
So instead of an abstract class plus extended classes per datatype, I can
now define a class, passing a memory object to its constructor. Only·one
extended memory class per memory type is required. Memory objects for
SystemRam, SystemEeprom and I2C memory chips are provided, plus a
BitArray class.
The second advantage is that I·can now easily use unions (as in C, same
memory space holds different datatypes at different times) by simply passing
a memory object to some class, based upon a·value at a known location in
the memory object that serves as an union· This is useful to reduce runtime
ram requirements and also to reuse memory.
regards peter
·
Comments
Do you have any example code of using the memory class to create·unions? I was hoping to do this very thing and found your posting here.
a Memory object.
For example, you can define a global ram char array
static char[noparse]/noparse myMemory = new char[noparse][[/noparse]256]; //256 bytes of ram
static SystemRam myRam = new SystemRam(myMemory,0,256); //make it a memory object
static Block blk1 = new Block(myRam,0,128); //first field
static Block blk2 = new Block(myRam,128,128); //second field
Note that myRam, blk1 and blk2 are all of type Memory and they physically
share the same ram locations, so myRam is just like a union.
You can use the BitArray class to access the bits of a Memory object.
regards peter
Post Edited (Peter Verkaik) : 5/19/2006 10:33:09 PM GMT
I have the memory classes downloaded and have instantiated the different blocks, as follows:
··· public static char[noparse]/noparse IOMemory = new char[noparse][[/noparse]64]; //64 bytes of ram
··· public static SystemRam IORam = new SystemRam(IOMemory,0,64); //make it a memory object
··· public static Block DOMem = new Block(IORam,17,1); //fifth field
Now I want to assign values to them·but I·am getting error messages that either say <The type of expression "Block" is not an array type> for this code:·········DOMem[noparse][[/noparse]0]=(char)j;
or <The type of the left-hand side"stamp/peripheral/memory/Block", is not compatible with the right hand "char"> for this code:·········DOMem=(char)j;
I'm not clear how·I assign values to this memory and/or reference·their values?
Thanks for your assistance.
eg. readByte(), writeByte(), readArray() and writeArray().
regards peter
··· public static char[noparse]/noparse IOMem = new char[noparse][[/noparse]64]; //64 bytes of ram
··· final static int DO = 17; //fifth field
...
······· IOMem[noparse][[/noparse]DO]=(char)j;
I am trying to use this chip for real-time control and its so slow to begin with that every added instruction and object instantiation just bogs it down further. The lure of Java got the project hooked before understanding the speed limitations of the chip.
Thanks for your assistance to this forum.
SIPI Robotics
I wrote the class to support equal/simultaneous datastructures
in system ram, system eeprom·and I2C memory using·a single class (Table classes).
That saved a lot of code space because only the read/write
methods are different for different memory types.
It also allows you to define a virtual lineair memory consisting of
different memory types. I once included the 56 ram bytes of a
DS1307 in a 128byte array together with·system eeprom bytes.
regards peter