148
Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems Institute Haute Ecole d’Ingénierie et de Gestion du Canton de Vaud This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License Février 2017 Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 1 / 148

Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Outils pour la simulation VHDLassertions, procédures, attributs

Yann Thoma

Reconfigurable and Embedded Digital Systems InstituteHaute Ecole d’Ingénierie et de Gestion du Canton de Vaud

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Février 2017

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 1 / 148

Page 2: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Plan

1 Introduction

2 Conventions

3 Wait

4 Assertions et messages

5 Boucles

6 Sous-programmes

7 Attributs

8 Accès aux fichiers

9 Paquetages

10 Contextes

11 Type protégé et variables partagées

12 Nombres Aléatoires

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 2 / 148

Page 3: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Introduction

Introduction

VHDL permet le design de circuitsSous-ensemble du langage

ET la simulationLangage complet

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 3 / 148

Page 4: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Introduction

Outils du langage

Les possibilités du langage bénéfiques à la vérification sont:wait, after: gestion du tempsassert: vérification d’assertionreport: affichage de messagesAttributs des signauxFonctions et procéduresAccès aux fichiers

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 4 / 148

Page 5: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Conventions

Conventions REDS pour les unités

Le nom du fichier correspond au nom de l’entité

Contenu Suffixe du fichier

Entité/Architecture (design) .vhdBanc de test _tb.vhdPaquetage _pkg.vhdContexte _ctx.vhd

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 5 / 148

Page 6: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Conventions

Conventions REDS pour les identificateurs

Déclaration au top

n<Nom_signal>_o signal actif bas

Déclaration dans l’entité

<nom_signal>_i entrée (in)<nom_signal>_o sortie (out)<nom_signal>_io entrée/sortie (inout)NOM_CONSTANTE constante générique

Déclaration dans l’architecture

<nom_signal>_s signal interneNOM_CONSTANTE constante

Déclaration dans un processus

<nom_signal>_v variable

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 6 / 148

Page 7: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Conventions

Conventions REDS pour les identificateurs

Dans les fichiers de simulation

<nom_Signal>_sti signal de stimulus (entrée)<nom_Signal>_obs signal observé (sortie)<nom_Signal>_ref signal de référence (calculé)

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 7 / 148

Page 8: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Conventions

Conventions - Exploitation dans les scripts

Le respect des conventions permet de faciliter l’ajout de signauxdans le chronogramme de sortie de simulation

Exemple: wave.do

add wave -noupdate -divider Stimuliadd wave -noupdate *_stiadd wave -noupdate -divider Referencesadd wave -noupdate *_refadd wave -noupdate -divider Observedadd wave -noupdate *_obs

# Ou groupeadd wave -noupdate -expand -group Stimuli *_stiadd wave -noupdate -expand -group References *_refadd wave -noupdate -expand -group Observed *_obs

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 8 / 148

Page 9: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Instruction wait

L’instruction wait permet d’attendre:1 Qu’un des signaux d’une liste soit modifié2 Qu’une condition soit vérifiée3 Qu’un certain temps se soit écoulé

Le premier évènement qui arrive termine l’instruction wait

Syntaxe[label: ] wait [on sensitivity_list]

[until condition][for time_expression];

sensitivity_list = signal1, signal2, ...time_expression = une valeur de temps, de type time;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 9 / 148

Page 10: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Type time

time est un type physiquecaractérisé par son unité de base, l’intervalle de ses valeurs et seséventuelles sous-unités

type timetype time is range -(2**63-1) to (2**63+1)-- 64 bits nécessaires pour exprimer l’heure en femtosecondes

unitsfs; -- unité de baseps = 1000 fs;ns = 1000 ps;us = 1000 ns;ms = 1000 us;sec = 1000 ms;min = 60 sec;hr = 60 min;

end units;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 10 / 148

Page 11: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Type time: exemple

Exempleconstant CLK_PERIOD: time := 10 ns;

constant Ta: time := 100 ms;

constant Ta: time := Ta + 10 ns;

Attention, il faut un espace entre la valeur et l’unité!

Code non valideconstant CLK_PERIOD: time := 10ns;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 11 / 148

Page 12: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Instruction wait

L’instruction wait ne peut être utilisée que dans la zone dedéclaration séquentielle

processbegin

...wait ...;...

end process;

function ...begin

...wait ...;...

end function;

procedure ...begin

...wait ...;...

end procedure;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 12 / 148

Page 13: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Instruction wait: Exemples

constant CLK_PERIOD: time := 10 ns; -- constante de type time

wait; -- attente infinie

wait for 10 ns; -- attente de 10 ns

wait for CLK_PERIOD; -- attente de 10 ns

wait on SignalA; -- attente que SignalA change de valeur

wait on SignalA until SignalA=’1’; -- attente que SignalA change de-- valeur et vaille ’1’

wait on SignalA for 100 ns; -- attente que SignalA change de valeur,-- mais au maximum 100 ns

wait until rising_Edge(clk); -- attente d’un flanc montant de clk

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 13 / 148

Page 14: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Time et simulation

Attention, l’unité de temps de la simulation doit être au moinsaussi petite que la plus petite unité utilisée!!!

Exemple, si le pas de simulation est 1 nsconstant CLK_PERIOD: time := 10 ns;

constant Ta: time := 10 ps;

processbegin

wait for CLK_PERIOD; -- okwait for Ta; -- problème de simulation

end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 14 / 148

Page 15: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Wait: génération des signaux

Les signaux d’entrée de l’entité à tester doivent être forcés par letesteur.L’utilisation de l’instruction wait est cruciale.Autre possibilité: clause after.

Exempleconstant CLK_PERIOD: time:=40 ns; ...a<=’0’, ’1’ after 10 ns, ’0’ after 20 ns, ’1’ after 60 ns;b<=’0’, ’1’ after CLK_PERIOD, ’0’ after 2*CLK_PERIOD;generateur: processbegin

c<=’0’;wait for 10ns;c<=’1’;wait for 10ns;c<=’0’;wait for 40ns;c<=’1’;wait;

end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 15 / 148

Page 16: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Banc de test: génération d’une horloge

Pour un système synchrone, un processus du testeur est responsablede générer une horloge:

Génération d’horlogeconstant CLK_PERIOD: time:=40 ns;signal clk: std_logic;...clk_process: processbegin

clk<=’0’;wait for CLK_PERIOD/2;clk<=’1’;wait for CLK_PERIOD/2;

end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 16 / 148

Page 17: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Banc de test: génération d’un reset

Pour un système synchrone, un processus du testeur doit êtreresponsable de générer un reset.Pourquoi?Pour éviter que les bascules ne se trouvent dans l’état indéfini ’U’.Elles contiennent alors leurs valeurs initiales correctes.

Génération de resetconstant CLK_PERIOD: time:=40 ns;signal nreset: std_logic;...reset_process: processbegin

nreset<=’0’;wait for CLK_PERIOD/4;nreset<=’1’;wait;

end process;-- Cet exemple ne fonctionne-- que pour un reset asynchrone!!!

Génération de resetconstant CLK_PERIOD: time:=40 ns;signal nreset: std_logic;...reset_process: processbegin

nreset<=’0’;wait for CLK_PERIOD;nreset<=’1’;wait;

end process;-- Cet exemple fonctionne également-- pour un reset synchrone.

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 17 / 148

Page 18: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Notion de temps

Le VHDL définit la notion de tempsPossibilité de modéliser le comportement réel des portes logiques

Retard sur la mise à jour des sortiesRetard sur les fils

Possibilité d’utiliser le même langage pourSynthèseSimulationModélisationSpécification

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 18 / 148

