Reputation: 427
I know when using report
and severity
Modelsim displays the simulation time instant as part of its message to the console. Is there anyway to "get" this time instant as a string variable so I can print my own message with this "time" string?
Upvotes: 5
Views: 13735
Reputation: 3983
Read @MortenZdk post first. This is a long comment with formatting.
Rather than using 'image, I recommend the VHDL-2008 to_string function. You can use this in conjunction the built-in write operations for a file:
write(OUTPUT, "This is the time: " & to_string(now) & LF) ;
Alternately, you can also use it with textio and it will disambiguate a literal string value. For example, no type qualifier is required in the following:
write(write_buf, "The time is:" & to_string(now)) ;
writeline(OUTPUT, write_buf) ;
If you really hate textio, you can use concatenation and to_string just like you would use a "," in print statements in other languages. Don't forget the LF character at the end to end the line. You can also add LF characters in other places to print multiple lines.
write(OUTPUT, "%%ERROR: RX value does not match expected value" &
"Received Value: " & to_hstring(RxVal) &
" Expected Value: " & to_hstring(ExpectedVal) &
" at time: " & to_string(now) & LF ) ;
to_string supports a superset of what 'image supports. Most notable is array values (such as std_logic_vector). It is overloadable, but is already supported for all types supported by textio in VHDL-2008. It also supports hex and octal overloading in the form of to_hstring and to_ostring (just like hwrite and owrite). Note that VHDL-2008 removed the issues with hwrite, owrite, hread, and oread.
As an alternative to access types, VHDL-2008 also has a string read that returns both a value and a length. It skips white space, and then reads characters (up to the length of the string variable) until it finds white space. The following example allows the string token to be up to 80 characters.
variable ReadVal : string(1 to 80) ;
variable ReadLen : integer ;
...
sread(ReadBuf, ReadVal, ReadLen) ;
Upvotes: 0
Reputation: 15924
The simulation time is available through the now
function, which will a return the value as time
type. The image
attribute of the time
type can be used to convert this to string with time'image(now)
. So you can print the simulation time in your own message with:
report "This is the time: " & time'image(now);
Addition: If additional string manipulation is needed, then the simulation time string can be represented in a variable with code like:
process is
variable sim_time_str_v : string(1 to 30); -- 30 chars should be enough
variable sim_time_len_v : natural;
begin
...
sim_time_len_v := time'image(now)'length;
sim_time_str_v := (others => ' ');
sim_time_str_v(1 to sim_time_len_v) := time'image(now);
report "Sim time string length: " & integer'image(sim_time_len_v);
report "Sim time string.......:'" & sim_time_str_v & "'";
...
However, VHDL is cumbersome when it comes to text string manipulation, since storing the result of some manipulation requires that the length is known. For more advanced string manipulations, then access
type in combination with functions can be used in simulation.
Upvotes: 11