Laboratorio de Arquitectura de Computadoras Estándar IEEE 1164 de VHDL Oscar Alvarado Nava oan@azc.uam.mx Departamento de Electrónica División de Ciencias Básicas e Ingeniería Universidad Autónoma Metropolitana, Unidad Azcapotzalco 17-Primavera, mayo de 2017 Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 1/33
Contenido 1 2 Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 2/33
Funciones y procedimientos La funcionalidad secuecial de un circuito se puede definir en una función (function) o en un procedimiento (procedure) Las funciones se deberán contar con Declaración Definición Llamada Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 3/33
Definición, declaración y llamada de una función 15 architecture beh of adder4 is 16 -- declaracion 17 function suma4 (x,y: bit_vector (3 downto 0);cin :bit ) return bit_vector ; 18 19 -- definicion 20 function suma4 (x,y: bit_vector (3 downto 0);cin :bit ) return bit_vector is 21 variable ci,co:bit ; 22 variable suma : bit_vector (3 downto 0) :="0000 "; 23 begin 24 ci := cin ; 25 for i in 0 to 3 loop 26 suma (i) := x(i) xor y(i) xor ci; 27 co := (x(i) and y(i)) or (x(i) and ci) or (y(i) and ci); 28 ci := co; 29 end loop ; 30 return suma ; 31 end function suma4 ; 32 33 begin 34 -- llamada 35 s <= suma4 (x, y,cin ); 36 end architecture beh ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 4/33
Paquetes Las funciones se pueden agrupar en paquetes (package) Los paquetes a su vez se pueden agrupar como bibliotecas (library) Los paquetes serán conformados en dos partes Declaración de funciones y entidades Definición de funciones Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 5/33
Paquetes 1 package ac_bib is 2 -- declaraciones 3 function suma4 (x,y: bit_vector (3 downto 0);cin :bit ) return bit_vector ; 4 end package ; 5 6 package body ac_bib is 7 -- definiciones 8 function suma4 (x,y: bit_vector (3 downto 0);cin :bit ) return bit_vector is 9 variable ci,co:bit ; 10 variable suma : bit_vector (3 downto 0) :="0000 "; 11 begin 12 ci := cin ; 13 for i in 0 to 3 loop 14 suma (i) := x(i) xor y(i) xor ci; 15 co := (x(i) and y(i)) or (x(i) and ci) or (y(i) and ci); 16 ci := co; 17 end loop ; 18 return suma ; 19 end function suma4 ; 20 21 end package body ac_bib ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 6/33
Acceso a funciones en paquetes Para acceder a las funciones agrupadas en los paquetes, serán necesario incluirlos como encabezados especificando su ruta La ruta deberá componerse con puntos como separadores La ruta deberá iniciar con la palabra reservada use Si el paquete se ecuentra en el directorio de trabajo, su ruta puede ser abreviada por la palabra work Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 7/33
Encabezados 1 -- encabezado 2 use work. ac_bib.all ; 3 --el paque se encuentra en la ruta de trabajo 4 --y se llama ac_bib 5 entity adder4 is 6 port ( 7 x:in bit_vector (3 downto 0); 8 y:in bit_vector (3 downto 0); 9 cin :in bit ; 10 s: out bit_vector (3 downto 0); 11 cout : out bit 12 ); 13 end entity adder4 ; 14 15 architecture beh of adder4 is 16 begin 17 s <= suma4 (x, y,cin ); 18 end architecture beh ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 8/33
Operaciones aritméticas VHDL tiene definida las operaciones aritméticas para los objetos integer y natural Para los objetos bit y bit vector NO están definidas Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 9/33
Operación no definida 1 2 3 4 entity adder4 is 5 port ( 6 x:in bit_vector (3 downto 0); 7 y:in bit_vector (3 downto 0); 8 cin :in bit ; 9 s: out bit_vector (3 downto 0); 10 cout : out bit 11 ); 12 end entity adder4 ; 13 14 architecture beh of adder4 is 15 begin 16 17 s <= x + y + cin ; -- error : operaciones no definidas 18 end architecture beh ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 10/33
Sobrecarga de operadores Es posible definir una operación a través de una función y sobre-cargar la funcionalidad de un operador aritmético Para sobre-cargar el operador la función deberá tener por nombre el caracter que representa la operación Puede haber múltiples sobre-cargas del mismo operador Las declaraciones y definiciones pueden alojarse en un paquete Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 11/33
Sobrecarga del operador + 1 package ac_bib is 2 -- declaraciones 3 function "+"(X,Y: bit_vector (3 downto 0);CIN :bit ) return bit_vector ; 4 end package ; 5 6 package body ac_bib is 7 -- definiciones 8 function "+"(X,Y: bit_vector (3 downto 0);CIN :bit ) return bit_vector is 9 variable ci,co:bit ; 10 variable suma : bit_vector (3 downto 0) :="0000 "; 11 begin 12 ci := CIN ; 13 for i in 0 to 3 loop 14 suma (i) := x(i) xor y(i) xor ci; 15 co := (x(i) and y(i)) or (x(i) and ci) or (y(i) and ci); 16 ci := co; 17 end loop ; 18 return suma ; 19 end function "+"; 20 21 end package body ac_bib ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 12/33
LLamada a operador sobrecargado 1 -- encabezado 2 use work. ac_bib.all ; 3 4 entity adder4 is 5 port ( 6 x:in bit_vector (3 downto 0); 7 y:in bit_vector (3 downto 0); 8 cin :in bit ; 9 s: out bit_vector (3 downto 0); 10 cout : out bit 11 ); 12 end entity adder4 ; 13 14 architecture beh of adder4 is 15 begin 16 -- operador sobrecargado 17 s <= x + y; 18 end architecture beh ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 13/33
Tipo de dato multivaluado std logic El estándar especifica 9 valores para este tipo de dato: U Uninitialized X Forcing unknown 0 Forcing 0 1 Forcing 1 Z High Impedance W Weak unknown H Weak 0 L Weak 1 - Don t care También se define para std logic vector Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 14/33
Encabezados Las definiciones de tipos y operaciones, se definenen las bibliotecas library ieee; use ieee.std logic 1164.all; Las definiciones para operaciones aritméticas de números con signo, se definen las biblioteca use ieee.std logic arith.all; Las definiciones para operaciones de números sin signo, se definen las biblioteca use ieee.std logic unsigned.all; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 15/33
Uso de std logic en ghdl En GHDL será necesario agregar: --ieee=synopsys Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 16/33
Biblioteca estandarizada Definición de tipos (signed y unsigned), operaciones aritméticas y cambio de tipos (casting) ieee.numeric std.all; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 17/33
ALU Una ALU (Arithmetic Logic Unit) es un circuito combinacional capaz de realizar operaciones aritméticas y lógicas Tiene dos entradas n bits para los operandos Una entrada de m bits para las indentificar las 2 m operaciones Una salida de n bits para el resultado Un conjunto de bits para las banderas de estado, generalmente, desbordamiento v, cero z, negativo n y acarreo c Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 18/33
Esquema o símbolo de una ALU Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 19/33
Unidad aritmética-lógica TTL-74381 Función cod-op Operación clear 000 0000 sub 001 b-a sub 010 a-b add 011 a+b xor 100 a b or 101 a b and 110 a b preset 111 1111 Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 20/33
Entidad con std logic unsigned 1 library ieee ; 2 use ieee. std_logic_1164.all ; 3 use ieee. std_logic_unsigned.all ; 4 5 entity alu74381 is 6 port ( 7 s: in std_logic_vector (2 downto 0); 8 a: in std_logic_vector (3 downto 0); 9 b: in std_logic_vector (3 downto 0); 10 f: out std_logic_vector (3 downto 0) 11 ); 12 end entity alu74381 ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 21/33
Descripción del comportamiento 13 architecture beh of alu74381 is 14 begin 15 process (s,a,b) -- circuito combinacional 16 begin 17 case s is 18 when " 000 " => 19 f <= " 0000 "; 20 when " 001 " => 21 f <= b - a; 22 when " 010 " => 23 f <= a - b; 24 when " 011 " => 25 f <= a + b; 26 when " 100 " => 27 f <= a xor b; 28 when " 101 " => 29 f <= a or b; 30 when " 110 " => 31 f <= a and b; 32 when others => -- consider las 3^9-7 combinaciones restantes 33 f <= " 1111 "; 34 end case ; 35 end process ; 36 end architecture beh ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 22/33
Test bench (1/2) 1 library ieee ; 2 use ieee. std_logic_1164.all ; 3 --use ieee. std_logic_unsigned.all ; 4 5 entity tb_alu74381 is 6 end entity tb_alu74381 ; 7 8 architecture beh of tb_alu74381 is 9 component alu74381 is 10 port ( 11 s: in std_logic_vector (2 downto 0); 12 a: in std_logic_vector (3 downto 0); 13 b: in std_logic_vector (3 downto 0); 14 f: out std_logic_vector (3 downto 0) 15 ); 16 end component alu74381 ; 17 18 signal es: std_logic_vector (2 downto 0) :="000 "; 19 signal ea: std_logic_vector (3 downto 0) :="1010 "; 20 signal eb: std_logic_vector (3 downto 0) :=x"b"; 21 signal sf: std_logic_vector (3 downto 0); Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 23/33
Test bench (2/2) 22 begin 23 u0: alu74381 24 port map ( 25 s=>es, 26 a=>ea, 27 b=>eb, 28 f=>sf 29 ); 30 process -- proceso para selector 31 begin 32 wait for 20 ns; 33 es <= " 001 "; -- B-A 34 wait for 20 ns; 35 es <= " 010 "; -- A-B 36 wait for 20 ns; 37 es <= " 011 "; -- A+B 38 wait for 20 ns; 39 es <= " 100 "; -- A xor B 40 wait for 20 ns; 41 es <= " 101 "; -- A or B 42 wait for 20 ns; 43 es <= " 110 "; -- A and B 44 wait for 20 ns; 45 es <= " 111 "; -- FF 46 end process ; 47 end architecture beh ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 24/33
Análisis, enlazado, ejecución y resultados oskr@kro: /alu unsigned$ ghdl -a --ieee=synopsys alu74381.vhdl oskr@kro: /alu unsigned$ ghdl -a --ieee=synopsys tb alu74381.vhdl oskr@kro: /alu unsigned$ ghdl -e --ieee=synopsys tb alu74381 oskr@kro: /alu unsigned$./tb alu74381 --stop-time=200ns --vcd=tb alu74381.vcd oskr@kro: /alu unsigned$ gtkwave tb alu74381.vcd Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 25/33
Makefile 1 all : tb_alu74381.vcd 2 3 tb_alu74381.vcd : alu74381.o tb_alu74381.o 4 ghdl -e -- ieee = synopsys tb_alu74381 5./ tb_alu74381 --stop -time =200ns --vcd=tb_alu74381.vcd 6 gtkwave tb_alu74381. vcd ondas. sav 7 8 alu74381.o: alu74381.vhdl 9 ghdl -a -- ieee = synopsys alu74381. vhdl 10 11 tb_alu74381.o: tb_alu74381.vhdl 12 ghdl -a -- ieee = synopsys tb_alu74381. vhdl 13 14 clean : 15 rm *.o tb_alu74381 *. vcd *. cf Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 26/33
Entidad con numeric std 1 library ieee ; 2 use ieee. std_logic_1164.all ; 3 use ieee. numeric_std.all ; 4 5 entity alu74381 is 6 port ( 7 s: in std_logic_vector (2 downto 0); 8 a: in std_logic_vector (3 downto 0); 9 b: in std_logic_vector (3 downto 0); 10 f: out std_logic_vector (3 downto 0) 11 ); 12 end entity alu74381 ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 27/33
Descripción del comportamiento (1) 13 architecture beh of alu74381 is 14 begin 15 process (s,a,b) -- circuito combinacional 16 begin 17 case s is 18 when " 000 " => 19 f <= " 0000 "; 20 when " 001 " => 21 f <= std_logic_vector ( signed (b) - signed (a)); 22 when " 010 " => 23 f <= std_logic_vector ( signed (a) - signed (b)); 24 when " 011 " => 25 f <= std_logic_vector ( signed (b) + signed (a)); 26 when " 100 " => 27 f <= a xor b; 28 when " 101 " => 29 f <= a or b; 30 when " 110 " => 31 f <= a and b; 32 when others => -- consider las 3^9-7 combinaciones restantes 33 f <= " 1111 "; 34 end case ; 35 end process ; 36 end architecture beh ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 28/33
Descripción del comportamiento (2) 13 architecture beh of alu74381 is 14 signal aint,bint,fint : signed (3 downto 0); 15 begin 16 aint <=signed (a); 17 bint <=signed (b); 18 f<= std_logic_vector ( fint ); 19 20 process (s,a,b) -- circuito combinacional 21 begin 22 case s is 23 when " 000 " => 24 fint <= " 0000 "; 25 when " 001 " => 26 fint <= bint - aint ; 27 when " 010 " => 28 fint <= aint - bint ; 29 when " 011 " => 30 fint <= aint + bint ; 31 when " 100 " => 32 fint <= aint xor bint ; 33 when " 101 " => 34 fint <= aint or bint ; 35 when " 110 " => 36 fint <= aint and bint ; 37 when others => -- consider las 3^9-7 combinaciones restantes 38 fint <= " 1111 "; 39 end case ; 40 end process ; 41 end architecture beh ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 29/33
Test bench (1/2) 1 library ieee ; 2 use ieee. std_logic_1164.all ; 3 use ieee. numeric_std.all ; 4 5 entity tb_alu74381 is 6 end entity tb_alu74381 ; 7 8 architecture beh of tb_alu74381 is 9 component alu74381 is 10 port ( 11 s: in std_logic_vector (2 downto 0); 12 a: in std_logic_vector (3 downto 0); 13 b: in std_logic_vector (3 downto 0); 14 f: out std_logic_vector (3 downto 0) 15 ); 16 end component alu74381 ; 17 18 signal es: std_logic_vector (2 downto 0) :="000 "; 19 signal ea: std_logic_vector (3 downto 0) :="1010 "; 20 signal eb: std_logic_vector (3 downto 0) :=x"b"; 21 signal sf: std_logic_vector (3 downto 0); Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 30/33
Test bench (2/2) 22 begin 23 u0: alu74381 24 port map ( 25 s=>es, 26 a=>ea, 27 b=>eb, 28 f=>sf 29 ); 30 process -- proceso para selector 31 variable sel : signed (2 downto 0) :="000 "; 32 variable uno : signed (2 downto 0) :="001 "; 33 begin 34 wait for 20 ns; 35 es <= std_logic_vector ( sel ); 36 sel := sel + uno ; 37 end process ; 38 39 end architecture beh ; Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 31/33
Análisis, enlazado, ejecución y resultados oskr@kro: /alu numeric$ ghdl -a alu74381.vhdl oskr@kro: /alu numeric$ ghdl -a tb alu74381.vhdl oskr@kro: /alu numeric$ ghdl -e tb alu74381 oskr@kro: /alu numeric$./tb alu74381 --stop-time=200ns --vcd=tb alu74381.vcd oskr@kro: /alu numeric$ gtkwave tb alu74381.vcd Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 32/33
Makefile 1 all : tb_alu74381.vcd 2 3 tb_alu74381.vcd : alu74381.o tb_alu74381.o 4 ghdl -e tb_alu74381 5./ tb_alu74381 --stop -time =200ns --vcd=tb_alu74381.vcd 6 gtkwave tb_alu74381. vcd ondas. sav 7 8 alu74381.o: alu74381.vhdl 9 ghdl -a alu74381. vhdl 10 11 tb_alu74381.o: tb_alu74381.vhdl 12 ghdl -a tb_alu74381. vhdl 13 14 clean : 15 rm *.o tb_alu74381 *. vcd *. cf Oscar Alvarado Nava UAM Azcapotzalco Estándar IEEE 1164 de VHDL 33/33