1 -- Single port Block RAM with one cycle output buffer
4 use ieee.std_logic_1164.all;
5 use ieee.numeric_std.all;
12 WIDTH : natural := 64;
13 HEIGHT_BITS : natural := 1024;
14 MEMORY_SIZE : natural := 65536;
15 RAM_INIT_FILE : string
19 addr : in std_logic_vector(HEIGHT_BITS - 1 downto 0) ;
20 di : in std_logic_vector(WIDTH-1 downto 0);
21 do : out std_logic_vector(WIDTH-1 downto 0);
22 sel : in std_logic_vector((WIDTH/8)-1 downto 0);
28 architecture behaviour of main_bram is
30 constant WIDTH_BYTES : natural := WIDTH / 8;
32 -- RAM type definition
33 type ram_t is array(0 to (MEMORY_SIZE / WIDTH_BYTES) - 1) of std_logic_vector(WIDTH-1 downto 0);
36 impure function init_ram(name : STRING) return ram_t is
37 file ram_file : text open read_mode is name;
38 variable ram_line : line;
39 variable temp_word : std_logic_vector(WIDTH-1 downto 0);
40 variable temp_ram : ram_t := (others => (others => '0'));
42 for i in 0 to (MEMORY_SIZE / WIDTH_BYTES) - 1 loop
43 exit when endfile(ram_file);
44 readline(ram_file, ram_line);
45 hread(ram_line, temp_word);
46 temp_ram(i) := temp_word;
53 signal memory : ram_t := init_ram(RAM_INIT_FILE);
54 attribute ram_style : string;
55 attribute ram_style of memory : signal is "block";
56 attribute ram_decomp : string;
57 attribute ram_decomp of memory : signal is "power";
60 signal obuf : std_logic_vector(WIDTH-1 downto 0);
63 -- Actual RAM template
64 memory_0: process(clk)
66 if rising_edge(clk) then
70 memory(to_integer(unsigned(addr)))((i + 1) * 8 - 1 downto i * 8) <=
71 di((i + 1) * 8 - 1 downto i * 8);
76 obuf <= memory(to_integer(unsigned(addr)));
82 end architecture behaviour;