I'm trying to design a memory emulation entity for simulation. To make it as versatile as possible, it uses generics to define data and address widths. Additionally, one should be able to supply an initialization memory image via a third generic:
entity memory is
generic (
DATA_WIDTH : positive;
ADDR_WIDTH : positive;
INIT_DATA : image_t
);
port (
[...]
);
end memory;
Where image_t
would look something like this:
type image_t is
array(0 to (2 ** ADDR_WIDTH - 1)) of
std_logic_vector(DATA_WIDTH-1 downto 0);
But where could I possibly define this type? Entities don't have an is ... begin
block like
architectures that could be used. After reading another question on here,
I've pondered on using a generic package:
package memory_pkg is
generic (
DATA_WIDTH : positive;
ADDR_WIDTH : positive
);
type image_t is
array(0 to (2 ** ADDR_WIDTH - 1)) of
std_logic_vector(DATA_WIDTH-1 downto 0);
end package;
This just moves the problem one level deeper though, because I can't find a way to instantiate the package such that
- it uses the entity generics (possible by instantiating it in the architecture head) AND
- its contents are available in the entity declaration (possible by instantiating it on the file level, before the entity)
So it seems like a dead end. Is there any way (maybe using VHDL-2019) to do what I'm trying to accomplish?