I am writing a model for a serial flash device. I wonder how do I best model the internal memory? I would like the memory size to be configurable by the user since I intend to reuse this model for different serial flashes. It also needs to retain its content upon reset while the rest of the logic is reset.
I tried using a statically allocated character buffer but that is not configurable and seems very inappropriate for such large sizes as my flash model. My flash model is 512 MB.
saved char flash_image[512 * 1024 * 1024];
Assuming this will go into Simics, it is best modeled with two subobjects, both of which are available in Simics Base.
The first is an
imagewhich stores the actual data, the second is aramwhich is used to read/write into the image. Both theimageand theramare connects using theinit_as_subobjtemplate which makes Simics automatically create them as sub-objects of the device. They are placed in a group where we can add aninitmethod, which sets default values for the required attributes of the subobjects; in this case the "size" of the image and the "image" of the ram.The
ramobject also uses themap_targettemplate, which gives us useful methods for reading and writing into the ram.The size of the image is given a default value by a parameter in this example, but it can also be set or overridden by the user when creating the object, by assigning to the attribute
flash.image.size, e.g. like this: