• systemverilog:interface中的modport用法


            使用modport可以将interface中的信号分组并指定方向,方向是从modport连接的模块看过来的。简单示例如下:

    1. interface cnt_if (input bit clk);
    2. logic rstn;
    3. logic load_en;
    4. logic [3:0] load;
    5. logic [7:0] count;
    6. modport TEST (input clk, count,
    7. output rstn,load_en,load);
    8. modport DUT (input clk,rstn,load_en,load,
    9. output count);
    10. endinterface
    11. module Design(clk,rstn,load_en,load,count );
    12. input clk,rstn,load_en,load;
    13. output reg [7:0] count;
    14. always @(posedge clk or negedge rstn)
    15. if(!rstn)
    16. count<=0;
    17. else
    18. count<=count+1;
    19. endmodule
    20. class AA;
    21. virtual cnt_if.DUT this_s;
    22. function new(virtual cnt_if.DUT if_inst);
    23. this_s=if_inst;
    24. endfunction
    25. task assig();
    26. this_s.rstn=0;
    27. repeat(100) @(posedge this_s.clk);
    28. this_s.rstn=1;
    29. this_s.load_en=0; this_s.load=1; this_s.count='d56;
    30. repeat(100) @(posedge this_s.clk);
    31. this_s.rstn=0; this_s.load_en=1; this_s.load=0; this_s.count='d34;
    32. endtask
    33. endclass
    34. module tb;
    35. logic clk;
    36. initial begin clk=0; end
    37. always #5 clk=~clk;
    38. //cnt_if.DUT if_instance (clk);
    39. cnt_if if_instance (clk);
    40. AA ainstance=new(if_instance.DUT);
    41. //Design(clk,rstn,load_en,load,count );
    42. Design design_inst(.clk(if_instance.DUT.clk), .rstn(if_instance.DUT.rstn) ,.load_en(if_instance.DUT.load_en ), .load(if_instance.DUT.load) ,.count(if_instance.DUT.count) );
    43. initial
    44. begin
    45. ainstance.assig;
    46. end
    47. endmodule

    注意:
    (1)在interface中使用modport将信号分组后,在tb中例化时,直接例化interface的实例,不能例化interface中modport的实例;
    (2)在calss中直接例化interface中modport的实例;
    (3)在tb中实例化interface的实例后,将interface的实例的modport通过点运算符传递给DUT。

    仿真波形如下:

  • 相关阅读:
    人工智能轨道交通行业周刊-第23期(2022.11.14-11.20)
    对MMVAE中IWAE代码实现的理解
    CVE-2023-25194 Kafka JNDI 注入分析
    一文读懂:AWS 网络对等互连(VPC peering)实用操作指南
    Flask——接口路由技术
    【安卓基础2】简单控件
    Flask数据库_filter过滤器的使用
    IDEA 数据库插件Database Navigator 插件
    用C++标准库生成制定范围内的整数随机数
    【学习笔记】线性基
  • 原文地址:https://blog.csdn.net/qq_33300585/article/details/134430014