-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_serial_test.sv
1745 lines (1264 loc) · 60.4 KB
/
custom_serial_test.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
`include "uvm_macros.svh"
import uvm_pkg::*;
typedef class custom_serial_base_transaction;
interface custom_serial_interface
( input clk,
input rstn
);
reg serial;
string instance_name="";
semaphore sem_if;
bit monitor_first_time;
initial begin
sem_if = new(1);
end
clocking cb_driver@(posedge clk);
output serial;
endclocking
clocking cb_monitor@(posedge clk);
input serial;
endclocking
function string get_inst_name();
return instance_name;
endfunction
//Make sure to make interface/module/programing block methods as
//automatic to avoid one call affecting the previous call
task automatic drive_idle();
bit [7:0] idle = 'h07;
//SV Streaming operator to reverse the bits, since foreach is
//driving from MSB bit to LSB bit for packet arrays
idle = {<<{idle}};
sem_if.get(1);
foreach(idle[i]) begin
@cb_driver;
cb_driver.serial <= idle[i];
end
sem_if.put(1);
endtask
task automatic drive_am();
bit [7:0] am = 'h55;
int num_am = 5;
//For TX and RX Monitor Synchronization 2 is used.
int num_device = 2;
am = {<<{am}};
sem_if.get(1);
repeat(num_am*num_device) begin
foreach(am[i]) begin
@cb_driver;
cb_driver.serial <= am[i];
end
end
sem_if.put(1);
endtask
task automatic drive_trans(custom_serial_base_transaction t);
bit [7:0] sop = 'hfb;
bit [7:0] eop = 'hfd;
//Don't use t.print() inside uvm_info. It doesn't return a string.
//`uvm_info(get_inst_name(), $sformatf("Received Transaction = %p", t.print()), UVM_MEDIUM)
//Instead use t.sprint() with format specified %s
`uvm_info(get_inst_name(), $sformatf("Received Transaction : \n%s", t.sprint()), UVM_MEDIUM)
sem_if.get(1);
for(int i=0; i< $bits(sop); i++) begin
@cb_driver;
cb_driver.serial <= sop[i];
end
for(int i=0; i< $bits(t.link_id); i++) begin
@cb_driver;
cb_driver.serial <= t.link_id[i];
end
for(int i=0; i< $bits(t.length); i++) begin
@cb_driver;
cb_driver.serial <= t.length[i];
end
foreach(t.payload[i]) begin
for(int j=0; j< $bits(t.payload[i]); j++) begin
@cb_driver;
cb_driver.serial <= t.payload[i][j];
end
end
for(int i=0; i< $bits(eop); i++) begin
@cb_driver;
cb_driver.serial <= eop[i];
end
sem_if.put(1);
endtask : drive_trans
task automatic detect_am();
bit serial_mon[$];
bit [7:0] am = 'h55;
int num_am = 5;
int num_device = 1;
bit am_detected=0;
forever begin
@cb_monitor;
if(serial_mon.size == $bits(am)*num_am*num_device)
void'(serial_mon.pop_front());
serial_mon.push_back(cb_monitor.serial);
if(serial_mon.size == $bits(am)*num_am*num_device) begin
am_detected=1;
foreach(serial_mon[i]) begin
if(serial_mon[serial_mon.size-1-i] != am[i%$bits(am)])
am_detected = 0;
end
end
if(am_detected) begin
`uvm_info(get_inst_name(),"All AMs detected", UVM_MEDIUM)
break;
end
end
monitor_first_time=1;
endtask
task automatic collect_trans(output custom_serial_base_transaction t);
bit [7:0] serial_mon[$];
bit [7:0] single_cycle_data;
bit [7:0] sop = 'hfb;
bit [7:0] eop = 'hfd;
bit sop_detected;
bit eop_detected;
t = custom_serial_base_transaction::type_id::create("t");
//Used to give 1 cycle gap b/w am & this task to WA coding bug
if(monitor_first_time) begin
@cb_monitor;
monitor_first_time=0;
end
forever begin
for(int i=0; i< $bits(single_cycle_data); i+=1) begin
@cb_monitor;
single_cycle_data[i] = cb_monitor.serial;
end
if(single_cycle_data == sop) begin
sop_detected = 1;
end
else if(single_cycle_data == eop) begin
eop_detected = 1;
end
else if(sop_detected) begin
serial_mon.push_back(single_cycle_data);
end
if(eop_detected) begin
if(serial_mon.size>0) begin
t.link_id = serial_mon.pop_front();
if(serial_mon.size>0) begin
t.length = serial_mon.pop_front();
if(serial_mon.size>0) begin
t.payload = new[serial_mon.size];
foreach(serial_mon[i]) begin
t.payload[i] = serial_mon[i];
end
end
end else begin
`uvm_error(get_inst_name(),"Invalid size transaction received")
end
end
else begin
`uvm_error(get_inst_name(),"Received EOP without SOP")
end
break;
end
end
endtask
endinterface : custom_serial_interface
typedef enum {LED0_ON=8'h00,LED0_OFF=8'h01,LED1_ON=8'h10,LED1_OFF=8'h11} serial_command;
class custom_serial_base_transaction extends uvm_sequence_item;
rand bit [7:0] link_id;
rand bit [7:0] length;
rand bit [7:0] payload[];
rand bit [7:0] command;
serial_command serial_command_set[];
serial_command cmd;
`uvm_object_utils(custom_serial_base_transaction)
function new(string name="custom_serial_base_transaction_0");
super.new(name);
serial_command_set = new[cmd.num];
cmd = cmd.first();
foreach(serial_command_set[i]) begin
serial_command_set[i] = cmd;
cmd = cmd.next;
end
endfunction : new
//soft keyword is used to override the constraint for error injection.
//Error can also be injected by overriding the same constraint in
//extended class. Also done in post_randomize() function
constraint payload_size {
soft payload.size == length;
}
constraint min_length {
soft length > 0;
}
constraint max_length {
length < 10;
}
constraint command_set {
payload.size > 0 -> command == payload[0];
}
constraint valid_command {
soft command inside {serial_command_set};
}
//It's recommended to not use factory macro utils to avoid compile/run time overhead issues.
//Define your functions using do_*
virtual function void do_print(uvm_printer printer);
string idx;
super.do_print(printer);
printer.print_field_int("ID",link_id,$bits(link_id),UVM_HEX);
printer.print_field_int("LENGTH",length,$bits(length),UVM_HEX);
foreach(payload[i]) begin
idx.itoa(i);
printer.print_field_int({"PAYLOAD[",idx,"]"},payload[i],$bits(payload[i]),UVM_HEX);
end
endfunction : do_print
endclass : custom_serial_base_transaction
class custom_serial_length_error_transaction extends custom_serial_base_transaction;
`uvm_object_utils(custom_serial_length_error_transaction)
function new(string name="custom_serial_length_error_transaction_0");
super.new(name);
endfunction : new
constraint payload_length_error {
payload.size inside {length-1,[length+1:length+5]};
}
endclass : custom_serial_length_error_transaction
class custom_serial_zero_length_transaction extends custom_serial_base_transaction;
`uvm_object_utils(custom_serial_zero_length_transaction)
function new(string name="custom_serial_zero_length_transaction_0");
super.new(name);
endfunction : new
constraint payload_length {
length == 0;
payload.size > 0;
payload.size < 10;
}
endclass : custom_serial_zero_length_transaction
class custom_serial_monitor extends uvm_monitor;
`uvm_component_utils(custom_serial_monitor)
uvm_analysis_port#(custom_serial_base_transaction) analysis_port;
custom_serial_base_transaction t;
virtual custom_serial_interface serial_vif;
function new(string name, uvm_component parent);
super.new(name,parent);
endfunction : new
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info(get_type_name(),$sformatf("[BUILD PHASE] Start.."), UVM_NONE)
//Why analysis ports are created with new() instead of type_id::create?
analysis_port = new("analysis_port",this);
uvm_config_db#(virtual custom_serial_interface)::get(this,"","custom_serial_vif",serial_vif);
`uvm_info(get_type_name(),$sformatf("[BUILD PHASE] End.."), UVM_NONE)
endfunction : build_phase
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
`uvm_info(get_type_name(),$sformatf("[CONNECT PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[CONNECT PHASE] End.."), UVM_NONE)
endfunction : connect_phase
virtual function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
`uvm_info(get_type_name(),$sformatf("[END OF ELABORATION PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[END OF ELABORATION PHASE] End.."), UVM_NONE)
endfunction : end_of_elaboration_phase
virtual function void start_of_simulation_phase(uvm_phase phase);
super.start_of_simulation_phase(phase);
`uvm_info(get_type_name(),$sformatf("[START OF SIMULATION PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[START OF SIMULATION PHASE] End.."), UVM_NONE)
endfunction : start_of_simulation_phase
virtual task run_phase(uvm_phase phase);
super.run_phase(phase);
`uvm_info(get_type_name(),$sformatf("[RUN PHASE] Start.."), UVM_NONE)
serial_vif.detect_am();
forever begin
serial_vif.collect_trans(t);
analysis_port.write(t);
end
`uvm_info(get_type_name(),$sformatf("[RUN PHASE] End.."), UVM_NONE)
endtask : run_phase
virtual function void extract_phase(uvm_phase phase);
super.extract_phase(phase);
`uvm_info(get_type_name(),$sformatf("[EXTRACT PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[EXTRACT PHASE] End.."), UVM_NONE)
endfunction : extract_phase
virtual function void check_phase(uvm_phase phase);
super.check_phase(phase);
`uvm_info(get_type_name(),$sformatf("[CHECK PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[CHECK PHASE] End.."), UVM_NONE)
endfunction : check_phase
virtual function void report_phase(uvm_phase phase);
super.report_phase(phase);
`uvm_info(get_type_name(),$sformatf("[REPORT PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[REPORT PHASE] End.."), UVM_NONE)
endfunction : report_phase
virtual function void final_phase(uvm_phase phase);
super.final_phase(phase);
`uvm_info(get_type_name(),$sformatf("[FINAL PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[FINAL PHASE] End.."), UVM_NONE)
endfunction : final_phase
endclass : custom_serial_monitor
class custom_serial_driver extends uvm_driver#(custom_serial_base_transaction);
`uvm_component_utils(custom_serial_driver)
custom_serial_base_transaction t;
custom_serial_base_transaction t_q[$];
virtual custom_serial_interface serial_vif;
function new(string name, uvm_component parent);
super.new(name,parent);
endfunction : new
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info(get_type_name(),$sformatf("[BUILD PHASE] Start.."), UVM_NONE)
uvm_config_db#(virtual custom_serial_interface)::get(this,"","custom_serial_vif",serial_vif);
`uvm_info(get_type_name(),$sformatf("[BUILD PHASE] End.."), UVM_NONE)
endfunction : build_phase
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
`uvm_info(get_type_name(),$sformatf("[CONNECT PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[CONNECT PHASE] End.."), UVM_NONE)
endfunction : connect_phase
virtual function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
`uvm_info(get_type_name(),$sformatf("[END OF ELABORATION PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[END OF ELABORATION PHASE] End.."), UVM_NONE)
endfunction : end_of_elaboration_phase
virtual function void start_of_simulation_phase(uvm_phase phase);
super.start_of_simulation_phase(phase);
`uvm_info(get_type_name(),$sformatf("[START OF SIMULATION PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[START OF SIMULATION PHASE] End.."), UVM_NONE)
endfunction : start_of_simulation_phase
virtual task run_phase(uvm_phase phase);
super.run_phase(phase);
`uvm_info(get_type_name(),$sformatf("[RUN PHASE] Start.."), UVM_NONE)
wait_reset();
fork
begin
forever begin
seq_item_port.get_next_item(t);
`uvm_info(get_type_name(),$sformatf("Received Transaction %s",t.sprint()), UVM_MEDIUM)
t_q.push_back(t);
seq_item_port.item_done();
end
end
begin
#(1ns * $urandom_range(10,5));
drive_am();
drive_trans();
end
begin
drive_idle();
end
join
`uvm_info(get_type_name(),$sformatf("[RUN PHASE] End.."), UVM_NONE)
endtask : run_phase
virtual function void extract_phase(uvm_phase phase);
super.extract_phase(phase);
`uvm_info(get_type_name(),$sformatf("[EXTRACT PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[EXTRACT PHASE] End.."), UVM_NONE)
endfunction : extract_phase
virtual function void check_phase(uvm_phase phase);
super.check_phase(phase);
`uvm_info(get_type_name(),$sformatf("[CHECK PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[CHECK PHASE] End.."), UVM_NONE)
endfunction : check_phase
virtual function void report_phase(uvm_phase phase);
super.report_phase(phase);
`uvm_info(get_type_name(),$sformatf("[REPORT PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[REPORT PHASE] End.."), UVM_NONE)
endfunction : report_phase
virtual function void final_phase(uvm_phase phase);
super.final_phase(phase);
`uvm_info(get_type_name(),$sformatf("[FINAL PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[FINAL PHASE] End.."), UVM_NONE)
endfunction : final_phase
virtual task wait_reset();
wait(serial_vif.rstn==1);
endtask : wait_reset
virtual task drive_idle();
forever begin
serial_vif.drive_idle();
end
endtask : drive_idle
virtual task drive_am();
serial_vif.drive_am();
endtask : drive_am
virtual task drive_trans();
custom_serial_base_transaction trans;
forever begin
wait(t_q.size>0)
trans = t_q.pop_front();
serial_vif.drive_trans(trans);
end
endtask : drive_trans
endclass : custom_serial_driver
class custom_serial_sequence extends uvm_sequence#(custom_serial_base_transaction);
// The uvm_sequence_base class provides the interfaces needed to create streams
// of sequence items and/or other sequences.
//
// A sequence is executed by calling its <start> method, either directly
// or invocation of any of the `uvm_do_* macros.
//
// Executing sequences via <start>:
//
// A sequence's <start> method has a ~parent_sequence~ argument that controls
// whether <pre_do>, <mid_do>, and <post_do> are called *in the parent*
// sequence. It also has a ~call_pre_post~ argument that controls whether its
// <pre_body> and <post_body> methods are called.
// In all cases, its <pre_start> and <post_start> methods are always called.
//
// When <start> is called directly, you can provide the appropriate arguments
// according to your application.
//
// The sequence execution flow looks like this
//
// User code
//
//| sub_seq.randomize(...); // optional
//| sub_seq.start(seqr, parent_seq, priority, call_pre_post)
//|
//
// The following methods are called, in order
//
//|
//| sub_seq.pre_start() (task)
//| sub_seq.pre_body() (task) if call_pre_post==1
//| parent_seq.pre_do(0) (task) if parent_sequence!=null
//| parent_seq.mid_do(this) (func) if parent_sequence!=null
//| sub_seq.body (task) YOUR STIMULUS CODE
//| parent_seq.post_do(this) (func) if parent_sequence!=null
//| sub_seq.post_body() (task) if call_pre_post==1
//| sub_seq.post_start() (task)
//
//
// Executing sub-sequences via `uvm_do macros:
//
// A sequence can also be indirectly started as a child in the <body> of a
// parent sequence. The child sequence's <start> method is called indirectly
// by invoking any of the `uvm_do macros.
// In these cases, <start> is called with
// ~call_pre_post~ set to 0, preventing the started sequence's <pre_body> and
// <post_body> methods from being called. During execution of the
// child sequence, the parent's <pre_do>, <mid_do>, and <post_do> methods
// are called.
//
// The sub-sequence execution flow looks like
//
// User code
//
//|
//| `uvm_do_with_prior(seq_seq, { constraints }, priority)
//|
//
// The following methods are called, in order
//
//|
//| sub_seq.pre_start() (task)
//| parent_seq.pre_do(0) (task)
//| parent_req.mid_do(sub_seq) (func)
//| sub_seq.body() (task)
//| parent_seq.post_do(sub_seq) (func)
//| sub_seq.post_start() (task)
//|
//
// Remember, it is the *parent* sequence's pre|mid|post_do that are called, not
// the sequence being executed.
//
//
// Executing sequence items via <start_item>/<finish_item> or `uvm_do macros:
//
// Items are started in the <body> of a parent sequence via calls to
// <start_item>/<finish_item> or invocations of any of the `uvm_do
// macros. The <pre_do>, <mid_do>, and <post_do> methods of the parent
// sequence will be called as the item is executed.
//
// The sequence-item execution flow looks like
//
// User code
//
//| parent_seq.start_item(item, priority);
//| item.randomize(...) [with {constraints}];
//| parent_seq.finish_item(item);
//|
//| or
//|
//| `uvm_do_with_prior(item, constraints, priority)
//|
//
// The following methods are called, in order
//
//|
//| sequencer.wait_for_grant(prior) (task) \ start_item \
//| parent_seq.pre_do(1) (task) / \
//| `uvm_do* macros
//| parent_seq.mid_do(item) (func) \ /
//| sequencer.send_request(item) (func) \finish_item /
//| sequencer.wait_for_item_done() (task) /
//| parent_seq.post_do(item) (func) /
//
// Attempting to execute a sequence via <start_item>/<finish_item>
// will produce a run-time error.
`uvm_object_utils(custom_serial_sequence)
custom_serial_base_transaction t;
bit [7:0] link_id;
uvm_cmdline_processor uvm_cmdline_processor_t;
string num_packets_s;
int num_packets;
int scb_exp_packet_count;
//UVM Objects do not have parent
function new(string name="custom_serial_sequence_0");
super.new(name);
set_automatic_phase_objection(1);
uvm_cmdline_processor_t = uvm_cmdline_processor::get_inst();
if(uvm_cmdline_processor_t.get_arg_value("+num_packets=",num_packets_s))
num_packets = num_packets_s.atoi();
else
num_packets = 5;
endfunction : new
// This task is a user-definable callback that is called before the
// optional execution of <pre_body>.
// This method should not be called directly by the user.
virtual task pre_start();
super.pre_start();
`uvm_info(get_type_name(),$sformatf("[PRE START] Start.."), UVM_NONE)
if(!uvm_config_db#(int)::get(m_sequencer,"","NUM_PACKETS_TX",scb_exp_packet_count)) begin
`uvm_fatal(get_type_name(),"Unable to get value of NUM_PACKETS_TX")
end
fork begin
forever begin
uvm_config_db#(int)::wait_modified(m_sequencer,"","NUM_PACKETS_TX");
uvm_config_db#(int)::get(m_sequencer,"","NUM_PACKETS_TX",scb_exp_packet_count);
end
end
join_none
`uvm_info(get_type_name(),$sformatf("[PRE START] End.."), UVM_NONE)
endtask : pre_start
// This task is a user-definable callback that is called before the
// execution of <body> ~only~ when the sequence is started with <start>.
// If <start> is called with ~call_pre_post~ set to 0, ~pre_body~ is not
// called.
// This method should not be called directly by the user.
virtual task pre_body();
super.pre_body();
`uvm_info(get_type_name(),$sformatf("[PRE BODY] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[PRE BODY] End.."), UVM_NONE)
endtask : pre_body
// This task is a user-definable callback task that is called ~on the
// parent sequence~, if any
// sequence has issued a wait_for_grant() call and after the sequencer has
// selected this sequence, and before the item is randomized.
//
// Although pre_do is a task, consuming simulation cycles may result in
// unexpected behavior on the driver.
//
// This method should not be called directly by the user.
virtual task pre_do(bit is_item);
super.pre_do(is_item);
`uvm_info(get_type_name(),$sformatf("[PRE DO] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[PRE DO] End.."), UVM_NONE)
endtask : pre_do
// This function is a user-definable callback function that is called after
// the sequence item has been randomized, and just before the item is sent
// to the driver. This method should not be called directly by the user.
virtual function void mid_do(uvm_sequence_item this_item);
super.mid_do(this_item);
`uvm_info(get_type_name(),$sformatf("[MID DO] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[MID DO] End.."), UVM_NONE)
endfunction : mid_do
// This is the user-defined task where the main sequence code resides.
// This method should not be called directly by the user.
virtual task body();
super.body();
`uvm_info(get_type_name(),$sformatf("[BODY] Start.."), UVM_NONE)
uvm_config_db#(int)::get(m_sequencer,"","link_id",link_id);
repeat(num_packets) begin
t = custom_serial_base_transaction::type_id::create("t");
start_item(t,-1,m_sequencer);
if(!t.randomize() with {link_id == local::link_id;})
`uvm_error(get_type_name(),"Failed to randomize. Please check")
finish_item(t);
end
`uvm_info(get_type_name(),$sformatf("[BODY] End.."), UVM_NONE)
endtask : body
// This function is a user-definable callback function that is called after
// the driver has indicated that it has completed the item, using either
// this item_done or put methods. This method should not be called directly
// by the user.
virtual function void post_do(uvm_sequence_item this_item);
super.post_do(this_item);
`uvm_info(get_type_name(),$sformatf("[POST DO] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[POST DO] End.."), UVM_NONE)
endfunction : post_do
// This task is a user-definable callback task that is called after the
// execution of <body> ~only~ when the sequence is started with <start>.
// If <start> is called with ~call_pre_post~ set to 0, ~post_body~ is not
// called.
// This task is a user-definable callback task that is called after the
// execution of the body, unless the sequence is started with call_pre_post=0.
// This method should not be called directly by the user.
virtual task post_body();
super.post_body();
`uvm_info(get_type_name(),$sformatf("[POST BODY] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[POST BODY] End.."), UVM_NONE)
endtask : post_body
// This task is a user-definable callback that is called after the
// optional execution of <post_body>.
// This method should not be called directly by the user.
virtual task post_start();
super.post_start();
`uvm_info(get_type_name(),$sformatf("[POST START] Start.."), UVM_NONE)
fork begin
//Since disable_fork is used, to prevent if from killing
//other forks, this is kept inside an outer fork
fork
begin
wait(scb_exp_packet_count >= num_packets);
end
begin
#(500ns * num_packets);
`uvm_error(get_type_name(),$sformatf("Timeout waiting for packets. Expected : 'h%0h, Actual : 'h%0h",num_packets,scb_exp_packet_count))
end
join_any
disable fork;
end
join
`uvm_info(get_type_name(),$sformatf("[POST START] End.."), UVM_NONE)
endtask : post_start
endclass : custom_serial_sequence
class custom_serial_sequencer extends uvm_sequencer#(custom_serial_base_transaction);
`uvm_component_utils(custom_serial_sequencer)
function new(string name, uvm_component parent);
super.new(name,parent);
endfunction : new
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info(get_type_name(),$sformatf("[BUILD PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[BUILD PHASE] End.."), UVM_NONE)
endfunction : build_phase
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
`uvm_info(get_type_name(),$sformatf("[CONNECT PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[CONNECT PHASE] End.."), UVM_NONE)
endfunction : connect_phase
virtual task run_phase(uvm_phase phase);
super.run_phase(phase);
`uvm_info(get_type_name(),$sformatf("[RUN PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[RUN PHASE] End.."), UVM_NONE)
endtask : run_phase
endclass : custom_serial_sequencer
class custom_serial_agent extends uvm_agent;
`uvm_component_utils(custom_serial_agent)
custom_serial_driver drv;
custom_serial_monitor mon;
custom_serial_sequencer sqr;
bit is_active;
function new(string name, uvm_component parent);
super.new(name,parent);
endfunction : new
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info(get_type_name(),$sformatf("[BUILD PHASE] Start.."), UVM_NONE)
if(is_active) begin
drv = custom_serial_driver::type_id::create("drv",this);
sqr = custom_serial_sequencer::type_id::create("sqr",this);
end
mon = custom_serial_monitor::type_id::create("mon",this);
`uvm_info(get_type_name(),$sformatf("[BUILD PHASE] End.."), UVM_NONE)
endfunction : build_phase
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
`uvm_info(get_type_name(),$sformatf("[CONNECT PHASE] Start.."), UVM_NONE)
if(is_active) begin
drv.seq_item_port.connect(sqr.seq_item_export);
end
`uvm_info(get_type_name(),$sformatf("[CONNECT PHASE] End.."), UVM_NONE)
endfunction : connect_phase
virtual function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
`uvm_info(get_type_name(),$sformatf("[END OF ELABORATION PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[END OF ELABORATION PHASE] End.."), UVM_NONE)
endfunction : end_of_elaboration_phase
virtual function void start_of_simulation_phase(uvm_phase phase);
super.start_of_simulation_phase(phase);
`uvm_info(get_type_name(),$sformatf("[START OF SIMULATION PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[START OF SIMULATION PHASE] End.."), UVM_NONE)
endfunction : start_of_simulation_phase
virtual task reset_phase(uvm_phase phase);
super.reset_phase(phase);
`uvm_info(get_type_name(),$sformatf("[RESET PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[RESET PHASE] End.."), UVM_NONE)
endtask : reset_phase
virtual task configure_phase(uvm_phase phase);
super.configure_phase(phase);
`uvm_info(get_type_name(),$sformatf("[CONFUGURE PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[CONFIGURE PHASE] End.."), UVM_NONE)
endtask : configure_phase
virtual task main_phase(uvm_phase phase);
super.main_phase(phase);
`uvm_info(get_type_name(),$sformatf("[MAIN PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[MAIN PHASE] End.."), UVM_NONE)
endtask : main_phase
virtual task shutdown_phase(uvm_phase phase);
super.shutdown_phase(phase);
`uvm_info(get_type_name(),$sformatf("[SHUTDOWN PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[SHUTDOWN PHASE] End.."), UVM_NONE)
endtask : shutdown_phase
virtual function void extract_phase(uvm_phase phase);
super.extract_phase(phase);
`uvm_info(get_type_name(),$sformatf("[EXTRACT PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[EXTRACT PHASE] End.."), UVM_NONE)
endfunction : extract_phase
virtual function void check_phase(uvm_phase phase);
super.check_phase(phase);
`uvm_info(get_type_name(),$sformatf("[CHECK PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[CHECK PHASE] End.."), UVM_NONE)
endfunction : check_phase
virtual function void report_phase(uvm_phase phase);
super.report_phase(phase);
`uvm_info(get_type_name(),$sformatf("[REPORT PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[REPORT PHASE] End.."), UVM_NONE)
endfunction : report_phase
virtual function void final_phase(uvm_phase phase);
super.final_phase(phase);
`uvm_info(get_type_name(),$sformatf("[FINAL PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[FINAL PHASE] End.."), UVM_NONE)
endfunction : final_phase
endclass : custom_serial_agent
class custom_serial_scoreboard extends uvm_scoreboard;
`uvm_analysis_imp_decl(_tx)
`uvm_analysis_imp_decl(_rx)
`uvm_component_utils(custom_serial_scoreboard)
uvm_analysis_imp_tx#(custom_serial_base_transaction,custom_serial_scoreboard) analysis_imp_tx;
uvm_analysis_imp_rx#(custom_serial_base_transaction,custom_serial_scoreboard) analysis_imp_rx;
custom_serial_base_transaction q_rx[$];
custom_serial_base_transaction q_tx[$];
int num_passing;
int num_failing;
int num_compared;
int num_received_tx;
int num_received_rx;
function new(string name, uvm_component parent);
super.new(name,parent);
endfunction : new
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info(get_type_name(),$sformatf("[BUILD PHASE] Start.."), UVM_NONE)
analysis_imp_tx = new("analysis_imp_tx",this);
uvm_config_db#(int)::set(this.get_parent(),"agt0.sqr","NUM_PACKETS_TX",num_received_tx);
uvm_config_db#(int)::set(this.get_parent(),"agt0.sqr","NUM_PACKETS_TX",num_received_rx);
analysis_imp_rx = new("analysis_imp_rx",this);
`uvm_info(get_type_name(),$sformatf("[BUILD PHASE] End.."), UVM_NONE)
endfunction : build_phase
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
`uvm_info(get_type_name(),$sformatf("[CONNECT PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[CONNECT PHASE] End.."), UVM_NONE)
endfunction : connect_phase
virtual function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
`uvm_info(get_type_name(),$sformatf("[END OF ELABORATION PHASE] Start.."), UVM_NONE)
`uvm_info(get_type_name(),$sformatf("[END OF ELABORATION PHASE] End.."), UVM_NONE)
endfunction : end_of_elaboration_phase
virtual function void start_of_simulation_phase(uvm_phase phase);