SystemC时间比较
问题描述:
我想比较SystemC中的仿真时间。我想在我的while循环开始时获取当前的仿真时间,并且一旦仿真时间达到了特定的数字,我希望它离开循环。以下是我正在考虑的尝试,但由于语法问题,它不起作用。SystemC时间比较
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()
的分辨率是否重要?或者系统本身执行该决议?
答
首先,我假设您正在使用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.