Learn SystemC - Combined Events

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

文章目录

wait()

systemC支持以下多种wait()调用:

  1. wait(): 等待敏感列表中的事件(SystemC 1.0)
  2. wait(e1): 等待事件e1
  3. wait(e1 | e2 | e3): 等待事件e1 或 e2 或 e3(三个事件任一事件发生)
  4. wait(e1 & e2 & e3): 等待事件e1 和 e2 和 e3(三个事件都发生,不一定同时)
  5. wait(200, SC_NS): 等待200 ns.
  6. wait(200, SC_NS, e1): 等待事件e1, 200 ns后超时
  7. wait(200, SC_NS, e1 | e2 | e3): 等待事件e1或e2或e3, 200 ns后超时
  8. wait(200, SC_NS, e1 & e2 & e3): 等待事件e1和e2和e3, 200 ns后超时
  9. wait(sc_time(200, SC_NS)): 等待200 ns.
  10. wait(sc_time(200, SC_NS), e1): 等待事件e1, 200 ns后超时
  11. wait(sc_time(200, SC_NS), e1 | e2 | e3): 等待事件e1或e2或e3, 200 ns后超时
  12. wait(sc_time(200, SC_NS), e1 & e2 & e3 ): 等待事件e1和e2和e3, 200 ns后超时
  13. wait(200): 等待200个时钟,只在SC_CTHREAD中使用 (SystemC 1.0)
  14. wait(0, SC_NS): 等待一个delta cycle.
  15. wait(SC_ZERO_TIME): 等待一个delta cycle.

注意:
在SystemC2.0中不支持"|“和”&"混用

下面看下本节示例:

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

SC_MODULE(COMBINED) {
  sc_event e1, e2, e3, e4, e5, e6, e7, e8, e9, e10; // 声明多个事件
  SC_CTOR(COMBINED) {
    SC_THREAD(trigger); // reigster trigger
    SC_THREAD(catcher_0); // register catchers
    SC_THREAD(catcher_1);
    SC_THREAD(catcher_2and3);
    SC_THREAD(catcher_4or5);
    SC_THREAD(catcher_timeout_or_6);
    SC_THREAD(catcher_timeout_or_7or8);
    SC_THREAD(catcher_timeout_or_9and10);
  }
  void trigger(void) {
    e1.notify(1, SC_SEC);  // 事件e1在1s时发生
    e2.notify(2, SC_SEC);  // ...
    e3.notify(3, SC_SEC);
    e4.notify(4, SC_SEC);
    e5.notify(5, SC_SEC);
    e6.notify(6, SC_SEC);
    e7.notify(7, SC_SEC);
    e8.notify(8, SC_SEC);
    e9.notify(9, SC_SEC);
    e10.notify(10, SC_SEC); // e10 fires at 10s
  }
  void catcher_0(void) {
    wait(2, SC_SEC); // timer triggered
    std::cout << sc_time_stamp() << ": 2sec timeout" << std::endl;
  }
  void catcher_1(void) {
    wait(e1); // e1 triggered
    std::cout << sc_time_stamp() << ": catch e1" << std::endl;
  }
  void catcher_2and3(void) {
    wait(e2 & e3); // e2 and e3
    std::cout << sc_time_stamp() << ": catch e2 and e3" << std::endl;
  }
  void catcher_4or5(void) {
    wait(e4 | e5); // e4 or e5
    std::cout << sc_time_stamp() << ": catch e4 or e5" << std::endl;
  }
  void catcher_timeout_or_6(void) {
    wait(sc_time(5, SC_SEC), e6); // timer or e6
    std::cout << sc_time_stamp() << ": 5sec timeout or catch e6"<< std::endl;
  }
  void catcher_timeout_or_7or8(void) {
    wait(sc_time(20, SC_SEC), e7 | e8); // timer or (e7 or e8)
    std::cout << sc_time_stamp() << ": 20sec timeout or catch e7 or e8" << std::endl;
  }
  void catcher_timeout_or_9and10(void) {
    wait(sc_time(20, SC_SEC), e9 & e10); // timer or (e9 and e10)
    std::cout << sc_time_stamp() << ": 20sec timeout or catch (e9 and e10)" << std::endl;
  }
};

int sc_main(int, char*[]) {
  COMBINED combined("combined");
  sc_start();
  return 0;
}

运行结果:

1 s: catch e1
2 s: 2sec timeout
3 s: catch e2 and e3
4 s: catch e4 or e5
5 s: 5sec timeout or catch e6  # timeout comes first
7 s: 20sec timeout or catch e7 or e8  # e7 comes first
10 s: 20sec timeout or catch (e9 and e10)  # (e9 and e10) comes first
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值