我正在尝试比较SystemC中的模拟时间。我希望在while循环开始时获得当前的模拟时间,一旦模拟时间达到一个特定的数字,我就希望它离开循环。以下是我想尝试的方法,但由于语法问题,它不起作用。
sc_time currentTime;
int imageDur; //This value is variable; Resolution is seconds
currentTime = sc_time_stamp(); //Get current simulation time
while(sc_time_stamp() - currentTime < imageDur){
//Do stuff
}这样做的问题是,imageDur是int类型,而我不能执行sc_time到int的比较。因此,我的下一个想法是通过以下方法将imageDur转换为sc_time:
sc_time scImageDur;
scImageDur(imageDur,SC_SEC);但这在语法上也是不正确的。
有点卡住了,不知道该怎么做。另外,当我做减法比较时,sc_time_stamp()的分辨率重要吗?或者是系统自己解决问题?
发布于 2017-04-12 15:33:42
首先,我假设您正在使用SC_THREAD,以便在SystemC中移动模拟时间。
您可以在模拟中尝试执行以下操作:
// ... in SC_THREAD registered function.
sc_time currentTime = sc_time_stamp();
int imagDur; //< Assuming you are getting a value from somewhere.
sc_time scImageDur = sc_time(imagDur, SC_SEC);
while((sc_time_stamp() - currentTime) < scImageDur) {
// Do stuff
wait(10, SC_SEC); //< Move simulation time. (Very Important.)
}
// sc_stop(); //< Stop simulation or let it continue.
// ..... in SC_THREAD registered function.如果这对你有效,请告诉我。
注意:而不是每次都变差,一种更好的方法是计算结束时间,如果它是常量。
// ... in SC_THREAD registered function.
sc_time currentTime = sc_time_stamp();
int imagDur; //< Assuming you are getting a value from somewhere.
sc_time scImageDur = sc_time(imagDur, SC_SEC) + currentTime; //< calculate the end time.
while(sc_time_stamp() < scImageDur) { //< better since you are not computing the diff every time.
// Do stuff
wait(10, SC_SEC); //< Move simulation time. (Very Important.)
}
// sc_stop(); //< Stop simulation or let it continue.
// ..... in SC_THREAD registered function.https://stackoverflow.com/questions/43358340
复制相似问题