VHDL
• What is VHDL?
Hardware
Description
1
History of VHDL
(3)
(4)
2
Usage
(5)
• Design Specification
– unambiguous definition of components and interfaces in a
large design
• Design Simulation
– verify system/subsystem/chip performance prior to design
implementation
• Design Synthesis
– automated generation of a hardware design
(6)
3
Digital System Design Flow
Requirements
• Design flows operate at
multiple levels of abstraction
Functional Design Behavioral Simulation
• Need a uniform description to
translate between levels
Register Transfer RTL Simulation • Increasing costs of design and
Level Design Validation
fabrication necessitate greater
Logic Simulation reliance on automation via
Logic Design Verification CAD tools
Fault Simulation
– $5M - $100M to design new
Timing Simulation chips
Circuit Design
Circuit Analysis – Increasing time to market
pressures
Physical Design Design Rule Checking
(7)
Register Transfer
VHDL Model Level Design
Timing Extraction
4
The Role of Hardware Description
Languages
BEHAVIORAL STRUCTURAL
algorithms processors
register transfers registers
Boolean expressions gates
transfer functions transistors
cells
modules
chips
boards
PHYSICAL [Gajski and Kuhn]
BEHAVIORAL STRUCTURAL
algorithms processors
register transfers registers
Boolean expressions gates
transfer functions transistors
cells
modules
chips
boards
PHYSICAL [Gajski and Kuhn]
5
The Marketplace
Maximum revenue
Revenue loss
Revenue
se
M
ri
ar
t
ke
ke
t
ar
fa
M
ll
From V. K. Madisetti and T. W. Egolf,
“Virtual Prototyping of Embedded
Microcontroller Based DSP Systems,”
IEEE Micro, pp. 9–21, 1995.
Delay
Time
Alternatives
(12)
6
Role of VHDL
H Hardware
D Description
VHDL
L Language
(13)
7
Modeling Digital Systems
Systems Hierarchy
Level of Abstraction
Functions
CPUs, memories
Increasing
•Fidelity
•#of events
ALUs, registers
Switches
(2)
1
Describing Systems
microphone
To the
Processor headphones
ZPS
61899
speakers
amplifier
(3)
(4)
2
What Elements Should be in a
Description?
• VHDL was conceived for the description of digital
systems
– From switches to networked systems
(5)
Event
a a sum
b
b
carry
sum
carry
5 10 15 20 25 30 35 40
Time (ns)
(6)
3
Attributes of Digital Systems: Timing
R
Clk
Triggering D Q
edge
D
Q
Clk
Q
S
10 15 20 25 30 35 40
Time (ns)
(7)
TRANSMIT
ACK
(8)
4
Attributes of Digital Systems: Signal
Values
• We associate logical values with the state of a signal
possible
signal values?
(9)
• Shared Signals
– multiple drivers
(10)
5
Modeling Digital Systems
(11)
• For Simulation
– Discrete event simulation
– Understanding is invaluable in debugging programs
• For Synthesis
– Hardware inference
– The resulting circuit is a function of the building blocks used
for implementation
• Primitives: NAND vs. NOR
• Cost/performance
(12)
6
Simulation vs. Synthesis
entity my_ckt is
port (x, y : in bit ;
z : out bit )
end entity my_ckt;
architecture behavioral of
my_ckt is synthesis
begin
-- some code here
--
end architecture behavioral;
entity my_ckt is
port (x, y :in bit ;
z : out bit )
end entity my_ckt; simulation
architecture behavioral of
my_ckt is
begin
-- some code here
--
end architecture behavioral;
(13)
@5 ns
@5 ns @15 ns
0
@10 ns
Head
(14)
7
Discrete Event Simulation: Example
Simulation Time Event List Head
Initial state: a = b = 1, sum = carry = U
10ns 1Æ0
b
a@15ns
sum
a sum
carry
b
5 10 15 20 25 30 35 40
carry
(15)
(16)
8
Simulation Modeling
a sum
b VHDL Model
carry
compiler
(17)
Design HDL
Specification
Author HDL
Synthesis
Author Hardware
engine
Design
(18)
9
Summary
(19)
10
Basic Language Concepts
a sum
carry
(2)
1
Describing the Interface: The Entity Construct
case insensitive
a sum
b
entity half_ADder is
port ( a, b : in bit;
sum, carry :out bit);
carry end entity half_adder;
VHDL 1993
(3)
(4)
2
Example Entity Descriptions
A B
entity ALU32 is
port( A, B: in bit_vector (31 downto 0);
C : out bit_vector (31 downto 0);
N Op: in bit_vector (5 downto 0);
op Z N, Z: out bit);
end entity ALU32;
C
LSB
MSB
entity D_ff is
D Q port( D, Q, Clk, R, S: in bit;
Q, Qbar : out bit);
end entity D_ff;
clk Q
(5)
entity half_adder is
a sum port (a, b : in bit;
b sum, carry :out bit);
end entity half_adder;
VHDL 1993
(6)
3
Example Entity Descriptions: IEEE 1164
A B entity ALU32 is
port( A, B: in std_ulogic_vector (31 downto 0);
C : out std_ulogic_vector (31 downto 0);
N Op: in std_ulogic_vector (5 downto 0);
op Z N, Z: out std_logic);
end entity ALU32;
entity D_ff is
D Q port( D, Q, Clk, R, S: in std_ulogic;
Q, Qbar : out std_ulogic);
end entity D_ff;
clk Q
(7)
b entity half_adder is
port (a, b : in std_ulogic;
carry sum, carry :out std_ulogic);
end entity half_adder;
(8)
4
Libraries and Packages
package
package
specification of the
declaration
package contents
(9)
Configurations
entity
configuration
architecture-3
architecture-2
architecture-1
5
Design Units
(11)
s2
s3 c_out
c_in
(12)
6
Simple Signal Assignment Statement
(13)
Implementation of Signals
Transaction
0→1 1→Z 1→0
24 23 10
waveform element
(14)
7
Implementation of Signals (cont.)
(15)
driver
(16)
8
Example: Waveform Generation
signal
10 20 30 40
(17)
(18)
9
Conditional Signal Assignment
(19)
Unaffected Signals
library IEEE;
use IEEE.std_logic_1164.all;
entity pr_encoder is
port (S0, S1,S2,S3: in std_logic;
Z : out std_logic_vector (1 downto 0));
end entity pr_encoder;
architecture behavioral of pr_encoder is
begin
Z <= “00” after 5 ns when S0 = ‘1’ else
“01” after 5 ns when S1 = ‘1’ else
unaffected when S2 = ‘1’ else
“11” after 5 ns when S3 = ‘1’ else
“00” after 5 ns;
end architecture behavioral;
(20)
10
Selected Signal Assignment Statement
library IEEE;
use IEEE.std_logic_1164.all;
entity mux4 is
port ( In0, In1, In2, In3 : in std_logic_vector (7 downto 0);
Sel: in std_logic_vector(1 downto 0);
Z : out std_logic_vector (7 downto 0));
end entity mux4;
architecture behavioral-2 of mux4 is
begin
with Sel select
Z <= (In0 after 5 ns) when “00”,
(In1 after 5 ns) when “01”, All options must be covered
(In2 after 5 ns) when “10”, and only one
(In3 after 5 ns) when “11” must be true!
(In3 after 5 ns) when others;
end architecture behavioral;
• The “when others” clause can be used to ensure that all options
are covered
• The “unaffected” clause may also be used here
(21)
entity entity_name is
port( input signals : in type; Define the interface
output signals : out type);
end entity entity_name;
output-signal-1 <= simple, conditional, or selected CSA; Definition of how & when external
output-signal-2 <= simple, conditional, or selected CSA; signal values are computed
end architecture arch_name;
(22)
11
Delay Models in VHDL
• Inertial delay
– Default delay model
– Suitable for modeling delays through devices such as gates
• Transport Delay
– Model delays through devices with very small inertia, e.g.,
wires
– All input events are propagated to output signals
• Delta delay
– What about models where no propagation delays are
specified?
– Infinitesimally small delay is automatically inserted by the
simulator to preserve correct ordering of events
(23)
Input
input
8 ns output
Out 1
2 ns
Out 2
5 10 15 20 25 30 35
12
Transport Delays: Example
a Inertial
b
sum
Transport
carry
s1
s2
(25)
s1 s3
In1
In2 s4
s2
(26)
13
Delta Delays: Behavior
IN1
Delta In2
Events
IN2
S2
S3
S1
S2
10 ∆ 2∆ 3∆
S4
10 20 30 40 50 60 70
(27)
• Delay models
– Inertial
• For devices with inertia such as gates
• VHDL 1993 supports pulse rejection widths
– Transport
• Ensures propagation of all events
• Typically used to model elements such as wires
– Delta
• Automatically inserted to ensure functional correctness of code
blocks that do not specify timing
• Enforces the data dependencies specified in the code
(28)
14
Summary
(29)
15
Modeling Complex Behavior
Outline
• Attributes
(2)
1
Raising the Level of Abstraction
add R1, R2, R3
R W
sub R3, R4, R5
move R7, R3
..
Data Output
Data input
Address
.
Memory Module Instruction Set Simulation
(3)
Description of a
Complex
Process Output signals
Input signals
Sig1 <= …..
Sig2 <= …...
(4)
2
The Process Statement
library IEEE;
use IEEE.std_logic_1164.all;
entity mux4 is
port (In0, In1, In2, In3: in std_logic_vector (7 downto 0);
Sel: in std_logic_vector(1 downto 0);
Z : out std_logic_vector (7 downto 0));
end entity mux4;
(5)
(6)
3
Concurrent Processes: Full Adder
s1
In1 sum
Half Half
Adder Adder
In2 s2
c_in c_out
s3
(8)
4
Concurrent Processes: Half Adder
(9)
Processes + CSAs
library IEEE; MemRead MemWrite
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
(10)
5
Process + CSAs: The Write Process
(11)
(12)
6
Iteration
Example: A Simple Multiplier
architecture behavioral of mult32 is
constant module_delay: Time:= 10 ns;
begin
mult_process: process(multiplicand,multiplier) is
variable product_register : std_logic_vector (63 downto 0) := X”0000000000000000”;
variable multiplicand_register : std_logic_vector (31 downto 0):= X”00000000”;
begin
multiplicand_register := multiplicand;
product_register(63 downto 0) := X”00000000” & multiplier;
for index in 1 to 32 loop
if product_register(0) = ‘1’ then
product_register(63 downto 32) := product_register (63 downto 32) +
multiplicand_register(31 downto 0);
end if;
-- perform a right shift with zero fill
product_register (63 downto 0) := ‘0’ & product_register (63 downto 1);
end loop;
-- write result to output port Concatenation operator
product <= product_register after module_delay;
(13)
Iteration
• while loop
– Boolean expression for termination
(14)
7
Outline
• Attributes
(15)
Process Behavior
• All processes are executed once at start-up
• Thereafter dependencies between signal values and events on
these signals determine process initiation
• One can view processes as components with an
interface/function
• Note that signals behave differently from variables!
library IEEE; begin
use IEEE.std_logic_1164.all; L1: var_s1 := x and y;
L2: var_s2 := var_s1 xor z;
entity sig_var is L3: res1 <= var_s1 nand var_s2;
port (x, y, z: in std_logic; end process;
res1, res2: out std_logic);
end entity sig_var; proc2: process (x, y, z) -- Process 2
begin
architecture behavior of sig_var is L1: sig_s1 <= x and y;
signal sig_s1, sig_s2: std_logic; L2: sig_s2 <= sig_s1 xor z;
begin L3: res2 <= sig_s1 nand sig_s2;
proc1: process (x, y, z) is -- Process 1 end process;
variable var_s1, var_s2: std_logic;
end architecture behavior;
(16)
8
Variables vs. Signals: Example
signals
variables
This transition is
determined by
process initiation
variables signals
• Writing processes
– Use signals to represent corresponding hardware entities
– Use variables when computing (future) values of signals
(18)
9
Simulation and Signals
Execute Process
• Process is initiated
current signal future signal
values values • Compute new signal values using
current signal values
s1 reference compute
s1 – Use the value of the signal
s2 Process Foo at process initiation
s2
– Ignore textual
s7 dependencies between
s7 signals
update
(19)
s1 s3
In1
In2 s4
s2
(20)
10
Using Signals in a Process
library IEEE;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_1164.all;
entity combinational is
entity combinational is
port (In1, In2: in std_logic;
port (In1, In2: in std_logic;
z : out std_logic);
z : out std_logic);
end entity combinational;
end entity combinational;
signal s1, s2, s3, s4: std_logic:= ‘0’;
signal s1, s2, s3, s4: std_logic:=
‘0’; begin
begin sig_in_proc: process (In1, In2) is
s1 <= not In1; begin
s2 <= not In2; s1 <= not In1;
s3 <= not (s1 and In2); s2 <= not In2;
s4 <= not (s2 and In1); s3 <= not (s1 and In2);
z <= not (s3 and s4);
Encapsulate in a s4 <= not (s2 and In1);
process
end architecture behavior; z <= not (s3 and s4);
end process sig_in_proc;
end architecture behavior;
(21)
IN2 IN2
Z Z
S1 S1
S2 S2
S3 S3
S4 S4
10 20 30 40 50 60 70 10 20 30 40 50 60 70
Using concurrent signal assignment statements Using signal assignment statements within a process
(22)
11
Outline
• Attributes
(23)
library IEEE;
use IEEE.std_logic_1164.all;
entity dff is
port (D, Clk : in std_logic;
Q, Qbar : out std_logic);
end entity dff; signifies a value change on signal clk
architecture behavioral of dff is
begin
output: process is
begin
wait until (Clk’event and Clk = ‘1’); -- wait for rising edge
Q <= D after 5 ns;
Qbar <= not D after 5 ns;
end process output;
end architecture behavioral;
(24)
12
The Wait Statement: Waveform
Generation
library IEEE; clock_process: process is
use IEEE.std_logic_1164.all; begin
entity two_phase is phi1 <= ‘1’, ‘0’ after 10 ns;
port(phi1, phi2, reset: out std_logic); phi2 <= ‘0’, ‘1’ after 12 ns, ‘0’ after
end entity two_phase; 18 ns;
architecture behavioral of two_phase is wait for 20 ns;
begin end process clock_process;
rproc: reset <= ‘1’, ‘0’ after 10 ns; end architecture behavioral;
reset
events specified
by the reset phi1
and clock
phi2
processes
10 20 30 40 50 60
Time (ns)
(25)
(26)
13
The Wait Statement
(27)
Outline
• Attributes
(28)
14
Attributes
driver
(29)
Classes of Attributes
• Value attributes
– returns a constant value
• Function attributes
– invokes a function that returns a value
• Signal attributes
– creates a new signal
• Type Attributes
– Supports queries about the type of VHDL objects
• Range attributes
– returns a range
(30)
15
Value Attributes
• Examples
Value attribute Value
type_name’left returns the left most value of type_name in its
defined range
type_name’right returns the right most value of type_name in its
defined range
type_name’high returns the highest value of type_name in its range
type_name’low returns the lowest value of type_name in its range
array_name’length returns the number of elements in the array
array_name
(31)
Example
clk_process: process
begin
wait until (clk’event and clk = ‘1’);
if reset = ‘1’ then
state <= statetype’left;
else state <= next_state;
end if;
end process clk_process;
(32)
16
Function Attributes
(33)
(34)
17
Range Attributes
(35)
Signal Attributes
(36)
18
Signal Attributes: Example
(37)
Outline
• Attributes
(38)
19
State Machines
0/1
Combinational Outputs
Inputs logic
1/0 s0 s1 0/1
1/0
Next state
State
Clk
• Basic components
– Combinational component: output function and next state
function
– Sequential component
• Natural process-based implementation
(39)
library IEEE;
use IEEE.std_logic_1164.all;
entity state_machine is
port(reset, clk, x : in std_logic;
z : out std_logic);
end entity state_machine;
architecture behavioral of state_machine is
type statetype is (state0, state1);
signal state, next_state : statetype := state0;
begin
comb_process: process (state, x) is
begin
--- process description here
end process comb_process;
clk_process: process is
begin
-- process description here
end process clk_process;
end architectural behavioral;
(40)
20
Example: Output and Next State Functions
clk_process: process is
begin
wait until (clk’event and clk = ‘1’); -- wait until the
rising edge
if reset = ‘1’ then -- check for reset and initialize
state
state <= statetype’left;
else state <= next_state;
end if;
end process clk_process;
end behavioral;
(42)
21
Summary
• Processes
– variables and sequential statements
– if-then, if-then-else, case, while, for
– concurrent processes
– sensitivity list
• Attributes
• Modeling State machines
wait on ReceiveData’transaction
if ReceiveData’delayed = ReceiveData then
..
(43)
22
Modeling Structure
microphone
To processor headphones
Micro
3284
speakers
amplifier
(2)
1
Modeling Structure
s1 sum
In1
HA HA
In2 s2
c_out
c_in s3
a sum
a
out
b carry b
ports
Modeling Structure
(4)
2
Example: State Machine
library IEEE; component dff is
use IEEE.std_logic_1164.all; port (clk, reset, d : in std_logic;
entity serial_adder is q, qbar : out std_logic);
port (x, y, clk, reset : in std_logic; end component dff;
z : out std_logic); signal s1, s2 :std_logic;
end entity serial_adder; begin
architecture structural of serial_adder is --
-- -- describe the component interconnection
-- declare the components that we will be using --
-- C1: comb port map (x => x, y => y, c_in =>
component comb is s1, z =>z, carry => s2);
port (x, y, c_in : in std_logic; D1: dff port map(clk => clk, reset =>reset,
z, carry : out std_logic); d=> s2, q=>s1,
end component comb; qbar => open);
end architecture structural;
(6)
3
Hierarchy and Abstraction
-- top level
full_adder.vhd
half_adder.vhd
or_2.vhd
-- bottom level
and2.vhd xor2.vhd
4
Generics
library IEEE;
use IEEE.std_logic_1164.all;
entity xor2 is
generic (gate_delay : Time:= 2 ns);
port(In1, In2 : in std_logic;
z : out std_logic);
end entity xor2;
(9)
(10)
5
Example: Full Adder
s1
In1 sum
In2 H1 H2
s2
c_out
s3
c_in
-- top level
full_adder.vhd
half_adder.vhd
or_2.vhd
-- bottom level
and2.vhd xor2.vhd
(11)
...
H1: half_adder generic map (gate_delay => 6 ns)
port map(a => In1, b => In2, sum => s1, 6 ns
carry=>s2);
H2: half_adder ...
...
6 ns
6 ns
EX1: xor2 generic map 6 ns EX1: xor2 generic map (gate_delay =>
(gate_delay => gate_delay) gate_delay)
... ...
A1: and2 generic map A1: and2 generic map
(gate_delay => gate_delay) (gate_delay => gate_delay) 6 ns
6 ns
6 ns
6 ns
(12)
6
Precedence of Generic Declarations
architecture generic_delay2 of half_adder is
component xor2
generic (gate_delay: Time);
port(a,b : in std_logic;
c : out std_logic);
end component;
component and2
generic (gate_delay: Time:= 6 ns);
takes precedence
port (a, b : in std_logic;
c : out std_logic);
end component;
begin
EX1: xor2 generic map (gate_delay => gate_delay)
port map(a => a, b => b, c => sum);
A1: and2 generic map (gate_delay => 4 ns)
port map(a=> a, b=> b, c=> carry);
end generic_delay2;
Generics: Properties
Design Entity
VHDL Program
signal
signal signal
value value
(14)
7
Example: N-Input Gate
entity generic_or is
generic (n: positive:=2);
port (in1 : in std_logic_vector ((n-1) downto 0);
z : out std_logic);
end entity generic_or;
architecture behavioral of generic_or is
begin
process (in1) is
variable sum : std_logic:= ‘0’;
begin
sum := ‘0’; -- on an input signal transition sum must
be reset
for i in 0 to (n-1) loop
sum := sum or in1(i);
end loop;
z <= sum;
end process;
end architecture behavioral;
(15)
8
Example: N-bit Register
entity generic_reg is
generic (n: positive:=2);
port ( clk, reset, enable : in std_logic;
d : in std_logic_vector (n-1 downto 0);
q : out std_logic_vector (n-1 downto 0));
end entity generic_reg;
architecture behavioral of generic_reg is
begin
reg_process: process (clk, reset)
begin
if reset = ‘1’ then
q <= (others => ‘0’);
elsif (rising_edge(clk)) then
if enable = ‘1’ then q <= d;
end if;
end if;
end process reg_process;
end architecture behavioral;
9
Example: Using Global Resources
library IEEE; signal local_F15, local_phi2 : std_logic; -- local
use IEEE.std_logic_1164.all; signals
begin
entity my_clocks is
O1: osc4 port map(F15 =>local_F15); --
port (phi1, phi2: out std_logic);
instantiate the oscillator
end entity my_clocks;
B1: bufg port map (I => local_F15, O => phi1); --
architecture behavioral of my_clocks is instantiate the two global buffers
component OSC4 is -- on chip oscillator B2: bufg port map (I => local_phi2, O => phi2);
port (F8M : out std_logic; -- 8 Mhz clock
F500k : out std_logic;-- 500Khz clock local_phi2 <= not local_F15; -- phi2 is the
F15 : out std_logic);-- 15 hz clock complement of phi1
end component OSC4;
(19)
(20)
10
Core Generators
(21)
(22)
11
The Generate Statement: Example
• Instantiating an register
entity dregister is
port ( d : in std_logic_vector(7 downto 0);
q : out std_logic_vector(7 downto 0);
clk : in std_logic);
end entity dregisters
architecture behavioral of dregister is
begin
d: for i in dreg’range generate
reg: dff port map( (d=>d(i), q=>q(i), clk=>clk;
end generate;
end architecture register;
(23)
component one_bit is -- declare the single bit ALU a7: one_bit generic map (gate_delay) -- instantiate ALU
generic (gate_delay:time); for bit position 7
port (in1, in2, cin : in std_logic; port map (in1=>in1(width-1), in2=>in2(width-1), result=>
result, cout : out std_logic; result(width-1), cin=>carry_vector(width-2),
opcode: in std_logic_vector (1 downto 0)); opcode=>opcode, cout=>cout);
end component one_bit; end architecture behavioral;
(24)
12
Using the Generate Statement
(25)
Configurations
entity configuration
binding
architecture-3
architecture-2
architecture-1
(26)
13
Component Binding
architecture gate_level of comb is
a combinational z
b logic
Binding Information
carry
Q D
Q Clk
architecture high_speed of comb is
R
• We are concerned with configuring the architecture and not the entity
• Enhances sharing of designs: simply change the configuration
(27)
component dff is
port (clk, reset, d :in std_logic;
q, qbar :out std_logic);
end component dff;
signal s1, s2 : std_logic;
begin
C1: comb port map (a => a, b => b, c_in => s1, z =>z, carry => s2);
D1: dff port map(clk => clk, reset =>reset, d=> s2, q=>s1, qbar =>open);
end architecture structural;
• Search for entity with the same component name
• If multiple such entities exist, bind the last compiled
architecture for that entity
• How do we get more control over binding?
(28)
14
Configuration Specification
library name
architecture structural of full_adder is entity name
-- architecture name
--declare components here
signal s1, s2, s3: std_logic;
--
-- configuration specification
for H1: half_adder use entity WORK.half_adder (behavioral);
for H2: half_adder use entity WORK.half_adder (structural);
for O1: or_2 use entity POWER.lpo2 (behavioral)
generic map(gate_delay => gate_delay)
port map (I1 => a, I2 => b, Z=>c);
begin -- component instantiation statements
H1: half_adder port map (a =>In1, b => In2, sum => s1, carry=> s2);
H2: half_adder port map (a => s1, b => c_in, sum => sum, carry => s2);
O1: or_2 port map(a => s2, b => s3, c => c_out);
end structural;
Configuration Specification
(30)
15
Configuration Declaration
configuration Config_A of full_adder is -- name the configuration
-- for the entity
for structural -- name of the architecture being configured
for H1: half_adder use entity WORK.half_adder (behavioral);
end for;
--
for H2: half_adder use entity WORK.half_adder (structural);
end for;
--
for O1: or_2 use entity POWER.lpo2 (behavioral)
generic map(gate_delay => gate_delay)
port map (I1 => a, I2 => b, Z=>c);
end for;
--
end for;
end Config_A;
(31)
Summary
• Structural models
– Syntactic description of a schematic
• Hierarchy and abstraction
– Use of IP cores
– Mixing varying levels of detail across components
• Generics
– Construct parameterized models
– Use in configuring the hardware
• Configurations
– Configuration specification
– Configuration declaration
(32)
16
Subprograms, Packages, and
Libraries
Essentials of Functions
function rising_edge (signal clock: std_logic) return
boolean is
--
--declarative region: declare variables local to the
function
--
begin
-- body
--
return (expression)
end rising_edge;
(2)
1
Essentials of Functions (cont.)
function rising_edge (signal clock: std_logic) return
boolean is
--
--declarative region: declare variables local to the
function
--
begin
-- body
--
return (expression)
end rising_edge;
(3)
Placement of Functions
Architecture
visible in processes
function W
A, B & C
visible only in
process A
2
Function: Example
begin
output: process
begin
wait until (rising_edge(Clk));
Q <= D after 5 ns;
Qbar <= not D after 5 ns;
end process output;
end architecture behavioral;
(5)
Function: Example
function to_bitvector (svalue : std_logic_vector) return
bit_vector is
variable outvalue : bit_vector (svalue’length-1 downto 0);
begin
for i in svalue’range loop -- scan all elements of the array
case svalue (i) is
when ‘0’ => outvalue (i) := ‘0’;
when ‘1’ => outvalue (i) := ‘1’;
when others => outvalue (i) := ‘0’;
end case;
end loop;
return outvalue;
end to_bitvector
(6)
3
Implementation of Signals
• The basic structure of a signal assignment statement
– signal <= (value expression after time expression)
• RHS is referred to as a waveform element
• Every signal has associated with it a driver
value-time pairs
driver
Shared Signals
driver
driver
(8)
4
Resolved Signals
driver
driver
(9)
Weak Pull Up
Device
... Z
• Physical operation
– If any of the control signals activate the switch, the output
signal is pulled low
• VHDL model
– If any of the drivers attempt to drive the signal low (value at
the head of the driver), the resolution functions returns a
value of 0
– Resolution function is invoked when any driver attempts to
drive the output signal
(10)
5
Resolved Types: std_logic
type std_ulogic is (
‘U’, -- Uninitialized
‘X’, -- Forcing Unknown
‘0’, -- Forcing 0 Type only supports only single drivers
‘1’, -- Forcing 1
‘Z’, -- High Impedance
‘W’, -- Weak Unknown
‘L’, -- Weak 0
‘H’, -- Weak 1
‘-’ -- Don’t care
);
(11)
6
Example
die
global error
signal
chip carrier
(13)
A Complete Example
library IEEE; subtype wire_or_logic is wire_or New resolved
use IEEE.std_logic_1164.all; std_ulogic; type
7
Summary: Essentials of Functions
• Placement of functions
– Visibility
• Formal parameters
– Actuals can have widths bound at the call time
(15)
Essentials of Procedures
(16)
8
Procedures: Placement
architecture behavioral of cpu is
--
-- declarative region
visible to all
-- procedures can be placed in their entirety here
processes
--
begin
process_a: process
visible only within
-- declarative region of a process
process_a
-- procedures can be placed here
begin
--
-- process body
--
end process_a;
process_b: process visible only within
--declarative regions process_b
begin
-- process body
end process_b;
end architecture behavioral;
(17)
Placement of Procedures
Architecture
visible in processes
procedure W
A, B & C
visible only in
process A
(18)
9
Procedures and Signals
procedure mread (address : in std_logic_vector (2 downto 0);
signal R : out std_logic;
signal S : in std_logic;
signal ADDR : out std_logic_vector (2 downto 0);
signal data : out std_logic_vector (31 downto 0)) is
begin
ADDR <= address;
R <= ‘1’;
wait until S = ‘1’;
data <= DO;
R <= ‘0’;
end mread;
(19)
10
Concurrent vs. Sequential Procedure Calls
a z
b Combinational
Logic
carry
Q D
Q Clk
ab/s
11/0
00/0 01/0
01/1 0 1 10/0
10/1 11/1
00/1
(21)
11
Equivalent Sequential Procedure Call
architecture structural of serial_adder is begin
component comb C1: comb port map (a => a, b => b,
port (a, b, c_in : in std_logic; c_in => s1, z =>z, carry => s2);
z, carry : out std_logic); --
end component; -- sequential procedure call
procedure dff(signal d, clk, reset : in std_logic; --
signal q, qbar : out std_logic) is process
begin begin
if (reset = ‘0’) then dff(clk => clk, reset =>reset, d=> s2,
q <= ‘0’ after 5 ns; q=>s1, qbar =>open);
qbar <= ‘1’ after 5 ns; wait on clk, reset,s2;
elsif (clk’event and clk = ‘1’) then end process;
q <= d after 5 ns; end architecture structural;
qbar <= (not D) after 5 ns;
end if;
end dff;
signal s1, s2 : std_logic;
(23)
Subprogram Overloading
R
bit_vector
D Q
D Q
Clk Q
Clk Q
R S
std_logic_vector R
D Q
D Q
Clk Q
Clk Q
S
S
(24)
12
Subprogram Overloading
• Consider the following procedures for the previous components
dff_bit (clk, d, q, qbar)
asynch_dff_bit (clk, d,q,qbar,reset,clear)
dff_std (clk,d,q,qbar)
asynch_dff_std (clk, d,q,qbar,reset,clear)
(25)
Subprogram Overloading
Packages!
(26)
13
Essentials of Packages
• Package Declaration
– Declaration of the functions, procedures, and types that are
available in the package
– Serves as a package interface
– Only declared contents are visible for external use
• Package body
– Implementation of the functions and procedures declared in the
package header
– Instantiation of constants provided in the package header
(27)
package std_logic_1164 is
type std_ulogic is (‘U’, --Unitialized
‘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;
type std_logic_vector is array (natural range <>) of std_logic;
function “and” (l, r : std_logic_vector) return std_logic_vector;
--..<rest of the package definition>
end package std_logic_1164;
(28)
14
Example: Package Body
(29)
Essentials of Libraries
Design VHDL
File Analyzer
.....
(30)
15
Design Units
package
architecture-3 body
architecture-2
architecture-1
(31)
Visibility Rules
library IEEE;
use IEEE.std_logic_1164.all;
entity design-1 is
.....
file.vhd
library IEEE;
use IEEE.std_logic_1164.rising_edge;
entity design-2 is
......
• When multiple design units are in the same file visibility of libraries
and packages must be established for each primary design unit
(entity, package header, configuration) separately!
– Secondary design units derive library information from associated primary
design unit
• The use clause may selectively establish visibility, e.g., only the
function rising_edge() is visible within entity design-2
– Secondary design inherit visibility
• Note design unit descriptions are decoupled from file unit boundaries
(32)
16
Summary
• Functions
– Resolution functions
• Procedures
– Concurrent and sequential procedure calls
• Subprogram overloading
• Packages
– Package declaration - primary design unit
– Package body
• Libraries
– Relationships between design units and libraries
– Visibility Rules
(33)
17
Basic Input and Output
File Objects
• VHDL objects
– signals
– variables
– constants
– Files
• The file type permits us to declare and use file objects
VHDL Program
file:
type declaration
operations
(2)
1
File Declarations
(3)
(4)
2
Binary File I/O (VHDL 1987)
(5)
write(buf,arg) line
3
Example: Use of the TEXTIO Package
use STD.Textio.all; L1: write(buf, “This is an example of
entity formatted_io is -- this entity is empty formatted I/O”);
end formatted_io; L2: writeline(outfile, buf); -- write buffer to
architecture behavioral of formatted_io is file
begin L3: write(buf, “The First Parameter is =”);
process is L4: write(buf, count);
file outfile :text; -- declare the file to be a text file L5: write(buf, ‘ ‘);
variable fstatus :File_open_status; L6: write(buf, “The Second Parameter is = “);
variable count: integer := 5; L7: write(buf, value);
variable value : bit_vector(3 downto 0):= X”6”; L8: writeline(outfile, buf);
variable buf: line; -- buffer to file L9: write(buf, “...and so on”);
begin L10: writeline(outfile, buf);
file_open(fstatus, outfile,”myfile.txt”, L11: file_close(outfile); -- flush the buffer to
write_mode); -- open the file for writing the file
wait;
end process;
end architecture behavioral;
(7)
(8)
4
Example: Type Conversion
(9)
(10)
5
Useful Code Blocks (from Bhasker95)
(11)
(12)
6
Useful Code Blocks: Filenames
process is
variable buf : line;
variable fname : string(1 to 10);
begin
--
-- prompt and read filename from standard input
--
write(output, “Enter Filename: “);
readline(input,buf);
read(buf, fname);
--
-- process code
--
end process;
(13)
library IEEE;
entity checking is
end checking; -- the entity is an empty entity
-- use file I/O to read test vectors and write test results
Testing process
(14)
7
Useful Code Blocks: Testing Models (cont.)
process is
-- use implicit file open
--
file infile : TEXT open read_mode is "infile.txt";
file outfile : TEXT open write_mode is "outfile.txt";
variable check : std_logic_vector (15 downto 0) := x"0008";
begin
-- copy the input file contents to the output file
while not (endfile (infile)) loop
read_v1d (infile, check); Can have a model here to test
--
--
write_v1d (outfile, check);
end loop;
file_close(outfile); -- flush buffers to output file
wait; -- artificial wait for this example Example: Usually will not have this in your models
end process;
end architecture behavioral;
(15)
Testbenches
Model
Tester under
Test
tester. vhd model.vhd
input port
testbench.vhd
(16)
8
Example
library IEEE;
use IEEE.std_logic_1164.all;
use STD.textio.all;
use WORK.classio.all; -- declare the I/O package
entity srtester is -- this is the module generating the tests
port (R, S, D, Clk : out std_logic;
Q, Qbar : in std_logic);
end entity srtester;
architecture behavioral of srtester is
begin
clk_process: process -- generates the clock waveform with
begin -- period of 20 ns
Clk<= ‘1’, ‘0’ after 10 ns, ‘1’ after 20 ns, ‘0’ after 30 ns;
wait for 40 ns;
end process clk_process;
(17)
Example (cont.)
Example (cont.)
io_process: process -- this process performs the test
file infile : TEXT is in “infile.txt”; -- functions
file outfile : TEXT is out “outfile.txt”;
variable buf : line;
variable msg : string(1 to 19) := “This vector failed!”;
variable check : std_logic_vector (4 downto 0);
begin
while not (endfile (infile)) loop -- loop through all test vectors in
read_v1d (infile, check); -- the file
-- make assignments here
wait for 20 ns; -- wait for outputs to be available after applying
if (Q /= check (1) or (Qbar /= check(0))) then -- error check
write (buf, msg);
writeline (outfile, buf);
write_v1d (outfile, check);
end if;
end loop;
wait; -- this wait statement is important to allow the simulation to halt!
end process io_process;
end architectural behavioral;
(18)
9
Structuring Testers
library IEEE;
use IEEE.std_logic_1164.all;
use WORK.classio.all; -- declare the I/O package
entity srbench is
end srbench;
architecture behavioral of srbench is
--
-- include component declarations here
--
-- configuration specification
--
for T1:srtester use entity WORK.srtester (behavioral);
for M1: asynch_dff use entity WORK.asynch_dff (behavioral);
signal s_r, s_s, s_d, s_q, s_qb, s_clk : std_logic;
begin
T1: srtester port map (R=>s_r, S=>s_s, D=>s_d, Q=>s_q, Qbar=>s_qb, Clk =>
s_clk);
M1: asynch_dff port map (R=>s_r, S=>s_s, D=>s_d, Q=>s_q, Qbar=>s_qb, Clk
=> s_clk);
end behavioral;
(19)
Stimulus Generation
(20)
10
Stimulus Generation: Example (Smith96)
process
begin
databus <= (others => ‘0’);
for N in 0 to 65536 loop
databus <= to_unsigned(N,16) xor
shift_right(to_unsigned(N,16),1);
for M in 1 to 7 loop
wait until rising_edge(clock);
end loop;
wait until falling_edge(Clock);
end loop;
--
-- rest of the the test program
--
end process;
• Test generation vs. File I/O: how many vectors would be need?
(21)
(22)
11
Validation
(23)
12
Example: (Bhaskar 95)
architecture check_times of DFF is
constant hold_time: time:=5 ns;
constant setup_time : time:= 2 ns;
begin
process
variable lastevent: time;
begin
if d’event then
assert NOW = 0 ns or (NOW - lastevent) >=
hold_time
report “Hold time too short”
severity FAILURE;
lastevent := NOW;
end if;
-- check setup time
-- D flip flop behavioral model
end process;
end architecture check_times
(25)
Summary
• Basic input/output
– ASCII I/O and the TEXTIO package
– binary I/O
– VHDL 87 vs. VHDL 93
• Testbenches
(26)
13
Programming Mechanics
Design Units
package
architecture-3 body
Secondary Design Units architecture-2
architecture-1
(2)
1
Name Spaces
• Visibility of names
– Visibility of a name follows the hierarchy
• Declared in a package Æ all design units that use the package
• Entity Æ in architectures used for this entity
• Architecture Æ processes used in the architecture
• Process Æ in the process
• Subprogram Æ subprogram
(3)
Design VHDL
File Analyzer
.....
(4)
2
Project Management
(5)
(6)
3
Compilation Dependencies
entity board is
port (….
dependency
Micro
3284
entity micro3284 is
port (..
(7)
• Elaboration
– Of the hierarchy Æ produces a netlist of processes
s1 s3 s5
s2 s4 s6
– Of declarations
• Generics and type checking
– Storage allocation
– Initialization
(8)
4
Basic Steps: Simulation
• Initialization
– All processes are executed until suspended by wait
statements or sensitivity lists
– All nets initialized to default or user specified values
– Initialize simulation time
• Simulation
– Discrete event simulation
– Two step model of time
• Set net values
• Execute all affected processes and schedule new values for
nets
– Simulator step time
(9)
5
Identifiers, Data Types, and
Operators
• Identifiers
– Basic identifiers: start with a letter, do not end with “_”
– Case insensitive
• Data Objects
– Signals
– Constants
– Variables
– Files
(2)
1
VHDL Standard Data Types
(3)
– Examples
type instr_opcode is (‘add’, ‘sub’, ‘xor’, ‘nor’, ‘beq’, ‘lw’, ‘sw’);
type state is (‘empty’, ‘half_full’, ‘half_empty’, ‘empty’);
• Array types
(4)
2
Physical Types
(5)
entity inv_rc is
generic (c_load: real:= 0.066E-12); -- farads
port (i1 : in std_logic;
o1: out: std_logic);
constant rpu: real:= 25000.0; --ohms
constant rpd: real :=15000.0; -- ohms
end inv_rc;
explicit type casting and range management
(6)
3
Physical Types: Example (cont.)
Example adapted from “VHDL: Analysis and Modeling of Digital Systems,” Z. Navabi, McGraw Hill, 1998.
(7)
entity inv_rc is
generic (c_load: capacitance := 66 ffr); -- farads
port (i1 : in std_logic;
o1: out: std_logic);
constant rpu: resistance:= 25000 ohms;
constant rpd : resistance := 15000 ohms;
end inv_rc;
Define a new overloaded multiplication operator
architecture delay of inv_rc is
This expression now becomes
constant tplh: time := (rpu/ 1 l_o)* (c_load/1 ffr) *3 fs/1000;
constant tpll: time := (rpu/ 1 l_o)* (c_load/1 ffr) *3 fs/1000;
begin
o1 <= ‘1’ after tplh when i1 = ‘0’ else
‘0’ after tpll when i1 = ‘1’ or i1 = ‘Z’ else rpu * c_load * 3
‘X’ after tplh;
end delay;
Example adapted from “VHDL: Analysis and Modeling of Digital Systems,” Z. Navabi, McGraw Hill, 1998.
(8)
4
Modeling with Physical Types
• Examples
– Modeling power
– Modeling silicon area
– Modeling physical resources that are “cumulative”
(9)
Operators
(10)
5
References
13. D. Patterson and J. Hennessey, Computer Organization & Design: The Hardware/Soft-
ware Interface. San Francisco : Morgan Kaufmann, 1994.
14. D. Perry, VHDL. New York, NY: McGraw Hill, Second Edition, 1994.
15. M. Richards, “The Rapid Prototyping of Application–Specific Signal Processors Pro-
gram,” Proceedings of the First Annual RASSP Conference, Defense Advanced
Research Projects Agency, 1994.
16. K. Skahill, VHDL for Programmable Logic. Reading, MA: Addison-Wesley, 1996.
17. D. J. Smith, “HDL Chip Design: A Practical Guide for Designing, Synthesizing, and
simulating ASICs and FPGAs using VHLD or Verilog,” Doone Publications, 1996
18. D. E. Thomas, C. Y. Hitchcock III, T. J. Kowalski, J. V. Rajan, and R. A. Walker,
“Automatic Data Path Synthesis,” IEEE Computer, vol. 16, no. 12, December 1983,
pp. 59–70.
19. R. Walker and D. E. Thomas, “A Model of Design Representation and Synthesis,”
Proceedings of the 22nd ACM/IEEE Design Automation Conference, 1985 pp. 453–
459.
20. S. Yalamanchili, Introductory VHDL: From Simulation to Synthesis, Prentice Hall,
2001.