Page 19: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Notion de temps

Permet de simuler l’écoulement du tempsEst intégrée dans la notion de signalGrâce à la clause after

B <= A after 10 ns;

Signal A

Signal B 10 ns

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 19 / 148

Page 20: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Pilote d’un signal

La notion de temps permet d’exprimer l’évolution d’un signalLe pilote d’un signal stocke l’évolution de la valeur du signal aucours du temps

Valeur courante du signalvaleur

'1'

20 ns

'0' '1'

30 ns

'0'

40 ns

'1'

10 ns

Valeur courante du signal

couple date/valeur prévue

'0'

10 ns

valeurpassée

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 20 / 148

Page 21: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Pilote d’un signal

Le pilote d’un signal :Modélise le comportement réel d’un signal sur un fils,interconnexion, ... d’un circuit électroniquePermet de modéliser les temps de propagation des portes

Des attributs nous permettrons de tester les valeurs contenuesdans le pilote

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 21 / 148

Page 22: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Délais inertial et transport

Il existe deux types de délaiInertiel (par défaut): les impulsions d’une durée inférieure au délaiindiqué sont supprimées du signal affecté

S <= inertial A after 10 ns; -- ExpliciteS <= A after 10 ns; -- Par défaut

Transport: retard pur

S <= transport A after 10 ns;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 22 / 148

Page 23: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Délai inertiel avec option reject

Modélise un délai où l’impulsion filtrée est plus petite que le retardpur :

S <= reject 5 ns inertial A after 10 ns;

Dans l’exemple ci-dessus, les impulsions inférieures à 5 ns sontfiltrées. Les impulsions supérieures à 5 ns sont retardées de 10ns (comme le délai transport)

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 23 / 148

Page 24: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Délai inertiel: exemple

A <= ’0’, ’1’ after 5 ns, ’0’ after 10 ns,’1’ after 20 ns, ’0’ after 22 ns;

S <= A after 3 ns; --delai inertial

3ns

A

0 55 10 15 20 25

S

3ns L'impulsion

est filtrée

3ns

5ns

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 24 / 148

Page 25: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Délai inertiel: exemple

A <= ’1’, ’0’ after 10 ns, ’1’ after 20 ns;B <= ’0’, ’1’ after 5 ns, ’0’ after 22 ns;

S <= A and B after 3 ns; --delai inertial

3ns

A

B

0 55 10 15 20 25

S

3nsL'impulsion

est filtrée

3ns

5ns

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 25 / 148

Page 26: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Délai transport: exemple

A <= ’0’, ’1’ after 5 ns, ’0’ after 10 ns,’1’ after 20 ns, ’0’ after 22 ns;

S <= transport A after 3 ns;

A

0 55 10 15 20 25

S

3ns

5ns

3ns 3ns L'impulsion est

transmise, durée 2ns

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 26 / 148

Page 27: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Délai transport: exemple

A <= ’1’, ’0’ after 10 ns, ’1’ after 20 ns;B <= ’0’, ’1’ after 5 ns, ’0’ after 22 ns;

S <= transport A and B after 3 ns;

A

B

0 55 10 15 20 25

S

3ns 3ns

5ns

3ns L'impulsion est

transmise, durée 2ns

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 27 / 148

Page 28: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Délai inertiel avec reject: exemple

A <= ’0’, ’1’ after 10 ns, ’0’ after 20 ns,’1’ after 30 ns, ’0’ after 35 ns,’1’ after 50 ns, ’0’ after 53 ns;

S <= reject 4 ns inertial A after 6 ns;

Impulsion

propagée10 ns

6 ns 6 ns 6 ns 6 ns

5 ns3 ns

60

A

0 10 20 30 40 50

S

Impulsion

filtrée

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 28 / 148

Page 29: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Analyse du fonctionnement des délais

Délai inertielLors de l’affectation, les valeurs futures enregistrées dans le pilotesont supprimées

Délai transportLors de l’affectation, seules les valeurs futures ayant un délai égalou supérieur sont modifiées.

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 29 / 148

Page 30: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Wait

Utilisation

Les délais permettent de:Simuler les délais des portes logiques

Pourrait être intégré dans un design structurelSimuler des délais sur des liens

Par exemple entre deux cartesAvec des longueurs de liens variables

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 30 / 148

Page 31: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Assertions et messages

Instruction assert

La clause assert permet de faire apparaître un diagnostic lorsd’une simulation.Il est possible de vérifier si une affirmation est vraie ou fausse.Si l’affirmation est fausse, nous parlons de violation d’assertion

Le niveau d’erreur est affiché par le simulateur.Par défaut, le niveau de sévérité est NOTE

un message peut également être émis.

Syntaxeassert boolean_expression [report expression] [severity level];

-- le type severity_level est défini dans la librairie STD.type severity_level is (NOTE, WARNING, ERROR, FAILURE);

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 31 / 148

Page 32: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Assertions et messages

Instruction assert

L’instruction assert peut être utilisée dans:la zone de description concurrente

entity ...begin

...assert ...;...

end entity;

architecture ...begin

...assert ...;...

end architecture;

la zone de déclaration séquentielle

process ...begin

...assert ...;...

end process;

function ...begin

...assert ...;...

end function;

procedure ...begin

...assert ...;...

end procedure;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 32 / 148

Page 33: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Assertions et messages

Assertions

L’évaluation de l’assertion se fait en fonction de son emplacementDans la zone de description concurrente

A chaque fois qu’un des signaux de la condition change de valeurDans la zone de déclaration séquentielle

A chaque fois que l’instruction séquentielle est atteinte

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 33 / 148

Page 34: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Assertions et messages

Assertions: Exemple

architecture comp of dut_tb is...

begin

-- L’assertion est vérifiée à chaque fois que BCD_obs changeassert (BCD_obs<=9) report "BCD a dépassé sa capacité"

severity WARNING;

process testbegin

...-- L’assertion n’est vérifiée que lorsque l’exécution du-- processus passe à cette instructionassert (A_obs=A_ref) report "résultat incorrect pour A"

severity ERROR;...assert (A_obs=15) report "La sortie A ne vaut pas 15"

severity ERROR;end test;

end comp;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 34 / 148

Page 35: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Assertions et messages

Instruction report

L’instruction report permet de faire apparaître un message lorsd’une simulation.

Le niveau d’erreur est affiché par le simulateur.Par défaut, le niveau de sévérité est NOTE

Syntaxereport expression [severity level];

-- le type severity_level est défini dans la librairie STD.type severity_level is (NOTE, WARNING, ERROR, FAILURE);

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 35 / 148

Page 36: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Assertions et messages

Instruction report

L’instruction report ne peut être utilisée que dans la zone dedéclaration séquentielle

processbegin

...report ...;...

end process;

function ...begin

...report ...;...

end function;

procedure ...begin

...report ...;...

end procedure;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 36 / 148

Page 37: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Assertions et messages

Report: Exemple

Exemplereport "Debut de la simulation";-- identique àreport "Debut de la simulation" severity NOTE;

if (A_ref/=A_obs) thenreport "résultat incorrect pour A" severity error;

end if;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 37 / 148

Page 38: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Assertions et messages

assert vs. report

Les deux codes suivants ont le même comportement

procedure test isbegin

...if (a_ref/=a_obs) then

report "Erreur sur A";end if;...

end test;

procedure test isbegin

...assert (a_ref=a_obs)

report "Erreur sur A";...

end test;

L’instruction assert devrait toujours être utilisée avec unreport, afin d’offrir des messages explicites

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 38 / 148

