1.定义
程序包:为了使已定义的常数、数据类型、元件调用说明、子程序等能被更多的其他设计实体方便地访问和同享,可将它们收集在一个vhdl程序包中。
2.语法结构
多个程序包可以并入一个vhdl库中
一个程序包至少应该包含以下结构中的一种:
1.常数说明
2.数据结构类型说明
3.元件定义
4.子程序
语法结构:
package 程序包名 is
程序包首说明部分
end 程序包名;
package boby 程序包名 is
程序包体说明部分以及包体内容
end 程序包名;
3.示例
程序包文件pack.vhd,该程序包属于sp_package库,需在编译前处理下该文件的属性
library ieee;
use ieee.std_logic_1164.all;
package pack is
constant width_value:integer :=8;
constant depth_value:integer:=10;
type mem_arr is array(2**depth_value -1 downto 0) of std_logic_vector( width_value-1 downto 0);
component sub
port(
clk:in std_logic;
wre:in std_logic;
addr:in std_logic_vector(depth_value -1 downto 0);
din:in std_logic_vector( width_value-1 downto 0);
dout:out std_logic_vector( width_value-1 downto 0)
);
end component;
end pack;
sub.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
library sp_package;
use sp_package.pack.all;
entity sub is
port(
clk:in std_logic;
wre:in std_logic;
addr:in std_logic_vector(depth_value -1 downto 0);
din:in std_logic_vector( width_value-1 downto 0);
dout:out std_logic_vector( width_value-1 downto 0)
);
end sub;
architecture rtl of sub is
signal mem:mem_arr;
begin
process(clk)begin
if(rising_edge(clk))then
if(wre='1')then
mem(conv_integer(addr))<=din;
end if;
end if;
end process;
process(clk)begin
if(rising_edge(clk))then
if(wre='0')then
dout<=mem(conv_integer(addr));
end if;
end if;
end process;
end rtl;
top.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
library sp_package;
use sp_package.pack.all;
entity top is
port(
clk:in std_logic;
wre:in std_logic;
addr:in std_logic_vector(depth_value -1 downto 0);
din:in std_logic_vector( width_value-1 downto 0);
dout:out std_logic_vector( width_value-1 downto 0)
);
end top;
architecture rtl of top is
begin
uut:sp_package.pack.sub
port map(
clk=>clk,
wre=>wre,
addr=>addr,
din=>din,
dout=>dout
);
end rtl;
4.综合结果
使用高云综合工具GowinSynthesis综合为一个SP