我需要使用“if-else”或“case”设置常量的值,并根据另一个常量的值选择不同的常量值。这在 VHDL 中可能吗?这将是模拟开始时常量值的一次性更改...示例:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity bridge is
generic (
burst_mode :std_logic := '0'
);
end entity;
architecture rtl of bridge is
constant fifo_aw_wdata :natural := 2 when (burst_mode = '0') else 5;
begin
-- fifo: entity work myfifo
-- generic map(
-- aw => fifo_aw_wdata
-- )
-- port map(
-- ...
-- );
end architecture;
Run Code Online (Sandbox Code Playgroud)
上面的 VHDL 代码给出了错误信息:
Error ';' is expected instead of 'when'
Run Code Online (Sandbox Code Playgroud)
在 Verilog 中,做这种事情很容易……所以我认为 VHDL 也有机会做到这一点?Verilog 示例:
module #(parameter burst_mode = 1'b0) bridge;
localparam fifo_aw_wdata = (!burst_mode) ? 2 : 5;
// fifo myfifo #(.aw(fifo_aw_wdata)) ( ...);
endmodule;
Run Code Online (Sandbox Code Playgroud)
这个解决方案有点奇怪,但它有效:
architecture rtl of bridge is
function setup1(s:std_logic; i0:integer; i1:integer)
return integer is
begin
if s = '1' then
return i1;
else
return i0;
end if;
end function;
constant fifo_aw_wdata :natural := setup1(burst_mode, 2, 5);
begin
-- fifo: entity work myfifo
-- generic map(
-- aw => fifo_aw_wdata
-- )
-- port map(
-- ...
-- );
end architecture;
Run Code Online (Sandbox Code Playgroud)