w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tb_fifo_simple_dram.vhd
Go to the documentation of this file.
1-- $Id: tb_fifo_simple_dram.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2019- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: tb_fifo_simple_dram - sim
7-- Description: Test bench for fifo_simple_dram
8--
9-- Dependencies: simlib/simclk
10-- simlib/simclkcnt
11-- tbd_fifo_simple_dram [UUT]
12--
13-- To test: fifo_simple_dram
14--
15-- Target Devices: generic
16-- Tool versions: xst 14.7; viv 2017.2 ghdl 0.35
17-- Revision History:
18-- Date Rev Version Comment
19-- 2019-02-09 1109 1.0 Initial version
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_simple_dram is
35
36 signal CLK : slbit := '0';
37 signal RESET : slbit := '0';
38 signal CE : slbit := '0';
39 signal WE : slbit := '0';
40 signal DI : slv16 := (others=>'0');
41 signal DO : slv16 := (others=>'0');
42 signal EMPTY : slbit := '0';
43 signal FULL : slbit := '0';
44 signal SIZE : slv4 := (others=>'0');
45
46 signal N_EMPTY : slbit := '1';
47 signal N_FULL : slbit := '0';
48 signal N_SIZE : slv4 := (others=>'0');
49 signal R_EMPTY : slbit := '1';
50 signal R_FULL : slbit := '0';
51 signal R_SIZE : slv4 := (others=>'0');
52
53 signal CLK_STOP : slbit := '0';
54 signal CLK_CYCLE : integer := 0;
55
56 constant clock_period : Delay_length := 20 ns;
57 constant clock_offset : Delay_length := 200 ns;
58 constant setup_time : Delay_length := 5 ns;
59 constant c2out_time : Delay_length := 10 ns;
60
61begin
62
63 CLKGEN : simclk
64 generic map (
67 port map (
68 CLK => CLK,
70 );
71
72 CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
73
74 UUT : entity work.tbd_fifo_simple_dram
75 port map (
76 CLK => CLK,
77 RESET => RESET,
78 CE => CE,
79 WE => WE,
80 DI => DI,
81 DO => DO,
82 EMPTY => EMPTY,
83 FULL => FULL,
84 SIZE => SIZE
85 );
86
87
88 proc_stim: process
89 file fstim : text open read_mode is "tb_fifo_simple_dram_stim";
90 variable iline : line;
91 variable oline : line;
92 variable dname : string(1 to 6) := (others=>' ');
93 variable ok : boolean;
94 variable nwait : integer := 0; --
95 variable idi : slv16 := (others=>'0');
96 variable ido : slv16 := (others=>'0');
97 variable isize : slv4 := (others=>'0');
98 begin
99
100 wait for clock_offset;
101 wait until rising_edge(CLK);
102
103 file_loop: while not endfile(fstim) loop
104
105 readline (fstim, iline);
106
107 readcomment(iline, ok);
108 next file_loop when ok;
109
110 readword(iline, dname, ok);
111 if ok then
112 case dname is
113 when ".wait " => -- .wait ncyc
114 read_ea(iline, nwait);
115 for i in 1 to nwait loop
116 wait until rising_edge(CLK);
117 end loop; -- i
118
119 when "reset " => -- reset
120 writetimestamp(oline, CLK_CYCLE, ": reset");
121 writeline(output, oline);
122 RESET <= '1';
123 isize := "0000";
124 N_EMPTY <= '1';
125 N_FULL <= '0';
126 N_SIZE <= isize;
127 wait until rising_edge(CLK);
128 RESET <= '0';
129 wait for 0 ns;
130
131 when "write " => -- write di
132 readgen_ea(iline, idi, 16);
133 writetimestamp(oline, CLK_CYCLE, ": write");
134 write(oline, idi, right, 18);
135 writeline(output, oline);
136 CE <= '1';
137 WE <= '1';
138 DI <= idi;
139 isize := slv(unsigned(isize) + 1);
140 N_SIZE <= isize;
141 N_EMPTY <= '0';
142 if isize = "1111" then
143 N_FULL <= '1';
144 end if;
145
146 wait until rising_edge(CLK);
147 CE <= '0';
148 WE <= '0';
149 wait for 0 ns;
150
151 when "read " => -- read do
152 readgen_ea(iline, ido, 16);
153 CE <= '1';
154 WE <= '0';
155 isize := slv(unsigned(isize) - 1);
156 N_SIZE <= isize;
157 N_FULL <= '0';
158 if isize = "0000" then
159 N_EMPTY <= '1';
160 end if;
161
162 wait for c2out_time; -- check same cycle read response
163 writetimestamp(oline, CLK_CYCLE, ": read ");
164 write(oline, DO, right, 18);
165 if DO = ido then
166 write(oline, string'(" OK"));
167 else
168 write(oline, string'(" FAIL, exp="));
169 write(oline, ido, right, 18);
170 end if;
171 writeline(output, oline);
172
173 wait until rising_edge(CLK);
174 CE <= '0';
175 wait for 0 ns;
176
177 when others => -- bad directive
178 write(oline, string'("?? unknown command: "));
179 write(oline, dname);
180 writeline(output, oline);
181 report "aborting" severity failure;
182 end case;
183
184 else
185 report "failed to find command" severity failure;
186 end if;
187
188 end loop; -- file_loop:
189
190 writetimestamp(oline, CLK_CYCLE, ": DONE ");
191 writeline(output, oline);
192
193 wait for 20*clock_period;
194
195 CLK_STOP <= '1';
196
197 wait; -- suspend proc_stim forever
198 -- clock is stopped, sim will end
199
200 end process proc_stim;
201
202
203 proc_moni: process
204 variable oline : line;
205 variable iempty_1 : slbit := '1';
206 begin
207
208 loop
209
210 wait until rising_edge(CLK); -- at rising clock
211
212 R_EMPTY <= N_EMPTY; -- latch expected values
213 R_FULL <= N_FULL;
214 R_SIZE <= N_SIZE;
215
216 wait for c2out_time; -- after clock2output time check
217
218 if EMPTY='0' or iempty_1 ='0' then
219 writetimestamp(oline, CLK_CYCLE, ": moni ");
220 write(oline, DO, right, 18);
221 write(oline, EMPTY, right, 3);
222 write(oline, FULL, right, 2);
223 write(oline, SIZE, right, 6);
224 write(oline, string'(" ("));
225 write(oline, to_integer(unsigned(SIZE)), right, 2);
226 write(oline, string'(")"));
227 if EMPTY /= R_EMPTY then
228 write(oline, string'(" FAIL EMPTY exp="));
229 write(oline, R_EMPTY);
230 end if;
231 if FULL /= R_FULL then
232 write(oline, string'(" FAIL FULL exp="));
233 write(oline, R_FULL);
234 end if;
235 if SIZE /= R_SIZE then
236 write(oline, string'(" FAIL SIZE exp="));
237 write(oline, R_SIZE);
238 end if;
239 writeline(output, oline);
240 end if;
241
242 iempty_1 := EMPTY;
243
244 end loop;
245
246 end process proc_moni;
247
248end sim;
out CLK slbit
Definition: simclk.vhd:33
OFFSET Delay_length := 200 ns
Definition: simclk.vhd:31
in CLK_STOP slbit := '0'
Definition: simclk.vhd:35
PERIOD Delay_length := 20 ns
Definition: simclk.vhd:30
out CLK_CYCLE integer
Definition: simclkcnt.vhd:29
in CLK slbit
Definition: simclkcnt.vhd:27
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
slv4 :=( others => '0') N_SIZE
slv4 :=( others => '0') SIZE
slv4 :=( others => '0') R_SIZE
Delay_length := 200 ns clock_offset
Delay_length := 5 ns setup_time
Delay_length := 10 ns c2out_time
slv16 :=( others => '0') DI
slv16 :=( others => '0') DO
Delay_length := 20 ns clock_period