日常记录(33)虚接口

虚接口

没有虚接口,那interface无法接入到class中。

interface SBus ();
    // nets
    logic req, grant;
    logic [7:0] addr, data;

endinterface : SBus

class SBusTrans;
    // data or class properties
    virtual SBus bus;

    function new(virtual SBus s);
        bus=s;
    endfunction : new

    task request();
        bus.req=1;
    endtask: request

    task wait_for_bus();
        @(posedge bus.grant);
    endtask: wait_for_bus
endclass : SBusTrans

module devA (SBus s);
    initial begin
        int handler=$fopen("devA.log");
        $fmonitor(handler, "A req, grant %d, %d", s.req, s.grant);
    end
endmodule

module devB (SBus s);
    initial begin
        int handler=$fopen("devB.log");
        $fmonitor(handler, "B req, grant %d, %d", s.req, s.grant);
    end
endmodule

module top ();
    SBus s[1:4]();
    devA a1(s[1]);
    devB a2(s[2]);
    initial begin
        SBusTrans t[2];
        t[0]=new(s[1]);
        t[1]=new(s[2]);

        #5 t[0].request;
        #5 t[1].request;
    end

endmodule

  

输出

cat dev*
A req, grant x, x
A req, grant 1, x
B req, grant x, x
B req, grant 1, x

  

 

目标:

1.读懂代码,

2.编写程序

3.调试代码

 

黑盒测试:激励生成后,同时灌入DUT和参考模型,对比输出。

灰盒测试:在黑盒的基础上,不仅有参考模型,同时添加断言和监控在DUT内,结果比较

白盒测试:在DUT内部或外部添加监控和断言,结果比较。

 

验证要考虑的要素:

1.完备性:制定方案最大限度的验证被测设计。

2.可重用性:不同场合下验证环境架构的的兼容性。

3.可靠性:采用自动化工具完成系列操作。减少手动操作。

4.效率:给定时间内的验证工作投入产出最大化

5.性能:验证程序的效率

  

强制转换

枚举,转换前有一个'.

module taa ();
    typedef enum {R, G, B} colors;
    colors c;
    initial begin
        c=G;
        c=colors'(2);
        $display("color is %s", c);
    end
endmodule

  

类型判定、ref与input、默认参数、默认赋值

\$typename进行参数类型判定然后通过=进行数据传递,然后在function里的第二个参数前,加了input防止变成ref类型报错。

default可以添加默认的数据,但是被判断不能混合赋值,这里进行了分两步的方式赋值。

完全不指定方向,function中默认第一个为input类型,完全不指定类型,默认为logic类型。

module taa ();
    function void calc(ref int a[], input int length=a.size-1);
         int sum=0;
         for (int i = 0; i <length+1; i++) begin
             sum+=a[i];
         end
         $display("the sum value of it is %d", sum);
    endfunction: calc

    initial begin
        int aa[10]={default:1};
        int bb[];
        aa[0:3]={1,2,3,4};
        bb = aa;
        $display("typename %s", $typename(aa));
        $display("typename %s", $typename(bb));
        calc(bb);
    end
endmodule

  

输出

typename int$[0:9]
typename int$[]
the sum value of it is          16

  

Fork-Join的展开化

注意automatic的位置

module tbb ();
initial begin
    automatic int i;
    for (int i = 0; i < 10; i++) begin
        fork
            $display("i is %d", i);
        join_none
    end
    $display("start...");

    for (i = 0; i < 10; i++) begin
        fork
            $display("automatic i is %d", i);
        join_none
    end

    for (i = 0; i < 10; i++) begin
        fork
            automatic int j=i;
            $display("replace i is %d", j);
        join_none
    end
end
endmodule

  

输出

start...
i is          10
i is          10
i is          10
i is          10
i is          10
i is          10
i is          10
i is          10
i is          10
i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
automatic i is          10
replace i is           0
replace i is           1
replace i is           2
replace i is           3
replace i is           4
replace i is           5
replace i is           6
replace i is           7
replace i is           8
replace i is           9

  

参数化信箱

参数化信箱内容为string

module tcc ();
    typedef mailbox #(string) box2;
    box2 ma2=new;
    string s;
    initial begin
        ma2.put("hello");
        ma2.put(123);

        ma2.get(s);
        $display("get : %s ",s);
        // error: mismatching
        /* ma2.get(s); */
        /* $display("get : %s ",s); */
    end
endmodule

  

输出

get : hello 

  

posted @ 2022-01-07 15:29  大浪淘沙、  阅读(59)  评论(0编辑  收藏  举报