[英]How to create a list of Tcl commands in a text file and then run it in ISim?
[英]Copying ISim results as strings/text
您可以在測試平台(頂層)中使用VHDL的文件I / O功能,將來自DUT的信號轉換為人類可讀的字符串,並將其寫入STDOUT或文件中。
文件I / O的粗略概述。
VHDL具有用於文件I / O和字符串操作的多個程序包和過程/功能。
std.textio
VHDL為string
定義了一種稱為line
的訪問類型(指針),為文本文件定義了一種基本文件類型的text
。
用法:
use std.textio.all;
來自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
該軟件包聲明了更多的過程來格式化std_logic
值。
用法:
library ieee; use std.textio.all; use ieee.std_logic_1164.all; use ieee.std_logic_textio.all;
來自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
資料來源: VHDL Kompakt (漢堡大學的德語VHDL書)
使用范例
以下示例將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
是一個內置函數,代表當前的模擬時間。 它由to_string
格式化,需要時間和精度。 信號mySignal
由raw_format_slv_hex
格式化。 此函數將任意大小的STD_LOGIC_VECTOR
格式化為十六進制字符串。
該文件應具有以下內容:
========================================
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
....
最后提示
write
過程會將數據附加到LineBuffer
字符串中。 當您調用writeline時,緩沖區將被寫入文件,並且該操作后LineBuffer
為空。
最后,這是一個有關如何讀取RAM / ROM初始化文件並將其轉換為通用內存表示形式的示例片段 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.