Repository navigation
Expand file tree
/
Copy pathDRAM_wrapper.vhd
More file actions
139 lines (109 loc) · 3.18 KB
/
Copy pathDRAM_wrapper.vhd
File metadata and controls
139 lines (109 loc) · 3.18 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use std.textio.all;
use ieee.std_logic_textio.all;
use WORK.constants.all;
use WORK.functions.all;
-- Memory filled by a process which reads from a file
entity DRAM_wrapper is
port (
Clk : in std_logic;
Rst : in std_logic;
Enable : in std_logic;
RnW : in std_logic;
Addr : in std_logic_vector(31 downto 0);
Din : in std_logic_vector(31 downto 0);
Dout : out std_logic_vector(31 downto 0)
);
end DRAM_wrapper ;
architecture DRam_Bhe of DRAM_wrapper is
component sram_32_1024_freepdk45 is
port (
clk0 : in std_logic; -- clock
csb0 : in std_logic; -- chip select (negative triggered)
web0 : in std_logic; -- Read not Write
din0 : in std_logic_vector(31 downto 0); -- input data
addr0 : in std_logic_vector(9 downto 0); -- address
dout0 : out std_logic_vector(31 downto 0)); -- read data
end component;
signal MEM_out, STACK_out: std_logic_vector(31 downto 0);
signal s_Din, zeros: std_logic_vector(31 downto 0);
signal rst_DRAM_addr, DRAM_addr, rst_STACK_addr, STACK_addr: std_logic_vector(9 downto 0);
signal STACK_addr_32: std_logic_vector(31 downto 0);
signal s_RnW: std_logic;
signal mEN, sEN: std_logic;
signal is_mem: std_logic;
signal idx, idx_next: std_logic_vector(9 downto 0);
begin
mem: sram_32_1024_freepdk45
port map (
clk0 => CLK,
web0 => s_RnW, -- Read not Write
din0 => Din,
addr0 => DRAM_addr,
csb0 => mEN,
dout0 => MEM_out
);
stack: sram_32_1024_freepdk45
port map (
clk0 => CLK,
web0 => s_RnW, -- Read not Write
din0 => Din,
addr0 => STACK_addr,
csb0 => sEN,
dout0 => STACK_out
);
DRAM_addr <= rst_DRAM_addr when (rst= '0' and enable = '1') else
addr(9 downto 0);
STACK_addr <= rst_STACK_addr when (rst= '0' and enable = '1') else
STACK_addr_32(9 downto 0);
s_Din <= (others=>'0') when (rst= '0' and enable = '1') else
Din;
s_RnW <= '0' when (rst= '0' and enable = '1') else
RnW;
is_mem <= '1' when (unsigned(Addr) < unsigned(stack_start)) else
'0';
Dout <= MEM_out when (is_mem = '1') else
STACK_out;
STACK_addr_32 <= std_logic_vector(unsigned(Addr) - unsigned(stack_start));
idx_proc: process(clk,rst) begin
if(rst = '1') then
idx<= (others=>'0');
else
if( rising_edge(clk)) then
idx <= idx_next;
end if;
end if;
end process idx_proc;
rst_proc: process(idx,rst)
begin
if(rst = '1') then
idx_next<=(others=>'0');
else
if(to_integer(unsigned(idx)) <= N_INSTR) then
rst_DRAM_addr <= idx;
rst_STACK_addr <= idx;
idx_next <= std_logic_vector(unsigned(idx) +1);
end if;
end if;
end process rst_proc;
process(enable, rst, addr, is_mem, STACK_addr_32) begin
case(enable) is
when '1' => if(rst = '0') then
mEN <='0';
sEN <='0';
elsif(is_mem = '1') then -- memory
mEN <='0';
sEN <='1';
else
mEN <='1';
sEN <='0';
end if;
when others => if(rst = '0') then
mEN <='1';
sEN <='1';
end if;
end case;
end process;
end DRam_Bhe;