简体   繁体   English

将ISim结果复制为字符串/文本

[英]Copying ISim results as strings/text

I'm creating a VHDL project, and using ISim to simulate beforehand - which is all fine. 我正在创建一个VHDL项目,并使用ISim预先进行仿真-一切都很好。

However, my results use fixed point - and although Isim can represent its signals as a range of radix's, unsurprisingly, fixed point decimal isn't one of them. 但是,我的结果使用了固定点-尽管Isim可以将其信号表示为一系列基数,但毫不奇怪,固定点十进制并不是其中之一。

Hence I'd like to get the current value of each signal as text but the "copy" function only copies the entity and signal name, and not the string value. 因此,我想以文本形式获取每个信号的当前值,但是“复制”功能仅复制实体和信号名称,而不复制字符串值。

For example 例如

在此处输入图片说明

I want to get the value of "[00010000, 00020000...etc etc] but I actually just get the value of "/fixedpointtb/UUT/s1_fcs[0]" ie entity name. 我想获取值[[00010000,00020000 ... etc等],但实际上我只获取值“ / fixedpointtb / UUT / s1_fcs [0]”,即实体名称。

Common sense says there must be a simple way of doing this but I can't see how! 常识说,必须有一种简单的方法来做到这一点,但我不知道怎么做!

You can use VHDL's file I/O capabilities in your testbench (at top-level) to convert the signals from DUT into a human readable string and write it to STDOUT or into a file. 您可以在测试平台(顶层)中使用VHDL的文件I / O功能,将来自DUT的信号转换为人类可读的字符串,并将其写入STDOUT或文件中。

A coarse overview on file I/O. 文件I / O的粗略概述。

VHDL has several packages and procedures/functions for file I/O and string operations. VHDL具有用于文件I / O和字符串操作的多个程序包和过程/功能。

  • std.textio std.textio
    VHDL defines an access type (a pointer) called line for string and a basic file type text for text files. VHDL为string定义了一种称为line的访问类型(指针),为文本文件定义了一种基本文件类型的text

    Usage: 用法:

     use std.textio.all; 

    Declarations from std.textio : 来自std.textio声明:

     -- types type line is access string; type text is file of string; -- STD files file input : text open read_mode is "STD_INPUT"; file output : text open write_mode is "STD_OUTPUT"; -- procedures (some with overloads) read (<lineVar>, <vhdlObji [,<status>]); readline (<fileObj>, <lineVari); write (<lineVar>, <vhdlObj> [,right|left, <width>]); write (<lineVar>, <realObj> [,right|left, <width>, <digits>]); write (<lineVar>, <timeObj> [,right|left, <width>, <unit>]); writeline (<fileObj>, <lineVar>); -- functions endfile (<fileObj>) : boolean 
  • ieee.std_logic_textio ieee.std_logic_textio
    This package declares more procedures to format std_logic values. 该软件包声明了更多的过程来格式化std_logic值。

    Usage: 用法:

     library ieee; use std.textio.all; use ieee.std_logic_1164.all; use ieee.std_logic_textio.all; 

    Declarations from ieee.std_logic_textio : 来自ieee.std_logic_textio声明:

     read (<lineVar>, <vhdlObj> [,<status>]); -- binary hread (<lineVar>, <vhdlObj> [,<status>]); -- hexadecimal oread (<lineVar>, <vhdlObj> [,<status>]); -- octal write (<lineVar>, <vhdlObj> [,right|left, <width>]); -- binary hwrite (<lineVar>, <vhdlObj> [,right|left, <width>]); -- hexadecimal owrite (<lineVar>, <vhdlObj> [,right|left, <width>]); -- octal 

Source: VHDL Kompakt (German VHDL book from Universität Hamburg) 资料来源: VHDL Kompakt (汉堡大学的德语VHDL书)

Usage example 使用范例

The following example writes the value of mySignal to a logfile and reports the time. 以下示例将mySignal的值写入日志文件并报告时间。

signal mySignal : STD_LOGIC_VECTOR(7 downto 0);
-- ....

process
  file     LogFile    : TEXT open WRITE_MODE is "logfile.log";
  variable LineBuffer : LINE;
begin
  write(LineBuffer,  (     STRING'("========================================")));
  write(LineBuffer,  (CR & STRING'("TESTBENCH REPORT")));
  write(LineBuffer,  (CR & STRING'("========================================")));
  writeline(LogFile, LineBuffer);

  wait until mySignal /= x"00";
  wait until rising_edge(Clock);
  for i in 0 to 7 loop
    wait until rising_edge(Clock);
    write(LineBuffer, "Time " & to_string(now, 1) & "  Value 0x" & raw_format_slv_hex(mySignal));
    writeline(LogFile, LineBuffer);
  end loop;
end process;

now is a built-in function, representing the current simulation time. now是一个内置函数,代表当前的模拟时间。 It is formatted by to_string , which expects a time and a precision. 它由to_string格式化,需要时间和精度。 The signal mySignal is formatted by raw_format_slv_hex . 信号mySignalraw_format_slv_hex格式化。 This function formats a STD_LOGIC_VECTOR of arbitrary size to a hexadecimal string. 此函数将任意大小的STD_LOGIC_VECTOR格式化为十六进制字符串。

The file should have such content: 该文件应具有以下内容:

========================================
TESTBENCH REPORT
========================================
Time 50 ns  Value 0x08
Time 60 ns  Value 0x09
Time 70 ns  Value 0x0A
Time 80 ns  Value 0x0B
Time 90 ns  Value 0x0C
....

One last hint 最后提示

write procedures append there data to the LineBuffer string. write过程会将数据附加到LineBuffer字符串中。 When you call writeline, the buffer is written to the file and the LineBuffer is empty after that operation. 当您调用writeline时,缓冲区将被写入文件,并且该操作后LineBuffer为空。

And finally, here is an example snippet on how to read a RAM/ROM initialization file and convert it into a generic memory representation. 最后,这是一个有关如何读取RAM / ROM初始化文件并将其转换为通用内存表示形式的示例片段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM