1 |
2 |
danv |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- Copyright (C) 2010
|
4 |
|
|
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
5 |
|
|
-- JIVE (Joint Institute for VLBI in Europe) <http://www.jive.nl/>
|
6 |
|
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
7 |
|
|
--
|
8 |
|
|
-- This program is free software: you can redistribute it and/or modify
|
9 |
|
|
-- it under the terms of the GNU General Public License as published by
|
10 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
11 |
|
|
-- (at your option) any later version.
|
12 |
|
|
--
|
13 |
|
|
-- This program is distributed in the hope that it will be useful,
|
14 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
-- GNU General Public License for more details.
|
17 |
|
|
--
|
18 |
|
|
-- You should have received a copy of the GNU General Public License
|
19 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20 |
|
|
--
|
21 |
|
|
-------------------------------------------------------------------------------
|
22 |
|
|
|
23 |
|
|
LIBRARY IEEE, common_pkg_lib;
|
24 |
|
|
USE IEEE.std_logic_1164.ALL;
|
25 |
|
|
USE IEEE.numeric_std.ALL;
|
26 |
|
|
USE common_pkg_lib.common_pkg.ALL;
|
27 |
|
|
USE common_pkg_lib.tb_common_pkg.ALL;
|
28 |
|
|
|
29 |
|
|
-- Purpose: Test bench for common_paged_ram_crw_crw
|
30 |
|
|
--
|
31 |
|
|
-- Features:
|
32 |
|
|
-- . Use c_gap_sz = 0 to try writing and reading multiple page without idle
|
33 |
|
|
-- cycles
|
34 |
|
|
-- . Most applications use c_nof_pages = 2, but use > 2 is supported too.
|
35 |
|
|
--
|
36 |
|
|
-- Usage:
|
37 |
|
|
-- > as 10
|
38 |
|
|
-- > run -all
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
ENTITY tb_common_paged_ram_crw_crw IS
|
42 |
|
|
END tb_common_paged_ram_crw_crw;
|
43 |
|
|
|
44 |
|
|
ARCHITECTURE tb OF tb_common_paged_ram_crw_crw IS
|
45 |
|
|
|
46 |
|
|
CONSTANT clk_period : TIME := 10 ns;
|
47 |
|
|
|
48 |
|
|
CONSTANT c_data_w : NATURAL := 8;
|
49 |
|
|
CONSTANT c_nof_pages : NATURAL := 2; -- >= 2
|
50 |
|
|
CONSTANT c_page_sz : NATURAL := 8;
|
51 |
|
|
CONSTANT c_start_page_a : NATURAL := 0;
|
52 |
|
|
CONSTANT c_start_page_b : NATURAL := 1;
|
53 |
|
|
CONSTANT c_gap_sz : NATURAL := 0; -- >= 0
|
54 |
|
|
CONSTANT c_rl : NATURAL := 1;
|
55 |
|
|
|
56 |
|
|
SIGNAL rst : STD_LOGIC;
|
57 |
|
|
SIGNAL clk : STD_LOGIC := '1';
|
58 |
|
|
SIGNAL tb_end : STD_LOGIC := '0';
|
59 |
|
|
|
60 |
|
|
-- DUT
|
61 |
|
|
SIGNAL next_page : STD_LOGIC;
|
62 |
|
|
|
63 |
|
|
SIGNAL next_page_a : STD_LOGIC;
|
64 |
|
|
SIGNAL adr_a : STD_LOGIC_VECTOR(ceil_log2(c_page_sz)-1 DOWNTO 0) := (OTHERS=>'0');
|
65 |
|
|
SIGNAL wr_en_a : STD_LOGIC;
|
66 |
|
|
SIGNAL wr_dat_a : STD_LOGIC_VECTOR(c_data_w-1 DOWNTO 0) := (OTHERS=>'0');
|
67 |
|
|
|
68 |
|
|
SIGNAL next_page_b : STD_LOGIC;
|
69 |
|
|
SIGNAL adr_b : STD_LOGIC_VECTOR(ceil_log2(c_page_sz)-1 DOWNTO 0) := (OTHERS=>'0');
|
70 |
|
|
SIGNAL rd_en_b : STD_LOGIC := '0';
|
71 |
|
|
|
72 |
|
|
SIGNAL mux_rd_dat_b : STD_LOGIC_VECTOR(c_data_w-1 DOWNTO 0);
|
73 |
|
|
SIGNAL mux_rd_val_b : STD_LOGIC;
|
74 |
|
|
|
75 |
|
|
SIGNAL adr_rd_dat_b : STD_LOGIC_VECTOR(c_data_w-1 DOWNTO 0);
|
76 |
|
|
SIGNAL adr_rd_val_b : STD_LOGIC;
|
77 |
|
|
|
78 |
|
|
SIGNAL ofs_rd_dat_b : STD_LOGIC_VECTOR(c_data_w-1 DOWNTO 0);
|
79 |
|
|
SIGNAL ofs_rd_val_b : STD_LOGIC;
|
80 |
|
|
|
81 |
|
|
-- Verify
|
82 |
|
|
SIGNAL verify_en : STD_LOGIC;
|
83 |
|
|
SIGNAL ready : STD_LOGIC := '1';
|
84 |
|
|
|
85 |
|
|
SIGNAL prev_mux_rd_dat_b : STD_LOGIC_VECTOR(c_data_w-1 DOWNTO 0);
|
86 |
|
|
SIGNAL prev_adr_rd_dat_b : STD_LOGIC_VECTOR(c_data_w-1 DOWNTO 0);
|
87 |
|
|
SIGNAL prev_ofs_rd_dat_b : STD_LOGIC_VECTOR(c_data_w-1 DOWNTO 0);
|
88 |
|
|
|
89 |
|
|
BEGIN
|
90 |
|
|
|
91 |
|
|
clk <= NOT clk AND NOT tb_end AFTER clk_period/2;
|
92 |
|
|
rst <= '1', '0' AFTER clk_period*7;
|
93 |
|
|
|
94 |
|
|
verify_en <= '0', '1' AFTER clk_period*(15+(c_nof_pages-1)*c_page_sz);
|
95 |
|
|
|
96 |
|
|
-- Apply stimuli via port 'a', do write 'a' and read 'b', and derive the 'b' stimuli from the 'a' stimuli with 1 clock cycle latency
|
97 |
|
|
next_page_a <= next_page;
|
98 |
|
|
next_page_b <= next_page WHEN rising_edge(clk);
|
99 |
|
|
|
100 |
|
|
wr_dat_a <= INCR_UVEC(wr_dat_a, 1) WHEN rising_edge(clk) AND wr_en_a='1';
|
101 |
|
|
adr_a <= INCR_UVEC( adr_a, 1) WHEN rising_edge(clk) AND wr_en_a='1';
|
102 |
|
|
adr_b <= adr_a WHEN rising_edge(clk);
|
103 |
|
|
rd_en_b <= wr_en_a WHEN rising_edge(clk);
|
104 |
|
|
|
105 |
|
|
p_stimuli : PROCESS
|
106 |
|
|
BEGIN
|
107 |
|
|
next_page <= '0';
|
108 |
|
|
wr_en_a <= '0';
|
109 |
|
|
proc_common_wait_until_low(clk, rst);
|
110 |
|
|
proc_common_wait_some_cycles(clk, 3);
|
111 |
|
|
|
112 |
|
|
-- Access the pages several times
|
113 |
|
|
FOR I IN 0 TO c_nof_pages*3 LOOP
|
114 |
|
|
wr_en_a <= '1';
|
115 |
|
|
proc_common_wait_some_cycles(clk, c_page_sz-1);
|
116 |
|
|
next_page <= '1';
|
117 |
|
|
proc_common_wait_some_cycles(clk, 1);
|
118 |
|
|
next_page <= '0';
|
119 |
|
|
wr_en_a <= '0';
|
120 |
|
|
proc_common_wait_some_cycles(clk, c_gap_sz); -- optinal gap between the pages
|
121 |
|
|
END LOOP;
|
122 |
|
|
|
123 |
|
|
wr_en_a <= '0';
|
124 |
|
|
proc_common_wait_some_cycles(clk, c_page_sz);
|
125 |
|
|
tb_end <= '1';
|
126 |
|
|
WAIT;
|
127 |
|
|
END PROCESS;
|
128 |
|
|
|
129 |
|
|
u_dut_mux : ENTITY work.common_paged_ram_crw_crw
|
130 |
|
|
GENERIC MAP (
|
131 |
|
|
g_str => "use_mux",
|
132 |
|
|
g_data_w => c_data_w,
|
133 |
|
|
g_nof_pages => c_nof_pages,
|
134 |
|
|
g_page_sz => c_page_sz,
|
135 |
|
|
g_start_page_a => c_start_page_a,
|
136 |
|
|
g_start_page_b => c_start_page_b
|
137 |
|
|
)
|
138 |
|
|
PORT MAP (
|
139 |
|
|
rst_a => rst,
|
140 |
|
|
rst_b => rst,
|
141 |
|
|
clk_a => clk,
|
142 |
|
|
clk_b => clk,
|
143 |
|
|
clken_a => '1',
|
144 |
|
|
clken_b => '1',
|
145 |
|
|
next_page_a => next_page_a,
|
146 |
|
|
adr_a => adr_a,
|
147 |
|
|
wr_en_a => wr_en_a,
|
148 |
|
|
wr_dat_a => wr_dat_a,
|
149 |
|
|
rd_en_a => '0',
|
150 |
|
|
rd_dat_a => OPEN,
|
151 |
|
|
rd_val_a => OPEN,
|
152 |
|
|
next_page_b => next_page_b,
|
153 |
|
|
adr_b => adr_b,
|
154 |
|
|
wr_en_b => '0',
|
155 |
|
|
wr_dat_b => (OTHERS=>'0'),
|
156 |
|
|
rd_en_b => rd_en_b,
|
157 |
|
|
rd_dat_b => mux_rd_dat_b,
|
158 |
|
|
rd_val_b => mux_rd_val_b
|
159 |
|
|
);
|
160 |
|
|
|
161 |
|
|
u_dut_adr : ENTITY work.common_paged_ram_crw_crw
|
162 |
|
|
GENERIC MAP (
|
163 |
|
|
g_str => "use_adr",
|
164 |
|
|
g_data_w => c_data_w,
|
165 |
|
|
g_nof_pages => c_nof_pages,
|
166 |
|
|
g_page_sz => c_page_sz,
|
167 |
|
|
g_start_page_a => c_start_page_a,
|
168 |
|
|
g_start_page_b => c_start_page_b
|
169 |
|
|
)
|
170 |
|
|
PORT MAP (
|
171 |
|
|
rst_a => rst,
|
172 |
|
|
rst_b => rst,
|
173 |
|
|
clk_a => clk,
|
174 |
|
|
clk_b => clk,
|
175 |
|
|
clken_a => '1',
|
176 |
|
|
clken_b => '1',
|
177 |
|
|
next_page_a => next_page_a,
|
178 |
|
|
adr_a => adr_a,
|
179 |
|
|
wr_en_a => wr_en_a,
|
180 |
|
|
wr_dat_a => wr_dat_a,
|
181 |
|
|
rd_en_a => '0',
|
182 |
|
|
rd_dat_a => OPEN,
|
183 |
|
|
rd_val_a => OPEN,
|
184 |
|
|
next_page_b => next_page_b,
|
185 |
|
|
adr_b => adr_b,
|
186 |
|
|
wr_en_b => '0',
|
187 |
|
|
wr_dat_b => (OTHERS=>'0'),
|
188 |
|
|
rd_en_b => rd_en_b,
|
189 |
|
|
rd_dat_b => adr_rd_dat_b,
|
190 |
|
|
rd_val_b => adr_rd_val_b
|
191 |
|
|
);
|
192 |
|
|
|
193 |
|
|
u_dut_ofs : ENTITY work.common_paged_ram_crw_crw
|
194 |
|
|
GENERIC MAP (
|
195 |
|
|
g_str => "use_ofs",
|
196 |
|
|
g_data_w => c_data_w,
|
197 |
|
|
g_nof_pages => c_nof_pages,
|
198 |
|
|
g_page_sz => c_page_sz,
|
199 |
|
|
g_start_page_a => c_start_page_a,
|
200 |
|
|
g_start_page_b => c_start_page_b
|
201 |
|
|
)
|
202 |
|
|
PORT MAP (
|
203 |
|
|
rst_a => rst,
|
204 |
|
|
rst_b => rst,
|
205 |
|
|
clk_a => clk,
|
206 |
|
|
clk_b => clk,
|
207 |
|
|
clken_a => '1',
|
208 |
|
|
clken_b => '1',
|
209 |
|
|
next_page_a => next_page_a,
|
210 |
|
|
adr_a => adr_a,
|
211 |
|
|
wr_en_a => wr_en_a,
|
212 |
|
|
wr_dat_a => wr_dat_a,
|
213 |
|
|
rd_en_a => '0',
|
214 |
|
|
rd_dat_a => OPEN,
|
215 |
|
|
rd_val_a => OPEN,
|
216 |
|
|
next_page_b => next_page_b,
|
217 |
|
|
adr_b => adr_b,
|
218 |
|
|
wr_en_b => '0',
|
219 |
|
|
wr_dat_b => (OTHERS=>'0'),
|
220 |
|
|
rd_en_b => rd_en_b,
|
221 |
|
|
rd_dat_b => ofs_rd_dat_b,
|
222 |
|
|
rd_val_b => ofs_rd_val_b
|
223 |
|
|
);
|
224 |
|
|
|
225 |
|
|
-- Verify that the read data is incrementing data
|
226 |
|
|
proc_common_verify_data(c_rl, clk, verify_en, ready, mux_rd_val_b, mux_rd_dat_b, prev_mux_rd_dat_b);
|
227 |
|
|
proc_common_verify_data(c_rl, clk, verify_en, ready, adr_rd_val_b, adr_rd_dat_b, prev_adr_rd_dat_b);
|
228 |
|
|
proc_common_verify_data(c_rl, clk, verify_en, ready, ofs_rd_val_b, ofs_rd_dat_b, prev_ofs_rd_dat_b);
|
229 |
|
|
|
230 |
|
|
-- Verify that the read data is the same for all three DUT variants
|
231 |
|
|
p_verify_equal : PROCESS(clk)
|
232 |
|
|
BEGIN
|
233 |
|
|
IF rising_edge(clk) THEN
|
234 |
|
|
IF UNSIGNED(mux_rd_dat_b) /= UNSIGNED(adr_rd_dat_b) OR UNSIGNED(mux_rd_dat_b) /= UNSIGNED(ofs_rd_dat_b) THEN
|
235 |
|
|
REPORT "DUT : read data differs between two implementations" SEVERITY ERROR;
|
236 |
|
|
END IF;
|
237 |
|
|
IF mux_rd_val_b /= adr_rd_val_b OR mux_rd_val_b /= ofs_rd_val_b THEN
|
238 |
|
|
REPORT "DUT : read valid differs between two implementations" SEVERITY ERROR;
|
239 |
|
|
END IF;
|
240 |
|
|
END IF;
|
241 |
|
|
END PROCESS;
|
242 |
|
|
|
243 |
|
|
END tb;
|