Page 39: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Assertions et messages

Affichage d’une valeur

Il est possible d’afficher la valeur d’un signal ou d’une variable

Exemplesignal entier : integer;signal unbit : std_logic;...processbegin

...report "La valeur de entier est" & integer’image(entier);

report "Le signal unbit vaut: " & std_logic’image(unbit);end process;

’image() n’est pas accessible pour le type std_logic_vectorIl faut développer soi-même une fonction (binaire ou hexa)

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 39 / 148

Page 40: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Boucles

Boucles

Les boucles permettent d’effectuer une répétition d’instructionsGénérer un ensemble de stimuliVérifier régulièrement les sorties du système

Types de boucles:Boucle simple: loopBoucle for: for ... loopBoucle while: while ... loop

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 40 / 148

Page 41: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Boucles

Loop

Syntaxe[label_loop :]loop

...end loop [label_loop];

Sortie de boucleexit [label_loop]; exit [label_loop] when <expression booléenne>;

Instruction nextnext [label_loop]; next [label_loop] when <expression booléenne>;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 41 / 148

Page 42: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Boucles

Loop: exemple

Exemple 1loop

...if a=10 then

next;end if;...if a > 15 then

exit;end if;

end loop;

Exemple 2loop

...

...next when a=10;.........exit when a > 15;...

end loop;

Le comportement des deux exemples est identique

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 42 / 148

Page 43: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Boucles

Loop: exemple

Exemple 3uneloop:loop

uneautre:loop...next uneloop when a=10;...exit when a > 15; -- quitte la boucle uneautre

end loopend loop;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 43 / 148

Page 44: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Boucles

While

Syntaxe[label_loop :]while <condition> loop

...end loop [label_loop];

Exemplewhile a<15 loop

...end loop;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 44 / 148

Page 45: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Boucles

For

Syntaxe[label_loop :]for <identificateur> in <intervalle> loop

...end loop [label_loop];

Exemplefor i in 0 to 7 loop

...end loop;

type semaine is (lun,mar,mer,jeu,ven,sam,dim);...for jours in semaine’RANGE loop

...end loop;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 45 / 148

Page 46: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Boucles

Banc de test: génération d’une horloge

Pour un système synchrone, un processus du testeur est responsablede générer une horloge:

Génération d’horlogeconstant CLK_PERIOD: time:=40 ns;signal clk: std_logic;...clk_process: processbegin

clk<=’0’;wait for CLK_PERIOD/2;clk<=’1’;wait for CLK_PERIOD/2;

end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 46 / 148

Page 47: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Boucles

Banc de test: génération d’une horloge

La génération de l’horloge devrait s’arrêter en fin de simulation

Génération d’horlogeconstant CLK_PERIOD: time:=40 ns;signal clk: std_logic;signal sim_end: boolean:=false;...clk_process: processbegin

while(not sim_end) loopclk<=’0’;wait for CLK_PERIOD/2;clk<=’1’;wait for CLK_PERIOD/2;

end loop;wait;

end process;

Génération d’horlogeconstant CLK_PERIOD: time:=40 ns;signal clk: std_logic;signal sim_end: boolean:=false;...clk_process: processbegin

loopclk<=’0’;wait for CLK_PERIOD/2;clk<=’1’;wait for CLK_PERIOD/2;if sim_end then

wait;end if;

end loop;end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 47 / 148

Page 48: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Boucles

Boucles: Génération de stimuli

Exemple de génération d’une entrée sur 8 bits

Génération de stimulisti_process: processbegin

entreeA<="00000000";wait for CLK_PERIOD;entreeA<="00000001";wait for CLK_PERIOD;entreeA<="00000010";wait for CLK_PERIOD;entreeA<="00000011";wait for CLK_PERIOD;...

end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 48 / 148

Page 49: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Boucles

Boucles: Génération de stimuli

Amélioration avec une boucle for

Génération de stimulisti_process: processbegin

for i in 0 to 999 loopentreeA<=std_logic_vector(to_unsigned(i,entreeA’length));wait for CLK_PERIOD;

end loop;...

end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 49 / 148

Page 50: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Programmation modulaire

"Logicielle"Sous-programmes: fonctions, procéduresPaquetagesLibrairies

"Matérielle"Construction hiérarchique

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 50 / 148

Page 51: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Sous-programmes pour la simulation

Permet de modulariser le codePermet de regrouper des actions répétitivesPermet de réutiliser des fonctionsPossibilité de créer une boîte à outils pour les testsUtilise les performances du langage VHDLRend le fichier de simulation plus lisiblePermet d’automatiser la simulation

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 51 / 148

Page 52: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Sous-programmes

a

b

c

in

out

inout

Procédure

a

b

in

Fonction

in

f(a,b)

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 52 / 148

Page 53: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Fonctions

Les paramètres sont uniquement en entréeRetourne une seule valeurLa fonction a un type, celui de la valeur retournéeUtilisé pour des fonctions universelles

Conversion de typesSurcharge des opérateurs

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 53 / 148

Page 54: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Fonctions: syntaxe

Syntaxefunction nom[(liste_des_parametres)] return type is

zone_declarativebegin

zone d’instructions séquentielles

return une_valeur;end [function] [nom];

liste_des_parametres ::= element {; element}element ::= liste_de_noms : [in,out,inout] typeliste_de_noms ::= nom {, nom}

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 54 / 148

Page 55: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Déclaration d’une fonction

Une fonction peut être déclarée dans:un module VHDL

architecture ... isfunction ...

begin...

end architecture;

process ...function ...

begin...

end process;

Autres possibilités: dans l’entité ou dans un generate

un paquetage, en deux parties

Déclarationpackage ... is

...function...;...

end package;

Spécification (corps)

package body ... is...function ......

end package;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 55 / 148

Page 56: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Exemple de fonction: min

Exemplefunction min(a,b: integer) return integer isbegin

if a<b thenreturn a;

elsereturn b;

end if;end min;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 56 / 148

Page 57: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Exemple de fonction: conversion

Exemple-- fonction de conversion Integer --> Std_Logic-- si 0 --> ’0’; sinon --> ’1’function To_Std_Logic (Value : Integer)

return Std_Logic isvariable Result : Std_Logic;

beginif (Value = 0) then

Result := ’0’;else

Result := ’1’;end if;return Result;

end To_Std_Logic;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 57 / 148

Page 58: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Utilisation de la fonction

Exemple d’utilisationprocessbegin

...for I in 0 to 1 loop

-- Assignation du signal de stimuli EN_sti-- avec la valeur de l’indice de boucle IEN_sti <= To_Std_Logic(I);...

end loop;...

end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 58 / 148

Page 59: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Exemple de fonction: résolution

Fonction de résolution du type r_bit, qui comprend les valeurs ’0’,’1’, ’Z’, et ’X’

function r_resolution(sources: r_bit_vector) return r_bit isvariable resultat: r_bit := ’Z’;

beginfor i in sources’range loop

case sources(i) iswhen ’X’ => return ’X’;when ’0’ => if resultat=’1’ then

return ’X’; else resultat := ’0’;end if;

when ’1’ => if resultat=’0’ thenreturn ’X’; else resultat := ’1’;

end if;when ’Z’ => null;

end case;end loop;return resultat;

end r_resolution;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 59 / 148

Page 60: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Fonction Now

Fonction définie dans le paquetage standardRetourne le temps écoulé depuis le début de la simulationUtile pour mesurer le temps écoulé entre deux événementsFonction impure: ne retourne pas toujours la même valeur

package standard is...subtype delay_length is time range 0 fs to time’high;impure function Now return delay_length;...

