Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 use 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?

like image 368
Emil Eriksson Avatar asked Dec 28 '25 21:12

Emil Eriksson


1 Answers

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.

like image 57
Charles Steinkuehler Avatar answered Dec 30 '25 22:12

Charles Steinkuehler