signals and variables
type bit is ('0','1');
However, because bit does not give a representation for X and Z, multiple valued logics are generally preferred for modeling and simulation. IEEE Standard 1164 has been defined for this purpose, and is discussed in more detail below.
type boolean is (false, true);
type character is the set of ASCII symbols
The VHDL language designers almost did include reals because it was felt they represented an inappropriate level of modeling for digital design.
They were included to support expression evaluation of physical, measured values and the intent to allow inclusion of attributes from the "physical" axis of design modeling.
constant Tenio_lz : TIME := Tenio_plz + (Tio_clh * (io_cap));Timing is important for simulation purposes, but is frequently ignored during synthesis. Instead the synthesis tool seeks to minimize delays and once the implementation is generated, a back annotator supplies predicted timing values for the model. Consequently, good VHDL models should use named constants everywhere so that the back annotator can generate a table of values in a configuration body or package rather than requiring text substitution through an entire collection of source modules.
constant Reg_size: integer := 16; constant Tprop: time := 15 ns; signal preset, clear: bit; signal CS1: bit; variable i_slice: integer range 0 to Reg_size-1;Comments
-- All text on a line to the right of the double hyphen is a comment. -- In the cases above a constant object named Reg_size -- is declared to be of type integer and set to a value of 16 -- Signal objects named preset, clear, and CS1 all are -- declared to be of type bit. Variable object i_slice will be -- allowed only to take on values between 0 and 15.
Example
Type declarations do not occur frequently in architecture bodies. They usually should appear in a package declaration used by the architecture and invoked in a USE statement.
An important example of a user defined type is std_ulogic which is more frequently used for modeling bits than type bit
PACKAGE std_logic_INC IS ------------------------------------------------------------------ -- logic state system (unresolved) 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 );
Example
signal ready, request, MRQ : std_logic ; -- where std_logic is a multiple valued logic bit.constant identifier : type_id := constant_expression ;
Example
constant Tio_clh : TIME := 0.1 ns;
constant Tenio_lz : TIME := Tenio_plz + (Tio_clh * (io_cap));
entity acia is generic ( slot_id : in bit_vector ( 0 to 2 )); port ( -- System side data : inout bit_vector (7 downto 0); addrs : out bit_vector (7 downto 0); irq : out bit; bus_busy: inout bit; bus_req: out bit; data_valid: inout bit; -- Asynchronous side xmit : out bit; recv : in bit; r_strobe: in bit; async_clk: in bit; ); end acia ;
Interface Modes -- represent direction of value flow
architecture identifier of entity_identifier is
entity XOR port ( a, b : in bit; z : out bit ); end; architecture nand_gates of XOR is signal s0, s1, s2: bit; begin s0 <= a nand b; s1 <= a nand s0; s2 <= b nand s0; z <= s1 nand s2; end nand_gates;
Note: To compile a VHDL architectural body,
the entity declaration indicated in the configuration specification must
be available in the work library, but this is not required for the architectural
bodies.
library asic; use asic.c_measure, asic.strength_logic; entity nand2 is generic (ycap : capacitance) port (a0,a1 : in iSig; y : out iSig ) end nand2; entity nand4 is generic (ycap : capacitance) port (a0,a1,a2,a3 : in iSig; y : out iSig) end nand6; entity nor2 is generic (ycap : capacitance) port (a0,a1 : in iSig; y : out iSig ) end nor2; entity nor4 is generic (ycap : capacitance) port (a0,a1,a2,a3 : in iSig; y : out iSig) end nor6; entity buf is generic (ycap : capacitance) port (a0 : in iSig; y : out iSig ) end buf; entity ipad is generic (ycap : capacitance) port (a0 : in iSig; y : out iSig ) end ipad; entity opad is generic (ycap : capacitance) port (a0 : in iSig; y : out iSig ) end opad; entity invert is generic (ycap : capacitance) port (a0 : in iSig; y : out iSig ) end invert; entity aoi2x2 is generic (ycap: capacitance) port (a0,a1,b0,b1 : in iSig; y : out iSig) end aoi2x2;
for example:
for example:
PACKAGE std_logic_INC IS ------------------------------------------------------------------ -- logic state system (unresolved) 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 ); ------------------------------------------------------------------ -- unconstrained array of std_ulogic for use with resolution function TYPE std_ulogic_vector IS ARRAY ( NATURAL RANGE <> ) OF std_ulogic; ------------------------------------------------------------------- -- common subtypes SUBTYPE X01 IS resolved std_ulogic RANGE 'X' TO '1'; SUBTYPE X01Z IS resolved std_ulogic RANGE 'X' TO 'Z'; SUBTYPE UX01 IS resolved std_ulogic RANGE 'U' TO '1'; ------------------------------------------------------------------- -- overloaded logical operators FUNCTION "and" ( l : std_ulogic; r : std_ulogic ) RETURN UX01; FUNCTION "nand" ( l : std_ulogic; r : std_ulogic ) RETURN UX01; FUNCTION "or" ( l : std_ulogic; r : std_ulogic ) RETURN UX01; FUNCTION "nor" ( l : std_ulogic; r : std_ulogic ) RETURN UX01; FUNCTION "xor" ( l : std_ulogic; r : std_ulogic ) RETURN UX01; FUNCTION "not" ( l : std_ulogic ) RETURN UX01; ------------------------------------------------------------------- -- vectorized overloaded logical operators FUNCTION "and" ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector; FUNCTION "nand" ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector; FUNCTION "or" ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector; FUNCTION "nor" ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector; FUNCTION "xor" ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector; FUNCTION "not" ( l : std_ulogic_vector ) RETURN std_ulogic_vector; ------------------------------------------------------------------- -- conversion functions FUNCTION To_bit ( s : std_ulogic; xmap : BIT := '0') RETURN BIT; FUNCTION To_bitvector ( s : std_ulogic_vector; xmap : BIT := '0') RETURN BIT_VECTOR; FUNCTION To_StdULogic ( b : BIT ) RETURN std_ulogic; FUNCTION To_StdULogicVector ( b : BIT_VECTOR ) RETURN std_ulogic_vector; ------------------------------------------------------------------- -- strength strippers and type convertors FUNCTION To_X01 ( s : std_ulogic_vector ) RETURN std_ulogic_vector; FUNCTION To_X01 ( s : std_ulogic ) RETURN X01; . . . FUNCTION To_UX01 ( b : BIT_VECTOR ) RETURN std_ulogic_vector; FUNCTION To_UX01 ( b : BIT ) RETURN UX01; ------------------------------------------------------------------- -- edge detection FUNCTION rising_edge (SIGNAL s : std_ulogic) RETURN BOOLEAN; FUNCTION falling_edge (SIGNAL s : std_ulogic) RETURN BOOLEAN; ------------------------------------------------------------------- -- object contains an unknown FUNCTION Is_X ( s : std_ulogic_vector ) RETURN BOOLEAN; FUNCTION Is_X ( s : std_ulogic ) RETURN BOOLEAN; END std_logic_1164; PACKAGE BODY std_logic_1164 IS ------------------------------------------------------------------- -- local types ------------------------------------------------------------------- TYPE stdlogic_1d IS ARRAY (std_ulogic) OF std_ulogic; TYPE stdlogic_table IS ARRAY(std_ulogic, std_ulogic) OF std_ulogic; ------------------------------------------------------------------- -- resolution function ------------------------------------------------------------------- CONSTANT resolution_table : stdlogic_table := ( ----------------------------------------------------------- -- | U X 0 1 Z W L H - | | ----------------------------------------------------------- ( 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U' ), -- | U | ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ), -- | X | ( 'U', 'X', '0', 'X', '0', '0', '0', '0', 'X' ), -- | 0 | ( 'U', 'X', 'X', '1', '1', '1', '1', '1', 'X' ), -- | 1 | ( 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', 'X' ), -- | Z | ( 'U', 'X', '0', '1', 'W', 'W', 'W', 'W', 'X' ), -- | W | ( 'U', 'X', '0', '1', 'L', 'W', 'L', 'W', 'X' ), -- | L | ( 'U', 'X', '0', '1', 'H', 'W', 'W', 'H', 'X' ), -- | H | ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ) -- | - | ); FUNCTION resolved ( s : std_ulogic_vector ) RETURN std_ulogic IS VARIABLE result : std_ulogic := 'Z'; -- weakest state default BEGIN -- the test for a single driver is essential otherwise the -- loop would return 'X' for a single driver of '-' and that -- would conflict with the value of a single driver unresolved -- signal. IF (s'LENGTH = 1) THEN RETURN s(s'LOW); ELSE FOR i IN s'RANGE LOOP result := resolution_table(result, s(i)); END LOOP; END IF; RETURN result; END resolved; ------------------------------------------------------------------- -- tables for logical operations ------------------------------------------------------------------- -- truth table for "and" function CONSTANT and_table : stdlogic_table := ( ------------------------------------------------------ -- | U X 0 1 Z W L H - | | ------------------------------------------------------ ( 'U', 'U', '0', 'U', 'U', 'U', '0', 'U', 'U' ), -- | U | ( 'U', 'X', '0', 'X', 'X', 'X', '0', 'X', 'X' ), -- | X | ( '0', '0', '0', '0', '0', '0', '0', '0', '0' ), -- | 0 | ( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ), -- | 1 |ETC. for about thirty more pages.
Since the members of the WORK library are whatever people have put into it, references to those packages, entities, and architectures must be named by a USE statement before the analyzer will be able to recognize them.
While VHDL does not prescribe how to create libraries, it does assume that libraries of designs will be created, and that a means is needed to explicitly describe where designs are to be found -- either to import declarations, or to select between collections of entities and architectures.
Examples:
Within a VHDL description one may specify LOGICAL library names, which then can be used as part of an extended naming scheme.
The logical name can then be associated with a file name at the system level when the tool is invoked.
Forms:
library ASIC; use ASIC.gate_array.all;
library WORK, STD; use STD.STANDARD.all;
use work.my_pkg.all;
Rev. 1/29/98 B. Huey