end standard;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 60 / 148

Page 61: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Fonction Now: exemple d’utilisation

processvariable Temps, T_Actif, T_Inactif : time;

begin...--Mesure du cycle d’une impulsionwait until Rising_Edge(Pulse);Temps := Now;wait until Falling_Edge(Pulse);T_Actif := Now - Temps;Temps := Now;wait until Rising_Edge(Pulse);T_Inactif := Now - Temps;...

end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 61 / 148

Page 62: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Procédures

Paramètres en entrée, sortie ou les deuxPeut retourner plusieurs valeurs

Via des paramètres de sortie

Remplace une partie de description séquentiellePermet de modulariser les bancs de testEt de réduire le nombre de lignes de code

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 62 / 148

Page 63: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Procédures: syntaxe

Syntaxeprocedure nom[(liste_des_parametres)] is

zone_declarativebegin

zone d’instructions séquentiellesend [procedure] [nom];

liste_des_parametres ::= element {; element}element ::= classe liste_de_noms : mode un_typeliste_de_noms ::= nom {, nom}classe ::= constant | variablemode ::= in | out | inout

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 63 / 148

Page 64: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Déclaration d’une procédure

Une procédure peut être déclarée dans:un module VHDL

architecture ... isprocedure ...

begin...

end architecture;

process ...procedure ...

begin...

end process;

Autres possibilités: dans l’entité ou dans un generate

un paquetage, en deux parties

Déclarationpackage ... is

...procedure...;...

end package;

Spécification (corps)

package body ... is...procedure ......

end package;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 64 / 148

Page 65: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Règles d’utilisation des procédures

Le mode par défaut est inLa classe du paramètre par défaut est:

Si le mode est in: constantSi le mode est out ou inout: variable

Un paramètre peut avoir une valeur par défautConseil: placer ces paramètres à la fin de la liste

Pour une procédure définie dans un processusPossibilité d’assigner un signal sans le déclarer dans la liste desparamètres, par effet de bord

Valable pour les variables du processusValable pour les signaux de l’entité et de l’architecture

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 65 / 148

Page 66: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Sous-programmes: visibilité

Déclarations locales à la procédure B

Procédure B

Déclarations locales à la procédure A

Procédure A

Appelant(paquetage, processus, bloc ou autre sous-programme)

Déclarations globales(locales à l’appelant)

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 66 / 148

Page 67: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Si une procédure est déclarée:Dans l’architecture, avant le begin

Accès en lecture à tous les signaux de l’architecturePas d’accès direct en écriture

Dans un processus, avant le beginAccès en lecture à tous les signaux de l’architectureAccès en écriture à tous les signaux de l’architectureAccès en lecture/écriture à toutes les variables du processus

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 67 / 148

Page 68: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Exemple de procédure: min

Exempleprocedure min(a,b: in integer; c: out integer) isbegin

if a<b thenc:=a;

elsec:=b;

end if;end min;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 68 / 148

Page 69: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Exemple de procédure: attente

Exemple-- Procédure permettant d’attendre plusieurs cycles d’horloge-- Premier appel termine le cycle précédent si pas completprocedure cycle (nombre_de_cycles : Integer := 1) isbegin

for i in 1 to nombre_de_cycles loopwait until Falling_Edge(Horloge_s);wait for 2 ns; --assigne stimuli 2ns

--apres flanc descendantend loop;

end cycle;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 69 / 148

Page 70: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Exemple de procédure: vérification

Exempleprocedure Verif(

constant Message : in String;constant Signal_ref : in Std_Logic;constant Signal_Obs : in Std_Logic;variable Nbr_Err : inout Natural ) is

beginif Signal_Obs /= Signal_Ref then

Nbr_Err := Nbr_Err + 1;Erreur <= ’1’, ’0’ after 4 ns; --effet de bordreport "Erreur verif Signal " & Message

severity ERROR;end if;

end Verif;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 70 / 148

Page 71: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Procédures: Utilisation de l’exemple vérification

Exempleprocessbegin

...-- Simulation avec une boucle forfor I in 0 to (2**Nbr_E)-1 loop

Entrees_Sti <= Std_logic_Vector(To_Unsigned(I,Nbr_E));

--Calcul de l’etat de la sortie avec un algorithmeSortie_Ref <= . . . .

wait for Pas_Sim/2;verif("Test avec boucle for",

Sortie_ref, Sortie_Obs, Nbr_Err);wait for Pas_Sim/2;

end loop;...

end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 71 / 148

Page 72: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Appel de sous-programmes

L’appel d’un sous-programme peut être concurrent ou séquentiel!

Exemplearchitecture testbench of mydut_tb is

procedure starting(config: in integer) isbegin

-- do somethingend starting;

begin

starting(8);

end testbench;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 72 / 148

Page 73: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Sous-programmes

Accès aux signaux en écriture

Exemplearchitecture testbench of mydut_tb is

signal my_signal_s : std_logic;procedure example isbegin

my_signal_s <= ’0’; Illégal!!!

end example;

begin

process is

procedure example isbegin

my_signal_s <= ’0’; Légal!

end example;

beginexample;

end process;end testbench;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 73 / 148

Page 74: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs

Un attribut est une caractéristique associée à un type ou à unobjet.Utile pour les tableauxUtile pour les signaux

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 74 / 148

Page 75: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs d’un tableau

Les attributs d’un tableau T s’utilisent de la façon suivante:T’nom_attribut(numero_dimension)Le numéro de la dimension peut être omis et vaut dans ce cas 1.Les attributs suivants sont définis sur n’importe quel type tableau:

LEFT: élément le plus à gauche de l’intervalle de l’indexRIGHT: élément le plus à droite de l’intervalle de l’indexHIGH: élément le plus grand de l’indexLOW: élément le plus petit de l’indexRANGE: sous-type des indices, intervalle entre l’attribut LEFT etRIGHT

REVERSE_RANGE: intervalle inverse de RANGE

LENGTH: nombre d’éléments du tableau

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 75 / 148

Page 76: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs d’un tableau: exemple

Soit le code suivant:

type index1 is range 1 to 20;type index2 is range 19 downto 2;type vecteur1 is index1 of std_logic;type vecteur2 is index2 of std_logic;

Déterminer les valeurs des attributs suivants:

Attribut vecteur1 vecteur2LEFT 1 19RIGHT 20 2HIGH 20 19LOW 1 2RANGE 1 to 20 19 downto 2REVERSE_RANGE 20 downto 1 2 to 19LENGTH 20 18

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 76 / 148

Page 77: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs d’un tableau: usage

Permet de rendre le code génériquePas besoin de connaître à l’avance la taille d’un tableau

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 77 / 148

Page 78: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs d’un signal

S’event

S’last_event

S’last_value

S’delayed(T)

S’stable(T)

S’quiet(T)

S’transaction

S’active

S’last_active

(S’driving)(S’driving_value)

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 78 / 148

Page 79: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs: évènements et transactions

Evènement sur un signalChangement d’état d’un signalExemple: passer de l’état ’1’ à ’Z’ pour un std_logic

Transaction sur un signalAffectation d’un signalExiste même si le signal ne change pas de valeurExemple: affecter la valeur ’1’ à un signal déjà à ’1’

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 79 / 148

Page 80: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs S’active

S’active

Type du résultat booléen

Résultat vrai lorsqu’une transaction se produit sur S

Signal S

Valeur S’active

Temps 5 10 15 20 25 30 35 40 45

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 80 / 148

Page 81: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs S’event

S’event

Type du résultat booléen

Résultat vrai lorsqu’un événement se produit sur S

Signal S

