Featured post

Top 5 books to refer for a VHDL beginner

VHDL (VHSIC-HDL, Very High-Speed Integrated Circuit Hardware Description Language) is a hardware description language used in electronic des...

Tuesday, 18 December 2012

Signal Declaration

Formal Definition

Signal is an object with a past history of values. A signal may have multiple drivers, each with a current value and projected future values. The term signal refers to objects declared by signal declarations and port declarations.

Simplified Syntax

signal signal_name : type;

signal signal_name : type := initial_value;

Description

Signals are the primary objects describing a hardware system and are equivalent to "wires". They represent communication channels among concurrent statements of system's specification. Signals and associated mechanisms of VHDL (like signal assignment statements, resolution function, delays, etc.) are used to model inherent hardware features such as concurrency, inertial character of signal propagation, buses with multiple driving sources, etc. Each signal has a history of values and may have multiple drivers, each of which has a current value and projected future values. All signal parameters are accessible by means of signal attributes.

Signals can be explicitly declared in the declarative part of:

· package declaration; signals declared in a package are visible in all design entities using the package (through the use clause);

· architecture (see architecture); such signals are visible inside the architecture only;

· block (see block); the scope of such signals is limited to the block itself;

· subprogram (see function and procedure); such signals are visible in respective subprogram.

Moreover, a port declaration in an entity is an implicit signal declaration (example 1). A signal declared this way is visible in all architectures assigned to that entity.

A signal declaration contains one or more identifiers (i.e. more than one signal can be declared in one statement) and a subtype indicator. Each signal name is an identifier and creates one separate signal. The (sub)type in the signal declaration can be of any scalar or composite type. Optionally, it may have some constraints. File and access types are not allowed for signals. Some typical signal declarations are given in the Example 1, below.

A signal can be assigned an initial (default) value in its declaration. It the value is produced by an expression, it must be of the same type as the signal itself. If there is no expression given in the signal declaration, then the default value of the signal is the left bound of the specified type (see Example 2).

A signal may be declared with a signal_kind statement, which can be either a register or bus. Such signal must be of a resolved type. A register type signal retains its current value even when all its drivers are turned off. However, the signal_kind bus relies on the resolution function to supply a "no-drive" value (see resolution function for details)

Examples

Example 1

library IEEE;
use IEEE.Std_Logic_1164.all;
entity DataTransm is
  port (Data : Std_Logic_Vector(15 downto 0));
end entity DataTransm;
architecture ExDecl of DataTransm is
signal Temp : Std_Logic;
signal FlagC, FlagZ : Bit;
begin
  . . .

Each statement of the architecture ExDecl may use any of the four signals: Data (16-bit vector), declared as a port in the entity part (above the architecture section), Temp which is a single signal of the type Std_Logic and two one bit signals: FlagC and FlagZ. Note that the signals FlagC and FlagZ are declared together in the same line because they both are of the same type.

Example 2

type Four_VL is ('X','0','1','Z');
signal Sig1 : Four_VL;
signal Sig2 : Four_VL := 'X';
signal Sig3 : Four_VL := '0';

All three above listed signals are of the same type, but their default values are specified in different ways. Sig1 will be assigned the leftmost value of the type, i.e. 'X' (Leftmost item in the first line), Sig2 is explicitly assigned the same value. However, as this is the leftmost value of the signal type in this assignment, it is redundant and can be omitted. Finally, Sig3 is assigned the '0' value. Since '0' is not the leftmost value of the type, it has to be assigned explicitly to the signal.

Important Notes

· It is illegal to declare signals in a process or a subprogram (except as formal parameters).

· Each port specified in an entity is accessible as a signal in every architecture assigned to this entity and need not to be declared again.

· A signal may never be of a file or access type.

· Despite that value assignment to a signal is made with the '<=' symbol, it is not applicable to the default value listed in the signal declaration, where the ':=' symbol must be used.

· If a signal is to be driven by more than one source (i.e. it will be assigned values in more than one statement), it has to be declared as of resolved type (see resolution anddriver).

· The signal_kinds (register and bus) are not supported by synthesis tools.

Slice

Formal Definition

A one-dimensional array of a sequence of consecutive elements of another one-dimensional array.

Simplified Syntax

object_name ( discrete_range )

function_call ( discrete_range )

Description

The slice is a subarray of a one-dimensional array, from a single element up to complete array.

The prefix used for a slice is the name of the parent array.

The index used for a slice must fall in the range of the indexes of the parent array. Moreover, the direction of the slice indexes must be the same as the direction of indexes of parent array (either ascending or descending).

The slice is an object which can be used in the same way as its parent array: if the parent array is a signal, then any its slice is also a signal, etc.

If the discrete range of a slice is null then the slice is null as well.

Examples

Example 1

signal DataBus : Bit_Vector(31 downto 0); -- parent array
DataBus(31 downto 26) -- slice 1
DataBus(24 downto 24) -- slice 2
DataBus(24 downto 30) -- slice 3
DataBus(15 to 31) -- no slice - ERROR!

