|
|
1 function new(vmm_log log);
2 function vmm_log set_log(vmm_log log);
3 function void display(string prefix = "");
4 virtual function string psdisplay(string prefix = "");
5 virtual function bit is_valid(bit silent = 1, int kind = -1);
6 virtual function vmm_data allocate();
7 virtual function vmm_data copy(vmm_data to = null);
8 virtual protected function void copy_data(vmm_data to);
9 virtual function bit compare( vmm_data to, output string diff,
10 input int kind = -1);
11 virtual function int unsigned byte_size(int kind = -1);
12 virtual function int unsigned max_byte_size(int kind = -1);
13 virtual function int unsigned byte_pack(ref logic [7:0]bytes[],
14 input int unsigned offset = 0, input int kind = -1);
15 virtual function int unsigned byte_unpack(const ref logic [7:0] bytes[],
16 input int unsigned offset = 0, input int len= -1, input int kind = -1);
17 virtual function bit load(int file);
18 virtual function void save(int file);
You could download file vmm_data_methods.sv here
|
|
|
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 // You should use enum, when needed
8 typedef enum {OKAY,ERROR,RETRY,SPLIT} rsp_t;
9 typedef enum {IDLE,BUSY,NONSEQ,SEQ} tnr_t;
10 typedef enum {WRITE,READ} cmd_t;
11 typedef enum {SINGLE,INCR,WRAP4,INCR4,WRAP8,
12 INCR8,WRAP16,INCR16} burst_t;
13
14 // Declare all the fields
15 rand bit [31:0] addr;
16 rand bit [31:0] data [16];
17 rand bit [3:0] beats;
18 rand tnr_t transfer;
19 rand rsp_t response;
20 rand cmd_t cmd;
21 rand burst_t burst;
22
23 // Make sure all variables have init value
24 function new(vmm_log log);
25 int i;
26 super.new(log);
27 this.log = log;
28 this.addr = 0;
29 for (i = 0; i < 16; i ++) begin
30 this.data[1] = 0;
31 end
32 this.beats = 0;
33 this.transfer = IDLE;
34 this.response = OKAY;
35 this.cmd = WRITE;
36 this.burst = SINGLE;
37 endfunction
38
39 // Print message
40 function void display(string prefix = "");
41 if (is_valid()) begin
42 `vmm_debug(log,$psprintf("%s",psdisplay(prefix)));
43 end else begin
44 `vmm_error(log,$psprintf("%s",psdisplay(prefix)));
45 end
46 endfunction
47
48 // Return the string members and their values
49 virtual function string psdisplay(string prefix = "");
50 string msg;
51 int i;
52 msg = $psprintf(" %s\n", prefix);
53 msg = $psprintf("%s ADDRESS : 32'h%x\n",msg,addr);
54 msg = $psprintf("%s COMMAND : %s\n",msg,cmd.name());
55 msg = $psprintf("%s TRANSFER : %s\n",msg,transfer.name());
56 msg = $psprintf("%s RESPONSE : %s\n",msg,response.name());
57 msg = $psprintf("%s BEATS : %0d\n",msg,beats);
58 msg = $psprintf("%s BURST : %s\n",msg,burst.name());
59
60 for (i = 0; i < beats; i++) begin
61 msg = $psprintf("%s DATA[%2d] : 32'h%x\n",msg,i,data[i]);
62 end
63 psdisplay = msg;
64 endfunction
65
66 virtual function bit is_valid(bit silent = 1, int kind = -1);
67 is_valid = (response ! = ERROR);
68 endfunction
69
70 virtual function vmm_data copy(vmm_data to = null);
71 ahb_data cpy;
72 int i;
73 if (to == null) begin
74 cpy = new (log);
75 end else begin
76 if ( ! ($cast(cpy,to))) begin
77 `vmm_fatal(log,"Object is not of type ahb_data");
78 end
79 end
80 cpy.addr = this.addr;
81 for (i = 0; i < 16; i ++) begin
82 cpy.data[i] = this.data[1];
83 end
84 cpy.beats = this.beats ;
85 cpy.transfer = this.transfer ;
86 cpy.response = this.response ;
87 cpy.cmd = this.cmd ;
88 cpy.burst = this.burst ;
89 copy = cpy;
90 endfunction
91
92 virtual function bit compare( vmm_data to, output string diff,
93 input int kind = -1);
94 int cmp = 1;
95 ahb_data cp;
96 if (to == null) begin
97 `vmm_error(log,"Passed pointer to copy method is null");
98 return 0;
99 end else begin
100 if ( ! ($cast(cp,to))) begin
101 `vmm_fatal(log,"Object is not of type ahb_data");
102 end
103 end
104 if (addr ! = cp.addr) begin
105 diff = $psprintf("Expected 32'h%x Got 32'h%x",addr, cp.addr);
106 return 0;
107 end
108 if (beats ! = cp.beats) begin
109 diff = $psprintf("Expected 32'h%x Got 32'h%x",beats, cp.beats);
110 return 0;
111 end
112 // You can add reset of the code here
113 compare = cmp;
114 endfunction
115
116 endclass
117
118 program test();
119 vmm_log log = new("vmm_log_test","ahb_data");
120 ahb_data mdata = new (log);
121 initial begin
122 if (mdata.randomize() == 0) begin
123 end else begin
124 mdata.display("PROGRAM");
125 end
126 #10 ;
127 end
128 endprogram
You could download file vmm_data_ex.sv here
|