i=0;
If rising_edge (clk) then
y(i)<=x(i) ;
i=:i+1;
end if;
像上面这样的块在功能块中是否可能?如果不是,是否有任何类似功能的子程序样式来实现这一点?
或者是否有任何可合成的"for 循环"用法而不是"if 语句"?
您可以使用过程:
procedure SetBits(signal clk : in std_logic; signal y : out std_logic_vector(7 downto 0)) is
begin
for i in 7 downto 0 loop
wait until (rising_edge(clk));
y(i) <= '1';
end loop;
end procedure;
然后像这样
sequential : process
begin
SetBits;
wait;
end process sequential;
不可以,函数中不能有时钟进程。不过,您可以使用循环:
if rising_edge(clk) then
for i in 0 to x'length - 1 loop
y(i) <= x(i); -- or whatever operation
end loop;
end if;
如果您确实需要,则只能将 for 循环部分包装在函数中:
function f(x : std_logic_vector) return std_logic_vector is
variable result : std_logic_vector(x'range);
begin
for i in x'range loop
result(i) := x(i); -- or whatever operation
end loop;
return result;
end function f;
if rising_edge(clk) then
y <= f(x);
end if;
当然,我假设您想做的不仅仅是分配位,否则您根本不需要循环或函数。