当前位置: 首页 > news >正文

SystemC -- A notion of time

1、simulation kernel用sc_time数据类型来跟踪仿真时间,指定delay和timeouts。

sc_time是用一个64bit的无符号整型数来表示。

SC_SECseconds 10^0 秒

SC_MSmilliseconds 10^-3 毫秒

SC_USmicroseconds 10^-6 微秒

SC_NSnanoseconds 10^-9 纳秒

SC_PSpicoseconds 10^-12 皮秒

SC_FSfemtoseconds 10^-15 飞秒

sc_time_stamp()用来获取当前的仿真时间,返回值是一个sc_time对象

sc_simulation_time()returns time as a double in the currentdefault time unit.

Info: (I804) /IEEE_Std_1666/deprecated: sc_simulation_time() is deprecated use sc_time_stamp()

To establish the default time unit, call sc_set_default_time_unit(). you must call this routine prior to call time specifications and prior to

the initiation of sc_start().

sc_start()启动仿真,括号中可带参数,指定的时间流逝后,仿真停止。

If you provide a time argument, simulation stops after the specified simulation time has elapsed.

#include "stdafx.h" #include <systemc.h> #include <iostream> using namespace std; SC_MODULE(My_Module) { SC_CTOR(My_Module) { SC_THREAD(mytime); } void mytime(); }; void My_Module::mytime() { int a = 5,b=3,c; c = a + b; wait(5,SC_NS); cout<<"The time is now "<<sc_time_stamp()<<"!"<<endl; sc_time t_delay(2,SC_MS); t_delay *= 2; cout<<"Delaying "<<t_delay<<endl; wait(t_delay); cout<<"The time is now "<<sc_time_stamp()<<"!"<<endl; } int sc_main(int sc_argc,char * argv[]) { My_Module md(""); sc_time m_time(5,SC_SEC); //sc_start(); //sc_start(10.0,SC_MS); //limit sim to 10 ms sc_start(m_time);//start sim and maximum simulation time system("pause"); return 0; }

输出:

#include "stdafx.h" #include <systemc.h> #include <iostream> using namespace std; int sc_main(int sc_argc,char * argv[]) { sc_set_time_resolution(1.0,SC_MS); sc_start(7200,SC_SEC);//limit simulation to 2 hours(or 7200 secs) sc_time st = sc_time_stamp();//获取当前仿真时刻和时间单位 double t = sc_simulation_time();//仅仅获取当前仿真时刻而无时间单位 //sc_cycle、sc_initialize:用于完成周期级仿真。 unsigned hours = int(t/3600.0); t -= 3600*hours; unsigned minutes = int(t/60.0); t -= 60.0*minutes; double seconds = t; cout<< hours << " hours " << minutes << " minutes " << seconds << " seconds " << endl; //system("pause"); return 0; }

输出:

上面时间输出错误,没有考虑到time units。

sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", SC_DO_NOTHING); 加入该句可以关闭有关deprecated 的warnings。

#include <systemc.h> #include <iostream> #include <math.h> using namespace std; int sc_main(int sc_argc,char * argv[]) { sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", SC_DO_NOTHING); cout<<"=== my time resolution is "<<sc_get_time_resolution()<<endl;//ps 10^-12s double t1 = sc_get_time_resolution().to_seconds(); cout<<"=== my time resolution is "<<t1<<"s."<<endl; sc_start(7296,SC_SEC); sc_time t = sc_time_stamp(); cout<<"Current time is "<<t<<endl; double t2 = sc_simulation_time();//ns? long long index = pow((double)10,(double)9); double ts = t2/index; // ns --> s unsigned hours = (int)(ts/3600.0); ts -= 3600 * hours; unsigned minutes = (int)(ts/60.0); ts -= 60 * minutes; double seconds = ts; cout <<"Time is "<< hours <<" hours " << minutes << " minutes " << seconds << " seconds " << endl; system("pause"); return 0; }

输出:

