SystemVerilog Mailbox

前言:mailboxe是一种通信机制,允许进程之间交换消息。希望与另一个进程通信的进程将消息发送到mailboxe,mailboxe将消息临时存储在系统定义的内存对象中,以便将消息传递给所需的进程。根据大小,mailboxe被分类为:

  • bounded mailbox
  • unbounded mailbox
  1. A bounded mailbox is with the size defined. mailbox becomes full when on storing a bounded number of messages. A process that attempts to place a message into a full mailbox shall be suspended until enough space becomes available in the mailbox queue.
  2. Unbounded mailboxes are with unlimited size.

一、Mailbox types

There are two types of mailboxes,

  • Generic Mailbox
  • Parameterized mailbox

1.1 Generic Mailbox (type-less mailbox)

  • The default mailbox is type-less. that is, a single mailbox can send and receive data of any type.
mailbox mailbox_name;
  • Parameterized mailbox (mailbox with particular type)
  • Parameterized mailbox is used to transfer a data of particular type.
mailbox#(type) mailbox_name;

 1.2 Mailbox Methods

  • SystemVerilog Mailbox is a built-in class that provides the following methods. these are applicable for both Generic and Parameterized mailboxes
        No.                                   Method                                                Description
1 new() Creat a mailbox
2 put() Place a message in a mailbox
3 try_put() Try to place a message in a mailbox without blocking
4 get() / peek() Retrieve a message from a mailbox
5 num() Returns the number of messages in the mailbox
6 try_get() / try_peek() Try to retrieve a message from a mailbox without blocking
  • new( );

Mailboxes are created with the new() method.

mailbox_name = new();        // Creates unbounded mailbox and returns mailbox handlemailbox_name = new(m_size);  //Creates bounded mailbox with size m_size and returns mailbox
//handle ,where m_size is integer  variable

1.3 SystemVerilog Mailbox example

In the example below,Mailbox is used for communication between generator and driver.

  • Process-1(Generator class) will generate (created and randomize) the packet and put into the mailbox mb_box
  • Process-2(Driver class) gets the generated packet from the mailbox and display the fields
//-------------------------------------------------------------------------
// Packet
//-------------------------------------------------------------------------
class packet;rand bit [7:0] addr;rand bit [7:0] data;//Displaying randomized valuesfunction void post_randomize();$display("Packet::Packet Generated");$display("Packet::Addr=%0d,Data=%0d",addr,data);endfunction
endclass//-------------------------------------------------------------------------
//Generator - Generates the transaction packet and send to driver
//-------------------------------------------------------------------------
class generator;packet pkt;mailbox m_box;//constructor, getting mailbox handlefunction new(mailbox m_box);this.m_box = m_box;endfunctiontask run;repeat(2) beginpkt = new();pkt.randomize(); //generating packetm_box.put(pkt);  //putting packet into mailbox$display("Generator::Packet Put into Mailbox");#5;endendtask
endclass//-------------------------------------------------------------------------
// Driver - Gets the packet from generator and display's the packet items
//-------------------------------------------------------------------------
class driver;packet pkt;mailbox m_box;//constructor, getting mailbox handlefunction new(mailbox m_box);this.m_box = m_box;endfunctiontask run;repeat(2) beginm_box.get(pkt); //getting packet from mailbox$display("Driver::Packet Recived");$display("Driver::Addr=%0d,Data=%0d\n",pkt.addr,pkt.data);endendtask
endclass//-------------------------------------------------------------------------
//     tbench_top
//-------------------------------------------------------------------------
module mailbox_ex;generator gen;driver    dri;mailbox m_box; //declaring mailbox m_boxinitial begin//Creating the mailbox, Passing the same handle to generator and driver, //because same mailbox should be shared in-order to communicate.m_box = new(); //creating mailboxgen = new(m_box); //creating generator and passing mailbox handledri = new(m_box); //creating driver and passing mailbox handle$display("------------------------------------------");forkgen.run(); //Process-1dri.run(); //Process-2join$display("------------------------------------------");end
endmodule
  •  Simulator Output 
------------------------------------------
Packet::Packet Generated
Packet::Addr=3,Data=38
Generator::Packet Put into Mailbox
Driver::Packet Recived
Driver::Addr=3,Data=38Packet::Packet Generated
Packet::Addr=118,Data=92
Generator::Packet Put into Mailbox
Driver::Packet Recived
Driver::Addr=118,Data=92------------------------------------------

