包中枚举类型的声明

Declaration of an enumeration type in a package

我更喜欢在包中声明一个枚举类型,这样我就可以在多个实体中使用它。这是我的简化代码:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
use work.polar_package;

entity Decoder is
    port (
        clk : in std_logic;
        reset : in std_logic
    );
end entity Decoder;

architecture behavioral of Decoder is
    signal state : polar_package.state_type;
begin
    top_modul : process (clk)
    begin
        if clk = '1' and clk'event then
            if reset = '1' then
                state <= p0;
            else

            end if;
        end if;
    end process top_modul;
end architecture behavioral;

并且我在包“polar_package”中声明并定义了“state_type”如下:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

package polar_package is
    type state_type is (p0 , p1 , p2);
end package polar_package;

package body polar_package is

end package body polar_package;

但是,我看到以下编译错误: 未知标识符“p0”

有什么解决方法吗?

尝试包括整个包,

use work.polar_package.all;

或者,如果你想更明确,只包括你需要的类型:

use work.polar_package.state_type;

请尝试:

状态 <= polar_package.p0;