story · 2020年05月18日

Systemverilog概念浅析之Callback

Systemverilog中的callback指定了一个被调用的callback method,和一个调用callback method的callback hook

callback method一般是dummy method,可以通过继承来覆盖。
518.1.bmp
在上面图中,temp()方法就是callback hook,callback\_1()和callback\_2()方法是callback method。在用戶调用temp()方法的时候,callback\_1()和 callback\_2()方法会自动调用,用戶也可以通过继承来覆盖callbackmethod。

在SV中最常用到的callback hook就是**randomize()**方法,它带有两个callback method:pre\_randomize()post\_randomize(),这两个方法分別在randomize()方法的前后执行.

Callback是在不改变验证组件(driver、monitor、generator)代码的条件下改变验证组件行为的一种机制。

可以用来

Inject errors
Put the transaction in the scoreboard
Gather functional coverage data

基类:

class transactor;
        virtual task pre_send();
        endtask
        virtual task post_send();
        endtask
        task send();
                this.pre_send();
                this.post_send();
        endtask : send
endclass : transactor

子类:

class my_transactor extend transactor;
        virtual task pre_send();
                ... //This function is implemented here
        endtask
        virtual task post_send();
                ... //This function is implemented here
        endtask
endclass : my_transactor

基类transactor具有3个task,其中2个被声明为virtual task且没有任何行为,然后被另一个task send调用。

virtual task pre\_send()和post\_send()称为callback taskes。

这样,我们可以通过更改继承自基类transactor的子类my\_ transactor中的callback taskes来更改transactor中task send的行为,而无需修改其代码。

本文转载自公众号:芯片数字实验室
原文链接:
https://mp.weixin.qq.com/s/V1IVl-k9WDtZeJwcKud31Q
未经作者同意,请勿转载!

推荐阅读

想了解更多内容,欢迎关注芯片数字实验室专栏
推荐阅读
关注数
12305
内容数
212
前瞻性的眼光,和持之以恒的学习~
目录
极术微信服务号
关注极术微信号
实时接收点赞提醒和评论通知
安谋科技学堂公众号
关注安谋科技学堂
实时获取安谋科技及 Arm 教学资源
安谋科技招聘公众号
关注安谋科技招聘
实时获取安谋科技中国职位信息