91
未未未未未未 未未未未未未未未 ,! [email protected]

未经作者允许,请勿发布 该文档! [email protected] n. VHDL Synthesis & Simulation (Basic Language Items)

Embed Size (px)

Citation preview

Page 1: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

  未经作者允许,请勿发布该文档!

[email protected]

Page 2: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

VHDL

Synthesis & Simulation

(Basic Language Items)

Page 3: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda OverviewOverview Entity Architecture Library & Use Package Configuration

Page 4: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Basic Language Framework

library ieee;use ieee.std_logic_1164.all;---------------------------------------------entity XYZ is port ( A, B, C : in std_logic; -- Comments F : out std_logic );end XYZ;---------------------------------------------architecture XYZ_arch of XYZ isbegin  F <= (A and B) or (B and C) or (C and A); end XYZ_arch;

Include…Include…

EntityEntity

ArchitectureArchitecture

Page 5: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview EntityEntity

KeywordsKeywords Port Generic

Architecture Library & Use Package Configuration

Page 6: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Entitylibrary ieee;use ieee.std_logic_1164.all;---------------------------------------------

entityentity XYZ isis port ( A, B, C : in std_logic; F : out std_logic );

endend XYZ;---------------------------------------------architecture XYZ_arch of XYZ isbegin F <= (A and B) or (B and C) or (C and A);end XYZ_arch;

Include…Include…

EntityEntity

ArchitectureArchitecture

Page 7: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Entity Definition

entityentity entity_name isis [Generics;] [Ports;] [Other Declarative Parts;] [Statements;]

endend [ entity ] [ entity_name ] ;

Page 8: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Entity Examples (ROM)

entityentity ROM is is port ( D0 : out bit; D1 : out bit; D2 : out bit; D3 : out bit; D4, D5, D6, D7 : out bit; A : in bit_vector(7 down to 0) );

endend ROM;

ROM

A0A1A2A3A4A5A6A7

D0D1D2D3D4D5D6D7

Page 9: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Entity Examples (Adder)

entityentity Full_Adder isis port (X, Y, Cin: in Bit; Cout, Sum: out Bit) ;

endend entityentity Full_Adder ; ;

X

Y

Cin

Sum

Cout

Page 10: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Entity Examples (n-input AND)

entityentity ANDN isis

generic (wid : integer := 2); port ( X : in bit_vector(wid-1 downto 0); F : out bit );

endend;

X(0) X(1) X(2)

X(wid-1)

F

Page 11: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Entity Example (Empty Entity)

entityentity Test_Bench isis

endend entityentity Test_Bench ;;

Test_Bench

Signal Generator

Test Target

Page 12: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview EntityEntity

Keywords PortPort Generic

Architecture Library & Use Package Configuration

Page 13: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Entity Definition (Ports)

entityentity entity_name isis Generics;

Ports;Ports; Other Declarative Parts; Statements;endend [ entity ] [ entity_name ] ;

Page 14: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Port Example (ANDN)

entity ANDN is

generic (wid : integer := 2);

portport (

X : in bit_vector(wid-1 downto 0);

F : out bit

);

end;

X(0) X(1) X(2)

X(wid-1)

F

Page 15: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Port Examples (ROM)entity ROM is

portport ( D0 : out bit;

D1 : out bit; D2 : out bit; D3 : out bit; D4, D5, D6, D7 : out bit; A : in bit_vector(7 down to 0) );end ROM;

ROM

A0A1A2A3A4A5A6A7

D0D1D2D3D4D5D6D7

Page 16: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Port Examples (Adder)entityentity Full_Adder isis

portport (X, Y, Cin: in Bit; Cout, Sum: out Bit) ;

end entity Full_Adder ;

X

Y

Cin

Sum

Cout

Page 17: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Port Examples (n-input AND)

entity ANDN is

generic (wid : integer := 2);

portport (

X : in bit_vector(wid-1 downto 0);

F : out bit

);

end;

X(0) X(1) X(2)

X(wid-1)

F

Page 18: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Port DefinitionPortPort ((Port_Name[, Port_Name] : Dir Type[:=Default_Val];;Port_Name[, Port_Name] : Dir Type[:=Default_Val];; .

.

.Port_Name[, Port_Name] : Dir Type[:=Default_Val];;

););

