嗨,大家好,我有以下包装,由我自己定义的包装VHDL包含错误
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_misc.all;
package util_pkg is
function log2c(n : natural) return natural;
end package util_pkg;
package body util_pkg is
function log2c(n : natural) return natural is
variable temp : natural := n;
variable ret_val : natural := 0;
begin
while temp > 1 loop
ret_val := ret_val + 1;
temp = temp/2;
end loop;
return ret_val;
end function log2c;
end package body util_pkg;
,而我的设计是
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_misc.all;
use work.util_pkg.all;
entity ldz is
generic(n : natural); --i can assume n > 1
port(x : in std_logic_vector(n - 1 downto 0);
y : out std_logic_vector(log2c(n) - 1 downto 0));
end entity ldz;
-- Example
architecture ldz_arch of ldz is
function ldz_count(x : unsigned) return natural is
n_ldz : natural := 0;
begin
for i in x'high to 0 loop
if(x(i) = '1') then
return x'length - i - 1;
end if;
end loop;
return x'length - 1;
end function ldz_count;
begin
y <= std_logic_vector(to_unsigned(ldz_count(to_unsigned(x)));
end architecture ldz_arch;
当我尝试验证语法与此NCVHDL的预是错误我得到
unit (UTIL_PKG) not found in library (WORKLIB)
但是这样的单位(包)是在同一个设计库中。 档案是util_pkg.vhd
而设计是ldz.vhd
什么是错的?
确保你在'ldz.vhd'之前编译了软件包,并确保通过添加'-work work'将你的软件包编译到工作库中。 – 0xMB
您的log2c功能不正确。例如:n = 5d = 101b。它迭代2次并将ret_val递增为2,但log2ceil(5)不是2,它是3. – Paebbels
如果x大于1位,则此循环'for i in x'high to 0 loop' has a empty range。 – Paebbels