如何在SystemVerilog中存储$ system(“ ...”)调用的返回值?

时间:2019-10-15 20:41:43

标签: system-verilog

如果我模拟以下模块:

<ul *ngFor="let item of menu">
 <li> {{ item.name }} </li>
 <li> {{ item.description}} </li>
 ....
</ul>

module test; longint seconds; initial begin seconds = $system("date +%s"); $display("Seconds: %0d", seconds); $finish; end endmodule ncsim的输出为:

vsim

所以我可以看到1571172006 Seconds: 0 调用正在以秒为单位$system打印时间,但是变量1571172006的值为{{1}因此,我没有保存该值。

我有办法保存这一价值吗? (最好不使用DPI)

谢谢。

edaplayground link

2 个答案:

答案 0 :(得分:1)

这太可怕了,但是您可以将Linux命令的输出通过管道传输到一个文件中,然后读取该文件:

div = 
     {
     id: (changeable value),
     html = 'div id="divName'+getId()+'"></div>',
     getId()
        {
        return this.id;
    },
}

$system("date +%s | tee date.txt");
fd = $fopen("date.txt","r");
count=($fgets(s, fd) == 0);        assert(count == 0);
count=($sscanf(s,"%d", seconds));  assert(count == 1);
$display("Seconds: %0d", seconds);

https://www.edaplayground.com/x/4R5e

答案 1 :(得分:1)

我不知道您为什么不想使用DPI。比马修的方法简单得多。 ?

module test;
  import "DPI-C" function longint date();
    longint seconds;
    initial begin
      seconds = date();
        $display("Seconds: %0d", seconds);
        $finish;
    end

endmodule

#include <time.h>
long int date() {
  return time(NULL);
}

https://www.edaplayground.com/x/5NTw