找回密码
 注册
关于网站域名变更的通知
查看: 304|回复: 1
打印 上一主题 下一主题

包(Package)

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2019-3-11 10:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
包(Package)

4 k0 |! y& l, Z& K& C. t- o4 Z7 F, m8 B/ j; ?, k
包中包含的通用定义可以在整个VHDL或多个设计中共享使用。 8 Y4 {) ~0 r7 g( t6 K3 b+ J
A package contains common definitions that can be shared across a VHDL design or even multiple designs./ U% _( u+ z1 q& w- t
# }- {$ W! T! c( o0 w* }
语法(Syntax)5 L$ F  O5 y/ z7 q; l

- h3 A/ o& n& rpackage package_name is
4 C3 h6 p+ Q$ H( ~' j. S0 g  package_declarations8 j3 z$ B  Q. K
end [ package ] [ package_name ];
: L7 H1 _( ]5 F- A+ }1, K) o" {- L9 g. X4 a& {# K# Y
2, H" z* U! p5 ^8 s
3/ O& K; @) r1 w! N! C1 @0 i% V1 M
说明(Description)
3 `0 R. Q. v  ^2 ~. G8 {; t7 J- `
! S' {% X" J, {/ V$ f包用来组织各式各样的声明,使其可以被许多设计共享使用。包存储在库中。一个包被分为包声明(强制的)和包主体(可选)。
$ m7 v8 d" u8 O/ O* U. L! m6 |/ z. uThe 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).
8 M. E3 ^7 i3 L; C包存在的目的是用来声明共享的类型,子类型,常量,信号,文件,断言,元件,属性和组。一旦包被定义,他就可以在多个独立设计中使用。 # W' U! O8 F# M8 f. @
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.
7 u% ?  {6 G: g% |, m) H输入使用了use子句,包中声明的项就可以在其他设计单元中可见。 ( E1 K& `* c: V
Items declared in a package declaration are visible in other design units if the use clause is applied.
7 M! g! `5 F; W" j: n+ F/ S( i& N: e+ T8 n* L9 f( _
例程(Example)
' _0 r! }% G3 c
4 _1 y/ i9 |" V3 O, \library IEEE;
. q! i; X0 a, A; {use IEEE.std_logic_1164.all;
$ D$ X# [- ~0 y" J% b! Dpackage Utils is
- C  _/ `9 x: t- a3 ~- B0 o* N  constant Size: positive; : b! u) v7 z% @
  subtype Vec8 is std_logic_vector(7 downto 0);( ~; D5 j2 V/ v& W; M' g
  function Parity (V: Vec8) return std_logic;
( [7 d1 P2 m) o, Gend Utils; # g5 A4 o+ B, H/ p8 x  e) W; D
13 N+ _, s8 a& I, k
2
4 R( q  p) ^# W  V; U; I' `- q3
* g6 m9 _4 D# J- ]( v8 M/ m4
( x5 I. H! S% F. D" E9 d# G4 E* o5' A1 K1 D) r% p5 |  W
6! B3 Y, z% E$ c6 s" K
7
5 |) ~4 F0 U7 S4 P5 ^注释(Notes)
; ?3 j8 @; X" ?, _
- ~' u0 }! {: e" A* o* G包声明可以包含子程序(函数或过程)声明;但子程序的主体不能出现在包声明中,必须在包主体内。
- `6 Q; m  W2 K1 o3 {, \' ~/ mA package declaration may contain a subprogram (function or 0 `0 V% w  m) p
procedure) declaration; the subprogram body is not allowed here and must appear in the package body.* p. R1 \3 h) s$ V* ^4 Z

