使用包含 std_logic 的泛型在 Verilog 中实例化 VHDL
Instantiate VHDL in Verilog with generics containing std_logic
我想替换 Verilog 模块中的一些通用同步器代码 (for this reason)。代码是一个标准的 2-flop 同步器。
always @ (posedge clk_i or posedge rst)
begin
if (rst)
begin
rx_sync_tmp <= 1'b1;
rx_sync <= 1'b1;
end
else
begin
rx_sync_tmp <= rx_i;
rx_sync <= rx_sync_tmp;
end
end
VHDL中的实体声明也很简单:
entity synchroniser_d_flip_flop_n is
generic(
NUM_STAGES : natural := 2;
RESET_ACTIVE_STATE : std_logic := '1';
DEFAULT_AFTER_RESET : std_logic := '0'
);
port(
clk_i : in std_logic;
reset_i : in std_logic;
d_i : in std_logic;
q_o : out std_logic
);
end synchroniser_d_flip_flop_n;
但是如果我尝试以明显的方式在 verilog 中实例化它:
synchroniser_d_flip_flop_n #(2, 1, 1) rx_sync_block(
clk_i,
rst,
rx_i,
rx_sync
);
Altera Quartus-II 15.0.2 给出以下错误(目标是 MAX10):
Error (10517): VHDL type mismatch error at synchroniser_d_flip_flop.vhd(9): std_logic type does not match integer literal
Error (10517): VHDL type mismatch error at synchroniser_d_flip_flop.vhd(10): std_logic type does not match integer literal
也就是说,似乎不接受1作为std_logic。
Xilinx seems to suggest 包含 std_logic 的 VHDL 泛型无法在 Verilog 中实例化:
Generics (Parameters) Mapping Following VHDL generic types (and their
Verilog equivalents) are supported.
integer
real
string
boolean
Note Any other generic type found on mixed language boundary is
considered an error.
tl;博士
是否有标准方法可以在 Verilog 文件中实例化包含 std_logic 的 VHDL 泛型?如果没有,建议的解决方法是什么?
没有标准 - 您必须检查您的模拟器文档。 Cadence 文档说 "The LSB of the Verilog integer parameter is mapped to a single-bit std_logic generic"。相关的 table 对 SV 毫无帮助,但我很确定这也适用于普通 Verilog。
MoldelSim/QuestaSim 文档说您可以在 Verilog 或 SV 中实例化 VHDL 设计单元,如果 "The generics are of type bit, bit_vector, integer, real, std_logic, std_logic_vector, vl_logic, vl_logic_vector, time, physical, enumeration, or string"。
isim 一直有点像火车残骸 - 他们还在 Vivado 中使用它吗?如果您坚持使用它,我会重写 VHDL 以采用整数泛型。
试试这个:
synchroniser_d_flip_flop_n #(2, 4'd3, 4'd3) rx_sync_block(
clk_i,
rst,
rx_i,
rx_sync
);
std_logic
可以采用 9 个枚举值中的任何一个:{U,X,0,1,Z,W,L,H,-}
因此对于 4'd3
,您指定的是此列表中的第 3 个值。对于逻辑 0,您会选择 4'd2
.
我想替换 Verilog 模块中的一些通用同步器代码 (for this reason)。代码是一个标准的 2-flop 同步器。
always @ (posedge clk_i or posedge rst)
begin
if (rst)
begin
rx_sync_tmp <= 1'b1;
rx_sync <= 1'b1;
end
else
begin
rx_sync_tmp <= rx_i;
rx_sync <= rx_sync_tmp;
end
end
VHDL中的实体声明也很简单:
entity synchroniser_d_flip_flop_n is
generic(
NUM_STAGES : natural := 2;
RESET_ACTIVE_STATE : std_logic := '1';
DEFAULT_AFTER_RESET : std_logic := '0'
);
port(
clk_i : in std_logic;
reset_i : in std_logic;
d_i : in std_logic;
q_o : out std_logic
);
end synchroniser_d_flip_flop_n;
但是如果我尝试以明显的方式在 verilog 中实例化它:
synchroniser_d_flip_flop_n #(2, 1, 1) rx_sync_block(
clk_i,
rst,
rx_i,
rx_sync
);
Altera Quartus-II 15.0.2 给出以下错误(目标是 MAX10):
Error (10517): VHDL type mismatch error at synchroniser_d_flip_flop.vhd(9): std_logic type does not match integer literal
Error (10517): VHDL type mismatch error at synchroniser_d_flip_flop.vhd(10): std_logic type does not match integer literal
也就是说,似乎不接受1作为std_logic。
Xilinx seems to suggest 包含 std_logic 的 VHDL 泛型无法在 Verilog 中实例化:
Generics (Parameters) Mapping Following VHDL generic types (and their Verilog equivalents) are supported.
integer real string boolean
Note Any other generic type found on mixed language boundary is considered an error.
tl;博士
是否有标准方法可以在 Verilog 文件中实例化包含 std_logic 的 VHDL 泛型?如果没有,建议的解决方法是什么?
没有标准 - 您必须检查您的模拟器文档。 Cadence 文档说 "The LSB of the Verilog integer parameter is mapped to a single-bit std_logic generic"。相关的 table 对 SV 毫无帮助,但我很确定这也适用于普通 Verilog。
MoldelSim/QuestaSim 文档说您可以在 Verilog 或 SV 中实例化 VHDL 设计单元,如果 "The generics are of type bit, bit_vector, integer, real, std_logic, std_logic_vector, vl_logic, vl_logic_vector, time, physical, enumeration, or string"。
isim 一直有点像火车残骸 - 他们还在 Vivado 中使用它吗?如果您坚持使用它,我会重写 VHDL 以采用整数泛型。
试试这个:
synchroniser_d_flip_flop_n #(2, 4'd3, 4'd3) rx_sync_block(
clk_i,
rst,
rx_i,
rx_sync
);
std_logic
可以采用 9 个枚举值中的任何一个:{U,X,0,1,Z,W,L,H,-}
因此对于 4'd3
,您指定的是此列表中的第 3 个值。对于逻辑 0,您会选择 4'd2
.