如何在 SystemVerilog 中存储来自 $system("...") 调用的 return 值?
How to store return value from $system("...") call in SystemVerilog?
如果我模拟以下模块:
module test;
longint seconds;
initial begin
seconds = $system("date +%s");
$display("Seconds: %0d", seconds);
$finish;
end
endmodule
ncsim
和 vsim
的输出都是:
1571172006
Seconds: 0
所以我可以看到 $system
调用 是 以秒为单位打印时间 1571172006
,但是变量 seconds
有一个值0
所以我没有保存那个值。
有什么方法可以保存这个值吗? (最好不要使用 DPI)
提前致谢。
这太可怕了,但是您可以将 linux 命令的输出通过管道传输到一个文件中,然后读取该文件:
$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);
module test;
longint seconds;
initial begin
int fd;
int count;
string s;
$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);
$finish;
end
endmodule
我不知道您为什么不想使用 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);
}
如果我模拟以下模块:
module test;
longint seconds;
initial begin
seconds = $system("date +%s");
$display("Seconds: %0d", seconds);
$finish;
end
endmodule
ncsim
和 vsim
的输出都是:
1571172006
Seconds: 0
所以我可以看到 $system
调用 是 以秒为单位打印时间 1571172006
,但是变量 seconds
有一个值0
所以我没有保存那个值。
有什么方法可以保存这个值吗? (最好不要使用 DPI)
提前致谢。
这太可怕了,但是您可以将 linux 命令的输出通过管道传输到一个文件中,然后读取该文件:
$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);
module test;
longint seconds;
initial begin
int fd;
int count;
string s;
$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);
$finish;
end
endmodule
我不知道您为什么不想使用 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);
}