-
Notifications
You must be signed in to change notification settings - Fork 250
/
tb_axi_lite_master.vhd
453 lines (369 loc) · 14.4 KB
/
tb_axi_lite_master.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
-- You can obtain one at http://mozilla.org/MPL/2.0/.
--
-- Copyright (c) 2014-2022, Lars Asplund lars.anders.asplund@gmail.com
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library vunit_lib;
context vunit_lib.vunit_context;
context work.com_context;
use work.axi_pkg.all;
use work.bus_master_pkg.all;
use work.axi_lite_master_pkg.all;
library osvvm;
use osvvm.RandomPkg.all;
entity tb_axi_lite_master is
generic (runner_cfg : string);
end entity;
architecture a of tb_axi_lite_master is
constant num_random_tests : integer := 128;
signal clk : std_logic := '0';
signal arready : std_logic := '0';
signal arvalid : std_logic;
signal araddr : std_logic_vector(31 downto 0);
signal rready : std_logic := '0';
signal rvalid : std_logic;
signal rdata : std_logic_vector(15 downto 0);
signal rresp : std_logic_vector(1 downto 0);
signal awready : std_logic := '0';
signal awvalid : std_logic;
signal awaddr : std_logic_vector(31 downto 0);
signal wready : std_logic := '0';
signal wvalid : std_logic;
signal wdata : std_logic_vector(15 downto 0);
signal wstrb : std_logic_vector(1 downto 0);
signal bvalid : std_logic := '0';
signal bready : std_logic;
signal bresp : std_logic_vector(1 downto 0);
constant bus_handle : bus_master_t := new_bus(data_length => wdata'length,
address_length => awaddr'length);
signal start, done : boolean := false;
begin
main : process
variable tmp : std_logic_vector(rdata'range);
variable rnd : RandomPType;
variable timestamp : time;
begin
test_runner_setup(runner, runner_cfg);
rnd.InitSeed("common_seed");
start <= true;
wait for 0 ns;
if run("Test single write") then
mock(get_logger(bus_handle), debug);
write_bus(net, bus_handle, x"01234567", x"1122");
wait_until_idle(net, bus_handle);
check_only_log(get_logger(bus_handle), "Wrote 0x1122 to address 0x01234567", debug);
unmock(get_logger(bus_handle));
elsif run("Test single write with byte enable") then
write_bus(net, bus_handle, x"01234567", x"1122", byte_enable => "10");
elsif run("Test write not okay") then
write_bus(net, bus_handle, x"01234567", x"1122");
elsif run("Test write with axi resp") then
write_axi_lite(net, bus_handle, x"01234567", x"1122", axi_resp_slverr);
elsif run("Test write with wrong axi resp") then
write_axi_lite(net, bus_handle, x"01234567", x"1122", axi_resp_decerr);
elsif run("Test single read") then
mock(get_logger(bus_handle), debug);
read_bus(net, bus_handle, x"01234567", tmp);
check_equal(tmp, std_logic_vector'(x"5566"), "read data");
check_only_log(get_logger(bus_handle), "Read 0x5566 from address 0x01234567", debug);
unmock(get_logger(bus_handle));
elsif run("Test read not okay") then
read_bus(net, bus_handle, x"01234567", tmp);
elsif run("Test read with axi resp") then
read_axi_lite(net, bus_handle, x"01234567", axi_resp_slverr, tmp);
elsif run("Test read with wrong axi resp") then
read_axi_lite(net, bus_handle, x"01234567", axi_resp_exokay, tmp);
elsif run("Test random") then
for i in 0 to num_random_tests-1 loop
if rnd.RandInt(0, 1) = 0 then
read_bus(net, bus_handle, rnd.RandSlv(araddr'length), tmp);
check_equal(tmp, rnd.RandSlv(rdata'length), "read data");
else
write_bus(net, bus_handle, rnd.RandSlv(awaddr'length), rnd.RandSlv(wdata'length));
end if;
end loop;
elsif run("Test random axi resp") then
for i in 0 to num_random_tests-1 loop
if rnd.RandInt(0, 1) = 0 then
read_axi_lite(net, bus_handle, rnd.RandSlv(araddr'length), rnd.RandSlv(axi_resp_t'length), tmp);
check_equal(tmp, rnd.RandSlv(rdata'length), "read data");
else
write_axi_lite(net, bus_handle, rnd.RandSlv(awaddr'length), rnd.RandSlv(wdata'length),
rnd.RandSlv(axi_resp_t'length));
end if;
end loop;
elsif run("Test idle when idle") then
wait until rising_edge(clk);
write_bus(net, bus_handle, x"01234567", x"1122");
wait for 0 ps;
timestamp := now;
wait_until_idle(net, bus_handle);
check(now > timestamp, "Write: First wait did not have to wait");
timestamp := now;
wait_until_idle(net, bus_handle);
check_equal(timestamp, now, "Write: Second wait had to wait");
wait until rising_edge(clk);
read_bus(net, bus_handle, x"01234567", tmp);
timestamp := now;
wait_until_idle(net, bus_handle);
check_equal(timestamp, now, "Read: Second wait had to wait");
end if;
wait for 100 ns;
if not done then
wait until done;
end if;
test_runner_cleanup(runner);
end process;
test_runner_watchdog(runner, 100 us);
support : process
variable rnd : RandomPType;
begin
rnd.InitSeed("common_seed");
wait until start;
if enabled("Test single write") then
awready <= '1';
wait until (awready and awvalid) = '1' and rising_edge(clk);
awready <= '0';
check_equal(awaddr, std_logic_vector'(x"01234567"), "awaddr");
wready <= '1';
wait until (wready and wvalid) = '1' and rising_edge(clk);
wready <= '0';
check_equal(wdata, std_logic_vector'(x"1122"), "wdata");
check_equal(wstrb, std_logic_vector'("11"), "wstrb");
bvalid <= '1';
bresp <= axi_resp_okay;
wait until (bready and bvalid) = '1' and rising_edge(clk);
bvalid <= '0';
done <= true;
elsif enabled("Test single write with byte enable") then
awready <= '1';
wait until (awready and awvalid) = '1' and rising_edge(clk);
awready <= '0';
check_equal(awaddr, std_logic_vector'(x"01234567"), "awaddr");
wready <= '1';
wait until (wready and wvalid) = '1' and rising_edge(clk);
wready <= '0';
check_equal(wdata, std_logic_vector'(x"1122"), "wdata");
check_equal(wstrb, std_logic_vector'("10"), "wstrb");
bvalid <= '1';
bresp <= axi_resp_okay;
wait until (bready and bvalid) = '1' and rising_edge(clk);
bvalid <= '0';
done <= true;
elsif enabled("Test write not okay") then
awready <= '1';
wait until (awready and awvalid) = '1' and rising_edge(clk);
awready <= '0';
wready <= '1';
wait until (wready and wvalid) = '1' and rising_edge(clk);
wready <= '0';
bvalid <= '1';
bresp <= axi_resp_slverr;
mock(bus_logger, failure);
wait until (bready and bvalid) = '1' and rising_edge(clk);
bvalid <= '0';
wait until mock_queue_length > 0 for 0 ns;
check_only_log(bus_logger, "bresp - Got AXI response SLVERR(10) expected OKAY(00)", failure);
unmock(bus_logger);
done <= true;
elsif enabled("Test write with axi resp") then
awready <= '1';
wait until (awready and awvalid) = '1' and rising_edge(clk);
awready <= '0';
check_equal(awaddr, std_logic_vector'(x"01234567"), "awaddr");
wready <= '1';
wait until (wready and wvalid) = '1' and rising_edge(clk);
wready <= '0';
check_equal(wdata, std_logic_vector'(x"1122"), "wdata");
check_equal(wstrb, std_logic_vector'("11"), "wstrb");
bvalid <= '1';
bresp <= axi_resp_slverr;
wait until (bready and bvalid) = '1' and rising_edge(clk);
bvalid <= '0';
done <= true;
elsif enabled("Test write with wrong axi resp") then
awready <= '1';
wait until (awready and awvalid) = '1' and rising_edge(clk);
awready <= '0';
check_equal(awaddr, std_logic_vector'(x"01234567"), "awaddr");
wready <= '1';
wait until (wready and wvalid) = '1' and rising_edge(clk);
wready <= '0';
check_equal(wdata, std_logic_vector'(x"1122"), "wdata");
check_equal(wstrb, std_logic_vector'("11"), "wstrb");
bvalid <= '1';
bresp <= axi_resp_exokay;
mock(bus_logger, failure);
wait until (bready and bvalid) = '1' and rising_edge(clk);
bvalid <= '0';
wait until mock_queue_length > 0 for 0 ns;
check_only_log(bus_logger, "bresp - Got AXI response EXOKAY(01) expected DECERR(11)", failure);
unmock(bus_logger);
done <= true;
elsif enabled("Test single read") then
arready <= '1';
wait until (arready and arvalid) = '1' and rising_edge(clk);
arready <= '0';
check_equal(araddr, std_logic_vector'(x"01234567"), "araddr");
rvalid <= '1';
rresp <= axi_resp_okay;
rdata <= x"5566";
wait until (rready and rvalid) = '1' and rising_edge(clk);
rvalid <= '0';
done <= true;
elsif enabled("Test read not okay") then
arready <= '1';
wait until (arready and arvalid) = '1' and rising_edge(clk);
arready <= '0';
rvalid <= '1';
rresp <= axi_resp_decerr;
rdata <= x"5566";
mock(bus_logger, failure);
wait until (rready and rvalid) = '1' and rising_edge(clk);
rvalid <= '0';
wait until mock_queue_length > 0 for 0 ns;
check_only_log(bus_logger, "rresp - Got AXI response DECERR(11) expected OKAY(00)", failure);
unmock(bus_logger);
done <= true;
elsif enabled("Test read with axi resp") then
arready <= '1';
wait until (arready and arvalid) = '1' and rising_edge(clk);
arready <= '0';
check_equal(araddr, std_logic_vector'(x"01234567"), "araddr");
rvalid <= '1';
rresp <= axi_resp_slverr;
rdata <= x"0000";
wait until (rready and rvalid) = '1' and rising_edge(clk);
rvalid <= '0';
done <= true;
elsif enabled("Test read with wrong axi resp") then
arready <= '1';
wait until (arready and arvalid) = '1' and rising_edge(clk);
arready <= '0';
check_equal(araddr, std_logic_vector'(x"01234567"), "araddr");
rvalid <= '1';
rresp <= axi_resp_decerr;
rdata <= x"0000";
mock(bus_logger, failure);
wait until (rready and rvalid) = '1' and rising_edge(clk);
rvalid <= '0';
wait until mock_queue_length > 0 for 0 ns;
check_only_log(bus_logger, "rresp - Got AXI response DECERR(11) expected EXOKAY(01)", failure);
unmock(bus_logger);
done <= true;
elsif enabled("Test random") then
for i in 0 to num_random_tests-1 loop
if rnd.RandInt(0, 1) = 0 then
arready <= '1';
wait until (arready and arvalid) = '1' and rising_edge(clk);
arready <= '0';
check_equal(araddr, rnd.RandSlv(araddr'length), "araddr");
rvalid <= '1';
rresp <= axi_resp_okay;
rdata <= rnd.RandSlv(rdata'length);
wait until (rready and rvalid) = '1' and rising_edge(clk);
rvalid <= '0';
else
awready <= '1';
wait until (awready and awvalid) = '1' and rising_edge(clk);
awready <= '0';
check_equal(awaddr, rnd.RandSlv(awaddr'length), "awaddr");
wready <= '1';
wait until (wready and wvalid) = '1' and rising_edge(clk);
wready <= '0';
check_equal(wdata, rnd.RandSlv(wdata'length), "wdata");
check_equal(wstrb, std_logic_vector'("11"), "wstrb");
bvalid <= '1';
bresp <= axi_resp_okay;
wait until (bready and bvalid) = '1' and rising_edge(clk);
bvalid <= '0';
end if;
end loop;
done <= true;
elsif enabled("Test random axi resp") then
for i in 0 to num_random_tests-1 loop
if rnd.RandInt(0, 1) = 0 then
arready <= '1';
wait until (arready and arvalid) = '1' and rising_edge(clk);
arready <= '0';
check_equal(araddr, rnd.RandSlv(araddr'length), "araddr");
rvalid <= '1';
rresp <= rnd.RandSlv(axi_resp_t'length);
rdata <= rnd.RandSlv(rdata'length);
wait until (rready and rvalid) = '1' and rising_edge(clk);
rvalid <= '0';
else
awready <= '1';
wait until (awready and awvalid) = '1' and rising_edge(clk);
awready <= '0';
check_equal(awaddr, rnd.RandSlv(awaddr'length), "awaddr");
wready <= '1';
wait until (wready and wvalid) = '1' and rising_edge(clk);
wready <= '0';
check_equal(wdata, rnd.RandSlv(wdata'length), "wdata");
check_equal(wstrb, std_logic_vector'("11"), "wstrb");
bvalid <= '1';
bresp <= rnd.RandSlv(axi_resp_t'length);
wait until (bready and bvalid) = '1' and rising_edge(clk);
bvalid <= '0';
end if;
end loop;
done <= true;
elsif enabled("Test idle when idle") then
wait until rising_edge(clk);
awready <= '1';
wait until (awready and awvalid) = '1' and rising_edge(clk);
awready <= '0';
check_equal(awaddr, std_logic_vector'(x"01234567"), "awaddr");
wait until rising_edge(clk);
wready <= '1';
wait until (wready and wvalid) = '1' and rising_edge(clk);
wready <= '0';
check_equal(wdata, std_logic_vector'(x"1122"), "wdata");
check_equal(wstrb, std_logic_vector'("11"), "wstrb");
wait until rising_edge(clk);
bvalid <= '1';
bresp <= axi_resp_okay;
wait until (bready and bvalid) = '1' and rising_edge(clk);
bvalid <= '0';
wait until rising_edge(clk);
arready <= '1';
wait until (arready and arvalid) = '1' and rising_edge(clk);
arready <= '0';
check_equal(araddr, std_logic_vector'(x"01234567"), "araddr");
wait until rising_edge(clk);
rvalid <= '1';
rresp <= axi_resp_okay;
rdata <= x"5566";
wait until (rready and rvalid) = '1' and rising_edge(clk);
rvalid <= '0';
done <= true;
end if;
end process;
dut : entity work.axi_lite_master
generic map (
bus_handle => bus_handle)
port map (
aclk => clk,
arready => arready,
arvalid => arvalid,
araddr => araddr,
rready => rready,
rvalid => rvalid,
rdata => rdata,
rresp => rresp,
awready => awready,
awvalid => awvalid,
awaddr => awaddr,
wready => wready,
wvalid => wvalid,
wdata => wdata,
wstrb => wstrb,
bvalid => bvalid,
bready => bready,
bresp => bresp);
clk <= not clk after 5 ns;
end architecture;