本文为英文版本翻译,原文地址:Combined Events
文章目录
wait()
systemC支持以下多种wait()调用:
- wait(): 等待敏感列表中的事件(SystemC 1.0)
- wait(e1): 等待事件e1
- wait(e1 | e2 | e3): 等待事件e1 或 e2 或 e3(三个事件任一事件发生)
- wait(e1 & e2 & e3): 等待事件e1 和 e2 和 e3(三个事件都发生,不一定同时)
- wait(200, SC_NS): 等待200 ns.
- wait(200, SC_NS, e1): 等待事件e1, 200 ns后超时
- wait(200, SC_NS, e1 | e2 | e3): 等待事件e1或e2或e3, 200 ns后超时
- wait(200, SC_NS, e1 & e2 & e3): 等待事件e1和e2和e3, 200 ns后超时
- wait(sc_time(200, SC_NS)): 等待200 ns.
- wait(sc_time(200, SC_NS), e1): 等待事件e1, 200 ns后超时
- wait(sc_time(200, SC_NS), e1 | e2 | e3): 等待事件e1或e2或e3, 200 ns后超时
- wait(sc_time(200, SC_NS), e1 & e2 & e3 ): 等待事件e1和e2和e3, 200 ns后超时
- wait(200): 等待200个时钟,只在SC_CTHREAD中使用 (SystemC 1.0)
- wait(0, SC_NS): 等待一个delta cycle.
- 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