[SV]SystemVerilog Mailbox相关推荐

  1. [SV]SystemVerilog Constraints(1)

    SystemVerilog Constraints(1) 一.Soft Constraints SystemVerilog constraints declared with the keyword ...

  2. [SV]SystemVerilog学习笔记之struct union

    SystemVerilog学习笔记(四) 一.结构体(struct) 1.1.结构体声明(struct) 结构体声明:结构体默认是变量,也可以声明为线网 var struct { // 通过var进行 ...

  3. [SV]SystemVerilog 断言(SVA)检查器库(OVL)

    SystemVerilog 断言(SVA)检查器库(OVL) 前言:SystemVerilog 断言(SVA)检查器库由如下两部分组成: 由检查器组成的SystemVerilog验证库(SVL),这些 ...

  4. [SV]SystemVerilog压缩数组(Packed Array)和非压缩数组( Unpacked Array)

    SystemVerilog压缩数组和非压缩数组 The term packed array is used to refer to the dimensions declared before the ...

  5. [SV]SystemVerilog進程之fork join专题详解及案例分析

                SystemVerilog進程之fork...join专题详解及案例分析  目錄 一.fork-join 1.1.fork join example, 二.fork-join_ ...

  6. [SV]SystemVerilog中指定打印格式

    SystemVerilog中指定打印格式 前言:本文主要总结一下SystemVerilog中的占位符,通过合理的使用占位符,可以再log中按自己指定的格式打印信息,方便case分析及debug. 一. ...

  7. [SV]SystemVerilog中forever begin end導致的Hang死

    SystemVerilog中forever begin end導致的Hang死 一.當if條件不成立的時候,肯定會hang死. forever beginif(expre == 1) beginrun ...

  8. [SV]SystemVerilog枚举型变量语法详解及应用举例

    SystemVerilog枚举型变量语法详解及应用举例 This section provides the examples to declare SystemVerilog enum of logi ...

  9. 覆盖率— SV,SystemVerilog

    文章目录 1. 覆盖率的类型 1.代码覆盖率 2.断言覆盖率 3.功能覆盖率 2. 功能覆盖策略 3.覆盖组 4.数据采样 4.1 bin的创建和应用 4.2 命名coverpoint和bin 4.3 ...

最新文章

  1. 脑与神经类开放数据库汇总
  2. dom不刷新 vue 加数据后_高频出现的Vue 面试题及答案
  3. SpringCloud 应用在 Kubernetes 上的最佳实践 —— 开发篇
  4. 微信小程序学习笔记(五)
  5. 得到鹅厂最新前端开发手册一份
  6. Netty 的 ByteBuf 是如何支持 堆内存非池化 实现的
  7. 95-290-240-源码-内存管理-StreamRecord-StreamRecord简介
  8. JQ简单二级导航,加子导航栏
  9. Java中list转map的常用方法
  10. PSP: PMP格式视频制作教程
  11. RocKey4加密狗复制软件及教程
  12. OA办公系统审批流程是什么?
  13. win7系统升级IE11,打补丁KB2729094失败解决办法
  14. 水洼数 DFS 蓝桥杯 java代码
  15. 3、管理员添加内容的实现
  16. 如何设置word的默认输入法——搜狗输入法
  17. vue用watch监听属性变化
  18. SpringMVC的视图和视图解析器
  19. 百度云网盘在线播放视频速度加快的方法
  20. 47 lvs-nat/dr

热门文章

  1. 著名中医专家樊正伦(zt)
  2. 袋鼠妈妈和植物主义哪个适合孕妇用?主要看这几点
  3. 《穷爸爸富爸爸——富人不为钱而工作》
  4. CTO语录:真正技术高手是如何炼成的?
  5. 龙芯银河麒麟java配置与proxyee-down安装运行
  6. linux架设DNF服务器,使用linux的dnf命令新一代的RPM软件包管理器
  7. 【原创】flex控制flash元件
  8. proteus 14调节555芯片电阻让其一直闪烁至肉眼视为常亮(proteus仿真 芯片构建计算机)
  9. 圣诞节要不要用Java发个邮件
  10. 电路交换和数据包交换 计算机网络_计算机网络典型的交换技术