SV工程杂记

1、创建多个并行的线程:参考绿皮书P186 例子7.11

在sv里面,会先执行循环体(父进程),再将循环体里面的子进程展开后再启动并行执行。fork操作会把每一个子进程添加到一个进程管理器中,但是不会对其立即执行。当父进程结束了循环体或挂起后,进程管理器才会执行其列表中的子进程。(参考:《system verilog与功能验证》P72)


2、assert(XX.randomize() with {AA >= 100;} ); 绿皮书 P151 // AA声明前面必须有rand或randc,不然不能把约束加进来;

3,随机一个变量:

void’(std::randomize(your_var) with   {  your_var  dist {0:/10,[1:100]:/10,999:/10 }

                                                                           your_var[3:0] == 0         } );

4、伴随线程(随便取的名)

fork
    while(1) begin  进行检查什么的 end
    while(1) begin  搜索结束条件什么的 end
join_any

$sscanf系统函数

 $sccanf的三个参数,第一个是扫描对象,第二个是扫描格式,第三个是提取出来的参数。它是具有返回值的,如果扫描不成功则返回0,如果扫描成功,每提取一个数据(即args的个数),则返回值加1。提取不会改变str值,除非将str作为args。

Some examples of sscanf:

  • This call to sscanf will return 1, and the variable a will be given the value "oo":

    sscanf("foo", "f%s", a);
  • The return value from sscanf will be 2. a will be given the value 4711. b will be given the value "bar".

    sscanf("4711bar", "%d%s", a, b);
  • The return value from sscanf will be 1, a will be given the value "test":

    sscanf(" \t test", "%*[ \t]%s", a)
  • This removes "the " from the beginning of the string in str. If str does not begin with "the ", it will not be changed

    sscanf(str, "the %s", str);
  • This assigns "foo" to s1 and "fum" to s2, and the array ({ ({ 1 }), ({ 2 }), ({ 3 }) }) to a. The return value will be 3.

    sscanf("foo % 1 2 3 fum",
           "%s %% %{%d%} %s", s1, a, s2);

A feature with sscanf is that you can define variables inside it:

sscanf("foo % 1 2 3 fum",
       "%s %% %{%d%} %s",
       string s1, array(string) a, string s2);

参考: https://docs.roxen.com/pike/7.0/tutorial/strings/sscanf.xml

Systemverilog : $sscanf系统函数-CSDN博客


动态数组作为方法的参数:

function    mem_read(input int  addr ,len,output  bit[31:0]  rdata)

    rdata = new[len];
    //read data from mem

endfunction

defparam

起作用的时间: defparam是 Verilog 中的一种参数传递机制,用于在模块实例化时重写参数值。当一个模块引用另外一个模块时,高层模块可以使用defparam改变低层模块用parameter定义的参数值(层次化路径)。defparam起作用的时间是在模块实例化时,它会将指定的参数值传递给被实例化的模块,从而改变模块的行为。

图片参考:Verilog 中 defparam localparam parameter 的语法说明,以及ALTDDIO IP应用_sv deparam localparam-CSDN博客


defparam: 重载参数

  • parameter 是一个模块中,常量的声明,可进行参数传递和重定义
  • defparam 是对已经声明的模块常量,在例化的时候对这个常量的数值进行修改
  • localparam 是模块内有效的定义,是局部变量,不可用于参数传递,也不能被重定义

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值