我该如何编写一个代码段,以评估一个通用类型,并相应地创建(或不创建)属性?
示例:
if G_MY_GENERIC then
attribute my_attribute_typ : string;
attribute my_attribute_typ of signal_having_an_attr : signal is "value";
else
--nothing is created
end if;
我该如何编写一个代码段,以评估一个通用类型,并相应地创建(或不创建)属性?
示例:
if G_MY_GENERIC then
attribute my_attribute_typ : string;
attribute my_attribute_typ of signal_having_an_attr : signal is "value";
else
--nothing is created
end if;
相反,你必须使用以下方式来有条件地设置属性(虽然繁琐但可以达到效果):
signal asvRam : svRam_at(0 to gc_nFifoDepth-1) := (others => (others => '0'));
type svStr_at is array(boolean) of string(0 to 10);
constant c_svRamStyle : svStr_at := (false => " ", true => "distributed");
attribute ram_style : string;
attribute ram_style of asvRam : signal is c_svRamStyle(gc_bDistributedRam);
完全可以编写类似的代码,但该属性仅在生成语句的范围内可见。
g_something: if test_condition generate
attribute my_attribute_typ : string;
attribute an_attribute of my_attribute_typ: signal is "value";
begin
-- attribute is visible in this scope
p_my_process: process(clk)
begin
-- attribute is also visible here
end process;
end generate;
-- but not here
基本上:这正是 VHDL 不起作用的方式。在 VHDL 中,您声明要使用特定硬件位,然后综合器尝试连接这些硬件位。任何动态创建硬件的迹象,例如 for ... generate
循环,本质上只是一种外观:语法糖可以减轻痛苦。
您可以有条件地对信号/变量进行赋值:
process (sig1, sig2, enable) is
begin
if enable = '1'
then
out <= sig1;
else
out <= sig2;
end if;
end process;