VHDL结构
VHDL含义
- Very high speed integrated circuit Hardware Description Language
形象划分
外部 | 内部 |
---|---|
可视部分,端口 | 不可视本部分,内部功能,算法 |
内容划分
实体entity
- 类属说明
– 确定实体或者组件中需要的常量 - 端口说明
– 定义系统的输入输出端口
实体举例
类属说明可有可无
- 仅端口说明
entity ddfs is
port(
clk : in std_logic;
rst : in std_logic;
freq_data : in std_logic_vector (7 downto 0);
dout : out std_logic_vector (7 downto 0)
);
end ddfs;
- 类属和端口说明
entity mcu1 is
generic(
addrwidth : integer := 16
);
port(
add_bus : out std_logic_vector(addrwidth-1 downto 0)
);
end mcu1;
entity pgand2 is
generic(
trise : time := 1 ns;
tfall : time := 1 ns
) ;
port (
a1 : in std_logic ;
a0 : in std_logic ;
z0 : out std_logic
);
end entity pgand2;
generic划重点
- generic说明的参数可以在本组件中使用
- 直接用名字,比冰冷的数字贴心
- 可以从上层传下来,模块化之间的信息传递
- 可以任性的改一个而动所有
- 定义端口大小,数据位宽,物理特性,元件例化的数量等
- 必须放在port说明前面
说明
- 有的版本是支持end entity 实体名
- 我喜欢这一种,end的多了,起码你知道这是end的哪一个
- 综合器仅支持类型为仅支持类型为integer的类属值,其它的可以用于仿真
类属说明generic
generic(
常数名称 : 类型[:= 缺省值];
常数名称 : 类型[:= 缺省值];
...
);
端口说明port
port(
端口名称{,端口名称...} : 端口类型 数据类型;
);
- 设计实体与外界接口的描述
- 指明接口输入,输出类型等,如in,out,buffer,inout
- 指明端口的数据类型,如std_logic
端口类型
端口类型 | 方向 | 功能与含义 |
---|---|---|
in | 输入 | 数据只能从此端口流入 |
out | 输出 | 数据只能从此端口流出 |
inout | 双向 | in+out双重功能 |
buffer | 缓冲 | 数据能从此端口流出,但能回读 |
linkage | 链接 | 无方向,随心连 |
结构体architecture
结构体举例
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity count_3bit is
port(
clk : in std_logic;
rst_n : in std_logic;
cnt : out std_logic_vector(2 downto 0)
);
end entity count_3bit;
architecture arc_count_3bit of count_3bit is
--结构体说明部分
signal cnt_tmp: integer range 0 to 7;
--结构体功能描述部分
begin
process begin
wait until(clk'event and clk='1');
if( (rst_n='0') or (cnt_tmp=7))then
cnt_tmp <= 0;
else
cnt_tmp <= cnt_tmp + 1;
end if;
end process;
cnt <= conv_std_logic_vector(cnt_tmp, 3);
end architecture arc_count_3bit;
结构体语法
-
同一实体中可以有多个结构体,但是不能重名
-
结构体中说明的常数,信号等不能与实体端口名相同
结构体名称 of 实体名称 is
[说明语句;]
begin
并行功能描述语句
end [architecture] 结构体名称
结构体说明
- 常数说明
- 数据类型说明
- 信号说明
- 例化元件说明
- 子程序说明
结构体功能描述
- 元件例化语句
- 子程序调用语句
- 块语句
- 进程语句
- 信号赋值语句
库,程序包
库中可以预定义一些有用信息以供调用.
- 数据类型
- 子程序
- 设计实体
library 库名;
表示打开了相关的库.
--向本设计实体开放指定库中的特定程序包内对应的项目.
use 库名.程序包名.项目名;
--向本设计实体开放指定库中的特定程序包内的所有项目
use 库名.程序包名.all;
配置
配置主要为顶层设计实体指定结构体,或为参与例化的元件实体指定所希望的结构体.
每个实体可以拥有多个不同的结构体,而各个结构体的地位是相同的.那么到底实体要用哪个结构体呢?就由配置语句进行说明.