0

VHDL でサイズ パラメータを使用して型を定義する方法があったのではないかと考えていました。例えば

type count_vector(size: Natural) is unsigned (size-1 downto 0);

そして後で次のようなことをします

variable int : count_vector(32) := (others => '0');
variable nibble : count_vector(4) := (others => '0');

基本的に、「配列のような」型を定義する方法はありますか、それとも構文で許可されていませんか?

現在、再利用性のためにジェネリックを使用しようとしていますが、ジェネリック型付けを最大限に活用できるようにしたいと考えています (つまり、VHDL で型ジェネリック エンティティを記述できますか? )。

前もって感謝します!

4

1 に答える 1

4
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity foo is
     generic (
        constant INT_LEFT:    natural := 32;
        constant NIB_LEFT:    natural := 4
     );
     -- note entity declarative items are forward looking only
     -- a port declaration requires a type or subtype declared in a package
     -- you can also use a package for any constants

     -- a type or subtype can be declared as an entity declarative item here:
--     subtype int_size is unsigned(INT_LEFT downto 0);
--     subtype nib_size is unsigned(NIB_LEFT downto 0);
end entity;

architecture fum of foo is
    -- or as an architecture declarative item here:
    subtype int_size is unsigned(INT_LEFT downto 0);
    subtype nib_size is unsigned(NIB_LEFT downto 0);   

begin
USAGE:
    process 
        variable int:  int_size := (others => '0');
        variable nibble: nib_size := (others =>'0');
    begin
        int := int + 3;
        -- the function "+" is L: UNSIGNED, R: NATURAL
        --  int_size and nibble_size are subtypes of UNSIGNED
        Report integer'IMAGE(TO_INTEGER(int));
        -- ditto for TO_INTEGER
        nibble := nibble + 2;
        -- if int_size or nibble_size were types it would require
        -- operator functions for those types.
        Report integer'IMAGE(TO_INTEGER(nibble));
        wait;
    end process;

end architecture fum;

追加した:

これは、次の質問に対するコメントでの BennyBarns の主張への回答です。

主張に反して:

entity t1 is
end entity;

architecture foo of t1 is

    type typeI is array ( natural range <>, natural range <>) of integer;

begin
    process is
        variable sigI : typeI(0 to 1, 0 to 1);  -- 2D integer array
    begin
        sigI(0,0) := 1;
        sigI(0,1) := 2;
        sigI(1,0) := 3;
        sigI(1,1) := 4; 
        report "Initialized indiviually";
        report "sigI(0,0) = " & integer'IMAGE(sigI(0,0));
        report "sigI(0,1) = " & integer'IMAGE(sigI(0,1));
        report "sigI(1,0) = " & integer'IMAGE(sigI(1,0));
        report "sigI(1,1) = " & integer'IMAGE(sigI(1,1));
        sigI := ((11,12),(13,14));
        report "Initialized as an aggregate";
        report "sigI(0,0) = " & integer'IMAGE(sigI(0,0));
        report "sigI(0,1) = " & integer'IMAGE(sigI(0,1));
        report "sigI(1,0) = " & integer'IMAGE(sigI(1,0));
        report "sigI(1,1) = " & integer'IMAGE(sigI(1,1));
        wait;
    end process;
end architecture;

ステートメントは不正確であり、サブタイプ宣言の例では、パッケージ numeric_std の UNSIGNED の型宣言の遅延範囲制約に関連しています。サブタイプ表示には、タイプ マークによって提供されるか、明示的に制約が必要です。制約のないタイプであるサブタイプ表示タイプ マークに対してのみ有効です。

制約のない型のサブタイプ宣言は、追加したかのように制約を提供する必要があります

signal A: unsigned;

エンティティ foo の fum へのアーキテクチャ宣言項目として:

ghdl -a foo.vhdl
foo.vhdl:24:12: declaration of signal "a" with unconstrained array type "unsigned" is not allowed

そして、物事を面白くするために、インターフェースリストを特別なものにすることができます:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity fie is
    port (
        a:  in  unsigned
    );
end entity;

architecture fee of fie is

begin

EVAL:
    process (a)
    begin
        report "Fie:a range is " & integer'IMAGE(a'LEFT) & " to " & 
                                  integer'IMAGE(a'RIGHT) ;
    end process;

end architecture fee;

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity fie_tb is
end entity;

architecture fum of fie_tb is
    component fie is
        port (a: in unsigned);
    end component;

    signal aa:  unsigned (3 to 7);
begin

EUT: fie port map (a => aa);

end architecture;

「ルール」は、インデックス制約と離散範囲に関する LRM セクション、IEEE Std 1076-2008 5.3.2.2、-2002/-1993 3.2.1.1 にあります。

于 2013-08-15T02:35:49.917 に答える