VHDL文法一覧
背景
VHDLの学習として文法などをまとめてみた。間違いや最新情報のキャッチアップは出来ていない可能性あり。 コメント頂ければ幸い。
論理合成に関するもの
ライブラリ宣言
library IEEE; use IEEE.std_logic_1164.all; -- 基本関数 use IEEE.std_logic_unsigned.all; -- 符号無し演算関数 use IEEE.std.logic_arith.all; -- 算術演算関数
モジュール
モジュールと入出力ポートの宣言
entity MODULE is port ( A : in std_logic; B : in std_logic_vector(7 downto 0); C :out stdlogic); end MODULE;
内部配線の宣言
signal D : std_logic;
アーキテクチャ
architecture RTL of MODULE is begin ・ ・ ・ end RTL;
ポート宣言
port(名前 :入出力 信号線種類);
入出力
in/out:inout
信号線の種類
ビット線
A : std_logic
バス線
A : std_logic_vector(7 downto 0);
モジュール内部信号
signal A : std_logic_vector( 7 donwto 0);
定数宣言
constant A : std_logic := '0'; --定義的な使い方
変数宣言
variable A : std_logic := '0'; --テストベンチ用
ジェネリック
generic( COUNT : integer := 4 ); -- パラメーターとして使用する
タイプ
列挙タイプ
type state is ( idle, start, stop );
Integerタイプ
type digit is integer range 0 to 9;
サブタイプ
subtype IOBUS is std_logic_vector(7 dwonto 0); subtype DIGIT is interger range 0 to 9;
配列
type WORD is array(1 to 8) of std_logic; type WORD is array(integer 1 to 8) of std_logic;
多次元配列
type memory is array(0 to 5, 7 downto 0) of std_logic;
プロセス文
process (CLK) begin if rising_edge(clk) then A <= B; end if; end process;
if文
if 条件 then elsif 条件 then else end if;
when文
A <= B when E = 1 else C when F = 1 else D;
case文
case A is when "00" => B <= "000"; when "01" => B <= "010"; when "10" => B <= "100"; when others => B <= "000"; end case;
センシティビティリスト
process (A,B,C) begin A <= B and C; C <= A or B; end process;
入力全てをセンシティビティリストにする場合
process (all) begin end process;
クロック
process (clk) begin if rising_edge(clk) then -- 処理 end if; end process; -- 立下りはfalling_edge(clk)
連結
C(4 down to 1) <= A(0) & B( 3 downto 1);
ビット抜出し
A(0) --Aの1bit目の値 B( 3 downto 1) --Bの4,3,2bit目の値
数値の表記方法
bit表示; '0' binary表示: "0010" Hex表示: X"FF08"
モジュール階層化
entity MODULE is port( -- ); end MODULE; architecture RTL of MODULE is component comp port ( -- compモジュールの入出力ポート ); end component; signal D : std_logic; begin c1: comp port map(A, B, C); -- entityポートの表示順に対応 end RTL;