请选择 进入手机版 | 继续访问电脑版

集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 959|回复: 1

包(Package)

[复制链接]
fpga_feixiang 发表于 2019-2-15 15:22:14 | 显示全部楼层 |阅读模式
包中包含的通用定义可以在整个VHDL或多个设计中共享使用。
A package contains common definitions that can be shared across a VHDL design or even multiple designs.

语法(Syntax)

package package_name is
  package_declarations
end [ package ] [ package_name ];
1
2
3
说明(Description)

包用来组织各式各样的声明,使其可以被许多设计共享使用。包存储在库中。一个包被分为包声明(强制的)和包主体(可选)。
The package is a unit that groups various declarations, which can be shared among several designs. Packages are stored in libraries. A package is split into a package declaration (mandatory) and a package body (optional).
包存在的目的是用来声明共享的类型,子类型,常量,信号,文件,断言,元件,属性和组。一旦包被定义,他就可以在多个独立设计中使用。
The purpose of a package is to declare shareable types, subtypes, constants, signals, files, aliases, component, attributes and groups. Once a package is defined, it can be used in multiple independent designs.
输入使用了use子句,包中声明的项就可以在其他设计单元中可见。
Items declared in a package declaration are visible in other design units if the use clause is applied.

例程(Example)

library IEEE;
use IEEE.std_logic_1164.all;
package Utils is
  constant Size: positive;
  subtype Vec8 is std_logic_vector(7 downto 0);
  function Parity (V: Vec8) return std_logic;
end Utils;
1
2
3
4
5
6
7
注释(Notes)

包声明可以包含子程序(函数或过程)声明;但子程序的主体不能出现在包声明中,必须在包主体内。
A package declaration may contain a subprogram (function or
procedure) declaration; the subprogram body is not allowed here and must appear in the package body.

包主体必须有一个包声明,如果声明中包含子程序声明或延迟常量。

A package body must accompany a package declaration if the
declaration contains subprogram declarations or deferred constants.

只有在包声明中定义的对象对外可见。

Only definitions placed in the package declaration are visible
outside the package.
包主体(Package Body)

包主体定义了包的子程序,以及包中定义的延迟常量值。
A package body defines the bodies of subprograms and the values of deferred constants defined in the package.

语法(Syntax)

package body package_name is
  package_body_declarations
end [ package body ] [ package_name ];
1
2
3
说明(Description)

包主体中包含完整的子程序主体,以及延迟常量值。其他声明也可以出现在包主体中,但是仅对包内部可用。
The package body includes complete definitions of subprogram body declarations as well as values of deferred constants declared in the corresponding package declarations. Other declarations (similar to those of package declaration) are also allowed here, but are visible only inside the package body.
包声明的延迟常量,可以在其完全声明前使用,仅当他是一个本地通用参数的默认值,本地端口或子程序的形式参数。
The deferred constant, which has been declared in a package declaration, may be used before its full declaration only in a default expression for a local generic parameter, local port or formal parameter of subprogram.

例程(Example)

package body Utils is
  constant Size: positive := 16;
  function Parity (V: Vec8) return std_logic is
    variable B: std_logic := '0';
  begin
    for I in V'Range loop
      B:= B xor V(I);
    end loop;
    return B;
  end Parity;
end Utils;
1
2
3
4
5
6
7
8
9
10
11
注释(Notes)

除了延迟常数值和子程序主体外的声明对包主体外不可见。
Declarations other than values of deferred constants and subprogram bodies are not visible outside the package body.
每个包仅有一个主体。
Each package can have only one body.
zhangyukun 发表于 2019-2-16 09:21:52 | 显示全部楼层
包(Package)
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-3-29 16:50 , Processed in 0.059679 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表