Architecture d'un fichier VHDL

Les deux blocs fondamentaux : l'entité (entity) et l'architecture (architecture).

Structure d'un fichier VHDL

Chaque fichier VHDL contient généralement deux blocs obligatoires :

  1. L'entité (entity) : définit l'interface externe (ports d'entrée/sortie)
  2. L'architecture (architecture) : décrit le comportement interne
-- 1. Déclarations de librairies
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
 
-- 2. Entité
entity nom_entite is
  generic (
    -- paramètres génériques (optionnel)
  );
  port (
    -- ports d'entrée/sortie
  );
end entity nom_entite;
 
-- 3. Architecture
architecture rtl of nom_entite is
  -- zone de déclaration (signaux, constantes, composants)
begin
  -- zone de description (logique concurrente et processus)
end architecture rtl;

Les librairies

Avant de décrire un circuit, on déclare les librairies nécessaires.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;   -- types std_logic, std_logic_vector
use IEEE.NUMERIC_STD.ALL;      -- unsigned, signed, conversions
LibrairieContenu principal
IEEE.STD_LOGIC_1164Types std_logic, std_logic_vector
IEEE.NUMERIC_STDTypes unsigned, signed, opérations arithmétiques
STD.STANDARDChargée automatiquement — types bit, integer, boolean

Attention : Ne pas utiliser IEEE.STD_LOGIC_ARITH et IEEE.STD_LOGIC_UNSIGNED — ces librairies non-standard causent des conflits. Préférer IEEE.NUMERIC_STD.


L'entité (Entity)

L'entité représente la vue externe du composant : son symbole schématique.

entity additionneur is
  generic (
    g_WIDTH : integer := 8   -- paramètre configurable
  );
  port (
    i_clk   : in  std_logic;
    i_rst   : in  std_logic;
    i_a     : in  std_logic_vector(g_WIDTH-1 downto 0);
    i_b     : in  std_logic_vector(g_WIDTH-1 downto 0);
    o_sum   : out std_logic_vector(g_WIDTH downto 0)
  );
end entity additionneur;

Modes de port

ModeSensUsage
inEntrée seulementSignaux de commande, données en entrée
outSortie seulementRésultats, sorties
inoutBidirectionnelBus tristate (rare en FPGA moderne)
bufferSortie relue en interneÉviter : préférer un signal interne

L'architecture (Architecture)

L'architecture définit comment le circuit fonctionne en interne.

architecture rtl of additionneur is
  -- Zone de déclaration
  signal w_carry : std_logic;
  constant c_ZERO : std_logic_vector(g_WIDTH-1 downto 0) := (others => '0');
 
begin
  -- Zone de description (tout est concurrent)
  o_sum <= ('0' & i_a) + ('0' & i_b);
 
end architecture rtl;

Noms d'architecture courants

NomSignification
rtlRegister Transfer Level (synthétisable)
behavioralComportemental (simulation uniquement parfois)
structuralInstanciation de composants
tbTestbench

Concurrence dans l'architecture

En VHDL, tout ce qui est dans la zone begin ... end s'exécute en parallèle, comme des fils électriques :

architecture rtl of exemple is
begin
  -- Ces trois instructions sont toutes actives simultanément
  o_y1 <= i_a AND i_b;
  o_y2 <= i_a OR  i_c;
  o_y3 <= NOT i_a;
end architecture rtl;

Ce n'est pas de la programmation séquentielle ! Penser en termes de hardware.


Commentaires et style

-- Commentaire sur une ligne (double tiret)
 
-- Pas de commentaires /* */ en VHDL standard
-- VHDL-2008 ajoute les commentaires /* */ mais peu d'outils les supportent
 
entity mon_composant is  -- commentaire en fin de ligne OK

Conventions de casse

VHDL est insensible à la casse : Signal, SIGNAL, signal sont identiques. Mais par convention :

  • Mots-clés en minuscules
  • Constantes et génériques en MAJUSCULES
  • Signaux et ports avec préfixes (voir cours 07 — Règles de codage)