spartan3e: BRAM gehaxe. lesbarer und wird auch richtig(er) instanziert
[calu.git] / cpu / src / ram_xilinx_b.vhd
1 library ieee;
2
3 use IEEE.std_logic_1164.all;
4 use IEEE.numeric_std.all;
5
6 use work.common_pkg.all;
7 use work.mem_pkg.all;
8
9 architecture behaviour of ram_xilinx is
10         type word_t is array (0 to 3) of std_logic_vector(7 downto 0);
11         subtype stfu_t is std_logic_vector(BYTE_WIDTH-1 downto 0);
12         type ram_t is array (0 to (2**ADDR_WIDTH)-1) of stfu_t;
13         signal ram0 : ram_t := (others => x"00");
14         signal ram1 : ram_t := (others => x"00");
15         signal ram2 : ram_t := (others => x"00");
16         signal ram3 : ram_t := (others => x"00");
17         signal q_local : word_t;
18
19 begin -- Re-organize the read data from the RAM to match the output
20         unpack: for i in 0 to 3 generate
21                 q(8*(i+1) - 1 downto 8*i) <= q_local(i);
22         end generate unpack;
23
24         process(clk)
25         begin
26                 if(rising_edge(clk)) then
27                         if(we = '1') then
28                                 if(be(0) = '1') then
29                                         ram0(to_integer(UNSIGNED(waddr))) <= wdata(7 downto 0);
30                                 end if;
31                                 if be(1) = '1' then
32                                         ram1(to_integer(UNSIGNED(waddr))) <= wdata(15 downto 8);
33                                 end if;
34                                 if be(2) = '1' then
35                                         ram2(to_integer(UNSIGNED(waddr))) <= wdata(23 downto 16);
36                                 end if;
37                                 if be(3) = '1' then
38                                         ram3(to_integer(UNSIGNED(waddr))) <= wdata(31 downto 24);
39                                 end if;
40                         end if;
41                         q_local(0) <= ram0(to_integer(UNSIGNED(raddr)));
42                         q_local(1) <= ram1(to_integer(UNSIGNED(raddr)));
43                         q_local(2) <= ram2(to_integer(UNSIGNED(raddr)));
44                         q_local(3) <= ram3(to_integer(UNSIGNED(raddr)));
45                 end if;
46         end process;
47         
48 end architecture behaviour;