for循环中的vhdl异步赋值

时间:2013-12-02 07:28:33

标签: for-loop asynchronous variable-assignment vhdl

我正在做这样的事情:

x        : in  STD_LOGIC_VECTOR(15 downto 0);

signal x_d: std_logic_vector(15 downto 0);

type inp_concat_array is array (0 to 15) of std_logic_vector(1 downto 0); 
signal inp_concat : inp_concat_array;

process (clk, reset)

begin

   if (rising_edge(clk)) then 

        if (reset = '1') then

            for i in 0 to 15 loop

                x_d(i) <= '0';  

            end loop;

        else 

            for i in 0 to 15 loop

                x_d(i) <= x(i); 

            end loop;

        end if;

   end if;


end process;



for j in 0 to 15 loop

    inp_concat(j) <= x(j) & x_d(j);

end loop;  

Xilinx ISE 14.2给出以下错误

“for”附近的语法错误 “loop”

附近的语法错误

我可以在FOR循环中使用异步赋值吗?

4 个答案:

答案 0 :(得分:2)

并发for循环必须使用generate语句,如:

inp_concat_loop : for j in 0 to 15 generate
  inp_concat(j) <= x(j) & x_d(j);
end generate;

或在David Koontzs回答的过程中。

答案 1 :(得分:1)

如果没有看到整个设计描述,回答您的问题可能会有点风险。您向我们提供了代码片段,并且没有语法错误的行号。代码片段包含三个for循环。

现在,如果此片段表示从设计单元(体系结构)中提取的连续片段,则表明您正在尝试在某个位置使用循环语句(for循环,适用于进程或子程序的顺序语句)适用于并发语句(体系结构体)。

为可能分析的内容提供缺失位:

library ieee;
use ieee.std_logic_1164.all;

entity asyn is
    port (
         x : in STD_LOGIC_VECTOR(15 downto 0);
         clk:    in std_logic;
         reset:  in std_logic
     );
 end entity;

architecture foo of asyn is
signal x_d: std_logic_vector(15 downto 0);

    type inp_concat_array is array (0 to 15) of std_logic_vector(1 downto 0);
    signal inp_concat : inp_concat_array;

begin 
    process (clk, reset)
    begin
        if (rising_edge(clk)) then
            if (reset = '1') then
                for i in 0 to 15 loop
                    x_d(i) <= '0';  
                end loop;
            else 
                for i in 0 to 15 loop
                    x_d(i) <= x(i); 
                end loop;
            end if;
        end if;
    end process;

    for j in 0 to 15 loop
        inp_concat(j) <= x(j) & x_d(j);
    end loop; 

end architecture;

使用不同的工具产生:

ghdl -a async.vhdl
async.vhdl:32:5: a generate statement must have a label
async.vhdl:32:22: 'generate' is expected instead of 'loop'

在适用于体系结构体中的并发语句的位置,唯一可以包含for关键字的语句是generate语句,它需要一个标签。

VHDL中没有要求预先消除语法错误的歧义(这就是为什么你有一个模糊的错误信息)。

另一种工具提供了更好的说明:

nvc -a async.vhdl
** Error: syntax error, unexpected for, expecting process
    File async.vhdl, Line 32
        for j in 0 to 15 loop
        ^^^

因此,如果你将for循环放在一个进程中,它就可以分析:

NEW_PROCESS:
    process (x,x_d)
    begin
        for j in 0 to 15 loop
            inp_concat(j) <= x(j) & x_d(j);
        end loop; 
    end process;

答案 2 :(得分:1)

以下是一个更简单,更简洁的解决方案的建议。仿真结果如下。

-----------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
-----------------------------------------------
entity test is
  port (
    clk, reset: in std_logic;
    x: in std_logic_vector(15 downto 0);
    --test signals:
    test: out std_logic_vector(1 downto 0);
    test_index: in natural range 0 to 15);
end entity;
-----------------------------------------------
architecture test of test is 
  signal x_d: std_logic_vector(15 downto 0);
  type inp_concat_array is array (0 to 15) of 
    std_logic_vector(1 downto 0); 
  signal inp_concat: inp_concat_array;
begin

  process (clk, reset)
  begin
    if rising_edge(clk) then 
      if reset = '1' then
        x_d <= (others => '0');  
      else 
        x_d <= x; 
      end if;
    end if;
  end process;

  gen: for i in 0 to 15 generate
    inp_concat(i) <= x(i) & x_d(i);
  end generate;

  test <= inp_concat(test_index);

end architecture;
-----------------------------------------------

enter image description here

答案 3 :(得分:0)

问题是你的异步for循环不在进程内,并且需要:这应该这样做

process(x,x_d)
begin
   for j in 0 to 15 loop
      inp_process(j) <= x(j) & x_d(j);
   end loop;
end process;