开发者

Where to declare a constant or type used in an entity declaration?

If I haven't misunderstood this completely, a constant or type can not be declared at the top level of a file. Only packages, entities, architectures et.c. can be declared there. They can be declared in the entity but not before the port and generic clauses.

Often you would want to define a type or constant for us开发者_StackOverflow社区e in the port or generic clause of an entity but since this can't be declared at the top level of the file and not inside the entity either, where should this be declared?


Typically these are declared in a package which is included at the beginning of your file, just as you would include the standard VHDL packages ie:

library ieee;

use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;

use work.My_Custom_Types_Pkg.all;

entity My_Entity is
    port (
        ...

You may then use your custom types in port declarations and anywhere else in your entity.


Note that packages, entities, etc. do not have to be bound to a particular file. So the right place to put constants is in a package. The package and its body can exist in the same file as the entity/architecture or in a separate file. The entity and architecture can also exist in separate file(s) (this has been discussed elsewhere on SO)

Also, another gotcha for those new to VHDL, just because the package might be in the same file doesn't make it visible to entities/architectures in that file, you still have to use the package at the point that you declare the entity (or architecture, if you only need the definitions there).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