|
|
A vmm scenario generator are transactors which repeatly select a scenario from a set of available scenarios, randomize it and then execute. A vmm scenario generator generates sequence of transactions. Unlike vmm_atomic_gen, which only generates only one transaction at a time, and does not depend on past generated transaction. Using vmm scenario generator, we can generate complex sequence of transation. |
|
|
1 `include "vmm.sv"
2
3 // Note : This is not exact representation of AHB data class
4 // All data class needs to extend from vmm_data
5 class ahb_data extends vmm_data;
6 vmm_log log;
7 // Declare all the fields
8 rand bit [31:0] addr;
9 rand bit [31:0] data;
10 rand bit cmd;
11
12 // Make sure all variables have init value
13 function new(vmm_log log = null);
14 int i;
15 super.new(log);
16 this.log = log;
17 this.addr = 0;
18 this.data = 0;
19 this.cmd = 0;
20 endfunction
21 virtual function vmm_data copy(vmm_data to = null);
22 ahb_data cpy;
23 int i;
24 if (to == null) begin
25 cpy = new (log);
26 end else begin
27 if ( ! ($cast(cpy,to))) begin
28 `vmm_fatal(log,"Object is not of type ahb_data");
29 end
30 end
31 cpy.addr = this.addr;
32 cpy.data = this.data;
33 cpy.cmd = this.cmd;
34 copy = cpy;
35 endfunction
36
37
38 // Print message
39 function void display(string prefix = "");
40 if (is_valid()) begin
41 `vmm_debug(log,$psprintf("%s",psdisplay(prefix)));
42 end else begin
43 `vmm_error(log,$psprintf("%s",psdisplay(prefix)));
44 end
45 endfunction
46
47 // Return the string members and their values
48 virtual function string psdisplay(string prefix = "");
49 string msg;
50 int i;
51 msg = $psprintf(" %s\n", prefix);
52 msg = $psprintf("%s ADDRESS : 32'h%x\n",msg,addr);
53 msg = $psprintf("%s DATA : 32'h%x\n",msg,data);
54 msg = $psprintf("%s CMD : 1'b%b\n",msg,cmd);
55
56 psdisplay = msg;
57 endfunction
58 endclass
59
60 // We need to add below line to construct vmm_channel for object ahb_data
61 `vmm_channel(ahb_data)
62 `vmm_scenario_gen(ahb_data,"SCENARIO GEN")
63
64
65 class my_ahb_data_scenario extends ahb_data_scenario;
66 int add_trans_index,sub_trans_index;
67 vmm_log log;
68
69 constraint add_items {
70 if ($void(scenario_kind) == add_trans_index) {
71 length == 2;
72 repeated == 0;
73 foreach(items[i]) {
74 if (i % 2 == 0) {
75 this.items[i].cmd == 0;
76 } else if (i % 2 == 1) {
77 this.items[i].cmd == 1;
78 this.items[i].addr == this.items[i-1].addr;
79 }
80 }
81 }
82 }
83
84 constraint sub_items {
85 if ($void(scenario_kind) == add_trans_index) {
86 length == 2;
87 repeated == 0;
88 foreach(items[i]) {
89 if (i % 2 == 0) {
90 this.items[i].cmd == 0;
91 } else if (i % 2 == 1) {
92 this.items[i].cmd == 1;
93 this.items[i].addr == this.items[i-1].addr;
94 }
95 }
96 }
97 }
98
99 function new(vmm_log log);
100 super.new();
101 this.log = log;
102 this.add_trans_index = define_scenario(" ADD ",2);
103 this.sub_trans_index = define_scenario(" SUB ",2);
104 endfunction
105
106 endclass
107
108 // This class sinks transactions
109 class sink extends vmm_xactor;
110 ahb_data_channel fifo;
111 vmm_log log;
112
113 function new(vmm_log log, string name, ahb_data_channel fifo);
114 super.new(name,name);
115 this.log = log;
116 this.fifo = fifo;
117 endfunction
118
119 virtual task main();
120 ahb_data d;
121 super.main();
122 while (1) begin
123 wait_if_stopped_or_empty(fifo);
124 fifo.get(d);
125 // Indicate we are processing the object
126 d.notify.indicate(vmm_data::STARTED);
127 #10 ;
128 // Indicate we done with processing the object
129 $display("Indicating done processing");
130 d.notify.indicate(vmm_data::ENDED);
131 end
132 endtask
133 endclass
134
135 program test();
136 vmm_log log = new("test","ahb_data");
137 ahb_data_channel fifo = new ("CHANNEL","FIFO");
138 ahb_data_scenario_gen src = new("SOURCE",-1,fifo);
139 my_ahb_data_scenario add_sub = new(log);
140
141 sink snk = new(log,"SINK",fifo);
142
143 initial begin
144 // Set number of transactions to generate
145 src.stop_after_n_insts = 1;
146 src.stop_after_n_scenarios = 2;
147 $display ("Size %0d",src.scenario_set.size());
148 src.scenario_set[0] = add_sub;
149 snk.start_xactor();
150 src.start_xactor();
151 // Wait for source to start
152 src.notify.wait_for(vmm_xactor::XACTOR_BUSY);
153 $display("Came out of SOURCE START");
154 // Wait for source to end
155 src.notify.wait_for(ahb_data_scenario_gen::DONE);
156 $display("Came out of SOURCE DONE");
157 #10 ;
158 end
159 endprogram
You could download file vmm_scenario_ex.sv here
|