ch10.09.htm

来自「介绍asci设计的一本书」· HTM 代码 · 共 744 行 · 第 1/3 页

HTM
744
字号
<HTML>

<HEAD>

  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Mac">

  

  <TITLE> 10.9&nbsp;	Other Declarations</TITLE>

</HEAD>

<!--#include file="top.html"-->

<!--#include file="header.html"--><br><!--#include file="AmazonAsic.html"-->





<P><A NAME="pgfId=10666"></A><A HREF="CH10.htm">Chapter&nbsp;&nbsp;start</A>&nbsp;&nbsp;&nbsp;<A HREF="CH10.08.htm">Previous

page</A>&nbsp;&nbsp;<A HREF="CH10.10.htm">Next&nbsp;&nbsp;page</A></P>



<H2>10.9&nbsp; Other Declarations</H2>



<P><P CLASS="BodyAfterHead"><A NAME="pgfId=10853"></A>A declaration is one

of the following [<A HREF="../../VHDL/LRM/HTML/1076_4.HTM#4">VHDL LRM4</A>]:</P>



<PRE>declaration ::=

&nbsp;&nbsp;type_declaration 	| subtype_declaration	| object_declaration

| interface_declaration 	| alias_declaration	| attribute_declaration

| component_declaration 	| entity_declaration

| configuration_declaration &nbsp;| subprogram_declaration

| package_declaration

<U>| group_template_declaration | group_declaration </U></PRE>



<P>I discussed entity, configuration,

component, package, interface, type, and subtype declarations in Sections

10.5-10.8. Next I shall discuss the other types of declarations (except

for groups or group templates [<A HREF="../../VHDL/LRM/HTML/1076_4.HTM#4.6">VHDL

93LRM4.6</A>-<A HREF="../../VHDL/LRM/HTML/1076_4.HTM#4.7">4.7</A>], new to VHDL-93,

that are not often used in ASIC design).</P>



<H3><A NAME="pgfId=11057"></A>10.9.1&nbsp; Object Declarations</H3>



<P><P CLASS="BodyAfterHead"><A NAME="pgfId=254368"></A>There are four object

classes in VHDL: constant, variable, signal, and file [<A HREF="../../VHDL/LRM/HTML/1076_4.HTM#4.3.1.1">VHDL

LRM 4.3.1.1</A>-<A HREF="../../VHDL/LRM/HTML/1076_4.HTM#4.3.1.3">4.3.1.3</A>]. You

use a constant declaration, signal declaration, variable declaration, or

file declaration together with a type. Signals can only be declared in the

declarative region (before the first <CODE>begin</CODE> ) of an architecture

or block, or in a package (not in a package body). Variables can only be

declared in the declarative region of a process or subprogram (before the

first <CODE>begin</CODE> ). You can think of signals as representing real

wires in hardware. You can think of variables as memory locations in the

computer. Variables are more efficient than signals because they require

less overhead.</P>



<P><P CLASS="Body"><A NAME="pgfId=7479"></A>You may assign an (explicit)

initial value when you declare a type. If you do not provide initial values,

the (implicit) default initial value of a type or subtype <CODE>T</CODE>

is <CODE>T'LEFT</CODE> (the leftmost item in the range of the type). For

example:</P>



<PRE><B>entity</B> Initial_1 <B>is</B> <B>end</B>; <B>architecture</B>

Behave <B>of</B> Initial_1 <B>is</B>

<B>type</B> Fahrenheit <B>is</B> <B>range</B> 32 <B>to</B> 212; 																-- Default initial value is 32.

<B>type</B> Rainbow <B>is</B> (R, O, Y, G, B, I, V);																-- Default initial value is R.

<B>type</B> MVL4 <B>is</B> ('X', '0', '1', 'Z');																-- MVL4'LEFT = 'X'.

-<B>begin</B> <B>end</B>;</PRE>







<P><P CLASS="Body"><A NAME="pgfId=364224"></A>The details of initialization

and assignment of initial values are important--it is difficult to implement

the assignment of initial values in hardware--instead it is better to mimic

the hardware and use explicit reset signals.</P>



<P><P CLASS="Body"><A NAME="pgfId=364225"></A>Here are the formal definitions

of constant and signal declarations:</P>



<PRE>constant_declaration ::= <B>constant</B>

identifier {, identifier}:subtype_indication [:= expression] ;

signal_declaration ::= <B>signal</B>

identifier {, identifier}:subtype_indication [<B>register</B>|<B>bus</B>] [:=expression];</PRE>



<P><P CLASS="Body"><A NAME="pgfId=364238"></A>I shall explain the use of

signals of kind <CODE>register</CODE> or <CODE>bus</CODE> in Section&nbsp;10.13.1.

Signal declarations are explicit signal declarations (ports declared in

an interface declaration are implicit signal declarations). Here is an example

that uses a constant and several signal declarations:</P>



<PRE><B>entity</B> Constant_2 <B>is</B> <B>end</B>; 

<B>library</B> IEEE; <B>use</B> IEEE.STD_LOGIC_1164.<B>all</B>;

