systemC应用程序有三个运行阶段:
其主要目的是创建内部数据结构来支持模拟的语义。
在精化过程中,将创建模块层次结构的各个部分(模块、端口、原始通道和流程),并且将端口和导出绑定到通道。
1)初始化
仿真内核识别所有仿真进程,并将它们置于可运行或等待进程集中。
除了那些请求“不初始化”的进程外,所有模拟进程都处于可运行集。
b)仿真
通常被描述为调度进程运行的状态机,并提前模拟时间。它有两个内部阶段:
1)评估:一次运行所有可运行进程。每个进程运行直到达到wait()或return。如果没有可运行进程,则停止。
A)将模拟时间移动到与计划事件最接近的时间
B)将等待特定时间的进程移动到可运行集中
C)回到评价阶段
从evaluate到advance-time的过程一直持续到三种情况中的一种发生。然后进入清理阶段。
A,所有的过程都产生了
B)进程执行了sc_stop()
C)达到最大时间
内核在精化和仿真的不同阶段调用四个回调函数。他们有下列声明:
虚void before_end_of_elaboration():在模块层次结构构造之后调用
虚拟void end_of_elaboration():在细化的最后,在所有回调before_end_of_elaboration完成之后,在这些回调执行的任何实例化或端口绑定完成之后,在开始模拟之前调用。
虚拟无效start_of_simulation():
A)当应用程序第一次调用sc_start或在模拟开始时立即调用,如果模拟是在内核的直接控制下启动的。
B)如果应用程序多次调用sc_start,则在第一次调用sc_start时调用start_of_simulation。
C)在回调end_of_elaboration之后,在调用调度器的初始化阶段之前调用。
A)在调度程序因为sc_stop而停止时调用,或者在模拟即将结束时调用,如果模拟是在内核的直接控制下启动的。
B)即使sc_stop被多次调用,也只调用一次。
c++#include <systemc>
using namespace sc_core;
SC_MODULE(STAGE) {
SC_CTOR(STAGE) { // 阐述
std::cout << sc_time_stamp() << ": Elaboration: constructor" << std::endl;
SC_THREAD(thread); // 初始化 + 模拟
}
~STAGE() { // 清理
std::cout << sc_time_stamp() << ": Cleanup: desctructor" << std::endl;
}
void thread() {
std::cout << sc_time_stamp() << ": Execution.initialization" << std::endl;
int i = 0;
while(true) {
wait(1, SC_SEC); // 提前时间
std::cout << sc_time_stamp() << ": Execution.simulation" << std::endl; // evaluation
if (++i >= 2) {
sc_stop(); // 2 次迭代后停止模拟
}
}
}
void before_end_of_elaboration() {
std::cout << "before end of elaboration" << std::endl;
}
void end_of_elaboration() {
std::cout << "end of elaboration" << std::endl;
}
void start_of_simulation() {
std::cout << "start of simulation" << std::endl;
}
void end_of_simulation() {
std::cout << "end of simulation" << std::endl;
}
};
int sc_main(int, char*[]) {
STAGE stage("stage"); // 阐述
sc_start(); // 执行到sc_stop
return 0; // 清理
}
shellSystemC 2.3.3-Accellera --- Oct 4 2020 22:59:38 Copyright (c) 1996-2018 by all Contributors, ALL RIGHTS RESERVED 0 s: Elaboration: constructor before end of elaboration end of elaboration start of simulation 0 s: Execution.initialization 1 s: Execution.simulation 2 s: Execution.simulation Info: /OSCI/SystemC: Simulation stopped by user. end of simulation 2 s: Cleanup: desctructor
本文作者:古月流新
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!