vhdl "parse error, unexpected FOR"

3k views Asked by At

I try to write programm on vhdl in ise 14.4 for crc16 calculation but dont understand why get "parse error, unexpected FOR" in it. Tried to put it into process but it dont works too.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;


entity crc16 is port(
clk : in STD_LOGIC:='0');
end crc16;

architecture Behavioral of crc16 is
signal data:std_logic_vector(15 downto 0):="1010101010101010";
signal ext_data:std_logic_vector(31 downto 0);
signal crc16_original:std_logic_vector(15 downto 0):="1100000000000010";
signal crc16:std_logic_vector(15 downto 0);
signal position:std_logic_vector(5 downto 0);
signal crc_out:std_logic_vector(14 downto 0);
signal i:std_logic_vector(5 downto 0);

begin


for i in 1 to 15 loop
    ext_data(i+16)<=data(i);
end loop;

for i in 1 to 15 loop
    ext_data(i)<='0';
end loop;

while ext_data > "111111111111111" loop
        for i in 0 to 31 loop
            if ext_data(i)="1" position=i;
        end loop;

    crc16<= crc16_original srl 31-position;
    ext_data<=ext_data xor crc16;
end loop;

for i in 0 to 14 loop
    crc_out(i)<=ext_data(i);
end loop;


end Behavioral;
1

There are 1 answers

2
Morten Zilmer On

There are several issues to point out:

  • The for-loop must be in a process, so that is likely to cause the “parse error, unexpected FOR” that you see.

  • The relation compare with > may give unexpected result for std_logic_vector, so you may take a look at the numeric_std package for casting as for example unsigned(std_logic_vector) before comparison is made.

  • Compare ext_data(i) = "1" is illegal, since "1" is taken as std_logic_vector, where as ext_data(i) is std_logic; instead ext_data(i) = '1' will compile.

  • Illegal construction around if ext_data(i) = "1" position=i;, since no then etc.

  • There is an signal with identifier i, which i is also used as loop variable, with the result that position <= i is taken as an integer assign to std_logic_vector; use different names for signals and loop variables.

  • Assign to signal is not position = i but position <= i, like elsewhere.

  • Expression 31-position mixes integer and std_logic_vector, which can't be done with the selected packages. Use casting with unsigned.

  • The ext_data<=ext_data xor crc16 uses different size arguments, since ext_data is 32 bits and crc16 is 16 bits; this does probably not yield the expected result.

  • srl is not defined for std_logic_vector (VHDL-2002), so consider casting with unsigned for well-defined behavior.

  • Assuming that that your code is "sandbox" code, since it has no outputs.

Based on the above, you may consider doing some initial experiments with smaller designs, in order to get familiar with the different VHDL constructions, and learn how this simulates and maps to hardware; remember VHDL is a "Hardware Description Language" and not a programming language.

Below is some code that compiles in ModelSim, but is unlikely to give the expected result:

library ieee;
use ieee.std_logic_1164.all;

entity crc16 is port(
  clk : in std_logic := '0');
end crc16;


library ieee;
use ieee.numeric_std.all;

architecture Behavioral of crc16 is
  signal data : std_logic_vector(15 downto 0) := "1010101010101010";
  signal ext_data : std_logic_vector(31 downto 0);
  signal crc16_original : std_logic_vector(15 downto 0) := "1100000000000010";
  signal crc16 : std_logic_vector(15 downto 0);
  signal position : std_logic_vector(5 downto 0);
  signal crc_out : std_logic_vector(14 downto 0);
  signal i_sig : std_logic_vector(5 downto 0);

begin

  process (clk) is
  begin
    if rising_edge(clk) then

      for i in 1 to 15 loop
        ext_data(i+16) <= data(i);
      end loop;

      for i in 1 to 15 loop
        ext_data(i) <= '0';
      end loop;

      while ext_data > "111111111111111" loop
        for i in 0 to 31 loop
          if ext_data(i) = '1' then
            position <= i_sig;  -- TBD[Probably not right code, but compiles]
          end if;
        end loop;
        crc16 <= std_logic_vector(unsigned(crc16_original) srl (31 - to_integer(unsigned(position))));
        ext_data <= ext_data xor crc16;
      end loop;

      for i in 0 to 14 loop
        crc_out(i) <= ext_data(i);
      end loop;

    end if;
  end process;

end Behavioral;