我的系统由几个必须连接到总线的组件组成。然而,为了保持系统总线独立,我给系统一个通用的总线端口,我通过一个总线专用模块运行,该模块在我的系统和特定总线之间进行转换。因此,通过切换平移模块很容易将整个系统连接到不同的总线。
但是,我不想每次都经历将系统与翻译模块连接的麻烦。因此,我想知道是否可以从泛型参数中实例化模块,并将其类型用于体系结构的输出。
通过一点插图,整体变得更加清晰,我的翻译模块具有以下“签名”。
entity translate<BusName>
port(toSystem: out toSystem_t,
fromSystem: in fromSystem_t,
toBus: out to<BusName>_t,
fromBus: in from<BusName>_t
end entity;
我现在想要构建一个包含系统和翻译器的实体,基于泛型,有点像这样:
entity entireSystem is
generic(busType := translate<BusName>)
port(toBus: out to<BusName>_t,
fromBus: in from<BusName>_t)
end entity
architecture genArc of entireSystem is
signal toTrans: fromSystem;
signal fromTrans: toSystem;
begin
system: system(toTrans,fromTrans)
translator: translate<BusName>(
fromTrans,
toTrans,
toBus,
fromBus
)
end architecture;
我的问题是:
我可以使用通用参数直接实例化组件,还是必须转到if generic=xxx generate
路径?我可以从通用参数派生端口类型。
最好是我可以使用一个通用参数来确定端口和实体,这样就无法通过事故为实体选择错误的类型。可以使用函数从泛型参数派生类型。
答案 0 :(得分:2)
我不这么认为,不。
如果要根据泛型实例化不同的内容,则必须使用if..generate
。
泛型可以对端口类型产生的唯一影响是改变宽度。您无法根据通用切换(比方说)integer
和boolean
。
答案 1 :(得分:0)
Can I use a generic parameter to directly instantiate a component,
or do I have to go the if generic=xxx generate path?
您可以在模块实例化中使用generic map
语法将总线大小传递给子组件。即:
u_system: system
generic map ( INPUT_WIDTH => INPUT_WIDTH, OUTPUT_WIDTH => OUTPUT_WIDTH )
port map ( ... )
在顶层,您需要使用两个泛型而不是一个。
或者,假设您的顶级组件必须与子组件具有相同的总线大小,您可以尝试在包文件中执行此操作,并使用函数调用来定义总线大小。即:
package pack is
-- # Define support bus name here
constant BusA : integer := 0;
...
constant BusZ : integer := 25;
-- # Bus name here
constant busname : integer := BusA;
-- # Input and Output Width
constant IWIDTH : integer := getIWIDTH( busname )
constant OWIDTH : integer := getOWIDTH( busname )
-- # Function declaration
function getIWIDTH( ii: integer ) return integer;
function getOWIDTH( ii: integer ) return integer;
end pack;
package body pack is
function getIWIDTH( ii: integer ) return integer is
variable oo : integer;
begin
-- # get iwidth here
return oo;
end function;
function getOWIDTH( ii: integer ) return integer is
variable oo : integer;
begin
-- # get owidth here
return oo;
end function;
end package body;