Constraint for AXI Strobe Signal
In the AXI protocol, the wstrb signal (write strobe) is used to indicate which bytes of the wdata signal (write data) are valid during a write transaction. The wstrb signal is a bitmask where each bit corresponds to a byte in the wdata signal, indicating whether the byte is valid (1) or should be ignored (0). The number of bits in the wstrb signal depends on the data width of the bus.
no. of strobe bits = no. of data bits / 8 ; for each byte of data 1bit of strobe needed
no of 1's in strobe = 2**awsize; the no. of bytes transferred is 2**awsize
The relationship between wstrb, wdata, and awsize (AXI write size) is as follows:
Here's an example to illustrate these concepts:
If awsize is 1, then for each beat:
For example, if wstrb is 4'b0011 , it means that bytes 0 and 1 of wdata are valid, and bytes 2 and 3 need to be ignored.
领英推荐
Check out the Below Executable code and let me know if you have any questions:
class axi_tx;
rand bit [ 1:0] awsize;
rand bit [ 3:0] wstrobe;
rand bit [31:0] wdata;
constraint awsize_c {
awsize <= 2; //as data is 4 bytes awsize <= 2
}
constraint wstrobe_c { //no. of 1's in wstrobe = 2**awsize
if(awsize == 0) $countones(wstrobe) == 1;
if(awsize == 1) $countones(wstrobe) == 2;
if(awsize == 2) $countones(wstrobe) == 4;
}
constraint wstrobe_c_1 { // to generate consecutive 1's
if(awsize == 1){
foreach(wstrobe[i]) {
if(i<3 && wstrobe[i] == 1) wstrobe[i+1] == 1;
}
}
}
constraint wdata_c { //data is not valid if wstrobe is 0
(wstrobe[0] == 0) -> (wdata[7:0] == 0);
(wstrobe[1] == 0) -> (wdata[15:8] == 0);
(wstrobe[2] == 0) -> (wdata[23:16] == 0);
(wstrobe[3] == 0) -> (wdata[31:24] == 0);
}
endclass
module top;
axi_tx tx=new();
initial begin
$display("###### OUTPUT ######");
for(int i=0 ; i< 6; i++) begin
assert(tx.randomize() with {awsize == i%3;});
$display("awsize = %0d no. of bytes = %0d",tx.awsize,2**tx.awsize);
$display("wdata = %h",tx.wdata);
$display("wstrobe = %b\n",tx.wstrobe);
end
$display("####### END #######");
end
endmodule
I appreciate your understanding of the methodology we've utilized to handle constraints and their real-world applications. Your support, through likes and reposts, will indeed encourage further exploration. I'm eagerly looking forward to engaging in meaningful discussions with you. Thank you! ????
Decoding of the above Code:
In Class
In Module Top
This program models an AXI (Advanced eXtensible Interface) transaction generator. It randomizes the "awsize", "wstrobe", and "wdata" signals based on the defined constraints and displays the generated values.
Design Verification Engineer @ Bitsilica
8 个月Can wstrobe_c not be written as $countones(wstrobe) == 2**awsize. Also we may have to include solve awsize before wstrobe. Is it possible?
Design Verification Engineer
8 个月"Data range updated! Thank you for pointing out the mistake. Let's continue exploring together. Your support means everything!" ??
Verification engineer
8 个月Thanks for the posting and constraint for the wdata value you have to change from 15:7 to 15:8