参考: VHDLによるFPGA設計 & デバッグ by 松村謙 & 坂巻 佳壽美
内容
デバッグコンソールに任意の文字列を出力する
使うのは以下の2点。
- write()
- writeline()
上記を使うにはテストベンチでは以下が必要になるようだ。
use IEEE.std_logic_textio.all;
library STD;
use STD.textio.all;
code
design.vhd
library IEEE;
use IEEE.std_logic_1164.all;
entity CLOCK is
port ( CLK: in std_logic;
Q : out std_logic);
end CLOCK;
architecture RTL of CLOCK is
signal FLIP : std_logic := '0';
begin
Q <= FLIP;
process(CLK)
begin
if (CLK'event and CLK = '1') then
if (FLIP = '0') then
FLIP <= '1';
else
FLIP <= '0';
end if;
end if;
end process;
end;
testbench.vhd
library IEEE;
use IEEE.std_logic_1164.all;
-- for write(), writeline()
use IEEE.std_logic_textio.all;
library STD;
use STD.textio.all;
entity testbench is
end testbench;
architecture SIM of testbench is
signal I_CLK : std_logic := '1';
signal I_Q : std_logic := '0';
component CLOCK
port ( CLK: in std_logic;
Q : out std_logic);
end component;
begin
process begin
I_CLK <= '1';
wait for 10 ns;
I_CLK <= '0';
wait for 10 ns;
end process;
process
variable lout : line;
begin
wait for 100 ns;
-- output to debug console
write(lout, string'("testline"));
writeline(output, lout);
-- to end the testbench
assert false
report "end." severity FAILURE;
end process;
U1: CLOCK port map(CLK => I_CLK, Q => I_Q);
end SIM;
testlineという文字列を出力する。
line型のloutにwrite()で書き出してから、それをoutputにwriteline()で書く、という流れ。
結果
EDA Playgroundでは以下のような出力となった。
# KERNEL:
の行が対応する出力。
# KERNEL: testline
# EXECUTION:: FAILURE: end.
# EXECUTION:: Time: 100 ns, Iteration: 0, Instance: /testbench, Process: line__27.
# KERNEL: Stopped at time 100 ns + 0.
exit
# VSIM: Simulation has finished.