Simulation Process:
如何注册一个Simulation Process:
什么时候可以注册:
限制:
注意:
c++#include <systemc>
using namespace sc_core;
SC_MODULE(PROCESS) {
sc_clock clk; // 声明时钟
SC_CTOR(PROCESS) : clk("clk", 1, SC_SEC) { // 实例化具有 1 秒周期性的时钟
SC_METHOD(method); // 注册方法
SC_THREAD(thread); // 注册线程
SC_CTHREAD(cthread, clk); // 注册时钟线程
}
void method(void) { // 定义方法成员函数
// 这里没有 while 循环
std::cout << "method triggered @ " << sc_time_stamp() << std::endl;
next_trigger(sc_time(1, SC_SEC)); // 1 秒后触发
}
void thread() { // 定义线程成员函数
while (true) { // 无限循环确保它永远不会退出
std::cout << "thread triggered @ " << sc_time_stamp() << std::endl;
wait(1, SC_SEC); // 等待 1 秒钟,然后再次执行
}
}
void cthread() { // 定义 CTHREAD 成员函数
while (true) { // 无限循环
std::cout << "cthread triggered @ " << sc_time_stamp() << std::endl;
wait(); // 等待下一个 CLK 事件,该事件在 1 秒后出现
}
}
};
int sc_main(int, char*[]) {
PROCESS process("process"); // 初始化模块
std::cout << "execution phase begins @ " << sc_time_stamp() << std::endl;
sc_start(2, SC_SEC); // 运行模拟 2 秒
std::cout << "execution phase ends @ " << sc_time_stamp() << std::endl;
return 0;
}
shellSystemC 2.3.3-Accellera --- Oct 4 2020 22:59:38 Copyright (c) 1996-2018 by all Contributors, ALL RIGHTS RESERVED execution phase begins @ 0 s method triggered @ 0 s thread triggered @ 0 s cthread triggered @ 0 s method triggered @ 1 s thread triggered @ 1 s cthread triggered @ 1 s execution phase ends @ 2 s
本文作者:古月流新
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!