Page 19: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Each Parts of Port portport

((

A0, A1 : in std_logic;

A2 : in std_logic := ‘1’;

F0 : buffer std_logic;

F1 : out std_logic;

F2 : inout std_logic

););

Port Name Dir Type Default Value

Page 20: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Type of “Dir” In Out Inout Buffer Linkage

Page 21: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Signal Direction

D Q

D Q

A0 (IN)

A1 (IN)

A2

(IN)

F0 (BUFFER)

F1 (OUT)

F2 (INOUT)

Other ICOther IC

Page 22: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Dir Example

D Q

D Q

A0 (IN)

A1 (IN)

A2

(IN)

F0 (BUFFER)

F1 (OUT)

F2 (INOUT)

portport

((

A0, A1 : in std_logic;;

A2 : in std_logic := ‘1’;;

F0 : buffer std_logic;;

F1 : out std_logic;;

F2 : inout std_logic

););

Page 23: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Use of Dirlibrary ieee;

use ieee.std_logic_1164.all;

------------------------------

entity ABC is

port

(

A0, A1, A2A0, A1, A2 : inin std_logic;

F0F0 : bufferbuffer std_logic;

F1F1 : outout std_logic;

F2F2 : inoutinout std_logic

);

end ABC;

---------------------------------architecture ABC_arch of ABC isbegin process(A0A0) begin if rising_edge(A0A0) then F0F0 <= not F0F0; F1F1 <= F2F2; end if; end process; F2F2 <= A1A1 when A2A2 = '1' ELSE 'Z';end ABC_arch;

Page 24: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Type portport

((

A0, A1 : in std_logic;

A2 : in std_logic := ‘1’;

F0 : buffer std_logic;

F1 : out std_logic;

F2 : inout std_logic

););

Port Name Dir Type Default Value

Page 25: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Typical Port Type Bit Bit_vector Std_logic Std_logic_vector

Page 26: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Bit ‘1’ ‘0’

Page 27: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Bit_vector

port

( X : in bit_vector(3 downto 0);

F : out bit );

X0X1X2X3

F

Port ( X0 : in bit; X1 : in bit; X2 : in bit; X3 : in bit; F : out bit );

Port (

X0, X1, X2, X3 : in bit; F : out bit );

Page 28: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Std_logic '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

??

Page 29: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Resolution Function Of Std_logicU X 0 1 Z W L H -

U U U U U U U U U U

X U X X X X X X X X

0 U X 0 X 0 0 0 0 X

1 U X X 1 1 1 1 1 X

Z U X 0 1 Z W L H X

W U X 0 1 W W W W X

L U X 0 1 L W L W X

H U X 0 1 H W W H X

- U X X X X X X X X

11

00

??

Page 30: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Std_logic_vector

port

( X : in std_logic_vector(3 downto 0);

F : out std_logic );

X0X1X2X3

F

Page 31: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview EntityEntity

Keywords Port GenericGeneric

Architecture Library & Use Package Configuration

Page 32: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Entity Definition (Generics)

entityentity entity_name isis

Generics;Generics; Ports; Other Declarative Parts; Statements;endend [ entity ] [ entity_name ] ;

Page 33: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

An AND Gate With Unknown Inputs

entity ANDN is

genericgeneric (widwid : integer := 2);

port (

X : in bit_vector(widwid-1 downto 0); F : out bit );end ANDN;

X(0) X(1) X(2)

X(wid-1)

F

Page 34: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Generic Definition

genericgeneric (

Name [, Name] : DataType [:= DefaultValue];; Name [, Name] : DataType [:= DefaultValue];;

...... Name [, Name] : DataType [:= DefaultValue]

);

Page 35: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Generic Example (1)entity abcd is

genericgeneric (

p_a : integer : = 2; p_b : integer : = 7 ); port ( A : out bit_vector(0 to p_a - 1); F : in bit );end;

Page 36: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Use of the Generic (ANDN.vhd)

library ieee;use ieee.std_logic_1164.all;---------------------------------entityentity ANDNANDN is genericgeneric (widwid : integer := 2); port ( X : in bit_vector(widwid-1 downto 0); F : out bit );endend ANDNANDN;---------------------------------architecture ANDN_arch of ANDNANDN isbegin process(X) variable tmp : bit; begin tmp := '1'; for i in widwid-1 downto 0 loop tmp := tmp and X(i); end loop; F <= tmp; end process;end ANDN_arch;

