Packages and Subprograms
Organize VHDL with reusable packages, functions and procedures.
Why Use a Package
A package groups what must be shared between several VHDL files:
- custom types;
- common constants;
- subtypes;
- function and procedure declarations;
- component declarations, when the project uses them.
Without a package, the same definitions are copied into several architectures. That often creates inconsistencies.
Package Declaration
The package declaration exposes the interface: what other files can use.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
package video_pkg is
subtype t_color is unsigned(7 downto 0);
type t_rgb is record
red : t_color;
green : t_color;
blue : t_color;
valid : std_logic;
end record t_rgb;
constant