Valeur S’event

Temps 5 10 15 20 25 30 35 40 45

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 81 / 148

Page 82: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attribut S’transaction

S’transaction

Type du résultat signal de type bit

Résultat signal de type bit qui change d’étatà chaque transaction sur S

Utilisation détection d’une transaction sur lesignal Start

wait on Start’transaction;

Signal S

Signal S’transaction

Temps 5 10 15 20 25 30 35 40 45

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 82 / 148

Page 83: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs S’last_active

S’last_active

Type du résultat temps (type time)

Résultat temps écoulé depuis la dernière transaction

Signal S

Signal S’last_active

Temps 5 10 15 20 25 30 35 40 452.5 ns 7.5 ns 2.5 ns

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 83 / 148

Page 84: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs S’last_event

S’last_event

Type du résultat temps (type time)

Résultat temps écoulé depuis le dernier événement

Signal S

Signal S’last_event

Temps 5 10 15 20 25 30 35 40 452.5 ns 7.5 ns 7.5 ns

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 84 / 148

Page 85: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs S’last_value

S’last_value

Type du résultat valeur de même type que S

Résultat l’état du signal précédent le dernier événement

Signal S

Valeur S’last_value

Temps 5 10 15 20 25 30 35 40 45

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 85 / 148

Page 86: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attribut S’stable(T)

S’stable(T)

Paramètre T type time, optionnel

Type du résultat signal de type booléen

Résultat vrai si le signal n’a pas eu d’événementsdurant le temps T

Signal S

S’Stable

S’Stable(5 ns)

Temps 5 10 15 20 25 30 35 40 45

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 86 / 148

Page 87: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attribut S’quiet(T)

S’quiet(T)

Paramètre T type time, optionnel

Type du résultat signal de type booléen

Résultat vrai si le signal n’a pas eu de transactionsdurant le temps T

Signal S

S’Quiet

S’Quiet(5 ns)

Temps 5 10 15 20 25 30 35 40 45

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 87 / 148

Page 88: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs S’delayed(T)

S’delayed(T)

Paramètre T type time, optionnel

Type du résultat signal de même type que S

Résultat l’état du signal au temps Now-T

Signal S

S’Delayed

S’Delayed(2.5 ns)

Temps 5 10 15 20 25 30 35 40 45

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 88 / 148

Page 89: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs d’un signal: résumé

S’event: TRUE si un événement vient d’affecter S, sinon FALSE

S’last_event: Temps écoulé depuis le dernier événement sur S

S’last_value: Valeur de S avant son dernier changement

S’delayed(T): Image de S décalée dans le temps d’une quantité T

S’stable(T): TRUE si S n’a pas subit d’événement depuis un tempsT

S’quiet(T): TRUE si S n’a pas été actif depuis un temps T

S’transaction: Retourne un signal de type BIT qui change d’état àchaque transaction sur S

S’active: TRUE si S est actif au temps actuel

S’last_active: Temps écoulé depuis la dernière activation de S

S’driving: FALSE si la transaction dans le process en cours est null

S’driving_value: Valeur de S pour la transaction dans le processen cours

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 89 / 148

Page 90: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs d’un signal: exemple

S’QUIET

S’TRANSACTION

S’STABLE

S’STABLE(5ns)

S’DELAYED

S’DELAYED (5 ns)

S’ACTIVE

S’LAST_ACTIVE

S’EVENT

S’LAST_EVENT

S’LAST_VALUE

FT T TF F

FT F TF FT T F

4ns 5ns 7ns 3ns3ns

4ns10ns 7ns 3ns8ns

0 10 0 1

5 10 15 20 25 30 35 40 45Temps (ns)

5 10 15 20 25 30 35 40 45Temps (ns)

truefalse

truefalse

truefalse

truefalse

truefalse

’1’’0’

’1’’0’

’1’’0’’1’’0’

Signal deréférence: S

Signaux

Fonctions

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 90 / 148

Page 91: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Attributs

Attributs d’un signal: exemple

Deux fonctions de la librairie IEEE.STD_LOGIC_1164

Exemplefunction rising_edge (signal s : std_ulogic) return BOOLEAN isbegin

return (s’EVENT and (To_X01(s) = ’1’) and(To_X01(s’LAST_VALUE) = ’0’));

end;

function falling_edge (signal s : std_ulogic) return BOOLEAN isbegin

return (s’EVENT and (To_X01(s) = ’0’) and(To_X01(s’LAST_VALUE) = ’1’));

end;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 91 / 148

Page 92: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Fichiers

Pour la vérification, les fichiers sont utiles pour:Récupérer des données de type stimuliRécupérer des données de référenceFournir les résultats observésFournir un rapport de simulation

Pour les descriptions de spécificationsLecture de données (ex: fichier de programmation d’une mémoire)

Le paquetage TEXTIO offreLe type FILELes fonctions nécessaires à l’accès des fichiers

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 92 / 148

Page 93: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Type fichier/FILE

Le type FILE représente de l’information stockée dans un fichierexterne

Déclaration d’un objetfile Nom_Ficher : Type_Fichier;

Le type de contenu du fichier doit être défini

Déclaration du type de fichiertype Type_Fichier is file of Quelque_Chose;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 93 / 148

Page 94: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Type fichier/FILE

Le paquetage TEXTIO définit le type suivant:type text is file of string;

Exemple de déclarationfile Mon_Fichier: text;

Exemple de types non prédéfinistype word is std_logic_vector(7 downto 0);type word_file is file of word;type real_file is file of real;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 94 / 148

Page 95: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Paquetage TEXTIO

La gestion des fichiers s’effectue au travers du paquetage TEXTIO

Utilisation du paquetage-- ligne à ajouter en début de fichieruse std.textio.all;

Facilite la manipulation des fichiersDéfinit les types et procédures nécessairesEst inclus dans la bibliothèque standardEst recommandé pour manipuler les fichiersEst portable

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 95 / 148

Page 96: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Paquetage TEXTIO

Les types suivants y sont déclarés:

type LINE is access string;

type TEXT is file of string;

type SIDE is (right,left);

subtype WIDTH is natural;

type file_type is file of elem_type;

type file_open_kind is (read_mode, write_mode, append_mode);

type file_open_status is (open_ok, status_error, name_error, mode_error);

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 96 / 148

Page 97: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Ouverture de fichier

Déclaration avec ouverture implicitearchitecture ... is

-- Déclaration d’un fichier en lecturefile fr: TEXT open READ_MODE is "Nom_Du_Fichier1.txt";-- Déclaration d’un fichier en lecture/écriturefile fw: TEXT open WRITE_MODE is "Nom_Du_Fichier2.txt";

processbegin...-- Les fichiers peuvent être directement accédés...

end process;end architecture;

Les fichiers sont automatiquementouverts en début de simulationfermés en fin de simulation

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 97 / 148

Page 98: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Ouverture de fichier

Il est possible de contrôler l’ouverture/fermeture des fichiersPermet plus de flexibilitéLa déclaration d’un fichier définit implicitement deux procédures

Pour un fichier de type file_type

procedure file_open(file f: file_type; external_name: in string;open_kind: in file_open_kind:= read_mode);

procedure file_close(file f: file_type);

type file_open_kind is (read_mode, write_mode, append_mode);

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 98 / 148

Page 99: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Ouverture de fichier

Déclaration avec ouverture explicitearchitecture ... is

-- Déclaration d’un type de fichiertype file_real is file of real;-- Déclaration d’un fichier en lecturefile fr: file_real;-- Déclaration d’un fichier en lecture/écriturefile fw: TEXT;

