[转帖]VHDL中Configuration

来源:http://waxman.ycool.com/post.1804338.html

VHDL配置(Configuration)语句描述层与层之间的连接关系以及实体与构造体之间的对应关系。设计者可以利用这种配置语句来选择不同的构造体,使其与要设计的实体相对应。在仿真某一个实体时,可以利用配置来选择不同的构造体,进行性能对比试验,以得到性能最佳的构造体。

最简单的配置语句,结构如下:

CONFIGURATION 配置名 OF 实体名 IS

       FOR  为实体选配的构造体名

       END FOR;

END 配置名;

举例说明:

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating

---- any Xilinx primitives in this code.

--library UNISIM;

--use UNISIM.VComponents.all;



entity counter is

port (load, clear, clk : in std_logic;

data_in :
in integer;

data_out :
out integer);

end counter;



-----------------------------------------------------------------------------------

----计数器count_255,计数范围:0255

-----------------------------------------------------------------------------------

architecture count_255 of counter is



begin

process(clk,clear,load)

variable count:integer :=0;

begin

if (clear = '1') then

count:
=0;

elsif(load
= '1') then

count:
=data_in;

elsif((clk
'event)and(clk = '1')and(clk'last_value = '0'))then

if(count = 255)then

count:
=0;

else

count :
= count + 1;

end if;

end if;



data_out
<= count;



end process;



end count_255;



-----------------------------------------------------------------------------------------

----计数器count_64K,计数范围:065535

-----------------------------------------------------------------------------------------

architecture count_64K of counter is



begin

process(clk)

variable count:integer :=0;

begin

if (clear = '1') then

count:
=0;

elsif(load
= '1') then

count:
=data_in;

elsif((clk
'event)and(clk = '1')and(clk'last_value = '0'))then

if(count = 65535)then

count:
=0;

else

count :
= count + 1;

end if;

end if;



data_out
<= count;



end process;



end count_64K;



------------------------------------------------------------------------------------------

----配置1,small_count,实体counter对应结构体count_255

------------------------------------------------------------------------------------------

configuration small_count of counter is

for count_255

end for;

end small_count;



------------------------------------------------------------------------------------------

----配置2,big_count,实体counter对应结构体count_64K

------------------------------------------------------------------------------------------

configuration big_count of counter is

for count_64K

end for;

end big_count;

       上面的例子中,一个计数器实体可以实现两个不同的构造体配置。这里需要注意的是,为了达到这个目的,计数器实体中,对装入计数器和构成计数器的数据位宽度不应做具体的说明,只将输入和输出数据作为integer(整型数据)来对待。这样就可以支持多种形式的计数器(如例中8位计数器和16位计数器)。

       除了上面所列举的很简单的实体对应构造体的配置以外呢,配置语句还有另一种功能,就是可以对元件例化(Component instance)语句进行配置。这是一种低层次的配置。通过这种配置方式,可以为同一个例化元件选择不同的例化方式。

       本来想写出这种配置语句的语法结构,不过,太复杂了,写了看得都头疼,还是看例子吧,便于理解,又方便实用。下面是《VHDL Golden Reference》上的一个例子:

----------------------------------------------

----------------------------------------------

---- 配置语句例2 -----

---- 2007年07月20日 -----

----------------------------------------------

----------------------------------------------



use Work.Types.all;



----------------------------------------------

---- 实体Top说明

----------------------------------------------

entity Top is -- Top level H/W description

port (A, B: in Int8; F, G: out Int8);

end Top;



----------------------------------------------

----实体Top对应的结构体Structure

----------------------------------------------

architecture Structure of Top is



component Blk

port (A: in Int8; F: out Int8);

end component;



begin



B1: Blk
port map (A, F);--元件例化,标号B1

B2: Blk
port map (B, G);--元件例化,标号B2



end Structure;





use Work.Types.all;

----------------------------------------------

---- 实体Blk说明

----------------------------------------------

entity Blk is -- Pre-synthesis

port (A: in Int8; F: out Int8);

end Blk;



----------------------------------------------

----实体Blk对应的结构体RTL

----------------------------------------------

architecture RTL of Blk is

begin

...

end RTL;







library IEEE;

use IEEE.Std_logic_1164.all;



entity GateLevelBlk is -- Post-synthesis

port (IP: in Std_logic_vector(7 downto 0);

OP:
out Std_logic_vector(7 downto 0));

end GateLevelBlk;



architecture Synth of GateLevelBlk is

begin

...

end Synth;



use Work.Types.all;



configuration TopMixed of Top is---TopMixed是配置名,Top是实体名

for Structure ---Structure是结构体名,是和实体Top相对应的结构体

for B1: Blk ---B1和B2是结构体structure中的元件例化语句的标号

use entity Work.Blk(RTL);--- 此语句说明,在元件例化的时候,利用用户自定义

---的实体blk来例化,其结构体是RTL

end for;

for B2: Blk

use entity Work.GateLevelBlk(Synth)--- 此语句说明,元件例化B2时,利用实体

---GateLevelBLK对应的Synth构造体来例化

port map (IP => To_Vector(A),

To_Int8(OP)
=> F);

end for;

end for;

end TopMixed;



use Work.Types.all;



entity Test is -- Test bench for Top

end Test;



architecture Bench of Test is



component Top

port (A, B: in Int8; F, G: out Int8);

end component;



signal A, B, F, G: Int8;



begin

...

Inst: Top
port map (A, B, F, G);

end Bench;



configuration TestMixed of Test is

for Bench

for all: Top ---对于上面所有Top对应的标号,都用下面的use语句来进行例化

use configuration Work.TopMixed;---此语句说明,用配置TopMixed来进行例化

end for;

end for;



end TestMixed;

配置的另一个例子见西电 侯伯亨 VHDL的书,30~31页例2-15~例2-18。

原文地址:https://www.cnblogs.com/zlh840/p/2101609.html