systemverilog中的bind

本文介绍了SystemVerilog中的bind功能,包括其两种语法形式,以及如何通过bind在设计中分离代码和断言。bind有助于模块间的便捷移植和复用,特别是对于ram/rom初始化提供了便利。
摘要由CSDN通过智能技术生成


前言

通常我们需要将设计的代码和验证的代码进行分离,systemverilog中提供bind的方式,能够在不改变设计代码的前提下,在设计的代码的module或者instance下边,例化一些用于存放断言等辅助代码的module/interface/program/checker。


一、bind的语法和用法

bind支持两种语法:
语法一:

bind bind_target_instance bind_instantiation ;
#bind_target_instance ::= hierarchical_identifier constant_bit_select

hierarchical_identifier:是RTL中被绑定的层次结构,
constant_bit_select:是需要绑定的module/interface/program/checker名字;
bind_instantiation:是例化后的module/interface/program/checker名字。

示例代码如下,将cpu_sv的interface,例化取名为u_cpu_sv,并绑定到tb.dut.u_cpu的层次结构下,这个时候,在u_cpu下边就可以看到u_cpu_sv这个例化后的interface。
同时,通过tb.dut.u_cpu.u_cpu_sv.ram_loder(),可以调用interface内部的task。

interface bin_loader_if_ram#(
  parameter DATAWIDTH=32,
  parameter MEMDEPTH=1024,
  parameter ROW_NUM=1
);
    reg [DATAWIDTH-1:0]   data_array[$];
    
	task ram_loder(string ram_image = "");
	    if($value$plusargs("ram_image=%s", ram_image)) begin
	        $display("set ram_image to %s", ram_image);
	    end
	    else begin
	        $display("ERROR, ram_image is not specified");
	        $finish;
	    end
	    fd = $fopen(ram_image,"rb");
        data_array.delete();
        for(i = 0; (i < MEMDEPTH) && ($fread(data,fd) != 0); i = i + 1) begin
            data_array.push_back(red_data);
        end
        $display("Read %H words into memory", data_array.size());
        $fclose(fd);
    end
	endtask : ram_loder
	...
endinterface : cpu_sv

module top
bind tb.dut.u_cpu cpu_sv u_cpu_sv();

initial begin
    tb.dut.u_cpu_sv.ram_loder();
end
endmodule

语法二:

bind bind_target_scope [: bind_target_instance_list] bind_instantiation ;
#bind_target_instance_list ::= bind_target_instance { , bind_target_instance }

bind_target_scope:是模块名或者接口名;
bind_target_instance_list:存放的是需要绑定的例化名;
bind_instantiation:是例化后的module/interface/program/checker名字。

示例代码1:

bind cpu cpu_sv u_cpu_sv();

这里用的是模块名,在所有cpu模块例化后的instance下,都会去bind一个cpu_sv,例化后的名字为u_cpu_sv。

示例代码2:

bind cpu: cpu1 cpu_sv u_cpu_sv();

这里用的是例化名,cpu模块例化名为cpu1的里边会去bind一个cpu_sv,命名为u_cpu_sv。

示例代码3:

bind cpu: cpu1, cpu2, cpu3 cpu_sv u_cpu_sv();

这里用的是例化名,cpu模块例化名为cpu1/cpu2/cpu3的里边会去bind一个cpu_sv,命名为u_cpu_sv。

二、bind的好处

利用bind做的ram/rom后门初始化,可以非常方便的在sub-system/soc之间相互移植。

在移植的时候,只需要修改bind指定的路径,然后根据路径调用bind内定义的方法即可,这样实现开发的组件很大程度被复用。


总结

本文主要总结和记录一下bind的用法。

  • 10
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
There are some simple tricks that every design engineer should know to facilitate the usage of SystemVerilog Assertions. Although this paper is not intended to be a comprehensive tutorial on SystemVerilog Assertions, it is worthwhile to give a simplified definition of a property and the concurrent assertion of a property. 1.1 What is an assertion? An assertion is basically a "statement of fact" or "claim of truth" made about a design by a design or verification engineer. An engineer will assert or "claim" that certain conditions are always true or never true about a design. If that claim can ever be proven false, then the assertion fails (the "claim" was false). Assertions essentially become active design comments, and one important methodology treats them exactly like active design comments. More on this in Section 2. A trusted colleague and formal analysis expert[1] reports that for formal analysis, describing what should never happen using "not sequence" assertions is even more important than using assertions to describe always true conditions. 1.2 What is a property? A property is basically a rule that will be asserted (enabled) to passively test a design. The property can be a simple Boolean test regarding conditions that should always hold true about the design, or it can be a sampled sequence of signals that should follow a legal and prescribed protocol. For formal analysis, a property describes the environment of the block under verification, i.e. what is legal behavior of the inputs. 1.3 Two types of SystemVerilog assertions SystemVerilog has two types of assertions: (1) Immediate assertions (2) Concurrent assertions Immediate assertions execute once and are placed inline with the code. Immediate assertions are not exceptionally useful except in a few places, which are detailed in Section 3.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值