Documente Academic
Documente Profesional
Documente Cultură
Daniel Etiemble
de@lri.fr
Introduction à VHDL
• Exemple de conception
– Code VHDL pour réaliser
A[3:0]
un comparateur 4 bits eqcomp4 égal
B[3:0]
-- eqcomp4 est un comparateur 4 bits
entity eqcomp4 is
port (a, b: in bit_vector(3 downto 0);
equals : out bit);
end eqcomp4;
NOTE:
architecture dataflow of eqcomp4 is
1. -- indique un commentaire
begin
equals <= ‘1’ when (a = b) else ‘0’; 2. Deux parties dans le code
end dataflow;
1
Format VHDL
Corps de l’architecture
• Il y a aussi d’autres
aspects Définition fonctionnelle
– package
– configuration
M1 Informatique Architectures avancées 3
2005-2006 D. Etiemble
Déclaration d’entité
ci
• Description des entrées
sorties a[3:0] sum[3:0]
composant
– Description des “ports” Schéma
d’un composant (les
“pattes” d’E/S du entity add4 is port(
schéma) a, b: in std_logic_vector(3 downto 0);
– entity <name> is . . . end ci: in std_logic;
<name>; sum: out std_logic_vector(3 downto 0);
– EXEMPLE : un co: out std_logic);
additionneur 4 bits end add4;
2
PORTS
Modes et types
• Un mode décrit la direction du transfert d’une donnée à travers
un port
– in
– out
– inout (signaux bidirectionnels)
– buffer (un noeud interne utilisé pour feedback)
• Il y a plusieurs types de données disponibles
– Boolean, bit, bit_vector, integer
– La bibliothèque standard IEEE fournit également std_ulogic et
std_logic et des tableaux de ces deux types
• On doit signaler à VHDL d’utiliser cette bibliothèque
library ieee;
use iee.std_logic_1164.all;
3
Architecture
Description comportementale
• Une descripton comportementale
library ieee;
use ieee.std_logic_1164.all;
fournit un algorithme qui modélise le
entity eqcomp4 is port( fonctionnement du circuit
a, b: in std_logic_vector(3 downto 0)
equals: out std_logic);
end eqcomp4; • Une déclaration de processus contient
architecture behavioral of eqcomp4 is un algorithme
begin
comp: process (a, b)
– Elle commence par une étiquette
begin (optionnel), le mot clé “process” et
if a = b then
equals <= ‘1’;
une liste des signaux actifs
else (sensivity list)
equals <= ‘0’;
end if;
– La liste des signaux actifs indique
end process comp; quels signaux provoqueront
end behavioral;
l’exécution du processus
4
Description flot de données
Descriptions structurelles
• Les composants sont
instanciés et connectés.
library ieee; – Ils doivent être définis dans
use ieee.std_logic_1164.all;
entity eqcomp4 is port( un package et compilés dans
a, b: in std_logic_vector(3 downto 0) une bibliothèque
equals: out std_logic);
end eqcomp4; – Les bibliogthèques sont
use work.gatespkg.all;
attachées par une déclaration
architecture struct of eqcomp4 is
signal x : std_logic_vector(0 to 3)
xnor2 and and4 sont dans la
begin bibliothèque work.gatespkg.
u0: xnor2 port map (a(0),b(0),x(0));
u1: xnor2 port map (a(1),b(1),x(1));
u2: xnor2 port map (a(2),b(2),x(2));
u3: xnor2 port map (a(3),b(3),x(3));
u4: and4 port map (x(0),x(1),x(2),x(3),equals);
end struct;
5
Modélisation structurelle en VHDL
VHDL Code
entity MAJORITY is port(
• Aspect du code VHDL : A_IN, B_IN, C_IN: in BIT;
Z_OUT : out BIT);
– L’architecture a trois end MAJORITY;
déclarations
• Deux composants architecture struct of MAJORITY is
--Declare logic operators
• Un signal component AND2_OP
– Les déclarations de port (A, B : in BIT; z : out BIT);
end component;
composants correspondent à component OR3_OP
leur entité port (A, B, C : in BIT; z : out BIT);
end component;
– Les déclarations de signaux --Declare signals to interconnect logic operators
créent un ou plusieurs signaux signal INT1, INT2, INT3 : BIT;
begin
internes A1: AND2_OP port map (A_IN,B_IN,INT1);
A2: AND2_OP port map (A_IN,C_IN,INT2);
A3: AND2_OP port map (B_IN,C_IN,INT3);
A4: OR3_OP port map (INT1,INT2,INT3,Z_OUT);
end struct;
M1 Informatique Architectures avancées 12
2005-2006 D. Etiemble
6
Déclaration de composants
• Les composants nécessaires sont aussi décrits avec
un style VHDL
entity AND2_OP is
entity OR3_OP is
port
port
(A, B : in BIT;
(A, B, C : in BIT;
Z : out BIT);
Z : out BIT);
end AND2_OP;
end OR3_OP;
architecture MODEL of AND2_OP is
architecture MODEL of OR3_OP is
begin
begin
Z <= A and B;
Z <= A or B or C;
end MODEL;
end MODEL;
7
Logique séquentielle
D
CLK
Structures hiérarchiques
entity MAJORITY_2x3 is port(
• Il n’y a pas de restrictions sur A1,B1, C1 : in BIT;
la hiérarchisation des modèles A2, B2, C2 : in Bit;
Z_OUT : out BIT);
structurels end MAJORITY_2x3;
– Les entités d’une réalisation architecture struct of MAJORITY_2x3 is
peuvent utiliser des composants component AND2_OP
port (A, B : in BIT; z : out BIT);
dont les entités à leur tour end component;
peuvent utiliser des composants component MAJORITY
port (A_IN,B_IN,C_IN : in BIT
Z_OUT : out BIT);
end component;
signal INT1, INT2: BIT;
EXEMPLE : un circuit avec deux begin
circuits majorité qui détecte quand M1: MAJORITY port map (A1,B1,C1,INT1);
M2: MAJORITY port map (A2,B2,C2,INT2);
deux groupes de trois entrées ont tous A1: AND2_OP port map (INT1,INT2,Z_OUT);
deux un signal de sortie haut. end struct;
8
PACKAGES
• Un package sert à réutiliser un
package LOGIC_OPS is ensemble de déclarations de
component AND2_OP composants
port (A, B : in BIT; z : out BIT); – Un package commence par le
end component; mot clé package et se termine par
component OR32_OP le mot clé end
port (A, B, C : in BIT; z : out BIT); – Il contient les définitions de
end component; composants et de signaux (et
plus…)
component NOT_OP
• Ce package pourrait être
port (A, : in BIT; A_BAR : out BIT); sauvegardé dans la bibliothèque
end component; WORK et appelé par
end LOGIC_OPS; – uses WORK.LOGIC_OPS.all
• Ou il pourrait être inclus dans le
fichier source qui contient toutes
les entités pour un problème
Bibliothèques
9
Exemple : décodeur
Exemple: décodeur 2 : 4
Z(3)
entity
entity decoder
decoder is
Interface
is
port
port (( A(1) Z(2)
AA :: in
in std_logic_vector(1 downto
std_logic_vector(1 downto
0);
0); A(0) Z(1)
ZZ :: out
out std_logic_vector(3
std_logic_vector(3 downto
downto
0) Z(0)
0)
);
);
end
end entity
entity decoder;
decoder;
A(1..0) Z(3..0)
architecture
architecture when_else
when_else of of decoder
decoder is
is 0 0 0 0 0 1
Fonction
begin
begin
ZZ <= "0001" when A = "00" else 0 1 0 0 1 0
<= "0001" when A = "00" else
"0010"
"0010" when
when AA == "01"
"01" else
else 1 0 0 1 0 0
"0100"
"0100" when
when AA == "10"
"10" else
else
"1000"
"1000" when
when AA == "11"
"11" else
else 1 1 1 0 0 0
"XXXX";
"XXXX";
end
end architecture
architecture when_else;
when_else;
10
Bascule D
architecture
architecture rtl rtl of
of D_FF
D_FF is
is
begin
begin Flip-flop
process
process (Clock,
(Clock, Reset)
Reset) isis
begin
begin D D Q Q
if
if Reset
Reset == ‘1’
‘1’ then
then
QQ <=
<= ‘0’;
‘0’;
if
if rising_edge(Clock)
rising_edge(Clock) Clock
R
then
then
QQ <=
<= D;
D;
end
Reset
end if;
if;
end
end process;
process;
end
end architecture
architecture rtl;rtl;
Compteur binaire
entity
entity counter
counter is is
generic
generic (n (n :: integer
integer :=
:= 4);
4);
port
port ((
clk : in std_logic;
clk : in std_logic;
reset:
reset: inin std_logic;
std_logic;
count:
count: out
out std_logic_vector(n-1
std_logic_vector(n-1 downto
downto
0)
0)
);
); use
use ieee.numeric_std.all;
ieee.numeric_std.all;
end
end entity
entity counter;
counter;
architecture
architecture binary
binary ofof counter
counter isis
begin
begin
process
process (clk,
(clk, reset)
reset)
• Pas de détails sur la manière de
variable
variable cntcnt :: unsigned(n-1
unsigned(n-1 downto
downto
réaliser l’opérateur. 0);
0);
• Le + indique l’opération begin
begin
if
if reset
reset == '1'
'1' then
then -- -- async
async reset
reset
d’incrémentation. cnt
cnt :=
:= (others
(others => => '0');
'0');
elsif rising_edge(clk)
elsif rising_edge(clk) then then
cnt
cnt :=
:= cnt
cnt ++ 1;
1;
end
end if;
if;
count
count <=<= std_logic_vector(cnt);
std_logic_vector(cnt);
end
end process;
process;
end
end architecture
architecture binary;
binary;
M1 Informatique Architectures avancées 22
2005-2006 D. Etiemble
11
Automate (FSM)
Sur la réception d’un signal (trigger), génère un signal active de 2 cycles et attend un signal accept
entity
entity trigger
trigger is
is
port
port ((
clk, reset:
clk, reset: in
in
std_logic;
std_logic;
trigger,
trigger, accept
accept :: in
in clk
std_logic; curr_state
std_logic;
active:
active: out
out
std_logic);
std_logic);
end entity trigger;
end entity trigger;
trigger State
State active
architecture Output
Output
architecture rtl rtl of
of trigger
trigger is
is Transition
Transition Logic
type state_type is (s0, s1, s2); Logic Logic
type state_type is (s0, s1, s2); Logic
signal
signal cur_state,
cur_state, accept R
next_state: state_type;
next_state: state_type;
begin
begin
registers:
registers: process
process (clk,
(clk, reset)
reset)
begin reset
begin
if (reset='1')
if (reset='1') then then
cur_state
cur_state <= <= s0;
s0;
elsif
elsif rising_edge(clk)
rising_edge(clk) then
then
cur_state <= next_state;
cur_state <= next_state;
end if;
M1 Informatique
end if; Architectures avancées 23
end
end process;
2005-2006
process; D. Etiemble
Automate (suite)
process
process (cur_state,
(cur_state, trigger,
trigger, accept)
accept) is
is trigger
begin
begin S0 S1
case cur_state is
case cur_state is
when
when s0
s0 =>
=>
active
active <=<= '0';
'0';
if
if (trigger
(trigger == '1')
'1') then
then
next_state
next_state <=<= s1;
s1;
else
else
accept S2
next_state
next_state <=<= s0;
s0;
end
end if;
if;
when
when s1
s1 =>
=>
active
active <=<= '1';
'1'; clk
next_state
next_state <= <= s2;
s2;
when s2 => curr_state
when s2 =>
active
active <=<= '1';
'1';
if
if (accept
(accept == '1')
'1') then
then
next_state
next_state <=<= s0;
s0;
else
else State
State
next_state Output
Output
next_state <=<= s2;
s2; Transition
Transition Logic
end
end if;
if; Logic Logic
end case;
Logic
end case;
end
end process;
process; R
12
Flot de conception FPGA (1)
Spécifications Réalisation
Description comportementale ou structurelle
Simulation RTL
• Simulation fonctionnelle
•Vérifie le fonctionnement
logique et le flot de données
(pas d’analyse temporelle)
Programmation et test
- Programmation & et test du
composant sur la carte
M1 Informatique Architectures avancées 26
2005-2006 D. Etiemble
13
Cycle de conception : description
• Description du système
Design Entry
– Textuelle (HDL)
• VHDL, Verilog…
Simulation
– Graphique
• Schéma bloc
Synthesis
• Graphe d’états
• Table de vérité
• … Place & Route
Simulation
• Simulation fonctionnelle:
Description
– Indépendante du type de
FPGA
Simulation
– Pas d’information temporelle
• Simulation temporelle Synthèse
– Simulation après placement et
routage
Placement & Routage
– “timing” détaillé
Simulation
Programmation et test
14
Synthèse RTL
• L’entrée est une description HDL
• Compilation & traduction Design Entry
– Génère la liste de noeuds indépendante de la
technologie Simulation
– Schéma TRL (analyse du code HDL)
• Mappage sur la technologie
Synthèse
– Mappage sur les structures spécifiques de la
technologie
• LUTs Place & Route
• Registres
• TAM/ROM
• Blocs DSP
Simulation
• Autres composants
• Optimisation logique Program device & test
– Analyse de l’implantation
Placement et routage
– Placement et routage
Place & Route
– Edition des contraintes
– Annotation de la liste de
Simulation
noeuds avec les informations
temporelles
Program device & test
– Fichier de configuration
15
Exemple : Quartus II d’Altera
• Logiciel de conception intégré
– Plusieurs techniques d’entrée
• textuelles: VHDL, Verilog,
AHDL
• Editeur de schéma
– Synthèse logique
– Placement et routage
– Simulation
– Analyse temporelle et puissance
dissipée
– Création de la “netlist” pour
l’analyse temporelle
– Programmation du composant
• ISE (Xilinx) a des caractéristiques
semblables
16