<B>architecture</B> Behave <B>of</B> Constant_2 <B>is</B>

<B>constant</B> Pi : REAL := 3.14159;																		-- A constant declaration.

<B>signal</B> B : BOOLEAN; <B>signal</B> s1, s2: BIT; 

<B>signal</B> sum : INTEGER <B>range</B> 0 <B>to</B> 15;																		-- Not a new type.

<B>signal</B> SmallBus : BIT_VECTOR (15 <B>downto</B> 0);																		-- 16-bit bus.

<B>signal</B> GBus : STD_LOGIC_VECTOR (31 <B>downto</B> 0); <B>bus</B>; -- A guarded signal.

<B>begin</B> <B>end</B>;</PRE>



<P><P CLASS="Body"><A NAME="pgfId=364233"></A>Here is the formal definition

of a variable declaration:</P>



<PRE>variable_declaration ::= <U>[shared]</U> <B>variable</B>

identifier {, identifier}:subtype_indication [:= expression] ;</PRE>



<P><P CLASS="Body"><A NAME="pgfId=13365"></A>A shared variable can be used

to model a varying quantity that is common across several parts of a model,

temperature, for example, but shared variables are rarely used in ASIC design.

The following examples show that variable declarations belong inside a <CODE>process</CODE>

statement, after the keyword <CODE>process</CODE> and before the first appearance

of the keyword <CODE>begin</CODE> inside a process:</P>



<PRE><B>library</B> IEEE; <B>use</B> IEEE.STD_LOGIC_1164.<B>all</B>; <B>entity</B> Variables_1 <B>is</B> <B>end</B>;

<B>architecture</B> Behave <B>of</B> Variables_1 <B>is begin</B> <B>process</B>

	<B>variable</B> i : INTEGER <B>range</B> 1 <B>to</B> 10 := 10; -- Initial value = 10.

	<B>variable</B> v : STD_LOGIC_VECTOR (0 <B>to</B> 31) := (<B>others</B> =&gt; '0'); 

	<B>begin</B> <B>wait</B>; <B>end</B> <B>process</B>; -- The wait stops an endless cycle.

<B>end</B>;</PRE>



<H3><A NAME="pgfId=571101"></A>10.9.2&nbsp; Subprogram Declarations</H3>



<P><P CLASS="BodyAfterHead"><A NAME="pgfId=571103"></A>VHDL code that you

use several times can be declared and specified as subprograms (functions

or procedures) [<A HREF="../../VHDL/LRM/HTML/1076_2.HTM#2.1">VHDL LRM2.1</A>]. A

function is a form of expression, may only use parameters of mode <CODE>in</CODE>

, and may not contain delays or sequence events during simulation (no <CODE>wait</CODE>

statements, for example). Functions are useful to model combinational logic.

A procedure is a form of statement and allows you to control the scheduling

of simulation events without incurring the overhead of defining several

separate design entities. There are thus two forms of subprogram declaration:

a function declaration or a procedure declaration.</P>



<PRE>subprogram_declaration ::= subprogram_specification ; ::=

&nbsp;<B>procedure </B>

	identifier|string_literal [(parameter_interface_list)]

|<B> </B><U>[pure|impure]</U> <B>function</B>

	identifier|string_literal [(parameter_interface_list)]

<B>return</B> type_name|<I>subtype_</I>name;</PRE>



<P><P CLASS="Body"><A NAME="pgfId=21041"></A>Here are a function and a procedure

declaration that illustrate the difference:</P>



<PRE><B>function </B>add(a, b, c : BIT_VECTOR(3 <B>downto</B> 0)) <B>return</B> BIT_VECTOR <B>is</B>

-- A function declaration, a function can't modify a, b, or c.

<B>procedure</B> Is_A_Eq_B (<B>signal</B> A, B : BIT; <B>signal</B> Y : <B>out</B> BIT);

-- A procedure declaration, a procedure can change Y.</PRE>



<P><P CLASS="Body"><A NAME="pgfId=15976"></A>Parameter names in subprogram

declarations are called formal parameters (or formals). During a call to

a subprogram, known as subprogram invocation, the passed values are actual

parameters (or actuals). An impure function, such as the function <CODE>now</CODE>

or a function that writes to or reads from a file, may return different

values each time it is called (even with the same actuals). A pure function

(the default) returns the same value if it is given the same actuals. You

may call subprograms recursively. Table&nbsp;10.13 shows the properties

of subprogram parameters.</P>



<P><TABLE BORDER="1" CELLSPACING="2" CELLPADDING="2">

<TR>

<TD COLSPAN="5"><P CLASS="TableTitle"><A NAME="pgfId=254206"></A>TABLE&nbsp;10.13&nbsp;&nbsp;&nbsp;&nbsp;Properties

of subprogram parameters.</TD></TR>

<TR>

<TD COLSPAN="5"><P><P CLASS="TableLeft"><A NAME="pgfId=339906"></A>Example subprogram declarations:</P>