The first slice is a 6-element Subarray of the DataBus. The second slice contains one element. Slice 3 is a null slice (the range is null). Finally, the fourth example is an error due to different directions of the parent array and the slice.

Important Notes

· The direction of the parent array and its slice must match (i.e. in both cases either to or downto keyword must be used).

Standard Package

Definition:

The STANDARD package predefines a number of types, subtypes, and functions which are visible to all design units.

Description

The STANDARD package is a part of the Language Specification. It defines basic types, subtypes, and functions, together with operators available for each of the (sub)types defined. The operators are specified implicitly. Below is a complete list of declared types, together with their predefined operators.

Contents:

The STANDARD package declares following types:

· BOOLEAN (with predefined
operators "and", "or", "nand", "nor", "xor", "xnor", "not", "=", "/=", "<", "<=", ">", ">="),

· BIT (with predefined operators "and", "or", "nand", "nor", "xor", "xnor", "not", "=", "/=", "<", "<=", ">", ">="),

· CHARACTER (with predefined operators "=", "/=", "<", "<=", ">", ">="),

· SEVERITY_LEVEL (with predefined operators "=", "/=", "<", "<=", ">", ">="),

· INTEGER (with predefined operators "=", "/=", "<", "<=", ">", ">=", "+", "-", "abs", "*", "/", "mod", "rem", "**"),

· REAL (with predefined operators "=", "/=", "<", "<=", ">", ">=", "+", "-", "abs", "*", "/", "**"),

· TIME (with predefined operators "=", "/=", "<", "<=", ">", ">=", "+", "-", "abs", "*", "/"),

· STRING (with predefined operators "=", "/=", "<", "<=", ">", ">=", "&"),

· BIT_VECTOR (with predefined
operators "and", "or", "nand", "nor", "xor", "xnor", "not", "sll", "srl", "sla", "sra", "rol", "ror", "=", "/=", "<", "<=", ">", ">=", "&"),

· FILE_OPEN_KIND (with predefined operators "=", "/=", "<", "<=", ">", ">="),

· FILE_OPEN_STATUS (with predefined operators "=", "/=", "<", "<=", ">", ">="),

and three subtypes:

· DELAY_LENGTH (subtype of TIME),

· POSITIVE (subtype of INTEGER),

· NATURAL (subtype of INTEGER),

See Boolean, Bit, Character, Integer, Real, Physical Types, String, Bit_Vector and File for details on respective types.

Important Notes

· Use of the STANDARD package is implicitly assumed by every VHDL simulator and compiler and need not to be explicitly declared by the 'use' clause.

· The user may not modify the contents of the package.

Std_Logic

Definition:

A nine-value resolved logic type Std_logic is not a part of the VHDL Standard. It is defined in IEEE Std 1164.

Syntax:

type std_ulogic is ( 'U', -- Uninitialized

                     'X', -- Forcing Unknown

                     '0', -- Forcing 0

                     '1', -- Forcing 1

                     'Z', -- High Impedance

                     'W', -- Weak Unknown

                     'L', -- Weak 0

                     'H', -- Weak 1

                     '-' -- Don't Care

                    );

type std_ulogic_vector is array (natural range <> ) of std_ulogic;

function resolved (s : std_ulogic_vector ) return std_ulogic;

subtype std_logic is resolved std_ulogic;

Description

The Std_ulogic type is an extension of the standard Bit type. It defines nine values, which allow specifying logical systems. Like Bit, this type is not resolved, i.e. it is not allowed to specify two value assignments to a signal of the Std_ulogic type.

In order to facilitate specification of multiple-driven signals (like data buses) the Std_Logic_1164 package defines resolution function for Std_ulogic, which in turn serves as a basis for declaration of Std_Logic type.

The Std_Logic_1164 package defines overloaded logical operators ("and", "nand", "or", "nor", "xor", and "not") for operands of the Std_ulogic type. Moreover, two conversion functions are defined as well: Std_ulogic to Bit (function To_Bit), and Bit to Std_ulogic (function To_StdULogic).

Examples

Example 1

Signal FlagC : Std_Logic := 'Z';
ALU : process
begin
  . . .
  if Carry then FlagC <= '1'; end if;
end process ALU;
Comm : process
begin
  . . .
  FlagC <= '0';
end process Comm;

Std_Logic is a resolved type, which means that multiple assignments to the same object are legal. If FlagC was of the Std_Ulogic type, such a code would not be acceptable.

Important Notes

· Std_Logic is defined as a subtype of Std_ULogic, therefore all operators and functions defined for Std_Ulogic can be applied to Std_Logic.

· Std_Logic is the industry standard logic type and in practice majority of signals are of this type (or its vector derivative, Std_Logic_Vector type).

Std_Logic_1164 Package

Definition:

Package Std_Logic_1164 is NOT a part of the VHDL Standard Definition. It is defined as IEEE Std 1164.

Description

The Std_Logic_1164 Package contains definitions of types, subtypes, and functions, which extend the VHDL into a multi-value logic. It is not a part of the VHDL Standard, but it is a separate Standard of the same standardization body (Institute of Electrical and Electronics Engineers, IEEE).

