w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tb_c7_sram_memctl.vhd
Go to the documentation of this file.
1-- $Id: tb_c7_sram_memctl.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2017- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: tb_c7_sram_memctl - sim
7-- Description: Test bench for c7_sram_memctl
8--
9-- Dependencies: vlib/simlib/simclk
10-- vlib/simlib/simclkcnt
11-- bplib/issi/is61wv5128bll
12-- c7_sram_memctl [UUT]
13--
14-- To test: c7_sram_memctl
15--
16-- Verified (with tb_c7_sram_memctl_stim.dat):
17-- Date Rev Code ghdl viv Target Comment
18-- 2017-06-11 912 _ssim 0.34 2017.1 xx xx
19--
20-- Target Devices: generic
21-- Tool versions: viv 2017.1; ghdl 0.34
22--
23-- Revision History:
24-- Date Rev Version Comment
25-- 2017-06-13 913 1.0 Initial version (derived from tb_s3_sram_memctl)
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.cmoda7lib.all;
36use work.simlib.all;
37
40
41architecture sim of tb_c7_sram_memctl is
42
43 signal CLK : slbit := '0';
44 signal RESET : slbit := '0';
45 signal REQ : slbit := '0';
46 signal WE : slbit := '0';
47 signal BUSY : slbit := '0';
48 signal ACK_R : slbit := '0';
49 signal ACK_W : slbit := '0';
50 signal ACT_R : slbit := '0';
51 signal ACT_W : slbit := '0';
52 signal ADDR : slv17 := (others=>'0');
53 signal BE : slv4 := (others=>'0');
54 signal DI : slv32 := (others=>'0');
55 signal DO : slv32 := (others=>'0');
56 signal O_MEM_CE_N : slbit := '0';
57 signal O_MEM_WE_N : slbit := '0';
58 signal O_MEM_OE_N : slbit := '0';
59 signal O_MEM_ADDR : slv19 := (others=>'0');
60 signal IO_MEM_DATA : slv8 := (others=>'0');
61
62 signal R_MEMON : slbit := '0';
63 signal N_CHK_DATA : slbit := '0';
64 signal N_REF_DATA : slv32 := (others=>'0');
65 signal N_REF_ADDR : slv17 := (others=>'0');
66 signal R_CHK_DATA_AL : slbit := '0';
67 signal R_REF_DATA_AL : slv32 := (others=>'0');
68 signal R_REF_ADDR_AL : slv17 := (others=>'0');
69 signal R_CHK_DATA_DL : slbit := '0';
70 signal R_REF_DATA_DL : slv32 := (others=>'0');
71 signal R_REF_ADDR_DL : slv17 := (others=>'0');
72
73 signal CLK_STOP : slbit := '0';
74 signal CLK_CYCLE : integer := 0;
75
76 constant clock_period : Delay_length := 20 ns;
77 constant clock_offset : Delay_length := 200 ns;
78 constant setup_time : Delay_length := 5 ns;
79 constant c2out_time : Delay_length := 10 ns;
80
81begin
82
83 CLKGEN : simclk
84 generic map (
87 port map (
88 CLK => CLK,
90 );
91
92 CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
93
94 MEM : entity work.is61wv5128bll
95 port map (
101 );
102
103 UUT : c7_sram_memctl
104 port map (
105 CLK => CLK,
106 RESET => RESET,
107 REQ => REQ,
108 WE => WE,
109 BUSY => BUSY,
110 ACK_R => ACK_R,
111 ACK_W => ACK_W,
112 ACT_R => ACT_R,
113 ACT_W => ACT_W,
114 ADDR => ADDR,
115 BE => BE,
116 DI => DI,
117 DO => DO,
123 );
124
125 proc_stim: process
126 file fstim : text open read_mode is "tb_c7_sram_memctl_stim";
127 variable iline : line;
128 variable oline : line;
129 variable ok : boolean;
130 variable dname : string(1 to 6) := (others=>' ');
131 variable idelta : integer := 0;
132 variable iaddr : slv17 := (others=>'0');
133 variable idata : slv32 := (others=>'0');
134 variable ibe : slv4 := (others=>'0');
135 variable ival : slbit := '0';
136 variable nbusy : integer := 0;
137
138 begin
139
140 wait for clock_offset - setup_time;
141
142 file_loop: while not endfile(fstim) loop
143
144 readline (fstim, iline);
145
146 readcomment(iline, ok);
147 next file_loop when ok;
148
149 readword(iline, dname, ok);
150 if ok then
151 case dname is
152 when ".memon" => -- .memon
153 read_ea(iline, ival);
154 R_MEMON <= ival;
155 wait for 2*clock_period;
156
157 when ".reset" => -- .reset
158 write(oline, string'(".reset"));
159 writeline(output, oline);
160 RESET <= '1';
161 wait for clock_period;
162 RESET <= '0';
163 wait for 9*clock_period;
164
165 when ".wait " => -- .wait
166 read_ea(iline, idelta);
167 wait for idelta*clock_period;
168
169 when "read " => -- read
170 readgen_ea(iline, iaddr, 16);
171 readgen_ea(iline, idata, 16);
172 ADDR <= iaddr;
173 REQ <= '1';
174 WE <= '0';
175
176 writetimestamp(oline, CLK_CYCLE, ": stim read ");
177 writegen(oline, iaddr, right, 6, 16);
178 write(oline, string'(" "));
179 writegen(oline, idata, right, 9, 16);
180
181 wait for clock_period;
182 REQ <= '0';
183
184 N_CHK_DATA <= '1', '0' after clock_period;
185 N_REF_DATA <= idata;
186 N_REF_ADDR <= iaddr;
187
188 nbusy := 0;
189 while BUSY = '1' loop
190 nbusy := nbusy + 1;
191 wait for clock_period;
192 end loop;
193
194 write(oline, string'(" nbusy="));
195 write(oline, nbusy, right, 2);
196 writeline(output, oline);
197
198 when "write " => -- write
199 readgen_ea(iline, iaddr, 16);
200 read_ea(iline, ibe);
201 readgen_ea(iline, idata, 16);
202 ADDR <= iaddr;
203 BE <= ibe;
204 DI <= idata;
205 REQ <= '1';
206 WE <= '1';
207
208 writetimestamp(oline, CLK_CYCLE, ": stim write");
209 writegen(oline, iaddr, right, 6, 16);
210 writegen(oline, ibe , right, 5, 2);
211 writegen(oline, idata, right, 9, 16);
212
213 wait for clock_period;
214 REQ <= '0';
215 WE <= '0';
216
217 nbusy := 0;
218 while BUSY = '1' loop
219 nbusy := nbusy + 1;
220 wait for clock_period;
221 end loop;
222
223 write(oline, string'(" nbusy="));
224 write(oline, nbusy, right, 2);
225 writeline(output, oline);
226
227
228 when others => -- bad directive
229 write(oline, string'("?? unknown directive: "));
230 write(oline, dname);
231 writeline(output, oline);
232 report "aborting" severity failure;
233 end case;
234 else
235 report "failed to find command" severity failure;
236
237 end if;
238
239 testempty_ea(iline);
240
241 end loop; -- file fstim
242
243 wait for 10*clock_period;
244
245 writetimestamp(oline, CLK_CYCLE, ": DONE ");
246 writeline(output, oline);
247
248 CLK_STOP <= '1';
249
250 wait; -- suspend proc_stim forever
251 -- clock is stopped, sim will end
252
253 end process proc_stim;
254
255
256 proc_moni: process
257 variable oline : line;
258 begin
259
260 loop
261 wait until rising_edge(CLK);
262
263 if ACK_R = '1' then
264 writetimestamp(oline, CLK_CYCLE, ": moni ");
265 writegen(oline, DO, right, 9, 16);
266 if R_CHK_DATA_DL = '1' then
267 write(oline, string'(" CHECK"));
268 if R_REF_DATA_DL = DO then
269 write(oline, string'(" OK"));
270 else
271 write(oline, string'(" FAIL, exp="));
272 writegen(oline, R_REF_DATA_DL, right, 9, 16);
273 write(oline, string'(" for a="));
274 writegen(oline, R_REF_ADDR_DL, right, 5, 16);
275 end if;
276 R_CHK_DATA_DL <= '0';
277 end if;
278 writeline(output, oline);
279 end if;
280
281 if R_CHK_DATA_AL = '1' then
285 R_CHK_DATA_AL <= '0';
286 end if;
287 if N_CHK_DATA = '1' then
291 end if;
292
293 end loop;
294
295 end process proc_moni;
296
297
298 proc_memon: process
299 variable oline : line;
300 begin
301
302 loop
303 wait until rising_edge(CLK);
304
305 if R_MEMON = '1' then
306 writetimestamp(oline, CLK_CYCLE, ": mem ");
307 write(oline, string'(" ce="));
308 write(oline, not O_MEM_CE_N, right, 2);
309 write(oline, string'(" we="));
310 write(oline, not O_MEM_WE_N, right);
311 write(oline, string'(" oe="));
312 write(oline, not O_MEM_OE_N, right);
313 write(oline, string'(" a="));
314 writegen(oline, O_MEM_ADDR, right, 5, 16);
315 write(oline, string'(" d="));
316 writegen(oline, IO_MEM_DATA, right, 8, 16);
317 writeline(output, oline);
318 end if;
319
320 end loop;
321
322 end process proc_memon;
323
324
325end sim;
out ACT_W slbit
out O_MEM_WE_N slbit
inout IO_MEM_DATA slv8
out ACK_R slbit
out BUSY slbit
out O_MEM_CE_N slbit
out ACT_R slbit
out ACK_W slbit
out O_MEM_OE_N slbit
out O_MEM_ADDR slv19
inout DATA slv8
in ADDR slv19
in WE_N slbit
in CE_N slbit
in OE_N slbit
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( 18 downto 0) slv19
Definition: slvtypes.vhd:52
std_logic_vector( 3 downto 0) slv4
Definition: slvtypes.vhd:36
std_logic_vector( 16 downto 0) slv17
Definition: slvtypes.vhd:50
std_logic_vector( 31 downto 0) slv32
Definition: slvtypes.vhd:59
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 7 downto 0) slv8
Definition: slvtypes.vhd:40
slv17 :=( others => '0') R_REF_ADDR_DL
slv32 :=( others => '0') R_REF_DATA_DL
slv4 :=( others => '0') BE
slv32 :=( others => '0') DO
slv17 :=( others => '0') N_REF_ADDR
slv19 :=( others => '0') O_MEM_ADDR
Delay_length := 200 ns clock_offset
Delay_length := 5 ns setup_time
Delay_length := 10 ns c2out_time
slv17 :=( others => '0') R_REF_ADDR_AL
slv32 :=( others => '0') DI
slv8 :=( others => '0') IO_MEM_DATA
slv17 :=( others => '0') ADDR
slv32 :=( others => '0') N_REF_DATA
slv32 :=( others => '0') R_REF_DATA_AL
Delay_length := 20 ns clock_period