ghdl(Bullseye)

2021/9/9


install

Buster(Debian10)からVHDL開発環境(ghdl)が有効になっていた。Busterでghdlを試すチャンスがなかったので、Bullseyeで試すことにした。
apt -y install ghdl gtkwave

動作確認

記述するものはソースリスト2つ
論理回路記述 ha.vhdl
 論理回路本体に関する部分
テストベンチ ha_tb.vhdl
 ha.vhdlの動作を確認するための記述
/*半加算器 Half Adder*/
library ieee;
use ieee.std_logic_1164.all;

//haの入出力端子を指定 入力a,b 出力c(carry),s
entity ha is
	port (
		a:	in	std_ulogic;
		b:	in	std_ulogic;
		c:	out	std_ulogic;
		s:	out	std_ulogic		//;最後はをつけない
	);
end ha;

//haの動作を記述
architecture behave of ha is
begin
	c <= a and b;
	s <=a xor b;
end behave;
library ieee;
use ieee.std_logic_1164.all;

entity ha_tb is   //(空欄)入出力端子はいらない
end ha_tb;

architecture test of ha_tb is
	component	ha
		port (
			a:	in	std_ulogic;
			b:	in	std_ulogic;
			c:	out	std_ulogic;
			o:	out	std_ulogic //最後は;をつけない
		);
	end component;

	signal	ax,b,c,o:	std_ulogic;
	begin
		half_adder : ha port map(a=>ax,b =>b, c=>c,o=>o);
		process	begin
		ax <= 'X';	b<= 'X';	wait for 1 ms;
		ax <= '0';	b<= '0';	wait for 1 ms;
		ax <= '0';	b<= '1';	wait for 1 ms;
		ax <= '1';	b<= '0';	wait for 1 ms;
		ax <= '1';	b<= '1';	wait for 1 ms;
		ax <= '0';	b<= '0';	wait for 1 ms;
		assert false report "Reached end of test";
		wait ;
		end process;
end test;

compile and GO

ghdlで*.vhdlをコンパイルする。
-oオプションで出力ファイルを指定できる。省略時はa.outを生成する。
vvp(ランタイムエンジン)でa.outを実行する。実行結果はテストベンチ中に記述したtmp.vcpに保存する。
実行結果は、gtkwaveでタイミングチャートを表示できる。
//以前に生成したライブラリを削除
ghdl --remove

//文法チェック
ghdl -s ha.vhdl
ghdl -s ha_tb.vhdl

//analyze 解析
ghdl -a ha.vhdl ha_tb.vhdl

//elaborate バイナリファイル生成 テストベンチ(entity名)を指定
ghdl -e ta_tb

//run 実行 : elaborageで指定したテストベンチ(ha_tb)を指定
ghdl -r ha_tb --vcd=tmp.vcd

//タイミングチャート表示
gtkwave tmp.vcd
Half Adder