Skip to content

Commit 3c81a62

Browse files
committed
Added axi randomization
1 parent 697de8f commit 3c81a62

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package axi_transaction;
2+
3+
parameter adr_width = 32;
4+
parameter data_width = 32;
5+
parameter max_size = 128;
6+
parameter max_len = 256;
7+
parameter size_width = $clog2 (max_size);
8+
parameter len_width = $clog2 (max_len);
9+
10+
typedef logic [adr_width - 1:0] adr_t;
11+
typedef logic [data_width - 1:0] data_t;
12+
typedef logic [size_width - 1:0] size_t;
13+
typedef logic [len_width - 1:0] len_t;
14+
15+
typedef enum { read, write } op_t;
16+
typedef enum { fixed, incr, wrap } burst_t;
17+
18+
class axi_transaction;
19+
20+
rand op_t op;
21+
rand adr_t adr;
22+
rand size_t size;
23+
rand len_t len;
24+
rand burst_t burst;
25+
rand data_t data [];
26+
27+
constraint size_c
28+
{
29+
size inside { 1, 2, 4, 8 /* , 16, 32, 64, 128 */ };
30+
size <= data_width / 8;
31+
}
32+
33+
constraint len_c
34+
{
35+
len == data.size;
36+
len > 0 && len <= max_len;
37+
}
38+
39+
// AXI has the following rules governing the use of bursts:
40+
// * for wrapping bursts, the burst length must be 2, 4, 8, or 16
41+
// * a burst must not cross a 4KB address boundary
42+
43+
constraint burst_c
44+
{
45+
burst == wrap
46+
-> len inside { 2, 4, 8, 16 };
47+
}
48+
49+
constraint adr_c
50+
{
51+
adr % size == 0;
52+
53+
if (burst == incr)
54+
adr / 4096 == (adr + len - 1) / 4096;
55+
}
56+
57+
constraint adr_distr_c
58+
{
59+
adr dist
60+
{
61+
[ 0 : 1 ] := 25,
62+
[ 32'hffff0000 : 32'hffffffff ] :/ 25,
63+
[ 2 : 32'hfffeffff ] :/ 25
64+
};
65+
}
66+
67+
function string str ();
68+
69+
string s;
70+
71+
$sformat (s, "%s adr='h%0h size=%0d len=%0d burst=%s",
72+
op.name, adr, size, len, burst.name);
73+
74+
for (int i = 0; i < data.size (); i++)
75+
s = { s, $sformatf (" 'h%h", data [i]) };
76+
77+
return s;
78+
79+
endfunction
80+
81+
endclass
82+
83+
endpackage

Diff for: updates_from_emails/2021_05_06_axi/testbench.sv

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import axi_transaction::*;
2+
3+
class my_axi_transaction extends axi_transaction;
4+
5+
constraint adr_distr_c
6+
{
7+
adr dist
8+
{
9+
[ 0 : 16 ] :/ 50,
10+
[ 4000 : 4100 ] :/ 50
11+
};
12+
}
13+
14+
constraint mine_c
15+
{
16+
len <= 6;
17+
}
18+
19+
endclass
20+
21+
module tb;
22+
23+
my_axi_transaction tr = new;
24+
25+
initial
26+
begin
27+
repeat (10)
28+
begin
29+
assert (tr.randomize ());
30+
$display ("random: %s", tr.str ());
31+
end
32+
33+
repeat (10)
34+
begin
35+
assert (tr.randomize () with
36+
{
37+
burst == wrap;
38+
});
39+
40+
$display ("wrap: %s", tr.str ());
41+
end
42+
43+
repeat (10)
44+
begin
45+
assert (tr.randomize () with
46+
{
47+
len inside { 3, 5 };
48+
});
49+
50+
$display ("len is either 3 or 5: %s", tr.str ());
51+
end
52+
53+
repeat (10)
54+
begin
55+
assert (tr.randomize () with
56+
{
57+
adr inside { [ 4094 : 4096 ] };
58+
len > 1;
59+
});
60+
61+
$display ("adr inside 4094..4096, len > 1: %s", tr.str ());
62+
end
63+
64+
$display ("Ramdomization failure:");
65+
66+
assert (tr.randomize () with
67+
{
68+
size inside { 3, 5 };
69+
});
70+
71+
$display ("size is either 3 or 5: %s", tr.str ());
72+
73+
$finish;
74+
end
75+
76+
endmodule

0 commit comments

Comments
 (0)