X(0) X(1) X(2)

X(wid-1)

F

Page 37: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Use of the Generic (My_package.vhd)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;---------------------------------package my_package is  componentcomponent ANDNANDN is generic (wid : integer := 2); port ( X : in bit_vector(wid-1 downto 0); F : out bit );

endend component; 

end my_package;

Page 38: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

library ieee;

use ieee.std_logic_1164.all;

library work;

use work.my_package.all;

---------------------------------

entity SEE is

port

( A : in bit_vector(3 downto 0);

B : in bit_vector(1 downto 0);

F1, F2 : out bit );

end SEE;

---------------------------------

architecture SEE_arch of SEE is

begin

U1: ANDNANDN generic map(4)generic map(4) port map (A, F1);

U2: ANDNANDN

port map (B, F2);

end SEE_arch;

Use of the Generic (see.vhd)

U1A(0)A(1)A(2)A(3)

F1

U2B(1)

B(3)F2

Page 39: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview Entity ArchitectureArchitecture

KeywordsKeywords Block Process Subprogram

Function Procedure

Library & Use Package Configuration

Page 40: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Architecturelibrary ieee;use ieee.std_logic_1164.all;---------------------------------------------entity XYZ is port ( A, B, C : in std_logic; F : out std_logic );end XYZ;---------------------------------------------

architecturearchitecture XYZ_arch ofof XYZ isisbeginbegin F <= (A and B) or (B and C) or (C and A);

endend XYZ_arch;

Include…Include…

EntityEntity

ArchitectureArchitecture

Page 41: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Architecture Definition

architecturearchitecture arch_name ofof entity_name isis architecture_declarative_part

beginbegin architecture_statement_part

endend [ architecture ] [ arch_name ] ;

Page 42: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Architecture Example (ABC.vhd)

library ieee;

use ieee.std_logic_1164.all;

------------------------------

entity ABC is

port(

A0,A1,A2 : in std_logic;

F0 : buffer std_logic;

F1 : out std_logic;

F2 : inout std_logic );

end ABC;

---------------------------------

architecturearchitecture ABC_arch ofof ABC isisbeginbegin process(A0) begin if rising_edge(A0) then F0 <= not F0; F1 <= F2; end if; end process; F2 <= A1 when A2 = '1' ELSE 'Z';

endend ABC_arch;

Page 43: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Architecture Example (ANDN.vhd)

library ieee;use ieee.std_logic_1164.all;---------------------------------entity ANDN is generic (wid : integer := 2); port( X : in bit_vector(wid-1 downto 0); F : out bit );end ANDN;---------------------------------

architecturearchitecture ANDN_archANDN_arch ofof ANDN isisbeginbegin process(X) variable tmp : bit; begin tmp := '1'; for i in wid-1 downto 0 loop tmp := tmp and X(i); end loop; F <= tmp; end process;

endend ANDN_archANDN_arch;

X(0) X(1) X(2)

X(wid-1)

F

Page 44: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Use of the Generic (see.vhd)

library ieee;use ieee.std_logic_1164.all;library work;use work.my_package.all;---------------------------------entity SEE is port ( A : in bit_vector(3 downto 0); B : in bit_vector(1 downto 0); F1, F2 : out bit );end SEE;---------------------------------

architecturearchitecture SEE_arch ofof SEE isisbeginbegin U1: ANDN generic map(4) port map (A, F1); U2: ANDN port map (B, F2);

endend SEE_arch;

U1A(0)A(1)A(2)A(3)

F1

U2B(1)

B(3)F2

Page 45: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview Entity ArchitectureArchitecture

Keywords BlockBlock Process Subprogram

Function Procedure

Library & Use Package Configuration

Page 46: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Inside Architecture How to maintain large architecture? How to modulate the architecture code? Separate the architecture in to several parts How to separate the architecture? VHDL language that can separate an

architecture Block Process

Page 47: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Example of Block (BLKBLK.vhd)

library ieee;

use ieee.std_logic_1164.all;

---------------------------------

entity blkblk is

port(X: in std_logic;

Y: out std_logic);

end blkblk;

architecturearchitecture blkblk_arch ofof blkblk isis signal A, B: std_logic; beginbegin

