rappels sur vhdl i) entité - moutou.pagesperso...
TRANSCRIPT
Rappels sur VHDL
I) Entité
e0e1e2
s0
s1
ENTITY Fct ISPORT(e0,e1,e2 : IN BIT; 3 entrees e0, e1 et e2 s0,s1 : OUT BIT); 2 sorties appelée s0 et s1END Fct;
Fct
//
e[2:0]S[1 :0]
Fct
Table de véritée2 e1 e0 s1 s0
32 Table de vérité
e(2) e(1) e(0) s(1) s(0)
ENTITY Fct ISPORT(e : IN BIT_VECTOR(2 DOWNTO 0); 3 entrees s : OUT BIT_VECTOR(1 DOWNTO 0)); 2 sortiesEND Fct;
II) Architecture
Qu'est-ce qu'il y a dans la boite ?
II-1) Architecture combinatoire « with select when »
Pas de tableau de Karnaugh : écriture directe
ARCHITECTURE mydemo OF demo ISBEGIN WITH a SELECT style with select when s <= "11" WHEN "0101", premiere ligne "01" WHEN "0110", deuxieme ligne "10" WHEN "1101", troisieme ligne "00" WHEN OTHERS;END mydemo;
//
e[3:0]S[1 :0]
demo4
2 Table de véritée(3) e(2) e(1) e(0) s(1) s(0)
0 1 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 Autrement 0 0
II-2) Architecture combinatoire avec équations
Avec les tableaux de Karnaugh ou pas ! Le compilateur peut simplifier.ARCHITECTURE mydemo OF demo ISBEGIN premiere ligne s(1) <= (NOT e(3) and e(2) and not e(1) and e(0)) OR troisieme ligne (e(3) and e(2) and not e(1) and e(0)); S(0) <= A compéterEND mydemo;
III) Librairie standard logic
Seule l'entité change
e0e1e2
s0
s1
library ieee;use ieee.std_logic_1164.all;ENTITY Fct ISPORT(e0,e1,e2 : IN std_logic; 3 entrees s0,s1 : OUT std_logic); 2 sortiesEND Fct;
Fct
//
e[2:0]S[1 :0]
Fct
Table de véritée2 e1 e0 s1 s0
32 Table de vérité
e(2) e(1) e(0) s(1) s(0)
library ieee;use ieee.std_logic_1164.all;ENTITY Fct ISPORT(e : IN std_logic_VECTOR(2 DOWNTO 0);3 entr s : OUT std_logic_VECTOR(1 DOWNTO 0));2 sortiesEND Fct;
On l'utilisera systématiquement à partir de maintenant
IV) Des architectures pour le séquentiel
1°) diagramme d'évolution vers equations recurrence
00
11
01
10
Q0Q1 0 1 0 0 1 1 1 0
Q1+
Q0Q1 0 1 0 1 0 1 1 0
Q0+
Équations de récurrence :Q1
+= Q1 XOR Q0
Q0+ = /Q0
État présent État futurQ1 Q0 Q1+ Q0+ 0 0 0 1 0 1 1 0 1 0 1 1 1 1 0 0
ARCHITECTURE acmpt OF cmpt ISBEGIN PROCESS (clk) BEGIN IF (clk'EVENT AND clk='1') THEN q0 <= NOT q0; q1 <= q0 XOR q1; END IF; END PROCESS;END acmpt;
BUFFER déconseillé dans un PORT par XilinxENTITY cmpt IS PORT ( clk: IN BIT; q0,q1: BUFFER BIT); END cmpt;
BUFFER déconseillé dansun PORT par Xilinxlibrary ieee;use ieee.std_logic_1164.all;ENTITY cmpt IS PORT (clk: IN std_logic;q0,q1: BUFFER std_logic); END cmpt;
ARCHITECTURE acmpt OF cmpt ISBEGIN PROCESS (clk) BEGIN IF rising_edge(clk) THEN q0 <= NOT q0; q1 <= q0 XOR q1; END IF; END PROCESS;END acmpt;
Ou mieux encore :
ARCHITECTURE acmpt OF cmpt ISSIGNAL s_q0,s_q1 : std_logic ;BEGIN PROCESS (clk) BEGIN IF rising_edge(clk) THEN s_q0 <= NOT s_q0; s_q1 <= s_q0 XOR s_q1; END IF; END PROCESS; q0 <= s_q0 ; q1 <= s_q1 END acmpt;
BUFFER déconseillé dansun PORT par Xilinxlibrary ieee;use ieee.std_logic_1164.all;ENTITY cmpt IS PORT (clk: IN std_logic;q0,q1: OUT std_logic); END cmpt;
compteur deuxieme versionENTITY cmpt IS PORT (clock: IN BIT;q : OUT BIT_VECTOR(1 DOWNTO 0));END cmpt;ARCHITECTURE mydemo OF cmpt IS Signal s_q : bit_VECTOR(1 DOWNTO 0) ;BEGIN PROCESS(clock) BEGIN IF clock'EVENT AND clock='1' THEN
CASE s_q IS style case when WHEN "00" => s_q <="01"; WHEN "01" => s_q <="10"; WHEN "10" => s_q <="11"; WHEN OTHERS => s_q <="00" ; END CASE;
END IF; END PROCESS; q <= s_q ;END mydemo;
2°) diagramme d'évolution sans equations recurrence
00
11
01
10
AC1 = x3.e4+x4.e3 D1 = e1+/e1=1AC2 = x1.e1 D2 = e2AC3 = x2.e2 D3 = e4AC4 = x1./e1 D4 = e3
x1+ = x3.e4+x4.e3 + Initx2+ = (x1.e1+x2./e2)./Initx3+ = (x2.e2+x3./e4)./Initx4+ = (x1./e1+x4./e3)./Init
Équations de sortiesa1 = x1 a2 = x1a3 = x3 + x4a4 = x2
e1 e1
e2e3
e4
1
2
3
4
a3
a4 a3
a1 a2
3°) Graphe d'états avec equations recurrence
4°) Graphe d'états sans equations recurrence
library IEEE;use IEEE.STD_LOGIC_1164.ALL;ENTITY Alarm IS PORT( clock,Key,Trip :IN std_logic; Ring :OUT std_logic );END Alarm;ARCHITECTURE ar OF Alarm IS TYPE typetat IS (Armed, Off, Ringing); SIGNAL etat : typetat; BEGIN PROCESS (clock,etat) BEGIN partie séquentielle IF Clock ='1' AND Clock'EVENT THEN CASE etat IS WHEN Off => IF key ='1' THEN etat <= Armed; ELSE etat <= Off; END IF; WHEN Armed => IF Key = '0' THEN
Ringing
Arm ed
R ing=0R ing=0
Ring=1
R ing=0
trip=1
Ring<='1'
Ring<='0'Ring<='0'
Key='1'
Key='0'
Key='0'
Of Armed
Ringing
Trip='1'
Key='0' Key='1' and Trip='0'
Key='1'Ringing
Arm ed
R ing=0R ing=0
Ring=1
R ing=0
trip=1
Ring<='1'
Ring<='0'Ring<='0'
Key='1'
Key='0'
Key='0'
Of Armed
Ringing
Trip='1'
1 1 1
inactive active initiale
1général
cas
.....
... convergenceen OU
divergenceen OU
simplejonction ET
distribution ET jonction ETdistribution ET
5
6
=1
=1
4
cnt = cnt+1
1
e1
e2 e3
e4
2
3
4
5
x1+ = x3.x5.e4+x1./e1+Initx2+ = (x1.e1+x2./e2)./Initx3+ = (x2e2+x3./(e4x5))./Initx4+ = (x1e1+e3x4)./Initx5+ = (x4e3+x5./(e4x3))./Init
Les équations de récurrences du GRAFCET :
AC1 = x3.x5.e4D1 = e1
AC2 = x1.e1D2 = e2
AC3 = x2e2D3 =x5e4
1e1
e2 e3
e4
2
3
4
5
x1+ = x3.x5.e4+x1./e1+Initx2+ = (x1.e1+x2./e2)./Initx3+ = (x2e2+x3/(e4x5))./Initx4+ = (x1e1+e3x4)./Initx5+ = (x4e3+x5/(e4x3))./Init
Les équations de récurrences du GRAFCET :
1
e1
{2,4}
e2.e3
{3,5}
e2./e3
{3,4}
e3./e2
{2,5}
e3 e2
e4
5°) Et les GRACETs ?
V) Associations de composants
C'est le travail normal d'un électronicien.
&e1S
e2 1
e0 e0e1
e2bar
i1
i2
i3
>1
&e1S
e2 1
e0 e0e1
e2bar
i1
i2
i3
>1&e1
S
e2 1
e0 e0e1
e2bar
i1
i2
i3
>1
e0
e1
es
s
s
e0
e1
&e1S
e2 1
e0 e0e1
e2bar
i1
i2
i3
>1
e0
e1
es
s
s
e0
e1
&e1
Se2 1
e0e0e1
e2bar
i1
i2
i3
>1
e0
e1
e
s
s
s
e0
e1
i1:et PORT MAP(e0=>e0,e1=>e1,s=>e0e1);i3:ou PORT MAP(e0=>e0e1,e1=>e2bar,s=>S);
&e1
Se2 1
e0
e0e1
e2bar
i1
i2
i3
>1
e0
e1
e
s
s
s
e0
e1
i1:et PORT MAP(e0=>e0,e1=>e1,s=>e0e1);i3:ou PORT MAP(e0=>e0e1,e1=>e2bar,s=>S);
ENTITY Fct IS entité grise globalePORT(e0,e1,e2 : IN BIT;
s : OUT BIT);END Fct;
ARCHITECTURE truc OF Fct IS signaux et composants avant le begin de l'architectureSIGNAL e0e1,e2bar : BIT; COMPONENT et PORT(e0,e1 : IN BIT;
s : OUT BIT);END COMPONENT;COMPONENT ouPORT(e0,e1 : IN BIT;
s : OUT BIT);END COMPONENT;COMPONENT inverseur PORT(e : IN BIT;
s : OUT BIT);END COMPONENT;BEGIN i1:et PORT MAP(e0=>e0,e1=>e1,s=>e0e1); i2:inverseur PORT MAP(e=>e2,s=>e2bar); i3:ou PORT MAP(e0=>e0e1,e1=>e2bar,s=>s);END truc; fin de l'architecture globaleENTITY et ISPORT(e0,e1 : IN BIT;
s : OUT BIT);END et;ENTITY ou ISPORT(e0,e1 : IN BIT;
s : OUT BIT);END ou;ENTITY inverseur ISPORT(e : IN BIT;
s : OUT BIT);END inverseur;ARCHITECTURE aet OF et ISBEGIN s<=e0 AND e1;END aet;ARCHITECTURE aou OF ou ISBEGIN s<=e0 OR e1;END aou;ARCHITECTURE ainv OF inverseur ISBEGIN s<= NOT e;END ainv;
Vcc I13 I/O7 I/06 I/O5 I/O4 I/O3 I/O2 I/O1 I/O0 I12 OE/I11
CLK/I0 I1 I2 I3 I4 I5 I6 I7 I8 I9 I10 GND
GAL 20V8
10 11 12 13 14 1516 17 18 19
0 1 2 3 4 5 6 7 8 9 20 21 22 23
01234567
89101112131415
1617181920212223
2425262728293031
1
D
I/O7
23I13
22
2
I/O621
I/O5
I/O4
20
19
*SG1
*SG1
*SG1
*SG1
SL04
SL05
SL06
SL07
1 11 00 00 1
1 10 X1 0
1 01 10 X
Q
Q
1 10 X1 0
SG0
SG1
SL17
1 0
OE
VccSL07
D Q
Q
1 10 X1 0
1 11 00 00 1
OE
Vcc
SG1
SL16
1 10 X1 0
1 01 10 X
SL06
1 10 X1 0
SL05
SG1
SL15
OE
Vcc
1 11 00 00 1
1 10 X1 0
1 01 10 X
D Q
Q
1 10 X1 0
SL04
SG1
SL14
OE
Vcc
1 11 00 00 1
1 10 X1 0
1 01 10 X
D Q
Q
I1
I23
I34
I45
I56
VI) Connaître les architectures pour aller plus loin
PAL -> CPLD -> FPGAGAL
1°) Les PALs et GALs
Reset
Preset
D Q
QClk
1 01 10 00 1
01
S0
I/0x
S1
Reset
Preset
D QQClk
01
S0
S1
I/O0
Reset
Preset
D QQ
01
S0
S1
I/O1
Reset
Preset
D QQ
01
S0
S1
I/O2
Reset
Preset
D QQ
1 01 10 00 1
01
S0
S1
I/O3
I4
I3
I2
I1
Clock
1 01 10 00 1
1 01 10 00 1
1 01 10 00 1
GAL 22V10CLK/I0 I1 I2 I3 I4 I5 I6 I7 I8 I9 I10 Gnd
I11I/O0I/01I/02I/03I/04I/05I/06I/O7I/08I/09Vcc
Logicblock
Logicblock
Logicblock
Logicblock
Logicblock
Logicblock
Logicblock
Logicblock
Pro
gram
ma b
leIn
terc
onne
c t(P
I)
I/O I/O
Architecture CPLD générique
2°) Les CPLD
3°) Les FPGAMémoires
- LUTs : LUT4 puis LUT6- mémoires BRAM- additionneurs- multiplieurs 18bits x 18 bits- remplacés de plus en plus par des blocs DSP
Exemple pour Xilinx
Les FPGA Xilinx sont basés sur des matrices de blocs logiques configurables ou CLB (Configurable Logic Block ). Chaque CLB est composé :– de petites mémoires, aussi appelées tables programmables ou LUT (Look-up Table) ;– de bascules (Flip-Flop) ou registres programmables ;– de ressources logiques spécifiques câblées (par exemple pour propager des retenues dans des additionneurs/soustracteurs) ;– de ressources de configuration.
Exemple de CLB :
avr_fpga (avr_fpga_spartan3.vhd)
cpu_core (cpu_core.vhd)
io (io.vhd)
opc_fetch (opc_fetch.vhd)
opc_deco (opc_deco.vhd)
data_path (data_path.vhd)
prog_mem (prog_mem.vhd)
alu(alu.vhd)
register_file(register_file.vhd)
Regs (reg_16.vhd)status_reg (status_reg.vhd)
data_mem(data_mem.vhd)
uart (uart.vhd)
uart_rx (uart_rx.vhd)
baudgen(baudgen.vhd)
uart_tx (uart_tx.vhd)
prog_mem_content.vhd
+Ressource commune : common.vhd
Mettre son processeur dans un FPGA
I) Architecture VHDL
Registres
UAL
Unité Arithmétique et Logique
On sait faire en VHDL (TD précédents) Sait-on faire en VHDL ?
RAM : Random Access Memory) ROM/EEPROM /
FLASH
2°) Le processeur en schématique
CPU_core
I_CLK
I_CLR
I_INTVEC(5:0)
Q_RD_IO
Q_OPC(15:0)
Q_PC(15:0)
Q_DOUT(7:0)
clk_50Mhz
Q_WE_IO
Q_ADR_IO(7:0)
I_CLR
I_DIN(7:0)
io
I_CLK
I_CLR
I_ADR_IO(7:0)
Q_TX
Q_DOUT(7:0)
Q_PORTC(7:0)
PORTB(7:0)Q_PORTB(7:0)
Q_PORTD(7:0)
I_RX
I_DIN(7:0)
Q_INTVEC(5:0)
PORTC(7:0)
PORTB(7:0)
PORTD(7:0)
I_PINB(7:0)
I_RX
I_RD_IO
I_WE_IO
PINB(7:0)
C
FD
D Q
inv
3°) Mettre un programme dans le processeur
partie4.vhdmem_content.vhd
partie2.vhdpartie1.vhd
projet_final.bit
Impact
ISE
avr-gcc
prog.elf
Chaîne de compilation Xilinx
Chaîne de compilation de
programme
prog.cprog.c
partie4.vhdmem_content.vhd
partie2.vhdpartie1.vhd
projet_final.bit
Impact
ISE
avr-gcc
prog.elf
Chaîne de compilation Xilinx
Chaîne de compilation de
programme
prog.cprog.c
Comment faire communiquer ces deux chaînes de compilation ?
3-1°) Solution très lente
avr-objcopy
avr-gcc
prog.hex
avr-objcopy
prog.hex
make_mem
partie4.vhdmem_content.vhd
partie2.vhdpartie1.vhd
projet_final.bit
Impact
ISE
avr-gcc
prog.elf
Chaîne de compilation Xilinx
Chaîne de compilation de
programme
data2mem
memory.bmm prog.cprog.c
Xilinx Utility
3-2°) Solution bien plus rapide
4°) Interfacer vos propres périphériques
ATMega8
FPGA
traitement
PORTs
Registres
Distinction entre PORT et périphériques
avr_fpga_spartan3.vhd
I_CLK_50
I_CLR
I_RX
I_SWITCH[7:0]
Q_7_SEGMENT[6:0]Q_LEDS[7:0]
Q_AN[3:0]Q_TX
I_CLKI_CLRI_ADR_IO[7:0]I_DIN[7:0]I_SWITCH[7:0]I_RD_IOI_RXI_WE_IO
io.vhd
iowr: process(I_CLK)
Q_DOUT[7:0]Q_INTVEC[5:0]
Q_TX
Q_7_SEGMENT[6:0]Q_LEDS[7:0]
Q_AN[3:0]
I_ADR_IO[7:0]
PORTB
PORTC
PORTD
I_DIN[7:0] (0x38)
(0x35)
(0x32)
4-1°) PORT en sortie
iowr: process(I_CLK) begin if (rising_edge(I_CLK)) then if (I_CLR = '1') then L_RX_INT_ENABLED <= '0'; L_TX_INT_ENABLED <= '0'; elsif (I_WE_IO = '1') then case I_ADR_IO is when X"38" => PORTB Q_7_SEGMENT <= I_DIN(6 downto 0); when X"35" => PORTC
Q_LEDS <= I_DIN; when X"32" => PORTD Q_AN <= I_DIN(3 downto 0);
when X"2A" => UCSRB L_RX_INT_ENABLED <= I_DIN(7); L_TX_INT_ENABLED <= I_DIN(6); when X"2B" => UCSRA: handled by uart when X"2C" => UDR: handled by uart when X"40" => UCSRC/UBRRH: (ignored) when others => end case; end if; end if; end process;
io.vhd
4-2°) PORT en entrée
iord: process(I_ADR_IO, I_SWITCH, U_RX_DATA, U_RX_READY, L_RX_INT_ENABLED, U_TX_BUSY, L_TX_INT_ENABLED) begin case I_ADR_IO is when X"2A" => Q_DOUT <= UCSRB: L_RX_INT_ENABLED Rx complete int enabled. & L_TX_INT_ENABLED Tx complete int enabled. & L_TX_INT_ENABLED Tx empty int enabled. & '1' Rx enabled & '1' Tx enabled & '0' 8 bits/char & '0' Rx bit 8 & '0'; Tx bit 8 when X"2B" => Q_DOUT <= UCSRA: U_RX_READY Rx complete & not U_TX_BUSY Tx complete & not U_TX_BUSY Tx ready & '0' frame error & '0' data overrun & '0' parity error & '0' double dpeed & '0'; multiproc mode when X"2C" => Q_DOUT <= U_RX_DATA; UDR when X"40" => Q_DOUT <= UCSRC '1' URSEL & '0' asynchronous & "00" no parity & '1' two stop bits & "11" 8 bits/char & '0'; rising clock edge
when X"36" => Q_DOUT <= I_SWITCH; PINB when others => Q_DOUT <= X"AA"; end case; end process;
avr_fpga_spartan3.vhd
I_CLK_50
I_CLR
I_RX
I_SWITCH[7:0]
Q_7_SEGMENT[6:0]Q_LEDS[7:0]
Q_AN[3:0]Q_TX
I_CLKI_CLRI_ADR_IO[7:0]I_DIN[7:0]I_SWITCH[7:0]I_RD_IOI_RXI_WE_IO
io.vhd
iord: process(I_ADR_IO,...
PINB
UCSRC
UDR
Q_INTVEC[5:0]Q_TX
I_ADR_IO[7:0]
Q_DOUT[7:0]I_SWITCH[7:0] (0x36)
(0x40)
(0x2C)
a
b
c
d
e
f g
Afficheurs
g f e d c b a
ATMega8 (Basys 2)
PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0PC7 PC6 PC5 PC4 PC3 PC2 PC1 PC0
PORTBPORTC
PINB
LEDs
Interrupteurs
"M12" "L13" "P12" "N11" "N14" "H12" "L14"
"E2" "F3" "G3" "B4" "K3" "L3" "P11"
PORTDPD7..4 PD3 PD2 PD1 PD0
"K14""M13""J12""F12""G1" "P4" "N4" "N5"
"P6" "P7" "M11" "M5"
4-3°) Un exemple de périphériques simples
I_CLK_50
"B8"
(Q_LEDS[7:0]) (Q_7_SEGMENT[6:0]) (Q_AN[3:0])
(I_SWITCH[6:0])"N3"I_CLR
L_RD_FIFO
io.vhd
+ps2c
I_clk
Programme VHDL donné
+ps2dps2d
clk
rx_done_tickReset
I_CLR
ps2c
dout data_in
readwrite
resetclk data_out
data_presentfull
half_full
bbfifo_16x8 iord: process
PINC[7:0]
PIND[7:0]
s_data_present 7
s_buffer_full 6s_half_full 5PIND_DATA
s_rx_done_tick
s_dout
4-4°) Un exemple : lecture données PS2
#include "avr/io.h"#undef F_CPU #define F_CPU 25000000UL#include "util/delay.h"#define RXDP 7 //RXDP : data present réception dans FIFO//******************************************************// main //******************************************************
int main (void) { unsigned char portc,portd; while(1) { portc = PINC; //lecture du PORTC voir si donnée ? if (portc & (1<<RXDP)){ // si data present portd = PIND; PORTB = portd; // sortie sur les 8 LEDs } _delay_ms(1000); // on verra passer les caractères } return 0; }