w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tb_nx_cram_memctl.vhd
Go to the documentation of this file.
1-- $Id: tb_nx_cram_memctl.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2010-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: tb_nx_cram_memctl - sim
7-- Description: Test bench for nx_cram_memctl
8--
9-- Dependencies: vlib/simlib/simclk
10-- vlib/simlib/simclkcnt
11-- bplib/micron/mt45w8mw16b
12-- tbd_nx_cram_memctl [UUT, abstact]
13--
14-- To test: nx_cram_memctl_as (via tbd_nx_cram_memctl_as)
15--
16-- Target Devices: generic
17-- Tool versions: xst 11.4-14.7; ghdl 0.26-0.31
18-- Revision History:
19-- Date Rev Version Comment
20-- 2011-12-23 444 1.4 use new simclk/simclkcnt
21-- 2011-11-26 433 1.3 renamed from tb_n2_cram_memctl
22-- 2011-11-21 432 1.2 now numeric_std clean; update O_FLA_CE_N usage
23-- 2010-05-30 297 1.1 use abstact uut tbd_nx_cram_memctl
24-- 2010-05-23 293 1.0 Initial version (derived from tb_s3_sram_memctl)
25------------------------------------------------------------------------------
26
27library ieee;
28use ieee.std_logic_1164.all;
29use ieee.numeric_std.all;
30use ieee.std_logic_textio.all;
31use std.textio.all;
32
33use work.slvtypes.all;
34use work.simlib.all;
35
38
39architecture sim of tb_nx_cram_memctl is
40
41component tbd_nx_cram_memctl is -- CRAM controller (abstract) [tb design]
42 port (
43 CLK : in slbit; -- clock
44 RESET : in slbit; -- reset
45 REQ : in slbit; -- request
46 WE : in slbit; -- write enable
47 BUSY : out slbit; -- controller busy
48 ACK_R : out slbit; -- acknowledge read
49 ACK_W : out slbit; -- acknowledge write
50 ACT_R : out slbit; -- signal active read
51 ACT_W : out slbit; -- signal active write
52 ADDR : in slv22; -- address (32 bit word address)
53 BE : in slv4; -- byte enable
54 DI : in slv32; -- data in (memory view)
55 DO : out slv32; -- data out (memory view)
56 O_MEM_CE_N : out slbit; -- cram: chip enable (act.low)
57 O_MEM_BE_N : out slv2; -- cram: byte enables (act.low)
58 O_MEM_WE_N : out slbit; -- cram: write enable (act.low)
59 O_MEM_OE_N : out slbit; -- cram: output enable (act.low)
60 O_MEM_ADV_N : out slbit; -- cram: address valid (act.low)
61 O_MEM_CLK : out slbit; -- cram: clock
62 O_MEM_CRE : out slbit; -- cram: command register enable
63 I_MEM_WAIT : in slbit; -- cram: mem wait
64 O_MEM_ADDR : out slv23; -- cram: address lines
65 IO_MEM_DATA : inout slv16 -- cram: data lines
66 );
67end component;
68
69 signal CLK : slbit := '0';
70 signal RESET : slbit := '0';
71 signal REQ : slbit := '0';
72 signal WE : slbit := '0';
73 signal BUSY : slbit := '0';
74 signal ACK_R : slbit := '0';
75 signal ACK_W : slbit := '0';
76 signal ACT_R : slbit := '0';
77 signal ACT_W : slbit := '0';
78 signal ADDR : slv22 := (others=>'0');
79 signal BE : slv4 := (others=>'0');
80 signal DI : slv32 := (others=>'0');
81 signal DO : slv32 := (others=>'0');
82 signal O_MEM_CE_N : slbit := '0';
83 signal O_MEM_BE_N : slv2 := (others=>'0');
84 signal O_MEM_WE_N : slbit := '0';
85 signal O_MEM_OE_N : slbit := '0';
86 signal O_MEM_ADV_N : slbit := '0';
87 signal O_MEM_CLK : slbit := '0';
88 signal O_MEM_CRE : slbit := '0';
89 signal I_MEM_WAIT : slbit := '0';
90 signal O_MEM_ADDR : slv23 := (others=>'0');
91 signal IO_MEM_DATA : slv16 := (others=>'0');
92
93 signal R_MEMON : slbit := '0';
94 signal N_CHK_DATA : slbit := '0';
95 signal N_REF_DATA : slv32 := (others=>'0');
96 signal N_REF_ADDR : slv22 := (others=>'0');
97 signal R_CHK_DATA_AL : slbit := '0';
98 signal R_REF_DATA_AL : slv32 := (others=>'0');
99 signal R_REF_ADDR_AL : slv22 := (others=>'0');
100 signal R_CHK_DATA_DL : slbit := '0';
101 signal R_REF_DATA_DL : slv32 := (others=>'0');
102 signal R_REF_ADDR_DL : slv22 := (others=>'0');
103
104 signal CLK_STOP : slbit := '0';
105 signal CLK_CYCLE : integer := 0;
106
107 constant clock_period : Delay_length := 20 ns; -- when changed update also
108 -- READ0DELAY ect delays !!
109 constant clock_offset : Delay_length := 200 ns;
110 constant setup_time : Delay_length := 7.5 ns; -- compatible ucf for
111 constant c2out_time : Delay_length := 12.0 ns; -- tbd_nx_cram_memctl_as
112
113begin
114
115 CLKGEN : simclk
116 generic map (
119 port map (
120 CLK => CLK,
122 );
123
124 CLKCNT : simclkcnt port map (CLK => CLK, CLK_CYCLE => CLK_CYCLE);
125
126 MEM : entity work.mt45w8mw16b
127 port map (
128 CLK => O_MEM_CLK,
129 CE_N => O_MEM_CE_N,
130 OE_N => O_MEM_OE_N,
131 WE_N => O_MEM_WE_N,
132 UB_N => O_MEM_BE_N(1),
133 LB_N => O_MEM_BE_N(0),
135 CRE => O_MEM_CRE,
136 MWAIT => I_MEM_WAIT,
137 ADDR => O_MEM_ADDR,
139 );
140
141 UUT : tbd_nx_cram_memctl
142 port map (
143 CLK => CLK,
144 RESET => RESET,
145 REQ => REQ,
146 WE => WE,
147 BUSY => BUSY,
148 ACK_R => ACK_R,
149 ACK_W => ACK_W,
150 ACT_R => ACT_R,
151 ACT_W => ACT_W,
152 ADDR => ADDR,
153 BE => BE,
154 DI => DI,
155 DO => DO,
156 O_MEM_CE_N => O_MEM_CE_N,
157 O_MEM_BE_N => O_MEM_BE_N,
158 O_MEM_WE_N => O_MEM_WE_N,
159 O_MEM_OE_N => O_MEM_OE_N,
160 O_MEM_CLK => O_MEM_CLK,
161 O_MEM_ADV_N => O_MEM_ADV_N,
162 O_MEM_CRE => O_MEM_CRE,
163 I_MEM_WAIT => I_MEM_WAIT,
164 O_MEM_ADDR => O_MEM_ADDR,
165 IO_MEM_DATA => IO_MEM_DATA
166 );
167
168 proc_stim: process
169 file fstim : text open read_mode is "tb_nx_cram_memctl_stim";
170 variable iline : line;
171 variable oline : line;
172 variable ok : boolean;
173 variable dname : string(1 to 6) := (others=>' ');
174 variable idelta : integer := 0;
175 variable iaddr : slv22 := (others=>'0');
176 variable idata : slv32 := (others=>'0');
177 variable ibe : slv4 := (others=>'0');
178 variable ival : slbit := '0';
179 variable nbusy : integer := 0;
180
181 begin
182
183 wait for clock_offset - setup_time;
184
185 file_loop: while not endfile(fstim) loop
186
187 readline (fstim, iline);
188
189 readcomment(iline, ok);
190 next file_loop when ok;
191
192 readword(iline, dname, ok);
193 if ok then
194 case dname is
195 when ".memon" => -- .memon
196 read_ea(iline, ival);
197 R_MEMON <= ival;
198 wait for 2*clock_period;
199
200 when ".reset" => -- .reset
201 write(oline, string'(".reset"));
202 writeline(output, oline);
203 RESET <= '1';
204 wait for clock_period;
205 RESET <= '0';
206 wait for 9*clock_period;
207
208 when ".wait " => -- .wait
209 read_ea(iline, idelta);
210 wait for idelta*clock_period;
211
212 when "read " => -- read
213 readgen_ea(iline, iaddr, 16);
214 readgen_ea(iline, idata, 16);
215 ADDR <= iaddr;
216 REQ <= '1';
217 WE <= '0';
218
219 writetimestamp(oline, CLK_CYCLE, ": stim read ");
220 writegen(oline, iaddr, right, 7, 16);
221 write(oline, string'(" "));
222 writegen(oline, idata, right, 9, 16);
223
224 nbusy := 0;
225 while BUSY='1' loop
226 nbusy := nbusy + 1;
227 wait for clock_period;
228 end loop;
229
230 write(oline, string'(" nbusy="));
231 write(oline, nbusy, right, 2);
232 writeline(output, oline);
233
234 N_CHK_DATA <= '1', '0' after clock_period;
235 N_REF_DATA <= idata;
236 N_REF_ADDR <= iaddr;
237
238 wait for clock_period;
239 REQ <= '0';
240
241 when "write " => -- write
242 readgen_ea(iline, iaddr, 16);
243 read_ea(iline, ibe);
244 readgen_ea(iline, idata, 16);
245 ADDR <= iaddr;
246 BE <= ibe;
247 DI <= idata;
248 REQ <= '1';
249 WE <= '1';
250
251 writetimestamp(oline, CLK_CYCLE, ": stim write");
252 writegen(oline, iaddr, right, 7, 16);
253 writegen(oline, ibe , right, 5, 2);
254 writegen(oline, idata, right, 9, 16);
255
256 nbusy := 0;
257 while BUSY = '1' loop
258 nbusy := nbusy + 1;
259 wait for clock_period;
260 end loop;
261
262 write(oline, string'(" nbusy="));
263 write(oline, nbusy, right, 2);
264 writeline(output, oline);
265
266 wait for clock_period;
267 REQ <= '0';
268
269 when others => -- bad directive
270 write(oline, string'("?? unknown directive: "));
271 write(oline, dname);
272 writeline(output, oline);
273 report "aborting" severity failure;
274 end case;
275 else
276 report "failed to find command" severity failure;
277
278 end if;
279
280 testempty_ea(iline);
281
282 end loop; -- file fstim
283
284 wait for 10*clock_period;
285
286 writetimestamp(oline, CLK_CYCLE, ": DONE ");
287 writeline(output, oline);
288
289 CLK_STOP <= '1';
290
291 wait; -- suspend proc_stim forever
292 -- clock is stopped, sim will end
293
294 end process proc_stim;
295
296
297 proc_moni: process
298 variable oline : line;
299 begin
300
301 loop
302 wait until rising_edge(CLK);
303
304 if ACK_R = '1' then
305 writetimestamp(oline, CLK_CYCLE, ": moni ");
306 writegen(oline, DO, right, 9, 16);
307 if R_CHK_DATA_DL = '1' then
308 write(oline, string'(" CHECK"));
309 if R_REF_DATA_DL = DO then
310 write(oline, string'(" OK"));
311 else
312 write(oline, string'(" FAIL, exp="));
313 writegen(oline, R_REF_DATA_DL, right, 9, 16);
314 write(oline, string'(" for a="));
315 writegen(oline, R_REF_ADDR_DL, right, 5, 16);
316 end if;
317 R_CHK_DATA_DL <= '0';
318 end if;
319 writeline(output, oline);
320 end if;
321
322 if R_CHK_DATA_AL = '1' then
326 R_CHK_DATA_AL <= '0';
327 end if;
328 if N_CHK_DATA = '1' then
332 end if;
333
334 end loop;
335
336 end process proc_moni;
337
338
339 proc_memon: process
340 variable oline : line;
341 begin
342
343 loop
344 wait until rising_edge(CLK);
345
346 if R_MEMON = '1' then
347 writetimestamp(oline, CLK_CYCLE, ": mem ");
348 write(oline, string'(" ce="));
349 write(oline, not O_MEM_CE_N, right, 2);
350 write(oline, string'(" be="));
351 write(oline, not O_MEM_BE_N, right, 4);
352 write(oline, string'(" we="));
353 write(oline, not O_MEM_WE_N, right);
354 write(oline, string'(" oe="));
355 write(oline, not O_MEM_OE_N, right);
356 write(oline, string'(" a="));
357 writegen(oline, O_MEM_ADDR, right, 6, 16);
358 write(oline, string'(" d="));
359 writegen(oline, IO_MEM_DATA, right, 4, 16);
360 writeline(output, oline);
361 end if;
362
363 end loop;
364
365 end process proc_memon;
366
367
368end sim;
in UB_N slbit
Definition: mt45w8mw16b.vhd:64
in CRE slbit
Definition: mt45w8mw16b.vhd:67
in WE_N slbit
Definition: mt45w8mw16b.vhd:63
in CLK slbit
Definition: mt45w8mw16b.vhd:60
out MWAIT slbit
Definition: mt45w8mw16b.vhd:68
in CE_N slbit
Definition: mt45w8mw16b.vhd:61
in OE_N slbit
Definition: mt45w8mw16b.vhd:62
in ADV_N slbit
Definition: mt45w8mw16b.vhd:66
in LB_N slbit
Definition: mt45w8mw16b.vhd:65
inout DATA slv16
Definition: mt45w8mw16b.vhd:71
in ADDR slv23
Definition: mt45w8mw16b.vhd:69
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( 22 downto 0) slv23
Definition: slvtypes.vhd:56
std_logic_vector( 3 downto 0) slv4
Definition: slvtypes.vhd:36
std_logic_vector( 31 downto 0) slv32
Definition: slvtypes.vhd:59
std_logic_vector( 15 downto 0) slv16
Definition: slvtypes.vhd:48
std_logic_vector( 21 downto 0) slv22
Definition: slvtypes.vhd:55
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
slv4 :=( others => '0') BE
slv32 :=( others => '0') DO
Delay_length := 12.0 ns c2out_time
Delay_length := 200 ns clock_offset
slv16 :=( others => '0') IO_MEM_DATA
slv22 :=( others => '0') R_REF_ADDR_DL
Delay_length := 7.5 ns setup_time
slv22 :=( others => '0') N_REF_ADDR
slv32 :=( others => '0') DI
slv2 :=( others => '0') O_MEM_BE_N
slv32 :=( others => '0') N_REF_DATA
slv23 :=( others => '0') O_MEM_ADDR
slv22 :=( others => '0') R_REF_ADDR_AL
slv32 :=( others => '0') R_REF_DATA_AL
slv22 :=( others => '0') ADDR
Delay_length := 20 ns clock_period