-
Notifications
You must be signed in to change notification settings - Fork 0
/
Memory.vhd
104 lines (79 loc) · 2.78 KB
/
Memory.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
--47221757
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity Memory is
port (
clk : in std_logic;
rst : in std_logic;
MemWriteM : in std_logic;
WriteDataM : in std_logic_vector(31 downto 0);
MemReadM : in std_logic; -- beware!!!! we should add in the decode mode a signal MemRead!!!!!
-----------MEM-WB REGISTER--------------
-- MEM-WB register inputs
RegWriteM : in std_logic;
MemToRegM : in std_logic;
-- ReadDataM : in std_logic_vector(31 downto 0); THIS IS AN INTERNAL SIGNAL CALLED :read_data_out !!!!!!!!!!!!
ALUOutM : in std_logic_vector(31 downto 0);
WriteRegM : in std_logic_vector(4 downto 0);
-- MEM-WB register outputs
RegWriteW : out std_logic:= '0';
MemToRegW : out std_logic;
ReadDataW : out std_logic_vector(31 downto 0);
ALUOutW : out std_logic_vector(31 downto 0);
WriteRegW : out std_logic_vector(4 downto 0)
----------------------------------------------------
);
end entity Memory;
architecture arc_Memory of Memory is
signal read_data_out : std_logic_vector(31 downto 0);
component DataMemory is
port(
clk : in std_logic;
rst : in std_logic;
address : in std_logic_vector(31 downto 0);
-- write side
mem_write : in std_logic;
write_data : in std_logic_vector(31 downto 0);
-- read side
mem_read : in std_logic;
read_data : out std_logic_vector(31 downto 0));
end component DataMemory;
begin -- begin arc
DMem:
DataMemory port map(
clk => clk,
rst => rst,
-- write side
address => ALUOutM ,
mem_write => MemWriteM,
write_data => WriteDataM,
-- read side
mem_read => MemReadM,
read_data => read_data_out
);
----------------------
-- !!!!NOTICE!!!!! The DATA MEMORY Exploits the rising and the falling edge of the clok!!! meaning within
-- the same clock it writes and then reads.
-- WRITE = RISING EDGE
-- READ = FALLING EDGE
--------------------------------
----- DEFINE THE PROCESSES FOR THE MEM-WB REGISTER -----
SYNC_MEM_WB:process(clk,rst)
begin --asynchronous rst
if (rst = '1') then
RegWriteW <= '0';
MemToRegW <= '0';
ReadDataW <= (others => '0');
ALUOutW <= (others => '0');
WriteRegW <= "00000";
elsif rising_edge(clk) then -- the register READS, thus the falling edge
RegWriteW <= RegWriteM;
MemToRegW <= MemToRegM;
ReadDataW <= read_data_out;
ALUOutW <= ALUOutM;
WriteRegW <= WriteRegM;
end if;
end process;
end architecture arc_Memory;