processbeginFILE_OPEN(fr, "Nom_du_Fichier1.txt", READ_MODE);FILE_OPEN(fw, "Nom_du_Fichier2.txt", WRITE_MODE);...-- Les fichiers peuvent être accédés...FILE_CLOSE(fr);FILE_CLOSE(fw);

end process;end architecture;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 99 / 148

Page 100: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Accès en lecture

-- lecture d’une ligne dans un fichierprocedure readline(file f: TEXT; L: out LINE);-- détection de la fin de fichierfunction endfile(file f: file_type) return boolean;-- lecture d’une valeur depuis une ligneprocedure read(line l: LINE; value: out elem_type);-- lecture d’une valeur depuis une ligne, avec statutprocedure read(line l: LINE; value: out elem_type;good: out boolean);

-- elem_type peut être:bit,bit_vector,boolean,character,integer,real,string,time

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 100 / 148

Page 101: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Accès en écriture

-- écriture d’une ligne dans un fichierprocedure writeline(file f: TEXT; L: inout LINE);-- écriture d’une valeur dans une ligneprocedure write(line l: inout LINE; value: in elem_type;

justified: in SIDE := right;field: in WIDTH :=0);

-- elem_type peut être:bit,bit_vector,boolean,character,integer,real,string,time-- justified peut être: RIGHT ou LEFT-- field définit un nombre minimum de colonnes

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 101 / 148

Page 102: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Accès en écriture

Procédures existantes-- écriture d’une valeur réelle dans une ligneprocedure write(line l: inout LINE;

value: in real;justified: in SIDE := right;field: in WIDTH :=0;digits: in Natural := 0);

-- écriture d’une valeur de temps dans une ligneprocedure write(line l: inout LINE;

value: in time;justified: in SIDE := right;field: in WIDTH :=0;unit: in time := ns);

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 102 / 148

Page 103: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Exemple d’accès en lecture

architecture testbench of test_fichier_tb is

-- Déclaration d’un fichier en lecturefile F: TEXT open READ_MODE is "mon_fichier.txt";

beginprocessvariable L: Line;variable Entier: integer;variable Chaine: String(1 to 10);

beginwhile not ENDFILE(F) loopREADLINE(F,L);READ(L,Entier);READ(L,Chaine);report "I did read number " & integer’image(Entier) &" and string ’" & Chaine & "’";

end loop;wait;

end process;end architecture;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 103 / 148

Page 104: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Exemple d’accès en écriture

architecture testbench of test_file_tb is

-- Déclaration d’un fichier en écriturefile F: TEXT open WRITE_MODE is "../src_tb/my_file.txt";

begin

processvariable L: Line;variable my_int: integer;variable my_string: String(1 to 10);

beginWRITE(L,string’("HEIG-VD/REDS: simulation ..."));WRITELINE(F,L);my_int:=25;WRITE(L,string’("Number = "),left, 10);WRITE(L,my_int,Left,10);WRITELINE(F,L);wait;

end process;end architecture;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 104 / 148

Page 105: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Exemple avec hread

Exemple de fonction existante: hread()Lit une valeur hexadécimale

Code VHDLarchitecture testbench of test_file_tb isfile READ_FILE : text open read_mode is "in.dat";

beginstimuli: processvariable Var_a,Var_b:

std_logic_vector(7 downto 0);variable li : LINE;

beginwhile (not EndFile(READ_FILE)) loop

readline(READ_FILE,li);hread(li,Var_a);hread(li,Var_b);force_input(Var_a,Var_b);wait for 10 ns;

end loop;wait;

end process;

end architecture;

Fichier in.dat0E 032C 0CFA 1718 05FF FF

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 105 / 148

Page 106: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Fichiers prédéfinis

Deux fichiers sont prédéfinis pour accéder au flux d’entrée et àcelui de sortie

file input : TEXT open read_mode is "STD_INPUT";file output : TEXT open write_mode is "STD_OUTPUT";

Ils permettentd’intéragir avec la simulation via le terminal de QuestaSimd’intéragir avec la simulation via le terminal de l’OS, en lançant lasimulation en ligne de commanded’échanger des données avec une application qui aurait lancé lasimulation

Attention, écrire sur l’output n’est pas identique à utiliser report

Compilation

La compilation doit se faire en mode VHDL-2008:vcom -2008 my_file.vhd

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 106 / 148

Page 107: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Exemple avec hread et input/output

Code VHDLarchitecture testbench of test_file_tb is

procedure force_input(a: std_logic_vector(7 downto 0); b: std_logic) isbegin

report "forcing values " & integer’image(to_integer(unsigned(a)))& " and " ;--& integer’image(to_integer(unsigned(b)));

end procedure force_input;begin

stimuli: processvariable Var_a : std_logic_vector(7 downto 0) := (others=>’0’);variable Var_bb : std_logic_vector(0 downto 0) := (others=>’0’);variable Var_b : std_logic;variable li : line;

beginwhile Var_a/="11111111" loopreadline(input,li);hread(li,Var_a);hread(li,Var_bb);Var_b := Var_bb(0);force_input(Var_a,Var_b);wait for 10 ns;write(li,string’("Et une ligne, une!"));writeline(output,li);

end loop;wait;

end process;end architecture;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 107 / 148

Page 108: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Accès aux fichiers

Sources de TextIO

Les sources de TextIO sont disponibles dans le répertoire sourcede ModelSim/QuestaSim:

Root_ModelSim/vhdl_src/stdFichier textio.vhd

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 108 / 148

Page 109: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Paquetages

Un paquetage sert à partager du code général à un projet.La spécification d’un paquetage présente tout ce qu’exporte lepaquetage:

constantesfichierstypes, sous-typessous-programmesdéclarations de composantsclauses use...

Le corps du paquetage contient:Les sous-programmes exportésDes déclarations locales (types, constantes, ...)Pas de déclarations de signaux!!!

La référence à un paquetage se fait par la clause use.

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 109 / 148

Page 110: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Exemple: spécification de paquetage

Exemple: spécification de paquetagepackage example_pkg is

type state_t is (init, read, write, done);

constant MEMSIZE : integer := 256;constant RESET_ACTIVE : std_logic := ’0’;

type memoire_t is array(0 to MEMSIZE-1) ofstd_logic_vector(15 downto 0);

component MyComponent isport (

A_i,B_i: in std_logic;C_o: out std_logic);

end component;

function min(a,b: in integer) return integer;function max(a,b: in integer) return integer;

end example_pkg;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 110 / 148

Page 111: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Exemple: corps de paquetage

Exemple: corps de paquetagepackage body example_pkg is

function min(a,b: in integer) return integer isbegin

if a < b then return a;else return b;end if;

end min;

function max(a,b: in integer) return integer isbegin

if a > b then return a;else return b;end if;

end max;

end example_pkg;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 111 / 148

Page 112: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Utilisation de paquetages

Pour l’utilisation d’un paquetage il faut le déclarer en début defichier:

Exempleuse work.example_pkg.all; Si la paquetage est compilé dans work

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 112 / 148

Page 113: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Paquetages génériques

Nouveau en VHDL-2008Paramètres génériques passés au paquetagePar exemple:

Tailles de bus pour émuler une mémoireType de donnée pour une FIFO virtuelle (sera vu dans le cours)

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 113 / 148

Page 114: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Exemple: tlm_unbounded_fifo_pkg

package tlm_unbounded_fifo_pkg is

generic (-- Type of the element stored into the FIFOstype element_type;

-- Maximum number of element stored.-- -1 means a virtually infinite number.nb_max_data : integer := -1;

-- raises objections when not emptyuse_objections : boolean := false;

-- time between two trials in blocking methodsretry_delta : time := 1 ns

);

