Jean
Jean

Reputation: 22695

Get system time in VCS

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 ?

Upvotes: 4

Views: 13320

Answers (3)

Meir
Meir

Reputation: 299

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

Upvotes: 1

Greg
Greg

Reputation: 19104

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();

Upvotes: 4

Ari
Ari

Reputation: 7556

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.

Upvotes: 5

Related Questions