问题
Is there way to get system time in VCS/UVM ? I am looking for something similar to Perl's localtime(time)
. Is there way to print system time for every uvm_info
printed ?
回答1:
One way is to use $system()
to run any system command, including system' date command.
initial
begin
$system("date");
end
From IEEE 1800 LRM:
$system
makes a call to the C function system(). The C function executes the argument passed to it as if the argument was executed from the terminal.$system
can be called as either a task or a function. When called as a function, it returns the return value of the call to system() with data type int. If$system
is called with no string argument, the C function system() will be called with the NULL string.
Also, see here.
回答2:
Depends on the version of VCS you are using. The latest version should support $system
as defined in IEEE Std 1800-2012 § 20.18.1. Assuming you are running in a UNIX based environment you can do:
function string get_localtime();
int fd;
string localtime;
void'($system("data > localtime")); // temp file
fd = $fopen("localtime", "r");
void'($fscanf(fd,"%s",localtime));
$fclose(fd);
void'($system("rm localtime")); // delete file
return localtime;
endfunction
If your version VCS doesn't support $system
or if your more conformable with C/C++, then use DPI (see IEEE Std 1800-2012 § 35). Create a function in C and compile it in VCS with your SystemVerilog files. In the SystemVerilog, add the import
to allow access to your C function. Assuming your method name is my_localtime and and return time is a string, the import should look like:
import "DPI" function string my_localtime();
回答3:
In c file wallclock.c :
#include <time.h>
wallclock() {
time_t t;
t = time(NULL);
return (ctime(&t));
//return time(NULL);
}
In SV file :
import "DPI-C" function string wallclock();
module try;
//int unsigned t;
string t;
initial begin
t = wallclock();
$write("time=%0s\n", t);
end
endmodule
来源:https://stackoverflow.com/questions/26046469/get-system-time-in-vcs