前言在项目中,一个tb通常是很多人一起开发的,大家或多或少都会往log中打印一些信息(message),方便自己debug。但是如果log里信息太多,会造成自己感兴趣的信息被淹没了,只能通过关键字搜索的方式去查找。因此,本文推荐可以使用uvm提供的uvm_log功能,只需要增加少量的代码,就可以根据id或uvm_severity类别,把自己感兴趣的信息单独提取到指定的文件。
uvm_log机制为了使用uvm_log功能,需要在打印message之前打开指定的文件,仿真结束时再关闭这个文件,并且需要把打开文件的句柄传递给uvm的message管理系统。可以将打开的文件设置为默认文件指向、或关联到指定的uvm_severity或id,或两者都关联。
在uvm_report_object和uvm_component类里提供了接口函数给用户去配置uvm_log功能,注意uvm_report_object是uvm_component的父类,因此大家只需要在uvm_component层次上调用这些接口函数就好了,而且可以控制uvm hierarchy上任何节点的消息打印行为。
具体的接口函数(api)分为两类。
第一类是只适用于当前uvm_component层次的,也就是这些接口函数的配置不会影响到uvm hierarchy的其它任何节点,有这些函数:
set_report_default_file(uvm_file file); //设置默认输出定向文件,如果id, severity都没有关联到输出定 //向文件的话,那么就默认采用这里设置的文件。set_report_id_file(string id, uvm_file file); //将id关联到参数指定的输出定向文件。set_report_severity_file(uvm_severity severity, uvm_file file); //将severity关联到参数指定的输出 // 定向文件。set_report_severity_id_file(uvm_severity severity, string id, uvm_file file); // 将severity // 和id一起关联到参数指定的输出定向文件。get_report_file_handle(uvm_severity severity, string id); // 返回指定severity和id的输出定向文件句柄这些函数参数中传递的文件句柄必须是multi-channel描述符(mcd)或与$fdisplay兼容的文件id。uvm_file类型其实就是int类型。如果上述接口函数对id或severity重复指定输出定向文件句柄,那么它们优先级是set_report_severity_id_file() > set_report_id_file() > set_report_severity_file() > set_report_default_file()。
第二类是除了适用于当前uvm_component层次,它的子uvm_component也都全部适用,有这些函数:
set_report_default_file_hier(uvm_file file);set_report_id_file_hier(string id, uvm_file file);set_report_severity_file_hier(uvm_severity severity, uvm_file file);set_report_severity_id_file_hier(uvm_severity severity, string id, uvm_file file);可以看出,第二类接口函数的命令是在第一类接口函数命名后面加上”_hier”,对应的功能是类似,只是作用的uvm_component范围不一样。
例子说了这么多,来几个例子。
第一个例子,在uvm_component子类里加入以下代码:
uvm_file log_fh = $fopen(cpu.log); // 打印cpu.log的文件,并把句柄传给log_fhthis.set_report_id_action(cpu, (uvm_display | uvm_log)); // 将”cpu”的id加上uvm_log功能this.set_report_id_file(cpu, log_fh); // 将“cpu”的id管理到log_fh文件句柄`uvm_info(cpu, the message will be logged in log file, uvm_low);`uvm_info(cpu0, the message will not be logged in log file, uvm_low);$fclose(log_fh); // 关闭log_fh文件句柄上述代码执行完之后,将会在仿真目录下生成1个名为cpu.log的文件,里面包含代码里第一个uvm_info打印的消息” the message will be logged in log file”。代码里第二个uvm_info的打印消息不会定向到cpu.log里,因为它的id是”cpu0”。
第二个例子,在uvm_component子类里加入以下代码:
uvm_file log_fh = $fopen(cpu.log);uvm_file default_fh = $fopen(default.log);this.set_report_id_action(cpu , (uvm_display | uvm_log));this.set_report_id_action(cpu0, (uvm_display | uvm_log));this.set_report_id_file(cpu, log_fh);this.set_report_default_file(default_fh);`uvm_info(cpu, the message will be logged in cpu.log file, uvm_low);`uvm_info(cpu0, the message will be logged in default.log file, uvm_low);$fclose(log_fh);$fclose(default_fh);上述代码执行完之后,将会在仿真目录下生成cpu.log和default.log两个文件,第一个uvm_info的id为”cpu”,它只会定向到cpu.log,而不会定向到default.log,因为set_report_id_file()设置的文件句柄优先级高于set_report_default_file()设置的。第二个uvm_info的id为”cpu0”,它会定向到defualt.log,因为没有显示关联到它的文件句柄,uvm会使用默认的文件句柄,也就是set_report_default_file()设置的defualt_fh(default.log)。
友情提示:
uvm_log功能需要用户自己创建文件句柄并关联到对应的id或severity上,因此用户需要维护文件句柄的打开和关闭,建议可以在report_phase()里去统一关闭它们,如果提前关闭的话。
有趣的功能衍生读者可以考虑 将id与uvm的uvm_cmdline_processor或sv自带的valueplusargs (user_string, variable)功能联系起来 ,这样通过command line可以很方便地控制要将哪些id定向到特定的log文件里, 这个功能很有用,也不需要重复编译就可以去定向提取各式各样的id ,大家可以自己先去试试,需要源代码的话在微信公众号聊天窗口里输入”id代码”,两种版本的代码都有提供。
2020年智能硬件行业处于物联网快速发展现状分析
QD-MiniLED显示技术到底有多好
直流脉冲与交流脉冲的区别
国企开放日走进ICPARK 探秘中国创“芯”基地
加强CPU、GPU和服务器等研发 计划出台推动算力建设政策文件
有趣的UVM_LOG用法
Semtech与亚马逊合作,助力低功耗远距离无线技术的开发和应用
带通滤波器是什么?
怎样将任何媒体文件转换成不同的格式
利用Power by Linear解决电源难题
毫米波雷达「四场景」|美的&英飞凌,如是说
浅谈FPC板和PCB板的发展
睿创微纳2021年度盘点:从8微米热成像到多光谱传感布局
北斗导航系统赶超GPS 2020年服务全球
与ETC有关的消息被频繁刷屏及及股票涨停潮占领
2011智能电网大盘点
MWC亮点前瞻:厂商纷纷“秀肌肉” 全球冲刺5G时代
人们对特斯拉的态度开始变化 极端立场开始逐渐消失
欧司朗推可转换LED指示灯产品打破LED产品都缺乏单一的标准
德州仪器推出四通道电源管理监控器系列