-----------------------------------------------
-- Progetto    : ALEE
-- Nome file   : ALEE.vhdl
-- Descrizione : utilizzo del simulatore per verificare le presenza di alee
-- Autore      : Guido Matrella
-- Revisione   : 1.0
-- Note        : consideriamo come esempio il MUX2x1
-----------------------------------------------

library IEEE;
use IEEE.std_logic_1164.all;

entity MUX2x1 is 
  port(
       IN0 : in STD_LOGIC; -- ingresso 0
       IN1 : in STD_LOGIC; -- ingresso 1
       sel : in STD_LOGIC; -- selettore
       Mout: out STD_LOGIC -- uscita del MUX2x1
       );
end MUX2x1;


architecture esempio_ALEE of MUX2x1 is 
-- supponiamo che per attraversare una Porta Logica
-- i segnali subiscano un ritardo standard di 1 ns
-- che chiameremo Ritardo di Propagazione = RdP
constant RdP : time := 1 ns; 
signal x,y,z,not_sel : STD_LOGIC;

-- in questo esempio ogni volta che usiamo una porta logica 
-- aggiungiamo un ritardo pari a RdP usando il comando 'after'
begin       
    not_sel <= transport not sel after RdP;  
    x <= transport IN0 and not_sel after RdP;
    y <= transport IN1 and sel after RdP;
    Mout <= transport x or y after Rdp;
    -- Verificata la presenza di un ALEA risolviamo il problema:
    -- z <= transport IN1 and IN0 after RdP;
    -- Mout <= transport x or y or z after Rdp;
        
end esempio_ALEE;

-----------------------------------------------
-----------------------------------------------
-- TEST BENCH 
-----------------------------------------------
-----------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;

entity TOP_TB is end TOP_TB;

architecture test of TOP_TB is
component MUX2x1 is 
  port(
       IN0 : in STD_LOGIC; -- ingresso 0
       IN1 : in STD_LOGIC; -- ingresso 1
       sel : in STD_LOGIC; -- selettore
       Mout: out STD_LOGIC -- uscita del MUX2x1
       );
end component;


signal IN0_tb, IN1_tb, sel_tb, Mout_tb : STD_LOGIC := '0';

begin
    UUT: MUX2x1 port map (IN0=>IN0_tb, IN1=>IN1_tb, sel=>sel_tb, Mout=>Mout_tb);

    stimoli: process
        begin
            sel_tb<='1';IN1_tb<='1';IN0_tb<='0'; wait for 20 ns;
            sel_tb<='0';IN1_tb<='1';IN0_tb<='1'; wait for 20 ns;
            
            
            wait;
        end process;
end;


 