首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SystemC时间比较

SystemC时间比较
EN

Stack Overflow用户
提问于 2017-04-12 08:32:10
回答 1查看 430关注 0票数 0

我正在尝试比较SystemC中的模拟时间。我希望在while循环开始时获得当前的模拟时间,一旦模拟时间达到一个特定的数字,我就希望它离开循环。以下是我想尝试的方法,但由于语法问题,它不起作用。

代码语言:javascript
运行
复制
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:

代码语言:javascript
运行
复制
sc_time scImageDur;
scImageDur(imageDur,SC_SEC);

但这在语法上也是不正确的。

有点卡住了,不知道该怎么做。另外,当我做减法比较时,sc_time_stamp()的分辨率重要吗?或者是系统自己解决问题?

EN

回答 1

Stack Overflow用户

发布于 2017-04-12 15:33:42

首先,我假设您正在使用SC_THREAD,以便在SystemC中移动模拟时间。

您可以在模拟中尝试执行以下操作:

代码语言:javascript
运行
复制
// ... 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.

如果这对你有效,请告诉我。

注意:而不是每次都变差,一种更好的方法是计算结束时间,如果它是常量。

代码语言:javascript
运行
复制
// ... 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.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43358340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档