文章目录
前言
本文摘选自《FPGA之道》,一起看看作者总结的VHDL编写的注意事项。
VHDL编写注意事项
大小写不敏感
使用VHDL编程的时候,一定要注意,这是一种case insensitive的语言,即大小写不敏感的语言。例如如下几条信号声明的语句对于VHDL来说其实是完全一样的。
signal abc : std_logic;
signal Abc : std_logic;
signal ABC : std_logic;
SIGnal abC : std_LoGic;
SIGNAL ABC : STD_LOGIC;
所以如果你想通过大小写来区分你的信号或变量,肯定是会出错的。例如你想定义两个变量——A和a,这时,编译器会报告一个redefinition(重定义)的错误。
但是,至今为止发现的唯一一个例外就是高阻状态的表示——‘Z’,一定要写成大写,如果写成小写,很多编译器会报错,例如:
data <= a when en = ‘1’ else ‘z’; – error!
data <= a when en = ‘1’ else ‘Z’; – ok!
VHDL中的关键字
命名不能与关键字相同,这几乎是所有编程语言的要求,而VHDL由于是不区分大小写的语言,所以更是需要注意。以下列举了VHDL中的一些关键字,供大家参考:
abs access after alias all and architecture array assert attribute
begin block body buffer bus case component configuration constant
disconnect downto else elsif end entity exit file for function generate generic group guarded if impure in inertial inout is label library linkage literal loop map mod nand new next nor not null of on open or others
out package port postponed procedure process pure range record register
reject rem report return rol ror select severity signal shared sla sll
sra srl subtype then to transport type unaffected untis until use variable
wait when while with xnor xor active ascending ascending base delayed
driving driving_value event falling_edge high image last_active write
last_event last_value left leftof length low pos pred quiet writeline
reverse_range right rightof rising_edge simple_name stable succ transaction
val value bit bit_vector boolean character integer line natural positive
real signed std_logic std_logic_vector string text time unsigned endfile
file_close file_open read readline