Main reason for development and standardization of Std_Logic_1164 was the need for more logical values (than the two defined by the type Bit in the Standard package) with resolution function. The types Std_Logic and Std_Logic_Vector (declared in Std_Logic_1164 package) became de facto industrial standards.

Contents:

The package contains the following declarations:

· type std_ulogic: unresolved logic type of 9 values;

· type std_ulogic_vector: vector of std_ulogic;

· function resolved resolving a std_ulogic_vector into std_ulogic;

· subtype std_logic as a resolved version of std_ulogic;

· type std_logic_vector: vector of std_logic;

· subtypes X01, X01Z, UX01, UX01Z: subtypes of resolved std_ulogic containing the values listed in the names of subtypes (i.e. UX01 contains values 'U', 'X', '0', and '1', etc.);

· logical functions for std_logic, std_ulogic, std_logic_vector and std_ulogic_vector;

· conversion functions between std_ulogic and bit, std_ulogic and bit_vector, std_logic_vector and bit_vector and vice-versa;

· functions rising_edge and falling_edge for edge detection of signals.

· x-value detection functions, is_x, which detect values 'U', 'X', 'Z', 'W', '-' in the actual parameter.

See std_logic and std_logic_vector for details.

Important Notes

· The Std_Logic_1164 Package is copyrighted and may not be altered (either by modifying/removing existing declarations or adding new ones).

· In order to use any of the declarations of the Std_Logic_1164 package, the 'library' and 'use' clauses have to be used:

library IEEE;

use IEEE.Std_Logic_1164.all;

Std_Logic_Vector

Definition:

The Std_Logic_Vector type is predefined in the Std_Logic_1164 package as a standard one-dimensional array type with each element being of the Std_Logic type.

Std_Logic_Vector is not a part of the VHDL Standard. Instead, it is defined by IEEE Std 1164

Syntax:

type std_logic_vector is array (natural range <>) of std_logic;

Description

Std_Logic_Vector is an unconstrained (unbound) vector of resolved nine-value logic elements (std_logic type), which are defined in the Std_Logic_1164 package.

The Std_Logic_1164 package defines overloaded logical operators ("and", "nand", "or", "nor", "xor", and "not") for operands of the Std_logic_vector type. In addition, conversion functions from and to Bit_Vector are supported as well.

Assignment to an object of the Std_Logic_Vector type can be performed in the same way as in case of arrays, i.e. using single element assignments, concatenation, aggregates, slicesor any combination of them. Moreover, because the elements are of resolved type it is allowed to make multiple assignments to a Std_Logic_Vector object type. In such a case, the resolution function defined for Std_Logic is used.

Examples

Example 1

Type T_Data is array (7 downto 0) of std_logic;
signal DataBus, Memory : T_Data;
CPU : process
variable RegA : T_Data;
begin
  ...
  DataBus <= RegA;
end process CPU;
Mem : process
begin
  ...
  DataBus <= Memory;
end process Mem;

Std_Logic_Vector is the best choice for buses, which are driven from different places, like the above listed data bus. Such a multiple assignment would be illegal if a Bit_Vector was used.

Important Notes

· Std_Logic_Vector should not be confused with the Std_Ulogic_Vector type. Elements of the latter are of the type Std_Ulogic and are unresloved version of Std_Logic. This means that it is illegal for the two values (e.g. '0' and 'Z') to be simultaneously driven into a signal of the Std_ulogic type.

· In order to use the Std_Logic_Vector type, the Std_Logic_1164 package must be explicitly listed at the beginning of an entity:

library IEEE;
use IEEE.Std_Logic_1164.all;

String

Formal Definition

The string type is predefined in the package Standard as a standard one-dimensional array type with each element being of the type Character.

Syntax:

type String is array (positive range <>) of character;

Description

The type string is an unconstrained vector of elements of the type Character. The size of a particular vector must be specified during its declaration (see example). The way the vector elements are indexed depends on the defined range - either ascending or descending (see range).

Assignment to an object of the type string can be performed in the same way as in case of any arrays, i.e. using single element assignments, concatenation, aggregates, slices or any combination of them.

The package Standard contains declarations of the predefined operators for the type String: "=", "/=", "<", "<=", ">", ">=" and "&". Relational operators allow to compare two strings, while the concatenation operator allows to concatenate two strings, a string and a character and two characters to create a string.

Examples

Example 1

constant Message1 : String(1 to 19) := "hold time violation";
signal Letter1 : character;
signal Message2 : string(1 to 10);
. . .
Message2 <= "Not" & Letter1;

Important Notes

· Unlike Bit_Vector, where the value of index is of the type Natural (from 0 up to maximum Integer), the index of String has a POSITIVE value, being an integer greater than 0. It would be an error, then, to declare a String with a range with zero as one of the boundary values.

· Strings are written in double quotes. Single elements, however, are of the type character, therefore values assigned to single elements (referred by the index) are specified in single quotes.

· Strings play supplementary role for system modeling as they do not reflect any particular feature of hardware. They are used mostly for issuing messages during simulation (see assertion statement)