データ伝送回路のテストベンチ(データファイルの使用)

掲載ページ:87、リスト番号:4.14

【VHDL記述】


library STD, IEEE;

use STD.TEXTIO.all;

use IEEE.std_logic_1164.all;

use IEEE.std_logic_textio.all;


entity TESTBENCH_DT_2 is

end TESTBENCH_DT_2;


architecture SIM_DATA of TESTBENCH_DT_2 is


component MULTIPLEXER4

port ( D : in std_logic_vector(3 downto 0);

S : in std_logic_vector(1 downto 0);

Y : out std_logic );

end component;

component DEMULTIPLEXER4

port ( D : in std_logic;

S : in std_logic_vector(1 downto 0);

Y : out std_logic_vector(3 downto 0));

end component;


signal S_Y : std_logic;

signal S_S : std_logic_vector(1 downto 0);

signal S_A, S_B : std_logic_vector(3 downto 0);


begin

M1 : MULTIPLEXER4 port map (S_A, S_S, S_Y);

M2 : DEMULTIPLEXER4 port map (S_Y, S_S, S_B);


-- テストベクトル(データファイルを用いた記述)

P1 : process

file TEST_IN : text is in "test_in.dat";

file TEST_OUT : text is out "test_out.dat";

variable LINE_IN, LINE_OUT : line;

variable V_S : std_logic_vector(1 downto 0);

variable V_A : std_logic_vector(3 downto 0);

begin

readline(TEST_IN, LINE_IN);

read(LINE_IN, V_S);

read(LINE_IN, V_A);

S_S <= V_S;

S_A <= V_A;

wait for 10 ns;

write(LINE_OUT, now, right, 6);

write(LINE_OUT, S_A, right, 5);

write(LINE_OUT, S_S, right, 3);

write(LINE_OUT, S_B, right, 5);

writeline(TEST_OUT, LINE_OUT);

if endfile(TEST_IN) then

wait;

end if;

end process;

end SIM_DATA;


configuration CFG_DT_2 of TESTBENCH_DT_2 is

for SIM_DATA

end for;

end CFG_DT_2;

【データ伝送回路のテストベンチ(リスト4.14)の入力データファイル(test_in.dat)(掲載ページ:88、リスト番号:4.15)】


00 0000

01 0000

10 0000

11 0000

00 0001

01 0001

10 0001

11 0001

00 0100

01 0100

10 0100

11 0100

00 1001

01 1001

10 1001

11 1001

【データ伝送回路のテストベンチ(リスト4.14)の出力データファイル(test_out.dat)(掲載ページ:88、リスト番号:4.16)】


10 NS 0000 00 0000

20 NS 0000 01 0000

30 NS 0000 10 0000

40 NS 0000 11 0000

50 NS 0001 00 0001

60 NS 0001 01 0000

70 NS 0001 10 0000

80 NS 0001 11 0000

90 NS 0100 00 0000

100 NS 0100 01 0000

110 NS 0100 10 0100

120 NS 0100 11 0000

130 NS 1001 00 0001

140 NS 1001 01 0000

150 NS 1001 10 0000

160 NS 1001 11 1000

【Verilog-HDL記述】


`timescale 1 ns / 10 ps


module TESTBENCH_DT_2;


reg[ 3 : 0 ] S_A;

wire[ 3 : 0 ] S_B;

reg[ 1 : 0 ] S_S;

wire S_Y;


integer I, FP;

reg[ 5 : 0 ] MEM[ 0 : 15 ];


MULTIPLEXER4 M1 (S_A, S_S, S_Y);

DEMULTIPLEXER4 M2 (S_Y, S_S, S_B);


// テストベクトル(データファイルを用いた記述)

initial begin

$readmemb( "TEST_IN_Verilog.DAT", MEM );

end


initial begin

FP = $fopen( "TEST_OUT_Verilog.DAT" );

for ( I = 0; I < 16; I = I + 1 ) begin

{ S_S, S_A } = MEM[ I ];

#10 ;

$fdisplay( FP, $stime, " %b %b %b", S_A, S_S, S_B );

end

$fclose(FP);

end

endmodule

【データ伝送回路のテストベンチ(Verilog-HDL記述用)の入力データファイル(TEST_IN_Verilog.DAT)】


00_0000

01_0000

10_0000

11_0000

00_0001

01_0001

10_0001

11_0001

00_0100

01_0100

10_0100

11_0100

00_1001

01_1001

10_1001

11_1001

【データ伝送回路のテストベンチ(リスト4.14)の出力データファイル(TEST_OUT_Verilog.DAT)】


10 0000 00 0000

20 0000 01 0000

30 0000 10 0000

40 0000 11 0000

50 0001 00 0001

60 0001 01 0000

70 0001 10 0000

80 0001 11 0000

90 0100 00 0000

100 0100 01 0000

110 0100 10 0100

120 0100 11 0000

130 1001 00 0001

140 1001 01 0000

150 1001 10 0000

160 1001 11 1000

【シミュレーション結果】