UVM产生异常激励的方法

news/2024/5/19 20:24:03 标签: systemverilog, 学习, UVM

UVM中,产生异常激励的方法(以白皮书中源码为例)

  1. 在my_transaction中添加一个crc_err的标志位这样,在post_randomize中计算CRC前先检查一下crc_err字段,如果为1,那么直接使用随机值,否则使用真实的CRC。
class my_transaction extends uvm_sequence_item;

   rand bit[47:0] dmac;//A 48-bit Ethernet destination address
   rand bit[47:0] smac;// a 48-bit Ethernet source address
   rand bit[15:0] ether_type;
   rand byte      pload[];//the size of the data 
   rand bit[31:0] crc;
   rand bit      crc_err;
   
   constraint pload_cons{pload.size >= 46; pload.size <= 1500;}
   
   function bit [31:0] calc_crc;
      return 32'h0;
   endfunction
   
    function void post_randomize();
       if (crc_err)
         ;//do nothing
       else
	     crc = calc_crc;
	endfunction
   
   `uvm_object_utils_begin(my_transaction)
      `uvm_field_int(dmac, UVM_ALL_ON)
	  `uvm_field_int(smac, UVM_ALL_ON)
	  `uvm_field_int(ether_type, UVM_ALL_ON)
	  `uvm_field_array_int(pload, UVM_ALL_ON)
	  `uvm_field_int(crc, UVM_ALL_ON)
	  `uvm_field_int(crc_err, UVM_ALL_ON | UVM_NOPACK)
	  `uvm_object_utils_end
	  
	  function new(string name = "my_transaction");
      super.new(name);
   endfunction
   
endclass

然后在sequence中使用如下方式产生异常激励

`uvm_do_with(tr, {tr.crc_err == 1;})
  1. 使用重载功能。
class my_transaction extends uvm_sequence_item;
…
 constraint crc_err_cons{
 crc_err == 1'b0;
 }
...
 endclass

如上:在测试正常用例时,约束错误标志位均为0,通过`uvm_do随机化

my_transaction tr;
`uvm_do(tr)

然后通过SystemVerilog中一个非常有用的特性是支持约束的重载。因此,依然使用第一种方式中my_transaction的定义,在其基础上派生一个新的transaction

class error_transaction extends my_transaction;
  `uvm_object_utils(error_transaction)
  function new(string name = "error_transaction");
    super.new(name);  
  endfunction
  constraint crc_error_cons{
    crc_error dist {0 := 1, 1 := 1};
  }
endclass

UVM中,可以使用uvm的factory机制实现重载。在test中实现覆盖,这种方法相比于sv的覆盖,会少写一个sequence,但是会多写一个error_test

class error_test extends uvm_test;
  ...
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    //覆盖原有transaction类型
    set_type_override_by_type(my_transaction::get_type(),error_transaction::get_type());
  endfunction
  //后者覆盖前者

http://www.niftyadmin.cn/n/1787973.html

相关文章

goroutine

一些例子 等待 goroutine 完成 在线示例 - 等待 goroutine 完成 // main.go package mainimport ("fmt""net/http""sync" )func main() {fmt.Println("start...")var urls []string{"https://www.baidu.com/","https:…

notepad++实现verilog代码的编译

介绍 在verilog学习中&#xff0c;我们想要检查代码的语法是否有误&#xff0c;一般需要在questasim或者其他的工程软件中进行编译仿真&#xff0c;大大降低了开发速度。对此&#xff0c;notepad编辑器中可以通过安装插件的方式&#xff0c;直接在notepad中实现编译&#xff0…

【sv中的继承与多态】

文章目录继承多态虚方法实现多态步骤继承 在验证的过程中&#xff0c;经常会有新的测试用例被添加进来&#xff0c;而且需要对原有的验证平台进行改进&#xff0c;特殊的测试用例经常会要求验证平台添加特定的功能。在过程化编程语言中&#xff0c;这要求修改原来的代码并且有…

Java并发编程 ReentrantLock是如何通过AbstractQueuedSynchronizer(AQS)来加锁解锁的

AQS简介 AQS是一个抽象的队列同步器&#xff0c;他为锁和一些同步组件如&#xff08;Semaphores,CountDownLatch&#xff09;提供了一个框架&#xff0c;AQS依赖于内部的一个FIFO的双向队列&#xff0c;同步器会将当前线程和其等待状态包装成一个Node添加到队列中&#xff0c; …

driver与monitor间的数据传输--UART

文章目录uart发送数据&#xff08;driver&#xff09;uart接受数据(monitor)uart发送数据&#xff08;driver&#xff09; CPU通过APB总线给uart写入数据&#xff0c;将数据保存在TX_FIFO中&#xff0c;然后通过uart_driver将并行数据串行的发送到总线上。注意&#xff1a;发送…

数据累加输出---verilog

文章目录介绍思路分析代码实现介绍 本题目来源为牛客网中在线编程>verilog模块&#xff0c;要求实现串行输入数据累加输出&#xff0c;输入端输入8bit数据&#xff0c;每当模块接收到4个输入数据后&#xff0c;输出端输出4个接收到数据的累加结果。输入端和输出端与上下游的…

Django连接MySQL出错

错误一&#xff1a;No module named MySQLdb 原因&#xff1a;python3连接MySQL不能再使用mysqldb&#xff0c;取而代之的是pymysql。 解决方法&#xff1a;在python的MySQL包中&#xff0c;即路径&#xff1a;C:\Users\adong\AppData\Local\Programs\Python\Python36\Lib\site…

24位数据转128位

实现24bit数据输入转换为128bit数据输出。其中&#xff0c;先到的数据应置于输出的高bit位。电路的接口如下图所示。valid_in用来指示数据输入data_in的有效性&#xff0c;valid_out用来指示数据输出data_out的有效性&#xff1b;clk是时钟信号&#xff1b;rst_n是异步复位信号…