hii everyone,
i want to assign adress for all the slaves from master but condition is that no address should repeat ,
means unique adress should be for each slave.
please provide me system verilog logic(code).
hii everyone,
i want to assign adress for all the slaves from master but condition is that no address should repeat ,
means unique adress should be for each slave.
please provide me system verilog logic(code).
In reply to raj@123:
class a;
parameter N = 10; //no of slaves
rand int unsigned add[N];
constraint unique_add { unique{add};}
// if needed end address take another array of same size and add parameter(no of bytes) to the add array and use start and end address
endclass
module tb;
a a1;
initial
begin
a1 = new;
a1.randomize;
$display("%p",a1.add);
end
endmodule
In reply to sasi_8985:
In reply to raj@123:
class a;
parameter N = 10; //no of slaves
rand int unsigned add[N];
constraint unique_add { unique{add};}
// if needed end address take another array of same size and add parameter(no of bytes) to the add array and use start and end address
endclass
module tb;
a a1;
initial
begin
a1 = new;
a1.randomize;
$display("%p",a1.add);
end
endmodule
what is the meaning of this line:- // if needed end address take another array of same size and add parameter(no of bytes) to the add array and use start and end address.
please explane
In reply to raj@123:
Don’t we have address ranges(i.e sizes) for each slave?
In reply to Desam:
class a;
parameter N = 10; //no of slaves
parameter width = 4;
int slaves_width[N];
rand int unsigned add[N],end_[N];
constraint unique_add { unique{add};}
constraint size { foreach(end_[i])
end_[i] == add[i] + this.slaves_width[i]; }
function void pre_randomize( int slaves_width[N] );
// this is to take width of slaves before
//hand
foreach(slaves_width[i])
this.slaves_width[i] = slaves_width[i];
endfunction
endclass
module tb;
a a1;
int aa[10] = '{10{4}};
initial
begin
a1 = new;
a1.pre_randomize(aa);
a1.randomize;
$display("%p *** %p",a1.add,a1.end_);
end
endmodule
BUT I am sure there is an other way which i am not aware of. lets wait and see.
In reply to sasi_8985:
In reply to Desam:
class a;
parameter N = 10; //no of slaves
parameter width = 4;
int slaves_width[N];
rand int unsigned add[N],end_[N];
constraint unique_add { unique{add};}
constraint size { foreach(end_[i])
end_[i] == add[i] + this.slaves_width[i]; }
function void pre_randomize( int slaves_width[N] );
// this is to take width of slaves before
//hand
foreach(slaves_width[i])
this.slaves_width[i] = slaves_width[i];
endfunction
endclass
module tb;
a a1;
int aa[10] = '{10{4}};
initial
begin
a1 = new;
a1.pre_randomize(aa);
a1.randomize;
$display("%p *** %p",a1.add,a1.end_);
end
endmodule
BUT I am sure there is an other way which i am not aware of. lets wait and see.
and one more thing i would like to generate 10 address according to my restriction means i have some restricted address list how to perfom this this.
for exaple i would like to generate 10 random slave slave address from 40 to 50
In reply to raj@123:
Plz look at code and hope it helps:
In reply to raj@123:
Here is an example for non-overlapping slave address. I assumed one slave is 1K in size and the 2nd slave is 2K is size. You can extrapolate and come up with more conditions if we have a 3rd slave but the idea should work. we solve slave1 before slave2 and so on to have a reference to work out the math for the other slave range. you can also use more constraints dep on what we are trying to accomplish. This ensures the non-overlapping part
// Code your testbench here
// or browse Examples
class packet;
int global_start=0;
int global_end=8192;
rand bit [12:0] S1,E1,S2,E2;
//assume slave1 size is 1K
constraint slave1 {
S1 >= 0;
S1 <= 7168;
E1 < 8192;
E1-S1 + 1 == 1024;
}
//solve slave1 range first to help having a reference for non-overlapping slave address
constraint solve1 {solve S1 before S2;}
constraint solve2 {solve E1 before E2;}
//assume slave2 size is 2k
constraint slave2{
S2 >= 0;
E2 < 8192;
E2-S2+1==2048;
if(8192-E1 < 2048)
E2 < S1;//as we don't have enough width for a slave2 range after E1 through 8192
E2 == S2 + 2047;
if(8192-E1 >2048)
S2 > E1;
S2 + 2048 < 8192;
}
endclass
module test;
initial begin
packet p1=new();
repeat(2) begin
if (p1.randomize()) begin
$display("S1 %0d is E1 is %0d",p1.S1,p1.E1);
$display("S2 %0d is E2 is %0d",p1.S2,p1.E2);
end
else $display("Randomization failed!");
end
end
endmodule