VHDL ::创建带有尺寸参数类型(vhdl :: creating a type with a s

2019-10-30 02:20发布

我想知道是有一种方式来确定的,在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型通用实体? )。

提前致谢!

Answer 1:

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断言:“我想补充的是,虽然你可以在VHDL使用n维数组,只有第一个可能是不受约束”。

相反,断言:

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;

该语句是不精确的并且涉及在该示例亚型声明在UNSIGNED的封装numeric_std类型声明延迟范围约束。 子类型的指示,需要由类型标记或显式或者提供一个约束。 这是唯一有效的子类型指示类型的标记是不受约束的类型。

不受约束的类型的子类型声明必须提供,就像如果你增加了一个约束

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标准1076至2008年5.3.2.2,-2002 / -1993 3.2.1.1。



文章来源: vhdl :: creating a type with a size parameter