|
|
|
|
|
|
|
|
|
|
|
|
vmm_atomic_gen
|
|
|
vmm_atomic_gen is basically a macro like vmm_channel, which basically builds a simple for loop to randomize the vmm_data and push into vmm_channel. The for loop varibale is controlled by a integer variable stop_after_n_insts. |
|
|
|
|
|
|
|
|
vmm_atomic_gen is extended from vmm_xactor, and has all the cool features of vmm_xactor. To be able to use a vmm_atomic_gen, following things are need at minimum. |
|
|
|
|
|
- vmm_data : Need to have perfect control of all the controlling variables to generate both normal and error traffic.
- instance : Create a instance of vmm_atomic_gen and set stop_after_n_insts
- start_sim: Call the start_xactor
|
|
|
|
|
|
Note :If you are new to VMM, constraint randomization, coverage convergence, Then I suggest stay away from atomic generators. It's so easy to mess things up :-) |
|
|
|
|
|
|
|
|
|
|
|
Example : vmm atomic generator
|
|
|
This is modified version of notify example |
|
|
|
|
|
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 [16];
10 rand bit [3:0] beats;
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 for (i = 0; i < 16; i ++) begin
19 this.data[1] = 0;
20 end
21 this.beats = 1;
22 endfunction
23 virtual function vmm_data copy(vmm_data to = null);
24 ahb_data cpy;
25 int i;
26 if (to == null) begin
27 cpy = new (log);
28 end else begin
29 if ( ! ($cast(cpy,to))) begin
30 `vmm_fatal(log,"Object is not of type ahb_data");
31 end
32 end
33 cpy.addr = this.addr;
34 for (i = 0; i < 16; i ++) begin
35 cpy.data[i] = this.data[1];
36 end
37 copy = cpy;
38 endfunction
39
40
41 // Print message
42 function void display(string prefix = "");
43 if (is_valid()) begin
44 `vmm_debug(log,$psprintf("%s",psdisplay(prefix)));
45 end else begin
46 `vmm_error(log,$psprintf("%s",psdisplay(prefix)));
47 end
48 endfunction
49
50 // Return the string members and their values
51 virtual function string psdisplay(string prefix = "");
52 string msg;
53 int i;
54 msg = $psprintf(" %s\n", prefix);
55 msg = $psprintf("%s ADDRESS : 32'h%x\n",msg,addr);
56 msg = $psprintf("%s BEATS : %0d\n",msg,beats);
57
58 for (i = 0; i < beats; i++) begin
59 msg = $psprintf("%s DATA[%2d] : 32'h%x\n",msg,i,data[i]);
60 end
61 psdisplay = msg;
62 endfunction
63 endclass
64
65 // We need to add below line to construct vmm_channel for object ahb_data
66 `vmm_channel(ahb_data)
67 `vmm_atomic_gen(ahb_data,"ATOMIC GEN")
68
69 // This class sinks transactions
70 class sink extends vmm_xactor;
71 ahb_data_channel fifo;
72 vmm_log log;
73
74 function new(vmm_log log, string name, ahb_data_channel fifo);
75 super.new(name,name);
76 this.log = log;
77 this.fifo = fifo;
78 endfunction
79
80 virtual task main();
81 ahb_data d;
82 super.main();
83 while (1) begin
84 wait_if_stopped_or_empty(fifo);
85 fifo.get(d);
86 // Indicate we are processing the object
87 d.notify.indicate(vmm_data::STARTED);
88 #10 ;
89 // Indicate we done with processing the object
90 $display("Indicating done processing");
91 d.notify.indicate(vmm_data::ENDED);
92 end
93 endtask
94 endclass
95
96 program test();
97 vmm_log log = new("test","ahb_data");
98 ahb_data_channel fifo = new ("CHANNEL","FIFO");
99 // Call new with pointer to channel
100 ahb_data_atomic_gen src = new("SOURCE",-1,fifo);
101 sink snk = new(log,"SINK",fifo);
102
103 initial begin
104 // Set number of transactions to generate
105 src.stop_after_n_insts = 2;
106 snk.start_xactor();
107 src.start_xactor();
108 // Wait for source to start
109 src.notify.wait_for(vmm_xactor::XACTOR_BUSY);
110 $display("Came out of SOURCE START");
111 // Wait for source to end
112 src.notify.wait_for(ahb_data_atomic_gen::DONE);
113 $display("Came out of SOURCE DONE");
114 #100 ;
115 end
116 endprogram
You could download file vmm_atomic_ex.sv here
|
|
|
|
|
|
Simulation Log : vmm atomic generator
|
|
|
|
|
|
Trace[INTERNAL] on ATOMIC GEN Atomic Generator(SOURCE) at 0:
Started
Debug[INTERNAL] on CHANNEL(FIFO) at 0:
New instance added to channel @-1 (level 1 of 1/0)
ADDRESS : 32'h1ff126c2
BEATS : 1
DATA[ 0] : 32'hf5ece2b5
Trace[INTERNAL] on SINK(SINK) at 0:
Started
Debug[INTERNAL] on CHANNEL(FIFO) at 0:
New instance removed from channel @0 (level 0 of 1/0)
ADDRESS : 32'h1ff126c2
BEATS : 1
DATA[ 0] : 32'hf5ece2b5
Came out of SOURCE START
Debug[INTERNAL] on CHANNEL(FIFO) at 0:
New instance added to channel @-1 (level 1 of 1/0)
ADDRESS : 32'h535836f8
BEATS : 1
DATA[ 0] : 32'h9746fa0b
Indicating done processing
Debug[INTERNAL] on CHANNEL(FIFO) at 10:
New instance removed from channel @0 (level 0 of 1/0)
ADDRESS : 32'h535836f8
BEATS : 1
DATA[ 0] : 32'h9746fa0b
Came out of SOURCE DONE
Indicating done processing
Trace[INTERNAL] on SINK(SINK) at 20:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|