Packages are contained in a library. For example, in the library called IEEE, there are packages called std_logic_1164, std_logic_unsigned and std_logic_arith. There is a library called WORK which is your default working directory. It is so fundamental that it does not have to be declared. The WORK library is the directory in which you store your projects. You can declare it with the statement:
LIBRARY work;
This is not necessary however.
Packages are a convenient place to locate your function prototypes and implementations. They can the be called from a design without declaring them as long as your design contains the statement: USE work.package_name.all;
Packages are made up of two parts, the Declarative part and the Body. The general form for the package is:
-- Declarative part
PACKAGE package_name IS
{function prototypes and component declarations}
END package_name;
-- Body of package – The place where function implementations are located.
PACKAGE BODY package_name IS
{function implementations}
END package_name;
Package example
LIBRARY ieee;
USE ieee.std_logic_1164.all;
PACKAGE mypack IS
-- Function prototype
FUNCTION lsl(in1: std_logic_vector)
RETURN std_logic_vector;
-- There may be any number of function prototypes
END mypack;
PACKAGE BODY mypack IS
FUNCTION lsl(in1: std_logic_vector)
RETURN std_logic_vector IS
VARIABLE d: std_logic_vector(3 downto 0);
BEGIN
FOR i IN 0 TO 2 LOOP
d(i + 1) := in1(i);
END LOOP;
d(0) := ‘0’;
RETURN d;
END lsl;
END mypack;
This package should be compiled in the same directory where projects that use it are located. The compiling of a package takes much less time than it normally takes. Don’t be surprised when it appears to terminate early.
Using the package
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE work.mypack.all;
ENTITY pack_try IS
PORT(a: IN std_logic_vector(3 downto 0);
b: OUT std_logic_vector(3 downto 0));
END pack_try;
ARCHITECTURE trial OF pack_try IS
BEGIN
b <= lsl a;
END trial;
0 comments