w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tb_s3_sram_memctl.vhd
Go to the documentation of this file.
1-- $Id: tb_s3_sram_memctl.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_s3_sram_memctl - sim
7-- Description: Test bench for s3_sram_memctl
8--
9-- Dependencies: vlib/simlib/simclk
10-- vlib/simlib/simclkcnt
11-- bplib/issi/is61lv25616al
12-- s3_sram_memctl [UUT]
13--
14-- To test: s3_sram_memctl
15--
16-- Verified (with tb_s3_sram_memctl_stim.dat):
17-- Date Rev Code ghdl ise Target Comment
18-- 2007-12-16 101 _ssim 0.26 8.1.03 I27 xc3s1000 c:ok
19-- 2007-12-16 101 - 0.26 - - c:ok
20--
21-- Target Devices: generic
22-- Tool versions: xst 8.2-14.7; ghdl 0.18-0.31
23-- Revision History:
24-- Date Rev Version Comment
25-- 2011-12-23 444 1.1 use new simclk/simclkcnt
26-- 2011-11-21 432 1.0.6 now numeric_std clean
27-- 2010-05-23 293 1.0.5 output # busy cycles; change CHK pipeline logic
28-- 2010-05-16 291 1.0.4 rename tb_memctl_s3sram->tb_s3_sram_memctl
29-- 2008-03-24 129 1.0.3 CLK_CYCLE now 31 bits
30-- 2008-02-17 117 1.0.2 use req,we rather req_r,req_w interface
31-- 2008-01-20 113 1.0.1 rename memdrv -> memctl_s3sram
32-- 2007-12-15 101 1.0 Initial version
33------------------------------------------------------------------------------
34
35library ieee;
36use ieee.std_logic_1164.all;
37use ieee.numeric_std.all;
38use ieee.std_logic_textio.all;
39use std.textio.all;
40
41use work.slvtypes.all;
42use work.s3boardlib.all;
43use work.simlib.all;
44
47
48architecture sim of tb_s3_sram_memctl is
49
50 signal CLK : slbit := '0';
51 signal RESET : slbit := '0';
52 signal REQ : slbit := '0';
53 signal WE : slbit := '0';
54 signal BUSY : slbit := '0';
55 signal ACK_R : slbit := '0';
56 signal ACK_W : slbit := '0';
57 signal ACT_R : slbit := '0';
58 signal ACT_W : slbit := '0';
59 signal ADDR : slv18 := (others=>'0');
60 signal BE : slv4 := (others=>'0');
61 signal DI : slv32 := (others=>'0');
62 signal DO : slv32 := (others=>'0');
63 signal O_MEM_CE_N : slv2 := (others=>'0');
64 signal O_MEM_BE_N : slv4 := (others=>'0');
65 signal O_MEM_WE_N : slbit := '0';
66 signal O_MEM_OE_N : slbit := '0';
67 signal O_MEM_ADDR : slv18 := (others=>'0');
68 signal IO_MEM_DATA : slv32 := (others=>'0');
69
70 signal R_MEMON : slbit := '0';
71 signal N_CHK_DATA : slbit := '0';
72 signal N_REF_DATA : slv32 := (others=>'0');
73 signal N_REF_ADDR : slv18 := (others=>'0');
74 signal R_CHK_DATA_AL : slbit := '0';
75 signal R_REF_DATA_AL : slv32 := (others=>'0');
76 signal R_REF_ADDR_AL : slv18 := (others=>'0');
77 signal R_CHK_DATA_DL : slbit := '0';
78 signal R_REF_DATA_DL : slv32 := (others=>'0');
79 signal R_REF_ADDR_DL : slv18 := (others=>'0');
80
81 signal CLK_STOP : slbit := '0';
82 signal CLK_CYCLE : integer := 0;
83
84 constant clock_period : Delay_length := 20 ns;
85 constant clock_offset : Delay_length := 200 ns;
86 constant setup_time : Delay_length := 5 ns;
87 constant c2out_time : Delay_length := 10 ns;
88
89begin
90
91 CLKGEN : simclk
92 generic map (
95 port map (
96 CLK => CLK,
98 );
99
100 CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
101
102 MEM_L : entity work.is61lv25616al
103 port map (
104 CE_N => O_MEM_CE_N(0),
105 OE_N => O_MEM_OE_N,
106 WE_N => O_MEM_WE_N,
107 UB_N => O_MEM_BE_N(1),
108 LB_N => O_MEM_BE_N(0),
109 ADDR => O_MEM_ADDR,
110 DATA => IO_MEM_DATA(15 downto 0)
111 );
112
113 MEM_U : entity work.is61lv25616al
114 port map (
115 CE_N => O_MEM_CE_N(1),
116 OE_N => O_MEM_OE_N,
117 WE_N => O_MEM_WE_N,
118 UB_N => O_MEM_BE_N(3),
119 LB_N => O_MEM_BE_N(2),
120 ADDR => O_MEM_ADDR,
121 DATA => IO_MEM_DATA(31 downto 16)
122 );
123
124 UUT : s3_sram_memctl
125 port map (
126 CLK => CLK,
127 RESET => RESET,
128 REQ => REQ,
129 WE => WE,
130 BUSY => BUSY,
131 ACK_R => ACK_R,
132 ACK_W => ACK_W,
133 ACT_R => ACT_R,
134 ACT_W => ACT_W,
135 ADDR => ADDR,
136 BE => BE,
137 DI => DI,
138 DO => DO,
145 );
146
147 proc_stim: process
148 file fstim : text open read_mode is "tb_s3_sram_memctl_stim";
149 variable iline : line;
150 variable oline : line;
151 variable ok : boolean;
152 variable dname : string(1 to 6) := (others=>' ');
153 variable idelta : integer := 0;
154 variable iaddr : slv18 := (others=>'0');
155 variable idata : slv32 := (others=>'0');
156 variable ibe : slv4 := (others=>'0');
157 variable ival : slbit := '0';
158 variable nbusy : integer := 0;
159
160 begin
161
162 wait for clock_offset - setup_time;
163
164 file_loop: while not endfile(fstim) loop
165
166 readline (fstim, iline);
167
168 readcomment(iline, ok);
169 next file_loop when ok;
170
171 readword(iline, dname, ok);
172 if ok then
173 case dname is
174 when ".memon" => -- .memon
175 read_ea(iline, ival);
176 R_MEMON <= ival;
177 wait for 2*clock_period;
178
179 when ".reset" => -- .reset
180 write(oline, string'(".reset"));
181 writeline(output, oline);
182 RESET <= '1';
183 wait for clock_period;
184 RESET <= '0';
185 wait for 9*clock_period;
186
187 when ".wait " => -- .wait
188 read_ea(iline, idelta);
189 wait for idelta*clock_period;
190
191 when "read " => -- read
192 readgen_ea(iline, iaddr, 16);
193 readgen_ea(iline, idata, 16);
194 ADDR <= iaddr;
195 REQ <= '1';
196 WE <= '0';
197
198 writetimestamp(oline, CLK_CYCLE, ": stim read ");
199 writegen(oline, iaddr, right, 6, 16);
200 write(oline, string'(" "));
201 writegen(oline, idata, right, 9, 16);
202
203 nbusy := 0;
204 while BUSY = '1' loop
205 nbusy := nbusy + 1;
206 wait for clock_period;
207 end loop;
208
209 write(oline, string'(" nbusy="));
210 write(oline, nbusy, right, 2);
211 writeline(output, oline);
212
213 N_CHK_DATA <= '1', '0' after clock_period;
214 N_REF_DATA <= idata;
215 N_REF_ADDR <= iaddr;
216
217 wait for clock_period;
218 REQ <= '0';
219
220 when "write " => -- write
221 readgen_ea(iline, iaddr, 16);
222 read_ea(iline, ibe);
223 readgen_ea(iline, idata, 16);
224 ADDR <= iaddr;
225 BE <= ibe;
226 DI <= idata;
227 REQ <= '1';
228 WE <= '1';
229
230 writetimestamp(oline, CLK_CYCLE, ": stim write");
231 writegen(oline, iaddr, right, 6, 16);
232 writegen(oline, ibe , right, 5, 2);
233 writegen(oline, idata, right, 9, 16);
234
235 nbusy := 0;
236 while BUSY = '1' loop
237 nbusy := nbusy + 1;
238 wait for clock_period;
239 end loop;
240
241 write(oline, string'(" nbusy="));
242 write(oline, nbusy, right, 2);
243 writeline(output, oline);
244
245 wait for clock_period;
246 REQ <= '0';
247
248 when others => -- bad directive
249 write(oline, string'("?? unknown directive: "));
250 write(oline, dname);
251 writeline(output, oline);
252 report "aborting" severity failure;
253 end case;
254 else
255 report "failed to find command" severity failure;
256
257 end if;
258
259 testempty_ea(iline);
260
261 end loop; -- file fstim
262
263 wait for 10*clock_period;
264
265 writetimestamp(oline, CLK_CYCLE, ": DONE ");
266 writeline(output, oline);
267
268 CLK_STOP <= '1';
269
270 wait; -- suspend proc_stim forever
271 -- clock is stopped, sim will end
272
273 end process proc_stim;
274
275
276 proc_moni: process
277 variable oline : line;
278 begin
279
280 loop
281 wait until rising_edge(CLK);
282
283 if ACK_R = '1' then
284 writetimestamp(oline, CLK_CYCLE, ": moni ");
285 writegen(oline, DO, right, 9, 16);
286 if R_CHK_DATA_DL = '1' then
287 write(oline, string'(" CHECK"));
288 if R_REF_DATA_DL = DO then
289 write(oline, string'(" OK"));
290 else
291 write(oline, string'(" FAIL, exp="));
292 writegen(oline, R_REF_DATA_DL, right, 9, 16);
293 write(oline, string'(" for a="));
294 writegen(oline, R_REF_ADDR_DL, right, 5, 16);
295 end if;
296 R_CHK_DATA_DL <= '0';
297 end if;
298 writeline(output, oline);
299 end if;
300
301 if R_CHK_DATA_AL = '1' then
305 R_CHK_DATA_AL <= '0';
306 end if;
307 if N_CHK_DATA = '1' then
311 end if;
312
313 end loop;
314
315 end process proc_moni;
316
317
318 proc_memon: process
319 variable oline : line;
320 begin
321
322 loop
323 wait until rising_edge(CLK);
324
325 if R_MEMON = '1' then
326 writetimestamp(oline, CLK_CYCLE, ": mem ");
327 write(oline, string'(" ce="));
328 write(oline, not O_MEM_CE_N, right, 2);
329 write(oline, string'(" be="));
330 write(oline, not O_MEM_BE_N, right, 4);
331 write(oline, string'(" we="));
332 write(oline, not O_MEM_WE_N, right);
333 write(oline, string'(" oe="));
334 write(oline, not O_MEM_OE_N, right);
335 write(oline, string'(" a="));
336 writegen(oline, O_MEM_ADDR, right, 5, 16);
337 write(oline, string'(" d="));
338 writegen(oline, IO_MEM_DATA, right, 8, 16);
339 writeline(output, oline);
340 end if;
341
342 end loop;
343
344 end process proc_memon;
345
346
347end sim;
in UB_N slbit
in ADDR slv18
in WE_N slbit
in CE_N slbit
in OE_N slbit
in LB_N slbit
inout DATA slv16
inout IO_MEM_DATA slv32
out O_MEM_CE_N slv2
out ACT_W slbit
out O_MEM_WE_N slbit
out ACK_R slbit
out BUSY slbit
out O_MEM_ADDR slv18
out ACT_R slbit
out O_MEM_BE_N slv4
out ACK_W slbit
out O_MEM_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( 3 downto 0) slv4
Definition: slvtypes.vhd:36
std_logic_vector( 17 downto 0) slv18
Definition: slvtypes.vhd:51
std_logic_vector( 31 downto 0) slv32
Definition: slvtypes.vhd:59
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 1 downto 0) slv2
Definition: slvtypes.vhd:34
slv32 :=( others => '0') R_REF_DATA_DL
slv18 :=( others => '0') N_REF_ADDR
slv4 :=( others => '0') BE
slv32 :=( others => '0') DO
slv4 :=( others => '0') O_MEM_BE_N
Delay_length := 200 ns clock_offset
Delay_length := 5 ns setup_time
slv2 :=( others => '0') O_MEM_CE_N
slv18 :=( others => '0') O_MEM_ADDR
slv32 :=( others => '0') IO_MEM_DATA
Delay_length := 10 ns c2out_time
slv32 :=( others => '0') DI
slv18 :=( others => '0') R_REF_ADDR_DL
slv32 :=( others => '0') N_REF_DATA
slv32 :=( others => '0') R_REF_DATA_AL
slv18 :=( others => '0') R_REF_ADDR_AL
slv18 :=( others => '0') ADDR
Delay_length := 20 ns clock_period