Constraint for AXI Strobe Signal

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:

  1. wstrb: The wstrb signal determines which bytes in the wdata signal are valid. For example, if the data width is 32 bits (awsize is set to 2), then wstrb is a 4-bit signal ([3:0]) where each bit corresponds to a byte in the 32-bit data word.
  2. wdata: The wdata signal contains the actual data to be written to memory. The value of wdata is only valid for the bytes indicated by wstrb.
  3. awsize: The awsize signal indicates the size of the data to be written. It determines the number of bytes in a single data beat. For example, if awsize is set to 2, each data beat is 32 bits (4 bytes). The wstrb signal should be set as 4'b1111 indicate which bytes in the wdata signal are valid for each beat if the wdata is of 32bits.

Here's an example to illustrate these concepts:

  • Let's say awsize is set to 1 (16 bits or 2 bytes per beat).
  • wdata is a 32-bit signal ([31:0]) containing the data to be written.
  • wstrb is a 4-bit signal ([3:0]) indicating which bytes in wdata are valid.

If awsize is 1, then for each beat:

  • wdata[31:0] contains the data for the beat.
  • wstrb[3:0] indicates which bytes in wdata[31:0] are valid.

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        
Output of the Above Code

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

  • Class Declaration: Declares a class named "axi_tx" containing three random variables:"awsize" is a 2-bit variable representing the size of the address bus."wstrobe" is a 4-bit variable representing the write strobe signal."wdata" is a 32-bit variable representing the data bus.
  • Constraints:awsize_c: Constrains "awsize" to be less than or equal to 2, as the address bus size is limited to 2 bits.wstrobe_c: Constrains the number of 1's in "wstrobe" to be equal to 2^awsize, ensuring that only the specified number of bytes are valid for write operations.wstrobe_c_1: Generates consecutive 1's in "wstrobe" if "awsize" is 1.wdata_c: Ensures that "wdata" is not valid (all zeros) if the corresponding bit in "wstrobe" is 0.

In Module Top

  • Instantiation of Class: Instantiates an object of the "axi_tx" class named "tx".
  • Initial Block:Displays a header indicating the beginning of the output.Loops 6 times:Randomizes the data members of the object "tx" with a constraint on "awsize" based on the loop index.Displays the value of "awsize" and the number of bytes based on the randomized "awsize".Displays the hexadecimal value of "wdata".Displays the binary value of "wstrobe".Displays a footer indicating the end of the output.

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.

arshiya sanglikar

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?

回复
mohamed irsath I

Design Verification Engineer

8 个月

"Data range updated! Thank you for pointing out the mistake. Let's continue exploring together. Your support means everything!" ??

回复
P ESWARA PRASAD

Verification engineer

8 个月

Thanks for the posting and constraint for the wdata value you have to change from 15:7 to 15:8

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了