forked from Endrico/CS701Proj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_mem.vhd
40 lines (35 loc) · 1.09 KB
/
data_mem.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
--Custom defined memory; much simpler than Altera Megafunction.
--Synchronous reads and writes
--Quartus automatically synthesises as RAM (Modelsim doesn't know the difference)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;
ENTITY data_mem IS
PORT
(
clock : IN STD_LOGIC := '1';
data : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
rdaddress : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
wraddress : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
wren : IN STD_LOGIC := '0';
q : OUT STD_LOGIC_VECTOR (15 DOWNTO 0)
);
END data_mem;
ARCHITECTURE behaviour OF data_mem IS
type DMEMORY is array(0 to 65535) of std_logic_vector(15 downto 0); --16K Memory
constant dataInit : DMEMORY := (
--PROGRAM HERE
others => x"0000");
signal DATA_MEM : DMEMORY := dataInit;
BEGIN
memory_access: process(clock)
begin
if (clock'event and clock='1') then
if (wren = '1') then
DATA_MEM(to_integer(unsigned(wraddress(15 downto 0)))) <= data;
end if;
q <= DATA_MEM(to_integer(unsigned(rdaddress(15 downto 0))));
end if;
end process memory_access;
END behaviour;