Advertisement
Guest User

Untitled

a guest
Jan 6th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 6.85 KB | None | 0 0
  1. LIBRARY ieee;
  2. USE ieee.std_logic_1164.ALL;
  3. use ieee.std_logic_arith.all;
  4. -- Uncomment the following library declaration if using
  5. -- arithmetic functions with Signed or Unsigned values
  6. --USE ieee.numeric_std.ALL;
  7.  
  8. ENTITY TestQuiz IS
  9. END TestQuiz;
  10.  
  11. ARCHITECTURE behavior OF TestQuiz IS
  12.  
  13.     -- Component Declaration for the Unit Under Test (UUT)
  14.  
  15.     COMPONENT QUIZ
  16.     PORT(
  17.          rst : IN  std_logic;
  18.          clk : IN  std_logic;
  19.          P1 : IN  std_logic;
  20.          P2 : IN  std_logic;
  21.          display : OUT  std_logic_vector(6 downto 0);
  22.          stato : OUT  std_logic_vector(2 downto 0);
  23.          cont : OUT  std_logic_vector(3 downto 0)
  24.         );
  25.     END COMPONENT;
  26.    
  27.  
  28.    --Inputs
  29.    signal rst : std_logic := '0';
  30.    signal clk : std_logic := '0';
  31.    signal P1 : std_logic := '0';
  32.    signal P2 : std_logic := '0';
  33.  
  34.     --Outputs
  35.    signal display : std_logic_vector(6 downto 0);
  36.    signal stato : std_logic_vector(2 downto 0);
  37.    signal cont : std_logic_vector(3 downto 0);
  38.  
  39.    -- Clock period definitions
  40.    constant clk_period : time := 10 ns;
  41.    
  42.     function to_string (a: std_logic_vector) return string is
  43.     variable b : string (1 to a'length) := (others => NUL);
  44.     variable stri : integer:=1;
  45.     begin
  46.         for i in a'range loop
  47.             b(stri) := std_logic'image(a((i)))(2);
  48.             stri:=stri+1;
  49.         end loop;
  50.         return b;
  51.     end function;
  52.  
  53. BEGIN
  54.  
  55.     -- Instantiate the Unit Under Test (UUT)
  56.    uut: QUIZ PORT MAP (
  57.           rst => rst,
  58.           clk => clk,
  59.           P1 => P1,
  60.           P2 => P2,
  61.           display => display,
  62.           stato => stato,
  63.           cont => cont
  64.         );
  65.  
  66.    -- Clock process definitions
  67.    clk_process :process
  68.    begin
  69.         clk <= '0';
  70.         wait for clk_period/2;
  71.         clk <= '1';
  72.         wait for clk_period/2;
  73.    end process;
  74.  
  75.  
  76.     -- Stimulus process
  77.     stim_proc: process
  78.     variable ing: std_logic_vector(1 downto 0);
  79.    begin
  80.       ing:=P1&P2;  
  81.       -- hold reset state for 100 ns.
  82.         rst<='1';
  83.       wait for 4*clk_period;   
  84.       rst<='0';
  85.       wait for clk_period*2;
  86.        
  87.  
  88.       -- insert stimulus here
  89.        
  90.         P2<='1'; P1<='0';                   --Inseriamo la combinazione per far transitare
  91.       wait for clk_period*2;              -- in uno stato dei 4 stati di prenotazione
  92.       for i in 0 to 3 loop
  93.           ing:=conv_std_logic_vector(i,2);  --Proviamo che qualsiasi combinazione di ingressi
  94.         P2<=ing(1); P1<=ing(0);           --non ha effetto sull'uscita per 11 clk
  95.         wait for clk_period*2;
  96.       end loop;
  97.         P2<='0'; P1<='1';                   --E che esiste un colpo di clock in cui la macchina
  98.         wait for clk_period*2;              --si spegne indipendemnete dagli ingressi prima
  99.                                                         --di tornare in uno dei due stati di non prenotazione              
  100.       P2<='0'; P1<='0';
  101.         wait for clk_period*2;                 --Aspetto qualche clock nello stato di non prenptazione
  102.        
  103.        
  104.         --Ripeto il procedimento per ogni stato.
  105.        
  106.         P2<='0'; P1<='1';
  107.       wait for clk_period*2;
  108.       for i in 0 to 3 loop             
  109.           ing:=conv_std_logic_vector(i,2);  
  110.         P2<=ing(1); P1<=ing(0);
  111.         wait for clk_period*2;
  112.       end loop;
  113.         P2<='1'; P1<='0';  
  114.         wait for clk_period*2;
  115.        
  116.        
  117.       P2<='0'; P1<='0';
  118.           wait for clk_period*2;
  119.          
  120.              
  121.       P2<='1'; P1<='1';
  122.       wait for clk_period*2;
  123.       for i in 0 to 3 loop
  124.           ing:=conv_std_logic_vector(i,2);  
  125.         P2<=ing(1); P1<=ing(0);
  126.         wait for clk_period*2;
  127.       end loop;
  128.         P2<='1'; P1<='1';
  129.         wait for clk_period*2;
  130.        
  131.        
  132.       P2<='0'; P1<='0';
  133.           wait for clk_period*2;
  134.          
  135.  
  136.       P2<='0'; P1<='1';
  137.       wait for clk_period*2;
  138.       for i in 0 to 3 loop
  139.           ing:=conv_std_logic_vector(i,2);  
  140.         P2<=ing(1); P1<=ing(0);
  141.         wait for clk_period*2;
  142.       end loop;
  143.         P2<='0'; P1<='0';
  144.         wait for clk_period*2;
  145.        
  146.        
  147.        
  148.         P2<='0'; P1<='0';
  149.         wait for clk_period*2;
  150.        
  151.        
  152.           P2<='1'; P1<='0';
  153.       wait for clk_period*2;
  154.       for i in 0 to 3 loop
  155.           ing:=conv_std_logic_vector(i,2);  
  156.         P2<=ing(1); P1<=ing(0);
  157.         wait for clk_period*2;
  158.       end loop;
  159.         P2<='0'; P1<='1';
  160.         wait for clk_period*2;
  161.        
  162.        
  163.       P2<='0'; P1<='0';
  164.           wait for clk_period*2;
  165.          
  166.          
  167.            P2<='1'; P1<='1';
  168.       wait for clk_period*2;
  169.       for i in 0 to 3 loop
  170.           ing:=conv_std_logic_vector(i,2);  
  171.         P2<=ing(1); P1<=ing(0);
  172.         wait for clk_period*2;
  173.       end loop;
  174.         P2<='1'; P1<='0';
  175.         wait for clk_period*2;
  176.        
  177.        
  178.       P2<='0'; P1<='0';
  179.           wait for clk_period*2;
  180.            
  181.       wait;
  182. end process;
  183.  
  184. --Processi per seguire meglio la simulazione
  185.  
  186. --Processo che segue le transizioni fra stati e che stampa quando ne avviene una
  187. checkState: process (stato)
  188. variable temp_in : std_logic_vector (1 downto 0);
  189.  
  190. begin
  191. temp_in(1):=P2;
  192. temp_in(0):=P1;
  193. if(rst/='1') then
  194.  if(stato="000") then
  195.     --assert (temp_in/="00") report "Nessuno dei giocatori ha premuto il pulsante (Precedenza P1)" severity note;
  196.     --assert (temp_in="00") report "Uscita dallo stato di prenotazione" severity note;
  197.  
  198.     assert false report "Uscita dallo stato di prenotazione (Precedenza P1)" severity note;
  199.  elsif (stato="001") then
  200.     assert false report "Il giocatore 1 si è prenotato (Precedenza P1)" severity note;
  201.  elsif (stato="010") then
  202.     assert false report "Il giocatore 2 si è prenotato (Precedenza P1)" severity note;
  203.  elsif (stato="011") then
  204.     --assert (temp_in/="00") report "Nessuno dei giocatori ha premuto il pulsante (Precedenza P1)" severity note;
  205.     --assert (temp_in="00") report "Uscita dallo stato di prenotazione" severity note;
  206.     assert false report "Uscita dallo stato di prenotazione (Precedenza P2)" severity note;
  207.  elsif (stato="100") then
  208.     assert false report "Il giocatore 1 si è prenotato (Precedenza P2)" severity note;
  209.  elsif (stato="101") then
  210.     assert false report "il giocatore 2 si è prenotato (Precedenza P2)" severity note;
  211.  else
  212.     assert false report "Transizione errata" severity warning;
  213.  end if;
  214. end if;
  215.  
  216. end process;
  217. --Gestione particolare della stampa delgi unici due stati che per "00"
  218. --rimangono in se stessi e di quando si resetta
  219. nessunPressione: process(clk)
  220. variable temp_ln : std_logic_vector (1 downto 0);
  221. begin
  222. temp_ln(1):=P2;
  223. temp_ln(0):=P1;
  224. if(rising_edge(clk)) then
  225.  if(rst='1') then
  226.   assert false report "Stai resettando la macchina" severity note;
  227.  elsif(stato="000") then
  228.   assert temp_ln/="00" report "Nessuno dei due giocatori sta premendo il pulsante (Precedenza P1)" severity note;
  229.  elsif(stato="011") then
  230.   assert temp_ln/="00" report "Nessuno dei due giocatori sta premendo il pulsante (Precedenza P2)" severity note;
  231.  end if;
  232. end if;
  233. end process;
  234.  
  235. checkCounter: process (cont) --Processo stampa contatore quando effetivamente  coinvolto in uno stato
  236. begin
  237.     if(cont/="0000") then
  238.     assert false report "Ho mantenuto l'uscita per: " & to_string(cont) severity note;
  239.     end if;
  240. end process;
  241.  
  242.  
  243. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement