VHDL中用户自定义属性的使用指南
立即解锁
发布时间: 2025-08-16 01:28:55 阅读量: 1 订阅数: 6 


VHDL设计指南:从入门到精通
### VHDL 中用户自定义属性的使用指南
在 VHDL 中,预定义属性可以提供关于类型、对象或其他元素的信息。同时,VHDL 还允许我们通过用户自定义属性,为模型中的元素添加额外的信息。这些信息可以是物理设计信息、布局约束或综合信息等。
#### 1. 用户自定义属性的声明
定义属性的第一步是使用属性声明来声明属性的名称和类型。语法规则如下:
```plaintext
attribute_declaration ⇐ attribute identifier : type_mark ;
```
属性声明将标识符定义为代表一个用户自定义属性,该属性可以取指定类型的值。类型可以是任何 VHDL 类型,但不能是访问类型、文件类型、受保护类型,也不能是包含这些类型子元素的复合类型。以下是一些属性声明的示例:
```vhdl
attribute cell_name : string;
attribute pin_number : positive;
attribute max_wire_delay : delay_length;
attribute encoding : bit_vector;
```
属性类型不一定是简单的标量。例如,我们可以定义一个属性来表示单元的放置位置:
```vhdl
type length is range 0 to integer'high
units
nm;
um = 1000 nm;
mm = 1000 um;
mil = 25400 nm;
end units length;
type coordinate is record
x, y : length;
end record coordinate;
attribute cell_position : coordinate;
```
#### 2. 用户自定义属性的规格说明
定义了属性的名称和类型后,我们可以使用属性规格说明为设计中的元素添加属性值。属性规格说明的语法规则如下:
```plaintext
attribute_specification ⇐
attribute identifier of entity_name_list : entity_class is expression ;
entity_name_list ⇐
( ( identifier I character_literal I operator_symbol ) [ signature ] ) { , … }
I others
I all
entity_class ⇐
entity
I architecture
I configuration
I package
I procedure
I function
I type
I subtype
I constant
I signal
I variable
I file
I component
I label
I literal
I units
I group
I property
I sequence
```
属性规格说明中的第一个标识符是之前声明的属性名称。要添加属性的元素列在实体名称列表中。这里的“实体”指的是设计中的任何元素,不要与实体声明中定义的实体接口混淆。以下是一些属性规格说明的示例:
```vhdl
attribute cell_name of std_cell : architecture is "DFF_SR_QQNN";
attribute pin_number of enable : signal is 14;
attribute max_wire_delay of clk : signal is 50 ps;
attribute encoding of idle_state : literal is b"0000";
attribute cell_position of the_fpu : label is ( 540 um, 1200 um );
```
对于声明为复合类型的属性,我们可以使用聚合、字符串或位串字面量的形式来指定属性值。如果类型是无约束或部分约束的子类型,未定义的索引范围将根据属性值确定。例如:
```vhdl
type string_vector is array (positive range <>) of string;
attribute key_vector : string_vector;
attribute key_vector of e : entity is
("66A6D 7DF3A 88CE1 8DEEB", "012BD 2BEE9 98634 93FE1");
```
#### 3. 不同元素类别的属性值指定
不同类别的元素在指定属性值时有不同的规则,具体如下表所示:
| 元素类别 | 属性规格说明位置 | 示例 |
| ---- | ---- | ---- |
| 实体、架构、配置、包 | 设计单元的声明部分 | ```vhdl<br>architecture std_cell of flipflop is<br> attribute cell_name of std_cell : architecture is "DFF_SR_QQNN";<br> ... -- other declarations<br>begin<br> ...<br>end architecture std_cell;<br>``` |
| 子程序 | 与属性规格说明在同一声明部分,可使用签名区分重载版本 | ```vhdl<br>process is<br> procedure add_with_overflow ( a, b : in integer;<br> sum : out integer;<br> overflow : out boolean ) is ...<br> procedure add_with_overflow ( a, b : in bit_vector;<br> sum : out bit_vector;<br> overflow : out boolean ) is ...<br> attribute built_in : string;<br> attribute built_in of<br> add_with_overflow [ integer, integer,<br> integer, boolean ] : procedure is<br> "int_add_overflow";<br> attribute built_in of<br> add_with_overflow [ bit_vector, bit_vector,<br> bit_vector, boolean ] : procedure is<br> "bit_vector_add_overflow";<br>begin<br> ...<br>end process;<br>``` |
| 类型、子类型、数据对象 | 元素声明后的同一声明部分 | ```vhdl<br>type mvl is ('X', '0', '1', 'Z');<br>type mvl_vector is array ( integer range <>) of mvl;<br>function resolve_mvl ( drivers : mvl_vector ) return mvl;<br>subtype resolved_mvl is resolve_mvl mvl;<br>type builtin_types is (builtin_bit, builtin_mvl, builtin_integer);<br>attribute builtin : builtin_types;<br>attribute builtin of resolved_mvl : subtype is b
```
0
0
复制全文
相关推荐









