需要将Verilog格雷码函数转换为vhdl
首先是Verilog:需要将Verilog格雷码函数转换为vhdl,vhdl,Vhdl,首先是Verilog: function [ADDR_WIDTH-1:0] gray_conv; input [ADDR_WIDTH-1:0] in; begin gray_conv = {in[ADDR_WIDTH-1], in[ADDR_WIDTH-2:0] ^ in[ADDR_WIDTH-1:1]}; end endfunction 下面是我将Verilog格雷码函数转换为vhdl的尝试: library ieee; use ieee.std_logic
function [ADDR_WIDTH-1:0] gray_conv;
input [ADDR_WIDTH-1:0] in;
begin
gray_conv = {in[ADDR_WIDTH-1],
in[ADDR_WIDTH-2:0] ^ in[ADDR_WIDTH-1:1]};
end
endfunction
下面是我将Verilog格雷码函数转换为vhdl的尝试:
library ieee;
use ieee.std_logic_1164.all;
entity bus_fifo_async is
generic(
ADDR_WIDTH : integer := 3;
DATA_WIDTH : integer := 32
);
port(
wr_rst_i : in std_logic;
wr_clk_i : in std_logic
);
end entity;
architecture rtl of fifty_shades_of_vhdl is
function gray_conv(din: std_logic_vector(ADDR_WIDTH-1 downto 0))
return std_logic_vector(ADDR_WIDTH-1 downto 0) is
begin
return ( din(ADDR_WIDTH-1) & (din(ADDR_WIDTH-2 downto 0)
xor din(ADDR_WIDTH-1 downto 1)));
end function;
begin
end architecture;
VHDL编译器“吐”在我身上。。。vhdl:44:35:此处不允许索引约束。答案是vhdl要求从函数返回std_逻辑向量时,std_逻辑向量的返回长度不受约束。这与verilog不同,verilog需要函数的受限返回类型 “返回标准逻辑向量”而不是“返回标准逻辑向量(添加宽度-1到0)”
您的代码有几个语法错误:2x个实体声明,额外;在端口列表的末尾。函数声明有一个返回值类型标记,并且没有子类型指示。这里只需删除子类型指示或创建std_logic_vector的子类型,用作类型标记。也可以像在函数中使用ADDR_WIDTH那样使用数组对象的LENGTH属性。优点是该函数适用于任何长度参数。请提供一个允许读者复制问题以及验证答案的方法。很棘手,好吧,我已经解决了。抱歉,我正在尝试剪切和粘贴所有需要的额外VHDL代码,但没有检查它。
library ieee;
use ieee.std_logic_1164.all;
entity bus_fifo_async is
generic(
ADDR_WIDTH : integer := 3;
DATA_WIDTH : integer := 32
);
port(
wr_rst_i : in std_logic;
wr_clk_i : in std_logic
);
end entity;
architecture rtl of fifty_shades_of_vhdl is
function gray_conv(din: std_logic_vector(ADDR_WIDTH-1 downto 0))
return std_logic_vector is
begin
return ( din(ADDR_WIDTH-1) & (din(ADDR_WIDTH-2 downto 0)
xor din(ADDR_WIDTH-1 downto 1)));
end function;
begin
end architecture;