-
Notifications
You must be signed in to change notification settings - Fork 0
/
dprom.vhd
65 lines (48 loc) · 1.39 KB
/
dprom.vhd
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
61
62
63
64
65
-- altera message_off 10306
library ieee;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.ALL;
use IEEE.numeric_std.all;
entity dprom is
generic
(
INIT_FILE : string := "";
ADDR_WIDTH : natural := 14;
DATA_WIDTH : natural := 8
);
port
(
wrclock : in std_logic;
wraddress : in std_logic_vector((ADDR_WIDTH - 1) downto 0) := (others => '0');
data : in std_logic_vector((DATA_WIDTH - 1) downto 0) := (others => '0');
wren : in std_logic := '0';
rdclock : in std_logic;
rdaddress : in std_logic_vector((ADDR_WIDTH - 1) downto 0);
q : out std_logic_vector((DATA_WIDTH - 1) downto 0);
cs : in std_logic := '1'
);
end dprom;
architecture rtl of dprom 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;
shared variable ram : memory_t;
attribute ram_init_file : string;
attribute ram_init_file of ram : variable is INIT_FILE;
signal q0 : std_logic_vector((DATA_WIDTH - 1) downto 0);
begin
q<= q0 when cs = '1' else (others => '1');
-- WR Port
process(wrclock) begin
if(rising_edge(wrclock)) then
if(wren = '1') then
ram(to_integer(unsigned(wraddress))) := data;
end if;
end if;
end process;
-- RD Port
process(rdclock) begin
if(rising_edge(rdclock)) then
q0 <= ram(to_integer(unsigned(rdaddress)));
end if;
end process;
end rtl;