5

我知道什么时候使用reportseverityModelsim 将仿真时间显示为控制台消息的一部分。无论如何要“获取”这个时间瞬间作为字符串变量,所以我可以用这个“时间”字符串打印我自己的消息?

4

2 回答 2

11

模拟时间可通过now函数获得,该函数将返回值作为time类型。该类型的image属性time可用于将其转换为带有 的字符串time'image(now)。因此,您可以在自己的消息中打印模拟时间:

report "This is the time: " & time'image(now);

补充:如果需要额外的字符串操作,那么模拟时间字符串可以用一个变量表示,代码如下:

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 & "'";
  ...

但是,VHDL 在处理文本字符串时很麻烦,因为存储某些操作的结果需要知道长度。对于更高级的字符串操作,access可以在模拟中使用结合函数的类型。

于 2013-08-23T02:50:12.590 回答
0

首先阅读@MortenZdk 帖子。这是一个带有格式的长注释。

我推荐使用 VHDL-2008 to_string 函数,而不是使用 'image。您可以将其与文件的内置写入操作结合使用:

write(OUTPUT, "This is the time: " & to_string(now) & LF) ; 

或者,您也可以将它与 textio 一起使用,它将消除文字字符串值的歧义。例如,以下不需要类型限定符:

write(write_buf, "The time is:" & to_string(now)) ; 
writeline(OUTPUT, write_buf) ; 

如果你真的讨厌 textio,你可以像在其他语言的打印语句中使用 "," 一样使用连接和 to_string。不要忘记末尾的 LF 字符来结束行。您还可以在其他地方添加 LF 字符以打印多行。

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 支持 'image 支持的超集。最值得注意的是数组值(例如 std_logic_vector)。它是可重载的,但已经支持 VHDL-2008 中 textio 支持的所有类型。它还支持 to_hstring 和 to_ostring 形式的十六进制和八进制重载(就像 hwrite 和 owrite 一样)。请注意,VHDL-2008 删除了 hwrite、owrite、hread 和 oread 的问题。

作为访问类型的替代方案,VHDL-2008 还具有一个字符串读取,它返回一个值和一个长度。它跳过空格,然后读取字符(直到字符串变量的长度),直到找到空格。以下示例允许字符串标记最多为 80 个字符。

variable ReadVal : string(1 to 80) ; 
variable ReadLen : integer ; 
...
sread(ReadBuf, ReadVal, ReadLen) ;
于 2013-08-27T17:29:14.883 回答