blob: 8ec8e080764eb1a22d47718172d5a1fe5ed43fa1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
-- A RAM initialized with an external file
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use STD.textio.all;
entity ram is
port(
clk_i : in std_logic;
we_i : in std_logic;
addr_i : in std_logic_vector(5 downto 0);
data_i : in std_logic_vector(31 downto 0);
data_o : out std_logic_vector(31 downto 0)
);
end ram;
architecture RTL of ram is
type mem_t is array (0 to 63) of bit_vector(31 downto 0);
impure function init(filename : in string) return mem_t is
file fh : text is in filename;
variable l : line;
variable mem : mem_t;
begin
for i in mem_t'range loop
readline(fh, l);
read(l, mem(i));
end loop;
return mem;
end function;
signal ram : mem_t := init("data/memory.dat");
begin
memory:
process(clk_i)
begin
if rising_edge(clk_i) then
if we_i = '1' then
ram(to_integer(unsigned(addr_i))) <= to_bitvector(data_i);
end if;
data_o <= to_stdlogicvector(ram(to_integer(unsigned(addr_i))));
end if;
end process;
end architecture RTL;
|