w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tb_fifo_2c_dram.vhd
Go to the documentation of this file.
1-- $Id: tb_fifo_2c_dram.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: tb_fifo_2c_dram - sim
7-- Description: Test bench for fifo_2c_dram
8--
9-- Dependencies: simlib/simclkv
10-- simlib/simclkvcnt
11-- tbd_fifo_2c_dram [UUT]
12--
13-- To test: fifo_2c_dram
14--
15-- Target Devices: generic
16-- Tool versions: xst 8.2, 9.1, 9.2, 11.3, 13.1; ghdl 0.18-0.29
17-- Revision History:
18-- Date Rev Version Comment
19-- 2011-12-23 444 1.1 use new simclk/simclkcnt
20-- 2011-11-07 421 1.0.5 now numeric_std clean
21-- 2010-06-03 299 1.0.4 use sv_ prefix for shared variables
22-- 2010-04-17 277 1.0.3 use direct instantiation of tbd_
23-- 2009-11-22 252 1.0.2 CLK*_CYCLE now 31 bits
24-- 2007-12-28 107 1.0.1 add reset and check handling
25-- 2007-12-28 106 1.0 Initial version
26------------------------------------------------------------------------------
27
28library ieee;
29use ieee.std_logic_1164.all;
30use ieee.numeric_std.all;
31use ieee.std_logic_textio.all;
32use std.textio.all;
33
34use work.slvtypes.all;
35use work.simlib.all;
36
39
40architecture sim of tb_fifo_2c_dram is
41
42 signal CLKW : slbit := '0';
43 signal CLKR : slbit := '0';
44 signal RESETW : slbit := '0';
45 signal RESETR : slbit := '0';
46 signal DI : slv16 := (others=>'0');
47 signal ENA : slbit := '0';
48 signal BUSY : slbit := '0';
49 signal DO : slv16 := (others=>'0');
50 signal VAL : slbit := '0';
51 signal SIZEW : slv4 := (others=>'0');
52 signal SIZER : slv4 := (others=>'0');
53
54 signal N_HOLD : slbit := '0';
55 signal R_HOLD : slbit := '0';
56
57 signal CLKW_PERIOD : Delay_length := 20 ns;
58 signal CLKR_PERIOD : Delay_length := 20 ns;
59 signal CLK_HOLD : slbit := '1';
60 signal CLK_STOP : slbit := '0';
61 signal CLKW_CYCLE : integer := 0;
62 signal CLKR_CYCLE : integer := 0;
63
64 signal CLKR_C2OUT : Delay_length := 10 ns;
65
66 shared variable sv_nrstr : integer := 0;
67 shared variable sv_ndatar : integer := 0; -- data counter (fifo data output)
68
69begin
70
71 CLKWGEN : simclkv
72 port map (
73 CLK => CLKW,
77 );
78
79 CLKWCNT : simclkcnt port map (CLK => CLKW, CLK_CYCLE => CLKW_CYCLE);
80
81 CLKRGEN : simclkv
82 port map (
83 CLK => CLKR,
87 );
88
89 CLKRCNT : simclkcnt port map (CLK => CLKR, CLK_CYCLE => CLKR_CYCLE);
90
91 UUT : entity work.tbd_fifo_2c_dram
92 port map (
93 CLKW => CLKW,
94 CLKR => CLKR,
95 RESETW => RESETW,
96 RESETR => RESETR,
97 DI => DI,
98 ENA => ENA,
99 BUSY => BUSY,
100 DO => DO,
101 VAL => VAL,
102 HOLD => R_HOLD,
103 SIZEW => SIZEW,
104 SIZER => SIZER
105 );
106
107
108 proc_stim: process
109 file fstim : text open read_mode is "tb_fifo_2c_dram_stim";
110 variable iline : line;
111 variable oline : line;
112 variable dname : string(1 to 6) := (others=>' ');
113 variable ok : boolean;
114 variable dtime : Delay_length := 0 ns;
115 variable nwait : integer := 0; --
116 variable nword : integer := 0; --
117 variable nbusy : integer := 0; -- number of busy before accept
118 variable idi : slv16 := (others=>'0');
119
120 variable ndataw : integer := 0; -- data counter (fifo data input)
121
122 variable iclkw_period : Delay_length := 20 ns;
123 variable iclkw_setup : Delay_length := 5 ns;
124 variable iclkr_period : Delay_length := 20 ns;
125 variable iclkr_c2out : Delay_length := 10 ns;
126
127 begin
128
129 file_loop: while not endfile(fstim) loop
130
131 readline (fstim, iline);
132
133 readcomment(iline, ok);
134 next file_loop when ok;
135
136 readword(iline, dname, ok);
137
138 if ok then
139 case dname is
140 when ".chold" => -- .chold time
141 write(oline, string'(".chold"));
142 writeline(output, oline);
143 read_ea(iline, dtime);
144 CLK_HOLD <= '1';
145 wait for dtime;
146 CLK_HOLD <= '0';
147 wait until rising_edge(CLKW);
148 wait for iclkw_period-iclkw_setup;
149
150 when ".cdef " => -- .cdef wper wset rper rout
151 write(oline, string'(".cdef "));
152 writeline(output, oline);
153 read_ea(iline, iclkw_period);
154 read_ea(iline, iclkw_setup);
155 read_ea(iline, iclkr_period);
156 read_ea(iline, iclkr_c2out);
157 CLKW_PERIOD <= iclkw_period;
158 CLKR_PERIOD <= iclkr_period;
159 CLKR_C2OUT <= iclkr_c2out;
160 if CLK_HOLD = '0' then
161 wait until rising_edge(CLKW);
162 wait for iclkw_period-iclkw_setup;
163 end if;
164
165 when ".ndata" => -- .ndata num
166 read_ea(iline, ndataw);
167 sv_ndatar := ndataw;
168
169 when ".hold " => -- .hold time
170 read_ea(iline, dtime);
171 if dtime > 0 ns then
172 N_HOLD <= '1', '0' after dtime;
173 else -- allow hold abort with 0ns
174 N_HOLD <= '0';
175 end if;
176
177 when ".wait " => -- .wait ncyc
178 read_ea(iline, nwait);
179 wait for nwait*iclkw_period;
180
181 when "resetw" => -- resetw ncyc
182 read_ea(iline, nwait);
183 RESETW <= '1';
184 wait for nwait*iclkw_period;
185 RESETW <= '0';
186
187 when "resetr" => -- resetr ncyc
188 read_ea(iline, nwait);
189 sv_nrstr := nwait;
190
191 when "send " => -- send nw nd
192 read_ea(iline, nwait);
193 read_ea(iline, nword);
194 for i in 1 to nword loop
195 wait for nwait*iclkw_period;
196
197 idi := slv(to_unsigned(ndataw, 16));
198 ndataw := ndataw + 1;
199 DI <= idi;
200 ENA <= '1';
201 nbusy := 0;
202
203 while BUSY='1' loop
204 nbusy := nbusy + 1;
205 wait for iclkw_period;
206 end loop;
207
208 writetimestamp(oline, CLKW_CYCLE, ": stim ");
209 write(oline, idi, right, 18);
210 write(oline, SIZEW, right, 7);
211 write(oline, string'(" ("));
212 write(oline, to_integer(unsigned(idi)), right, 5);
213 write(oline, string'(","));
214 write(oline, to_integer(unsigned(SIZEW)), right, 2);
215 write(oline, string'(")"));
216 if nbusy > 0 then
217 write(oline, string'(" nbusy="));
218 write(oline, nbusy, right, 2);
219 end if;
220 writeline(output, oline);
221
222 wait for iclkw_period;
223 ENA <= '0';
224
225 end loop; -- i
226
227 when others => -- bad directive
228 write(oline, string'("?? unknown command: "));
229 write(oline, dname);
230 writeline(output, oline);
231 report "aborting" severity failure;
232 end case;
233
234 else
235 report "failed to find command" severity failure;
236 end if;
237
238 testempty_ea(iline);
239
240 end loop; -- file_loop:
241
242 if N_HOLD = '1' then
243 wait until N_HOLD='0';
244 end if;
245 wait for 20*(iclkw_period+iclkr_period);
246 CLK_STOP <= '1';
247
248 writetimestamp(oline, CLKW_CYCLE, ": DONE-w ");
249 writeline(output, oline);
250 writetimestamp(oline, CLKR_CYCLE, ": DONE-r ");
251 writeline(output, oline);
252
253 wait; -- suspend proc_stim forever
254 -- clock is stopped, sim will end
255 end process proc_stim;
256
257
258 proc_moni: process
259 variable oline : line;
260 variable nhold : integer := 0; -- number of hold cycles before accept
261 variable isizer_last : slv4 := (others=>'0');
262 variable ido : slv16 := (others=>'0');
263 begin
264
265 loop
266 wait until rising_edge(CLKR);
267 wait for CLKR_C2OUT;
268
269 if VAL = '1' then
270 if R_HOLD = '1' then
271 nhold := nhold + 1;
272 else
273 ido := slv(to_unsigned(sv_ndatar, 16));
274 sv_ndatar := sv_ndatar + 1;
275
276 writetimestamp(oline, CLKR_CYCLE, ": moni ");
277 write(oline, DO, right, 18);
278 write(oline, SIZER, right, 7);
279 write(oline, string'(" ("));
280 write(oline, to_integer(unsigned(DO)), right, 5);
281 write(oline, string'(","));
282 write(oline, to_integer(unsigned(SIZER)), right, 2);
283 write(oline, string'(")"));
284 if nhold > 0 then
285 write(oline, string'(" nhold="));
286 write(oline, nhold, right, 2);
287 end if;
288
289 if DO = ido then
290 write(oline, string'(" OK"));
291 else
292 write(oline, string'(" FAIL, exp="));
293 write(oline, ido, right, 18);
294 end if;
295
296 writeline(output, oline);
297 nhold := 0;
298 end if;
299 else
300 if SIZER /= isizer_last then
301 writetimestamp(oline, CLKR_CYCLE, ": moni ");
302 write(oline, string'(" "));
303 write(oline, SIZER, right, 7);
304 write(oline, string'(" ("));
305 write(oline, to_integer(unsigned(SIZER)), right, 2);
306 write(oline, string'(")"));
307 writeline(output, oline);
308 end if;
309 end if;
310
311 isizer_last := SIZER;
312
313 end loop;
314
315 end process proc_moni;
316
317 proc_clkr: process (CLKR)
318 begin
319 if rising_edge(CLKR) then
320 R_HOLD <= N_HOLD;
321
322 if sv_nrstr > 0 then
323 RESETR <= '1';
324 sv_nrstr := sv_nrstr - 1;
325 else
326 RESETR <= '0';
327 end if;
328 end if;
329 end process proc_clkr;
330
331end sim;
out CLK_CYCLE integer
Definition: simclkcnt.vhd:29
in CLK slbit
Definition: simclkcnt.vhd:27
out CLK slbit
Definition: simclkv.vhd:30
in CLK_HOLD slbit := '0'
Definition: simclkv.vhd:32
in CLK_PERIOD Delay_length
Definition: simclkv.vhd:31
in CLK_STOP slbit := '0'
Definition: simclkv.vhd:34
std_logic_vector( 3 downto 0) slv4
Definition: slvtypes.vhd:36
std_logic_vector( 15 downto 0) slv16
Definition: slvtypes.vhd:48
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector slv
Definition: slvtypes.vhd:31
integer := 0 CLKW_CYCLE
Delay_length := 20 ns CLKR_PERIOD
integer := 0 CLKR_CYCLE
slv4 :=( others => '0') SIZER
Delay_length := 20 ns CLKW_PERIOD
Delay_length := 10 ns CLKR_C2OUT
slv4 :=( others => '0') SIZEW
slv16 :=( others => '0') DI
shared integer :=:= 0 sv_nrstr
shared integer :=:= 0 sv_ndatar
slv16 :=( others => '0') DO