让我们先了解两个时间测量值的区别:
在 systemC
中,sc_time
是模拟内核用于跟踪模拟时间的数据类型。它定义了几个时间单位:
SC_SEC
、SC_MS、SC_US
、SC_NS
、SC_PS SC_FS
。每个后续时间单位是其前一个时间单位的 1/1000
。
sc_time
对象可用作赋值、算术和比较运算的操作数:
乘法允许其操作数之一为双精度
除法允许除数为双精度
SC_ZERO_TIME
:
一个表示时间值为零的宏。每当写入时间值为零时(例如,创建增量通知或增量超时时),最好使用此常量。
要获取当前模拟时间,请使用 sc_time_stamp()
。
c++#include <systemc>
using namespace sc_core;
int sc_main(int, char*[]) {
sc_core::sc_report_handler::set_actions( "/IEEE_Std_1666/deprecated",
sc_core::SC_DO_NOTHING ); // 禁止因set_time_resolution而发出的警告
sc_set_time_resolution(1, SC_FS); // 已弃用函数,但仍然有用,默认值为 1 PS
sc_set_default_time_unit(1, SC_SEC); // change time unit to 1 second
std::cout << "1 SEC = " << sc_time(1, SC_SEC).to_default_time_units() << " SEC"<< std::endl;
std::cout << "1 MS = " << sc_time(1, SC_MS).to_default_time_units() << " SEC"<< std::endl;
std::cout << "1 US = " << sc_time(1, SC_US).to_default_time_units() << " SEC"<< std::endl;
std::cout << "1 NS = " << sc_time(1, SC_NS).to_default_time_units() << " SEC"<< std::endl;
std::cout << "1 PS = " << sc_time(1, SC_PS).to_default_time_units() << " SEC"<< std::endl;
std::cout << "1 FS = " << sc_time(1, SC_FS).to_default_time_units() << " SEC"<< std::endl;
sc_start(7261, SC_SEC); // 运行模拟 7261 秒
double t = sc_time_stamp().to_seconds(); // 以秒为单位获取时间
std::cout << int(t) / 3600 << " hours, " << (int(t) % 3600) / 60 << " minutes, " << (int(t) % 60) << "seconds" << 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 1 SEC = 1 SEC 1 MS = 0.001 SEC 1 US = 1e-06 SEC 1 NS = 1e-09 SEC 1 PS = 1e-12 SEC 1 FS = 1e-15 SEC 2 hours, 1 minutes, 1seconds
本文作者:古月流新
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!