VHDL你能在同一个文件中声明一个包和一个实体吗?

Wis*_*lil 5 entity vhdl package

我试图将包和实体放在同一个文件中,但它没有编译它给了我一个错误说:未知标识符std_logic,

有什么我应该做的把它们放在同一个文件中?

Mar*_*son 6

您在文件顶部提供的库声明适用于下一个设计单元(可能是您的包).

当您启动实体时,它是一个新的设计单元,并以空库空间开头,因此您必须再次放入库声明.如果在给定文件中放置多个实体,则会发生同样的情况 - 您必须为每个实体放置库子句.

VHDL编译器根本不关心任何文件是什么,它只对其中的单元进行操作.所以你可以entity在一个文件中有一些library声明,而architecture在另一个文件中.该库就不是那么需要在架构文件要重做,而他们在与实体.如果您只需要架构所需的库,那么它们可以包含在架构语句之前(无论您是在一个文件还是两个文件中):

library ieee; 
use ieee.std_logic_1164.all;
entity foo
port ( 
   bar: std_logic; 
   etc...);
end entity;

-- could start a new file here, or not.
use ieee.numeric_std.all; -- not needed for the entity as it doesn't use unsigned types
architecture a of foo is
    signal counter : unsigned (10 downto 0);
begin
...
end architecture;
Run Code Online (Sandbox Code Playgroud)