在网上流传的介绍VHDL Coding Style的文章中,一般是不建议在可综合的代码中使用变量的,这大概是由于variable具有局部作用域、赋值立即生效、仿真工具支持的不够等几个原因。但最近看到几段VHDL代码,大量使用variable,且使用方式非常规范。在一个prcoess中进行组合逻辑的设计,在另一个prcoess中使用寄存器进行时序逻辑的设计。在使用变量的process中,一般是如下的处理流程,
- Latch the current value
- 各类组合逻辑
- Combinatorial outputs before the reset
- Reset
- Register the variable for next clock cycle
- Registered Outputs
comb : process (localMac, r, rst, rxMaster, txSlave) is
variable v : RegType;
variable i : natural;
begin
-- Latch the current value
v := r;
-- Reset the flags
v.rxSlave := AXI_STREAM_SLAVE_INIT_C;
if txSlave.tReady = '1' then
v.txMaster.tValid := '0';
v.txMaster.tLast := '0';
v.txMaster.tUser := (others => '0');
v.txMaster.tKeep := (others => '1');
end if;
-- State Machine
case r.state is
--
end case;
-- Combinatorial outputs before the reset
rxSlave <= v.rxSlave;
-- Reset
if (rst = '1') then
v := REG_INIT_C;
end if;
-- Register the variable for next clock cycle
rin <= v;
-- Registered Outputs
txMaster <= r.txMaster;
end process comb;
seq : process (clk) is
begin
if rising_edge(clk) then
r <= rin after TPD_G;
end if;
end process seq;
free_range_vhdl.pdf
11.4 Signals vs. Variables

版权声明:本文为linbian1168原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。