• systemverilog:interface中端口方向、Clocking block的理解


    (1)从testbench的角度看,tb中信号的输入输出方向与interface中信号输入输出方向一致
    (2)从DUT角度看,DUT中信号输入输出方向与interface中信号输入输出方向相反。简单图示如下

    代码示例如下:
     

    1. interface my_if(input bit clk);
    2. bit write;
    3. bit [15:0] data_in;
    4. bit [7:0] address;
    5. logic [15:0] data_out;
    6. clocking cb @ (negedge clk);
    7. default input #1ns output #2ns;
    8. output write;
    9. output data_in;
    10. output address;
    11. input data_out;
    12. endclocking
    13. modport master(clocking cb);
    14. modport slave(input write, data_in, address, output data_out);
    15. endinterface
    16. module master( clk,data_out , write ,data_in,address );
    17. input logic clk,write;
    18. output logic [7:0] data_out;
    19. input logic [7:0] data_in ,address;
    20. always @(negedge clk)
    21. if(write==0)
    22. data_out<=0;
    23. else if (write==1)
    24. data_out<=data_in;
    25. endmodule
    26. class BB;
    27. virtual my_if master_inst;
    28. function new(virtual interface my_if a);
    29. master_inst=a;
    30. endfunction
    31. task ass();
    32. master_inst.master.cb.write<=0;
    33. repeat(10) @(posedge master_inst.clk);
    34. master_inst.master.cb.data_in<='h12;
    35. repeat(10) @(posedge master_inst.clk);
    36. master_inst.master.cb.data_in<='h34;
    37. repeat(10) @(posedge master_inst.clk);
    38. master_inst.master.cb.data_in<='h45;
    39. master_inst.master.cb.write<=1;
    40. repeat(10) @(posedge master_inst.clk);
    41. master_inst.master.cb.data_in<='h56;
    42. repeat(10) @(posedge master_inst.clk);
    43. master_inst.master.cb.data_in<='h67;
    44. repeat(10) @(posedge master_inst.clk);
    45. master_inst.master.cb.data_in<='h52;
    46. repeat(10) @(posedge master_inst.clk);
    47. master_inst.master.cb.data_in<='h81;
    48. repeat(10) @(posedge master_inst.clk);
    49. master_inst.master.cb.data_in<='h05;
    50. endtask
    51. endclass
    52. module slaver(my_if.slave sif);
    53. initial begin
    54. sif.data_out <= 16'h0;
    55. #275 sif.data_out <= 16'h1;
    56. end
    57. endmodule
    58. module test;
    59. bit clk = 0;
    60. always #50 clk = ~clk;
    61. my_if regbus(clk);
    62. master m0(.clk(regbus.clk ), .address(regbus.address), .data_out(regbus.data_out), .data_in(regbus.data_in),.write(regbus.write));
    63. //slaver s0(regbus.slave);
    64. BB b_inst=new(regbus);
    65. initial begin
    66. #100 b_inst.ass();
    67. end
    68. endmodule

    注意:
    (1)当interface中有modport或者clocking块时,在testbench中可以直接定义interface的实例,可以将其直接传递到class中,然后在class中的task中可以通过点运算法逐层次的访问modport或者clocking中的信号。也可以通过点运算符直接在tb中实例化interface中的modport对象,然后传递到class中。
    (2)在class中的task中对clocking块中的信号赋值时,必须使用非阻塞赋值语句<=;
     

  • 相关阅读:
    Win10系统Charles/Fiddler抓包无反应处理
    基于Javaweb的流动市场地摊管理系统
    自定义mvc增删改查
    12-Go语言接口interface
    Metabase学习教程:仪表盘-5
    基于Amazon EC2和Amazon Systems Manager Session Manager的堡垒机设计和自动化实现
    mysql为什么会选错索引,以及优化器是如何选择索引的
    3D元宇宙虚拟主播引领文旅产业迈向更加美好的未来!
    vue 路由守卫实现权限控制
    [网络工程师]-应用层协议-SNMP
  • 原文地址:https://blog.csdn.net/qq_33300585/article/details/134447200