必要に応じてレコード タイプを初期化するには、少なくとも 2 つの選択肢があります。1 つは初期化関数を使用しており、もう 1 つは集計で N の値を使用しています。
関数は、カスタム データ型を初期化する優れた方法です。あなたの場合、値default_entry_from_width(n)
を返すfunction を作成できます。entry_type
type entry_type is record
state: std_logic_vector;
end record;
function default_entry_from_width(width: natural) return entry_type is
variable return_vector: std_logic_vector(width-1 downto 0);
begin
for i in return_vector'range loop
return_vector(i) := '1' when i <= width/2 else '0';
end loop;
return (state => return_vector);
end;
constant ENTRY_1: entry_type := default_entry_from_width(3); -- return 011
constant ENTRY_2: entry_type := default_entry_from_width(4); -- return 0011
もう 1 つの方法は、事前に定義された N の値を使用して、集計で定数を初期化することです。
constant N: natural := 4;
constant ENTRY_3: entry_type := (
state => (
N-1 downto N/2 => '1',
N/2-1 downto 0 => '0'
)
);