编辑
2024-03-11
SystemC
00
请注意,本文编写于 366 天前,最后修改于 366 天前,其中某些信息可能已经过时。

目录

时间表示法
Time_Notation.cpp
结果

时间表示法

让我们先了解两个时间测量值的区别:

  1. 挂钟时间 从开始执行到完成的时间,包括等待其他系统活动和应用程序的时间
  2. 模拟时间 模拟建模的时间,可能小于或大于模拟的挂钟时间。

systemC 中,sc_time 是模拟内核用于跟踪模拟时间的数据类型。它定义了几个时间单位: SC_SECSC_MS、SC_USSC_NSSC_PS SC_FS。每个后续时间单位是其前一个时间单位的 1/1000

sc_time对象可用作赋值、算术和比较运算的操作数: 乘法允许其操作数之一为双精度 除法允许除数为双精度

SC_ZERO_TIME: 一个表示时间值为零的宏。每当写入时间值为零时(例如,创建增量通知或增量超时时),最好使用此常量。

要获取当前模拟时间,请使用 sc_time_stamp()

Time_Notation.cpp

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; }

结果

shell
SystemC 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 许可协议。转载请注明出处!