在使用泛型合成代码时,我遇到了一个问题:我的实体是:
entity MyEntity is
generic(
OUTWIDTH : integer range 8 to 64;
NBREG : integer range 2 to 8);
port(
port1 ....
port2 ....
);
end entity;
architecture rtl of MyEntity is
constant KEEP_VAL : std_logic_vector(OUTWIDTH/8-1 downto 0) := (others=>'1'); -- used to compare my signal with (others=>'1')
signal keep : std_logic_vector((NBREG*OUTWIDTH/8)-1 downto 0);
begin
process(clk)
variable v1 : integer range 0 to NBREG-1
begin
if(rising_edge(clk)) then
--SOME CODE
....
....
-- The comparison I want to do :
if(keep((v1+1)*(OUTWIDTH/8)-1 downto v1*(OUTWIDTH/8)) = KEEP_VAL) then -- the line where the error appears
-- DO sthg
end if;
end process;
end rtl;为了继续,我想知道是否具有泛型宽度(OUTWIDTH)的信号的所有位数都是'1‘。前面的代码在模拟中运行良好,但不需要合成。synplify for Libero:@E: CD289 :期待常量表达式
我想我可以用一个函数(每个位上的for循环并与‘1’进行比较)来完成它,但是还有其他的“直接”选项吗?
谢谢。
发布于 2017-03-24 14:35:53
尽管你的问题没有得到minimal complete verifiable example的支持,所以很难正确地帮助你,我可以做一个假设。
首先:很容易编写出模拟正确,但不会合成的VHDL。你必须专门为合成写VHDL。
合成器给出的问题很可能是由变量v1引起的。这条线很难合成:
if(keep((v1+1)*(OUTWIDTH/8)-1 downto v1*(OUTWIDTH/8)) = KEEP_VAL)这条单行将变量(=异步)算法(例如v1*(OUTWIDTH/8) )与多路复用器和比较操作结合在一起。你想怎样才能在逻辑上实现这一点?先是多路,然后比较?所有的比较,然后选择正确的结果?
可能更好的做法是分离操作:实现多路复用器(使用信号选择,而不是变量)和比较器。
发布于 2017-03-24 14:47:49
一些合成器将无法使用非恒定值来指定切片的范围。您可以做的一件事是将数组映射到2d数组中,并使用非常量索引来访问所需的内容,而不需要任何特殊的切片。
type keep_sliced_type is array(natural range <>) of std_logic_vector(outwidth/8-1 downto 0);
signal keep_sliced : keep_sliced_type(0 to nbreg-1);
...
g_map : for i in 0 to nbreg-1 generate
begin
keep_sliced(i) <= keep(i*outwidth/8+outwidth/8-1 downto i*outwidth/8); --range is composed entirely of constants
end generate;
...
if keep_sliced(v1)=keep_val then --replaces your erroring line此外,使用变量通常是个坏主意,但我在这里不会太深入。公平的警告,我刚在答案框里写了这段代码。它可能有轻微的语法错误。
https://stackoverflow.com/questions/43001563
复制相似问题