0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VHDL > デバッグ用文字列の出力 > variable lout : line; | write(lout, string'("testline")); | writeline(output, lout);

Last updated at Posted at 2016-05-27

参考: 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.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?