<PRE><A NAME="pgfId=340338"></A> <B>function</B> my_function(Ff) <B>return</B> BIT <B>is</B> -- Formal function parameter, Ff.

<B>procedure</B> my_procedure(Fp); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- Formal procedure parameter, Fp.</PRE>



<P><P CLASS="TableLeft"><A NAME="pgfId=340351"></A>Example subprogram calls:</P>



<PRE><A NAME="pgfId=339917"></A> my_result := my_function(Af); -- Calling a function with an actual parameter, Af.

MY_LABEL:my_procedure(Ap); &nbsp;&nbsp;-- Using a procedure with an actual parameter, Ap.</PRE>

</TD></TR>

<TR>

<TD><P CLASS="TableLeft"><A NAME="pgfId=254216"></A>Mode of <CODE>Ff</CODE>

or <CODE>Fp </CODE>(formals)</TD>

<TD><P CLASS="TableLeft"><A NAME="pgfId=254221"></A><B><CODE>in</CODE></B></TD>

<TD><P CLASS="TableLeft"><A NAME="pgfId=254223"></A><B><CODE>out</CODE></B></TD>

<TD><P CLASS="TableLeft"><A NAME="pgfId=254225"></A><B><CODE>inout</CODE></B></TD>

<TD><P CLASS="TableLeft"><A NAME="pgfId=254227"></A>No mode</TD></TR>

<TR>

<TD><P><P CLASS="TableLeft"><A NAME="pgfId=254229"></A>Permissible classes for

<CODE>Af</CODE></P>



<P><P CLASS="TableLeft"><A NAME="pgfId=364200"></A>(function actual parameter)</TD>

<TD><P><P CLASS="TableLeft"><A NAME="pgfId=254231"></A><B><CODE>constant</CODE></B>

(default)</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=255667"></A><B><CODE>signal</CODE></B></TD>

<TD><P CLASS="TableLeft"><A NAME="pgfId=254233"></A>Not allowed</TD>

<TD><P CLASS="TableLeft"><A NAME="pgfId=254235"></A>Not allowed</TD>

<TD><P CLASS="TableLeft"><A NAME="pgfId=254237"></A><B><CODE>file</CODE></B></TD></TR>

<TR>

<TD><P><P CLASS="TableLeft"><A NAME="pgfId=340411"></A>Permissible classes for

<CODE>Ap</CODE></P>



<P><P CLASS="TableLeft"><A NAME="pgfId=364203"></A>(procedure actual parameter)</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=364201"></A>&nbsp;</TD>

<TD><P><P CLASS="TableLeft"><A NAME="pgfId=255670"></A><B><CODE>constant</CODE></B>

(default)</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=255675"></A><B><CODE>variable</CODE></B></P>



<P><P CLASS="TableLeft"><A NAME="pgfId=255671"></A><B><CODE>signal</CODE></B></TD>

<TD><P><P CLASS="TableLeft"><A NAME="pgfId=255677"></A><B><CODE>constant</CODE></B></P>



<P><P CLASS="TableLeft"><A NAME="pgfId=255678"></A><B><CODE>variable</CODE></B>

(default)</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=255679"></A><B><CODE>signal</CODE></B></TD>

<TD><P><P CLASS="TableLeft"><A NAME="pgfId=255685"></A><B><CODE>constant</CODE></B><CODE>

</CODE></P>



<P><P CLASS="TableLeft"><A NAME="pgfId=255686"></A><B><CODE>variable</CODE></B>

(default)</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=255687"></A><B><CODE>signal</CODE></B></TD>

<TD><P CLASS="TableLeft"><A NAME="pgfId=254253"></A><B><CODE>file</CODE></B></TD></TR>

<TR>

<TD><P><P CLASS="TableLeft"><A NAME="pgfId=254255"></A>Can you read attributes

of</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=340427"></A><CODE>Ff</CODE> or <CODE>Fp</CODE>

(formals)?</TD>

<TD><P><P CLASS="TableLeft"><A NAME="pgfId=254257"></A>Yes, except:</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254258"></A>&nbsp;'STABLE</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254259"></A>&nbsp;'QUIET</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254260"></A>&nbsp;'DELAYED</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254261"></A>&nbsp;'TRANSACTION</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254262"></A>of a signal</TD>

<TD><P><P CLASS="TableLeft"><A NAME="pgfId=254264"></A>Yes, except:</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254265"></A>&nbsp;'STABLE 'QUIET</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254266"></A>&nbsp;'DELAYED</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254267"></A>&nbsp;'TRANSACTION</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254268"></A>&nbsp;'EVENT 'ACTIVE</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254269"></A>&nbsp;'LAST_EVENT</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254270"></A>&nbsp;'LAST_ACTIVE</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254271"></A>&nbsp;'LAST_VALUE</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=255992"></A>of a signal</TD>

<TD><P><P CLASS="TableLeft"><A NAME="pgfId=254273"></A>Yes, except:</P>



<P><P CLASS="TableLeft"><A NAME="pgfId=254274"></A>&nbsp;'STABLE</P>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?