forked from pulp-platform/axi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tb_axi_dw_pkg.sv
1379 lines (1233 loc) · 57.2 KB
/
tb_axi_dw_pkg.sv
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2020 ETH Zurich and University of Bologna.
// Copyright and related rights are licensed under the Solderpad Hardware
// License, Version 0.51 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law
// or agreed to in writing, software, hardware and materials distributed under
// this License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
//
// Authors:
// - Matheus Cavalcante <[email protected]>
// `axi_dw_upsizer_monitor` implements an AXI bus monitor that is tuned
// for the AXI Data Width Converters. It snoops on the slave and master port
// of the DWCs and populates FIFOs and ID queues to validate that no
// AXI beats get lost.
package tb_axi_dw_pkg ;
import axi_pkg::len_t ;
import axi_pkg::burst_t ;
import axi_pkg::size_t ;
import axi_pkg::cache_t ;
import axi_pkg::modifiable;
/****************
* BASE CLASS *
****************/
class axi_dw_monitor #(
parameter int unsigned AxiAddrWidth ,
parameter int unsigned AxiSlvPortDataWidth,
parameter int unsigned AxiMstPortDataWidth,
parameter int unsigned AxiIdWidth ,
parameter int unsigned AxiUserWidth ,
// Stimuli application and test time
parameter time TimeTest
);
localparam AxiSlvPortStrbWidth = AxiSlvPortDataWidth / 8;
localparam AxiMstPortStrbWidth = AxiMstPortDataWidth / 8;
localparam AxiSlvPortMaxSize = $clog2(AxiSlvPortStrbWidth);
localparam AxiMstPortMaxSize = $clog2(AxiMstPortStrbWidth);
typedef logic [AxiIdWidth-1:0] axi_id_t ;
typedef logic [AxiAddrWidth-1:0] axi_addr_t;
typedef logic [AxiSlvPortDataWidth-1:0] slv_port_data_t;
typedef logic [AxiSlvPortStrbWidth-1:0] slv_port_strb_t;
typedef logic [AxiMstPortDataWidth-1:0] mst_port_data_t;
typedef logic [AxiMstPortStrbWidth-1:0] mst_port_strb_t;
typedef struct packed {
axi_id_t axi_id;
logic axi_last ;
} exp_b_t;
typedef struct packed {
axi_id_t axi_id ;
slv_port_data_t axi_data;
slv_port_strb_t axi_strb;
logic axi_last ;
} exp_slv_rw_t;
typedef struct packed {
axi_id_t axi_id ;
mst_port_data_t axi_data;
mst_port_strb_t axi_strb;
logic axi_last ;
} exp_mst_rw_t;
typedef struct packed {
axi_id_t axi_id ;
axi_addr_t axi_addr;
len_t axi_len ;
burst_t axi_burst ;
size_t axi_size ;
cache_t axi_cache ;
} exp_ax_t;
typedef rand_id_queue_pkg::rand_id_queue #(
.data_t (exp_ax_t ),
.ID_WIDTH(AxiIdWidth)
) ax_queue_t;
typedef rand_id_queue_pkg::rand_id_queue #(
.data_t (exp_b_t ),
.ID_WIDTH(AxiIdWidth)
) b_queue_t;
typedef rand_id_queue_pkg::rand_id_queue #(
.data_t (exp_slv_rw_t ),
.ID_WIDTH(AxiIdWidth )
) slv_r_queue_t;
typedef rand_id_queue_pkg::rand_id_queue #(
.data_t (exp_mst_rw_t ),
.ID_WIDTH(AxiIdWidth )
) mst_r_queue_t;
/**********************
* Helper functions *
**********************/
// Returns a byte mask corresponding to the size of the AXI transaction
function automatic axi_addr_t size_mask(axi_pkg::size_t size);
return (axi_addr_t'(1) << size) - 1;
endfunction
/**
* Returns the conversion rate between tgt_size and src_size.
* @return ceil(num_bytes(tgt_size)/num_bytes(src_size))
*/
function automatic int unsigned conv_ratio(axi_pkg::size_t tgt_size, axi_pkg::size_t src_size) ;
return (axi_pkg::num_bytes(tgt_size) + axi_pkg::num_bytes(src_size) - 1)/axi_pkg::num_bytes(src_size);
endfunction: conv_ratio
/************************
* Virtual Interfaces *
************************/
virtual AXI_BUS_DV #(
.AXI_ADDR_WIDTH(AxiAddrWidth ),
.AXI_DATA_WIDTH(AxiSlvPortDataWidth),
.AXI_ID_WIDTH (AxiIdWidth ),
.AXI_USER_WIDTH(AxiUserWidth )
) slv_port_axi;
virtual AXI_BUS_DV #(
.AXI_ADDR_WIDTH(AxiAddrWidth ),
.AXI_DATA_WIDTH(AxiMstPortDataWidth),
.AXI_ID_WIDTH (AxiIdWidth ),
.AXI_USER_WIDTH(AxiUserWidth )
) mst_port_axi;
/*****************
* Bookkeeping *
*****************/
longint unsigned tests_expected;
longint unsigned tests_conducted;
longint unsigned tests_failed;
semaphore cnt_sem;
// Queues and FIFOs to hold the expected AXIDs
// Write transactions
ax_queue_t exp_mst_port_aw_queue;
exp_ax_t act_mst_port_aw_queue [$];
exp_ax_t act_slv_port_aw_queue [$];
exp_mst_rw_t exp_mst_port_w_queue [$];
exp_mst_rw_t act_mst_port_w_queue [$];
exp_slv_rw_t act_slv_port_w_queue [$];
b_queue_t exp_slv_port_b_queue;
// Read transactions
ax_queue_t exp_mst_port_ar_queue;
ax_queue_t act_mst_port_ar_queue;
ax_queue_t act_slv_port_ar_queue;
exp_slv_rw_t act_slv_port_r_queue [$];
slv_r_queue_t exp_slv_port_r_queue;
/*****************
* Constructor *
*****************/
function new (
virtual AXI_BUS_DV #(
.AXI_ADDR_WIDTH(AxiAddrWidth ),
.AXI_DATA_WIDTH(AxiSlvPortDataWidth),
.AXI_ID_WIDTH (AxiIdWidth ),
.AXI_USER_WIDTH(AxiUserWidth )
) slv_port_vif,
virtual AXI_BUS_DV #(
.AXI_ADDR_WIDTH(AxiAddrWidth ),
.AXI_DATA_WIDTH(AxiMstPortDataWidth),
.AXI_ID_WIDTH (AxiIdWidth ),
.AXI_USER_WIDTH(AxiUserWidth )
) mst_port_vif
);
begin
this.slv_port_axi = slv_port_vif;
this.mst_port_axi = mst_port_vif;
this.tests_expected = 0 ;
this.tests_conducted = 0 ;
this.tests_failed = 0 ;
this.exp_slv_port_b_queue = new ;
this.exp_slv_port_r_queue = new ;
this.exp_mst_port_aw_queue = new ;
this.exp_mst_port_ar_queue = new ;
this.act_mst_port_ar_queue = new ;
this.act_slv_port_ar_queue = new ;
this.cnt_sem = new(1) ;
end
endfunction
task cycle_start;
#TimeTest;
endtask: cycle_start
task cycle_end;
@(posedge slv_port_axi.clk_i);
endtask: cycle_end
/**************
* Monitors *
**************/
/*
* You need to override this task. Use it to push the expected AW requests on
* the slave side, and the B and R responses expected on the master side.
*/
virtual task automatic mon_slv_port_aw () ;
$error("This task needs to be overridden.");
endtask : mon_slv_port_aw
/*
* You need to override this task. Use it to push the expected W requests on
* the slave side.
*/
virtual task automatic mon_slv_port_w () ;
$error("This task needs to be overridden.");
endtask : mon_slv_port_w
/*
* You need to override this task. Use it to push the expected R responses on
* the master side.
*/
virtual task automatic mon_mst_port_r () ;
$error("This task needs to be overridden.");
endtask : mon_mst_port_r
/*
* You need to override this task. Use it to push the expected AR requests on
* the slave side, and the R responses expected on the master side.
*/
virtual task automatic mon_slv_port_ar () ;
$error("This task needs to be overridden.");
endtask : mon_slv_port_ar
/*
* This tasks stores the beats seen by the AR, AW and W channels
* into the respective queues.
*/
virtual task automatic store_channels ();
if (slv_port_axi.ar_valid && slv_port_axi.ar_ready)
act_slv_port_ar_queue.push(slv_port_axi.ar_id,
'{
axi_id : slv_port_axi.ar_id ,
axi_burst: slv_port_axi.ar_burst,
axi_size : slv_port_axi.ar_size ,
axi_addr : slv_port_axi.ar_addr ,
axi_len : slv_port_axi.ar_len ,
axi_cache: slv_port_axi.ar_cache
});
if (slv_port_axi.aw_valid && slv_port_axi.aw_ready) begin
act_slv_port_aw_queue.push_back('{
axi_id : slv_port_axi.aw_id ,
axi_burst: slv_port_axi.aw_burst,
axi_size : slv_port_axi.aw_size ,
axi_addr : slv_port_axi.aw_addr ,
axi_len : slv_port_axi.aw_len ,
axi_cache: slv_port_axi.aw_cache
});
// This request generates an R response.
// Push this to the AR queue.
if (slv_port_axi.aw_atop[axi_pkg::ATOP_R_RESP])
act_slv_port_ar_queue.push(slv_port_axi.aw_id,
'{
axi_id : slv_port_axi.aw_id ,
axi_burst: slv_port_axi.aw_burst,
axi_size : slv_port_axi.aw_size ,
axi_addr : slv_port_axi.aw_addr ,
axi_len : slv_port_axi.aw_len ,
axi_cache: slv_port_axi.aw_cache
});
end
if (slv_port_axi.w_valid && slv_port_axi.w_ready)
this.act_slv_port_w_queue.push_back('{
axi_id : {AxiIdWidth{1'b?}} ,
axi_data: slv_port_axi.w_data,
axi_strb: slv_port_axi.w_strb,
axi_last: slv_port_axi.w_last
});
if (slv_port_axi.r_valid && slv_port_axi.r_ready)
this.act_slv_port_r_queue.push_back('{
axi_id : slv_port_axi.r_id ,
axi_data: slv_port_axi.r_data ,
axi_strb: {AxiSlvPortStrbWidth{1'b?}},
axi_last: slv_port_axi.r_last
});
if (mst_port_axi.ar_valid && mst_port_axi.ar_ready)
act_mst_port_ar_queue.push(mst_port_axi.ar_id,
'{
axi_id : mst_port_axi.ar_id ,
axi_burst: mst_port_axi.ar_burst,
axi_size : mst_port_axi.ar_size ,
axi_addr : mst_port_axi.ar_addr ,
axi_len : mst_port_axi.ar_len ,
axi_cache: mst_port_axi.ar_cache
});
if (mst_port_axi.aw_valid && mst_port_axi.aw_ready) begin
act_mst_port_aw_queue.push_back('{
axi_id : mst_port_axi.aw_id ,
axi_burst: mst_port_axi.aw_burst,
axi_size : mst_port_axi.aw_size ,
axi_addr : mst_port_axi.aw_addr ,
axi_len : mst_port_axi.aw_len ,
axi_cache: mst_port_axi.aw_cache
});
// This request generates an R response.
// Push this to the AR queue.
if (mst_port_axi.aw_atop[axi_pkg::ATOP_R_RESP])
act_mst_port_ar_queue.push(mst_port_axi.aw_id,
'{
axi_id : mst_port_axi.aw_id ,
axi_burst: mst_port_axi.aw_burst,
axi_size : mst_port_axi.aw_size ,
axi_addr : mst_port_axi.aw_addr ,
axi_len : mst_port_axi.aw_len ,
axi_cache: mst_port_axi.aw_cache
});
end
if (mst_port_axi.w_valid && mst_port_axi.w_ready)
this.act_mst_port_w_queue.push_back('{
axi_id : {AxiIdWidth{1'b?}} ,
axi_data: mst_port_axi.w_data,
axi_strb: mst_port_axi.w_strb,
axi_last: mst_port_axi.w_last
});
endtask
/*
* This task monitors the master port of the DW converter. Every time it gets an AW transaction,
* it gets checked for its contents against the expected beat on the `exp_aw_queue`.
*/
task automatic mon_mst_port_aw ();
exp_ax_t exp_aw;
if (mst_port_axi.aw_valid && mst_port_axi.aw_ready) begin
// Test if the AW beat was expected
exp_aw = this.exp_mst_port_aw_queue.pop_id(mst_port_axi.aw_id);
if (exp_aw.axi_id != mst_port_axi.aw_id) begin
incr_failed_tests(1) ;
$warning("Slave: Unexpected AW with ID: %b", mst_port_axi.aw_id);
end
if (exp_aw.axi_addr != mst_port_axi.aw_addr) begin
incr_failed_tests(1);
$warning("Slave: Unexpected AW with ID: %b and ADDR: %h, exp: %h",
mst_port_axi.aw_id, mst_port_axi.aw_addr, exp_aw.axi_addr);
end
if (exp_aw.axi_len != mst_port_axi.aw_len) begin
incr_failed_tests(1);
$warning("Slave: Unexpected AW with ID: %b and LEN: %h, exp: %h",
mst_port_axi.aw_id, mst_port_axi.aw_len, exp_aw.axi_len);
end
if (exp_aw.axi_burst != mst_port_axi.aw_burst) begin
incr_failed_tests(1);
$warning("Slave: Unexpected AW with ID: %b and BURST: %h, exp: %h",
mst_port_axi.aw_id, mst_port_axi.aw_burst, exp_aw.axi_burst);
end
if (exp_aw.axi_size != mst_port_axi.aw_size) begin
incr_failed_tests(1);
$warning("Slave: Unexpected AW with ID: %b and SIZE: %h, exp: %h",
mst_port_axi.aw_id, mst_port_axi.aw_size, exp_aw.axi_size);
end
if (exp_aw.axi_cache != mst_port_axi.aw_cache) begin
incr_failed_tests(1);
$warning("Slave: Unexpected AW with ID: %b and CACHE: %b, exp: %b",
mst_port_axi.aw_id, mst_port_axi.aw_cache, exp_aw.axi_cache);
end
incr_conducted_tests(6);
end
endtask : mon_mst_port_aw
/*
* This task compares the expected and actual W beats on the master port.
*/
task automatic mon_mst_port_w ();
exp_mst_rw_t exp_w, act_w;
while (this.exp_mst_port_w_queue.size() != 0 && this.act_mst_port_w_queue.size() != 0) begin
exp_w = this.exp_mst_port_w_queue.pop_front();
act_w = this.act_mst_port_w_queue.pop_front();
// Do the checks
if (exp_w.axi_data != act_w.axi_data) begin
incr_failed_tests(1);
$warning("Slave: Unexpected W with DATA: %h, exp: %h",
act_w.axi_data, exp_w.axi_data);
end
if (exp_w.axi_strb != act_w.axi_strb) begin
incr_failed_tests(1);
$warning("Slave: Unexpected W with STRB: %h, exp: %h",
act_w.axi_strb, exp_w.axi_strb);
end
if (exp_w.axi_last != act_w.axi_last) begin
incr_failed_tests(1);
$warning("Slave: Unexpected W with LAST: %b, exp: %b",
act_w.axi_last, exp_w.axi_last);
end
incr_conducted_tests(3);
end
endtask : mon_mst_port_w
/*
* This task checks if a B response is allowed on a slave port of the DW converter.
*/
task automatic mon_slv_port_b ();
exp_b_t exp_b;
axi_id_t axi_b_id;
if (slv_port_axi.b_valid && slv_port_axi.b_ready) begin
incr_conducted_tests(1);
axi_b_id = slv_port_axi.b_id;
$display("%0tns > Master: Got last B with ID: %b",
$time, axi_b_id);
if (this.exp_slv_port_b_queue.empty()) begin
incr_failed_tests(1) ;
$warning("Master: unexpected B beat with ID: %b detected!", axi_b_id);
end else begin
exp_b = this.exp_slv_port_b_queue.pop_id(axi_b_id);
if (axi_b_id != exp_b.axi_id) begin
incr_failed_tests(1) ;
$warning("Master: got unexpected B with ID: %b", axi_b_id);
end
end
end
endtask : mon_slv_port_b
/*
* This task monitors a the master port of the DW converter and checks
* if the AR beats were all expected.
*/
task automatic mon_mst_port_ar ();
exp_ax_t exp_ar;
if (mst_port_axi.ar_valid && mst_port_axi.ar_ready) begin
// Test if the AR beat was expected
exp_ar = this.exp_mst_port_ar_queue.pop_id(mst_port_axi.ar_id);
if (exp_ar.axi_id != mst_port_axi.ar_id) begin
incr_failed_tests(1) ;
$warning("Slave: Unexpected AR with ID: %b", mst_port_axi.ar_id);
end
if (exp_ar.axi_addr != mst_port_axi.ar_addr) begin
incr_failed_tests(1);
$warning("Slave: Unexpected AR with ID: %b and ADDR: %h, exp: %h",
mst_port_axi.ar_id, mst_port_axi.ar_addr, exp_ar.axi_addr);
end
if (exp_ar.axi_len != mst_port_axi.ar_len) begin
incr_failed_tests(1);
$warning("Slave: Unexpected AR with ID: %b and LEN: %h, exp: %h",
mst_port_axi.ar_id, mst_port_axi.ar_len, exp_ar.axi_len);
end
if (exp_ar.axi_burst != mst_port_axi.ar_burst) begin
incr_failed_tests(1);
$warning("Slave: Unexpected AR with ID: %b and BURST: %h, exp: %h",
mst_port_axi.ar_id, mst_port_axi.ar_burst, exp_ar.axi_burst);
end
if (exp_ar.axi_size != mst_port_axi.ar_size) begin
incr_failed_tests(1);
$warning("Slave: Unexpected AR with ID: %b and SIZE: %h, exp: %h",
mst_port_axi.ar_id, mst_port_axi.ar_size, exp_ar.axi_size);
end
if (exp_ar.axi_cache != mst_port_axi.ar_cache) begin
incr_failed_tests(1);
$warning("Slave: Unexpected AR with ID: %b and CACHE: %b, exp: %b",
mst_port_axi.ar_id, mst_port_axi.ar_cache, exp_ar.axi_cache);
end
incr_conducted_tests(6);
end
endtask : mon_mst_port_ar
/*
* This task does the R channel monitoring on a slave port. It compares the last flags,
* which are determined by the sequence of previously sent AR vectors.
*/
task automatic mon_slv_port_r ();
exp_slv_rw_t exp_r;
if (act_slv_port_r_queue.size() != 0) begin
exp_slv_rw_t act_r = act_slv_port_r_queue[0] ;
if (exp_slv_port_r_queue.queues[act_r.axi_id].size() != 0) begin
exp_r = exp_slv_port_r_queue.pop_id(act_r.axi_id);
void'(act_slv_port_r_queue.pop_front());
// Do the checks
if (exp_r.axi_id != act_r.axi_id) begin
incr_failed_tests(1);
$warning("Slave: Unexpected R with ID: %b",
act_r.axi_id);
end
if (exp_r.axi_last != act_r.axi_last) begin
incr_failed_tests(1);
$warning("Slave: Unexpected R with ID: %b and LAST: %b, exp: %b",
act_r.axi_id, act_r.axi_last, exp_r.axi_last);
end
if (exp_r.axi_data != act_r.axi_data) begin
incr_failed_tests(1);
$warning("Slave: Unexpected R with ID: %b and DATA: %h, exp: %h",
act_r.axi_id, act_r.axi_data, exp_r.axi_data);
end
incr_conducted_tests(3);
end
end
endtask : mon_slv_port_r
// Some tasks to manage bookkeeping of the tests conducted.
task incr_expected_tests(input int unsigned times);
cnt_sem.get() ;
this.tests_expected += times;
cnt_sem.put() ;
endtask : incr_expected_tests
task incr_conducted_tests(input int unsigned times);
cnt_sem.get() ;
this.tests_conducted += times;
cnt_sem.put() ;
endtask : incr_conducted_tests
task incr_failed_tests(input int unsigned times);
cnt_sem.get() ;
this.tests_failed += times;
cnt_sem.put() ;
endtask : incr_failed_tests
/*
* This task invokes the various monitoring tasks. First, all processes that only
* push something in the FIFOs are invoked. After they are finished, the processes
* that pop something from them are invoked.
*/
task run();
forever begin
// At every cycle, spawn some monitoring processes.
cycle_start();
// Execute all processes that push something into the queues
PushMon: fork
proc_mst_aw : mon_slv_port_aw();
proc_mst_ar : mon_slv_port_ar();
proc_mst_w : mon_slv_port_w() ;
proc_slv_r : mon_mst_port_r() ;
proc_store_channel: store_channels() ;
join: PushMon
// These only pop something from the queues
PopMon: fork
proc_slv_aw: mon_mst_port_aw();
proc_mst_b : mon_slv_port_b() ;
proc_slv_ar: mon_mst_port_ar();
proc_mst_r : mon_slv_port_r() ;
join : PopMon
// Check the slave W FIFOs last
proc_check_slv_w: mon_mst_port_w();
cycle_end();
end
endtask : run
task print_result() ;
$info("Simulation has ended!") ;
$display("Tests Expected: %d", this.tests_expected) ;
$display("Tests Conducted: %d", this.tests_conducted);
$display("Tests Failed: %d", this.tests_failed) ;
if (tests_failed > 0) begin
$error("Simulation encountered unexpected transactions!");
end
endtask : print_result
endclass : axi_dw_monitor
/*************
* UPSIZER *
*************/
class axi_dw_upsizer_monitor #(
parameter int unsigned AxiAddrWidth ,
parameter int unsigned AxiSlvPortDataWidth,
parameter int unsigned AxiMstPortDataWidth,
parameter int unsigned AxiIdWidth ,
parameter int unsigned AxiUserWidth ,
// Stimuli application and test time
parameter time TimeTest
) extends axi_dw_monitor #(
.AxiAddrWidth (AxiAddrWidth ),
.AxiSlvPortDataWidth(AxiSlvPortDataWidth),
.AxiMstPortDataWidth(AxiMstPortDataWidth),
.AxiIdWidth (AxiIdWidth ),
.AxiUserWidth (AxiUserWidth ),
.TimeTest (TimeTest )
);
local static shortint unsigned slv_port_r_cnt[axi_id_t];
local static shortint unsigned mst_port_r_cnt[axi_id_t];
local static shortint unsigned slv_port_w_cnt;
local static shortint unsigned mst_port_w_cnt;
local static exp_mst_rw_t mst_port_w;
local static shortint unsigned mst_port_w_pnt;
/*****************
* Constructor *
*****************/
function new (
virtual AXI_BUS_DV #(
.AXI_ADDR_WIDTH(AxiAddrWidth ),
.AXI_DATA_WIDTH(AxiSlvPortDataWidth),
.AXI_ID_WIDTH (AxiIdWidth ),
.AXI_USER_WIDTH(AxiUserWidth )
) slv_port_vif,
virtual AXI_BUS_DV #(
.AXI_ADDR_WIDTH(AxiAddrWidth ),
.AXI_DATA_WIDTH(AxiMstPortDataWidth),
.AXI_ID_WIDTH (AxiIdWidth ),
.AXI_USER_WIDTH(AxiUserWidth )
) mst_port_vif
);
begin
super.new(slv_port_vif, mst_port_vif);
slv_port_w_cnt = '0;
mst_port_w_cnt = '0;
mst_port_w_pnt = '1;
mst_port_w = '0;
for (int unsigned id = 0; id < 2**AxiIdWidth; id++) begin
slv_port_r_cnt[id] = '0;
mst_port_r_cnt[id] = '0;
end
end
endfunction
/**************
* Monitors *
**************/
task automatic mon_slv_port_aw ();
exp_ax_t exp_aw;
if (slv_port_axi.aw_valid && slv_port_axi.aw_ready) begin
// Non-modifiable transaction
if (!axi_pkg::modifiable(slv_port_axi.aw_cache)) begin
// We expect that the transaction will not be modified
exp_aw = '{
axi_id : slv_port_axi.aw_id ,
axi_addr : slv_port_axi.aw_addr ,
axi_len : slv_port_axi.aw_len ,
axi_burst: slv_port_axi.aw_burst,
axi_size : slv_port_axi.aw_size ,
axi_cache: slv_port_axi.aw_cache
} ;
end
// Modifiable transaction
else begin
case (slv_port_axi.aw_burst)
// Passthrough upsize
axi_pkg::BURST_FIXED: begin
exp_aw = '{
axi_id : slv_port_axi.aw_id ,
axi_addr : slv_port_axi.aw_addr ,
axi_len : slv_port_axi.aw_len ,
axi_burst: slv_port_axi.aw_burst,
axi_size : slv_port_axi.aw_size ,
axi_cache: slv_port_axi.aw_cache
};
end
// INCR upsize
axi_pkg::BURST_INCR: begin
automatic axi_addr_t aligned_start = axi_pkg::aligned_addr(slv_port_axi.aw_addr, AxiMstPortMaxSize) ;
automatic axi_addr_t aligned_end = axi_pkg::aligned_addr(axi_pkg::aligned_addr(slv_port_axi.aw_addr, slv_port_axi.aw_size) + (unsigned'(slv_port_axi.aw_len) << slv_port_axi.aw_size), AxiMstPortMaxSize);
exp_aw = '{
axi_id : slv_port_axi.aw_id ,
axi_addr : slv_port_axi.aw_addr ,
axi_len : (aligned_end - aligned_start) >> AxiMstPortMaxSize ,
axi_burst: slv_port_axi.aw_burst ,
axi_size : slv_port_axi.aw_len == 0 ? slv_port_axi.aw_size : AxiMstPortMaxSize,
axi_cache: slv_port_axi.aw_cache
};
end
// WRAP upsize
axi_pkg::BURST_WRAP: begin
exp_aw = '0;
$warning("WRAP bursts are not supported.");
end
endcase
this.exp_mst_port_aw_queue.push(slv_port_axi.aw_id, exp_aw);
incr_expected_tests(6) ;
$display("%0tns > Master: AW with ID: %b",
$time, slv_port_axi.aw_id);
end
// Populate the expected B responses
this.exp_slv_port_b_queue.push(slv_port_axi.aw_id, '{
axi_id : slv_port_axi.aw_id,
axi_last: 1'b1
}) ;
incr_expected_tests(1) ;
$display(" Expect B response.") ;
end
endtask : mon_slv_port_aw
task automatic mon_slv_port_w ();
if (act_slv_port_w_queue.size() != 0) begin
exp_slv_rw_t act_slv_w = act_slv_port_w_queue[0];
if (act_mst_port_aw_queue.size() != 0 && act_slv_port_aw_queue.size() != 0) begin
// Retrieve the AW requests related to this W beat
exp_ax_t act_mst_aw = act_mst_port_aw_queue[0];
exp_ax_t act_slv_aw = act_slv_port_aw_queue[0];
// Calculate the offsets
shortint unsigned mst_port_lower_byte =
axi_pkg::beat_lower_byte(act_mst_aw.axi_addr, act_mst_aw.axi_size, act_mst_aw.axi_len, act_mst_aw.axi_burst, AxiMstPortStrbWidth, mst_port_w_cnt);
shortint unsigned mst_port_upper_byte =
axi_pkg::beat_upper_byte(act_mst_aw.axi_addr, act_mst_aw.axi_size, act_mst_aw.axi_len, act_mst_aw.axi_burst, AxiMstPortStrbWidth, mst_port_w_cnt);
shortint unsigned slv_port_lower_byte =
axi_pkg::beat_lower_byte(act_slv_aw.axi_addr, act_slv_aw.axi_size, act_slv_aw.axi_len, act_slv_aw.axi_burst, AxiSlvPortStrbWidth, slv_port_w_cnt);
shortint unsigned slv_port_upper_byte =
axi_pkg::beat_upper_byte(act_slv_aw.axi_addr, act_slv_aw.axi_size, act_slv_aw.axi_len, act_slv_aw.axi_burst, AxiSlvPortStrbWidth, slv_port_w_cnt);
shortint unsigned bytes_copied = 0;
// Pointer inside the outcoming word
if (mst_port_w_pnt == '1)
mst_port_w_pnt = mst_port_lower_byte;
mst_port_w.axi_last = mst_port_w_cnt == act_mst_aw.axi_len;
for (shortint unsigned b = slv_port_lower_byte; b <= slv_port_upper_byte; b++) begin
if (b + mst_port_w_pnt - slv_port_lower_byte == AxiMstPortStrbWidth)
break;
mst_port_w.axi_data[8*(b + mst_port_w_pnt - slv_port_lower_byte) +: 8] = act_slv_w.axi_data[8*b +: 8];
mst_port_w.axi_strb[b + mst_port_w_pnt - slv_port_lower_byte] = act_slv_w.axi_strb[b] ;
bytes_copied++;
end
// Increment the len counters
slv_port_w_cnt++ ;
mst_port_w_pnt += bytes_copied;
if (act_mst_aw.axi_burst == axi_pkg::BURST_FIXED // No upsizing
|| mst_port_w_pnt == AxiMstPortStrbWidth // Filled up an outcoming W beat
|| act_slv_w.axi_last // Last beat of a W burst
) begin
// Don't care for the bits outside these accessed by this request
for (int unsigned b = 0; b < AxiMstPortStrbWidth; b++)
if (!(mst_port_lower_byte <= b && b <= mst_port_upper_byte))
mst_port_w.axi_data[8*b +: 8] = {8{1'b?}};
this.exp_mst_port_w_queue.push_back(mst_port_w);
incr_expected_tests(3) ;
// Increment the len counter
mst_port_w_cnt++;
// Reset W beat
mst_port_w = '0;
mst_port_w_pnt = '1;
end
// Pop the AW request from the queues
if (slv_port_w_cnt == act_slv_aw.axi_len + 1) begin
void'(act_slv_port_aw_queue.pop_front());
slv_port_w_cnt = 0;
end
if (mst_port_w_cnt == act_mst_aw.axi_len + 1) begin
void'(act_mst_port_aw_queue.pop_front());
mst_port_w_cnt = 0;
end
// Pop the W request
void'(act_slv_port_w_queue.pop_front());
end
end
endtask : mon_slv_port_w
task automatic mon_slv_port_ar ();
exp_ax_t exp_slv_ar;
exp_b_t exp_mst_r;
if (slv_port_axi.ar_valid && slv_port_axi.ar_ready) begin
// Non-modifiable transaction
if (!axi_pkg::modifiable(slv_port_axi.ar_cache)) begin
// We expect that the transaction will not be modified
exp_slv_ar = '{
axi_id : slv_port_axi.ar_id ,
axi_addr : slv_port_axi.ar_addr ,
axi_len : slv_port_axi.ar_len ,
axi_burst: slv_port_axi.ar_burst,
axi_size : slv_port_axi.ar_size ,
axi_cache: slv_port_axi.ar_cache
};
end
// Modifiable transaction
else begin
case (slv_port_axi.ar_burst)
// Passthrough upsize
axi_pkg::BURST_FIXED: begin
exp_slv_ar = '{
axi_id : slv_port_axi.ar_id ,
axi_addr : slv_port_axi.ar_addr ,
axi_len : slv_port_axi.ar_len ,
axi_burst: slv_port_axi.ar_burst,
axi_size : slv_port_axi.ar_size ,
axi_cache: slv_port_axi.ar_cache
};
end
// INCR upsize
axi_pkg::BURST_INCR: begin
automatic axi_addr_t aligned_start = axi_pkg::aligned_addr(slv_port_axi.ar_addr, AxiMstPortMaxSize) ;
automatic axi_addr_t aligned_end = axi_pkg::aligned_addr(axi_pkg::aligned_addr(slv_port_axi.ar_addr, slv_port_axi.ar_size) + (unsigned'(slv_port_axi.ar_len) << slv_port_axi.ar_size), AxiMstPortMaxSize);
exp_slv_ar = '{
axi_id : slv_port_axi.ar_id ,
axi_addr : slv_port_axi.ar_addr ,
axi_len : (aligned_end - aligned_start) >> AxiMstPortMaxSize ,
axi_burst: slv_port_axi.ar_burst ,
axi_size : slv_port_axi.ar_len == 0 ? slv_port_axi.ar_size : AxiMstPortMaxSize,
axi_cache: slv_port_axi.ar_cache
};
end
// WRAP upsize
axi_pkg::BURST_WRAP: begin
exp_slv_ar = '0;
$warning("WRAP bursts are not supported.");
end
endcase
this.exp_mst_port_ar_queue.push(slv_port_axi.ar_id, exp_slv_ar);
incr_expected_tests(6) ;
$display("%0tns > Master: AR with ID: %b",
$time, slv_port_axi.ar_id);
end
end
endtask : mon_slv_port_ar
task automatic mon_mst_port_r ();
if (mst_port_axi.r_valid && mst_port_axi.r_ready) begin
// Retrieve the AR requests related to this R beat
exp_ax_t act_mst_ar = act_mst_port_ar_queue.get(mst_port_axi.r_id);
exp_ax_t act_slv_ar = act_slv_port_ar_queue.get(mst_port_axi.r_id);
axi_id_t id = mst_port_axi.r_id ;
// Calculate the offsets inside the incoming word
shortint unsigned mst_port_lower_byte =
axi_pkg::beat_lower_byte(act_mst_ar.axi_addr, act_mst_ar.axi_size, act_mst_ar.axi_len, act_mst_ar.axi_burst, AxiMstPortStrbWidth, mst_port_r_cnt[id]);
shortint unsigned mst_port_upper_byte =
axi_pkg::beat_upper_byte(act_mst_ar.axi_addr, act_mst_ar.axi_size, act_mst_ar.axi_len, act_mst_ar.axi_burst, AxiMstPortStrbWidth, mst_port_r_cnt[id]);
// Pointer inside the incoming word
shortint unsigned mst_port_data_pointer = mst_port_lower_byte;
// Conversion ratio. How many R beats are generated from this incoming R beat.
int unsigned conversion_ratio = axi_pkg::modifiable(act_mst_ar.axi_cache) ? conv_ratio(act_mst_ar.axi_size, act_slv_ar.axi_size) : 1;
// Several R beats generated from this incoming R beat
for (int unsigned beat = 0; beat < conversion_ratio; beat++) begin
exp_slv_rw_t act_slv_r = '0;
// Calculate the offsets inside the outcoming word
shortint unsigned slv_port_lower_byte =
axi_pkg::beat_lower_byte(act_slv_ar.axi_addr, act_slv_ar.axi_size, act_slv_ar.axi_len, act_slv_ar.axi_burst, AxiSlvPortStrbWidth, slv_port_r_cnt[id]);
shortint unsigned slv_port_upper_byte =
axi_pkg::beat_upper_byte(act_slv_ar.axi_addr, act_slv_ar.axi_size, act_slv_ar.axi_len, act_slv_ar.axi_burst, AxiSlvPortStrbWidth, slv_port_r_cnt[id]);
shortint unsigned bytes_copied = 0;
act_slv_r.axi_id = mst_port_axi.r_id ;
act_slv_r.axi_last = slv_port_r_cnt[id] == act_slv_ar.axi_len;
act_slv_r.axi_data = {AxiSlvPortDataWidth{1'b?}} ;
act_slv_r.axi_strb = {AxiSlvPortStrbWidth{1'b?}} ;
for (shortint unsigned b = mst_port_data_pointer; b <= mst_port_upper_byte; b++) begin
act_slv_r.axi_data[8*(b + slv_port_lower_byte - mst_port_data_pointer) +: 8] = mst_port_axi.r_data[8*b +: 8];
bytes_copied++;
if (b + slv_port_lower_byte - mst_port_data_pointer == slv_port_upper_byte)
break;
end
this.exp_slv_port_r_queue.push(act_slv_r.axi_id, act_slv_r);
incr_expected_tests(3) ;
// Increment the len counters
slv_port_r_cnt[id]++ ;
mst_port_data_pointer += bytes_copied;
// Used the whole R beat
if (mst_port_data_pointer == AxiMstPortStrbWidth)
break;
// Finished the R beat
if (act_slv_r.axi_last)
break;
end
// Increment the len counter
mst_port_r_cnt[id]++;
// Pop the AR request from the queues
if (mst_port_r_cnt[id] == act_mst_ar.axi_len + 1) begin
void'(act_mst_port_ar_queue.pop_id(act_mst_ar.axi_id));
mst_port_r_cnt[id] = 0;
end
if (slv_port_r_cnt[id] == act_slv_ar.axi_len + 1) begin
void'(act_slv_port_ar_queue.pop_id(act_slv_ar.axi_id));
slv_port_r_cnt[id] = 0;
end
end
endtask: mon_mst_port_r
endclass : axi_dw_upsizer_monitor
/***************
* DOWNSIZER *
***************/
class axi_dw_downsizer_monitor #(
parameter int unsigned AxiAddrWidth ,
parameter int unsigned AxiSlvPortDataWidth,
parameter int unsigned AxiMstPortDataWidth,
parameter int unsigned AxiIdWidth ,
parameter int unsigned AxiUserWidth ,
// Stimuli application and test time
parameter time TimeTest
) extends axi_dw_monitor #(
.AxiAddrWidth (AxiAddrWidth ),
.AxiSlvPortDataWidth(AxiSlvPortDataWidth),
.AxiMstPortDataWidth(AxiMstPortDataWidth),
.AxiIdWidth (AxiIdWidth ),
.AxiUserWidth (AxiUserWidth ),
.TimeTest (TimeTest )
);
local static shortint unsigned slv_port_r_cnt[axi_id_t];
local static shortint unsigned mst_port_r_cnt[axi_id_t];
local static exp_slv_rw_t slv_port_r[axi_id_t];
local static shortint unsigned slv_port_r_pnt[axi_id_t];
local static shortint unsigned slv_port_w_cnt;
local static shortint unsigned mst_port_w_cnt;
/**********************
* Helper functions *
**********************/
/*
* Returns how many beats of the incoming AXI transaction will be dropped after downsizing
* due to an unaligned memory address.
*/
function automatic len_t aligned_adjustment(axi_addr_t addr, axi_pkg::size_t size) ;
return (addr & size_mask(size) & ~size_mask(AxiMstPortMaxSize))/axi_pkg::num_bytes(AxiMstPortMaxSize);
endfunction: aligned_adjustment
/*****************
* Constructor *
*****************/
function new (
virtual AXI_BUS_DV #(
.AXI_ADDR_WIDTH(AxiAddrWidth ),
.AXI_DATA_WIDTH(AxiSlvPortDataWidth),
.AXI_ID_WIDTH (AxiIdWidth ),
.AXI_USER_WIDTH(AxiUserWidth )
) slv_port_vif,
virtual AXI_BUS_DV #(
.AXI_ADDR_WIDTH(AxiAddrWidth ),
.AXI_DATA_WIDTH(AxiMstPortDataWidth),
.AXI_ID_WIDTH (AxiIdWidth ),
.AXI_USER_WIDTH(AxiUserWidth )
) mst_port_vif
);
begin
super.new(slv_port_vif, mst_port_vif);
slv_port_w_cnt = 0;
mst_port_w_cnt = 0;
for (int unsigned id = 0; id < 2**AxiIdWidth; id++) begin
slv_port_r_cnt[id] = '0;
mst_port_r_cnt[id] = '0;
slv_port_r[id] = '0;
slv_port_r_pnt[id] = '1;
end
end
endfunction
/**************
* Monitors *
**************/
task automatic mon_slv_port_aw ();
exp_ax_t exp_aw;
if (slv_port_axi.aw_valid && slv_port_axi.aw_ready) begin
case (slv_port_axi.aw_burst)
axi_pkg::BURST_INCR: begin
// Transaction unchanged
if (conv_ratio(slv_port_axi.aw_size, AxiMstPortMaxSize) == 1) begin
exp_aw = '{
axi_id : slv_port_axi.aw_id ,
axi_addr : slv_port_axi.aw_addr ,
axi_len : slv_port_axi.aw_len ,
axi_burst: slv_port_axi.aw_burst,
axi_size : slv_port_axi.aw_size ,
axi_cache: slv_port_axi.aw_cache
};
this.exp_mst_port_aw_queue.push(slv_port_axi.aw_id, exp_aw);
incr_expected_tests(6) ;
end
// INCR downsize
else begin
automatic int unsigned num_beats = (slv_port_axi.aw_len + 1) * conv_ratio(slv_port_axi.aw_size, AxiMstPortMaxSize) - aligned_adjustment(slv_port_axi.aw_addr, slv_port_axi.aw_size);
// One burst