S
Shannon
Guest
I have a generic RAM entity:
entity ram is
generic
(
DATA_WIDTH : natural := 10;
ADDR_WIDTH : natural := 10
);
port
(
clk : in std_logic;
addr : in natural range 0 to 2**ADDR_WIDTH - 1;
data : in std_logic_vector((DATA_WIDTH-1) downto 0);
we : in std_logic := '1';
q : out std_logic_vector((DATA_WIDTH -1) downto 0)
);
end entity;
architecture rtl of ram is
subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
type memory_t is array(2**ADDR_WIDTH - 1 downto 0) of word_t;
signal ram : memory_t;
signal addr_reg : natural range 0 to 2**ADDR_WIDTH - 1;
begin
process(clk)
begin
if(rising_edge(clk)) then
if(we = '1') then
ram(addr) <= data;
end if;
addr_reg <= addr;
end if;
end process;
q <= ram(addr_reg);
end rtl;
In my top level I create two instances of this ram with different data
widths and addr width.
So far so good.
Now I want to initialize these two rams when I program them in-
circuit. For a single ram, Quartus wants you to add to the
architecture:
attribute ram_init_file : string;
attribute ram_init_file of ram : signal is "ram.mif";
Where "ram.mif" is the initialization file. My problem is that this
must go in the architecture declaration section or the ram entity. Is
there a way to do this at the top level so that I don't have to create
two separate ram entities?
It looks like I'm going to add a third and possibly fourth ram. I
would really like to only have one generic ram entity yet have the
four instances all initialized with separate data files.
I hope my question is clear.
Shannon
entity ram is
generic
(
DATA_WIDTH : natural := 10;
ADDR_WIDTH : natural := 10
);
port
(
clk : in std_logic;
addr : in natural range 0 to 2**ADDR_WIDTH - 1;
data : in std_logic_vector((DATA_WIDTH-1) downto 0);
we : in std_logic := '1';
q : out std_logic_vector((DATA_WIDTH -1) downto 0)
);
end entity;
architecture rtl of ram is
subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
type memory_t is array(2**ADDR_WIDTH - 1 downto 0) of word_t;
signal ram : memory_t;
signal addr_reg : natural range 0 to 2**ADDR_WIDTH - 1;
begin
process(clk)
begin
if(rising_edge(clk)) then
if(we = '1') then
ram(addr) <= data;
end if;
addr_reg <= addr;
end if;
end process;
q <= ram(addr_reg);
end rtl;
In my top level I create two instances of this ram with different data
widths and addr width.
So far so good.
Now I want to initialize these two rams when I program them in-
circuit. For a single ram, Quartus wants you to add to the
architecture:
attribute ram_init_file : string;
attribute ram_init_file of ram : signal is "ram.mif";
Where "ram.mif" is the initialization file. My problem is that this
must go in the architecture declaration section or the ram entity. Is
there a way to do this at the top level so that I don't have to create
two separate ram entities?
It looks like I'm going to add a third and possibly fourth ram. I
would really like to only have one generic ram entity yet have the
four instances all initialized with separate data files.
I hope my question is clear.
Shannon