Documentos de Académico
Documentos de Profesional
Documentos de Cultura
INTRODUCTION ELEMENTS OF VHDL LANGUAGE ELEMENTS CONCURRENT STATEMENTS SEQUENTIAL STATEMENTS SIGNALS & VARIABLES GENERICS MULTIVALUED LOGIC SYSTEM OPERATOR OVERLOADING PACKAGES
1
Introduction
WHAT IS VHDL? FEATURES OF VHDL HISTORY OF VHDL LEVELS OF ABSTRACTION
What is VHDL?
VHDL stands for
Features of VHDL
VHDL is the amalgamation of following languages: Concurrent Language Sequential Language Timing Specification Simulation Language
Test Language
Concurrent Language
Concurrent Statements execute at the same time in parallel, as in Hardware. Z <= C + X; X <= A + B; X <= A + B; Z <= C + X;
Sequential Language
Sequential Statements execute one at a time in sequence. As the case with any conventional language Sequence of statements is important.
Timing Specification
clock waveform
process begin clock <= not clock; wait for 30 ns; end process;
30
60
90
120
150
180
Test Language
Test bench - Is part of a VHDL model that generates a set of test vectors and sends them to the Module being tested. - Collects the responses made by the Module Under Test and compares them against a specification of correct results.
Design Hierarchy
Hierarchy can be represented using VHDL. Consider example of a Full-adder which is the top-level module, being composed of three lower level modules i.e. Half-Adder and OR gate.
History of VHDL
In 1981 the Institute for Defense Analysis (IDA) had arranged a workshop to study Various Hardware Description methods Need for a standard language Features required by such a standard.
A team of three companies, IBM, Texas Instruments, and Intermetrics were awarded contract by DoD to develop a language.
Version 7.2 of VHDL was released along with Language Reference Manual (LRM) in 1985. Standardized by IEEE in 1987 known as the IEEE Std 1076-1987.
10
Abstraction
1 ABSTRACTION = DETAIL
OR
ABSTRACTION =
THEREFORE Highest Level of abstraction means Lowest Level Of detail. DETAILS OF WHAT ??
Finally we want to make a Chip, Hence Levels of Abstraction Tell us as too how close is our description to What is required to make a chip.
11
DETAIL
Levels of Abstraction
Different styles are adopted for writing VHDL code. Abstraction defines how much detail about the design is specified in a particular description. There are four main levels of Abstraction. Layout Level Logic level Register Transfer Level
Behavioral Level
12
Layout Level
Lowest level of Abstraction. Specifies Actual layout of design on Silicon Contains Detailed timing information, and analog effects.
13
Logic Level
Design has information about Function Architecture Technology Detailed timings Layout information and analog effects are ignored.
14
15
Comb logic
FLIP FLOP
Comb logic
FLIP FLOP
16
Behavioral Level
Describing function of a design using HDLs, without specifying the architecture of registers. Contains timing information required to represent a function.
17
Behavioral Level
Behavioral Model of an AND gate. architecture and_gate_arch of and_gate is begin process(a,b) begin if (a = '1' and b = '1') then c <= '1'; else c <= '0'; end if; end process; end and_gate_arch;
18
Entity
Equivalent to pin configuration of an IC.
Syntax:
entity entity_name is port (port_list) ; end entity_name;
Entity
VHDL design description must include, ONLY ONE ENTITY Entity Declaration Defines the input and output ports of the design. Each port in the port list must be given, a name data flow direction a type. Can be used as a component in other entities after being compiled into a library.
21
Entity
Proper documentation of the ports in an entity is very important. A specified port should have a self explanatory name that provides information about its function. Ports should be well documented with comments at the end of the line providing additional information about the signal. Consider example of an ALU.
22
Entity
entity ALU is port ( In1 : in std_logic_vector (3 downto 0); In2 : in std_logic_vector (3 downto 0); Opsel : in std_logic_vector (3 downto 0); Cin : in std_logic; Mode : in std_logic; Result : out std_logic_vector (3 downto 0); Cout : out std_logic; Equal : out std_logic ); end ALU;
-- first operand -- second operand -- operation select -- carry in -- mode arithm/logic -- operation result -- carry out -- Is 1 when In1 = In2
23
Modes
Signal in the port has a Mode which indicates the driver direction. Mode also indicates whether or not the port can be read from within the entity. Four types of Modes are used in VHDL. Mode IN Mode OUT Mode INOUT Mode BUFFER
24
Mode IN
Value can be read but not assigned. Example: entity driver is port ( A : in std_logic; ); end driver ; Port Signal Entity
Mode OUT
Value can be assigned but not read. Example: entity driver is port ( B : out std_logic; ); end driver ; Drivers reside inside the entity Entity Port Signal
26
Mode INOUT
Bi-directional Value can be read and assigned Example: entity driver is port (Data : inout std_logic) ; end driver ; Entity Port signal Data
Mode BUFFER
Entity Output port with Internal read capability Driver reside Inside the entity Example: entity driver is port (Count : buffer std_logic ) ; end driver ;
Count
28
Architecture
Specifies, Behavior Function Relationship between inputs and outputs of an entity.
Syntax:
architecture architecture_name of entity_name is declarations begin concurrent_statements end [ architecture_name ];
29
Architecture
Equivalent to truth table. Example: A L L H B L H L C L L L
30
Architecture
Can contain only Concurrent Statements. A design can be described in an Architecture using various Levels of Abstraction. To facilitate faster design Better understanding Lesser complexity. AN ENTITY CAN HAVE MORE THAN ONE ARCHITECTURE!!
31
Architecture Bodies
Behavioral Also known as High-level Descriptions. Consists of a set of assignment statements to represent behavior. No need to focus on the gate-level implementation of a design.
32
Architecture Bodies
Dataflow Use concurrent signal assignment statements.
33
Architecture Bodies
Structural Components from libraries are connected together. Designs are hierarchical. Each component can be individually simulated. Consists of VHDL netlists.
35
Configuration
NEED:
36
Configuration
Configuration declaration is used to select one of the many architectures that an entity may have. Syntax: configuration configuration_name of entity_name is for architecture_name for instantiation:component_name use library_name.entity_name(architecture_name); end for; end for; end configuration_name;
37
Configuration
entity gates is port ( a,b : in STD_LOGIC; c: out STD_LOGIC ); end gates; architecture and2_arch of gates is begin c <= a and b; end and2_arch; architecture or2_arch of gates is begin c <= a or b; end or2_arch; configuration and_or of gates is for and2_arch; end for;
38
Language Elements
VHDL is a strongly TYPED Language. VHDL is not case sensitive. VHDL supports a variety of data types and operators. OBJECTS OPERATORS AGGREGATES
39
OBJECTS
Objects are used to represent & store the data in the system being described in VHDL.
The name given to object (also port ) is called as identifier. RESERVED WORDS cannot be used as identifies Each object has a type & class. Class indicates how the object is used in the model & what can be done with the object. Type indicates what type of data the object contains.
40
OBJECTS
Each object belong to one of the following CLASS CONSTANT SIGNAL VARIABLE The set of values that each object can hold is specified by DATA TYPES SCALAR ACCESS FILE COMPOSITE
Integer
Real
Enumerated
Physical
Array
41
CONSTANTS
These are identifiers with fixed value.
Has set of values that signal count : integer range 0 follow within specific range to 8 Has a set of values in given range of real numbers. signal real_data : real range 0.0 to 35.5
Real
Physical
Used to represent physical Constant set_up : time := 2 ns. quantities such as current, time distance
45
Operators
Logical Operators Relational Operators Shift Operators Adding Operators Multiplying Operators Miscellaneous Operators Highest priority Lowest priority (except not) ??
46
Logical Operators
AND OR NAND NOR XOR XNOR NOT
Are defined for Types BIT and BOOLEAN. One dimensional arrays of BIT and BOOLEAN.
Incorrect Examples: port ( a, b, c : bit_vector (3 downto 0); d, e, f, g : bit_vector (1 downto 0); h, i, j, k : bit; l, m, n, o, p : boolean );
h <= i and j or k; l <= m nand n nand o nand p; a <= b and e; h <= i or l; -- parenthesis required; -- parenthesis required; --operands must be of the same size --operands must be of the same type;
47
/=
<
>
<=
>=
= and /= are predefined for all types. <, <=, >, and >= are predefined for For integer types Enumerated types One-dimensional arrays of enumeration and integer types.
48
Relational Operators
No numerical meaning is associated with a BIT vector Elements of a vector are just a collection of objects of the same type.
For array types operands are aligned to the left and compared to the right.
49
sll
sll srl sla sra rol ror
srl
sla
sra
ror
rol
Shift left logical Shift right logical Shift left arithmetic Shift right arithmetic Rotate left logical Rotate right logical
50
Shift Operators
Each operator Takes an array of BIT or BOOLEAN as the left operand Integer value as the right operand Ex: A is a bit_vector equal to 10010101 A sll 2 is 01010100 (shift left logical, filled with 0) A srl 3 is 00010010 (shift right logical, filled with 0) A sla 3 is 10101111 (shift left arithmetic, filled with right bit ) A sra 2 is 11100101 (shift right arithmetic, filled with left bit ) A rol 3 is 10101100 (rotate left) A ror 2 is 01100101 (rotate right)
51
Adding Operators
+
Addition
subtraction
&
concatenation
Concatenation Operator (&) Operands can be one-dimensional array type or element type & Operator works on vectors only. Example: signal a: std_logic_vector ( 5 downto 0 ); signal b,c,d: std_logic_vector ( 2 downto 0 ); begin b <= 0 & c(1) & d(2); a <= c & d; end;
52
Adding Operators
Do not use Concatenation operator on the left of the assignment symbol. architecture bad of ex is signal a : std_logic_vector ( 2 downto 0 ); signal b : std_logic_vector ( 3 downto 0 ); begin 0 & a <= b; -- Error! end bad;
53
Multiplying Operators
* / mod rem
( * ) and ( / ) are predefined for: Integers, Floating point numbers mod ( modulus ) and rem ( remainder ) are predefined for Integers only. Example: variable A,B : Integer; Variable C : Real; C <= 12.34 * ( 234.4 / 43.89 ); A <= B mod 2;
54
Miscellaneous Operators
Abs **
The abs operator has only one operand. It allows defining the operands absolute value. The result is of the same type as the operand.
** ( Exponential Operator ) is defined for any integer or floating point number Examples : 2 ** 8 = 256 3.8 ** 3 = 54.872 abs (-1) = 1
55
Aggregates
Assigns values to the elements of an array. Example : a <= ( others => 0; ) identical to a <= 00000 We can assign values to some bits in a vector and use others clause to assign the remaining bits. Example: a <= ( 1=>1, 3=>1, others =>0 ); signal data_bus : std_logic_vector ( 15 downto 0 ); data_bus <= ( 14 downto 8 => '0', others => '1 );
56
Aggregates
Elements in a vector can also be assigned values of other signals.
Each element of the value defined by an aggregate must be represented ONCE AND ONLY ONCE in the aggregate.
57
Concurrent Statements
MEANING IN HARDWARE TERMS CONCURRENT CONSTRUCTS WHEN_ELSE STATEMENT WITH_SELECT STATEMENT COMPONENT INSTANTIATION USE OF GENERATE STATEMENT
58
Concurrent Statements
Consider X = X+Y; In software: X and Y are register locations The contents of X and Y are added and the result is stored in X.
59
Concurrent Statements
In concurrent statements, there are no implied registers. Feedback is described around Combinational logic.
60
A> B>
0 1 2 z
C>
3
61
A >
0 1 z
??
62
0 1 z
1 x
63
64
No two choices can overlap. All possible choices must be enumerated. Each choice can be either a static expression (such as 3) or a static range (such as 1 to 3). 66
67
Design Hierarchy
Hierarchy can be implemented using VHDL. Predefined design can be used to model complex functionality. Full adder can be implemented using two half adders as shown below Top level IN1 IN2 IN3 Component carry A U1 B C B S A U2 C S
sum
68
Design Hierarchy
entity half is port ( A,B : in BIT; S1,Carry : out BIT); end half; architecture add_arch of half is component xor port ( A,B : in BIT; C : out BIT); end component; component nd2 port ( A,B : in BIT; C : out BIT); end component signal s1,c1, c2 : BIT; begin U1: xor port map (A => a, B =>b, S => S1); U2: ND2 port map ( A =>a, B =>b, C=>carry);
69
Component Instantiation
Component Represents a precompiled Entity- Architecture pair. Instantiation Is selecting a compiled specification in the library and linking it with the architecture where it will be used. Port mapping Assignment of actual signals in the system to the formal ports of the component declaration.
70
Component Instantiation
Syntax:
instance_name : component_name
port map ( [ port_name => ] expression [port_name => ] expression );
instance_name names this instance of the component type by component_name - WHY? port map connects each port of this instance of component_name to a signal-valued expression in the current entity.
71
Component Instantiation
entity ND4 IS port ( IN1,IN2,IN3,IN4 : in BIT; Z : out BIT); end ND4; architecture gate_arch of ND4 is component ND2 port ( A, B: in BIT; C : out BIT); end component; signal TEMP_1,TEMP_2 : BIT; begin U1: ND2 port map ( A =>IN1, B =>IN2, C=>TEMP1 ); U2: ND2 port map ( A =>IN3, B =>IN4, C=>TEMP2 ); U3: ND2 port map ( A =>TEMP1, B =>TEMP2, C=>Z );
72
Component Instantiation
Ports can be mapped to signals by Positional or mixed notation. U1: ND2 port map ( IN1,IN2, TEMP_1 ); U2: ND2 port map (A => X, C => Z, B => Y); U3: ND2 port map (IN1,IN2, C => TEMP1); -- positional -- Named -- Mixed
Named association is preferred because it makes the code more readable and pins can be specified in any order. All positional connections should be placed before any named connections.
73
Generate Statement
Concurrent statements can be conditionally selected or replicated using generate statement.
Used to create multiple copies of components, processes, or blocks. For ex: Provides a compact description of regular structures such as memories, registers, and counters.
74
Generate Statement
Two forms of generate statement forgenerate Number of copies is determined by a discrete range ifgenerate Zero or one copy is made, conditionally Syntax: label: if expression generate { concurrent_statement } end generate [ label ];
Syntax: label: for identifier in range generate { concurrent_statement } end generate [ label ] ;
Note: Range must be a computable integer, in either of these forms: integer_expression to integer_expression integer_expression downto integer_expression Each integer_expression evaluates to an integer.
75
Generate Statement
for.generate Example:
76
Generate Statement
Example:
77
Generate Statement
ifgenerate Example:
78
Generate Statement
Example:
79
Drivers
Are created by signal assignment statements Concurrent signal assignment produces one driver for each signal assignment
80
Drivers
81
Drivers
Signals with multiple sources can be found in numerous applications. Ex. : Computer data bus may receive data from the processor, memory, disks, and I/o devices. Each of the above devices drives the bus and each bus signal line may have multiple drivers. Such multiple source signals require a method for determining the resulting value when several sources are concurrently feeding the same signal line. When defining a synthesizable design do not initialize ports or signals.
82
Resolution Function
VHDL uses a Resolution Function to determine the actual output. For a multiple driven signal, values of all drivers are resolved together to create a single value for the signal. This is known as Resolution Function Examines the values of all of the drivers and returns a single value called the resolved value of the signal. Std_Logic and Std_Logic_Vector are resolved Functions. The de facto industrial standard types.
83
Resolution Function
Bad Model ENTITY mux IS PORT (i0, i1, i2, i3, a, b : IN std_logic; q : OUT std_logic); END mux; ARCHITECTURE bad OF mux IS BEGIN q <= i0 WHEN a =0' AND b = 0' ELSE 0'; q <= il WHEN a =1 AND b = 0' ELSE 0; q <= i2 WHEN a =0' AND b = 1 ELSE '0; q <= i3 WHEN a =1 AND b = 1 ELSE 0; END BAD; Four assignments Better Model ARCHITECTURE better OF mux IS BEGIN q <= i0 WHEN a =0' AND b = 0' ELSE i1 WHEN a =1' AND b = 0' ELSE i2 WHEN a =0' AND b = 1' ELSE i3 WHEN a =1' AND b = 1' ELSE Z; END better; single statement.
84
SEQUENTIAL STATEMENTS
HOW DOES PROCESS WORK?
Sensitivity List
Simulator runs a process when any one of the signals in the sensitivity list changes. Process should either have a sensitivity list or a wait statement at the end.
Only static signal names for which reading is permitted may appear in the sensitivity list of a process statement.
The execution of a process statement consists of the repetitive execution of its sequence of statements.
87
If Statement
if condition1 then Syntax: { sequential_statement }
{ sequential_statement }
end if; If Statement evaluates each condition in order.
if Statement
Avoid using more than three levels of Ifelse statements . When defining the condition, use parentheses to differentiate levels of operations on the condition.
89
If statement
process (sel, a, b, c, d) begin If sel(2) = 1 then y <= A; elsif sel(1) = 1 then y <= B; elsif sel(0) = 1 then y <= C; else y <= D; end if; end process;
Case Statement
Syntax: case expression is when choice1 => { statements } when choice2 => { statements } when others => { statements } end case;
Case Statement is a series of parallel checks to check a condition. It selects, for execution one of a number of alternative sequences of statements. Statements following each when clause is evaluated, only if the choice value matches the expression value.
91
Case statement
process (sel,a,b,c,d) begin case sel is when 0=> y <=a; when 1=> y <=b; when 2=> y <=c; when others => y<=d; end case; end process; Does not result in prioritized logic structure unlike the if statement. Corresponds to with.select in concurrent statements.
92
Case statement
Every possible value of the case expression must be covered in one and only one when clause. Each choice can be either a static expression ( such as 3 ) or a static range ( such as 1 to 3 ). we cannot have a when condition that changes when it is being evaluated.
93
when 0 =>
OUT_1 <= 1; when 1 => OUT_1 <= 0; end case; -- Values 2 to 15 are not covered by choices
94
Null Statement
Does not perform any action Can be used to indicate that when some conditions are met no action is to be performed Example:
case a is
when 00 => q1 <= 1; when 01 => q2 <= 1; when 10 => q3 <= 1;
Example: process ( s,c,d,e,f ) begin if s = 00 then pout<= c; elsif s = 01 then pout <= d; elsif s= 10 then pout <= e; else pout <= f; end if; end process;
96
Process statement
Two types of processes: Combinatorial Clocked Combinatorial Process Generates combinational logic All inputs must be present in the sensitivity list. process (a,b,c) begin x <=( a and b) or c; end process;
98
Process Statement
Clocked Process: Generates synchronous logic.
process (clk) begin if (clk event and clk =1 ) then Q < = D; end if; end process; Any signal assigned under a clkevent generates a Flip-flop.
99
Process Statement
Clocked processes having an else clause will generate wrong hardware.
process(clk) begin if (clk'event and clk = '1') then out1 <= a and b; else out1 <= c; end if; end process;
100
101
Process(CLK) begin If CLK=1 and CLKevent then Q <= D; end if; end process; Qbar <= not D;
process (CLK, RST) begin if ( RST = 1 ) then Q <= 0; elsif ( CLKevent and CLK = 1) then Q <= D; end if; end process;
104
process (clk)
begin if (clkevent and clk = '1') then out1 <= a and b;
end if;
end process;
105
106
ENTITY add IS port (a, b : IN INTEGER range 0 to 7; z : OUT INTEGER range 0 to 15); END add; ARCHITECTURE arithm OF add IS BEGIN z <= a + b;
107
entity test_14 is port ( a, b, SEL : in std_logic; c : out std_logic ); end test_14; architecture test_14_arch of test_14 is begin C<= A WHEN (SEL=0) ELSE B; end test_14_arch;
108
entity test_14 is port ( a, b, SEL : in integer ; c : out integer ); end test_14; architecture test_14_arch of test_14 is begin C<= A WHEN (SEL=0) ELSE B; end test_14_arch;
109
Avoid the inference of latches in synchronous designs. As latches infer feedback and they cause difficulties in timing analysis and test insertion applications. Most synthesizers provide warnings when latches are inferred.
110
111
Process Statement
Value that the signal is updated with is the last value assigned to it within the process execution.
Signals assigned to within a process are not updated with their new values until the process suspends.
112
Wait Statement
Wait statement : Suspends the execution of a process or procedure until some conditions are met. Three basic forms: wait on [sensitivity clause] wait until [condition clause] wait for [timeout clause]
113
Wait On Clause
Wait on statement at the end of the process is equivalent to the sensitivity list at the beginning of the process.
A process with a sensitivity clause must not contain an explicit wait statement.
process -- No Sensitivity list begin if ( clk'event and clk = '1') then q <= d; end if; wait on clk; -- Replaces the Sensitivity list end process;
114
115
116
117
signal cnt3 : std_logic_vector(2 downto 0) := "000"; clk <= not clk after 10 ns; w3 : process begin wait on clk; cnt3 <= cnt3 + '1'; end process w3;
Time 0 10 20 30 40 50 60
Cnt3 0 1 2 3 4 5 6
Cnt4 0 1 1 2 2 3 3
118
cnt5 changes whenever positive edge occurs on clk AND each after 7 ns.
0 17 27 37 47 57 67 77 87
120
Loop statements
Loop statements are used to iterate through a set of sequential statements. Syntax: loop_label: while condition loop sequence_of_statements end loop loop_label
process ( Input ) variable i : POSITIVE := 1; begin L1: while i <= 8 loop Output (i) <= Input (i+8) ; i := i + 1; end loop L1; end process;
121
123
125
sum := 1; j := 0; L3 : loop J := J + 21; sum := sum * 10; if sum > 100 then exit L3; end if; end loop L3;
Note:
126
127
Signals
Represents wires within a circuit.
architecture and_gt of anding is signal temp : std_logic; begin U1 : AND2 portmap (a,b,temp); U2 : AND2 portmap (temp,a,b); end and_gt;
>
Each signal has a history of values i.e holds a list of values which include current value of signal & set of possible future values that are to appear on the signal.
128
Variables
These are objects with single current value. Are used to store the intermediate values between the sequential VHDL statements. Variable can be declared & used inside the process statement only. But retain their value throughout the entire simulation. process ( a ) variable a_int : integer := 1; begin
Note : a_int contains the total number of events that occurred on signal a
a_int := a_int + 1;
end process;
129
Signals vs Variables
Signals or variables are the objects used to store intermediate value in sequential region. A Signal has three properties attached to it Type, Value, Time. Type and Value.
Variables are used and declared in a process. A variable cannot be used to communicate between processes.
Signal assignments are done using Variable assignments are done using
<= :=
Use signals as channels of communication between concurrent statements.In non-synthesizable models, avoid using signals to describe storage elements.Use variable instead. Signals occupy about two orders of magnitude more storage than variables during simulation.Signals also cost a performance penalty due to the simulation overhead necessary to maintain the data structures representing signals.
130
CASE 2 : process (clk) If (clkevent and clk = 1) then temp <= a and b; y <= c and temp;
131
132
133
tb : process begin wait for 10 ns; sum1 := sum1 + 1; sum2 := sum1 + 1; end process;
Time Sum1 0 1 1 2 2 3 3 Sum2 0 2 2 3 3 4 4
138
139
Generics
Are specified in entities inside the generic clause. Provides information to a block from its environment. Example : Size of interface ports, width of components
140
Generics
entity AND_GATE is generic ( N: NATURAL := 3 ); port ( A : in std_logic_vector ( 1 to N ); Z : out bit ); architecture gen_ex of and_gate is begin process (A) variable and_out : bit; begin and_out := 1; for K in 1 to N loop and_out := and_out and A(K); exit when and_out = 0; end loop; Z <= and_out; end process; end gen_ex;
141
Generics
Applications of generics Can be used anywhere in a code where a static value is needed. Use of generics facilitates easy design changes. Used in behavioral modeling of components. For ex. : Timing parameters such as delays, Set-up times, Hold times can be modeled using Generics. Generics Are specified in entities. Hence, any change in the value of a generic affects all architectures associated with that entity. Constants Are specified in architectures. Hence, any change in the value of a constant will be localized to the selected architecture only.
142
Logic Systems
Need for a multi-valued Logic System In real life, a digital system may need more values than just '0' and '1' to represent the signal value. Conventional Logic systems had only three values I.e. 0 , 1 and Z Consider truth table for AND gate A B Y 0 0 0 0 1 0 1 0 0 1 1 1 For 0 Z ??? "Standard Logic" to allow us to represent logic systems with more than just values of '0' and '1'. This is a multi-valued logic system
143
: Value was known, but is not any more. : Value was never known in the first place ! : Handle different output drivers. : Optimizes synthesis implementation.
145
Operator Overloading
Arithmetic operations are not predefined in the language to work on vectors. Example: entity add is port ( a : in std_logic_vector; -------- Error! b : in std_logic_vector; c : out std_logic_vector ); end add; architecture wrong of add is begin c <= a + b; end wrong;
147
Operator Overloading
By using Operator Overloading we can extend the definition of predefined operators. Function bodies are written to define the behavior of overloaded operators.
When the compiler encounters a function declaration in which the function name is an operator enclosed in double quotes, the compiler treats this function as an operator overloading function.
Ex. : function "+"( L: STD_LOGIC_VECTOR; R: STD_LOGIC_VECTOR) return STD_LOGIC_VECTOR is
148
Packages
Package : A convenient way to store & share declarations that are common across many design units. Package consists of two parts Package declaration package package_name is Contains a set of declarations declarations Defines interface for package end package_name; package body package_name is Package body declarations; Specifies the actual behavior of the package. end package_name; A Package Declaration can have only one Package body. Package body is optional.
149
Packages
USE WORK.DECLARE.ALL; use IEEE.std_logic_1164.all; entity AND_4BIT is port ( X, Y, Z : in STD_LOGIC; P :out STD_LOGIC; ); end AND_4BIT; architecture AND_4BIT_arch of AND_4BIT is SIGNAL TEMP1 : STD_LOGIC; begin U1 : and_gt PORT MAP (X,Y,TEMP1); U2 : and_gt PORT MAP (Z,TEMP1,P); end AND_4BIT_arch;
150
No Component declaration
Packages
library IEEE; use IEEE.STD_LOGIC_1164.ALL; package declare is
component and_gt port ( a: in STD_LOGIC; b: in STD_LOGIC; c: out STD_LOGIC ); end component; end declare;
151
Packages
Package can also have function declaration. In such case package declaration requires a package body which will describe the behavior of package
package shifting is function shift (data : std_logic_vector) return std_logic_vector; is end shifting; package body shifting is function shift (data : std_logic_vector) return std_logic_vector is variable done : std_logic_vector (data'range); begin done := data sll 2; -- return data sll 2 (no need to declare variable) return done; end shift; end shifting;
152