/ P+ N* F/ m5 G8 u7 I3 G: h+ f包主体必须有一个包声明,如果声明中包含子程序声明或延迟常量。- t0 B' n' {+ G

+ E2 M3 e( p. |# g$ j" ZA package body must accompany a package declaration if the
+ y* U% _$ a8 T  g  jdeclaration contains subprogram declarations or deferred constants.
6 M& V, Y9 h- G& K2 n% O! q/ H" O. M" r: j
只有在包声明中定义的对象对外可见。, W$ I0 \+ u0 J2 H0 C7 D) g% d
, x" Z; ~  W9 S, N
Only definitions placed in the package declaration are visible 0 ^: Z/ J+ U! g3 v4 [9 @
outside the package.
( p, m) J( m# F* P; o包主体(Package Body)
0 L" b+ K" g- x. z6 [. }2 ~7 f0 F! D, v; p) B) V% ^" C
包主体定义了包的子程序,以及包中定义的延迟常量值。
0 c# }4 x+ k$ R! K3 a6 s$ OA package body defines the bodies of subprograms and the values of deferred constants defined in the package.3 A6 j7 X& q6 W$ B# _* `/ J
) w( O' f7 H) _% b. @8 h% _
语法(Syntax)/ `( @3 O# a1 I0 t8 ]; p

9 M" B$ L) w2 Y7 d, i$ c# z& npackage body package_name is
: F8 \" N1 N5 w/ d) {/ I3 B  package_body_declarations
3 s. S2 N. |) p% w: S4 ?4 fend [ package body ] [ package_name ];
/ p7 J1 S+ W+ J1' t& }( d! q8 G# G  q% K" y
2' o1 D9 v6 `) U1 [
30 i, \+ ~: J! m9 G8 y7 }- p
说明(Description)
. I- q& H2 }9 K+ P; p2 Q2 |, t0 Q. `# X. |5 p3 }4 R' s
包主体中包含完整的子程序主体,以及延迟常量值。其他声明也可以出现在包主体中,但是仅对包内部可用。
5 P# U5 \) n+ |; |# ~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.
0 a5 A0 d) i  N; r4 s包声明的延迟常量,可以在其完全声明前使用,仅当他是一个本地通用参数的默认值,本地端口或子程序的形式参数。 ) Z% h" F6 T5 _# I
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.
  U. |+ T3 N9 z  U' E- g. d
6 I% w% T3 \+ v# O& Y1 |2 i例程(Example)( ^& c$ @: B& a6 t" |

9 D3 x+ ^& g" W0 G* s! x( upackage body Utils is 8 K' e4 T4 [' ~! I/ b( R" W3 u' O
  constant Size: positive := 16;
, c/ O* i: N) @  function Parity (V: Vec8) return std_logic is * @# G  v% m2 _8 O; O/ Y+ Q
    variable B: std_logic := '0'; & Y) f6 A+ L! v- B: p6 p0 P
  begin * v/ r: v7 g3 ?1 X# L, P
    for I in V'Range loop 6 z. {+ o9 R1 A$ W% K
      B:= B xor V(I);
+ D7 P" n5 J* X( ~    end loop;
8 r. w0 F9 t1 d8 K1 k    return B; 9 Z+ u% N+ G' T$ f9 c' f- y
  end Parity;
8 X( r/ p7 l6 t' b" q) R4 z1 Oend Utils;
: x. q3 p/ J8 N$ D: E% A8 n* u# X" t1. l6 f# y+ F8 I. D; K. y
2
/ ~, _7 J, m" Y+ s32 K  ]" v, K$ `3 _4 e4 K/ N
4
% B( w; O7 k$ `) y/ n* t5
8 [: y4 x4 m" G  r6
6 y& Z. s6 I+ |7
* T+ N5 z- n5 v8! V, u- y; [! W4 u0 r/ d2 j8 N( d
9
, X0 {4 j8 b9 U2 m5 O: v3 M4 s  z10$ ?9 Q- f7 |9 g/ S/ N) z! p
116 z# |- t6 D/ M1 Z) R7 z4 q
注释(Notes)" C$ w- R* m+ t4 k8 R

* C5 x, y, c1 o, V! T除了延迟常数值和子程序主体外的声明对包主体外不可见。( K" e9 E+ k5 y/ S% u+ O
Declarations other than values of deferred constants and subprogram bodies are not visible outside the package body.
% z# s8 P1 G3 _! `每个包仅有一个主体。+ V, c# V+ p* o+ S4 M2 p
Each package can have only one body.
5 a% m. a' }. P  d9 a) \

该用户从未签到

2#
发表于 2019-3-11 14:58 | 只看该作者
最近正在学习这方面  谢谢楼主
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-7-28 09:15 , Processed in 0.109375 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

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