...

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 114 / 148

Page 115: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Exemple

Instanciation du paquetage

library ieee;use ieee.std_logic_1164.all;use work.user_pkg.all;use work.tlm_unbounded_fifo_pkg;

-- Create a specialized package that will offer unbounded FIFOs with the-- specific user type of data in itpackage unbounded_user_tlm_pkg is new tlm_unbounded_fifo_pkggeneric map (element_type => user_type,

nb_max_data => 12);

-- Usage:work.unbounded_user_tlm_pkg.something...

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 115 / 148

Page 116: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Discrimination Synthèse/simulation

Il peut être utile de savoir si le VHDL est exploité en simulation ouen synthèseIdée:

Une constante définit le modeUn paquetage avec deux implémentations qui définissent cetteconstanteUn des deux est utilisé en simulation, l’autre en synthèse

Par exemple la taille d’une mémoire pourrait être différente pouraccélérer la simulation

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 116 / 148

Page 117: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Discrimination Synthèse/simulation

simsynth_pkg pour la simulationpackage simsynth_pkg is

constant SYNTHESIZE : boolean :=false;constant SIMULATE : boolean := true;

end simsynth_pkg;

simsynth_pkg pour la synthèsepackage simsynth_pkg is

constant SYNTHESIZE : boolean := true;constant SIMULATE : boolean := false;

end simsynth_pkg;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 117 / 148

Page 118: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Discrimination Synthèse/simulation

Utilisationuse work.simsynth_pkg.all;...

architecture behave of my_component isbegin

process isbegin

if SIMULATE then...

end if;end process;

genSim: if SIMULATE generate...

end generate;

end behave;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 118 / 148

Page 119: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Paquetages

Paquetage Env

VHDL-2008 offre un nouveau paquetage: EnvIl permet de terminer la simulation à n’importe quel instantEt retourne une valeur qui peut ensuite être interprétée

Fonctions-- interrompt la simulation, avec possibilité de continuerprocedure stop (status: integer);procedure stop;

-- termine la simulationprocedure finish (status: integer);procedure finish;

Utilisationuse std.env.all;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 119 / 148

Page 120: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Contextes

Contexte

Introduit avec VHDL-2008Un contexte permet de regrouper la déclaration de l’utilisation delibrairies et paquetagesPermet d’éviter de recopier tous les library et use dans chaquefichier

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 120 / 148

Page 121: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Contextes

Contexte: Pour un groupe

Exemplecontext reds_ctx is -- compiled into library redslib

library IEEE;use IEEE.std_logic_1164.all;use IEEE.numeric_std.all;use STD.env.all;

end context;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 121 / 148

Page 122: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Contextes

Contexte: Pour un projet

Syntaxecontext my_project_ctx is -- compiled into work

library redslib;context redslib.reds_ctx; -- group context

use work.simsynth_pkg.all;use work.pcie_pkg.all;

end context;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 122 / 148

Page 123: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Contextes

Contexte: Utilisation

Utilisation

library work;context work.my_project_ctx;

entity ... is...

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 123 / 148

Page 124: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Contextes

Contexte prédéfini

Il existe 2 contextes prédéfinis, dont le suivant:

IEEE_STD_CONTEXTcontext ieee_std_context is

library ieee;use ieee.std_logic_1164.all;use ieee.numeric_std.all;

end context ieee_std_context;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 124 / 148

Page 125: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Type protégé et variables partagées

Type protégé

Les variables simples ne sont visibles qu’à l’intérieur d’uneprocédure, d’une fonction ou d’un processusLes signaux peuvent être partagés et accédés par plusieursprocessusMais: problème d’accès concurrent à ces signauxLes types protégés offrent un moyen efficace de modulariser lecode et de résoudre (une partie) de la concurrenceEgalement utile pour la modélisation ou le reporting (p. exemple)Un type protégé offre:

Des méthodes externes (fonctions, procédures)L’exclusion mutuelle sur toutes ces méthodesDes variables internes

L’exclusion mutuelle implique qu’il n’est pas possible de placer deswait dans les méthodes du type (à vérifier)

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 125 / 148

Page 126: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Type protégé et variables partagées

Type protégé: déclaration

Le type protégé a une partie déclarative et un corpsLa partie déclarative présente l’interface externe du type

Semblable aux méthodes publiques d’une classe (dans un autrelangage)

Exempletype counter_t is protected

impure function get_value return integer;

procedure set_value(a: in integer);

procedure increment;

end protected counter_t;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 126 / 148

Page 127: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Type protégé et variables partagées

Type protégé: crops

Le corps permet de déclarer des variables et d’implémenter lesméthodes

Exempletype counter_t is protected body

variable value : integer := 0;

impure function get_value return integer isbegin

return value;end function get_value;procedure set_value(a: in integer) isbegin

value := a;end procedure set_value;procedure increment isbegin

value := value + 1;end procedure increment;

end protected body counter_t;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 127 / 148

Page 128: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Type protégé et variables partagées

Utilisation

Syntaxearchitecture testbench of my_tb is

shared variable my_counter_v : counter_t;

begin

process isbegin

my_counter_v.set_value(5);my_counter_v.increment;report "Value : " & integer’image(my_counter_v.get_value);wait;

end process;

end testbench;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 128 / 148

Page 129: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Type protégé et variables partagées

Exemple d’utilisation

Gestion centralisée des erreursCréation d’un type pour la modélisationUtilisation d’une variable partagée commune à tous les processusSlides suivants: modélisation d’une mémoire

Méthodes pour l’écriture et la lectureGestion de la verbositéDans un paquetage générique

Taille du bus d’adresseType des éléments à stocker

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 129 / 148

Page 130: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Type protégé et variables partagées

package memory_object_pkg is

generic (type element_type; -- Type of the element storedADDR_SIZE : integer := 8 -- Size of the address bus

);

subtype verbosity_t is integer range 0 to 1;

type memory_type is protected

procedure write(addr: in std_logic_vector; data: element_type);

impure function read(addr: in std_logic_vector)return element_type;

procedure set_verbosity(verb: in verbosity_t);

end protected memory_type;

end memory_object_pkg;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 130 / 148

Page 131: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Type protégé et variables partagées

package body memory_object_pkg is

type memory_type is protected body

-- Type of the memory array used to store the datatype memory_t is array(0 to 2**ADDR_SIZE-1) of element_type;

-- The memory array used to store the datavariable mem: memory_t;

-- Verbosity tested to display or not messagesvariable verbosity : verbosity_t;

-- Sets the verbosity of the object.-- When 0, no messages except the warningsprocedure set_verbosity(verb: in verbosity_t) isbegin

verbosity := verb;end set_verbosity;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 131 / 148

Page 132: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Type protégé et variables partagées

procedure write(addr: in std_logic_vector; data: element_type) isbegin

if is_x(addr) thenreport "The address contains an unknown value: " &

to_bstring(addr) severity warning;return;

end if;if unsigned(addr) >= 2**ADDR_SIZE then

report "The address is out of range: " & to_hstring(addr) &"while the memory contains " &integer’image(2**ADDR_SIZE) &" elements" severity warning;

return;end if;if verbosity > 0 then

report "Writing a value to the emulated memory";end if;mem(to_integer(unsigned(addr))) := data;

end write;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 132 / 148

Page 133: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Type protégé et variables partagées

impure function read(addr: in std_logic_vector) return element_type isvariable element: element_type;

beginif is_x(addr) then

report "The address contains an unknown value: " &to_bstring(addr) severity warning;return element;