u1: blocku1: block signal C, D: std_logic;

beginbegin A <= C; B <= D; C <= X; D <= X;

end block u1;end block u1;

u2: blocku2: block signal C, E: std_logic;

beginbegin C <= A; E <= B;

u3: blocku3: block signal E, F, G: std_logic;

beginbegin E <= A; F <= E; G <= u2.E;

end block u3;end block u3; end block u2;end block u2; Y <= X and (A or B);endend blkblk_arch;

Page 48: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Definition of Block

BlockLabel: blockblock [( GuardExpression)] [is] Declarations;

beginbegin ConcurrentStatements;

end blockend block [BlockLabel];

Page 49: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Example of Block (BLKBLK.vhd)

library ieee;

use ieee.std_logic_1164.all;

---------------------------------

entity blkblk is

port(X: in std_logic;

Y: out std_logic);

end blkblk;

architecturearchitecture blkblk_arch ofof blkblk isis signal A, B: std_logic; beginbegin

u1: blocku1: block signal C, D: std_logic;

beginbegin A <= C; B <= D; C <= X; D <= X;

end block u1;end block u1;

u2: blocku2: block signal C, E: std_logic;

beginbegin C <= A; E <= B;

u3: blocku3: block signal E, F, G: std_logic;

beginbegin E <= A; F <= E; G <= u2.E;

end block u3;end block u3; end block u2;end block u2; Y <= X and (A or B);endend blkblk_arch;

Page 50: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Example of Block (Test_16.vhd)

