码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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。

    仿真波形如下:

  • 相关阅读:
    究极异常处理逻辑——多层次异常的处理顺序
    java计算机毕业设计Vue框架电商后台管理系统MyBatis+系统+LW文档+源码+调试部署
    idea安装MyBatisX插件
    SpringBoot+Vue项目餐饮管理系统
    使用SpringBatch读取csv文件
    git submodule 子模块的基本使用
    【技能树笔记】网络篇——练习题解析(七)
    UE4 C++:UFUNCTION宏、函数说明符、元数据说明符
    Gotchiverse NFT 游戏公会访谈——8bit Gamers 公会
    基于Matlab实现蚁群算法求解TSP问题(附上源码+数据)
  • 原文地址:https://blog.csdn.net/qq_33300585/article/details/134430014
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号