128 lines
2.7 KiB
Systemverilog
128 lines
2.7 KiB
Systemverilog
|
class spi_trans;
|
||
|
|
||
|
//Properties for Randomizing the MOSI
|
||
|
rand bit cmd;
|
||
|
rand bit s;
|
||
|
rand bit[24:0] addr;
|
||
|
rand bit[ 4:0] op;
|
||
|
rand bit[31:0] data[];
|
||
|
|
||
|
//Properties for Randomizing the pkt_sent process
|
||
|
rand int interval;
|
||
|
rand int half_sclk;
|
||
|
|
||
|
|
||
|
constraint cstr {
|
||
|
(s==1'b0 && data.size()==1) || (s==1'b1 && data.size()==16);
|
||
|
interval <= 1000;
|
||
|
interval >= 0;
|
||
|
half_sclk <= 32;
|
||
|
half_sclk >= 4;
|
||
|
(addr >= 25'h000_0000 &&
|
||
|
addr <= 25'h000_0033 &&
|
||
|
s == 1'b0 ) ||
|
||
|
(addr >= 25'h010_0000 &&
|
||
|
addr <= 25'h010_001F &&
|
||
|
s == 1'b0 ) ||
|
||
|
(addr >= 25'h010_0040 &&
|
||
|
addr <= 25'h010_00A7 &&
|
||
|
s == 1'b0 ) ||
|
||
|
(addr >= 25'h010_0040 &&
|
||
|
addr <= 25'h010_0067 &&
|
||
|
s == 1'b1 ) ||
|
||
|
(addr >= 25'h020_0000 &&
|
||
|
addr <= 25'h020_001F &&
|
||
|
s == 1'b0 ) ||
|
||
|
(addr >= 25'h020_0098 &&
|
||
|
addr <= 25'h020_00A3 &&
|
||
|
s == 1'b0 ) ||
|
||
|
(addr >= 25'h020_0100 &&
|
||
|
addr <= 25'h020_0123 &&
|
||
|
s == 1'b0 ) ||
|
||
|
(addr >= 25'h020_0128 &&
|
||
|
addr <= 25'h020_014F &&
|
||
|
s == 1'b1 ) ||
|
||
|
(addr >= 25'h020_0128 &&
|
||
|
addr <= 25'h020_018F &&
|
||
|
s == 1'b0 );
|
||
|
(addr < 25'h000_0020) ||
|
||
|
(addr > 25'h000_0023) ||
|
||
|
(data[0] <= 500);
|
||
|
}
|
||
|
|
||
|
function new();
|
||
|
endfunction
|
||
|
|
||
|
extern function bit compare(spi_trans rhs_);
|
||
|
extern function void print();
|
||
|
extern function void unpack(ref bit stream[$]);
|
||
|
|
||
|
endclass : spi_trans
|
||
|
|
||
|
|
||
|
|
||
|
function bit spi_trans::compare(spi_trans rhs_);
|
||
|
bit result=1'b1;
|
||
|
int i=0;
|
||
|
|
||
|
result = ((this.cmd == rhs_.cmd) &&
|
||
|
(this.s == rhs_.s) &&
|
||
|
(this.addr == rhs_.addr) &&
|
||
|
(this.op == rhs_.op));
|
||
|
|
||
|
if(this.data.size() != rhs_.data.size()) begin
|
||
|
$display("data_sizes are different");
|
||
|
result = 1'b0;
|
||
|
end
|
||
|
else
|
||
|
for(i=0;i<this.data.size();i++)begin
|
||
|
if(this.data[i] != rhs_.data[i])
|
||
|
result = 1'b0;
|
||
|
end
|
||
|
|
||
|
return result;
|
||
|
endfunction : compare
|
||
|
|
||
|
|
||
|
function void spi_trans::print();
|
||
|
int i=0;
|
||
|
$display("cmd:",this.cmd);
|
||
|
$display("s:",this.s);
|
||
|
$display("addr:",this.addr);
|
||
|
$display("op:",this.op);
|
||
|
for(i=0;i<this.data.size();i++)begin
|
||
|
$display("data[%d]='h%h=%d",i,data[i],data[i]);
|
||
|
end
|
||
|
endfunction : print
|
||
|
|
||
|
|
||
|
function void spi_trans::unpack(ref bit stream[$]);
|
||
|
int i=0,j=0;
|
||
|
|
||
|
stream[0]=cmd;
|
||
|
|
||
|
stream[1]=s;
|
||
|
|
||
|
for(i=0;i<25;i++)
|
||
|
stream[i+2] = addr[24-i];//Q:If the addr is 1234, is "1" occurs firstly or "4" does?
|
||
|
|
||
|
for(i=0;i<5;i++)
|
||
|
stream[i+27]= op[4-i];
|
||
|
|
||
|
for(i=0;i<this.data.size();i++)begin
|
||
|
//$display("i=%2d,datai=%b",i,data[i]);
|
||
|
for(j=0;j<32;j++)begin
|
||
|
stream[32+i*32+j]=data[i][31-j];
|
||
|
//$display("i=%2d,j=%2d,streamij=%b",i,j,stream[32+i*32+j]);
|
||
|
end
|
||
|
end
|
||
|
|
||
|
endfunction
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|