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