end if;if unsigned(addr) >= 2**ADDR_SIZE then

report "The address is out of range: " & to_hstring(addr) &"while the memory contains " &integer’image(2**ADDR_SIZE) &" elements" severity warning;

return element;end if;if verbosity > 0 then

report "Reading a value from the emulated memory";end if;return mem(to_integer(unsigned(addr)));

end read;

end protected body memory_type;

end memory_object_pkg;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 133 / 148

Page 134: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Type protégé et variables partagées

Limitations

Impossible de:créer un tableau de shared variablescréer un pointeur sur une shared variable

L’affectation d’une shared variable à une autre copie le contenu,pas de possibilité de partager un "pointeur"

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 134 / 148

Page 135: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

VHDL et l’aléatoire

VHDL ne possède pas de mécanisme de génération de nombresaléatoiresDes librairies ont été développées, pour la simulation

IEEE.math_realRNGOS-VVM...

Pour la synthèse (pas traité ici), il existe plusieurs moyens deréaliser des générateurs pseudo-aléatoires:

LFSRAutomate cellulaireAlgorithme de Mersenne Twister

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 135 / 148

Page 136: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

IEEE.math_real

Paquetage standardisé: ieee.math_realFourni la manipulation de réelsUne procédure:

procedure UNIFORM(variable SEED1, SEED2 : inout POSITIVE;variable X : out REAL);

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 136 / 148

Page 137: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

IEEE.math_real: exemple (1)

Déclaration des librairieslibrary ieee;-- exportation de UNIFORM-- exportation de TRUNCuse ieee.math_real.all;

-- exportation de TO_UNSIGNEDuse ieee.numeric_std.all;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 137 / 148

Page 138: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

IEEE.math_real: exemple (2)

process-- 2 seeds pour la génération aléatoirevariable seed1, seed2: positive;-- valeur aléatoire entre 0 et 1.0variable rand: real;-- valeur aléatoire entre 0 et 65535variable int_rand: integer;-- stimulus alétatoire sur 16 bitsvariable stim: std_logic_vector(15 downto 0);

begin-- possibilité d’initialiser les seeds

-- génération aléatoireUNIFORM(seed1, seed2, rand);-- troncature du nombre après changement d’échelleint_rand := INTEGER(TRUNC(rand*65536.0));-- conversion vers std_logic_vectorstim := std_logic_vector(to_unsigned(int_rand, stim’LENGTH));...

end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 138 / 148

Page 139: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

Paquetage RNG

Auteur: Gnanasekaran SwaminathanPaquetage exportant 10 variables aléatoires:

1 Uniform2 Negative Exponential3 Poisson4 Normal5 Log Normal6 Erlang7 Geometric8 Hyper Geometric9 Binomial

10 Weibull

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 139 / 148

Page 140: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

Paquetage RNG: exemple

Distribution uniformeuse work.RNG.all;

architecture testbench of random_pkg_example_tb issignal int_rnd : integer range -50 to 100;

begin

process-- Loi uniforme dans [-50, 100] avec seed 7variable var: Uniform := InitUniform(7, -50.0, 100.0);variable rnd: real := 0.0;

beginfor interation in 0 to 99 loopGenRnd(var);rnd := var.rnd; -- -50 <= rnd <= 100int_rnd <= integer(rnd);report "Value : " & integer’image(int_rnd);wait for 10 ns;

end loop;wait;

end process;end testbench;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 140 / 148

Page 141: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

Paquetage RNG: exemple

Distribution Normaleuse work.RNG.all;

architecture testbench of random_pkg_example_tb issignal int_rnd : integer range -50 to 100;

begin

process-- Loi Normale, de moyenne 25 et variance 10, avec seed 7variable var: Normal := InitNormal(7, 25.0,10.0);variable rnd: real := 0.0;

beginfor interation in 0 to 99 loopGenRnd(var);rnd := var.rnd;int_rnd <= integer(rnd);report "Value : " & integer’image(int_rnd);wait for 10 ns;

end loop;wait;

end process;end testbench;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 141 / 148

Page 142: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

OS-VVM

Open Source VHDL Verification MethodologyBibliothèque open-sourceConcepteur: AldecOffre:

RandomisationCouverture

Exploite VHDL-2008Offert en natif par QuestaSimlibrary osvvm; use osvvm.all;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 142 / 148

Page 143: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

OS-VVM - paquetages

SortListPkg_Int.vhdRandomBasePkg.vhdRandomPkg.vhdCoveragePkg.vhd

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 143 / 148

Page 144: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

OS-VVM - Lois de distribution

Lois de distribution

type RandomDistType is (NONE, -- loi uniformeUNIFORM, -- loi uniformeFAVOR_SMALL, -- util. de racine carrée pour favoriser les petitsFAVOR_BIG, -- util. de racine carrée pour favoriser les grandsNORMAL, -- loi uniformePOISSON -- loi de Poisson

);

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 144 / 148

Page 145: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

OS-VVM - Exemple

Exemple

use osvvm.RandomPkg.all;

...variable aleat_v: RandomPType; Type défini par RamdomPkg

...

aleat_v.InitSeed(aleat_v’instance_name);

unEntier := aleat_v.Uniform(1,10); min=1, max=10

unEntier := aleat_v.Normal(5.0, 1.0, 1, 9); min=1, max=9

unReal := aleat_v.Normal(5.0, 1.0, 1.0, 9.0); min=1.0, max=9.0

unEntier := aleat_v.FavorBig(0,255,(50,100)); Exclusion de 50 et 100

aleat_v.SetRandomParm(NORMAL, 10.0, 2.0);unEntier := aleat_v.RandInt(0,20); Entier Normal entre 0 et 20

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 145 / 148

Page 146: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

OS-VVM - Couverture

Permet de connaître la couverture de valeurs prises par unevariablePermet de diriger la simulationEt de choisir de mettre fin à la simulationConcept

Définition de boîtes de couvertureSamplingLimité à des entiers

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 146 / 148

Page 147: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

OS-VVM - Couverture

Définition de bins

variable a_v: integer range 0 to 255;variable covA : CovPType;

-- une boîte par valeur dans 0..15covA.AddBins(GenBin(0,15,15));-- 8 boîtes de taille identiquecovA.AddBins(GenBin(0,255,8));

-- covA contient alors 2 bins-- la couverture est pleine si a_v a pris:-- toutes les valeurs entre 0 et 15-- et au moins une valeur entre 0 et 31-- et au moins une valeur entre 32 et 65-- ...

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 147 / 148

Page 148: Outils pour la simulation VHDL - HEIG-VD · 2017. 4. 28. · Outils pour la simulation VHDL assertions, procédures, attributs Yann Thoma Reconfigurable and Embedded Digital Systems

Nombres Aléatoires

OS-VVM - Exemple de couverture

processvariable covA : CovPType;variable a_value : integer := 0;variable nb_missing_values : integer;

begincovA.AddBins(GenBin(0,15,15)); Initialisation des boites

loopcovA.ICover(a_value); Sampling d’une valeur

if (covA.IsCovered) then Test de couverture

report "full coverage. Ending simulation.";wait;

end if;

nb_missing_values := covA.CountCovHoles; Nb de points manquants

a_value :=covA.RandCovPoint; Retourne une valeur non couverte

covA.WriteBin; Rapport de couverture

report "Missing " & integer’image(nb_missing_values) & " values. "& "Next one is : " & integer’image(a_value);

end loop;end process;

Y. Thoma (HES-SO / HEIG-VD / REDS) Outils pour la simulation VHDL Février 2017 148 / 148