#include <systemc.h> #include <iostream> using namespace std; int sc_main(int sc_argc,char * argv[]) { sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", SC_DO_NOTHING); /* for example,if the specified time resolution is 100ps, then coding 20ps will result in an effective value of 0 ps */ sc_set_time_resolution(1,SC_NS); sc_set_default_time_unit(1,SC_MS); //establish the default time unit cout<<"=== my time resolution is "<<sc_get_time_resolution()<<endl;//ns 10^-9s double t1 = sc_get_time_resolution().to_seconds(); cout<<"=== my time resolution is "<<t1<<"s."<<endl; sc_start(7296,SC_SEC); sc_time t = sc_time_stamp(); cout<<"Current time is "<<t<<endl; double t2 = sc_simulation_time();//default time unit double ts = t2/1000; // ms --> s unsigned hours = (int)(ts/3600.0); ts -= 3600 * hours; unsigned minutes = (int)(ts/60.0); ts -= 60 * minutes; double seconds = ts; cout <<"Time is "<< hours <<" hours " << minutes << " minutes " << seconds << " seconds " << endl; system("pause"); return 0; }

输出:

http://www.jsqmd.com/news/1154976/

相关文章:

  • PIC18微控制器与CMT-8540S音频模块的嵌入式音频方案
  • 为什么你的GPTs总被审核拒绝?资深OpenAI Partner工程师曝光4大隐形否决红线
  • 2026年猫粮选购指南:口碑好的优质猫粮品牌推荐 - 资讯快报
  • Linux 应急修复神器:mkbootdisk 命令详解,一键创建系统引导盘
  • 原来知名的多媒体会议音视频工厂背后藏着这些秘密?
  • 北京积家官方售后网点核验报告|最新维修地址及电话权威收录(2026年7月最新) - 积家中国服务中心
  • 东北大米批发怎么选?三个秘诀助你快速锁定优质供应商 - 浙江稻盛和夫
  • 直流有刷驱动器TC78H651AFNG与dsPIC30F3014的电机控制方案
  • TB67H480FNG与PIC18LF27K40组合在精密电机控制中的应用
  • A3910与PIC18F85J50在嵌入式运动控制中的高效应用
  • 电池供电系统设计:NBM5100A与PIC18F45K22的智能能量管理方案
  • 做了上百件AI专利后,我把从项目挖点到成稿的全流程细节都拆透了
  • BiliTools哔哩哔哩工具箱:跨平台B站资源下载与管理终极指南
  • 爱彼中国官方售后服务体系全解析|最新网点地址及官网热线权威公布(2026年7月最新) - 亨得利中国服务中心
  • 基于TM4C123GH6PZ与PAM8904的智能音频警报系统设计
  • 2026长沙钻石回收实测:6大城区直营门店盘点,添价收凭正规资质与无损检测领跑行业 - 奢侈品回收中心
  • TensorBoard 2.16 实战:PyTorch 训练监控 5 大核心图表配置与解读
  • 7月走访西安碑林 5家商铺,本地人实测爱马仕 Birkin 奢侈品回收靠谱排行 - 融媒生活
  • 厦门黄金回收实地考察攻略:2026本地权威机构行情与门店筛选指南 - 奢品小当家
  • 一键获取!国家中小学智慧教育平台电子课本批量下载全攻略
  • 终极指南:如何使用readme-md-generator快速创建专业README文档
  • 上海第三机场开工在即,云端股份算力枢纽蓄势待发
  • Pycharm 快捷键、解释器设置、source root、远程开发、插件
  • 青岛市南万象城店收闲置香奈儿迪奥!逸程线下门店告别流动散户套路 - 全城热点
  • SENT 与 SPC 协议对比:在汽车转向系统中的 2 种信号传输方案选择
  • 计步应用 WeWard 推“步行模式”:锁定应用,促使用户达步数目标
  • 2026年大连搬家公司怎么选不被坑?5家搬家服务商实测对比与同城搬家+企业搬迁+透明定价指南 - 中国远见品牌企业资讯
  • 热镀锌电焊网厂家推荐哪几家靠谱 筛选 - 信息热点
  • 2026黄石本地人必选防水补漏检测维修公司靠谱服务商TOP5推荐:房屋渗漏水检测维修卫生间厨房天花板阳台外墙渗漏水检测补漏维修-暗管漏水检测专业仪器精准定位漏水点 - 一修哥咨询
  • 终极散热解决方案:用smcFanControl让你的Intel Mac告别过热烦恼[特殊字符]