Learn SystemC - Initialization

本文为英文版本翻译,原文地址:Initialization

初始化(Initialization)

初始化在sc_start()后调用,属于执行阶段(execution stage)。初始化按照下列顺序进行3个操作:

  1. 运行更新阶段(update phase),但不做delta notifaction阶段
  2. 添加除下面两种其他的方法,过程到可运行过程:
    a) 设置了dont_initialize的过程实例
    b) CTHREAD实例(clocked thread processes)
  3. 运行delta notification phase. delta notification阶段结束时, 进行evaluation 阶段.

NOTE

  1. 由于update requests可能在阐述阶段(elaboration)创建并用于设置primitive channels的初始值,因此update and delta notification是必需的。例如sc_inout的初始化。
  2. SystemC 1.0版本:
    a) thread processes在仿真的初始化阶段(initializaiton phase)不执行
    b) method processes如果设置对输入信号/端口敏感,那么它们在仿真的初始化阶段(initializaiton phase)会执行
  3. SystemC 2.0 在仿真的初始化阶段执行所有的thread processesmethod processes
    If the behavior of a thread process is different between SystemC 1.0 and SystemC 2.0, insert one wait() statement before the infinite loop of the thread process.
  4. 在初始化阶段,仿真过程(SC_METHODs in SystemC 1.0; SC_METHODs and SC_THREADs in SystemC 2.0)执行顺序不确定
  5. dont_initialize(): 阻止调度器在初始化阶段执行thread processesmethod processes

示例代码

// Learn with Examples, 2020, MIT license
#include <systemc>
using namespace sc_core;

SC_MODULE(INITIALIZATION) {
  sc_event e; // 用于仿真过程间触发
  SC_CTOR(INITIALIZATION) {
    SC_THREAD(trigger); // no static sensitivity
    SC_THREAD(catcher_1); // no static sensitivity
    SC_THREAD(catcher_2); // no static sensitivity
    SC_THREAD(catcher_3);
    sensitive << e; // statically sensitive to e
    dont_initialize(); // catcher_3初始化阶段不执行
  }
  void trigger() {
    while (true) { // e triggered at 1, 3, 5, 7 ...
      e.notify(1, SC_SEC); // notify after 1 s
      wait(2, SC_SEC); // trigger every 2 s
    }
  }
  void catcher_1() {
    while (true) {
      std::cout << sc_time_stamp() << ": catcher_1 triggered" << std::endl;
      wait(e); // dynamic sensitivity
    }
  }
  void catcher_2() {
    wait(e); // avoid initialization --- mimic systemC 1.0 behavior
    while (true) {
      std::cout << sc_time_stamp() << ": catcher_2 triggered" << std::endl;
      wait(e); // dynamic sensitivity
    }
  }
  void catcher_3() { // relies on dont_initialize() to avoid initialization
    while (true) {
      std::cout << sc_time_stamp() << ": catcher_3 triggered" << std::endl;
      wait(e); // dynamic sensitivity
    }
  }
};

int sc_main(int, char*[]) {
  INITIALIZATION init("init");
  sc_start(4, SC_SEC);
  return 0;
}

运行结果:

# catcher_1 is executed during initialization, catcher_2 and catcher_3 have same behavior but are implemented differently
0 s: catcher_1 triggered  # during initialization
1 s: catcher_3 triggered  # e triggered, not executed during initialization
1 s: catcher_1 triggered  # e triggered
1 s: catcher_2 triggered  # e triggered, not executed during initialization
3 s: catcher_3 triggered  # e triggered
3 s: catcher_2 triggered  # e triggered
3 s: catcher_1 triggered  # e triggered
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值