aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/synth109/ram2.vhdl
blob: 11f093552a827f5fe51136a1fcaee9e7bab1c941 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
library ieee;
use ieee.std_logic_1164.all;

entity ram2 is

  generic (
    WIDTH      : integer := 32;
    SIZE       : integer := 64;
    ADDRWIDTH  : integer := 6
    );

  port (
    clkA   : in  std_logic;
    clkB   : in  std_logic;
    enA    : in  std_logic;
    enB    : in  std_logic;
    weA    : in  std_logic;
    weB    : in  std_logic;
    addrA  : in  std_logic_vector(ADDRWIDTH-1 downto 0);
    addrB  : in  std_logic_vector(ADDRWIDTH-1 downto 0);
    diA    : in  std_logic_vector(WIDTH-1 downto 0);
    diB    : in  std_logic_vector(WIDTH-1 downto 0);
    doA    : out std_logic_vector(WIDTH-1 downto 0);
    doB    : out std_logic_vector(WIDTH-1 downto 0)
    );

end ram2;

library ieee;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

architecture behavioral of ram2 is
  type ramType is array (0 to SIZE-1) of std_logic_vector(WIDTH-1 downto 0);
  shared variable ram : ramType := (others => (others => '0'));
begin
  process (clkA)
  begin
    if rising_edge(clkA) then
      if enA = '1' then
        if weA = '1' then
          ram(conv_integer(addrA)) := diA;
        end if;
        doA <= ram(conv_integer(addrA));
      end if;
    end if;
  end process;

  process (clkB)
  begin
    if rising_edge(clkB) then
      if enB = '1' then 
        if weB = '1' then
          ram(conv_integer(addrB)) := diB;
        end if;
        doB <= ram(conv_integer(addrB));
      end if;
    end if;
  end process;
end behavioral;