sv program module

请添加图片描述

为了避免races,在验证中引入program;
在这里插入图片描述

Similarities between program and module block

  1. A program block can instantiate another program block in the way how the module is instantiated another module block.
  2. Both can have no or more inputs, inout, and output ports.
  3. Both can have tasks, functions, variable declaration.
  4. Both can have continuous assignments, initial blocks, concurrent assertions, generate blocks, etc.

在这里插入图片描述

Difference between program and module block

  1. A program block can not instantiate a module block. On the opposite side, a module block can instantiate another module or program block.
  2. A program block can not have an interface, user-defined primitives (UDP), always block or nested program.
  3. The initial block inside the program block is scheduled in the reactive region whereas the initial blocks inside the module lock are scheduled in the active region.

tips

  • program 用在验证; 而module用在design;
  • program一般在top引用;
  • program 不能用always ; primitives; UDPs ,例化模块; interface; 包含其他program
  • It shall not contain always procedures,
    primitives, UDPs, or declarations or instances of modules, interfaces, or other programs
  • References to program signals from outside any program block shall be an error
  • Nested programs with no ports or top-level programs that are not
    explicitly instantiated are implicitly instantiated once. Implicitly instantiated programs have the same
    instance and declaration name.

https://vlsiverify.com/system-verilog/program-block/

//+++++++++++++++++++++++++++++++++++++++++++++++++
// Simple Program with ports
//+++++++++++++++++++++++++++++++++++++++++++++++++
program simple(input wire clk,output logic reset,
            enable, input logic [3:0] count);
  //=================================================
  // Initial block inside program block
  //=================================================
  initial begin
    $monitor("@%0dns count = %0d",$time,count);
    reset = 1;
    enable = 0;
    #20 reset = 0;
    @ (posedge clk);
    enable = 1;
    repeat (5) @ (posedge clk);
    enable = 0;
    // Call task in module
    simple_program.do_it();
  end
  //=================================================
  // Task inside a module
  //=================================================
  task do_it();
    $display("%m I am inside program");
  endtask

endprogram
//=================================================
//  Module which instanciates program block
//=================================================
module simple_program();
logic clk  = 0;
always #1 clk ++;
logic [3:0] count;
wire reset,enable;
//=================================================
// Simple up counter
//=================================================
always @ (posedge clk)
 if (reset) count <= 0;
 else if (enable) count ++;
//=================================================
// Program is connected like a module
//=================================================
simple prg_simple(clk,reset,enable,count);
//================================================
=
// Task inside a module
//=================================================
task do_it();
  $display("%m I am inside module");
endtask
//=================================================
// Below code is illegal
//=================================================
//initial begin
//  prg_simple.do_it();
//end

endmodule

  • 15
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值