1 |
7 |
umairsiddi |
--------------------------------------------------------------
|
2 |
|
|
-- test.vhd
|
3 |
|
|
--------------------------------------------------------------
|
4 |
|
|
-- project: HPC-16 Microprocessor
|
5 |
|
|
--
|
6 |
|
|
-- usage: basic testbench top-level
|
7 |
|
|
--
|
8 |
|
|
-- dependency: cpu.vhd, ramNx16.vhd, ram8x16.vhd
|
9 |
|
|
--
|
10 |
|
|
-- Author: M. Umair Siddiqui (umairsiddiqui@opencores.org)
|
11 |
|
|
---------------------------------------------------------------
|
12 |
|
|
------------------------------------------------------------------------------------
|
13 |
|
|
-- --
|
14 |
|
|
-- Copyright (c) 2005, M. Umair Siddiqui all rights reserved --
|
15 |
|
|
-- --
|
16 |
|
|
-- This file is part of HPC-16. --
|
17 |
|
|
-- --
|
18 |
|
|
-- HPC-16 is free software; you can redistribute it and/or modify --
|
19 |
|
|
-- it under the terms of the GNU Lesser General Public License as published by --
|
20 |
|
|
-- the Free Software Foundation; either version 2.1 of the License, or --
|
21 |
|
|
-- (at your option) any later version. --
|
22 |
|
|
-- --
|
23 |
|
|
-- HPC-16 is distributed in the hope that it will be useful, --
|
24 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
|
25 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
|
26 |
|
|
-- GNU Lesser General Public License for more details. --
|
27 |
|
|
-- --
|
28 |
|
|
-- You should have received a copy of the GNU Lesser General Public License --
|
29 |
|
|
-- along with HPC-16; if not, write to the Free Software --
|
30 |
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
|
31 |
|
|
-- --
|
32 |
|
|
------------------------------------------------------------------------------------
|
33 |
|
|
--------------------------------
|
34 |
|
|
-- --
|
35 |
|
|
-- non-tristate version --
|
36 |
|
|
-- --
|
37 |
|
|
--------------------------------
|
38 |
|
|
library ieee;
|
39 |
|
|
use ieee.std_logic_1164.all;
|
40 |
|
|
use ieee.std_logic_arith.all;
|
41 |
|
|
use ieee.std_logic_unsigned.all;
|
42 |
|
|
-----------------------------------------------------------
|
43 |
|
|
entity test is
|
44 |
|
|
generic
|
45 |
|
|
(
|
46 |
|
|
clk_period : time := 40 ns;
|
47 |
|
|
half_clk_period : time := 20 ns;
|
48 |
|
|
--
|
49 |
|
|
cpu_pc_preset_value : std_logic_vector(15 downto 0) := X"0000";
|
50 |
|
|
cpu_sp_preset_value : std_logic_vector(15 downto 0) := X"001e";
|
51 |
|
|
--
|
52 |
|
|
ram_adr_width : integer := 4;
|
53 |
|
|
|
54 |
|
|
file_name_prefix : string := "add2";
|
55 |
|
|
sim_stop_time : time := 3000 ns;
|
56 |
|
|
--
|
57 |
|
|
ram2_adr : std_logic_vector(15 downto 0) := X"ff00";
|
58 |
|
|
|
59 |
|
|
ram2_init_0 : std_logic_vector(15 downto 0) := X"7fff";
|
60 |
|
|
ram2_init_1 : std_logic_vector(15 downto 0) := X"0001";
|
61 |
|
|
ram2_init_2 : std_logic_vector(15 downto 0) := (others => '0');
|
62 |
|
|
ram2_init_3 : std_logic_vector(15 downto 0) := (others => '0');
|
63 |
|
|
ram2_init_4 : std_logic_vector(15 downto 0) := (others => '0');
|
64 |
|
|
ram2_init_5 : std_logic_vector(15 downto 0) := (others => '0');
|
65 |
|
|
ram2_init_6 : std_logic_vector(15 downto 0) := (others => '0');
|
66 |
|
|
ram2_init_7 : std_logic_vector(15 downto 0) := (others => '0')
|
67 |
|
|
);
|
68 |
|
|
end test;
|
69 |
|
|
|
70 |
|
|
architecture sim of test is
|
71 |
|
|
----------------------------------------
|
72 |
|
|
-- cpu interface signal
|
73 |
|
|
----------------------------------------
|
74 |
|
|
signal clk_i : std_logic;
|
75 |
|
|
signal rst_i : std_logic;
|
76 |
|
|
signal ack_i : std_logic;
|
77 |
|
|
signal intr_i : std_logic;
|
78 |
|
|
--
|
79 |
|
|
signal sel_o : std_logic_vector(1 downto 0);
|
80 |
|
|
signal stb_o : std_logic;
|
81 |
|
|
signal cyc_o : std_logic;
|
82 |
|
|
signal we_o : std_logic;
|
83 |
|
|
--
|
84 |
|
|
signal inta_cyc_o : std_logic;
|
85 |
|
|
signal i_cyc_o : std_logic;
|
86 |
|
|
signal c_cyc_o : std_logic;
|
87 |
|
|
signal d_cyc_o : std_logic;
|
88 |
|
|
--
|
89 |
|
|
signal adr_o : std_logic_vector(15 downto 0);
|
90 |
|
|
--
|
91 |
|
|
signal dat_i : std_logic_vector(15 downto 0);
|
92 |
|
|
signal dat_o : std_logic_vector(15 downto 0);
|
93 |
|
|
signal ram_dat_o : std_logic_vector(15 downto 0);
|
94 |
|
|
signal ram2_dat_o : std_logic_vector(15 downto 0);
|
95 |
|
|
-----------------------------------------
|
96 |
|
|
-- ram interfacing
|
97 |
|
|
-----------------------------------------
|
98 |
|
|
signal ram_cs : std_logic;
|
99 |
|
|
signal ram_oe : std_logic;
|
100 |
|
|
--
|
101 |
|
|
signal ram2_cs : std_logic;
|
102 |
|
|
signal ram2_oe : std_logic;
|
103 |
|
|
begin
|
104 |
|
|
----------------------------------------------------------------------
|
105 |
|
|
clk_gen : process
|
106 |
|
|
begin
|
107 |
|
|
wait for half_clk_period;
|
108 |
|
|
clk_i <= '1';
|
109 |
|
|
wait for half_clk_period;
|
110 |
|
|
clk_i <= '0';
|
111 |
|
|
if now >= sim_stop_time then
|
112 |
|
|
assert false
|
113 |
|
|
report "simulation completed (not an error)"
|
114 |
|
|
severity error;
|
115 |
|
|
wait;
|
116 |
|
|
end if;
|
117 |
|
|
end process;
|
118 |
|
|
-----------------------------------------------------------------------
|
119 |
|
|
rst_gen : process
|
120 |
|
|
begin
|
121 |
|
|
wait for half_clk_period;
|
122 |
|
|
rst_i <= '1';
|
123 |
|
|
wait for 4 * clk_period;
|
124 |
|
|
rst_i <= '0';
|
125 |
|
|
wait;
|
126 |
|
|
end process;
|
127 |
|
|
-------------------------------------------------------------------------
|
128 |
|
|
cpu : entity work.cpu
|
129 |
|
|
generic map
|
130 |
|
|
(
|
131 |
|
|
pc_preset_value => cpu_pc_preset_value,
|
132 |
|
|
sp_preset_value => cpu_sp_preset_value
|
133 |
|
|
)
|
134 |
|
|
port map
|
135 |
|
|
(
|
136 |
|
|
CLK_I => clk_i,
|
137 |
|
|
RST_I => rst_i,
|
138 |
|
|
ACK_I => ack_i,
|
139 |
|
|
INTR_I => intr_i,
|
140 |
|
|
--
|
141 |
|
|
SEL_O => sel_o,
|
142 |
|
|
STB_O => stb_o,
|
143 |
|
|
CYC_O => cyc_o,
|
144 |
|
|
WE_O => we_o,
|
145 |
|
|
--
|
146 |
|
|
INTA_CYC_O => inta_cyc_o,
|
147 |
|
|
I_CYC_O => i_cyc_o,
|
148 |
|
|
C_CYC_O => c_cyc_o,
|
149 |
|
|
D_CYC_O => d_cyc_o,
|
150 |
|
|
--
|
151 |
|
|
DAT_I => dat_i,
|
152 |
|
|
DAT_O => dat_o,
|
153 |
|
|
ADR_O => adr_o
|
154 |
|
|
);
|
155 |
|
|
--------------------------------------------------
|
156 |
|
|
ack_gen : ack_i <= stb_o;
|
157 |
|
|
-----------------------------------------------------------------------
|
158 |
|
|
ram_cs_gen : process(stb_o, adr_o)
|
159 |
|
|
variable temp : integer;
|
160 |
|
|
constant max_loc : integer := (2 ** (ram_adr_width + 1)) - 1;
|
161 |
|
|
begin
|
162 |
|
|
if stb_o = '1' then
|
163 |
|
|
temp := conv_integer(adr_o);
|
164 |
|
|
if 0 <= temp and temp <= max_loc then
|
165 |
|
|
ram_cs <= '1';
|
166 |
|
|
else
|
167 |
|
|
ram_cs <= '0';
|
168 |
|
|
end if;
|
169 |
|
|
end if;
|
170 |
|
|
end process ram_cs_gen;
|
171 |
|
|
----------------------------------------------------------------------
|
172 |
|
|
ram_oe <= not we_o;
|
173 |
|
|
----------------------------------------------------------------------
|
174 |
|
|
ram: entity work.ramNx16(async)
|
175 |
|
|
generic map
|
176 |
|
|
(
|
177 |
|
|
init_file_name => file_name_prefix & "_init_ram.txt",
|
178 |
|
|
adr_width => ram_adr_width
|
179 |
|
|
|
180 |
|
|
)
|
181 |
|
|
port map
|
182 |
|
|
(
|
183 |
|
|
clk => clk_i,
|
184 |
|
|
adr => adr_o(ram_adr_width downto 1),
|
185 |
|
|
dat_i => dat_o, -- connected to output of cpu
|
186 |
|
|
--
|
187 |
|
|
cs => ram_cs,
|
188 |
|
|
we => we_o,
|
189 |
|
|
ub => sel_o(1),
|
190 |
|
|
lb => sel_o(0),
|
191 |
|
|
oe => ram_oe,
|
192 |
|
|
--
|
193 |
|
|
dat_o => ram_dat_o
|
194 |
|
|
);
|
195 |
|
|
--------------------------------------------------
|
196 |
|
|
ram2: entity work.ram8x16
|
197 |
|
|
generic map
|
198 |
|
|
(
|
199 |
|
|
init_0 => ram2_init_0,
|
200 |
|
|
init_1 => ram2_init_1,
|
201 |
|
|
init_2 => ram2_init_2,
|
202 |
|
|
init_3 => ram2_init_3,
|
203 |
|
|
init_4 => ram2_init_4,
|
204 |
|
|
init_5 => ram2_init_5,
|
205 |
|
|
init_6 => ram2_init_6,
|
206 |
|
|
init_7 => ram2_init_7
|
207 |
|
|
|
208 |
|
|
)
|
209 |
|
|
port map
|
210 |
|
|
(
|
211 |
|
|
clk => clk_i,
|
212 |
|
|
adr => adr_o(3 downto 1),
|
213 |
|
|
dat_i => dat_o, -- connected to cpu output
|
214 |
|
|
--
|
215 |
|
|
cs => ram2_cs,
|
216 |
|
|
we => we_o,
|
217 |
|
|
ub => sel_o(1),
|
218 |
|
|
lb => sel_o(0),
|
219 |
|
|
oe => ram2_oe,
|
220 |
|
|
--
|
221 |
|
|
dat_o => ram2_dat_o
|
222 |
|
|
);
|
223 |
|
|
-----------------------------------------------
|
224 |
|
|
ram2_oe <= not we_o;
|
225 |
|
|
----------------------------------------------
|
226 |
|
|
ram2_cs_gen : process(stb_o, adr_o)
|
227 |
|
|
variable temp : integer;
|
228 |
|
|
constant max_loc : integer := conv_integer(ram2_adr) + 15;
|
229 |
|
|
begin
|
230 |
|
|
if stb_o = '1' then
|
231 |
|
|
temp := conv_integer(adr_o);
|
232 |
|
|
if ram2_adr <= temp and temp <= max_loc then
|
233 |
|
|
ram2_cs <= '1';
|
234 |
|
|
else
|
235 |
|
|
ram2_cs <= '0';
|
236 |
|
|
end if;
|
237 |
|
|
end if;
|
238 |
|
|
end process ram2_cs_gen;
|
239 |
|
|
----------------------------------------------
|
240 |
|
|
ram_out_mux : process(ram_cs, ram2_cs, ram_dat_o, ram2_dat_o)
|
241 |
|
|
-- which ram output will drive the cpu's dat_i
|
242 |
|
|
variable cs : std_logic_vector(1 downto 0);
|
243 |
|
|
begin
|
244 |
|
|
cs := ram_cs & ram2_cs;
|
245 |
|
|
case cs is
|
246 |
|
|
when "10" => dat_i <= ram_dat_o;
|
247 |
|
|
when "01" => dat_i <= ram2_dat_o;
|
248 |
|
|
when others => dat_i <= (others => '0');
|
249 |
|
|
end case;
|
250 |
|
|
end process ram_out_mux;
|
251 |
|
|
end sim;
|