-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.vhd
More file actions
58 lines (52 loc) · 1.47 KB
/
Copy pathmemory.vhd
File metadata and controls
58 lines (52 loc) · 1.47 KB
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
--------------------------------------------------------------------------------
-- Author: Parham Alvani (parham.alvani@gmail.com)
--
-- Create Date: 16-03-2017
-- Module Name: memory.vhd
--------------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity memory is
generic (blocksize : integer := 1024);
port(
clk, readmem, writemem : in std_logic;
addressbus: in std_logic_vector (9 downto 0);
input : in std_logic_vector (31 downto 0);
output : out std_logic_vector (31 downto 0);
memdataready : out std_logic
);
end entity memory;
architecture behavioral of memory is
type mem is array (0 to blocksize - 1) of std_logic_vector (31 downto 0);
begin
process (clk)
variable buffermem : mem := (others => (others => '0'));
variable ad : integer;
variable init : boolean := true;
begin
if init = true then
init := false;
end if;
--databus <= (others => 'Z');
--memdataready <= '0';
if clk'event and clk = '1' then
ad := to_integer(unsigned(addressbus));
if readmem = '1' then -- Readiing :)
memdataready <= '1';
if ad >= blocksize then
output <= (others => 'Z');
else
output <= buffermem(ad);
end if;
elsif writemem = '1' then -- Writing :)
memdataready <= '1';
if ad < blocksize then
buffermem(ad) := input;
end if;
else
memdataready <= '0';
end if;
end if;
end process;
end architecture behavioral;