トライステートバッファー

p.184
4ビット幅のトライステートバッファーを合成する。

library ieee;
use ieee.std_logic_1164.all;

entity tri_state_buffer is
    generic(
        /*
       naturalは自然数型(0~2^31-1)。
       ほかにinteger、positiveなども。
       stdライブラリーのstandardパッケージに含まれているためインクルードは不要。
       */
        NUM_BITS : natural := 4
    );
    port(
        ena  : in  std_logic;
        inp  : in  std_logic_vector(NUM_BITS-1 downto 0);
        outp : out std_logic_vector(NUM_BITS-1 downto 0)
    );
end entity;

architecture rtl of tri_state_buffer is 
begin
    /*
   ena(ble)信号が1のときは筒抜け、それ以外のときはHi-Z。
   VHDL 2008を指定しておく。
   */
    outp <= inp when ena else (others => 'Z');
end architecture;