begin begin Blck_Test_1: blockblock (clock = '1' and Clock'EVENT)

beginbegin Destination_1 <= guarded Source;Destination_2 <= Source;

end blockend block Blck_Test_1;

Blck_Test_2: blockblock (Clock = '1' and not(Clock'STABLE))

begin begin Destination_3 <=guarded Source;Destination_4 <=Source;

end blockend block Blck_Test_2;

Monitor: processprocessvariable Source_Var : NATURAL;variable Dest_1_Var, Dest_2_Var : NATURAL;variable Dest_3_Var, Dest_4_VAr : NATURAL

begin begin Source_Var := Source;Dest_1_Var := Destination_1; Dest_2_Var := Destination_2;Dest_3_Var := Destination_3; Dest_4_Var := Destination_4;wait on Destination_1,Destination_2, Destination_3,Destination_4;

end processend process Monitor;

Tick_Tock: processprocess beginbegin

wait for 10 ns;Clock <=not clock;

end processend process Tick_Tock; Source_Wave: Source <=1 after 8 ns, 2 after 15 ns, 3 after 16 ns, 4 after 17 ns, 5 after 18 ns,6 after 19 ns;

endend Behave_1;

entityentity Test_16 is isendend Test_16;

architecture architecture Behave_1 ofof Test_16 is is signal Source : NATURAL := 0; signal Destination_1 : NATURAL := 0; signal Destination_2 : NATURAL := 0; signal Destination_3 : NATURAL := 0; signal Destination_4 : NATURAL := 0; signal Clock : BIT := '0';

Page 51: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Guarded Signals In Block

BlockLabel: blockblock [( GuardExpression)][( GuardExpression)] [is] Declarations;

beginbegin ConcurrentStatements;

end blockend block [BlockLabel];

Page 52: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Guarded Signals Example (LT1.vhd)

library ieee;

use ieee.std_logic_1164.all;

entityentity LT1 isis

port

( D, CLK : in bit;

Q : out bit;

Free_in : in bit;

Free_out : out bit );

endend LT1;

architecturearchitecture LT1_arch of of LT1 isisbegin

U1: blockblock

beginbegin Q <= guarded D;

Free_out <= not Free_in;

end blockend block U1;

endend LT1_arch;

Q <= D;

Free_out <= not Free_in;

DCLK

Free_in

Q

Free_out

Page 53: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Guarded Signals Example (LT.vhd)

library ieee;

use ieee.std_logic_1164.all;

entityentity LT isis

port

( D, CLK : in bit;

Q : out bit;

Free_in : in bit;

Free_out : out bit );

endend LT;

architecturearchitecture LT_arch of of LT isisbegin

U1: blockblock (CLK = '1')(CLK = '1')

beginbegin Q <= guardedguarded D;

Free_out <= not Free_in;

end blockend block U1;

endend LT_arch;

Q <= guardedguarded D;

Free_out <= not Free_in;

LatchD

CLK

Free_in

Q

Free_out

Page 54: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Guarded Signals Example (Wave)

Page 55: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview Entity ArchitectureArchitecture

Keywords Block ProcessProcess Subprogram

Function Procedure

Library & Use Package Configuration

Page 56: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Process Definition

[process_label:] processprocess [(sensitivity_list)] [is]

process_declarative_part

beginbegin process_statement_part

end processend process [process_label];

Page 57: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Example of Process (Test_16.vhd)

begin begin Blck_Test_1: blockblock (clock = '1' and Clock'EVENT)

beginbegin Destination_1 <= guarded Source;Destination_2 <= Source;

end blockend block Blck_Test_1;

Blck_Test_2: blockblock (Clock = '1' and not(Clock'STABLE))

begin begin Destination_3 <=guarded Source;Destination_4 <=Source;

end blockend block Blck_Test_2;

Monitor: processprocessvariable Source_Var : NATURAL;variable Dest_1_Var, Dest_2_Var : NATURAL;variable Dest_3_Var, Dest_4_VAr : NATURAL

begin begin Source_Var := Source;Dest_1_Var := Destination_1; Dest_2_Var := Destination_2;Dest_3_Var := Destination_3; Dest_4_Var := Destination_4;wait on Destination_1,Destination_2, Destination_3,Destination_4;

end processend process Monitor;

Tick_Tock: processprocess beginbegin

wait for 10 ns;Clock <=not clock;

end processend process Tick_Tock; Source_Wave: Source <=1 after 8 ns, 2 after 15 ns, 3 after 16 ns, 4 after 17 ns, 5 after 18 ns,6 after 19 ns;

endend Behave_1;

entityentity Test_16 is isendend Test_16;

architecture architecture Behave_1 ofof Test_16 is is signal Source : NATURAL := 0; signal Destination_1 : NATURAL := 0; signal Destination_2 : NATURAL := 0; signal Destination_3 : NATURAL := 0; signal Destination_4 : NATURAL := 0; signal Clock : BIT := '0';

Page 58: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Example of Process (Test_16.vhd zoom)

Monitor: processprocessvariable Source_Var : NATURAL;

variable Dest_1_Var, Dest_2_Var : NATURAL;

variable Dest_3_Var, Dest_4_VAr : NATURAL

begin begin Source_Var := Source;

Dest_1_Var := Destination_1; Dest_2_Var := Destination_2;

Dest_3_Var := Destination_3; Dest_4_Var := Destination_4;

wait on Destination_1,Destination_2, Destination_3,Destination_4;

end processend process Monitor;

Tick_Tock: processprocess

beginbeginwait for 10 ns;

Clock <=not clock;

end processend process Tick_Tock;

Page 59: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Process Example With Sensitive Table (MY_DFF.vhd)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

---------------------------------

entity MY_DFF is

port

( D, CP : in std_logic;

Q : out std_logic );

end MY_DFF;

architecturearchitecture MY_DFF_arch ofof MY_DFF isisbeginbegin

process process (CP)(CP) beginbegin if rising_edge(CP)rising_edge(CP) then

Q <= D; end if;

end process;end process;endend MY_DFF_arch;

D Q CLK

Page 60: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Process Example With ‘Wait’ (MY_DFF.vhd)

architecturearchitecture MY_DFF_arch ofof MY_DFF isis

beginbegin

processprocess

beginbegin

wait until CP'event and CP ='1';wait until CP'event and CP ='1'; Q <= D;

end process;end process;

endend MY_DFF_arch;

D Q CLK

Page 61: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Process Example (Latch.vhd)

library ieee;

use ieee.std_logic_1164.all;

---------------------------------

entity LT is

port

( D, CLK : in bit;

Q : out bit );

end LT;

architecturearchitecture LT_arch ofof LT isisbeginbegin

process process (CLK, D)

beginbegin if CLK = '1' then Q <= D; end if;

end process;end process;endend LT_arch;

D Q CLK

DCLK

Q

Page 62: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Process (PROC2 Diagram)

脉冲生成器 PA

脉冲生成器 PB

to_b

to_a

X

Page 63: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Process Example (Proc2.vhd)

library ieee;use ieee.std_logic_1164.all;----------------------------entity PROC2 is port ( X: in std_logic);end PROC2;

architecturearchitecture PROC2_arch ofof PROC2 isis signal to_a, to_b: std_logic := '0';

beginbegin PA: process(X, to_a) begin if (X'event and X = '1') or (to_a'event and to_a = '1') then to_b <= '1' after 20ns, '0' after 30ns; end if; end process PA; PB: process(to_b) begin if (to_b'event and to_b = '1') then to_a <= '1' after 10ns, '0' after 20ns; end if; end process PB;

endend PROC2_arch;

PA: process(X, to_a) begin if (X'event and X = '1') or (to_a'event and to_a = '1') then to_b <= '1' after 20ns, '0' after 30ns; end if; end process PA;PB: process(to_b) begin if (to_b'event and to_b = '1') then to_a <= '1' after 10ns, '0' after 20ns; end if; end process PB;

脉冲生成器 PA

脉冲生成器 PB

to_b

to_a

X

Page 64: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Process Example (Proc2 Wave)

脉冲生成器 PA

脉冲生成器 PB

to_b

to_a

X

Page 65: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview Entity ArchitectureArchitecture

Keywords Block Process SubprogramSubprogram

FunctionFunction Procedure

Library & Use Package Configuration

Page 66: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Function Definition

functionfunction Name [(ParamList)] returnreturn Type;

functionfunction Name [(ParamList)] returnreturn Type isis DeclarativePart;

beginbegin StatementPart;

end functionend function Name;

Declaration

Body

Page 67: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Functions Example (My_Package.vhd)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

---------------------------------

packagepackage my_package isis

endend my_package;

functionfunction SUM2SUM2(S1, S2: in std_logic_vector)

returnreturn std_logic_vector;

packagepackage bodybody my_package isis

endend my_package;

functionfunction SUM2SUM2(S1, S2: in std_logic_vector)

returnreturn std_logic_vector isis variable tmp: std_logic_vector(S1'range);

beginbegin tmp := S1+S2;

return tmp;

endend SUM2SUM2;

Page 68: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Function Call Examplelibrary ieee;

use ieee.std_logic_1164.all;

library work;

use work.my_package.all;

---------------------------------

entity SUBPROC is

port ( X : in std_logic_vector(3 downto 0);

Y : in std_logic_vector(3 downto 0);

Z : out std_logic_vector(3 downto 0) );

end SUBPROC;

architecturearchitecture SUBPROC_arch ofof SUBPROC isis

beginbegin

Z <= SUM2(X, Y);SUM2(X, Y);endend SUBPROC_arch;

XY

Z

Page 69: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview Entity ArchitectureArchitecture

Keywords Block Process SubprogramSubprogram

Function ProcedureProcedure

Library & Use Package Configuration

Page 70: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Procedure Definition

procedureprocedure Name [(ParamList)]

procedureprocedure Name [(ParamList)] isis DeclarativePart;

beginbegin StatementPart;

end procedureend procedure Name;

Declaration

Body

Page 71: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Procedure Example (My_Pachage.vhd)

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

---------------------------------

packagepackage my_package isis

end end my_package;

packagepackage bodybody my_package isis

endend my_package;

procedureprocedure NOT_PROC NOT_PROC (A : in std_logic

C : out std_logic);

procedure procedure NOT_PROC NOT_PROC (A: in std_logic;

B: out std_logic) isis

beginbegin B := not A;

endend NOT_PROC;NOT_PROC;

Page 72: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Procedure Call Examplelibrary ieee;

use ieee.std_logic_1164.all;

library work;

use work.my_package.all;

---------------------------------

entity SUBPROC is

port( M : in std_logic;

CLK : in std_logic;

K : out std_logic );

end SUBPROC;

architecturearchitecture SUBPROC_arch ofof SUBPROC isis

beginbegin

ProcessProcess (CLK)

variable tmp: std_logic;

beginbegin

if rising_edge(CLK) then

NOT_PROC(M, tmp);NOT_PROC(M, tmp); K <= tmp;

end if;

end process;end process;

endend SUBPROC_arch;

M

CLK

D Q

CLK

K

Page 73: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview Entity Architecture Library & UseLibrary & Use Package Configuration

Page 74: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Library & Use (Definition)

librarylibrary LibraryName, LibraryName, …;

useuse LibraryName.PackageName.ItemName;

useuse LibraryName.PackageName.all;

useuse LibraryName.ItemName;

useuse LibraryName.all;

……

Page 75: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Library & Use Library

Name of library, contain pre-defined design items

Is treated as directory in most EDA tools Commonly used library

IEEE IEEE standard library STD VHDL standard library Work Used defined library

Page 76: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Library & Use (Example)librarylibrary ieee;

useuse ieee.std_logic_1164.all;

useuse ieee.std_logic_arith.all;

useuse ieee.std_logic_unsigned.all;

librarylibrary work;

useuse work.my_package.all;

Page 77: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview Entity Architecture Function Procedure Library & Use PackagePackage Configuration

Page 78: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Format of Package File

package PackageName is PackageDeclarations;

end [package] [PackageName];

package body PackageName is PackageBody;

end [package body] [PackageName];

Declaration

Body

A package file has 2 Parts, Declaration parts and Body parts

Page 79: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Package Example (sub-program)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;---------------------------------

packagepackage my_package isis

function SUM2(S1, S2: in std_logic_vector) return std_logic_vector; procedure NOT_PROC(A: in std_logic; B: out std_logic);

endend my_package;

package bodypackage body my_package isis

function SUM2(S1, S2: in std_logic_vector) return std_logic_vector is variable tmp: std_logic_vector(S1'range); begin tmp := S1+S2; return tmp; end SUM2;

procedure NOT_PROC(A: in std_logic; B: out std_logic) is begin B := not A; end NOT_PROC;

endend my_package;

Page 80: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Package Declarationspackage PackageName is ProcedureDeclaration; FunctionDeclearation; ComponentDeclaration; SubtypeDeclaration; ConstantDeclaration; SignalDeclaration; FileDeclaration; AliasDeclaration; AttributeDeclaration;end [package] [PackageName];

Declaration

Page 81: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Package Example (sub-program)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;---------------------------------

packagepackage my_package isis

function SUM2(S1, S2: in std_logic_vector)return std_logic_vector; procedure NOT_PROC(A: in std_logic; B: out std_logic);

endend my_package;

package bodypackage body my_package isis function SUM2(S1, S2: in std_logic_vector) return std_logic_vector is variable tmp: std_logic_vector(S1'range); begin tmp := S1+S2; return tmp; end SUM2; procedure NOT_PROC(A: in std_logic; B: out std_logic) is begin B := not A; end NOT_PROC;

endend my_package;

Page 82: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Package Example (Component)

library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;---------------------------------

packagepackage my_package isis componentcomponent ANDN isis generic (wid : integer := 2); port ( X: in bit_vector(wid-1 downto 0); F : out bit );

end component;end component;

endend my_package;

entityentity ANDN isis

generic (wid : integer := 2); port (X:in bit_vector(wid-1 downto 0); F:out bit );

endend;

X(0) X(1) X(2)

X(wid-1)

F

Page 83: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Package Example (Type & Constant)

library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;---------------------------------packagepackage my_package isis constant const_K : integer := 100; type state_type is (idle, s0, s1, s2, s3); subtype Byte is Std_logic_vector(7 downto 0); component XYZ is port ( A, B, C : in std_logic; F : out std_logic ); end component; component ANDN is generic (wid : integer := 2); port ( X : in bit_vector(wid-1 downto 0); F : out bit ); end component; function SUM2(S1, S2: in std_logic_vector) return std_logic_vector; procedure NOT_PROC(A: in std_logic; B: out std_logic);endend my_package;

package bodypackage body my_package isis

function SUM2(S1, S2: in std_logic_vector) return std_logic_vector is variable tmp: std_logic_vector(S1'range); begin tmp := S1+S2; return tmp; end SUM2;

procedure NOT_PROC(A: in std_logic; B: out std_logic) is begin B := not A; end NOT_PROC;

endend my_package;

Types & Constan

t

Components

Sub-program

Page 84: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Agenda Overview Entity Architecture Function Procedure Library & Use Package ConfigurationConfiguration

Page 85: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Configuration Definition (1)

configurationconfiguration ConfigName ofof EntityName isis forfor ArchitectureName

end for;end for;

endend [configuration] [ConfigName] ;;

Page 86: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Configuration Example (WHAT.vhd)library ieee;use ieee.std_logic_1164.all;---------------------------------entity WHAT is

port(A, B : in bit;

F : out bit);

end WHAT;

entity WHO is

port(X : in bit;

Y : out bit);

end WHO;

---------------------------------

architecture WHAT_arch0 of WHAT isbegin F <= A and B;end WHAT_arch0; architecture WHAT_arch1 of WHAT isbegin F <= A or B;end WHAT_arch1;architecture WHAT_arch2 of WHAT isbegin F <= A xor B;end WHAT_arch2;architecture WHO_arch0 of WHO isbegin Y <= not X;end WHO_arch0;architecture WHO_arch1 of WHO isbegin Y <= X;end WHO_arch1;

configuration WHO_conf0 of WHO is

for WHO_arch0 end for;end WHO_conf0;

configuration WHO_conf1 of WHO is

for WHO_arch1 end for;end WHO_conf1;

Page 87: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Configuration Example (WHAT)

WHAT

WHO

WHO_conf0

WHO_conf1

Page 88: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Configuration Definition (2)

configurationconfiguration ConfigName ofof EntityName isis forfor Label: ComponentName

USE …;

end for;end for;

endend [configuration] [ConfigName] ;;

Page 89: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Configuration Example (UWHAT.vhd)library ieee;use ieee.std_logic_1164.all;library work;use work.my_package.ALL;entityentity UWHAT is port (A0, A1, A2, A3: in bit; B0, B1, B2, B3: in bit; F0, F1, F2, F3 : out bit;

X0, X1 : in bit; Y0, Y1 : out bit );endend UWHAT;

architecturearchitecture UWHAT_arch0 of UWHAT isbegin U0: WHAT port map(A0, B0, F0); U1: WHAT port map(A1, B1, F1); U2: WHAT port map(A2, B2, F2); U3: WHAT port map(A3, B3, F3); P0: WHO port map(X0, Y0); P1: WHO port map(X1, Y1);endend UWHAT_arch0;

configurationconfiguration UWHAT_conf of UWHAT is for UWHAT_arch0 for U0: WHAT use entity work.WHAT(WHAT_arch0); end for; for U1: WHAT use entity work.WHAT(WHAT_arch1); end for; for others: WHAT use entity work.WHAT(WHAT_arch2); end for; for all: WHO use configuration work.WHO_conf0; end for; end for;endend UWHAT_conf;

U0:WHAT

U1:WHAT

U2:WHAT

P0:WHO

P1:WHO

A0B0

A1B1

A2B2

A3

B3

X0

X1

F0

F1

F2

F3

Y0

Y1

U3:WHAT

Page 90: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Configuration Example (UWHAT)UWHAT

A0B0A1B1A2B2A3B3

X0

X1

F0

F1

F2

F3

Y0

Y1

configurationconfiguration UWHAT_conf of UWHAT is for UWHAT_arch0 for U0: WHAT use entity work.WHAT(WHAT_arch0); end for; for U1: WHAT use entity work.WHAT(WHAT_arch1); end for; for others: WHAT use entity work.WHAT(WHAT_arch2); end for; for all: WHO use configuration work.WHO_conf0; end for; end for;endend UWHAT_conf;

Page 91: 未经作者允许,请勿发布 该文档! yingqichen@sjtu.edu.c n. VHDL Synthesis & Simulation (Basic Language Items)

Configuration Examplearchitecture Structure_View of Processor is component ALU port (…); end component; component MUX port (…); end component; component Latch port ( … ); end component;begin

A1: ALU port map (… ) ;

M1: MUX port map ( … ) ;

M2: MUX port map ( …) ;

M3: MUX port map ( … ) ;

L1: Latch port map ( … ) ;

L2: Latch port map ( … ) ;end Structure_View ;

library TTL, Work ;

configurationconfiguration V4_27_87 ofof Processor isis use Work.all ;

end configurationend configuration V4_27_87 ;

forfor Structure_View

forfor A1: ALU use configuration TTL.SN74LS181 ;

end forend for ;

forfor M1,M2,M3: MUX use entity Multiplex4 (Behavior) ;

end forend for ;

forfor all: Latch -- use defaults

end forend for ;

end forend for ;